#include <printf.h>
#include <devfd.h>
+/*
+ * TODO: Debug, low density is half the sectors/track,
+ * what to do about 80 v 40 track ?
+ *
+ */
/* Two drives but minors 2,3 are single density mode */
#define MAX_FD 4
static uint8_t motorct;
static uint8_t fd_selected = 0xFF;
-static uint8_t fd_tab[MAX_FD];
+static uint8_t fd_tab[MAX_FD] = { 0xFF, 0xFF };
/*
* We only support normal block I/O
int ct = 0;
int tries;
uint8_t err = 0;
- uint8_t *driveptr = fd_tab + minor;
+ uint8_t *driveptr = &fd_tab[minor & 1];
uint8_t cmd[6];
if(rawflag)
dptr = (uint16_t)udata.u_buf->bf_data;
block = udata.u_buf->bf_blk;
-// kprintf("Issue command: drive %d\n", minor);
+ kprintf("Issue command: drive %d block %d\n", minor, block);
cmd[0] = is_read ? FD_READ : FD_WRITE;
- cmd[1] = block / 8; /* 2 sectors per block */
- cmd[2] = ((block & 7) << 1) + 1;
+ cmd[1] = block / 16; /* 2 sectors per block */
+ cmd[2] = ((block & 15) << 1); /* 0 - 1 base is corrected in asm */
cmd[3] = is_read ? OPDIR_READ: OPDIR_WRITE;
cmd[4] = dptr & 0xFF;
cmd[5] = dptr >> 8;
while (ct < 2) {
for (tries = 0; tries < 4 ; tries++) {
+ kprintf("Sector: %d Track %d\n", cmd[2]+1, cmd[1]);
err = fd_operation(cmd, driveptr);
if (err == 0)
break;
out (FDCTRK), a
cp TRACK(ix)
jr z, fdiosetup
-
;
; So we can verify
;
+ bit 4, SECTOR(ix) ; side ?
+ ld a, (fdcctrl)
+ jr z, seekside1
+ set 1, a
+ jr seekside
+seekside1:
+ res 1, a
+seekside:
+ out (FDCCTRL), a
ld a, SECTOR(ix)
+ inc a
out (FDCSEC), a
+ ld a, TRACK(ix)
+ out (FDCDATA), a ; target
;
; Need to seek the disk
;
call waitdisk
jr nz, setuptimeout
and #0x18 ; error bits
- jr z, fdiosetup
+ jr z, seekgood
; seek failed, not good
setuptimeout: ; NE = bad
ld a, #0xff ; we have no idea where we are, force a seek
ld (de), a ; zap track info
ret
;
-; Head in the right place
+; Seek worked ok
;
-fdiosetup:
+seekgood:
+ in a, (FDCREG)
ld a, TRACK(ix)
ld (de), a ; save track
+;
+; Head in the right place
+;
+fdiosetup:
; cmp #22 ; FIXME
; jr nc, noprecomp
; ld a, (fdcctrl)
;noprecomp:
ld a, (fdcctrl)
;precomp1:
- bit 3, SECTOR(ix) ; check if we need side 1
+ bit 4, SECTOR(ix) ; check if we need side 1
jr nz, fdio_s1
res 1, a
jr fdio_setsec
fdio_setsec:
out (FDCCTRL), a
ld a, SECTOR(ix)
- and #7 ; remove side bit
+ inc a ; 1 based
out (FDCSEC), a
in a, (FDCREG) ; Clear any pending status