/[projet1]/public/oric/demos/SlideShowDemo/code/loader.asm
Defence Force logotype

Contents of /public/oric/demos/SlideShowDemo/code/loader.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1015 - (show annotations)
Thu Dec 12 20:53:08 2013 UTC (5 years, 11 months ago) by dbug
File size: 7014 byte(s)
Archived the latest version of the loader code.
It's still pretty much work in progress, but it would suck that my hard drive dies :p
1
2 #include "disk_info.h"
3
4 #define COLOR(color) pha:lda #16+(color&7):sta $bb80+40*27:pla
5 #define STOP(color) pha:lda #16+(color&7):sta $bb80+40*27:jmp *:pla
6 #define INSTALL_HANDLER(address,callback) lda #$4c:sta address:lda #<callback:sta address+1:lda #>callback:sta address+2 ; jmp=$4c
7
8 .zero
9
10 *=$00
11
12 retry_counter .dsb 1 ; Number of attempts at loading data (ie: not quite clear what happens when this fails...)
13 sectors_to_go .dsb 1 ; How many sectors do we still need to load for this file
14 current_track .dsb 1 ; Index of the track being loaded
15 current_sector .dsb 1 ; Index of the sector being loaded
16 current_side .dsb 1 ; Has the bit 4 set to 0 or 1 to be used as a mask on the Microdisc control register (other bits have to be set to zero)
17 irq_save_a .dsb 1 ; To preserve the accumulator value in the IRQ code
18
19 .text
20
21 ; FFF7-FFF9 - Load File (JMP/LOW/HIGH) - file to load in X register
22 ; FFFA-FFFB - NMI Vector (Usually points to $0247)
23 ; FFFC-FFFD - RESET Vector (Usually points to $F88F)
24 ; FFFE-FFFF - IRQ Vector (Normally points to $0244)
25 ;
26
27 *=location_loader
28
29
30 Initialize
31 jmp StartUp
32
33 ; This file is generated by the floppy builder
34 #include "floppy_description.h"
35
36 ; Some local variables we need
37
38 StartUp
39 ; Set-up a safe irq that does nothing (just contains a RTI instruction)
40 ; This helps avoiding crashes if the user presses RESET for example :)
41 lda #<IrqDoNothing ; NMI vector
42 sta $fffa
43 sta $fffc
44 lda #>IrqDoNothing ; RESET vector
45 sta $fffb
46 sta $fffd
47
48 ; Install our API (top of memory function calls)
49 INSTALL_HANDLER($FFF7,LoadData)
50
51 jsr SetUpIrqHandlers
52 jsr SoftHiresWithCopyCharset
53
54
55 ;ldx #LOADER_FIRST_PICTURE
56 ;jsr LoadData
57 ;STOP(1)
58
59 ; Load the slideshow
60 ldx #LOADER_SLIDESHOW
61 jsr LoadData
62
63 ;STOP(1)
64 jsr ExecuteData
65
66 ;
67 ; End of demo - Just stay there doing nothing
68 ;
69 sei
70 .(
71 loop
72 jmp loop
73 .)
74
75
76 ClearZeroPage
77 .(
78 lda #0
79 tax
80 loop
81 sta $00,x
82 dex
83 bne loop
84 rts
85 .)
86
87
88 SetUpIrqHandlers
89 sei
90
91 ldy #<IrqHandler
92 lda #>IrqHandler
93 sty $fffe
94 sta $ffff
95
96 ; Make sure the microdisc IRQ is disabled
97 jsr WaitCompletion
98
99 ;lda #%10000100 ; Disable the FDC (Eprom select + FDC Interrupt request)
100 ;sta MICRODISC
101
102 ;jsr WaitCompletion
103
104 rts
105
106 IrqHandler
107 sta irq_save_a
108 pla
109 and #%00010000 ; Check the saved B flag to detect a BRK
110 bne from_brk
111
112 from_irq
113 bit $304
114
115 lda $bfdf
116 eor #1
117 ora #16
118 sta $bfdf
119
120 lda irq_save_a
121 pha
122 IrqDoNothing
123 rti
124
125 from_brk
126 lda #16+1
127 sta $bb80+40*27
128 nop
129 nop
130 nop
131 lda #16+2
132 sta $bb80+40*27
133 jmp from_brk
134
135
136
137 HexData .byt "0123456789ABCDEF"
138
139
140 ; X=File index
141 LoadData
142 sei
143
144 ; Make sure the microdisc IRQ is disabled
145 jsr WaitCompletion
146
147 lda #%10000100 ; Disable the FDC (Eprom select + FDC Interrupt request)
148 sta MICRODISC
149
150 ;jsr WaitCompletion
151
152 ;
153 ; Setup, we use the table to find out where the file is located on the floppy,
154 ; where to write it in memory, and how large it is.
155 ;
156 lda FileLoadAdressHigh,x
157 sta __auto_execute_address+2
158 sta __auto_write_address+2
159
160 lda FileLoadAdressLow,x
161 sta __auto_execute_address+1
162 sta __auto_write_address+1
163
164 ; Starting track
165 ldy #%00000000 ; Side 0
166 lda FileStartTrack,x ; If the track id is larger than 128, it means it is on the other side of the floppy
167 bpl first_side
168 ; The file starts on the second side
169 ldy #%00010000 ; Side 1
170 and #%01111111 ; Mask out the extra bit
171 first_side
172 sty current_side
173 sta current_track
174
175 ; First sector
176 lda FileStartSector,x
177 sta current_sector
178
179 ; Number of sectors to load
180 lda FileSectorCount,x
181 sta sectors_to_go
182
183 ;
184 ; Loop to read all the sectors
185 ;
186 read_sectors_loop
187
188 ; Check if we have reached the end of the track
189 lda current_sector
190 cmp #FLOPPY_SECTOR_PER_TRACK+1
191 bne same_track
192
193 ; Next track
194 inc current_track
195 lda current_track
196 cmp #FLOPPY_TRACK_NUMBER
197 bne stay_on_same_side
198
199 ; Reset to the first track on the other side
200 lda #0
201 sta current_track
202
203 lda #%00010000
204 sta current_side
205 stay_on_same_side
206
207 ; Reset the sector position
208 lda #1
209 sta current_sector
210 same_track
211
212 #ifdef LOADER_SHOW_DEBUGINFO
213 ; Display debug info
214 jsr DisplayPosition
215 #endif
216
217 lda current_sector
218 sta FDC_sector_register
219 inc current_sector
220
221 ; Check if the drive is on the correct track
222 lda current_track
223 cmp FDC_track_register
224 beq stay_on_the_track
225
226 ; Set the new track
227 sta FDC_data
228
229 lda #CMD_Seek
230 sta FDC_command_register
231 jsr WaitCompletion
232
233 lda #%10000100 ; on force les le Microdisk en side0, drive A ... Set le bit de données !!!
234 ora current_side
235 sta MICRODISC
236
237 stay_on_the_track
238 lda #CMD_ReadSector
239 sta FDC_command_register
240
241
242 ldy #wait_status_floppy
243 waitcommand
244 nop
245 nop
246 dey
247 bne waitcommand
248
249 ;
250 ; Read the sector data
251 ;
252 ldy #0
253 microdisc_read_data
254 lda $0318
255 bmi microdisc_read_data
256
257 lda $313
258 __auto_write_address
259 sta $c000,y
260 iny
261
262 bne microdisc_read_data
263
264 lda FDC_status_register
265 and #$1C
266
267 ; Try to let time to an IRQ to play
268 cli
269 nop
270 nop
271 sei
272
273 ; Next sector
274 inc __auto_write_address+2
275 dec sectors_to_go
276 bne read_sectors_loop
277
278 ; Data successfully loaded (we hope), so we restore the interrupts
279 cli
280 rts
281
282 ExecuteData
283 jsr SetUpIrqHandlers
284 jsr ClearZeroPage
285 __auto_execute_address
286 jsr $a000
287 jsr SetUpIrqHandlers
288 rts
289
290
291 WaitCompletion
292 ldy #4
293 r_wait_completion
294 dey
295 bne r_wait_completion
296 r2_wait_completion
297 lda FDC_status_register
298 lsr
299 bcs r2_wait_completion
300 asl
301 rts
302
303 #ifdef LOADER_SHOW_DEBUGINFO
304 DisplayPosition
305 .(
306 lda current_side
307 lsr
308 lsr
309 lsr
310 lsr
311 tax
312 lda HexData,x
313 sta $bb80+40*27+0
314
315 lda #3
316 sta $bb80+40*27+1
317
318 lda current_track
319 lsr
320 lsr
321 lsr
322 lsr
323 tax
324 lda HexData,x
325 sta $bb80+40*27+2
326
327 lda current_track
328 and #15
329 tax
330 lda HexData,x
331 sta $bb80+40*27+3
332
333 lda #2
334 sta $bb80+40*27+4
335
336 lda current_sector
337 lsr
338 lsr
339 lsr
340 lsr
341 tax
342 lda HexData,x
343 sta $bb80+40*27+5
344
345 lda current_sector
346 and #15
347 tax
348 lda HexData,x
349 sta $bb80+40*27+6
350
351 ;jsr WaitLoop
352 rts
353 .)
354 #endif
355
356
357 SoftHiresWithCopyCharset
358 ldy #$00 ;copy charset
359 .(
360 copy_charset_loop
361 lda $b500,y
362 sta $9900,y
363 lda $b600,y
364 sta $9a00,y
365 lda $b700,y
366 sta $9b00,y
367 lda $b900,y
368 sta $9d00,y
369 lda $ba00,y
370 sta $9e00,y
371 lda $bb00,y
372 sta $9f00,y
373 dey
374 bne copy_charset_loop
375 .)
376 SoftHires
377 lda #$a0 ;clear down all memory area with zero
378 sta $01
379 lda #$00
380 sta $00 ; a = 0 from here
381 ldx #$20
382 hm_01
383 sta ($00),y
384 iny
385 bne hm_01
386 inc $01
387 dex
388 bne hm_01
389 lda #30 ;write hires switch
390 sta $bf40
391 lda #$a0 ;clear hires with #$40
392 sta $01
393 ldx #$20
394 ldx #64
395 hm_04
396 ldy #124
397 hm_05
398 lda #$40
399 sta ($00),y
400 dey
401 bpl hm_05
402 lda $00
403 adc #125
404 sta $00
405 bcc hm_02
406 inc $01
407 hm_02
408 dex
409 bne hm_04
410 rts
411
412

  ViewVC Help
Powered by ViewVC 1.1.26