/[projet1]/public/oric/demos/OricTech/code/sector_2-microdisc.asm
Defence Force logotype

Contents of /public/oric/demos/OricTech/code/sector_2-microdisc.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1404 - (show annotations)
Thu Apr 20 05:41:39 2017 UTC (2 years, 11 months ago) by Jede
File size: 6238 byte(s)
Correcting data register. The fdc bug is not in this register



1 ;
2 ; This part of the code is a bit tricky: Basically the Atmos with Microdisc and the Telestrat despite using a similar boot
3 ; loading system are actually loading the boot sector at different addresses.
4 ;
5 ; Since the 6502 is not particularly well equiped to handle code that can be loaded at any address we had to find a trick.
6 ; What we are doing is to make the code run at a particular address, and have a small module that makes sure that it is
7 ; moved at the correct place wherever it was loaded in first place. That makes the code a lot easier to write :)
8 ;
9 ; Warning: This whole code CANNOT be more than 256 bytes (ie: the size of the sector)
10 ;
11 ; The bootloader will be placed in the screen area because we know that this is not going to be used by the operating system.
12 ; By chosing an address in HIRES area, we also guarantee that it will not be visible on the screen (the Oric boots in TEXT).
13 ;
14 #define FINAL_ADRESS $9800 ; First 256 bytes of the STD charset are invisible
15
16
17 #define OPCODE_RTS $60
18
19 #define FDC_command_register $0310
20 #define FDC_status_register $0310
21 #define FDC_track_register $0311
22 #define FDC_sector_register $0312
23 #define FDC_data $0313
24 #define FDC_flags $0314
25 #define FDC_drq $0318
26
27 #define FDC_Flag_DiscSide %00010000
28
29 #define CMD_ReadSector $80
30 #define CMD_Seek $1F
31
32 #define wait_status_floppy 30
33
34 #include "floppy_description.h" ; This file is generated by the floppy builder
35
36 .zero
37
38 *=$00
39
40 retry_counter .dsb 1 ; Number of attempts at loading data (ie: not quite clear what happens when this fails...)
41
42
43 .text
44
45 ;
46 ; These are the 23 header bytes that goes before the actual executable part of the bootsector
47 ;
48 .byt $00,$00,$FF,$00,$D0,$9F,$D0,$9F,$02,$B9,$01,$00,$FF,$00,$00,$B9,$E4,$B9,$00,$00,$E6,$12,$00
49
50 .text
51
52 ;
53 ; Here starts the actual executable part, maximum available size is 233 bytes (256-23)
54 ;
55
56 ;
57 ; Try to find the load address
58 ;
59 sei ; Disable interruptions
60
61 lda #OPCODE_RTS
62 sta $00 ; Write in $00 Page => take one less byte
63 jsr $0000 ; JSR on the RTS immediately return.
64
65 ;
66 ; Compute the absolute address of where the code we want to copy begins,
67 ; and save it in zero page ($00 and $01)
68 ;
69 _start_relocator_
70 tsx ; Get stack offset
71 dex
72 clc
73 lda $0100,x ; Get LOW adress byte
74 adc #<(_end_relocator_-_start_relocator_+1)
75 sta $00
76 lda $0101,x ; Get HIGH adress byte
77 adc #>(_end_relocator_-_start_relocator_+1)
78 sta $01
79
80 ; Now $00 and $01 contain the adress of LABEL
81 ; We can now copy the whole code to it's new
82 ; location
83 ldy #0
84 copy_loop
85 lda ($00),y
86 sta FINAL_ADRESS,y
87 iny
88 cpy #(_END_-_BEGIN_)
89 bne copy_loop
90
91 jmp FINAL_ADRESS
92 _end_relocator_
93
94
95 ;
96 ; Here is some code compiled at a fixed adress in memory.
97 ;
98
99 *=FINAL_ADRESS
100
101 _BEGIN_
102 ;
103 ; Switch to HIRES
104 ;
105 ldy #39 ; From $9900 to $c000 is 39 pages (9984 bytes)
106 lda #0
107 loop_hires_outer
108 tax
109 loop_hires_inner
110 __auto_hires
111 sta $9900,x
112 inx
113 bne loop_hires_inner
114 inc __auto_hires+2
115 dey
116 bne loop_hires_outer
117
118 lda #30 ; Write hires switch
119 sta $bfdf
120
121
122 ;
123 ; Read sector data
124 ;
125 ldy #4
126 sty retry_counter
127 read_sectors_loop
128
129 readretryloop
130 nop
131 nop
132 nop
133
134 read_one_sector
135 ;
136 ; Check if we are on the correct track already and if not
137 ; then send a SEEK command to the FDC to move the head to
138 ; the correct track.
139 ;
140 ldx #FLOPPY_LOADER_TRACK
141 .dsb ((FDC_track_register&3)-((*+3)&3))&3,$ea
142 cpx FDC_track_register
143 beq track_ok
144
145 ; Write the track number in the FDC data register
146 stx FDC_data
147
148
149 .dsb ((FDC_drq&3)-((*+3)&3))&3,$ea
150 wait_drive2
151 lda FDC_drq ; We are waiting for the drive maybe not useful if drive is ready after the eprom boot
152 bmi wait_drive2
153
154 ;
155 ; Send a SEEK command (change track)
156 ;
157 lda #CMD_Seek
158 .dsb ((FDC_command_register&3)-((*+3)&3))&3,$ea
159 sta FDC_command_register
160 ;
161 ; Command words should only be loaded in the Command Register when the Busy status bit is off (Status bit 0). The one exception is the Force Interrupt command.
162 ; Whenever a command is being executed, the Busy status bit is set.
163 ; When a command is completed, an interrupt is generated and the busy status bit is reset.
164 ; The Status Register indicates whethter the completed command encountered an error or was fault free. For ease of discussion, commands are divided into four types (I, II, III, IV).
165 ldy #4
166 r_wait_completion
167 dey
168 bne r_wait_completion
169 r2_wait_completion
170 .dsb ((FDC_status_register&3)-((*+3)&3))&3,$ea
171 lda FDC_status_register
172 lsr
173 bcs r2_wait_completion
174 asl
175
176 track_ok
177
178 ; Write the sector number in the FDC sector register
179 __auto__sector_index
180 lda #FLOPPY_LOADER_SECTOR
181 .dsb ((FDC_sector_register&3)-((*+3)&3))&3,$ea
182 sta FDC_sector_register ;
183
184 lda #%10000100 ; Force the system to use the Side 0 of the A: drive
185 sta FDC_flags
186
187 ;
188 ; Send a READSECTOR command
189 ;
190 lda #CMD_ReadSector
191 .dsb ((FDC_command_register&3)-((*+3)&3))&3,$ea
192 sta FDC_command_register
193
194 ldy #wait_status_floppy
195 waitcommand
196 nop ; Not useful but for old Floppy drive maybe
197 nop ; Not useful but for old Floppy drive maybe
198 dey
199 bne waitcommand
200
201 ;
202 ; Read the sector data
203 ;
204 ldy #0
205 .dsb ((FDC_drq&3)-((*+3)&3))&3,$ea
206 fetch_bytes_from_FDC
207 lda FDC_drq
208 bmi fetch_bytes_from_FDC
209 ;.dsb ((FDC_data&3)-((*+3)&3))&3,$ea
210 lda FDC_data
211 __auto_write_address
212 sta FLOPPY_LOADER_ADDRESS,y
213
214 iny
215 bne fetch_bytes_from_FDC
216 ; Done loading the sector
217
218 .dsb ((FDC_status_register&3)-((*+3)&3))&3,$ea
219 lda FDC_status_register
220 and #$1C
221
222 beq sector_OK
223 dec retry_counter
224 bne readretryloop
225
226 sector_OK
227 inc __auto__sector_index+1
228 inc __auto_write_address+2
229 dec sector_counter
230 bne read_sectors_loop
231
232 ;
233 ; Data successfully loader (we hope)
234 ;
235 sei
236 lda #%10000001 ; Disable the FDC (Eprom select + FDC Interrupt request)
237 sta FDC_flags
238
239 ldx #0 ; 0 = Microdisc initialisation code
240 jmp FLOPPY_LOADER_ADDRESS
241
242
243 sector_counter .byt (($FFFF-FLOPPY_LOADER_ADDRESS)+1)/256
244
245
246 _END_
247

  ViewVC Help
Powered by ViewVC 1.1.26