static uint8_t motorct;
static uint8_t fd_selected = 0xFF;
-static uint8_t fd_tab[MAX_FD];
+extern uint8_t *fd_tab;
static void fd_motor_busy(void)
{
{
blkno_t block;
uint16_t dptr;
- int ct = 0;
+ uint8_t nblock;
int tries;
uint8_t err;
uint8_t *driveptr = fd_tab + minor;
- uint8_t cmd[6];
+ uint8_t cmd[7];
if(rawflag)
goto bad2;
goto bad;
}
- dptr = (uint16_t)udata.u_buf->bf_data;
- block = udata.u_buf->bf_blk;
+ if (rawflag == 0) {
+ dptr = (uint16_t)udata.u_buf->bf_data;
+ block = udata.u_buf->bf_blk;
+ nblock = 2;
+ } else if (rawflag == 1) {
+ if (((uint16_t)udata.u_offset|udata.u_count) & BLKMASK)
+ goto bad2;
+ dptr = (uint16_t)udata.u_base;
+ block = udata.u_offset >> 9;
+ nblock = udata.u_count >> 8;
+ }
// kprintf("Issue command: drive %d\n", minor);
- cmd[0] = is_read ? FD_READ : FD_WRITE;
- 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;
+ cmd[0] = rawflag;
+ cmd[1] = is_read ? FD_READ : FD_WRITE;
+ cmd[2] = block / 9; /* 2 sectors per block */
+ cmd[3] = ((block % 9) << 1) + 1; /*eww.. */
+ cmd[4] = is_read ? OPDIR_READ: OPDIR_WRITE;
+ cmd[5] = dptr >> 8;
+ cmd[6] = dptr & 0xFF;
- while (ct < 2) {
+ while (nblock) {
for (tries = 0; tries < 4 ; tries++) {
err = fd_operation(cmd, driveptr);
if (err == 0)
/* FIXME: should we try the other half and then bale out ? */
if (tries == 3)
goto bad;
- cmd[4]++; /* Move on 256 bytes in the buffer */
- cmd[2]++; /* Next sector for 2nd block */
- ct++;
+ cmd[5]++; /* Move on 256 bytes in the buffer */
+ cmd[3]++; /* Next sector for next block */
+ if (cmd[3] == 10) {
+ cmd[3] = 1; /* Track on */
+ cmd[2]++;
+ }
+ nblock--;
}
fd_motor_idle();
return 1;
;
; Core floppy routines for the Dragon
+;
+; Must live in common space as they are called from interrupt
+; contexts and also map user space about
;
.globl fd_nmi_handler
.globl _fd_operation
.globl _fd_motor_on
.globl _fd_motor_off
+
+ .globl _fd_tab
;
; MMIO for the floppy controller
;
DIRECT EQU 3 ; 0 = read 2 = write 1 = status
DATA EQU 4
- .area .text
+ .area .common
;
; NMI handling for the floppy drive
;
orcc #0x40 ; Make sure FIR is off
jsr piasave
ldy 6,s ; Drive struct
+ tst ,y+ ; User or kernel ?
+ beq fd_op_k
+ jsr map_process_always
+fd_op_k:
jsr fdsetup ; Set up for a command
tfr a,b ; Status code or 0xFF for total failure
+ jsr map_kernel
bsr piaload
puls y,cc,dp,pc ; Restore IRQ state etc
;
no_work_motor:
puls y,dp,pc
- .area .data
-
+;
+; We need these mapped during interrupts so must live in common
+;
+ .area .common
nmivector:
.word nmi_handler
curdrive:
.byte 0xff
-
- .area .bss
+;
+; BSS but used with user mapping so keep common
+;
+ .area .common
motor_running:
.byte 0
fdcctrl:
.byte 0
.byte 0
.byte 0
- .byte 0
\ No newline at end of file
+ .byte 0
+_fd_tab:
+ .byte 0,0,0,0