Author Topic: I need to load page x of an app without calling code.  (Read 6881 times)

0 Members and 1 Guest are viewing this topic.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
I need to load page x of an app without calling code.
« on: December 13, 2013, 10:46:44 pm »
For my app, which is going to consist of 1% code and 99% data, I need to be able to swap to an arbitrary page. I plan on copying my code to RAM, so that I am free to switch pages. I know you can switch to a physical flash page by writing to a port, but I need to switch to pages based on the order they appear in the app. Can someone help me out?

Also, for copying code to RAM, how do I get spasm to compute jp addresses as if they were for that RAM? If I don't, the addresses would still point flash, which would not work.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: I need to load page x of an app without calling code.
« Reply #1 on: December 14, 2013, 02:44:34 am »
You must not think of flash and RAM as two separate memories. Memory $0000-$7FFF is flash, and $8000-$FFFF is RAM.

To make a flash page available, just write its number to port 6 to put it in $4000-$7FFF, and port 5 to put it in $0000-$3FFF (a flash page is 16384 = $3FFF bytes).

When code of an app is executed, all addresses between $4000 and $7FFF refers to its own code (since it always takes one full page), so if you want to copy something in RAM, only a ldir instruction is enough.

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #2 on: December 14, 2013, 05:21:52 am »
Also, for copying code to RAM, how do I get spasm to compute jp addresses as if they were for that RAM? If I don't, the addresses would still point flash, which would not work.
Just add another .org before the RAM code.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #3 on: December 14, 2013, 10:17:39 am »
Also, for copying code to RAM, how do I get spasm to compute jp addresses as if they were for that RAM? If I don't, the addresses would still point flash, which would not work.
Just add another .org before the RAM code.
Thanks, I didn't realize it would be that simple.

You must not think of flash and RAM as two separate memories. Memory $0000-$7FFF is flash, and $8000-$FFFF is RAM.

To make a flash page available, just write its number to port 6 to put it in $4000-$7FFF, and port 5 to put it in $0000-$3FFF (a flash page is 16384 = $3FFF bytes).

When code of an app is executed, all addresses between $4000 and $7FFF refers to its own code (since it always takes one full page), so if you want to copy something in RAM, only a ldir instruction is enough.
I get that part, but I need to know what page to swap to. From what I understand, the OS maps pages of an application to different physical flash pages.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: I need to load page x of an app without calling code.
« Reply #4 on: December 14, 2013, 12:22:49 pm »
Well, I guess this should be written somewhere in your app when it's compiled. Then all you'll have to do is get that number and output it to port 6 from RAM.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #5 on: December 14, 2013, 12:31:30 pm »
Well, I guess this should be written somewhere in your app when it's compiled. Then all you'll have to do is get that number and output it to port 6 from RAM.
But page x of an app does not correspond to page x of the physical flash page. If you have multiple apps installed, some of them will have to be offset.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: I need to load page x of an app without calling code.
« Reply #6 on: December 14, 2013, 12:35:00 pm »
Well, no, app pages are pages within flash pages. For example, if an app is on app page 1, you will read it as being on (for example) page $10 since it's the 16th flash page (IIRC).

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #7 on: December 14, 2013, 02:14:45 pm »
What if there is another app installed that occupies that page? The OS would install my app to a different page.

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #8 on: December 14, 2013, 03:23:19 pm »
I haven't programmed in assembly, but couldn't you check what page you start running from and then change page relatively?

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #9 on: December 14, 2013, 03:28:18 pm »
When your application starts, read the value of port 6, which dictates which page of physical flash the base page of your app resides on. Subsequent pages of your app extend downwards in physical page numbers.
« Last Edit: December 14, 2013, 03:30:07 pm by Runer112 »

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #10 on: December 14, 2013, 10:26:49 pm »
When your application starts, read the value of port 6, which dictates which page of physical flash the base page of your app resides on. Subsequent pages of your app extend downwards in physical page numbers.
Ok, so it's all linearly mapped, and there's no table the OS stores to access? Thanks, that's all I needed to know.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #11 on: December 16, 2013, 01:47:29 pm »
I've got another question about multi page apps, this time having to do with spasm and the defpage macro. When I run spasm, I get an error that a page is being skipped, then a message stating that same page was added successfully:
Code: [Select]
Pass one...
Pass two...
-----------------------------------------------
Beginning APP "MyApp", courtesy of SPASM macros
-----------------------------------------------
(error)
Warning: Skipping page 1 at user request.
Page 0 free space: 14895
(error)
Warning: Skipping page 2 at user request.
Page 1 free space: 131
Page 2 free space: 144
Success: Page sizes validated and "MyApp" is ready for signing.
           In 3 page(s), 15170 bytes are available.
Done
Assembly time: 0.036 seconds

I have a lot of pages in my app (above, I commented everything out but the first two temporarily to reduce compile time), so this is the structure to my code:

main.asm:
Code: [Select]
#include "ti83plus.inc"
#include "app.inc"

defpage(0, "MyApp")

[code goes here]

#include "pageinc.asm"

validate()

pageinc.asm:
Code: [Select]
#include "page01.asm"
#include "page02.asm"
#include "page03.asm"
[and so on...]

page01.asm:
Code: [Select]
defpage(1)
.db [data goes here]

And so on for all the pages. Can someone help me understand what is causing these error messages?
« Last Edit: December 17, 2013, 01:53:10 pm by fb39ca4 »

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #12 on: December 17, 2013, 12:42:54 pm »
Bump. I still can't solve this problem, which is the only thing holding me back. Spasm says the pages are skipped, then says they are added to the app, but when I look at the Wabbitemu debugger, the pages are filled with zeroes. Is there a sample multipage app I can look at to see if I am doing anything wrong?
« Last Edit: December 17, 2013, 12:44:55 pm by fb39ca4 »

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #13 on: December 17, 2013, 01:48:03 pm »
Sample. The only real observed difference is the fact that the defpages are not in the same file as the first defpage, and that the closing quotes in the initial defpage is not closed.
Code: [Select]
#include "pc/redefs.inc"
#define main_build
#include "pc/defs.inc"
#include "pc/app.inc"
#define getpagenum(label) label>>16
#define cpcall(label) call XPC \ .dw label \ .db getpagenum(label)
#define cpjump(label) call XPJ \ .db getpagenum(label) \ .dw label
#define loadslot(xx,lbl) call LSL \ .db xx*3 \ .dw lbl \ .db getpagenum(lbl)
#DEFINE CLSB(xx) $000000FF&(xx)
#DEFINE CMSB(xx) ($0000FF00&xx)>>8
#DEFINE MENU_SCREEN_WIDTH 12
;-----------------------------------------------------------------------------
;DEFINE AREA FOR DEBUGGING PURPOSES. UNCOMMENT TO ALLOW FOR EASIER WORK.

;Bypasses menu on app startup into game mode. To change the parameters of
;what you're starting up with, check in p0\_0.z80 and search for the define.
#DEFINE CADAN_MENUBYPASS

;If you're using CADAN_MENUBYPASS, uncomment one of these defines below to
;SELECT YOUR CHARACTER automatically.

;#DEFINE CADAN_MENUBYPASS_CHARSEL %00000001 ;DevBlock
#DEFINE CADAN_MENUBYPASS_CHARSEL %00000010 ;Iambian
;#DEFINE CADAN_MENUBYPASS_CHARSEL %00000100 ;Netham45 (spork)
;#DEFINE CADAN_MENUBYPASS_CHARSEL %00001000 ;Placeholder
;#DEFINE CADAN_MENUBYPASS_CHARSEL %00010000 ;Placeholder
;#DEFINE CADAN_MENUBYPASS_CHARSEL %00100000 ;Nanami
;#DEFINE CADAN_MENUBYPASS_CHARSEL %01000000 ;Netham45 (lobster)
;#DEFINE CADAN_MENUBYPASS_CHARSEL %10000000 ;Placeholder

;Automatically sets hexadecimal mode in-game. Also, changes output to the
;scoreboard from curscore to the 4 bytes in scoredebug. Yus.
;#DEFINE CADAN_AUTOSCOREDEBUG

;-----------------------------------------------------------------------------

;=============================================================================
defpage(0, "CaDan v2") ;======================================================
;
;This project is dedicated to my beloved Etri, the Catgirl o' Nine Tails, who
;understood me and my desire to extract Red Kool-Aid from all of humanity.
;
;Coding of the Calculator Danmaku Project was done as a collaborative effort
;
;Primary coding and planning: Rodger Weisman (Iambian Zenith)
;Code and script build, test: Timothy (Geekboy)
;Big time code optimization : "calc84maniac"
;
.echo "------------------"
#include "p0/_0.z80"
#include "p0/xpage.z80"    ;RAM routines held here
#include "p0/lib_menu.z80" ;Menu library routines and their supporters
#include "p0/lib_txtr.z80" ;text display library routines
#include "p0/lib_grfx.z80" ;menu graphics library
#include "p0/lib_dcmp.z80" ;decompression library
#include "p0/lib_scor.z80" ;score handler library
MenuGraphicsData:          ;menu graphical data. Read tables from this address
#include "gfxdat/build/imenu.z80"
MenuExecData:
#include "gfxdat/build/smenu.z80"
MenuTextData:
#include "gfxdat/build/tmenu.z80"

.echo "Space before 7000: ",$7000-$," out of 14366"
.block $7800-($&$0000FFFF) ;Making room for page-aligned font tables
#include "p0/dat_font.z80" ;font, kerning, and ASCII translation data
#include "p0/dat/dat_minm.z80" ;danmaku mode mini menu. No more than 213 bytes
.echo "------------------"

;=============================================================================
defpage(1)  ;=================================================================
.echo "------------------"
#include "p1/LUTables.z80" ;must not exceed 256 bytes. Page-aligned lookup table
.block $4100-($&$0000FFFF)
#include "p1/_1.z80"        ;interrupt, initialization and tasking routines
#include "p1/lib_reso.z80"  ;Resource table handlers
#include "p1/lib_scrn.z80"  ;All LCD driving routines found here
#include "p1/lib_shot.z80"  ;Bullet system
#include "p1/lib_psht.z80"  ;Player bullet system. All references in here.
#include "p1/lib_scpt.z80"  ;Script system. Contains "dat_scpt.z80"
;.block $7800-($&$0000FFFF)  ;### DEBUG SO SCRIPTSYS EDITS DO NOT KILL SCRIPT
#include "p1/lib_sprt.z80"  ;Sprite library
#include "p1/lib_enmy.z80"  ;Enemy table handlers and initializers
#include "p1/tst_stgs.z80"  ;TEST STAGES. DIRECTLY CALLED AND EXECUTED
;#include "p1/lib_sldr.z80"  ;Loading system. Supports script suspension
.echo "------------------"
;=============================================================================
defpage(2)  ;=================================================================
#include "p2/_2.z80"
;=============================================================================
validate()  ;=================================================================
« Last Edit: December 17, 2013, 01:50:29 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: I need to load page x of an app without calling code.
« Reply #14 on: December 17, 2013, 05:59:56 pm »
I've got that particular problem with spasm fixed. (There's another one I'll tackle later.) However, the data I expected to be in the next page of my app is not there. My program reads the current page from port $06, and sends back that number plus one to go to the next page. My application was stored in page 69 of flash according to the Wabbitemu debugger, but page 6A was filled with 0xFF.
« Last Edit: December 17, 2013, 08:46:39 pm by fb39ca4 »