Skip to content

Commit

Permalink
Check for read/write errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vinriviere committed Nov 20, 2021
1 parent cf6e0ed commit 7158deb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions bios/68kmbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,18 @@ static void m68kmbc_select_sector(ULONG sector)
M68KMBC_PORTS.excwr = HIBYTE(HIWORD(sector));
}

// Read the error code after a LBA read/write (0 = no error)
static UBYTE m68kmbc_errlba(void)
{
M68KMBC_PORTS.stopc = ERRLBA_OPC;
return M68KMBC_PORTS.excrd;
}

static LONG m68kmbc_read_sector(ULONG sector, UBYTE *buf)
{
WORD old_sr;
int i;
LONG ret;

old_sr = set_sr(0x2700);

Expand All @@ -172,15 +180,18 @@ static LONG m68kmbc_read_sector(ULONG sector, UBYTE *buf)
for (i = 0; i < SECTOR_SIZE; i++)
*buf++ = M68KMBC_PORTS.excrd;

ret = m68kmbc_errlba() ? EREADF : E_OK;

set_sr(old_sr);

return E_OK;
return ret;
}

static LONG m68kmbc_write_sector(ULONG sector, const UBYTE *buf)
{
WORD old_sr;
int i;
LONG ret;

old_sr = set_sr(0x2700);

Expand All @@ -191,9 +202,11 @@ static LONG m68kmbc_write_sector(ULONG sector, const UBYTE *buf)
for (i = 0; i < SECTOR_SIZE; i++)
M68KMBC_PORTS.excwr = *buf++;

ret = m68kmbc_errlba() ? EWRITF : E_OK;

set_sr(old_sr);

return E_OK;
return ret;
}

LONG m68kmbc_rw(UWORD rw, ULONG sector, UWORD count, UBYTE *buf, WORD dev)
Expand Down

0 comments on commit 7158deb

Please sign in to comment.