1 /***************************************************************************
2
3 machine.c
4
5 Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
6 I/O ports)
7
8 ***************************************************************************/
9
10 #include "driver.h"
11
12 unsigned char *toypop_sharedram_1, *toypop_sharedram_2, *toypop_customio, *toypop_speedup;
13 static unsigned char interrupt_enable_68k;
14
toypop_init_machine(void)15 void toypop_init_machine(void)
16 {
17 interrupt_enable_68k = 0;
18 }
19
READ_HANDLER(toypop_cycle_r)20 READ_HANDLER( toypop_cycle_r )
21 {
22 /* to speed up emulation, we check for the loop the 68000 CPU sits in almost all of the time
23 and end the current iteration (things will start going again with the next IRQ) */
24 if (READ_WORD(&toypop_speedup[0]) == 0 && cpu_get_pc() == 0x11c) cpu_spinuntil_int();
25
26 return READ_WORD(&toypop_speedup[0]);
27 }
28
READ_HANDLER(toypop_sharedram_1_r)29 READ_HANDLER( toypop_sharedram_1_r )
30 {
31 /* to speed up emulation, we check for the loop the sound CPU sits in most of the time
32 and end the current iteration (things will start going again with the next IRQ) */
33 if (offset == 0xa1 - 0x40 && toypop_sharedram_1[offset] == 0 && cpu_get_pc() == 0xe4df)
34 cpu_spinuntil_int();
35 return toypop_sharedram_1[offset];
36 }
37
WRITE_HANDLER(toypop_sharedram_1_w)38 WRITE_HANDLER( toypop_sharedram_1_w )
39 {
40 toypop_sharedram_1[offset] = data;
41 }
42
READ_HANDLER(toypop_sharedram_2_r)43 READ_HANDLER( toypop_sharedram_2_r )
44 {
45 return toypop_sharedram_2[offset >> 1];
46 }
47
WRITE_HANDLER(toypop_sharedram_2_w)48 WRITE_HANDLER( toypop_sharedram_2_w )
49 {
50 toypop_sharedram_2[offset >> 1] = data & 0xff;
51 }
52
WRITE_HANDLER(toypop_interrupt_enable_w)53 WRITE_HANDLER( toypop_interrupt_enable_w )
54 {
55 interrupt_enable_68k = 1;
56 }
57
WRITE_HANDLER(toypop_interrupt_disable_w)58 WRITE_HANDLER( toypop_interrupt_disable_w )
59 {
60 interrupt_enable_68k = 0;
61 }
62
toypop_interrupt(void)63 int toypop_interrupt(void)
64 {
65 if (interrupt_enable_68k)
66 // not sure whether the cause of the interrupt is a VBLANK or the main CPU.
67 // Anyway, this works
68 return 1;
69 else
70 return ignore_interrupt();
71 }
72
READ_HANDLER(toypop_customio_r)73 READ_HANDLER( toypop_customio_r )
74 {
75 int mode = toypop_customio[8];
76
77 /* mode 5 values are actually checked against these numbers during power up */
78 if (mode == 5)
79 switch (offset) {
80 case 2:
81 return 15;
82 case 6:
83 return 12;
84 case 16:
85 return 6;
86 case 17:
87 return 9;
88 case 32:
89 return 6;
90 case 33:
91 return 9;
92 default:
93 return toypop_customio[offset];
94 }
95 else
96 switch (offset) {
97 case 4:
98 return readinputport(0) & 0x0f;
99 case 5:
100 return readinputport(0) >> 4;
101 case 6:
102 return readinputport(1) & 0x0f;
103 case 7:
104 return readinputport(1) >> 4;
105 case 16:
106 return readinputport(2) & 0x0f;
107 case 17:
108 return readinputport(2) >> 4;
109 case 18:
110 return readinputport(3) & 0x0f;
111 case 19:
112 return readinputport(3) >> 4;
113 default:
114 return toypop_customio[offset];
115 }
116 }
117
WRITE_HANDLER(toypop_cpu_reset_w)118 WRITE_HANDLER( toypop_cpu_reset_w )
119 {
120 // this makes the service mode work
121 cpu_set_reset_line(1, PULSE_LINE);
122 }
123