/[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 1025 - (show annotations)
Sun Dec 15 11:47:51 2013 UTC (5 years, 11 months ago) by dbug
File size: 7519 byte(s)
FloppyBuilder 0.8 and SlideShow project
- Exports the file size now instead of sector count
- Exported file format contains the number of sides of the floppy
- The loader was moved to sector 4 and slideshow to sector 1 

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

  ViewVC Help
Powered by ViewVC 1.1.26