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
12 .if .defined(__ATARIXL__)
15 .import __SRPREP_LOAD__, __SRPREP_SIZE__
16 .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__
17 .import __SHADOW_RAM_RUN__
18 .import __CHARGEN_START__, __CHARGEN_SIZE__
19 .import __SAVEAREA_LOAD__
22 .include "zeropage.inc"
24 .include "save_area.inc"
26 .macro print_string text
29 start: .byte text, ATEOL
30 cont: ldx #0 ; channel 0
44 ; ------------------------------------------------------------------------
50 .word __SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__ - 1
52 ; ------------------------------------------------------------------------
58 print_string "in sramprep"
60 ; save values of modified system variables and ports
74 lda CIOV ; zero-page wrapper
80 lda SIOV ; zero-page wrapper
107 ; ... change system memory variables bla
109 CMPVAL = 64+255+992 ; you may ask, why these values... @@@ document
111 sys_ok: lda #<__SAVEAREA_LOAD__
116 lda #>__SAVEAREA_LOAD__
121 lda #>__SAVEAREA_LOAD__ - 1
126 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
129 ldx #$50 ; take any IOCB, hopefully free (@@@ fixme)
131 ; Reopen it in Graphics 0
142 lda #<screen_device_length
144 lda #>screen_device_length
149 print_string "GR 0 FAILED"
154 jmp (DOSVEC) ; abort loading
160 ; Now close it again; we don't need it anymore :)
165 print_string "GR 0 OKOKO"
169 ; Save the zero page locations we need
177 ; copy chargen to low memory
179 lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
181 lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
185 ; page align the new chargen address
199 lda #>__CHARGEN_SIZE__
201 lda #<__CHARGEN_SIZE__
205 ; TODO: switch to this temp. chargen
210 stx NMIEN ; disable NMI
213 sta PORTB ; now ROM is mapped out
215 ; copy shadow RAM contents to their destination
217 lda #<__SHADOW_RAM_SIZE__
219 lda #>__SHADOW_RAM_SIZE__
220 beq no_copy ; we have no shadow RAM contents
222 ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len
223 do_copy:lda #<__SHADOW_RAM_LOAD__
225 lda #>__SHADOW_RAM_LOAD__
227 lda #<__SHADOW_RAM_RUN__
229 lda #>__SHADOW_RAM_RUN__
231 lda #<__SHADOW_RAM_SIZE__
233 lda #>__SHADOW_RAM_SIZE__
240 ; copy chargen to its new location
246 lda #<__CHARGEN_START__
248 lda #>__CHARGEN_START__
250 lda #>__CHARGEN_SIZE__
252 lda #<__CHARGEN_SIZE__
262 sta NMIEN ; enable VB again
263 cli ; and enable IRQs
268 ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html)
299 .byte "HERE ****************** HERE ***************>>>>>>"
302 .word __SHADOW_RAM_SIZE__
324 screen_device: .byte "S:",0
325 screen_device_length = * - screen_device
327 .byte " ** srprep ** end-->"
329 ; ------------------------------------------------------------------------
330 ; Provide an empty SHADOW_RAM segment in order that the linker is happy
331 ; if the user program doesn't have a SHADOW_RAM segment.
333 .segment "SHADOW_RAM"
336 ; ------------------------------------------------------------------------
337 ; Chunk "trailer" - sets INITAD
343 .word __SRPREP_LOAD__
345 .endif ; .if .defined(__ATARIXL__)