Author Topic: Paging memory from Basic without changing HIMEM  (Read 144 times)

0 Members and 1 Guest are viewing this topic.

Offline NotFound

  • CPC464
  • **
  • Posts: 5
  • Country: es
    • Awards
I've beem thinking about using the banked memory from Basic, without using external RSX or machine code. To do that, we must ensure that the paging area does not conflict with Basic internals or the Basic programs and its variables, and usually this is done by setting HIMEM below &4000.
But we just need to ensure that the 16KB from &4000 upwards are free from conflicts, and we can do that by defining an integer array of DIM 8191 (2 bytes by integer, index start at 0), if we found a way of putting the start of the array at &400.
After several test, I got this:
Code: [Select]
10 REM First define all non array variables
 20 i% = 0
 30 addr! = 0
 40 d! = 0
 50 REM Define the filler and page arrays
 60 DIM filler%(0)
 70 DIM a%(0)
 80 REM Ensure the array content will start at even address
 90 addr! = @a%(0)
 100 IF a > &4000 THEN ERROR 7
 110 IF (addr! AND 1) = 0 THEN GOTO 190
 120 IF wasodd% THEN PRINT "Oddity!": END
 130 ERASE a%
 140 ERASE filler%
 150 wasodd% = 1
 160 DIM filler%(0)
 170 DIM a%(0)
 180 GOTO 90
 190 REM Dimension the filler to position a% content at &4000
 200 ERASE a%
 210 ERASE filler%
 220 DIM filler%((&4000 - addr!) / 2)
 230 REM Dimension a% to use 16KB
 240 DIM a%(16 * 512 - 1)
 250 REM Verify a%
 260 addr! = @a%(0)
 270 IF UNT(addr!) <> &4000 THEN PRINT "Unexpected fail!" : END
First we enforce an even address, then we create a filler array to use the space up to &4000.Also, we must define in adavance all non-array variables, and of course the program and that variables can't be as big to use space after &4000. But we can define more arrays after.
To verifty that all this works, we draw something in screen, copy it to bank 4, and in other program copy it back to screen:

First part:
Copy the previous code and add this:
Code: [Select]
1000 REM Example: copy screen content to bank 1
 1010 MODE 2
 1020 MOVE 0, 0 : DRAW 640, 400
 1030 MOVE 0, 0 : DRAW 640, 0
 1040 MOVE 0, 0 : DRAW 0, 400
 1050 MOVE 640, 0 : DRAW 0, 400
 1060 MOVE 639, 400 : DRAW 639, 0
 1070 MOVE 639, 399 : DRAW 0, 399
 1080 REM Copy it
 1090 OUT &7FC4, &C4
 1100 FOR i% = 0 TO 16383
 1110 POKE &4000 + i%, PEEK(&C000 + i%)
 1120 POKE &C000 + i%, 0
 1130 NEXT
 1140 OUT &7FC0, &C0
 1150 MODE 1
 1160 REM Verify by reding it from other progran
 1170 PRINT "Verifying..."
 1180 RUN"memg
Second part:Copy the first block andd add this:
Code: [Select]
1000 REM Copy the saved screen back to screen
 1010 MODE 2
 1020 LOCATE 1, 21 : PRINT "Verifying..."
 1030 OUT &7FC4, &C4
 1040 FOR i% = 0 TO &3FFF
 1050 POKE &C000 + i%, PEEK(&4000 + i%)
 1060 NEXT
 1070 OUT &7FC0, &C0
Save as "memg", and run the first part.
It works!
But frankly, I'm not sure if this can be really useful, or it's just a nice trick.
« Last Edit: 00:39, 16 July 21 by NotFound »