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

  ViewVC Help
Powered by ViewVC 1.1.26