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__
23 .include "zeropage.inc"
25 .include "save_area.inc"
27 .macro print_string text
30 start: .byte text, ATEOL
31 cont: ldx #0 ; channel 0
45 ; ------------------------------------------------------------------------
51 .word __SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__ - 1
53 ; ------------------------------------------------------------------------
60 print_string "entering stage #2"
63 ; save values of modified system variables and ports
77 lda CIOV ; zero-page wrapper
83 lda SIOV ; zero-page wrapper
96 .include "xlmemchk.inc" ; calculate lowest address used and new value for RAMTOP
108 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
112 .ifdef DEBUG ; only check in debug version, this shouldn't happen normally(tm)
114 print_string "Internal error, no free IOCB!"
118 jsr restore ; restore stuff we've changed
119 jmp (DOSVEC) ; abort loading
123 ; Reopen it in Graphics 0
134 lda #<screen_device_length
136 lda #>screen_device_length
141 ; shouldn't happen(tm)
142 print_string "Internal error, aborting..."
146 jsr restore ; restore stuff we've changed
147 jmp (DOSVEC) ; abort loading
150 scrok: ; now close it again -- we don't need it anymore
156 ; copy chargen to low memory
159 print_string "copy chargen to low memory"
160 print_string "set up high memory"
163 lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
165 lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
169 ; page align the new chargen address
183 lda #>__CHARGEN_SIZE__
185 lda #<__CHARGEN_SIZE__
189 ; TODO: switch to this temp. chargen
194 stx NMIEN ; disable NMI
197 sta PORTB ; now ROM is mapped out
199 ; copy shadow RAM contents to their destination
201 lda #<__SHADOW_RAM_SIZE__
203 lda #>__SHADOW_RAM_SIZE__
204 beq no_copy ; we have no shadow RAM contents
206 ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len
207 do_copy:lda #<__SHADOW_RAM_LOAD__
209 lda #>__SHADOW_RAM_LOAD__
211 lda #<__SHADOW_RAM_RUN__
213 lda #>__SHADOW_RAM_RUN__
215 lda #<__SHADOW_RAM_SIZE__
217 lda #>__SHADOW_RAM_SIZE__
224 ; copy chargen to its new (final) location
230 lda #<__CHARGEN_START__
232 lda #>__CHARGEN_START__
234 lda #>__CHARGEN_SIZE__
236 lda #<__CHARGEN_SIZE__
246 sta NMIEN ; enable VB again
247 cli ; and enable IRQs
250 print_string "Stage #2 OK"
255 .include "findfreeiocb.inc"
257 ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html)
288 ; clean up after a fatal error
290 restore:lda RAMTOP_save
303 .byte "HERE ****************** HERE ***************>>>>>>"
306 .word __SHADOW_RAM_SIZE__
328 screen_device: .byte "S:",0
329 screen_device_length = * - screen_device
331 .byte " ** srprep ** end-->"
333 ; ------------------------------------------------------------------------
334 ; Provide an empty SHADOW_RAM segment in order that the linker is happy
335 ; if the user program doesn't have a SHADOW_RAM segment.
337 .segment "SHADOW_RAM"
340 ; ------------------------------------------------------------------------
341 ; Chunk "trailer" - sets INITAD
347 .word __SRPREP_LOAD__
349 .endif ; .if .defined(__ATARIXL__)