/[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 1398 - (show annotations)
Sun Apr 9 18:38:29 2017 UTC (2 years, 5 months ago) by Jede
File size: 6232 byte(s)
Telestrat bug corrected


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 wait_drive2
149 .dsb ((FDC_drq&3)-((*+3)&3))&3,$ea
150 lda FDC_drq ; We are waiting for the drive maybe not useful if drive is ready after the eprom boot
151 bmi wait_drive2
152
153 ;
154 ; Send a SEEK command (change track)
155 ;
156 lda #CMD_Seek
157 .dsb ((FDC_command_register&3)-((*+3)&3))&3,$ea
158 sta FDC_command_register
159 ;
160 ; 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.
161 ; Whenever a command is being executed, the Busy status bit is set.
162 ; When a command is completed, an interrupt is generated and the busy status bit is reset.
163 ; 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).
164 ldy #4
165 r_wait_completion
166 dey
167 bne r_wait_completion
168 r2_wait_completion
169 .dsb ((FDC_status_register&3)-((*+3)&3))&3,$ea
170 lda FDC_status_register
171 lsr
172 bcs r2_wait_completion
173 asl
174
175 track_ok
176
177 ; Write the sector number in the FDC sector register
178 __auto__sector_index
179 lda #FLOPPY_LOADER_SECTOR
180 .dsb ((FDC_sector_register&3)-((*+3)&3))&3,$ea
181 sta FDC_sector_register ;
182
183 lda #%10000100 ; Force the system to use the Side 0 of the A: drive
184 sta FDC_flags
185
186 ;
187 ; Send a READSECTOR command
188 ;
189 lda #CMD_ReadSector
190 .dsb ((FDC_command_register&3)-((*+3)&3))&3,$ea
191 sta FDC_command_register
192
193 ldy #wait_status_floppy
194 waitcommand
195 nop ; Not useful but for old Floppy drive maybe
196 nop ; Not useful but for old Floppy drive maybe
197 dey
198 bne waitcommand
199
200 ;
201 ; Read the sector data
202 ;
203 ldy #0
204 fetch_bytes_from_FDC
205 .dsb ((FDC_drq&3)-((*+3)&3))&3,$ea
206 lda FDC_drq
207 bmi fetch_bytes_from_FDC
208 .dsb ((FDC_data&3)-((*+3)&3))&3,$ea
209 lda FDC_data
210 __auto_write_address
211 sta FLOPPY_LOADER_ADDRESS,y
212
213 iny
214 bne fetch_bytes_from_FDC
215 ; Done loading the sector
216
217 .dsb ((FDC_status_register&3)-((*+3)&3))&3,$ea
218 lda FDC_status_register
219 and #$1C
220
221 beq sector_OK
222 dec retry_counter
223 bne readretryloop
224
225 sector_OK
226 inc __auto__sector_index+1
227 inc __auto_write_address+2
228 dec sector_counter
229 bne read_sectors_loop
230
231 ;
232 ; Data successfully loader (we hope)
233 ;
234 sei
235 lda #%10000001 ; Disable the FDC (Eprom select + FDC Interrupt request)
236 sta FDC_flags
237
238 ldx #0 ; 0 = Microdisc initialisation code
239 jmp FLOPPY_LOADER_ADDRESS
240
241
242 sector_counter .byt (($FFFF-FLOPPY_LOADER_ADDRESS)+1)/256
243
244
245 _END_
246

  ViewVC Help
Powered by ViewVC 1.1.26