]> git.sur5r.net Git - cc65/blob - libsrc/atari/shadow_ram_prepare.s
Code & data for "shadow RAM preparation" load chunk in the atarixl target.
[cc65] / libsrc / atari / shadow_ram_prepare.s
1 ;
2 ; Atari XL shadow RAM preparation routines
3 ;
4 ; Tasks:
5 ; - move screen memory below load address
6 ; - copy shadow RAM contents to their destination
7 ;
8 ; Christian Groessler, chris@groessler.org, 2013
9 ;
10
11 .if .defined(__ATARIXL__)
12
13         .export         sramprep
14         .import         __SRPREP_LOAD__, __SRPREP_SIZE__
15         .import         __SHADOW_RAM_LOAD__, __SHADOW_RAM_SIZE__
16         .import         __CHARGEN_LOAD__, __CHARGEN_SIZE__
17         .import         __SAVEAREA_LOAD__
18
19         .include        "zeropage.inc"
20         .include        "atari.inc"
21         .include        "save_area.inc"
22
23 .macro print_string text
24         .local  start, cont
25         jmp     cont
26 start:  .byte   text, ATEOL
27 cont:   ldx     #0              ; channel 0
28         lda     #<start
29         sta     ICBAL,x         ; address
30         lda     #>start
31         sta     ICBAH,x
32         lda     #<(cont - start)
33         sta     ICBLL,x         ; length
34         lda     #>(cont - start)
35         sta     ICBLH,x
36         lda     #PUTCHR
37         sta     ICCOM,x
38         jsr     CIOV
39 .endmacro
40
41 ; ------------------------------------------------------------------------
42 ; Chunk header
43
44 .segment        "SRPREPHDR"
45
46         .word   __SRPREP_LOAD__
47         .word   __SRPREP_LOAD__ + __SRPREP_SIZE__ - 1
48
49 ; ------------------------------------------------------------------------
50 ; Actual code
51
52 .segment        "SRPREP"
53
54 sramprep:
55         print_string "in sramprep"
56
57 ; save values of modified system variables and ports
58         lda     RAMTOP
59         sta     RAMTOP_save
60         lda     MEMTOP
61         sta     MEMTOP_save
62         lda     MEMTOP+1
63         sta     MEMTOP_save+1
64         lda     APPMHI
65         sta     APPMHI_save
66         lda     APPMHI+1
67         sta     APPMHI_save+1
68         lda     PORTB
69         sta     PORTB_save
70
71 ; disable BASIC
72
73         lda     PORTB
74         ora     #2
75         sta     PORTB
76
77
78 ; ... change memory bla
79
80 CMPVAL = 64+255+992             ; you may ask, why these values...   @@@ document
81
82 sys_ok: lda     #<__SAVEAREA_LOAD__
83         sec
84         sbc     #<CMPVAL
85         sta     MEMTOP
86         sta     APPMHI
87         lda     #>__SAVEAREA_LOAD__
88         sbc     #>CMPVAL
89         sta     MEMTOP+1
90         sta     APPMHI+1
91
92         lda     #>__SAVEAREA_LOAD__ - 1
93         sta     RAMTOP
94         
95         
96
97 ; ... issue ar GRAPHICS 0 call (copied'n'pasted from TGI drivers)
98
99
100         ldx     #$50            ; take any IOCB, hopefully free (@@@ fixme)
101
102         ; Reopen it in Graphics 0
103         lda     #OPEN
104         sta     ICCOM,x
105         lda     #OPNIN | OPNOT
106         sta     ICAX1,x
107         lda     #0
108         sta     ICAX2,x
109         lda     #<screen_device
110         sta     ICBAL,x
111         lda     #>screen_device
112         sta     ICBAH,x
113         lda     #<screen_device_length
114         sta     ICBLL,x
115         lda     #>screen_device_length
116         sta     ICBLH,x
117         jsr     CIOV
118         bpl     okoko
119
120         print_string "GR 0 FAILED"
121         jsr     delay
122         jsr     delay
123         jsr     delay
124
125         jmp xxx
126
127 okoko:
128
129
130         ; Now close it again; we don't need it anymore :)
131         lda     #CLOSE
132         sta     ICCOM,x
133         jsr     CIOV
134
135         print_string "GR 0 OKOKO"
136         jsr     delay
137
138
139
140
141
142
143 xxx:
144
145
146
147
148
149         rts
150
151 ; short delay
152 .proc   delay
153
154         lda     #10
155 l:      jsr     delay1
156         clc
157         sbc     #0
158         bne     l
159         rts
160
161 delay1: ldx     #0
162         ldy     #0
163 loop:   dey
164         bne     loop
165         dex
166         bne     loop
167         rts
168
169 .endproc
170
171 screen_device:  .byte "S:",0
172 screen_device_length = * - screen_device
173
174         .byte   " ** srprep ** end-->"
175
176 ; ------------------------------------------------------------------------
177 ; Chunk "trailer" - sets INITAD
178
179 .segment        "SRPREPTRL"
180
181         .word   INITAD
182         .word   INITAD+1
183         .word   __SRPREP_LOAD__
184
185 .endif  ; .if .defined(__ATARIXL__)