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
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)
125 ldx #$50 ; take any IOCB, hopefully free (@@@ fixme)
127 ; Reopen it in Graphics 0
138 lda #<screen_device_length
140 lda #>screen_device_length
145 print_string "Internal error, aborting..."
150 jmp (DOSVEC) ; abort loading
156 ; Now close it again; we don't need it anymore :)
162 print_string "Stage #2 OK"
167 ; Save the zero page locations we need
175 ; copy chargen to low memory
177 lda #>(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
179 lda #<(__SRPREP_LOAD__ + __SRPREP_SIZE__ + __SHADOW_RAM_SIZE__)
183 ; page align the new chargen address
197 lda #>__CHARGEN_SIZE__
199 lda #<__CHARGEN_SIZE__
203 ; TODO: switch to this temp. chargen
208 stx NMIEN ; disable NMI
211 sta PORTB ; now ROM is mapped out
213 ; copy shadow RAM contents to their destination
215 lda #<__SHADOW_RAM_SIZE__
217 lda #>__SHADOW_RAM_SIZE__
218 beq no_copy ; we have no shadow RAM contents
220 ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len
221 do_copy:lda #<__SHADOW_RAM_LOAD__
223 lda #>__SHADOW_RAM_LOAD__
225 lda #<__SHADOW_RAM_RUN__
227 lda #>__SHADOW_RAM_RUN__
229 lda #<__SHADOW_RAM_SIZE__
231 lda #>__SHADOW_RAM_SIZE__
238 ; copy chargen to its new location
244 lda #<__CHARGEN_START__
246 lda #>__CHARGEN_START__
248 lda #>__CHARGEN_SIZE__
250 lda #<__CHARGEN_SIZE__
260 sta NMIEN ; enable VB again
261 cli ; and enable IRQs
266 ; my 6502 fu is rusty, so I took a routine from the internet (http://www.obelisk.demon.co.uk/6502/algorithms.html)
297 .byte "HERE ****************** HERE ***************>>>>>>"
300 .word __SHADOW_RAM_SIZE__
322 screen_device: .byte "S:",0
323 screen_device_length = * - screen_device
325 .byte " ** srprep ** end-->"
327 ; ------------------------------------------------------------------------
328 ; Provide an empty SHADOW_RAM segment in order that the linker is happy
329 ; if the user program doesn't have a SHADOW_RAM segment.
331 .segment "SHADOW_RAM"
334 ; ------------------------------------------------------------------------
335 ; Chunk "trailer" - sets INITAD
341 .word __SRPREP_LOAD__
343 .endif ; .if .defined(__ATARIXL__)