Skip to content

Commit

Permalink
Properly detect errors again.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Jan 6, 2024
1 parent 84c8a80 commit d1c91aa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
56 changes: 32 additions & 24 deletions arch/brother/pn8800/floppy.z80
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ label WRITEE
ld (deblock_flag), a

call change_track
jp nz, return_bios_error
jr nz, return_bios_error

ld a, 1
ld (track_dirty), a
Expand Down Expand Up @@ -130,12 +130,15 @@ label WRITEE
deblock_flag equ $+1
ld a, 0
cp 1
jp z, flush_track
jr nz, return_bios_success
call flush_track
jp nz, return_bios_error
; fall through
return_bios_success:
xor a
ret

; Returns nz on error.
change_track:
BTRACK equ $+1
ld a, 0
Expand All @@ -147,33 +150,35 @@ track_dirty equ $ + 1
ld a, 0
or a
call nz, flush_track
ret nz

; Switch to the new track.

ld a, (BTRACK)
ld (current_track), a

; Send command.

ld a, 0x66 ; READ SECTORS
call send_read_write_command

; Do DMA to read data.
; Set up DMA to read data.

ld d, 1010b
call perform_fdc_dma_readwrite
jr c_to_nz
call start_fdc_dma_readwrite

flush_track:
; Send command.

ld a, 0x65 ; WRITE SECTORS
call send_read_write_command
ld a, 0x46 ; READ SECTORS
call do_read_write_command
jr c_to_nz

; Do DMA to write data.
; Returns nz on error.
flush_track:
; Set up DMA to write data.

ld d, 1000b
call perform_fdc_dma_readwrite
call start_fdc_dma_readwrite

; Send command.

ld a, 0x45 ; WRITE SECTORS
call do_read_write_command
jr c, c_to_nz

xor a ; sets z
Expand All @@ -194,7 +199,7 @@ flush_cache:
ret

; Command opcode in A.
send_read_write_command:
do_read_write_command:
ld (fdc_readwrite), a

; Seek to track.
Expand All @@ -215,10 +220,19 @@ send_read_write_command:

ld hl, fdc_readwrite
ld b, fdc_readwrite.end - fdc_readwrite
jp FDCTXB
call FDCTXB

; Wait for completion.

call FDCENDRW

; carry preserved
ld a, 00010000b
out0 (DSTAT), a
ret

; Low four bits of DCNTL should be in d.
perform_fdc_dma_readwrite:
start_fdc_dma_readwrite:
ld hl, fdc_dma
ld b, fdc_dma.end - fdc_dma
ld c, MAR1L
Expand All @@ -232,12 +246,6 @@ perform_fdc_dma_readwrite:
out0 (DCNTL), a
ld a, 10000000b ; DE1 enable, DWE1 disable
out0 (DSTAT), a ; start the transfer

call FDCENDRW

; carry preserved
ld a, 00010000b
out0 (DSTAT), a
ret

; Returns a=0 and z on exit.
Expand Down
25 changes: 12 additions & 13 deletions arch/brother/pn8800/hd63266.z80
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,38 @@ label FDCTXB
ret

; Finish up a read or write transfer.
; Returns nz on success, z on failure.
; Returns c on failure.

label FDCENDRW
call FDCRDST
; Parsing the status code is fiddly, because we're allowed a readfail if
; EN is set.
ld a, (FDCSTAT+1)
rla ; EN->C
ld a, (FDCSTAT+0)
ld a, (FDCSTAT+0) ; IC6->b6, IC7->b7, EN->C
rla ; IC6->b7, IC7->C, EN->b0
rla ; IC6->C, IC7->b0, EN->b1
rla ; IC6->b0, IC7->b1, EN->b2
and 7 ; clip off stray bits
; This gives us a number from 0..7 which is our error. We use this
; bitmap to determine whether it's fatal or not.
; EN, IC7, IC6
; 1 ; OK
; 0 ; readfail
; 0 ; unknown command
; 0 ; disk removed
; 1 ; OK
; 1 ; reached end of track
; 0 ; unknown command
; 0 ; disk removed
; 0 0 0 -> 0 ; OK
; 0 0 1 -> 1 ; readfail
; 0 1 0 -> 1 ; unknown command
; 0 1 1 -> 1 ; disk removed
; 1 0 0 -> 0 ; OK
; 1 0 1 -> 0 ; reached end of track
; 1 1 0 -> 1 ; unknown command
; 1 1 1 -> 1 ; disk removed
inc a
ld b, a
ld a, 10001100b
ld a, 01110011b
.1
add a
djnz .1
; The appropriate bit from the bitmap is now in C.
ld a, 0
rla ; copy carry to bit 0, set z or nz
ret

; Reads bytes from the FDC data register until the FDC tells us to stop (by
Expand Down

0 comments on commit d1c91aa

Please sign in to comment.