Author Topic: Page Swapping  (Read 3647 times)

0 Members and 1 Guest are viewing this topic.

SirCmpwn

  • Guest
Page Swapping
« on: March 18, 2011, 07:39:30 pm »
This is my entire code:
Code: [Select]
di
ld a, $82
out (7), a
ld a, $81 ;also tried $80
out (7), a
ei
ret

This crashes, any idea why?

EDIT: I'm a dork :P perhaps I shouldn't be executing in the 0x8000-0xC000 when I swap it out.
« Last Edit: March 18, 2011, 08:02:35 pm by SirCmpwn »

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Page Swapping
« Reply #1 on: March 18, 2011, 09:58:54 pm »
that would be a good idea.  Just to clarify to anyone who's reading and has the same problem, port 7 controls the ram page that is located in the 0x8000-0xC000 range.  When you swap the page out, pc still points to whatever location inside there, and so points to the new page and not the old one.

I had the same issue for multipage apps.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: Page Swapping
« Reply #2 on: March 28, 2011, 07:18:54 am »
So how does one deal with that issue?
There's something about Tuesday...


Pushpins 'n' stuff...


Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Page Swapping
« Reply #3 on: March 28, 2011, 07:34:15 am »
So how does one deal with that issue?
Well, you place code outside of the page you are moving to move it.  For example, in an app that's stored from $4000-$7FFF, you could place a routine in ram at $8000 that swaps the pages out.  This is essentially what bcall does, albeit with a table lookup routine and other stuff.  bcall is on page 0 at a set location, and it can therefore swap any page out of any bank, because it can't be swapped out.

TL;DR, you have to have a routine outside of the page you are trying to swap.

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: Page Swapping
« Reply #4 on: March 28, 2011, 09:16:48 am »
For a really easy way that will work on all calculators. Output $81 (Ram page 1) to port (06) ($4000-$8000). Then jump to a [label in you program - $4000]. You are now executing in the $4000 range so you can do whatever with port (07). Then when you are done, put page $81 back into (07) and jump back.

Remember though, when you are executing in the $4000's, all the labels in your program are still back up in the $8000 range. So anything that requires an absolute address: jp; ld hl, (label in your program); and call; all need to be adjusted accordingly when you switch.
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 jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Page Swapping
« Reply #5 on: March 28, 2011, 05:05:05 pm »
note that the post above refers to if you use an asm program only, and not an app.

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Page Swapping
« Reply #6 on: March 28, 2011, 05:26:02 pm »
Why don't you just swap in the 4000h-7FFFh range (port 6). It's what EOS uses itself. (Though that won't work for applications, in which case your code is fine, but only for applications.)
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Page Swapping
« Reply #7 on: March 28, 2011, 05:33:38 pm »
What's the hex for storing ports? I'd like to try this page switching thing in Axe.
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Page Swapping
« Reply #8 on: March 28, 2011, 05:37:08 pm »
What's the hex for storing ports? I'd like to try this page switching thing in Axe.
D3 is out, so D306 would be out (6),a.  ld a,* is 3E, so ld a, $FF would be 3EFF.  So to swap page 81 into the $4000 region, you would do 3E81D306.  More of these equates can be found here.

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: Page Swapping
« Reply #9 on: March 28, 2011, 11:12:10 pm »
Points to keep in mind:
- If you alter the mapping in the 8000-BFFF or C000-FFFF blocks, system routines - including the system interrupt service routine - will not work.  Most other stuff - e.g., shell library routines, many Axe builtin commands - won't work either.
- If you alter the mapping in the 4000-7FFF block, you must restore the original mapping before exiting your program.