Author Topic: Multi-Page Apps, what's the difference?  (Read 16824 times)

0 Members and 1 Guest are viewing this topic.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Multi-Page Apps, what's the difference?
« on: August 17, 2010, 08:59:27 am »
So my game is getting to big for 1 page, (my compiler sais my header is invalid, though when I remove the last lines of code I've written, I can just compile it like always, so I guess it's getting too big), but simply changing the "2" in the header doesn't seem to work  :) :
Code: [Select]
#INCLUDE "DWEDIT.INC"
.org $4000
.db $80,$0F ;Field: Program length
.db $00,$00,$00,$00 ;Length=0 (N/A for unsigned apps)
.db $80,$12 ;Field: Program type
.db $01,$04 ;Type= Shareware, TI-83Plus
.db $80,$21 ;Field: App ID
.db $01 ;Id = 1
.db $80,$31 ;Field: App Build
.db $01 ;Build = 1
.db $80,$48 ;Field: App Name
.db "MyNameXX" ;Name must be 8 characters
.db $80,$81 ;Field: App Pages
.db $02 ;App Pages = 2                               <-------------- Simply changing this won't do.
.db $80,$90 ;No default splash screen
.db $03,$26,$09,$04,$04,$6f,$1b,$80 ;Field: Date stamp- 5/12/1999
.db $02,$0d,$40 ;Dummy encrypted TI date stamp signature
.db $a1,$6b,$99,$f6,$59,$bc,$67
.db $f5,$85,$9c,$09,$6c,$0f,$b4,$03,$9b,$c9
.db $03,$32,$2c,$e0,$03,$20,$e3,$2c,$f4,$2d
.db $73,$b4,$27,$c4,$a0,$72,$54,$b9,$ea,$7c
.db $3b,$aa,$16,$f6,$77,$83,$7a,$ee,$1a,$d4
.db $42,$4c,$6b,$8b,$13,$1f,$bb,$93,$8b,$fc
.db $19,$1c,$3c,$ec,$4d,$e5,$75
.db $80,$7F ;Field: Program Image length
.db 0,0,0,0 ;Length=0, N/A
.db 0,0,0,0 ;Reserved
.db 0,0,0,0 ;Reserved
.db 0,0,0,0 ;Reserved
.db 0,0,0,0 ;Reserved

So My questions are:
What do I need to change in order to make my header "valid" again?
What's the key difference between having a singe-page App, or multi-paged ones?
How is this going to affect my programming?
What do I need to keep track of with multiple pages?
Is it importand that some things are on the same page? Or can I just randomly do as I please? (probably not :-[)

A lot of questions, but if anyone can share any wisedom it would be great@


79% of all statistics are made up randomly.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #1 on: August 17, 2010, 09:12:45 am »
Others can answer better than I can, but you will likely have to reorganize your code. It is necessary to keep some stuff together, and from what I've heard multipage apps can be somewhat of a pain. D:

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #2 on: August 17, 2010, 10:12:03 am »
I can feel that this will be a great topic.  Here's about all the wisdom I can offer:  When you have more than one page you must deal with page switching.  Since page switching is slow, don't split code that needs to be fast over the boundary.  However, if you just want to include data on the second page I think you'll be fine. :)
« Last Edit: August 17, 2010, 10:12:10 am by ztrumpet »

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #3 on: August 17, 2010, 11:20:39 am »
How do I decide what data goes on what page, and when it switches pages?
And what data will get lost when switching?
More importantly, how to switch?
Is the only way to interacts between page by an appVar or the AppBackupScreen bytes?
And what do i need to change in my header in order to get it working again?

Really a load of ??? here, and that Developpers guide doesn't help me much at all, I'm still a rookie programmer...


79% of all statistics are made up randomly.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #4 on: August 17, 2010, 11:27:08 am »
Ok, here's the deal:  Your application header is fine.  Since you have a knowledge of ASM, I'll get into a little bit of technical talk, but you can always ask questions if you are confused.

Even though your application is run directly from flash ROM, you can only have access to one application page at a time.  As was said eariler, you need to switch pages to access them.  If you are running a 2-page application, you cannot run page 1 (the second page) until you switch to it from page 0.

Now, your calculator does all this switching for you, but you need to tell the calculator which page to jump to, and WHERE on the page to jump to.  You need what's called a "branch table."  This is where you put all functions (with labels, variables, etc) that must be called from another page.

After your application header, use a "jp" statement to jump to where your program begins. 

Now, you start typing in data for labels that are on your second page.  If there is a label on your second page that your first page needs to call, you need to place it in this branch table.  If there is a label on your second page that ONLY your second page uses, you don't need to type in any data about it.

Suppose you have a label on your second page called Access_Sprite_Data, and you need to call it from your first page.  Remember, your first page is called page 0, and your second page is called page 1. 

The data to tell the calculator about this label should be typed in after your JP statement.  However, make sure that this page data starts on a byte that is a multiple of 3--and I would not be the best person to help you with that.  If it does not start on a byte that is a multiple of 3, add some .db 0 statements until the data is.  We're going to pretend that the data starts on byte 132, which is a multiple of 3.

.dw Access_Sprite_Data        ; The label on the second page that you need to call from the first page
.db 1                                  ; This function is on the second page

Now, let's say you have a third application page, with a timer function.

.dw Adjust_Timer
.db 2

And so on and so forth.  Just remember that you only need to type in functions/labels that are called from another page.

But you're not done yet.  The data is there, but the calculator doesn't know it.  So what you need is a "nickname" for each label in that branch table.  We will use ASD as the nickname for Access_Sprite_Data, and Timer as the nickname for Adjust_Timer.

ASD .equ 44 * 3     ; 44 * 3 = 132.  We need this because the page data for Access_Sprite_Data is on byte 132 of the program.
Timer .equ 45 * 3   ; 45 * 3 = 135, and the data for Adjust_Timer is on byte 135 of the program


Now, to actually call the label, use B_CALL on the nickname.  DO NOT use call, and do not use the actual label name.

B_CALL ASD
B_CALL Timer


If you need to jump to a label instead of calling it, use B_JUMP.

Now, this technique can only be used for labels that can be called and jumped to.  You, unfortunately, cannot use this to access data from another page.  You should have functions on the page with your data to access that data.

The last thing is, you have to tell your compiler which data goes on which page.  But this differs with each compiler (which one are you using?), so that is something I cannot help you with

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #5 on: August 17, 2010, 11:33:26 am »
Wow, that's complex.  Thanks for enlightening us/me.  That's more knowledge than I ever knew about multi page apps.  Thanks Hot Dog! ;D

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #6 on: August 17, 2010, 11:37:29 am »
Wow, that's complex.  Thanks for enlightening us/me.  That's more knowledge than I ever knew about multi page apps.  Thanks Hot Dog! ;D

Your welcome! 

Yes, it gets a little bit complicated, and the Developer's Guide can get confusing.  That's why I'm including an appendix in the Z80 ASM lessons about how to write applications -- single and multipage.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #7 on: August 17, 2010, 11:45:25 am »
Thanks, I think I get it.
I'll try and see.
Unfortunately, I dont ahve acces to my stuff right now, but I'll edit this, cuz I do still ahev a question or two ^_^
Anyway, thanks alot!

EDIT:

"After your application header, use a "jp" statement to jump to where your program begins."  
Huh? there's just my header, and then, after a long list of #define and "a .equ b" there's just
Code: [Select]
b_call _RunIndicOff
        b_call _GrBufClr
        rest of lines
So where would I do that JP statement?
Doesn't seem necessary either...

Suppose you have a label on your second page called Access_Sprite_Data, and you need to call it from your first page.  Remember, your first page is called page 0, and your second page is called page 1. 

The data to tell the calculator about this label should be typed in after your JP statement.  However, make sure that this page data starts on a byte that is a multiple of 3--and I would not be the best person to help you with that.  If it does not start on a byte that is a multiple of 3, add some .db 0 statements until the data is.  We're going to pretend that the data starts on byte 132, which is a multiple of 3.
How do I check if the byte's on a multiple of 3?
Also, what exactly should be on a multiple of 3?
The label I'm jumping to?
Or the command "JP"?

Thanks again!
« Last Edit: August 18, 2010, 05:43:00 am by Jerros »


79% of all statistics are made up randomly.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #8 on: August 18, 2010, 08:56:03 am »
So, at $4000 on the first page will be the header, which goes to $407F.
The calculator starts execution of the app at $4080. If you want a multipage app, (or rather if you want to run routines on other pages), you'll need a branch table (what was mentioned above). However, you'll need to skip over the table because executing it would not be good, so you'll want to use jp to skip over it. After that you'll need one byte of padding to get to a multiple of three (anything will do, so just use nop). After that, you'll need to add your off-page calls.
Starting at $4084, after the header, jp, and nop, will be the branch table. As Hot_Dog said, first you'll put the address of the routine, then the page, indexed from 0. (So the main page is page 0, the next page is page 1, and so on) As for a "nickname," it would be easiest to adapt a convention for naming them. The one I'll use in the example I'm about to give will be to prefix an underscore ('_') to the label name. For getting what it is divided by three, you'll want to use ($-$4000)/3. Now for an example.
Code: [Select]
;Branch table example
.org $4000
;Header goes here
.org $4080
    jp Start
    nop
;We're now at $4084, and here will be the branch table
;Let's suppose you have a routine called PutSprite on the third page
_PutSprite .equ ($-$4000)/3
    .dw PutSprite
    .db 2
;And a routine FetchData on the second page
_FetchData .equ ($-$4000)/3
    .dw FetchData
    .db 2
Start:
;At the end of the branch table, your code can start
;When you need to run PutSprite, use b_call(_PutSprite)
;Same for FetchData, for which you use b_call(_FetchData)
If you're still confused, feel free to continue asking. :)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #9 on: August 22, 2010, 10:11:10 am »
Got 1 problem now it seems:
When I compile it, I get an error message on this line:
Code: [Select]
LabelOnPage2_Jump .equ ($-$4000)/3 ; LabelOnPage2_Jump is the nickname for LabelOnPage2
    .dw LabelOnPage2 ; Name of the label on the other page
    .db 1 ; 0=page1   and   1=page2   right?
on the second line, my compiler tells me "Label not found: <LabelOnPage2>"

At the very beginning of the programm, after the header and between all other #defines and .equ's theres:
Code: [Select]
LabelOnPage2_Jump .equ 1*3
I don't know if the 1*3 is correct though, page 2 looks like this:
Code: [Select]
nop
nop
LabelOnPage2:
...rest of things
Also, how do I keep track of the location of the labels on the second page?
The first label is easy, I assume that line 1 = byte 1, so adding 2 nop's made the label be at byte 3.
But how do I keep track of labels further down in the programm?

Thank you!

EDIT: Ok, I realize now that I have a duplicate label, since I have both:
Code: [Select]
LabelOnPage2_Jump .equ 1*3
and
Code: [Select]
LabelOnPage2_Jump .equ ($-$4000)/3 ; LabelOnPage2_Jump is the nickname for LabelOnPage2
    .dw LabelOnPage2 ; Name of the label on the other page
    .db 1 ; 0=page1   and   1=page2   right?
Fixed that by only using the secon thing (the 3-lines one), but the problem is still that it gives the "Label not found" message I described earlier.
« Last Edit: August 22, 2010, 11:41:24 am by Jerros »


79% of all statistics are made up randomly.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #10 on: August 22, 2010, 07:19:39 pm »
Hm... How is the assembly source structured and what assembler are you using? That can influence how labels are handled.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #11 on: August 22, 2010, 08:42:21 pm »
Im curious as to what happens if you have a second page with only data and no actual code?

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #12 on: August 22, 2010, 08:47:53 pm »
Im curious as to what happens if you have a second page with only data and no actual code?

You could probably theortically access this data, but if so it's a lot more complicated than meets the eye.  If you try to access it simply by using code from your first page, you could crash your calculator.  It's much easier to load it with your own code on the data page.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #13 on: August 23, 2010, 01:06:01 am »
Ah i see, im asking because of Axe parser, i was wondering if 2 page apps might be possible if there was only data on the second page, as quigibo already said how page switching for code was not going to happen.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #14 on: August 23, 2010, 02:15:23 am »
Hm... How is the assembly source structured and what assembler are you using? That can influence how labels are handled.
I'm using "AppDev".
It needs 2 seperate .z80 files for 2-paged apps, one named "Name" and the other "Name2".

I've kinda figured alot out by now, though my asseblrer wants the specific offset for the labels I jump to, which I really wouldn't know:
Code: [Select]
JumpToLabelPage2 = $ - $4000
  .dw $4000                                 ; <-- if its the first line of the page, it'd be this. How do I know the offset of labels further down the programm?
  .db 1

;Why is there big empty space down here? Mods?
So... how do I know the offsets of the labels in the programm?
And ehh, I can have lables with the same name on page1 and page2 right?
« Last Edit: August 23, 2010, 08:26:21 am by Jerros »


79% of all statistics are made up randomly.