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 "in sramprep"
64 ; save values of modified system variables and ports
78 lda CIOV ; zero-page wrapper
84 lda SIOV ; zero-page wrapper
111 ; ... change system memory variables bla
113 CMPVAL = 64+255+992 ; you may ask, why these values... @@@ document
115 sys_ok: lda #<__SAVEAREA_LOAD__
120 lda #>__SAVEAREA_LOAD__
125 lda #>__SAVEAREA_LOAD__ - 1
130 ; ... issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers)
133 ldx #$50 ; take any IOCB, hopefully free (@@@ fixme)
135 ; Reopen it in Graphics 0
146 lda #<screen_device_length
148 lda #>screen_device_length
153 print_string "Internal error, aborting..."
158 jmp (DOSVEC) ; abort loading
164 ; Now close it again; we don't need it anymore :)
170 print_string "Stage #2 OK"
175 ; Save the zero page locations we need
183 ; copy chargen to low 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 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
274 ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html)
305 .byte "HERE ****************** HERE ***************>>>>>>"
308 .word __SHADOW_RAM_SIZE__
330 screen_device: .byte "S:",0
331 screen_device_length = * - screen_device
333 .byte " ** srprep ** end-->"
335 ; ------------------------------------------------------------------------
336 ; Provide an empty SHADOW_RAM segment in order that the linker is happy
337 ; if the user program doesn't have a SHADOW_RAM segment.
339 .segment "SHADOW_RAM"
342 ; ------------------------------------------------------------------------
343 ; Chunk "trailer" - sets INITAD
349 .word __SRPREP_LOAD__
351 .endif ; .if .defined(__ATARIXL__)