Skip to content

Commit d7f3937

Browse files
committed
jgz80: Differentiate pulsing interrupts vs holding interrupts asserted
1 parent 6eeaa18 commit d7f3937

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

z80.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ static inline unsigned process_interrupts(z80* const z) {
669669
}
670670

671671
if (z->nmi_pending) {
672-
z->nmi_pending = 0;
672+
z->nmi_pending &= ~Z80_PULSE;
673673
z->halted = 0;
674674
z->iff1 = 0;
675675
inc_r(z);
@@ -679,8 +679,8 @@ static inline unsigned process_interrupts(z80* const z) {
679679
return cyc;
680680
}
681681

682-
if (z->int_pending && z->iff1) {
683-
//z->int_pending = 0; // Commented when function to clear the line was added
682+
if (z->irq_pending && z->iff1) {
683+
z->irq_pending &= ~Z80_PULSE;
684684
z->halted = 0;
685685
z->iff1 = 0;
686686
z->iff2 = 0;
@@ -689,7 +689,7 @@ static inline unsigned process_interrupts(z80* const z) {
689689
switch (z->interrupt_mode) {
690690
case 0:
691691
cyc += 11;
692-
cyc += exec_opcode(z, z->int_data);
692+
cyc += exec_opcode(z, z->irq_data);
693693
break;
694694

695695
case 1:
@@ -699,7 +699,7 @@ static inline unsigned process_interrupts(z80* const z) {
699699

700700
case 2:
701701
cyc += 19;
702-
call(z, rw(z, (z->i << 8) | z->int_data));
702+
call(z, rw(z, (z->i << 8) | z->irq_data));
703703
break;
704704

705705
default:
@@ -748,9 +748,9 @@ Z80_EXPORT void z80_init(z80* const z) {
748748
z->iff1 = 0;
749749
z->iff2 = 0;
750750
z->halted = 0;
751-
z->int_pending = 0;
751+
z->irq_pending = 0;
752752
z->nmi_pending = 0;
753-
z->int_data = 0;
753+
z->irq_data = 0;
754754
}
755755

756756
Z80_EXPORT void z80_reset(z80* const z) {
@@ -1267,19 +1267,32 @@ Z80_EXPORT void z80_debug_output(z80* const z) {
12671267
}
12681268
#endif /* Z80_DEBUG */
12691269

1270-
// function to call when an NMI is to be serviced
1271-
Z80_EXPORT void z80_gen_nmi(z80* const z) {
1272-
z->nmi_pending = 1;
1270+
// functions to call when an NMI is to be serviced
1271+
Z80_EXPORT void z80_assert_nmi(z80* const z) {
1272+
z->nmi_pending |= Z80_ASSERT;
12731273
}
12741274

1275-
// function to call when an INT is to be serviced
1276-
Z80_EXPORT void z80_gen_int(z80* const z, uint8_t data) {
1277-
z->int_pending = 1;
1278-
z->int_data = data;
1275+
Z80_EXPORT void z80_pulse_nmi(z80* const z) {
1276+
z->nmi_pending |= Z80_PULSE;
12791277
}
12801278

1281-
Z80_EXPORT void z80_clr_int(z80* const z) {
1282-
z->int_pending = 0;
1279+
Z80_EXPORT void z80_clr_nmi(z80* const z) {
1280+
z->nmi_pending = 0;
1281+
}
1282+
1283+
// functions to call when an INT is to be serviced
1284+
Z80_EXPORT void z80_assert_irq(z80* const z, uint8_t data) {
1285+
z->irq_pending |= Z80_ASSERT;
1286+
z->irq_data = data;
1287+
}
1288+
1289+
Z80_EXPORT void z80_pulse_irq(z80* const z, uint8_t data) {
1290+
z->irq_pending |= Z80_PULSE;
1291+
z->irq_data = data;
1292+
}
1293+
1294+
Z80_EXPORT void z80_clr_irq(z80* const z) {
1295+
z->irq_pending = 0;
12831296
}
12841297

12851298
// executes a non-prefixed opcode

z80.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
#define Z80_EXPORT
2020
#endif
2121

22+
enum {
23+
Z80_PULSE = 1,
24+
Z80_ASSERT = 2
25+
};
26+
2227
typedef struct z80 z80;
2328
struct z80 {
2429
uint8_t (*read_byte)(void*, uint16_t);
@@ -40,10 +45,11 @@ struct z80 {
4045
uint8_t i, r; // interrupt vector, memory refresh
4146
uint8_t iff_delay;
4247
uint8_t interrupt_mode;
43-
uint8_t int_data;
48+
uint8_t irq_data;
49+
uint8_t irq_pending;
50+
uint8_t nmi_pending;
4451
bool iff1 : 1, iff2 : 1;
4552
bool halted : 1;
46-
bool int_pending : 1, nmi_pending : 1;
4753
};
4854

4955
Z80_EXPORT void z80_init(z80* const z);
@@ -53,8 +59,11 @@ Z80_EXPORT void z80_set_sp(z80* const z, uint16_t sp);
5359
Z80_EXPORT unsigned z80_step(z80* const z); /* return cycles used */
5460
Z80_EXPORT unsigned z80_step_n(z80* const z, unsigned cycles);
5561
Z80_EXPORT void z80_debug_output(z80* const z);
56-
Z80_EXPORT void z80_gen_nmi(z80* const z);
57-
Z80_EXPORT void z80_gen_int(z80* const z, uint8_t data);
58-
Z80_EXPORT void z80_clr_int(z80* const z);
62+
Z80_EXPORT void z80_assert_nmi(z80* const z);
63+
Z80_EXPORT void z80_pulse_nmi(z80* const z);
64+
Z80_EXPORT void z80_clr_nmi(z80* const z);
65+
Z80_EXPORT void z80_assert_irq(z80* const z, uint8_t data);
66+
Z80_EXPORT void z80_pulse_irq(z80* const z, uint8_t data);
67+
Z80_EXPORT void z80_clr_irq(z80* const z);
5968

6069
#endif // Z80_Z80_H_

0 commit comments

Comments
 (0)