dptr = (uint16_t)udata.u_dptr;
block = udata.u_block;
- kprintf("Reading from block %d\n", block);
while(ct < udata.u_nblock) {
cmd[0] = is_read ? FD_READ : FD_WRITE;
/* Double sided assumed FIXME */
err = fd_operation(cmd, driveptr);
if (err == 0)
break;
- kprintf("Try %d err %d\n", tries, err);
if (tries > 1)
fd_reset(driveptr);
}
udata.u_dptr += 512;
ct++;
}
- kprintf("Read return %x\n", ct << BLKSHIFT);
return ct << BLKSHIFT;
bad:
kprintf("fd%d: error %x\n", minor, err);
out (FDCSEC), a
in a, (FDCREG) ; Clear any pending status
- ld a, CMD(ix)
+ ld c, CMD(ix)
ld de, #0 ; timeout handling
- out (FDCREG), a ; issue the command
- ld b, #0
-rwiowt: djnz rwiowt
ld a, DIRECT(ix)
dec a
ld a, (fdcctrl)
ld (fdc_active), a ; NMI pop and jump
jr z, fdio_in
jr nc, fdio_out
+ ld a,c
+ out (FDCREG), a ; issue the command
;
-; Status registers
+; Status registers. At this point A also holds the state returned
+; from the FDCREG poll for data xfers but we dont currently use it.
;
fdxferdone:
ei
; Read from the disk - HL points to the target buffer
;
fdio_in:
+ ld a,c
ld e, #0x16 ; bits to check
ld bc, #FDCDATA ; 512 bytes/sector, c is our port
-fdio_inl:
+ out (FDCREG), a ; issue the command
+ di
+fdio_in1:
in a, (FDCREG)
and e
- jr z, fdio_inl
- ini
- di
- ld a, d
-fdio_inbyte:
- out (FDCCTRL), a ; stalls
+ jr z, fdio_in1
ini
- jr nz, fdio_inbyte
-fdio_inbyte2:
- out (FDCCTRL), a ; stalls
+ jr nz, fdio_in1
+fdio_in2:
+ in a, (FDCREG)
+ and e
+ jr z, fdio_in2
ini
- jr nz, fdio_inbyte2
+ jr nz, fdio_in2
jr fdxferdone
;
; Read from the disk - HL points to the target buffer
;
fdio_out:
- set 6,d ; halt mode bit
+ ld a, c
ld c, #FDCDATA ; C is our port
ld e, #0x76
-fdio_outl:
+ out (FDCREG), a ; issue the command
+ di
+fdio_out1:
in a, (FDCREG) ; Wait for DRQ (or error)
and e
- jr z, fdio_outl
+ jr z, fdio_out1
outi ; Stuff byte into FDC while we think
- di
- in a, (FDCREG) ; No longer busy ??
- rra
- jr nc, fdxferbad ; Bugger...
- ld b, (hl) ; Next byte
- inc hl
-fdio_waitlock:
- ld a, d
- out (FDCCTRL), a ; wait states on
- in a, (FDCREG)
- and e
- jr z, fdio_waitlock
- out (c), b
- ld a, d
-fdio_outbyte:
- out (FDCCTRL), a ; stalls
- outi
- jr fdio_outbyte
+ jr nz,fdio_out1
fdio_nmiout:
;
; Now tidy up
push hl
push de
;
- ; Select drive B
+ ; Select drive
;
- cp l
- jr z, was_selected
-;
-; Select our drive
-;
-notsel:
ld a, l
out (FDCCTRL), a
- out (FDCCTRL), a ; TRS80 erratum apparently needs this
ld (fdcctrl), a
ld bc, #0x7F00 ; Long delay (may need FE or FF for some disks)
call nap
;
; All is actually good
;
-was_selected:
ld hl, #0
ret