2 ; Christian Groessler, Jun-2013
4 ; This routine is used in preparation to move the screen memory
5 ; in front of the program.
7 ; It calculates the value to put into RAMTOP for a subsequent
8 ; "GRAPHICS 0" call, and the lowest address which will be used
9 ; by the screen memory afterwards.
12 ; __SAVEAREA_LOAD__ - load address of the program
14 ; lodadr - (high byte only) value to
16 ; lowadr - lowest address occupied by
21 ; When setting a display mode, the ROM takes the RAMTOP value
22 ; and subtracts the size of the screen memory from it. This will
23 ; become the new screen memory address.
24 ; From this address it subtracts the size of the display list.
25 ; This will become the new display list address.
26 ; Screen memory cannot cross 4K boundaries and a display list
27 ; cannot cross a 1K boundary.
29 ; Work out a sane value for RAMTOP to prevent boundary crossing.
30 ; RAMTOP is only one byte, it counts in memory pages.
32 ; The ROM doesn't do this boundary checking, since it doesn't
33 ; expect RAMTOP to have (rather) arbitrary values. For a
34 ; "GRAPHICS 0" call and RAMTOP representing the possible physically
35 ; available memory, boundary crossing cannot happen.
38 SCRBUFSZ = (40 * 24) ; size of mode 0 screen buffer
39 DLSZ = 32 ; size of mode 0 display list
44 ; subtract screen memory size from our load address
54 ; check if a 4K boundary is crossed
64 ; if lodadr is at an exact 4K boundary, it's still ok
70 ; 4K boundary will be crossed, use this 4K boundary address as lodadr
79 lodadr: .word __SAVEAREA_LOAD__ & $FF00 ; our program's load address, rounded down to page boundary
85 ; subtract display list size from calculated screen address
96 .if 0 ; this cannot happen
97 ; check if a 1K boundary is crossed
105 bne al4k ; 1K boundary will be crossed, decrease lodadr
108 ; address of display list is ok
109 ; decrease lowadr by two