2 ; Atari XL shadow RAM preparation routines
5 ; - move screen memory below load address
6 ; - copy ROM chargen to its new place
7 ; - copy shadow RAM contents to their destination
9 ; Christian Groessler, chris@groessler.org, 2013
14 .if .defined(__ATARIXL__)
17 .import __SRPREP_LOAD__, __SRPREP_SIZE__
18 .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__
19 .import __SHADOW_RAM_RUN__
20 .import __CHARGEN_START__, __CHARGEN_SIZE__
21 .import __SAVEAREA_LOAD__
24 .include "zeropage.inc"
26 .include "save_area.inc"
28 .macro print_string text
31 start: .byte text, ATEOL
32 cont: ldx #0 ; channel 0
46 ; ------------------------------------------------------------------------
52 .word __SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__ - 1
54 ; ------------------------------------------------------------------------
61 print_string "entering stage #2"
64 ; save values of modified system variables and ports
78 lda CIOV ; zero-page wrapper
84 lda SIOV ; zero-page wrapper
97 .include "xlmemchk.inc" ; calculate lowest address used and new value for RAMTOP
109 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
113 .ifdef DEBUG ; only check in debug version, this shouldn't happen normally(tm)
115 print_string "Internal error, no free IOCB!"
119 jsr restore ; restore stuff we've changed
120 jmp (DOSVEC) ; abort loading
124 ; Reopen it in Graphics 0
135 lda #<screen_device_length
137 lda #>screen_device_length
142 ; shouldn't happen(tm)
143 print_string "Internal error, aborting..."
147 jsr restore ; restore stuff we've changed
148 jmp (DOSVEC) ; abort loading
151 scrok: ; now close it again -- we don't need it anymore
157 ; Save the zero page locations we need
165 ; copy chargen to low memory
168 print_string "copy chargen to low memory"
169 print_string "set up high memory"
172 lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
174 lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
178 ; page align the new chargen address
192 lda #>__CHARGEN_SIZE__
194 lda #<__CHARGEN_SIZE__
198 ; TODO: switch to this temp. chargen
203 stx NMIEN ; disable NMI
206 sta PORTB ; now ROM is mapped out
208 ; copy shadow RAM contents to their destination
210 lda #<__SHADOW_RAM_SIZE__
212 lda #>__SHADOW_RAM_SIZE__
213 beq no_copy ; we have no shadow RAM contents
215 ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len
216 do_copy:lda #<__SHADOW_RAM_LOAD__
218 lda #>__SHADOW_RAM_LOAD__
220 lda #<__SHADOW_RAM_RUN__
222 lda #>__SHADOW_RAM_RUN__
224 lda #<__SHADOW_RAM_SIZE__
226 lda #>__SHADOW_RAM_SIZE__
233 ; copy chargen to its new (final) location
239 lda #<__CHARGEN_START__
241 lda #>__CHARGEN_START__
243 lda #>__CHARGEN_SIZE__
245 lda #<__CHARGEN_SIZE__
255 sta NMIEN ; enable VB again
256 cli ; and enable IRQs
259 print_string "Stage #2 OK"
264 .include "findfreeiocb.inc"
266 ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html)
297 ; clean up after a fatal error
299 restore:lda RAMTOP_save
312 .byte "HERE ****************** HERE ***************>>>>>>"
315 .word __SHADOW_RAM_SIZE__
337 screen_device: .byte "S:",0
338 screen_device_length = * - screen_device
340 .byte " ** srprep ** end-->"
342 ; ------------------------------------------------------------------------
343 ; Provide an empty SHADOW_RAM segment in order that the linker is happy
344 ; if the user program doesn't have a SHADOW_RAM segment.
346 .segment "SHADOW_RAM"
349 ; ------------------------------------------------------------------------
350 ; Chunk "trailer" - sets INITAD
356 .word __SRPREP_LOAD__
358 .endif ; .if .defined(__ATARIXL__)