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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26