| version 1.12, 2004/08/12 17:57:36 | version 1.15, 2004/08/14 12:16:17 | 
| Line 17  void neitem_fdcbusy(UINT id) { | Line 17  void neitem_fdcbusy(UINT id) { | 
 |  |  | 
 | fdc.s.busy = FALSE; | fdc.s.busy = FALSE; | 
 | if (fdc.s.bufdir) { | if (fdc.s.bufdir) { | 
| TRACEOUT(("dma ready!")); | //              TRACEOUT(("dma ready!")); | 
 | dmac_sendready(TRUE); | dmac_sendready(TRUE); | 
 | } | } | 
 | (void)id; | (void)id; | 
 | } | } | 
 |  |  | 
| static void setbusy(UINT clock) { | static void setbusy(SINT32 clock) { | 
 |  |  | 
| fdc.s.busy = TRUE; | if (clock > 0) { | 
| nevent_set(NEVENT_FDC, clock, neitem_fdcbusy, NEVENT_ABSOLUTE); | fdc.s.busy = TRUE; | 
|  | nevent_set(NEVENT_FDC, clock, neitem_fdcbusy, NEVENT_ABSOLUTE); | 
|  | } | 
|  | else { | 
|  | fdc.s.busy = FALSE; | 
|  | nevent_reset(NEVENT_FDC); | 
|  | } | 
|  | } | 
|  |  | 
|  | static void setmotor(REG8 drvcmd) { | 
|  |  | 
|  | UINT    drv; | 
|  | SINT32  clock; | 
|  |  | 
|  | drv = drvcmd & 3; | 
|  | clock = CPU_CLOCK + CPU_BASECLOCK - CPU_REMCLOCK; | 
|  | if (drvcmd & 0x80) { | 
|  | if (fdc.s.motorevent[drv] == FDCMOTOR_STOP) { | 
|  | fdc.s.motorevent[drv] = FDCMOTOR_STARTING; | 
|  | fdc.s.motorclock[drv] = clock; | 
|  | } | 
|  | else if (fdc.s.motorevent[drv] == FDCMOTOR_STOPING) { | 
|  | fdc.s.motorevent[drv] = FDCMOTOR_READY; | 
|  | } | 
|  | } | 
|  | else { | 
|  | if ((fdc.s.motorevent[drv] == FDCMOTOR_STARTING) || | 
|  | (fdc.s.motorevent[drv] == FDCMOTOR_READY)) { | 
|  | fdc.s.motorevent[drv] = FDCMOTOR_STOPING; | 
|  | fdc.s.motorclock[drv] = clock; | 
|  | } | 
|  | } | 
|  | } | 
|  |  | 
|  | void fdc_callback(void) { | 
|  |  | 
|  | SINT32  clock; | 
|  | UINT    i; | 
|  |  | 
|  | clock = CPU_CLOCK + CPU_BASECLOCK - CPU_REMCLOCK; | 
|  | for (i=0; i<4; i++) { | 
|  | if (fdc.s.motorevent[i] == FDCMOTOR_STARTING) { | 
|  | if ((clock - fdc.s.motorclock[i]) >= (SINT32)pccore.realclock) { | 
|  | fdc.s.motorevent[i] = FDCMOTOR_READY; | 
|  | } | 
|  | } | 
|  | else if (fdc.s.motorevent[i] == FDCMOTOR_STOPING) { | 
|  | if ((clock - fdc.s.motorclock[i]) >= (SINT32)pccore.realclock) { | 
|  | fdc.s.motorevent[i] = FDCMOTOR_STOP; | 
|  | } | 
|  | } | 
|  | } | 
 | } | } | 
 |  |  | 
 | static REG8 getstat(void) { | static REG8 getstat(void) { | 
| Line 98  static REG8 type2cmd(REG8 sc) { | Line 149  static REG8 type2cmd(REG8 sc) { | 
 | FDDFILE fdd; | FDDFILE fdd; | 
 | UINT    size; | UINT    size; | 
 | REG8    stat; | REG8    stat; | 
 |  | #if defined(SUPPORT_DISKEXT) | 
 |  | SINT32  clock; | 
 |  | SINT32  curclock; | 
 |  | SINT32  nextclock; | 
 |  | UINT32  secinfo; | 
 |  | #endif | 
 |  |  | 
 | track = (fdc.s.c << 1) + fdc.s.h; | track = (fdc.s.c << 1) + fdc.s.h; | 
 | if (!(fdc.s.cmd & 0x20)) { | if (!(fdc.s.cmd & 0x20)) { | 
| Line 132  static REG8 type2cmd(REG8 sc) { | Line 189  static REG8 type2cmd(REG8 sc) { | 
 | fdc.s.bufpos = 0; | fdc.s.bufpos = 0; | 
 | fdc.s.bufsize = size; | fdc.s.bufsize = size; | 
 | fdc.s.curtime = 0; | fdc.s.curtime = 0; | 
 |  |  | 
 |  | #if defined(SUPPORT_DISKEXT) | 
 |  | // ウェイト値を計算 | 
 |  | clock = 0; | 
 |  | if (fdc.s.motorevent[fdc.s.drv] == FDCMOTOR_STARTING) { | 
 |  | curclock = CPU_CLOCK + CPU_BASECLOCK - CPU_REMCLOCK; | 
 |  | curclock -= fdc.s.motorclock[fdc.s.drv]; | 
 |  | if (curclock < (SINT32)pccore.realclock) { | 
 |  | nextclock = pccore.realclock - curclock; | 
 |  | TRACEOUT(("motor starting busy %d", nextclock)); | 
 |  | clock += nextclock; | 
 |  | } | 
 |  | } | 
 |  | secinfo = fdd->sec(fdd, fdc.s.media, track, sc); | 
 |  | if (secinfo) { | 
 |  | nextclock = LOW16(secinfo); | 
 |  | nextclock *= fdc.s.loopclock; | 
 |  | nextclock /= LOW16(secinfo >> 16); | 
 |  | curclock = nevent_getwork(NEVENT_RTC); | 
 |  | nextclock -= curclock; | 
 |  | if (nextclock < 0) { | 
 |  | nextclock += fdc.s.loopclock; | 
 |  | } | 
 |  | TRACEOUT(("wait clock -> %d [%d/%d]", nextclock, | 
 |  | LOW16(secinfo), LOW16(secinfo >> 16))); | 
 |  | clock += nextclock; | 
 |  | } | 
 |  | setbusy(max(clock, 500)); | 
 |  | #else | 
 |  | setbusy(500); | 
 |  | #endif | 
 | return(stat); | return(stat); | 
 | } | } | 
 |  |  | 
| Line 156  static REG8 crccmd(void) { | Line 244  static REG8 crccmd(void) { | 
 |  |  | 
 | track = (fdc.s.c << 1) + fdc.s.h; | track = (fdc.s.c << 1) + fdc.s.h; | 
 | fdd = fddfile + fdc.s.drv; | fdd = fddfile + fdc.s.drv; | 
 |  | TRACEOUT(("fdd->crc %d %d %d", fdc.s.drv, track, fdc.s.crcnum)); | 
 | stat = fdd->crc(fdd, fdc.s.media, track, fdc.s.crcnum, fdc.s.buffer); | stat = fdd->crc(fdd, fdc.s.media, track, fdc.s.crcnum, fdc.s.buffer); | 
 | if (stat & FDDSTAT_RECNFND) { | if (stat & FDDSTAT_RECNFND) { | 
 | fdc.s.crcnum = 0; | fdc.s.crcnum = 0; | 
| Line 165  static REG8 crccmd(void) { | Line 254  static REG8 crccmd(void) { | 
 | fdc.s.bufdir = FDCDIR_IN; | fdc.s.bufdir = FDCDIR_IN; | 
 | fdc.s.bufsize = 6; | fdc.s.bufsize = 6; | 
 | fdc.s.rreg = fdc.s.buffer[0]; | fdc.s.rreg = fdc.s.buffer[0]; | 
 |  | fdc.s.crcnum++; | 
 | } | } | 
 | else { | else { | 
 | fdc.s.bufdir = FDCDIR_NONE; | fdc.s.bufdir = FDCDIR_NONE; | 
| Line 199  static void bufposinc(void) { | Line 289  static void bufposinc(void) { | 
 | } | } | 
 | fdc.s.stat = stat; | fdc.s.stat = stat; | 
 | } | } | 
 | if (r) { |  | 
 | fdc.s.rreg = fdc.s.r + 1; |  | 
 | stat = type2cmd(fdc.s.rreg); |  | 
 | if (!(stat & FDDSTAT_RECNFND)) { |  | 
 | fdc.s.r = fdc.s.r + 1; |  | 
 | fdc.s.stat = stat; |  | 
 | } |  | 
 | else { |  | 
 | r = FALSE; |  | 
 | } |  | 
 | } |  | 
 | } | } | 
| if (!r) { | fdc.s.bufdir = FDCDIR_NONE; | 
| fdc.s.bufdir = FDCDIR_NONE; | dmac_sendready(FALSE); | 
| dmac_sendready(FALSE); | if (r) { | 
|  | fdc.s.rreg = fdc.s.r + 1; | 
|  | stat = type2cmd(fdc.s.rreg); | 
|  | if (!(stat & FDDSTAT_RECNFND)) { | 
|  | fdc.s.r = fdc.s.r + 1; | 
|  | fdc.s.stat = stat; | 
|  | } | 
 | } | } | 
 | } | } | 
 | } | } | 
| Line 225  void IOOUTCALL fdc_o(UINT port, REG8 val | Line 310  void IOOUTCALL fdc_o(UINT port, REG8 val | 
 | if ((port & (~7)) != 0x0ff8) { | if ((port & (~7)) != 0x0ff8) { | 
 | return; | return; | 
 | } | } | 
| //      TRACEOUT(("fdc %.4x,%.2x [%.4x]", port, value, Z80_PC)); | TRACEOUT(("fdc %.4x,%.2x [%.4x]", port, value, Z80_PC)); | 
 | switch(port & 7) { | switch(port & 7) { | 
 | case 0:                                                                 // コマンド | case 0:                                                                 // コマンド | 
 | fdc.s.cmd = value; | fdc.s.cmd = value; | 
| Line 243  void IOOUTCALL fdc_o(UINT port, REG8 val | Line 328  void IOOUTCALL fdc_o(UINT port, REG8 val | 
 | setbusy(20); | setbusy(20); | 
 | switch(cmd) { | switch(cmd) { | 
 | case 0x00:                                                              // リストア | case 0x00:                                                              // リストア | 
 | //      if (value & 8) {                                        // LAYDOCK |  | 
 | //              setbusy(0); |  | 
 | //      } |  | 
 | fdc.s.motor = 0x80;                                     // モーターOn? | fdc.s.motor = 0x80;                                     // モーターOn? | 
 | fdc.s.c = 0; | fdc.s.c = 0; | 
 | fdc.s.step = 1; | fdc.s.step = 1; | 
| Line 297  void IOOUTCALL fdc_o(UINT port, REG8 val | Line 379  void IOOUTCALL fdc_o(UINT port, REG8 val | 
 | case 0x09: | case 0x09: | 
 | case 0x0a:                                                              // ライトデータ | case 0x0a:                                                              // ライトデータ | 
 | case 0x0b: | case 0x0b: | 
 | setbusy(500); |  | 
 | fdc.s.stat = type2cmd(fdc.s.r); | fdc.s.stat = type2cmd(fdc.s.r); | 
 | break; | break; | 
 |  |  | 
| Line 309  void IOOUTCALL fdc_o(UINT port, REG8 val | Line 390  void IOOUTCALL fdc_o(UINT port, REG8 val | 
 | case 0x0d:                                                              // フォースインタラプト | case 0x0d:                                                              // フォースインタラプト | 
 | setbusy(0);                                                     // 必要ない? | setbusy(0);                                                     // 必要ない? | 
 | //                                      fdc.s.skip = 0;                                         // 000330 | //                                      fdc.s.skip = 0;                                         // 000330 | 
 |  | fdc.s.stat = 0; | 
 | dmac_sendready(FALSE); | dmac_sendready(FALSE); | 
 | break; | break; | 
 |  |  | 
| Line 358  void IOOUTCALL fdc_o(UINT port, REG8 val | Line 440  void IOOUTCALL fdc_o(UINT port, REG8 val | 
 | fdc.s.r = 0;                                            // SACOM TELENET | fdc.s.r = 0;                                            // SACOM TELENET | 
 | fdc.s.rreg = 0; | fdc.s.rreg = 0; | 
 | } | } | 
 |  | setmotor(value); | 
 | break; | break; | 
 | } | } | 
 | } | } | 
 |  |  | 
 | REG8 IOINPCALL fdc_i(UINT port) { | REG8 IOINPCALL fdc_i(UINT port) { | 
 |  |  | 
 | // static       BYTE    timeoutwait; |  | 
 | // static       BYTE    last_r; |  | 
 | // static       short   last_off; |  | 
 | REG8    ret; | REG8    ret; | 
 |  |  | 
 |  | //      TRACEOUT(("fdc inp %.4x", port)); | 
 |  |  | 
 | if ((port & (~7)) != 0x0ff8) { | if ((port & (~7)) != 0x0ff8) { | 
 | return(0xff); | return(0xff); | 
 | } | } | 
 | #if 0 |  | 
 | if ((port &= 0xf) != 8) { |  | 
 | last_r = -1; |  | 
 | last_off = -1; |  | 
 | timeoutwait = 4; |  | 
 | } |  | 
 | #endif |  | 
 | switch(port & 7) { | switch(port & 7) { | 
 | case 0:                                                                 // ステータス | case 0:                                                                 // ステータス | 
 | ret = fdc.s.busy; | ret = fdc.s.busy; | 
| Line 398  REG8 IOINPCALL fdc_i(UINT port) { | Line 473  REG8 IOINPCALL fdc_i(UINT port) { | 
 | if (!(ret & 0x02)) { | if (!(ret & 0x02)) { | 
 | dmac_sendready(FALSE); | dmac_sendready(FALSE); | 
 | } | } | 
 |  | TRACEOUT(("ret->%.2x", ret)); | 
 | return(ret); | return(ret); | 
 |  |  | 
 | case 1:                                                                 // トラック | case 1:                                                                 // トラック | 
| Line 410  REG8 IOINPCALL fdc_i(UINT port) { | Line 486  REG8 IOINPCALL fdc_i(UINT port) { | 
 | if (fdc.s.motor) { | if (fdc.s.motor) { | 
 | if (fdc.s.bufdir == FDCDIR_IN) { | if (fdc.s.bufdir == FDCDIR_IN) { | 
 | fdc.s.data = fdc.s.buffer[fdc.s.bufpos]; | fdc.s.data = fdc.s.buffer[fdc.s.bufpos]; | 
| TRACEOUT(("read %.2x %.2x [%.4x]", fdc.s.data, fdc.s.bufpos, Z80_PC)); | TRACEOUT(("read %.2x - %.2x [%.4x]", fdc.s.bufpos, fdc.s.data, Z80_PC)); | 
 | bufposinc(); | bufposinc(); | 
 | } | } | 
 | } | } | 
| Line 440  void fdc_reset(void) { | Line 516  void fdc_reset(void) { | 
 | ZeroMemory(&fdc, sizeof(fdc)); | ZeroMemory(&fdc, sizeof(fdc)); | 
 | fdc.s.step = 1; | fdc.s.step = 1; | 
 | fdc.s.equip = xmilcfg.fddequip; | fdc.s.equip = xmilcfg.fddequip; | 
 |  | fdc.s.loopclock = pccore.realclock / 5; | 
 | } | } | 
 |  |  |