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 ; ------------------------------------------------------------------------
60 print_string "in sramprep"
62 ; save values of modified system variables and ports
76 lda CIOV ; zero-page wrapper
82 lda SIOV ; zero-page wrapper
109 ; ... change system memory variables bla
111 CMPVAL = 64+255+992 ; you may ask, why these values... @@@ document
113 sys_ok: lda #<__SAVEAREA_LOAD__
118 lda #>__SAVEAREA_LOAD__
123 lda #>__SAVEAREA_LOAD__ - 1
128 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
131 ldx #$50 ; take any IOCB, hopefully free (@@@ fixme)
133 ; Reopen it in Graphics 0
144 lda #<screen_device_length
146 lda #>screen_device_length
151 print_string "GR 0 FAILED"
156 jmp (DOSVEC) ; abort loading
162 ; Now close it again; we don't need it anymore :)
168 print_string "Stage #2 OK"
173 ; Save the zero page locations we need
181 ; copy chargen to low memory
183 lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
185 lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
189 ; page align the new chargen address
203 lda #>__CHARGEN_SIZE__
205 lda #<__CHARGEN_SIZE__
209 ; TODO: switch to this temp. chargen
214 stx NMIEN ; disable NMI
217 sta PORTB ; now ROM is mapped out
219 ; copy shadow RAM contents to their destination
221 lda #<__SHADOW_RAM_SIZE__
223 lda #>__SHADOW_RAM_SIZE__
224 beq no_copy ; we have no shadow RAM contents
226 ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len
227 do_copy:lda #<__SHADOW_RAM_LOAD__
229 lda #>__SHADOW_RAM_LOAD__
231 lda #<__SHADOW_RAM_RUN__
233 lda #>__SHADOW_RAM_RUN__
235 lda #<__SHADOW_RAM_SIZE__
237 lda #>__SHADOW_RAM_SIZE__
244 ; copy chargen to its new location
250 lda #<__CHARGEN_START__
252 lda #>__CHARGEN_START__
254 lda #>__CHARGEN_SIZE__
256 lda #<__CHARGEN_SIZE__
266 sta NMIEN ; enable VB again
267 cli ; and enable IRQs
272 ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html)
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__)