/[projet1]/public/oric/demos/SlideShowDemo/code/sector_1-jasmin.asm
Defence Force logotype

Contents of /public/oric/demos/SlideShowDemo/code/sector_1-jasmin.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1047 - (show annotations)
Sun Dec 22 11:02:56 2013 UTC (6 years, 2 months ago) by dbug
File size: 9180 byte(s)
More Jasmin/Microdisc compatibility work.
Kudos to Fabrice for cracking that one in Fantasmagoric, it's not easy to factorize.
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 $a000+50*40
15
16
17 #define OPCODE_RTS $60
18
19 #define JASMIN_LOADER
20 #include "disk_info.h"
21
22 .zero
23
24 *=$00
25
26 retry_counter .dsb 1 ; Number of attempts at loading data (ie: not quite clear what happens when this fails...)
27
28 .text
29
30 *=$400
31 jmp $440 ;.byt $01,$00,$00
32 .byt $00,$00,$00,$00,$00,$20,$20,$20,$20,$20,$20,$20,$20
33 .byt $00,$00,$03,$00,$00,$00,$01,$00,$53,$45,$44,$4F,$52,$49,$43,$20
34 .byt $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
35 .byt $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20
36
37 JasminStart
38 ;jmp JasminStart
39 ;
40 ; Here starts the actual executable part, maximum available size is 233 bytes (256-23)
41 ;
42
43 ;
44 ; Try to find the load address
45 ;
46 sei ; Disable interruptions
47
48 ; Enable Overlay ram
49 lda #1
50 sta $03FA ; Enable Overlay
51 lda #1
52 sta $03FB ; Disable ROM
53
54 ;
55 ; Read sector data
56 ;
57 ldy #4
58 sty retry_counter
59 read_sectors_loop
60
61 readretryloop
62 nop
63 nop
64 nop
65
66 read_one_sector
67 ;
68 ; Check if we are on the correct track already and if not
69 ; then send a SEEK command to the FDC to move the head to
70 ; the correct track.
71 ;
72 ldx #loader_track_position
73 cpx FDC_track_register
74 beq track_ok
75
76 ; Write the track number in the FDC data register
77 stx FDC_data
78
79 wait_drive2
80 lda FDC_drq ; We are waiting for the drive maybe not useful if drive is ready after the eprom boot
81 bmi wait_drive2
82
83 ;
84 ; Send a SEEK command (change track)
85 ;
86 lda #CMD_Seek
87 sta FDC_command_register
88 ;
89 ; 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.
90 ; Whenever a command is being executed, the Busy status bit is set.
91 ; When a command is completed, an interrupt is generated and the busy status bit is reset.
92 ; 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).
93 ldy #4
94 r_wait_completion
95 dey
96 bne r_wait_completion
97 r2_wait_completion
98 lda FDC_status_register
99 lsr
100 bcs r2_wait_completion
101 asl
102
103 track_ok
104
105 ; Write the sector number in the FDC sector register
106 __auto__sector_index
107 lda #loader_sector_position
108 sta FDC_sector_register ;
109
110 ; Interdire les IRQ du fdc ICI !
111 ;lda #%10000100 ; on force les le Microdisk en side0, drive A ... Set le bit de données !!!
112 ;sta FDC_flags
113
114 ;
115 ; Send a READSECTOR command
116 ;
117 lda #CMD_ReadSector
118 sta FDC_command_register
119
120 ldy #wait_status_floppy
121 waitcommand
122 nop ; Not useful but for old Floppy drive maybe
123 nop ; Not useful but for old Floppy drive maybe
124 dey
125 bne waitcommand
126
127 ;
128 ; Read the sector data
129 ;
130 ldy #0
131 fetch_bytes_from_FDC
132 lda FDC_drq
133 bmi fetch_bytes_from_FDC
134 lda FDC_data
135 __auto_write_address
136 sta location_loader,y
137
138 iny
139 bne fetch_bytes_from_FDC
140 ; Done loading the sector
141
142 lda FDC_status_register
143 and #$1C
144
145 beq sector_OK
146 dec retry_counter
147 bne readretryloop
148
149 sector_OK
150 inc __auto__sector_index+1
151 inc __auto_write_address+2
152 dec sector_counter
153 bne read_sectors_loop
154
155 ;
156 ; Data successfully loader (we hope)
157 ;
158 sei
159 lda #%10000001 ; Disable the FDC (Eprom select + FDC Interrupt request)
160 sta FDC_flags
161
162 ldx #FDC_OFFSET_JASMIN
163 jmp location_loader
164
165
166
167
168
169 sector_counter .byt (($FFFF-location_loader)+1)/256
170
171
172 _END_
173
174
175
176 ; Type I commands
177 ; The type I commands include the Restore, Seek, Step, Step-In and Step-
178 ; Out commands. Each of the Type I commands contains a rate field r1 r0
179 ; which determines the stepping motor rate.
180 ; r1 r0 Stepping rate
181 ; 0 0 6 ms
182 ; 0 1 12 ms
183 ; 1 0 20 ms
184 ; 1 1 30 ms
185 ; An optional verification of head position can be performed by settling
186 ; bit 2 (V=1) in the command word. The track number from the first
187 ; encountered ID Field is compared against the contents of the Track
188 ; Register. If the track numbers compare (and the ID Field CRC is correct)
189 ; the verify operation is complete and an INTRQ is generated with no
190 ; errors.
191 ;
192 ; Seek
193 ; This command assumes that the Track Register contains the track number
194 ; of the current position of the head and the Data Register contains the
195 ; desired track number. The FD179X will update the Track Register and
196 ; issue stepping pulses in the appropriate direction until the contents of
197 ; the Track Register are equal to the contents of the Data Register. An
198 ; interrupt is generated at the completion of the command. Note: when
199 ; using multiple drives, the track register must be updated for the drive
200 ; selected before seeks are issued.
201
202 ;
203 ; Type II commands
204 ; Type II commands are the Read Sector and Write Sector commands. Prior
205 ; to loading the Type II command into the Command Register, the computer
206 ; must load the Sector Register with the desired sector number. Upon
207 ; receipt of the Type II command, the busy status bit is set. The FD179X
208 ; must find an ID field with a matching Track number and Sector number,
209 ; otherwise the Record not found status bit is set and the command is
210 ; terminated with an interrupt. Each of the Type II commands contains an
211 ; m flag which determines if multiple records (sectors) are to be read or
212 ; written. If m=0, a single sector is read or written and an interrupt is
213 ; generated at the completion of the command. If m=1, multiple records are
214 ; read or written with the sector register internally updated so that an
215 ; address verification can occur on the next record. The FD179X will
216 ; continue to read or write multiple records and update the sector
217 ; register in numerical ascending sequence until the sector register
218 ; exceeds the number of sectors on the track or until the Force Interrupt
219 ; command is loaded into the Command Register. The Type II commands for
220 ; 1791-94 also contain side select compare flags. When C=0 (bit 1), no
221 ; comparison is made. When C=1, the LSB of the side number is read off the
222 ; ID Field of the disk and compared with the contents of the S flag.
223 ;
224 ; Read Sector
225 ; Upon receipt of the command, the head is loaded, the busy status bit set
226 ; and when an ID field is encountered that has the correct track number,
227 ; correct sector number, correct side number, and correct CRC, the data
228 ; field is presented to the computer. An DRQ is generated each time a byte
229 ; is transferred to the DR. At the end of the Read operation, the type of
230 ; Data Address Mark encountered in the data field is recorded in the
231 ; Status Register (bit 5).
232 ;
233
234
235 /*
236 From: http://www.metabarn.com/v1050/docs/v1050_ProgTechDoc.txt
237
238 During a command which performs a data transfer such as diskette
239 read or write, data must be read from or written to the diskettes
240 byte-by—byte via the Z-80A. This can be done either by polling
241 the WD1793 data request bit (DRQ, status bit 1) or by the DRQ
242 interrupt. Reading or writing the data register will reset both
243 the DRQ bit and interrupt. The total time between byte transfers
244 is 23 microseconds for 5" double density or 8" single density;
245 the polling loop or interrupt service routine must be shorter
246 than this to insure that no bytes are lost.
247
248 The diskette motors are turned on by resetting bit 6 of port A of
249 the miscellaneous 8255, and turned off by setting the same bit.
250 Our BIOS code turns the motors on, then leaves them on for two
251 seconds to save time in the case of multiple disk accesses.
252 After turning on the motors, you must wait 800 ms. to be sure
253 that the drives are up to speed before attempting to transfer
254 data. The Ready input of the WD1793 is supplied from pin 34 of
255 the drive interface; it indicates that the drive is loaded and
256 has made at least one revolution at > 50% of normal speed. Note
257 that the drive looks at the index pulse for this; if a hard-
258 sectored disk is inserted the results are invalid.
259
260 The reset line of the WD1793 is held in the reset mode by
261 hardware at power-on. A timing restriction is inherent in the
262 WD1793: after writing a command, the Z-80A must not read the
263 status register for 28 microseconds.
264
265 */

  ViewVC Help
Powered by ViewVC 1.1.26