| version 1.5, 2004/08/11 12:08:16 | version 1.7, 2004/08/11 16:09:04 | 
| Line 93  static void ctcstep(CTCCH *ch) { | Line 93  static void ctcstep(CTCCH *ch) { | 
 | intr = ctcwork(ch); | intr = ctcwork(ch); | 
 | if (intr) { | if (intr) { | 
 | ch->intr |= intr; | ch->intr |= intr; | 
 | TRACEOUT(("-> ievent_set")); |  | 
 | ievent_set(IEVENT_CTC0 + ch->num); | ievent_set(IEVENT_CTC0 + ch->num); | 
 | } | } | 
 | } | } | 
| Line 107  static void ctcnextevent(CTCCH *ch) { | Line 106  static void ctcnextevent(CTCCH *ch) { | 
 | if (ch->intr) { | if (ch->intr) { | 
 | return; | return; | 
 | } | } | 
| event = 0x04000000; | event = 0x01000000; | 
 | for (i=0; i<3; i++) { | for (i=0; i<3; i++) { | 
 | if ((ch->cmd[i] & 0x82) == 0x80) { | if ((ch->cmd[i] & 0x82) == 0x80) { | 
 | clock = ch->count[i]; | clock = ch->count[i]; | 
 | if (ch->cmd[i] & 0x40) { | if (ch->cmd[i] & 0x40) { | 
 | clock = clock * 2; | clock = clock * 2; | 
 | } | } | 
 | TRACEOUT(("ch %d -> %d :%.2x:%.8x", i, clock, ch->cmd[i], ch->count[i])); |  | 
 | event = min(event, clock); | event = min(event, clock); | 
 | } | } | 
 | } | } | 
| Line 127  static void ctcnextevent(CTCCH *ch) { | Line 125  static void ctcnextevent(CTCCH *ch) { | 
 | clock = clock * 2; | clock = clock * 2; | 
 | } | } | 
 | } | } | 
 | TRACEOUT(("ch %d -> %d", 3, clock)); |  | 
 | event = min(event, clock); | event = min(event, clock); | 
 | } | } | 
 | event /= 2; |  | 
 | event *= pccore.multiple; | event *= pccore.multiple; | 
 |  | event /= 2; | 
 |  | if (event == 0) { | 
 |  | event = 1; | 
 |  | } | 
 | nevent_set(NEVENT_CTC0 + ch->num, event, neitem_ctc, NEVENT_ABSOLUTE); | nevent_set(NEVENT_CTC0 + ch->num, event, neitem_ctc, NEVENT_ABSOLUTE); | 
 | TRACEOUT(("ctc -> %d (%x)", event, event)); |  | 
 | } | } | 
 |  |  | 
 | void neitem_ctc(UINT id) { | void neitem_ctc(UINT id) { | 
| Line 145  void neitem_ctc(UINT id) { | Line 144  void neitem_ctc(UINT id) { | 
 | intr = ctcwork(ch); | intr = ctcwork(ch); | 
 | if (intr) { | if (intr) { | 
 | ch->intr |= intr; | ch->intr |= intr; | 
 | TRACEOUT(("-> ievent_set")); |  | 
 | ievent_set(IEVENT_CTC0 + ch->num); | ievent_set(IEVENT_CTC0 + ch->num); | 
 | } | } | 
 | else { | else { | 
| Line 164  BRESULT ieitem_ctc(UINT id) { | Line 162  BRESULT ieitem_ctc(UINT id) { | 
 | ch = ctc.ch + (id - IEVENT_CTC0); | ch = ctc.ch + (id - IEVENT_CTC0); | 
 | intr = ctcwork(ch); | intr = ctcwork(ch); | 
 | intr |= ch->intr; | intr |= ch->intr; | 
 | TRACEOUT(("ieitem_ctc %d - %.2x", id - IEVENT_CTC0, intr)); |  | 
 | r = FALSE; | r = FALSE; | 
 | if (intr) { | if (intr) { | 
 | for (i=0, bit=1; i<4; i++, bit<<=1) { | for (i=0, bit=1; i<4; i++, bit<<=1) { | 
| Line 185  BRESULT ieitem_ctc(UINT id) { | Line 182  BRESULT ieitem_ctc(UINT id) { | 
 | else if (!r) { | else if (!r) { | 
 | r = TRUE; | r = TRUE; | 
 | intr ^= bit; | intr ^= bit; | 
| TRACEOUT(("z80int %d", i)); | Z80_INTERRUPT((REG8)(ch->vector + (i << 1))); | 
| Z80_INT((REG8)(ch->vector + (i << 1))); |  | 
 | } | } | 
 | } | } | 
 | } | } | 
 | } | } | 
 | TRACEOUT(("--> %.2x", intr)); |  | 
 | ch->intr = intr; | ch->intr = intr; | 
 | if (intr) { | if (intr) { | 
 | TRACEOUT(("-> ievent_set")); |  | 
 | ievent_set(IEVENT_CTC0 + ch->num); | ievent_set(IEVENT_CTC0 + ch->num); | 
 | } | } | 
 | else { | else { | 
| Line 204  BRESULT ieitem_ctc(UINT id) { | Line 198  BRESULT ieitem_ctc(UINT id) { | 
 | } | } | 
 |  |  | 
 |  |  | 
 |  |  | 
 |  |  | 
 | #if 0 |  | 
 | void x1_ctc_int(void) { |  | 
 |  |  | 
 | CTCCH   *ch; |  | 
 | UINT    r; |  | 
 | SINT32  clk0; |  | 
 | SINT32  clk4; |  | 
 | SINT32  clk2; |  | 
 | SINT32  subcnt; |  | 
 | UINT    i; |  | 
 | REG8    bit; |  | 
 | REG8    ctcint_flg; |  | 
 |  |  | 
 | ctcint_flg = Z80_ABLEINTERRUPT(); |  | 
 |  |  | 
 | clk4 = pccore.HSYNC_CLK; |  | 
 | clk2 = clk4 >> 1; |  | 
 |  |  | 
 | if (pccore.ROM_TYPE >= 2) { |  | 
 | ch = ctc.ch + 0; |  | 
 | r = 3; |  | 
 | } |  | 
 | else { |  | 
 | ch = ctc.ch + 2; |  | 
 | r = 1; |  | 
 | } |  | 
 |  |  | 
 | do { |  | 
 | clk0 = 0; |  | 
 | bit = 1; |  | 
 | for (i=0; i<4; i++) { |  | 
 | if (!(ch->cmd[i] & 0x02)) { |  | 
 | if (ch->count[i] <= 0) { |  | 
 | ch->count[i] += ch->countmax[i]; |  | 
 | } |  | 
 | if (!(ch->cmd[i] & 0x40)) { |  | 
 | subcnt = clk4; |  | 
 | } |  | 
 | else if (i == 3) { |  | 
 | subcnt = clk0; |  | 
 | } |  | 
 | else { |  | 
 | subcnt = clk2; |  | 
 | } |  | 
 | ch->count[i] -= subcnt; |  | 
 | if (ch->count[i] <= 0) { |  | 
 | ch->int_flag |= bit; |  | 
 | if (!i) { |  | 
 | clk0 = 1; |  | 
 | } |  | 
 | } |  | 
 | } |  | 
 | bit <<= 1; |  | 
 | } |  | 
 |  |  | 
 | bit = 1; |  | 
 | for (i=0; i<4; i++) { |  | 
 | if (ch->int_flag & bit) { |  | 
 | if (!(ch->cmd[i] & 0x80)) { |  | 
 | ch->int_flag ^= bit; |  | 
 | } |  | 
 | else if (ctcint_flg) { |  | 
 | ctcint_flg = 0; |  | 
 | ch->int_flag ^= bit; |  | 
 | //                                      TRACEOUT(("ctc%u int -- %d", 3 - r, i)); |  | 
 | Z80_INT((REG8)(ch->vector + (i << 1))); |  | 
 | } |  | 
 | } |  | 
 | bit <<= 1; |  | 
 | } |  | 
 | ch++; |  | 
 | } while(--r); |  | 
 | } |  | 
 | #endif |  | 
 |  |  | 
 |  |  | 
 | // ---- | // ---- | 
 |  |  | 
 | static void ctcch_o(CTCCH *ch, UINT port, REG8 value) { | static void ctcch_o(CTCCH *ch, UINT port, REG8 value) { | 
| Line 367  void IOOUTCALL ctc_o(UINT port, REG8 val | Line 283  void IOOUTCALL ctc_o(UINT port, REG8 val | 
 |  |  | 
 | CTCCH   *ch; | CTCCH   *ch; | 
 |  |  | 
| TRACEOUT(("ctc - %.4x %.2x [%.4x]", port, value, Z80_PC)); | //      TRACEOUT(("ctc - %.4x %.2x [%.4x]", port, value, Z80_PC)); | 
 | ch = getctcch(port); | ch = getctcch(port); | 
 | if (ch != NULL) { | if (ch != NULL) { | 
 | ctcch_o(ch, port, value); | ctcch_o(ch, port, value); |