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
17 .import __SRPREP_LOAD__, __SRPREPCHNK_LAST__
18 .import __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__, __SHADOW_RAM_RUN__
19 .import __SHADOW_RAM2_LOAD__, __SHADOW_RAM2_SIZE__, __SHADOW_RAM2_RUN__
20 .import __CHARGEN_START__, __CHARGEN_SIZE__
21 .import __STARTADDRESS__ ; needed by xlmemchk.inc
23 .include "zeropage.inc"
25 .include "save_area.inc"
27 .macro print_string text
30 start: .byte text, ATEOL
31 cont: ldx #0 ; channel 0
45 ; ------------------------------------------------------------------------
46 ; EXE load chunk header
51 .word __SRPREPCHNK_LAST__ - 1
53 ; ------------------------------------------------------------------------
58 ; ***** entry point *****
62 print_string "entering stage #2"
65 ; save values of modified system variables and ports
86 .include "xlmemchk.inc" ; calculate lowest address used and new value for RAMTOP
95 ; set APPMHI to MEMLO (+ 1 for sanity)
105 ; issue a GRAPHICS 0 call (copied'n'pasted from TGI drivers) to move screen memory down
109 .ifdef DEBUG ; only check in debug version, this shouldn't really happen(tm)
111 print_string "Internal error, no free IOCB!"
115 jsr restore ; restore stuff we've changed
116 jmp (DOSVEC) ; abort loading
120 ; reopen it in Graphics 0
131 lda #<screen_device_length
133 lda #>screen_device_length
138 ; shouldn't happen(tm)
139 print_string "Internal error, aborting..."
143 jsr restore ; restore stuff we've changed
144 jmp (DOSVEC) ; abort loading
147 scrok: ; now close it again -- we don't need it anymore
153 ; copy chargen to low memory, just after the next possible address beyond our loaded chunk data
156 print_string "copy chargen to low memory"
159 lda #>__SRPREPCHNK_LAST__
161 lda #<__SRPREPCHNK_LAST__
165 ; page align the new chargen address
176 ; align to next 1K boundary
192 pha ; needed later to set CHBAS/CHBASE
194 lda #>__CHARGEN_SIZE__
196 lda #<__CHARGEN_SIZE__
201 print_string "now setting up high memory"
207 stx NMIEN ; disable NMI
211 pla ; get temp. chargen address
212 sta WSYNC ; wait for horiz. retrace
213 stx PORTB ; now ROM is mapped out
215 ; switch to temporary chargen
220 ; copy shadow RAM contents to their destination (segment SHADOW_RAM)
222 lda #<__SHADOW_RAM_SIZE__
224 lda #>__SHADOW_RAM_SIZE__
225 beq no_copy ; we have no shadow RAM contents
227 ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len
228 do_copy:lda #<__SHADOW_RAM_LOAD__
230 lda #>__SHADOW_RAM_LOAD__
232 lda #<__SHADOW_RAM_RUN__
234 lda #>__SHADOW_RAM_RUN__
236 lda #<__SHADOW_RAM_SIZE__
238 lda #>__SHADOW_RAM_SIZE__
245 ; copy shadow RAM #2 contents to their destination (segment SHADOW_RAM2)
247 lda #<__SHADOW_RAM2_SIZE__
249 lda #>__SHADOW_RAM2_SIZE__
250 beq no_copy2 ; we have no shadow RAM #2 contents
252 ; ptr1 - src; ptr2 - dest; tmp1, tmp2 - len
254 lda #<__SHADOW_RAM2_LOAD__
256 lda #>__SHADOW_RAM2_LOAD__
258 lda #<__SHADOW_RAM2_RUN__
260 lda #>__SHADOW_RAM2_RUN__
262 lda #<__SHADOW_RAM2_SIZE__
264 lda #>__SHADOW_RAM2_SIZE__
271 ; copy chargen to its new (final) location
277 lda #<__CHARGEN_START__
279 lda #>__CHARGEN_START__
281 lda #>__CHARGEN_SIZE__
283 lda #<__CHARGEN_SIZE__
292 sta WSYNC ; wait for horiz. retrace
297 sta NMIEN ; enable VB again
298 cli ; and enable IRQs
301 print_string "Stage #2 OK"
302 print_string "loading main chunk"
307 .include "findfreeiocb.inc"
309 ; routine taken from http://www.obelisk.demon.co.uk/6502/algorithms.html
340 ; clean up after a fatal error
342 restore:lda RAMTOP_save
376 .byte "HERE ****************** HERE ***************>>>>>>"
379 .word __SHADOW_RAM_SIZE__
381 .endif ; .ifdef DEBUG
383 screen_device: .byte "S:",0
384 screen_device_length = * - screen_device
387 .byte " ** srprep ** end-->"
390 ; ------------------------------------------------------------------------
391 ; Provide empty SHADOW_RAM and SHADOW_RAM2 segments in order that the
392 ; linker is happy if the user program doesn't have these segments.
394 .segment "SHADOW_RAM"
395 .segment "SHADOW_RAM2"
398 ; ------------------------------------------------------------------------
399 ; EXE load chunk "trailer" - sets INITAD
407 .endif ; .ifdef __ATARIXL__