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
110 .include "xlmemchk.inc" ; calculate lowest address used and new value for RAMTOP
122 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
126 .ifdef DEBUG ; only check in debug version, this shouldn't happen normally(tm)
128 print_string "Internal error, no free IOCB!"
132 jsr restore ; restore stuff we've changed
133 jmp (DOSVEC) ; abort loading
137 ; Reopen it in Graphics 0
148 lda #<screen_device_length
150 lda #>screen_device_length
155 ; shouldn't happen(tm)
156 print_string "Internal error, aborting..."
160 jsr restore ; restore stuff we've changed
161 jmp (DOSVEC) ; abort loading
164 scrok: ; now close it again -- we don't need it anymore
170 ; Save the zero page locations we need
178 ; copy chargen to low memory
181 print_string "copy chargen to low memory"
182 print_string "set up high memory"
185 lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
187 lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
191 ; page align the new chargen address
205 lda #>__CHARGEN_SIZE__
207 lda #<__CHARGEN_SIZE__
211 ; TODO: switch to this temp. chargen
216 stx NMIEN ; disable NMI
219 sta PORTB ; now ROM is mapped out
221 ; copy shadow RAM contents to their destination
223 lda #<__SHADOW_RAM_SIZE__
225 lda #>__SHADOW_RAM_SIZE__
226 beq no_copy ; we have no shadow RAM contents
228 ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len
229 do_copy:lda #<__SHADOW_RAM_LOAD__
231 lda #>__SHADOW_RAM_LOAD__
233 lda #<__SHADOW_RAM_RUN__
235 lda #>__SHADOW_RAM_RUN__
237 lda #<__SHADOW_RAM_SIZE__
239 lda #>__SHADOW_RAM_SIZE__
246 ; copy chargen to its new (final) location
252 lda #<__CHARGEN_START__
254 lda #>__CHARGEN_START__
256 lda #>__CHARGEN_SIZE__
258 lda #<__CHARGEN_SIZE__
268 sta NMIEN ; enable VB again
269 cli ; and enable IRQs
272 print_string "Stage #2 OK"
277 .include "findfreeiocb.inc"
279 ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html)
310 ; clean up after a fatal error
312 restore:lda RAMTOP_save
325 .byte "HERE ****************** HERE ***************>>>>>>"
328 .word __SHADOW_RAM_SIZE__
350 screen_device: .byte "S:",0
351 screen_device_length = * - screen_device
353 .byte " ** srprep ** end-->"
355 ; ------------------------------------------------------------------------
356 ; Provide an empty SHADOW_RAM segment in order that the linker is happy
357 ; if the user program doesn't have a SHADOW_RAM segment.
359 .segment "SHADOW_RAM"
362 ; ------------------------------------------------------------------------
363 ; Chunk "trailer" - sets INITAD
369 .word __SRPREP_LOAD__
371 .endif ; .if .defined(__ATARIXL__)