From: Alan Cox Date: Sat, 6 Dec 2014 02:49:39 +0000 (+0000) Subject: dragon: initial fdc work X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=2caab4fbff07ddf970c8a2046bf2e9e3d411597d;p=FUZIX.git dragon: initial fdc work Now correctly loads the superblock off disk. Something is astray once we try and seek off track 0 however --- diff --git a/Kernel/platform-dragon/devfd.c b/Kernel/platform-dragon/devfd.c index 1d3443a9..f9acb737 100644 --- a/Kernel/platform-dragon/devfd.c +++ b/Kernel/platform-dragon/devfd.c @@ -5,8 +5,8 @@ #define MAX_FD 4 -#define OPDIR_READ 0 -#define OPDIR_NONE 1 +#define OPDIR_NONE 0 +#define OPDIR_READ 1 #define OPDIR_WRITE 2 #define FD_READ 0x88 /* 2797 needs 0x88, 1797 needs 0x80 */ @@ -42,6 +42,9 @@ static void fd_motor_timeout(void) * for our usage but would break for single density media. */ +/* static uint8_t selmap[4] = { 0x01, 0x02, 0x04, 0x40 }; - COCO */ +static uint8_t selmap[4] = {0x00, 0x01, 0x02, 0x03 }; + static int fd_transfer(uint8_t minor, bool is_read, uint8_t rawflag) { blkno_t block; @@ -50,9 +53,7 @@ static int fd_transfer(uint8_t minor, bool is_read, uint8_t rawflag) int tries; uint8_t err; uint8_t *driveptr = fd_tab + minor; - uint16_t cmd[5]; - - /* FIXME: raw is broken unless nicely aligned */ + uint8_t cmd[6]; if(rawflag) goto bad2; @@ -60,7 +61,7 @@ static int fd_transfer(uint8_t minor, bool is_read, uint8_t rawflag) fd_motor_busy(); /* Touch the motor timer first so we don't go and turn it off as we are doing this */ if (fd_selected != minor) { - uint8_t err = fd_motor_on(driveptr); + uint8_t err = fd_motor_on(selmap[minor]); if (err) goto bad; } @@ -68,17 +69,19 @@ static int fd_transfer(uint8_t minor, bool is_read, uint8_t rawflag) dptr = (uint16_t)udata.u_buf->bf_data; block = udata.u_buf->bf_blk; +// kprintf("Issue command: drive %d\n", minor); cmd[0] = is_read ? FD_READ : FD_WRITE; - cmd[1] = block / 18; - cmd[2] = (block % 18) + 1; /*eww.. */ - cmd[3] = minor; /* FIXME: other bits ? */ - cmd[4] = is_read ? OPDIR_READ: OPDIR_WRITE; - cmd[5] = block << 8; - cmd[6] = block & 0xFF; + cmd[1] = block / 9; /* 2 sectors per block */ + cmd[2] = ((block % 9) << 1) + 1; /*eww.. */ + cmd[3] = is_read ? OPDIR_READ: OPDIR_WRITE; + cmd[4] = dptr >> 8; + cmd[5] = dptr & 0xFF; while (ct < 2) { - for (tries = 0; tries < 3 ; tries++) { + for (tries = 0; tries < 4 ; tries++) { +// kprintf("Issue command: %d drive %d sec %d\n", cmd[0], minor, cmd[2]); err = fd_operation(cmd, driveptr); +// kprintf("Issue command: return %d\n", err); if (err == 0) break; if (tries > 1) @@ -87,7 +90,7 @@ static int fd_transfer(uint8_t minor, bool is_read, uint8_t rawflag) /* FIXME: should we try the other half and then bale out ? */ if (tries == 3) goto bad; - cmd[5]++; /* Move on 256 bytes in the buffer */ + cmd[4]++; /* Move on 256 bytes in the buffer */ cmd[2]++; /* Next sector for 2nd block */ ct++; } diff --git a/Kernel/platform-dragon/devfd.h b/Kernel/platform-dragon/devfd.h index 2354e361..69ecb5ec 100644 --- a/Kernel/platform-dragon/devfd.h +++ b/Kernel/platform-dragon/devfd.h @@ -9,7 +9,7 @@ int fd_open(uint8_t minor, uint16_t flag); /* low level interface */ uint8_t fd_reset(uint8_t *drive); uint8_t fd_operation(uint16_t *cmd, uint8_t *drive); -uint8_t fd_motor_on(uint8_t *drive); +uint8_t fd_motor_on(uint8_t drive); uint8_t fd_motor_off(void); #endif /* __DEVFD_DOT_H__ */ diff --git a/Kernel/platform-dragon/floppy.s b/Kernel/platform-dragon/floppy.s index 789ea06b..34c34bc6 100644 --- a/Kernel/platform-dragon/floppy.s +++ b/Kernel/platform-dragon/floppy.s @@ -12,20 +12,20 @@ ; ; MMIO for the floppy controller ; +; For a Dragon cartridge ; -; These four are a normal WD2797 under DragonDOS +FDCCTRL EQU 0xFF48 +; +; 0-1: drive select +; 2: motor on +; 3: density +; 4: precomp +; 5: nmi mode ; FDCREG EQU 0xFF40 FDCTRK EQU 0xFF41 FDCSEC EQU 0xFF42 FDCDATA EQU 0xFF43 -; -; This is the control logic -; -FDCCTRL EQU 0xFF48 ; drive select and motors -; bit5: NMI enable, 4: Precomp ?, 3: Density, 2: Motor, -; bits 0-1 are drive nymber 0-3 - ; ; Structures we use @@ -41,9 +41,8 @@ TRKCOPY EQU 0 CMD EQU 0 TRACK EQU 1 SECTOR EQU 2 -DRIVESEL EQU 3 -DIRECT EQU 4 ; 0 = read 2 = write 1 = status -DATA EQU 5 +DIRECT EQU 3 ; 0 = read 2 = write 1 = status +DATA EQU 4 .area .text ; @@ -75,36 +74,42 @@ waitdisk: waitdisk_l: leax -1,x beq forceint ; try forcing an interrupt - lda FDCREG + lda