diff --git a/Makefile b/Makefile index 9152795..b7339d8 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ all: bazel test -c dbg //... bazel build -c opt //:diskimages for a in $$(dirname bazel-bin/arch/*/diskimage.img bazel-bin/arch/*/*/diskimage.img); do \ - f=$$(basename $$a); ln -sf $$a/diskimage.img $$f.img; done + f=$$(basename $$a); ln -sf $$a/diskimage.img $$f.img; chmod a+rw $$f.img; done verbose: bazel test -s -c dbg //... diff --git a/arch/brother/pn8800/floppy.z80 b/arch/brother/pn8800/floppy.z80 index 838775f..2e3c21e 100644 --- a/arch/brother/pn8800/floppy.z80 +++ b/arch/brother/pn8800/floppy.z80 @@ -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 @@ -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 @@ -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 @@ -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. @@ -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 @@ -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. diff --git a/arch/brother/pn8800/hd63266.z80 b/arch/brother/pn8800/hd63266.z80 index ca76410..2329473 100644 --- a/arch/brother/pn8800/hd63266.z80 +++ b/arch/brother/pn8800/hd63266.z80 @@ -32,7 +32,7 @@ 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 @@ -40,31 +40,30 @@ label FDCENDRW ; 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