--- uae/src/hardfile.c 2018/04/24 16:39:03 1.1.1.2 +++ uae/src/hardfile.c 2018/04/24 16:39:58 1.1.1.3 @@ -16,45 +16,32 @@ #include "readcpu.h" #include "newcpu.h" #include "disk.h" -#include "xwin.h" #include "autoconf.h" +#include "filesys.h" #include "execlib.h" static int opencount = 0; -static int uaedevfd; -int numtracks = 512; -static ULONG hardfile_init(void) +static uae_u32 hardfile_open(void) { - ULONG tmp1, devicenode, bootnode; - int have36 = 1; - ULONG retval = m68k_dreg(regs, 0); - - filesys_init(); - - return retval; -} - -static ULONG hardfile_open(void) -{ - CPTR tmp1 = m68k_areg(regs, 1); /* IOReq */ + uaecptr tmp1 = m68k_areg(regs, 1); /* IOReq */ /* Check unit number */ - if (m68k_dreg(regs, 0) == 0) { + if (get_hardfile_data (m68k_dreg (regs, 0))) { opencount++; put_word (m68k_areg(regs, 6)+32, get_word (m68k_areg(regs, 6)+32) + 1); - put_long (tmp1+24, 0); /* io_Unit */ + put_long (tmp1+24, m68k_dreg (regs, 0)); /* io_Unit */ put_byte (tmp1+31, 0); /* io_Error */ put_byte (tmp1+8, 7); /* ln_type = NT_REPLYMSG */ return 0; } - put_long (tmp1+20, (ULONG)-1); - put_byte (tmp1+31, (UBYTE)-1); - return (ULONG)-1; + put_long (tmp1+20, (uae_u32)-1); + put_byte (tmp1+31, (uae_u8)-1); + return (uae_u32)-1; } -static ULONG hardfile_close(void) +static uae_u32 hardfile_close(void) { opencount--; put_word (m68k_areg(regs, 6)+32, get_word (m68k_areg(regs, 6)+32) - 1); @@ -62,20 +49,32 @@ static ULONG hardfile_close(void) return 0; } -static ULONG hardfile_expunge(void) +static uae_u32 hardfile_expunge(void) { return 0; /* Simply ignore this one... */ } -static ULONG hardfile_beginio(void) +static uae_u32 hardfile_beginio(void) { - ULONG tmp1, tmp2, dataptr, offset; - ULONG retval = m68k_dreg(regs, 0); + uae_u32 tmp1, tmp2, dataptr, offset; + uae_u32 retval = m68k_dreg(regs, 0); + int unit; + struct hardfiledata *hfd; tmp1 = m68k_areg(regs, 1); + unit = get_long (tmp1 + 24); +#undef DEBUGME +#ifdef DEBUGME + printf ("hardfile: unit = %d\n", unit); + printf ("hardfile: tmp1 = %08lx\n", (unsigned long)tmp1); + printf ("hardfile: cmd = %d\n", (int)get_word(tmp1+28)); +#endif + hfd = get_hardfile_data (unit); + put_byte (tmp1+8, NT_MESSAGE); put_byte (tmp1+31, 0); /* no error yet */ tmp2 = get_word (tmp1+28); /* io_Command */ +/* put_byte (tmp1 + 30, get_byte (tmp1 + 30) & ~1);*/ switch (tmp2) { case CMD_READ: dataptr = get_long (tmp1 + 40); @@ -87,15 +86,15 @@ static ULONG hardfile_beginio(void) tmp2 = get_long (tmp1 + 36); /* io_Length */ if (tmp2 & 511) goto bad_command; - if (tmp2 + offset > (ULONG)numtracks * 32 * 512) + if (tmp2 + offset > (uae_u32)hfd->size) goto bad_command; put_long (tmp1 + 32, tmp2); /* set io_Actual */ - lseek (uaedevfd, offset, SEEK_SET); + fseek (hfd->fd, offset, SEEK_SET); while (tmp2) { int i; char buffer[512]; - read (uaedevfd, buffer, 512); + fread (buffer, 1, 512, hfd->fd); for (i = 0; i < 512; i++, dataptr++) put_byte(dataptr, buffer[i]); tmp2 -= 512; @@ -113,17 +112,17 @@ static ULONG hardfile_beginio(void) tmp2 = get_long (tmp1 + 36); /* io_Length */ if (tmp2 & 511) goto bad_command; - if (tmp2 + offset > (ULONG)numtracks * 32 * 512) + if (tmp2 + offset > (uae_u32)hfd->size) goto bad_command; put_long (tmp1 + 32, tmp2); /* set io_Actual */ - lseek (uaedevfd, offset, SEEK_SET); + fseek (hfd->fd, offset, SEEK_SET); while (tmp2) { char buffer[512]; int i; for (i=0; i < 512; i++, dataptr++) buffer[i] = get_byte(dataptr); - write (uaedevfd, buffer, 512); + fwrite (buffer, 1, 512, hfd->fd); tmp2 -= 512; } break; @@ -132,11 +131,13 @@ static ULONG hardfile_beginio(void) break; case 18: /* GetDriveType */ + printf ("Shouldn't happen\n"); put_long (tmp1 + 32, 1); /* not exactly a 3.5" drive, but... */ break; case 19: /* GetNumTracks */ - put_long (tmp1 + 32, numtracks); + printf ("Shouldn't happen 2\n"); + put_long (tmp1 + 32, 0); break; /* Some commands that just do nothing and return zero */ @@ -156,40 +157,41 @@ static ULONG hardfile_beginio(void) default: /* Command not understood. */ - put_byte (tmp1+31, (UBYTE)-3); /* io_Error */ + put_byte (tmp1+31, (uae_u8)-3); /* io_Error */ retval = 0; break; } +#if 0 if ((get_byte (tmp1+30) & 1) == 0) { /* Not IOF_QUICK -- need to ReplyMsg */ m68k_areg(regs, 1) = tmp1; CallLib (get_long(4), -378); } +#endif return retval; } -static ULONG hardfile_abortio(void) +static uae_u32 hardfile_abortio(void) { - return (ULONG)-3; + return (uae_u32)-3; } void hardfile_install(void) { - ULONG functable, datatable, inittable; - ULONG initcode, openfunc, closefunc, expungefunc; - ULONG beginiofunc, abortiofunc; - - uaedevfd = open ("hardfile", O_RDWR | O_BINARY); + uae_u32 functable, datatable, inittable; + uae_u32 initcode, openfunc, closefunc, expungefunc; + uae_u32 beginiofunc, abortiofunc; - ROM_hardfile_resname = ds("hardfile.device"); + ROM_hardfile_resname = ds("uaehf.device"); ROM_hardfile_resid = ds("UAE hardfile.device 0.2"); - numtracks = hardfile_size / 16384; - /* initcode */ +#if 0 initcode = here(); calltrap(deftrap(hardfile_init)); dw(RTS); - +#else + initcode = filesys_initcode; +#endif /* Open */ openfunc = here(); calltrap(deftrap(hardfile_open)); dw(RTS); @@ -204,7 +206,14 @@ void hardfile_install(void) /* BeginIO */ beginiofunc = here(); - calltrap(deftrap(hardfile_beginio)); dw(RTS); + calltrap(deftrap(hardfile_beginio)); + dw (0x48E7); dw (0x8002); /* movem.l d0/a6,-(a7) */ + dw (0x0829); dw (0); dw (30); /* btst #0,30(a1) */ + dw (0x6608); /* bne.b +8 */ + dw (0x2C78); dw (0x0004); /* move.l 4,a6 */ + dw (0x4EAE); dw (-378); /* jsr ReplyMsg(a6) */ + dw (0x4CDF); dw (0x4001); /* movem.l (a7)+,d0/a6 */ + dw(RTS); /* AbortIO */ abortiofunc = here(); @@ -247,10 +256,4 @@ void hardfile_install(void) dl(functable); dl(datatable); dl(initcode); - - if (uaedevfd >= 0) { - CPTR initfunc; - - add_filesys_unit(NULL, "hardfile", 1); - } }