Author Topic: RAM  (Read 11862 times)

0 Members and 1 Guest are viewing this topic.

SirCmpwn

  • Guest
RAM
« on: December 06, 2010, 04:46:15 pm »
Hello,
How would I go about setting up an Axe application with a different page of RAM so that I have more space?  Also, would it work on newer models?

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: RAM
« Reply #1 on: December 06, 2010, 06:14:04 pm »
What do you mean setting it up with a different page of ram? As in copying it into another ram page, or running it from a ram page?

The only way, that I can think of, is to use port 6 and 7, and copy 0x4000 to 0x8000.  But messing with port 7 is hard. Also, you could just allocate enough space for an appvar, copy it, then copy it to a ram page.  Not sure if it is runnable, though.

SirCmpwn

  • Guest
Re: RAM
« Reply #2 on: December 06, 2010, 06:14:52 pm »
I just want to have a lot of free RAM that I can just use.  I figure swapping in a different RAM page would do this, but I don't know how.

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: RAM
« Reply #3 on: December 06, 2010, 09:13:46 pm »
Well, first off, how much RAM do you really need?  Could you stick to using the main RAM, and keep compatibility with the 83+ BE?

Hardware-wise, the Z80 address space is divided into 4 "banks", which each hold one 16k memory page.  The first bank is always used for Flash page zero; the second two ("A" and "B") can be mapped to any page you like, and the fourth ("C") is always used for RAM page zero on the 83+ BE, but can be mapped to any RAM page on the 83+ SE and 84+.

Now, all of that said, you should realize that you can't usually change the pages mapped in banks B and C, unless you're very careful about it; bank C contains your program's stack, and bank B contains your program's code and variables.  Bank B - RAM page 1 - also contains lots of variables that are used by system routines, including the system interrupt service routine.

So that leaves bank A.  In a RAM assembly program, you can change bank A whenever you like (unless it's a shell program and you're using shell library routines), but you also have to be sure to restore the original page to bank A when your program finishes.  This might be a plausible strategy for Axe programs (correct me if I'm wrong, but I don't think Axe programs use any shell library routines), but it wouldn't work for Flash applications.  And of course it does break compatibility with the 83+ BE.

As far as what pages you can use: newer 84+es have only 1 extra page of RAM, whereas older 84+es, 83+ SEs, and (I believe) Nspire-84+es have 6 extra pages.  Of RAM page 3 (or, on newer calculators, the single extra page), a small amount of memory is used by the OS for storing application base pages (so if you overwrite that area, you have to call FillBasePageTable to restore it), and a further area (about a kilobyte, as I recall) is used as scratch space for USB operations.

Perhaps it would be useful for Axe to provide an "allocate temporary buffer" function, which could be implemented in various ways depending on the calculator model and the type of program (RAM versus application) you're compiling.

SirCmpwn

  • Guest
Re: RAM
« Reply #4 on: December 06, 2010, 11:31:45 pm »
Thank you, but I know quite well about how the banks and all work.  If I didn't, I really shouldn't be writing KnightOS.  I just want to know how to swap in an extra RAM page, because I can never seem to get this particular part working.

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: RAM
« Reply #5 on: December 06, 2010, 11:56:02 pm »
Right, sorry.  In that case, I'm not sure what exactly you're asking.  Could you post an example of code you've tried that doesn't work the way you expect?

SirCmpwn

  • Guest
Re: RAM
« Reply #6 on: December 06, 2010, 11:57:09 pm »
I just don't understand how to set up memory to swap in spare RAM.  I don't have example code.

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: RAM
« Reply #7 on: December 07, 2010, 12:17:44 am »
I guess you would do something like "in a,(6) / push af / ld a, 83h / out (6),a" (Asm(DB06F53E83D306)) to set the mapping, and "pop af / out (6),a" (Asm(F1D306)) to restore it.  (Is it OK to use pushes and pops in inline assembly like that?)

SirCmpwn

  • Guest
Re: RAM
« Reply #8 on: December 07, 2010, 12:19:58 am »
Yes, it's okay, and thank you :)
That gives me C000 and up as free RAM, correct?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: RAM
« Reply #9 on: December 07, 2010, 12:20:38 am »
There shouldn't be a problem with that, I use that all the time for when I switch out pages. It won't pose a problem at all unless his code uses a "pop" without another "push."

EDIT: Ninja!

No, all it does is swap out 4000h to 7FFFh to the RAM page leaving the rest intact. Are you trying to make use of all of the RAM at once?

SirCmpwn

  • Guest
Re: RAM
« Reply #10 on: December 07, 2010, 12:23:22 am »
No, that much should be fine.  If I have an app running at 4000h, what happens to it?
« Last Edit: December 07, 2010, 12:23:41 am by SirCmpwn »

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: RAM
« Reply #11 on: December 07, 2010, 12:25:30 am »
Yes, it's okay, and thank you :)
That gives me C000 and up as free RAM, correct?
No, that's port 6, which controls the 4000-7FFF area.  And if you want to use the area from 4000h to 4080h, you should also add a B_CALL FillBasePageTable (that's EF1150) to clean up when you're done.
« Last Edit: December 07, 2010, 12:27:17 am by FloppusMaximus »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: RAM
« Reply #12 on: December 07, 2010, 12:26:10 am »
Then the App is switched out. If you run this from an app, you might have a problem.

SirCmpwn

  • Guest
Re: RAM
« Reply #13 on: December 07, 2010, 12:26:58 am »
So this only works from a program?  And I get 4000-7FFF, assuming I use FillBasePageTable?

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: RAM
« Reply #14 on: December 07, 2010, 12:29:08 am »
Right.

If you want to write an app that does this, it becomes much more complicated.

Oh, and you should also add a check at the start of your program, to be sure you're running on an SE/84+.