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

0 Members and 1 Guest are viewing this topic.

Offline matthias1992

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 408
  • Rating: +33/-5
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #15 on: August 23, 2010, 05:24:45 am »
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.
that's: ouch. So basically you can't have a game engine on page 0 and game data on page 1. That sucks, leads to alot of duplicate code i guess...or am I misunderstanding?
MASM xxxxxxxxxx aborted | SADce ====:::::: 40% -Halted until further notice| XAOS =====::::: 50% -Units done| SKYBOX2D engine ========== 100% -Pre-alpha done. Need to  document it and extend |

~Those who dream by day are cognizant of much more than those who dream by night only. -Sir Edgar Allen Poe-

Offline BuckeyeDude

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 283
  • Rating: +42/-0
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #16 on: August 23, 2010, 08:06:45 am »
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.
that's: ouch. So basically you can't have a game engine on page 0 and game data on page 1. That sucks, leads to alot of duplicate code i guess...or am I misunderstanding?
If its pretty small then yeah you can duplicate it or if its speed critical. Most of the time anything like data is stored on a separate page(s) and then loaded into RAM (this also conveniently encourages you compress your data) since your ram page is visible to any app page.

Also Jerros, I'm going to shamefully plug spasm here, but there is really not a much simpler way to build a multipage app. And since im pretty sure AppDev uses TASM any code you've written is (hopefully) compatible. SPASM is here. Once you've got that download app.inc and put it in the same directory as your project.

Code: [Select]
#include "ti83plus.inc"
#include "app.inc"
defpage(0, "MyApp")
;for bcallin
_AddHLOne .equ $ - $4000
.dw AddHLOne    ;i think address comes first...
.db 1
;all code on page 0 goes here
 ld hl,0
 bcall(_AddHLOne)
 bcall(_JForceCmdNoChar)
defpage(1)
;oh look an incredibly efficient routine on page 1 :D
AddHLOne:
 ld de,1
 add hl,de     ;lalala
 ret        ;impossible to optimize btw ;)
validate()
And then run
Quote
spasm -T -L infile.asm outfile.8xk
in the command prompt (or I recommend creating a .bat file). And boom multipage app. I think the code i wrote will work, but its like 5 am here so yeah i'm starting to crash :/

I should also mention that if you need some better speed than TIs bcall routine (which require 800-1000 clocks overhead), you can write your own page swap routine. Its not terribly difficult, just load it to ram, and mess with port 6. I might post one later, but I can guarantee whatever I write now won't work :P

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Multi-Page Apps, what's the difference?
« Reply #17 on: August 23, 2010, 08:29:01 am »
You forgot the JP after the header, btw. You don't want to be executing the .dw/.db data.

And you can access data on the other page easily using the flash reading bcalls. I believe this is what is planned for multi-paged apps in Axe (and reading from archived files already uses this method)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

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 #18 on: August 23, 2010, 09:35:23 am »
I can plug Brass :)
Modifying your post, I get this.

Code: [Select]
.binarymode ti8xapp
.variablename "outfile"
#include "ti83plus.inc"
.defpage 0,$4000,$4000 ;Define pages 0 and 1
.defpage 1,$4000,$4000

.page 0 ;Page 0 goes here
.block 128 ;Set aside 128 bytes for the header
    jp Start ;Jp over the branch table
    .branch AddHLOne
Start ;Colons after labels are optional
    ld hl,0
    bcall(_AddHLOne)
    bcall(_JForceCmdNoChar)
.page 1 ;Page 1 code goes here

AddHLOne
    ld de,1
    add hl,de
    ret
And then run
Code: [Select]
brass infile.asmin the command prompt. You'll get two files. A raw hex file "outfile.hex" and a signed app "outfile.8xk"
« Last Edit: August 23, 2010, 09:36:04 am by calcdude84se »
"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 thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Multi-Page Apps, what's the difference?
« Reply #19 on: August 23, 2010, 10:01:35 am »
Ok, I feel like I need to say this. There is another hacky way that you can get info off the second page of your app, or any flash page for that matter.

Code: [Select]

ld (saveSP), hl

ld a, 1
out (05), a ;puts ram page 1 in $C000, (it's usually page 0)

in a, (06)
inc a
out (07), a ;puts second page of app in $8000

ld sp, textShadow+$4000 ;anywhere will work as long as it's free

;now you access your variables+$4000 because they
;are swapped into $C000 instead of $8000

ld a, 4
ld (enemies+$4000), a

;even cooler yet, you can put ram routines way out in the
;$C000 region and execute them

ld hl, doStuff
ld de, statVars+$4000
ld bc, doStuffEnd-doStuff
ldir

call statVars+$4000

;or you can call a routine on the second half of your app

call secondPageRoutine ;it's address is ($9123) or something

ld a, $81
out (07), a ;ram page 1
xor a
out (05), a ;ram page 0

ld sp, (saveSp)

ret


doStuff:
ld a, 5
ret
doStuffEnd:

This essentially makes your app run from $4000 through $8000 to $C000. You could actually even have your second page .org $8000 and just run it like this. The only downfall is that you can't use bcalls. You would either have to make a bcall routine that puts memory back to normal and calls it, or not use bcalls.

Edit:
   Just realized why no one does this. It won't work on an 83+. That doesn't bother me, but you might want it to work on those.
« Last Edit: August 23, 2010, 10:04:48 am by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

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 #20 on: August 23, 2010, 10:08:57 am »
Quote
There is another hacky way that you can get info off the second page of your app, or any flash page for that matter.


* HotDog just learned something new ;D

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 #21 on: August 23, 2010, 10:10:33 am »
The only problem with that is it doesn't work on the 83+, for which RAM page 0 is permanently in $C000-$FFFF in memory map mode 0. There's no good way to do it in memory map mode 1, either, or I would write one.
Edit: Ninja'd :P
« Last Edit: August 23, 2010, 10:11:11 am by calcdude84se »
"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 #22 on: August 23, 2010, 10:22:19 am »
I've kinda figured alot out by now, though my assembler 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  page2, it'd be this. How do I know the offset of labels  ?
  .db 1                                        ;  further down the programm?

;And mods, I didn't put the big empty space down here?
Also, these^ things work fine if I just put these^ kind of jump things anywhere in the programm.
Why put 'em on top and JP to your ProgStart?
« Last Edit: August 23, 2010, 10:22:50 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 #23 on: August 23, 2010, 10:25:41 am »
Again, what assembler are you using and how is your source formatted? Are you using one file per page or one file for the whole app?
« Last Edit: August 23, 2010, 10:26:14 am by calcdude84se »
"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 #24 on: August 23, 2010, 10:43:12 am »
One .z80 file per page.
Page 2 looks like this:
Code: [Select]
#DEFINE NOAPPHEADER
#INCLUDE "DWEDIT.INC"
...
Long list of #defines and .equs
...
FirstLabel:                         ; When I need to call this one it's easy, gotta fill in $4000 and it works
                             ; Becomes a problem when I need the offset of"labels further down.
« Last Edit: August 23, 2010, 10:44:25 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 #25 on: August 23, 2010, 10:55:20 am »
Ah, that's the problem. Since they're assembled one page at a time, each page is unaware of the other's labels.
Depending on what assembler you're using, you could make the whole app one file (BuckeyeDude and I gave examples for Spasm and Brass).
But, if you insist on doing it this way, you have two options. The first is to have each page file included in a larger file, but your assembler still has to support multiple pages in one file. The other option is to make use of the export directive, but this entails adding another #include to the first page and means you have to assemble the first page last.
"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 #26 on: August 23, 2010, 11:12:49 am »
Quote
author=calcdude84se link=topic=4102.msg57402#msg57402 date=1282575320]
Ah, that's the problem. Since they're assembled one page at a time, each page is unaware of the other's labels.
Nono, fixed that already.
This assembler works like a charm, and I don't really feel like spending another week learning the psychology of a new assembler ><
My only problem is that it needs to know the offset.
AppDev doesn't even need me to do the:
Code: [Select]
JumpToLabelPage2 = $ - $4000
  .dw $4000
  .db 1
at the start of the program, anywhere will do. (saves a JP statement n_n)
My problem is that I only know the offset of the first label on page 2 ($4000, duh), but I'd like to know how to point at any other label too!
And for that, I need to know the offset of a label, which I don't.
Of course it's possible to do everything with only that one jump, but that's rediculous since there's got to be a way to check the offsets of my labels. ^_^
« Last Edit: August 23, 2010, 11:14:23 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 #27 on: August 23, 2010, 11:29:08 am »
No... you need to jp to the start of the code, skipping the branch table.
And the "offset" you're talking about is the label on the second page.
That .dw should be followed by a label name on the second page. But since they are different files, you get the problem I listed.
Sorry if I sound rude, but one or both of us are very confused. :(
"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 #28 on: August 23, 2010, 11:35:10 am »
About the branch table thing - I dont put that at the start of my programm, and it still jumps to the right place on page 2.
Since I dont put it at the start, there's no need for the JP to the ProgStart either. :P
And appearantly my assembler doesn't want the label name after the .dw, it wants the offset.
Like I said, If my label is the first thing on  Page2 i just put $4000 there, but I don't want to manually count every line to calculate what offset the other labels are at, that's insane!
Of course I could load a number in AppBackupScreen and then make a jump table at the first label of Page 2, which isnt much work or takes much room, but it's still cheating and a way of hiding my incompetence as a programmer, ghehe...
And I'm not having ANY problems at the moment, everything is working fine.
Well, I still can't jump to anyhing but the first label on page 2, but you now know why that is ;)
And don't worry, you aren't sounding rude.
I should've made muself much much more clear, you're no psychic.
I'm already overwhelmed by the many people willing to help me, and they're helping me ALOT, so thank you!
« Last Edit: August 23, 2010, 11:37:32 am by Jerros »


79% of all statistics are made up randomly.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Multi-Page Apps, what's the difference?
« Reply #29 on: August 23, 2010, 12:16:14 pm »
Just put the label after the .dw statement. That's what labels are for, so you don't have to calculate manual offsets ;)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman