1 #include "driver.h"
2
3
4 /* The timer clock which feeds the upper 4 bits of */
5 /* AY-3-8910 port A is based on the same clock */
6 /* feeding the sound CPU Z80. It is a divide by */
7 /* 5120, formed by a standard divide by 512, */
8 /* followed by a divide by 10 using a 4 bit */
9 /* bi-quinary count sequence. (See LS90 data sheet */
10 /* for an example). */
11 /* */
12 /* Bit 4 comes from the output of the divide by 1024 */
13 /* 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 */
14 /* Bit 3 comes from the QC output of the LS90 producing a sequence of */
15 /* 0, 0, 1, 1, 0, 0, 1, 1, 1, 0 */
16 /* Bit 6 comes from the QD output of the LS90 producing a sequence of */
17 /* 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 */
18 /* Bit 7 comes from the QA output of the LS90 producing a sequence of */
19 /* 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 */
20
21 static int frogger_timer[10] =
22 {
23 0x00, 0x10, 0x08, 0x18, 0x40, 0x90, 0x88, 0x98, 0x88, 0xd0
24 };
25
READ_HANDLER(frogger_portB_r)26 READ_HANDLER( frogger_portB_r )
27 {
28 /* need to protect from totalcycles overflow */
29 static int last_totalcycles = 0;
30
31 /* number of Z80 clock cycles to count */
32 static int clock;
33
34 int current_totalcycles;
35
36 current_totalcycles = cpu_gettotalcycles();
37 clock = (clock + (current_totalcycles-last_totalcycles)) % 5120;
38
39 last_totalcycles = current_totalcycles;
40
41 return frogger_timer[clock/512];
42 }
43
44
45
WRITE_HANDLER(frogger_sh_irqtrigger_w)46 WRITE_HANDLER( frogger_sh_irqtrigger_w )
47 {
48 static int last;
49
50
51 if (last == 0 && (data & 0x08) != 0)
52 {
53 /* setting bit 3 low then high triggers IRQ on the sound CPU */
54 cpu_cause_interrupt(1,0xff);
55 }
56
57 last = data & 0x08;
58 }
59
WRITE_HANDLER(frogger2_sh_irqtrigger_w)60 WRITE_HANDLER( frogger2_sh_irqtrigger_w )
61 {
62 static int last;
63
64
65 if (last == 0 && (data & 0x01) != 0)
66 {
67 /* setting bit 0 low then high triggers IRQ on the sound CPU */
68 cpu_cause_interrupt(1,0xff);
69 }
70
71 last = data & 0x01;
72 }
73