; ;\r
;------------------------------------------------------;\r
floppy_irq:\r
- push ds\r
- push eax\r
- push ebx\r
+ push ds\r
+ push eax\r
+ push ebx\r
\r
- mov ax, 0x10\r
- mov ds, ax\r
+ mov ax, 0x10\r
+ mov ds, ax\r
\r
- mov [fdd_int_done], 1\r
- mov al, 0x20\r
- out 0x20, al\r
+ mov [fdd_int_done], 1\r
+ mov al, 0x20\r
+ out 0x20, al\r
\r
- pop ebx\r
- pop eax\r
- pop ds\r
- iret\r
+ pop ebx\r
+ pop eax\r
+ pop ds\r
+ iret\r
\r
\r
\r
; out: nothing ;\r
;------------------------------------------------------;\r
fdd_off:\r
- cmp [fdd_motor_on], 0\r
- je .end\r
- push eax\r
- push edx\r
-\r
- mov dx, 0x3F2\r
- mov al, 0x0c ; motor off\r
- out dx, al\r
- mov [fdd_motor_on], 0\r
-\r
- pop edx\r
- pop eax\r
+ cmp [fdd_motor_on], 0\r
+ je .end\r
+ push eax\r
+ push edx\r
+\r
+ mov dx, 0x3F2\r
+ mov al, 0x0c ; motor off\r
+ out dx, al\r
+ mov [fdd_motor_on], 0\r
+\r
+ pop edx\r
+ pop eax\r
.end:\r
ret\r
\r
; out: nothing ;\r
;------------------------------------------------------;\r
fdd_on:\r
- cmp [fdd_motor_on], 1\r
- je .end\r
- push eax\r
- push edx\r
+ cmp [fdd_motor_on], 1\r
+ je .end\r
+ push eax\r
+ push edx\r
\r
- mov dx, 0x3F2 ; motor 0 on..\r
- mov al, 0x1C\r
- out dx, al\r
+ mov dx, 0x3F2 ; motor 0 on..\r
+ mov al, 0x1C\r
+ out dx, al\r
\r
- mov ecx, 20 ; 1/5 of a sec. to speed up\r
- call delay ; in timer.inc\r
- mov [fdd_motor_on], 1\r
+ mov ecx, 20 ; 1/5 of a sec. to speed up\r
+ call delay ; in timer.inc\r
+ mov [fdd_motor_on], 1\r
\r
- pop edx\r
- pop eax\r
+ pop edx\r
+ pop eax\r
.end:\r
ret\r
\r
; in: al = data byte ;\r
;------------------------------------------------------;\r
fdc_sendbyte:\r
- push edx\r
- push ecx\r
- push eax\r
+ push edx\r
+ push ecx\r
+ push eax\r
\r
- mov ecx, 50 ; 50 = 0.5 seconds.\r
- call active_delay ; timer.inc\r
+ mov ecx, 50 ; 50 = 0.5 seconds.\r
+ call active_delay ; timer.inc\r
.l1:\r
- cmp dword [ecx], 0 ; timeup?\r
- je .error\r
- mov dx, 0x3f4 ; check status reg\r
- in al, dx\r
- and al, 0xC0\r
- cmp al, 0x80 ; ok to write?\r
- jnz .l1\r
-\r
- pop eax\r
- pop ecx\r
- mov dx, 0x3F5 ; send byte\r
- out dx, al\r
- pop edx\r
- clc\r
- ret\r
+ cmp dword [ecx], 0 ; timeup?\r
+ je .error\r
+ mov dx, 0x3f4 ; check status reg\r
+ in al, dx\r
+ and al, 0xC0\r
+ cmp al, 0x80 ; ok to write?\r
+ jnz .l1\r
+\r
+ pop eax\r
+ pop ecx\r
+ mov dx, 0x3F5 ; send byte\r
+ out dx, al\r
+ pop edx\r
+ clc\r
+ ret\r
.error:\r
- pop eax\r
- pop ecx\r
- pop edx\r
- stc\r
- ret\r
+ pop eax\r
+ pop ecx\r
+ pop edx\r
+ stc\r
+ ret\r
\r
\r
\r
; out: al = data byte ;\r
;------------------------------------------------------;\r
fdc_getbyte:\r
- push edx\r
- push ecx\r
- push eax\r
+ push edx\r
+ push ecx\r
+ push eax\r
\r
- mov ecx, 50 ; 50 = 0.5 seconds.\r
- call active_delay ; timer.inc\r
+ mov ecx, 50 ; 50 = 0.5 seconds.\r
+ call active_delay ; timer.inc\r
.l1:\r
- cmp dword [ecx], 0 ; timeup?\r
- je .error\r
- mov dx, 0x3f4 ; check status reg\r
- in al, dx\r
- and al, 0xD0\r
- cmp al, 0xD0 ; ok to read?\r
- jnz .l1\r
-\r
- pop eax\r
- pop ecx\r
- mov dx, 0x3F5 ; get the byte\r
- in al, dx\r
- pop edx\r
- clc\r
- ret\r
+ cmp dword [ecx], 0 ; timeup?\r
+ je .error\r
+ mov dx, 0x3f4 ; check status reg\r
+ in al, dx\r
+ and al, 0xD0\r
+ cmp al, 0xD0 ; ok to read?\r
+ jnz .l1\r
+\r
+ pop eax\r
+ pop ecx\r
+ mov dx, 0x3F5 ; get the byte\r
+ in al, dx\r
+ pop edx\r
+ clc\r
+ ret\r
.error:\r
- pop eax\r
- pop ecx\r
- pop edx\r
- stc\r
- ret\r
+ pop eax\r
+ pop ecx\r
+ pop edx\r
+ stc\r
+ ret\r
\r
\r
\r
; ;\r
;------------------------------------------------------;\r
sensei:\r
- push eax\r
-\r
- mov al, 0x08 ; fdc command\r
- call fdc_sendbyte\r
- call fdc_getbyte\r
- mov ah, al ; save ST0 in ah\r
- call fdc_getbyte ; read PCN\r
- clc\r
- test ah, 0x80 ; test for error:\r
- jz .end ; "invalid command"\r
- stc\r
+ push eax\r
+\r
+ mov al, 0x08 ; fdc command\r
+ call fdc_sendbyte\r
+ call fdc_getbyte\r
+ mov ah, al ; save ST0 in ah\r
+ call fdc_getbyte ; read PCN\r
+ clc\r
+ test ah, 0x80 ; test for error:\r
+ jz .end ; "invalid command"\r
+ stc\r
.end:\r
- pop eax\r
- ret\r
+ pop eax\r
+ ret\r
\r
\r
\r
; ;\r
;------------------------------------------------------;\r
fdd_reset:\r
- push eax\r
- push ecx\r
- push edx\r
+ push eax\r
+ push ecx\r
+ push edx\r
\r
- mov byte [fdd_motor_on], 0\r
+ mov byte [fdd_motor_on], 0\r
\r
- mov dx, 0x3f2\r
- mov al, 8 ; off with all motors,\r
- out dx, al ; dma,irq etc..\r
+ mov dx, 0x3f2\r
+ mov al, 8 ; off with all motors,\r
+ out dx, al ; dma,irq etc..\r
\r
- mov ecx, 5\r
- call delay ; in timer.inc\r
+ mov ecx, 5\r
+ call delay ; in timer.inc\r
\r
- mov dx, 0x3f7\r
- mov al, 0\r
- out dx, al ; work at 500 kbit/s\r
+ mov dx, 0x3f7\r
+ mov al, 0\r
+ out dx, al ; work at 500 kbit/s\r
\r
- mov dx, 0x3f2\r
- mov al, 0x0c\r
- out dx, al ; reenable interrupts\r
+ mov dx, 0x3f2\r
+ mov al, 0x0c\r
+ out dx, al ; reenable interrupts\r
\r
- mov [fdd_int_done], 0\r
- call wait_int ; wait for floppy int.\r
- jc .error ; timeout?\r
+ mov [fdd_int_done], 0\r
+ call wait_int ; wait for floppy int.\r
+ jc .error ; timeout?\r
\r
- mov cx, 0x04\r
+ mov cx, 0x04\r
.status: ; 4 dummy-reads.\r
- call sensei\r
- loop .status\r
-\r
- mov al, 0x03 ; specify command\r
- call fdc_sendbyte\r
- mov al, 0xDF ; SRT, HUT\r
- call fdc_sendbyte\r
- mov al, 0x02 ; HLT, ND\r
- call fdc_sendbyte\r
-\r
- mov al, 1\r
- call fdd_recal_seek\r
- jc .error\r
- call fdd_off\r
- clc\r
- jmp .end\r
+ call sensei\r
+ loop .status\r
+\r
+ mov al, 0x03 ; specify command\r
+ call fdc_sendbyte\r
+ mov al, 0xDF ; SRT, HUT\r
+ call fdc_sendbyte\r
+ mov al, 0x02 ; HLT, ND\r
+ call fdc_sendbyte\r
+\r
+ mov al, 1\r
+ call fdd_recal_seek\r
+ jc .error\r
+ call fdd_off\r
+ clc\r
+ jmp .end\r
.error:\r
- call fdd_off\r
- stc\r
+ call fdd_off\r
+ stc\r
.end:\r
- pop edx\r
- pop ecx\r
- pop eax\r
- ret\r
+ pop edx\r
+ pop ecx\r
+ pop eax\r
+ ret\r
\r
\r
\r
; ;\r
;------------------------------------------------------;\r
fdd_recal_seek:\r
- push eax\r
-\r
- call fdd_on ; turn motor on\r
- cmp al, 0\r
- jne .recalibrate\r
- clc\r
- cmp bl, [result_C] ; are we there yet? :D\r
- je .ok\r
- mov al, 0x0F ; seek command\r
- call fdc_sendbyte\r
- mov al, bh ; ((head*4)|drive)\r
- call fdc_sendbyte\r
- mov al, bl ; track\r
- call fdc_sendbyte\r
- mov [result_C], bl ; now on..?\r
- jmp .get_int\r
+ push eax\r
+\r
+ call fdd_on ; turn motor on\r
+ cmp al, 0\r
+ jne .recalibrate\r
+ clc\r
+ cmp bl, [result_C] ; are we there yet? :D\r
+ je .ok\r
+ mov al, 0x0F ; seek command\r
+ call fdc_sendbyte\r
+ mov al, bh ; ((head*4)|drive)\r
+ call fdc_sendbyte\r
+ mov al, bl ; track\r
+ call fdc_sendbyte\r
+ mov [result_C], bl ; now on..?\r
+ jmp .get_int\r
.recalibrate:\r
- mov al, 0x07 ; recalibrate command\r
- call fdc_sendbyte\r
- mov al, 0 ; drive number\r
- call fdc_sendbyte\r
- mov [result_C], 0 ; now on track 0\r
+ mov al, 0x07 ; recalibrate command\r
+ call fdc_sendbyte\r
+ mov al, 0 ; drive number\r
+ call fdc_sendbyte\r
+ mov [result_C], 0 ; now on track 0\r
.get_int:\r
- mov [fdd_int_done], 0\r
- call wait_int\r
- jc .error\r
+ mov [fdd_int_done], 0\r
+ call wait_int\r
+ jc .error\r
\r
- call sensei ; sense interrupt status\r
- jc .error\r
+ call sensei ; sense interrupt status\r
+ jc .error\r
.ok:\r
- clc\r
- jmp .end\r
+ clc\r
+ jmp .end\r
.error:\r
stc\r
.end:\r
; cf = 0 if ok, 1 if error ;\r
;------------------------------------------------------;\r
fdd_read_write:\r
- pushad\r
-\r
- and dh, 1 ; head 0 or 1?\r
- mov [fdd_head], dh ; store it.\r
- shl dh, 2\r
- or dh, 0 ; drive 0, fd0\r
- mov [fdd_drivehead], dh ; dh = ((head*4)|drive)\r
- mov [fdd_errorcode], 0x04 ; basic error code\r
- cmp ch, 0x51 ; check for allowed\r
- jae .error ; track number.\r
- mov [fdd_track], ch\r
- cmp cl, 0x13 ; check for allowed\r
- jae .error ; sector number.\r
- mov [fdd_sector], cl\r
-\r
- cmp [fdd_error], 1\r
- jne .no_previous_error\r
- mov al, 1\r
- call fdd_recal_seek\r
+ pushad\r
+\r
+ and dh, 1 ; head 0 or 1?\r
+ mov [fdd_head], dh ; store it.\r
+ shl dh, 2\r
+ or dh, 0 ; drive 0, fd0\r
+ mov [fdd_drivehead], dh ; dh = ((head*4)|drive)\r
+ mov [fdd_errorcode], 0x04 ; basic error code\r
+ cmp ch, 0x51 ; check for allowed\r
+ jae .error ; track number.\r
+ mov [fdd_track], ch\r
+ cmp cl, 0x13 ; check for allowed\r
+ jae .error ; sector number.\r
+ mov [fdd_sector], cl\r
+\r
+ cmp [fdd_error], 1\r
+ jne .no_previous_error\r
+ mov al, 1\r
+ call fdd_recal_seek\r
.no_previous_error:\r
- call fdd_on\r
+ call fdd_on\r
\r
- mov dx, 0x3F7\r
- mov al, 0 ; 500Kb/sec mode\r
- out dx, al\r
- mov [fdd_errorcode], 0x80 ; error code\r
+ mov dx, 0x3F7\r
+ mov al, 0 ; 500Kb/sec mode\r
+ out dx, al\r
+ mov [fdd_errorcode], 0x80 ; error code\r
\r
- xor ecx, ecx\r
- mov cx, 3 ; try seek 3 times\r
+ xor ecx, ecx\r
+ mov cx, 3 ; try seek 3 times\r
.l2:\r
- mov al, 0\r
- push ebx\r
- mov bl, [fdd_track]\r
- mov bh, [fdd_drivehead] ; ((head*4)|drive)\r
- call fdd_recal_seek\r
- pop ebx\r
- jnc .l3 ; ok, continue.\r
- loop .l2\r
- jmp .error ; timeout.\r
+ mov al, 0\r
+ push ebx\r
+ mov bl, [fdd_track]\r
+ mov bh, [fdd_drivehead] ; ((head*4)|drive)\r
+ call fdd_recal_seek\r
+ pop ebx\r
+ jnc .l3 ; ok, continue.\r
+ loop .l2\r
+ jmp .error ; timeout.\r
.l3:\r
- push ebx\r
- cmp bl, 0\r
- je .read_fdd\r
+ push ebx\r
+ cmp bl, 0\r
+ je .read_fdd\r
\r
.write_fdd:\r
- push edi\r
- mov esi, edi\r
- mov edi, 0x80000 ; copy the stuff we will\r
- mov ecx, 128 ; write to the DMA buffer\r
- rep movsd ; 128*4=512\r
- pop edi\r
-\r
- mov bl, 2 ; channel 2\r
- mov esi, 512 ; bytes to write\r
- mov ecx, 0x80000 ; page & offset\r
- mov bh, 1 ; write floppy, read DMA\r
- call dma_transfer\r
-\r
- mov al, 0xC5 ; write sector command\r
- call fdc_sendbyte\r
- jmp .cont\r
+ push edi\r
+ mov esi, edi\r
+ mov edi, 0x80000 ; copy the stuff we will\r
+ mov ecx, 128 ; write to the DMA buffer\r
+ rep movsd ; 128*4=512\r
+ pop edi\r
+\r
+ mov bl, 2 ; channel 2\r
+ mov esi, 512 ; bytes to write\r
+ mov ecx, 0x80000 ; page & offset\r
+ mov bh, 1 ; write floppy, read DMA\r
+ call dma_transfer\r
+\r
+ mov al, 0xC5 ; write sector command\r
+ call fdc_sendbyte\r
+ jmp .cont\r
\r
.read_fdd:\r
- mov bl, 2 ; channel 2\r
- mov esi, 512 ; bytes to read\r
- mov ecx, 0x80000 ; page & offset\r
- mov bh, 0 ; read floppy, write DMA\r
- call dma_transfer\r
+ mov bl, 2 ; channel 2\r
+ mov esi, 512 ; bytes to read\r
+ mov ecx, 0x80000 ; page & offset\r
+ mov bh, 0 ; read floppy, write DMA\r
+ call dma_transfer\r
\r
- mov al, 0xE6 ; read sector command\r
- call fdc_sendbyte\r
+ mov al, 0xE6 ; read sector command\r
+ call fdc_sendbyte\r
\r
.cont:\r
- pop ebx\r
- mov al, [fdd_drivehead] ; ((head*4)|drive)\r
- call fdc_sendbyte\r
- mov al, [fdd_track] ; track/cylinder\r
- call fdc_sendbyte\r
-\r
- mov al, [fdd_head] ; head/side 0 or 1\r
- call fdc_sendbyte\r
- mov al, [fdd_sector] ; sector number\r
- call fdc_sendbyte\r
- mov al, 0x02 ; sector size, 512 bytes\r
- call fdc_sendbyte\r
-\r
- mov al, 0x12 ; sectors to a track\r
- call fdc_sendbyte\r
- mov al, 0x1B ; gap length\r
- call fdc_sendbyte\r
- mov al, 0xFF ; data length\r
- call fdc_sendbyte\r
-\r
- mov [fdd_int_done], 0\r
- call wait_int\r
- jc .error\r
-\r
- call fdc_getbyte\r
- mov [result_ST0], al ; ST0\r
- call fdc_getbyte\r
- mov [result_ST1], al ; ST1\r
- call fdc_getbyte\r
- mov [result_ST2], al ; ST2\r
- call fdc_getbyte\r
- mov [result_C], al ; cylinder\r
- call fdc_getbyte\r
- mov [result_H], al ; head\r
- call fdc_getbyte\r
- mov [result_R], al ; sector number.\r
- call fdc_getbyte\r
- mov [result_N], al ; sector size\r
-\r
- test [result_ST0], 0xc0 ; test if sr0 is 0xC0\r
- jnz .error\r
- cmp bl, 1 ; did we write the disk?\r
- je .ok\r
-\r
- mov ecx, 512 ; sector size in bytes\r
- mov esi, 0x80000 ; copy to dest. in edi\r
- rep movsb\r
+ pop ebx\r
+ mov al, [fdd_drivehead] ; ((head*4)|drive)\r
+ call fdc_sendbyte\r
+ mov al, [fdd_track] ; track/cylinder\r
+ call fdc_sendbyte\r
+\r
+ mov al, [fdd_head] ; head/side 0 or 1\r
+ call fdc_sendbyte\r
+ mov al, [fdd_sector] ; sector number\r
+ call fdc_sendbyte\r
+ mov al, 0x02 ; sector size, 512 bytes\r
+ call fdc_sendbyte\r
+\r
+ mov al, 0x12 ; sectors to a track\r
+ call fdc_sendbyte\r
+ mov al, 0x1B ; gap length\r
+ call fdc_sendbyte\r
+ mov al, 0xFF ; data length\r
+ call fdc_sendbyte\r
+\r
+ mov [fdd_int_done], 0\r
+ call wait_int\r
+ jc .error\r
+\r
+ call fdc_getbyte\r
+ mov [result_ST0], al ; ST0\r
+ call fdc_getbyte\r
+ mov [result_ST1], al ; ST1\r
+ call fdc_getbyte\r
+ mov [result_ST2], al ; ST2\r
+ call fdc_getbyte\r
+ mov [result_C], al ; cylinder\r
+ call fdc_getbyte\r
+ mov [result_H], al ; head\r
+ call fdc_getbyte\r
+ mov [result_R], al ; sector number.\r
+ call fdc_getbyte\r
+ mov [result_N], al ; sector size\r
+\r
+ test [result_ST0], 0xc0 ; test if sr0 is 0xC0\r
+ jnz .error\r
+ cmp bl, 1 ; did we write the disk?\r
+ je .ok\r
+\r
+ mov ecx, 512 ; sector size in bytes\r
+ mov esi, 0x80000 ; copy to dest. in edi\r
+ rep movsb\r
.ok:\r
- mov [fdd_errorcode], 0 ; no error.. :D\r
- mov [fdd_error], 0 ; no recal. next time\r
- clc\r
- jmp .end\r
+ mov [fdd_errorcode], 0 ; no error.. :D\r
+ mov [fdd_error], 0 ; no recal. next time\r
+ clc\r
+ jmp .end\r
.error:\r
- mov [fdd_error], 1 ; recalibrate next time\r
- stc\r
+ mov [fdd_error], 1 ; recalibrate next time\r
+ stc\r
.end:\r
- call fdd_off ; floppy motor off\r
- popad\r
- mov al, [fdd_errorcode] ; error status\r
- ret
\ No newline at end of file
+ call fdd_off ; floppy motor off\r
+ popad\r
+ mov al, [fdd_errorcode] ; error status\r
+ ret
\ No newline at end of file