src/mame/machine/namco06.c
| r4939 | r4940 | |
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | | The following Namco custom chips are all instances of the same 4-bit MCU, |
| 4 | | the Fujitsu MB8843 (42-pin DIP package) and MB8842/MB8844 (28-pin DIP), |
| 5 | | differently programmed. |
| 3 | Namco 06XX |
| 6 | 4 | |
| 7 | | chip MCU pins function |
| 8 | | ---- ------ ---- -------- |
| 9 | | 50XX MB8842 28 player score handling (protection) |
| 10 | | 51XX MB8843 42 I/O (coin management built-in) |
| 11 | | 52XX MB8843 42 sample playback |
| 12 | | 53XX MB8843 42 I/O (steering wheel support) |
| 13 | | 54XX MB8844 28 explosion (noise) generator |
| 5 | This chip is used as an interface to up to 4 other custom chips. |
| 6 | It signals IRQs to the custom MCUs when writes happen, and generates |
| 7 | NMIs to the controlling CPU to drive reads based on a clock. |
| 14 | 8 | |
| 15 | | 06XX interface: |
| 16 | | --------------- |
| 17 | | Galaga 51XX ---- ---- 54XX |
| 18 | | Bosconian (CPU board) 51XX ---- 50XX 54XX |
| 19 | | Bosconian (Video board) 50XX 52XX ---- ---- |
| 20 | | Xevious 51XX ---- 50XX 54XX |
| 21 | | Dig Dug 51XX 53XX ---- ---- |
| 22 | | Pole Position / PP II 51XX 53XX 52XX 54XX |
| 9 | SD0-SD7 are data I/O lines connecting to the controlling CPU |
| 10 | SEL selects either control (1) or data (0), usually connected to |
| 11 | an address line of the controlling CPU |
| 12 | /NMI is an NMI signal line for the controlling CPU |
| 23 | 13 | |
| 14 | ID0-ID7 are data I/O lines connecting to the other custom chips |
| 15 | /IO1-/IO4 are IRQ signal lines for each custom chip |
| 24 | 16 | |
| 25 | | Pinouts: |
| 17 | +------+ |
| 18 | [1]|1 28|Vcc |
| 19 | ID7|2 27|SD7 |
| 20 | ID6|3 26|SD6 |
| 21 | ID5|4 25|SD5 |
| 22 | ID4|5 24|SD4 |
| 23 | ID3|6 23|SD3 |
| 24 | ID2|7 22|SD2 |
| 25 | ID1|8 21|SD1 |
| 26 | ID0|9 20|SD0 |
| 27 | /IO1|10 19|/NMI |
| 28 | /IO2|11 18|/CS |
| 29 | /IO3|12 17|CLOCK |
| 30 | /IO4|13 16|R/W |
| 31 | GND|14 15|SEL |
| 32 | +------+ |
| 26 | 33 | |
| 27 | | MB8843 MB8842/MB8844 |
| 28 | | +------+ +------+ |
| 29 | | EXTAL|1 42|Vcc EXTAL|1 28|Vcc |
| 30 | | XTAL|2 41|K3 XTAL|2 27|K3 |
| 31 | | /RESET|3 40|K2 /RESET|3 26|K2 |
| 32 | | /IRQ|4 39|K1 O0|4 25|K1 |
| 33 | | SO|5 38|K0 O1|5 24|K0 |
| 34 | | SI|6 37|R15 O2|6 23|R10 /IRQ |
| 35 | | /SC /TO|7 36|R14 O3|7 22|R9 /TC |
| 36 | | /TC|8 35|R13 O4|8 21|R8 |
| 37 | | P0|9 34|R12 O5|9 20|R7 |
| 38 | | P1|10 33|R11 O6|10 19|R6 |
| 39 | | P2|11 32|R10 O7|11 18|R5 |
| 40 | | P3|12 31|R9 R0|12 17|R4 |
| 41 | | O0|13 30|R8 R1|13 16|R3 |
| 42 | | O1|14 29|R7 GND|14 15|R2 |
| 43 | | O2|15 28|R6 +------+ |
| 44 | | O3|16 27|R5 |
| 45 | | O4|17 26|R4 |
| 46 | | O5|18 25|R3 |
| 47 | | O6|19 24|R2 |
| 48 | | O7|20 23|R1 |
| 49 | | GND|21 22|R0 |
| 50 | | +------+ |
| 34 | [1] on polepos, galaga, xevious, and bosco: connected to K3 of the 51xx |
| 35 | on bosco and xevious, connected to R8 of the 50xx |
| 51 | 36 | |
| 52 | 37 | |
| 53 | | O O R R R K |
| 54 | | 50XX O O I I I |
| 55 | | 54XX O O I O I |
| 38 | 06XX interface: |
| 39 | --------------- |
| 40 | Galaga 51XX ---- ---- 54XX |
| 41 | Bosconian (CPU board) 51XX ---- 50XX 54XX |
| 42 | Bosconian (Video board) 50XX 52XX ---- ---- |
| 43 | Xevious 51XX ---- 50XX 54XX |
| 44 | Dig Dug 51XX 53XX ---- ---- |
| 45 | Pole Position / PP II 51XX 53XX 52XX 54XX |
| 56 | 46 | |
| 57 | | P O O R R R R K |
| 58 | | 51XX O O O I I I I I |
| 59 | | 52XX O O O I I O O I |
| 60 | | 53XX O? O O I I I I I |
| 61 | 47 | |
| 48 | Galaga writes: |
| 49 | control = 10(000), data = FF at startup |
| 50 | control = 71(011), read 3, control = 10 |
| 51 | control = A1(101), write 4, control = 10 |
| 52 | control = A8(101), write 12, control = 10 |
| 62 | 53 | |
| 63 | | For the 52XX, see sound/namco52.c |
| 54 | Xevious writes: |
| 55 | control = 10 at startup |
| 56 | control = A1(101), write 6, control = 10 |
| 57 | control = 71(011), read 3, control = 10 |
| 58 | control = 64(011), write 1, control = 10 |
| 59 | control = 74(011), read 4, control = 10 |
| 60 | control = 68(011), write 7, control = 10 |
| 64 | 61 | |
| 65 | | For the 54XX, see audio/namco54.c |
| 62 | Dig Dug writes: |
| 63 | control = 10(000), data = 10 at startup |
| 64 | control = A1(101), write 3, control = 10 |
| 65 | control = 71(011), read 3, control = 10 |
| 66 | control = D2(110), read 2, control = 10 |
| 66 | 67 | |
| 68 | Bosco writes: |
| 69 | control = 10(000), data = FF at startup |
| 70 | control = C8(110), write 17, control = 10 |
| 71 | control = 61(011), write 1, control = 10 |
| 72 | control = 71(011), read 3, control = 10 |
| 73 | control = 94(100), read 4, control = 10 |
| 74 | control = 64(011), write 1, control = 10 |
| 75 | control = 84(100), write 5, control = 10 |
| 76 | |
| 77 | |
| 78 | control = 34(001), write 1, control = 10 |
| 79 | |
| 67 | 80 | ***************************************************************************/ |
| 68 | 81 | |
| 69 | 82 | #include "driver.h" |
| r4939 | r4940 | |
| 83 | 96 | typedef struct _namco_06xx_state namco_06xx_state; |
| 84 | 97 | struct _namco_06xx_state |
| 85 | 98 | { |
| 86 | | UINT8 command; |
| 99 | UINT8 control; |
| 87 | 100 | emu_timer *nmi_timer; |
| 88 | 101 | const device_config *nmicpu; |
| 89 | 102 | const device_config *device[4]; |
| r4939 | r4940 | |
| 121 | 134 | READ8_DEVICE_HANDLER( namco_06xx_data_r ) |
| 122 | 135 | { |
| 123 | 136 | namco_06xx_state *state = get_safe_token(device); |
| 137 | UINT8 result = 0xff; |
| 138 | int devnum; |
| 124 | 139 | |
| 125 | 140 | LOG(("%s: 06XX '%s' read offset %d\n",cpuexec_describe_context(device->machine),device->tag,offset)); |
| 126 | 141 | |
| 127 | | if (!(state->command & 0x10)) |
| 142 | if (!(state->control & 0x10)) |
| 128 | 143 | { |
| 129 | | logerror("%s: 06XX '%s' read in write mode %02x\n",cpuexec_describe_context(device->machine),device->tag,state->command); |
| 144 | logerror("%s: 06XX '%s' read in write mode %02x\n",cpuexec_describe_context(device->machine),device->tag,state->control); |
| 130 | 145 | return 0; |
| 131 | 146 | } |
| 132 | 147 | |
| 133 | | switch (state->command & 0xf) |
| 134 | | { |
| 135 | | case 0x1: return (state->read[0] != NULL) ? (*state->read[0])(state->device[0],0) : 0xff; |
| 136 | | case 0x2: return (state->read[1] != NULL) ? (*state->read[1])(state->device[1],0) : 0xff; |
| 137 | | case 0x4: return (state->read[2] != NULL) ? (*state->read[2])(state->device[2],0) : 0xff; |
| 138 | | case 0x8: return (state->read[3] != NULL) ? (*state->read[3])(state->device[3],0) : 0xff; |
| 139 | | default: |
| 140 | | logerror("%s: 06XX '%s' read in unsupported mode %02x\n",cpuexec_describe_context(device->machine),device->tag,state->command); |
| 141 | | return 0xff; |
| 142 | | } |
| 148 | for (devnum = 0; devnum < 4; devnum++) |
| 149 | if ((state->control & (1 << devnum)) && state->read[devnum] != NULL) |
| 150 | result &= (*state->read[devnum])(state->device[devnum], 0); |
| 151 | |
| 152 | return result; |
| 143 | 153 | } |
| 144 | 154 | |
| 145 | 155 | |
| 146 | 156 | WRITE8_DEVICE_HANDLER( namco_06xx_data_w ) |
| 147 | 157 | { |
| 148 | 158 | namco_06xx_state *state = get_safe_token(device); |
| 159 | int devnum; |
| 149 | 160 | |
| 150 | 161 | LOG(("%s: 06XX '%s' write offset %d = %02x\n",cpuexec_describe_context(device->machine),device->tag,offset,data)); |
| 151 | 162 | |
| 152 | | if (state->command & 0x10) |
| 163 | if (state->control & 0x10) |
| 153 | 164 | { |
| 154 | | logerror("%s: 06XX '%s' write in read mode %02x\n",cpuexec_describe_context(device->machine),device->tag,state->command); |
| 165 | logerror("%s: 06XX '%s' write in read mode %02x\n",cpuexec_describe_context(device->machine),device->tag,state->control); |
| 155 | 166 | return; |
| 156 | 167 | } |
| 157 | 168 | |
| 158 | | switch (state->command & 0xf) |
| 159 | | { |
| 160 | | case 0x1: if (state->write[0] != NULL) (*state->write[0])(state->device[0],0,data); break; |
| 161 | | case 0x2: if (state->write[1] != NULL) (*state->write[1])(state->device[1],0,data); break; |
| 162 | | case 0x4: if (state->write[2] != NULL) (*state->write[2])(state->device[2],0,data); break; |
| 163 | | case 0x8: if (state->write[3] != NULL) (*state->write[3])(state->device[3],0,data); break; |
| 164 | | default: |
| 165 | | logerror("%s: 06XX '%s' write in unsupported mode %02x\n",cpuexec_describe_context(device->machine),device->tag,state->command); |
| 166 | | break; |
| 167 | | } |
| 169 | for (devnum = 0; devnum < 4; devnum++) |
| 170 | if ((state->control & (1 << devnum)) && state->write[devnum] != NULL) |
| 171 | (*state->write[devnum])(state->device[devnum], 0, data); |
| 168 | 172 | } |
| 169 | 173 | |
| 170 | 174 | |
| r4939 | r4940 | |
| 172 | 176 | { |
| 173 | 177 | namco_06xx_state *state = get_safe_token(device); |
| 174 | 178 | LOG(("%s: 06XX '%s' ctrl_r\n",cpuexec_describe_context(device->machine),device->tag)); |
| 175 | | return state->command; |
| 179 | return state->control; |
| 176 | 180 | } |
| 177 | 181 | |
| 178 | 182 | WRITE8_DEVICE_HANDLER( namco_06xx_ctrl_w ) |
| 179 | 183 | { |
| 180 | 184 | namco_06xx_state *state = get_safe_token(device); |
| 185 | int devnum; |
| 181 | 186 | |
| 182 | | LOG(("%s: 06XX '%s' command %02x\n",cpuexec_describe_context(device->machine),device->tag,data)); |
| 187 | LOG(("%s: 06XX '%s' control %02x\n",cpuexec_describe_context(device->machine),device->tag,data)); |
| 183 | 188 | |
| 184 | | state->command = data; |
| 189 | state->control = data; |
| 185 | 190 | |
| 186 | | if ((state->command & 0x0f) == 0) |
| 191 | if ((state->control & 0x0f) == 0) |
| 187 | 192 | { |
| 188 | 193 | LOG(("disabling nmi generate timer\n")); |
| 189 | 194 | timer_adjust_oneshot(state->nmi_timer, attotime_never, 0); |
| r4939 | r4940 | |
| 195 | 200 | // this timing is critical. Due to a bug, Bosconian will stop responding to |
| 196 | 201 | // inputs if a transfer terminates at the wrong time. |
| 197 | 202 | // On the other hand, the time cannot be too short otherwise the 54XX will |
| 198 | | // not have enough time to process the incoming commands. |
| 203 | // not have enough time to process the incoming controls. |
| 199 | 204 | timer_adjust_periodic(state->nmi_timer, ATTOTIME_IN_USEC(200), 0, ATTOTIME_IN_USEC(200)); |
| 200 | 205 | |
| 201 | | if (state->command & 0x10) |
| 202 | | { |
| 203 | | switch (state->command & 0xf) |
| 204 | | { |
| 205 | | case 0x1: if (state->readreq[0] != NULL) (*state->readreq[0])(state->device[0]); break; |
| 206 | | case 0x2: if (state->readreq[1] != NULL) (*state->readreq[1])(state->device[1]); break; |
| 207 | | case 0x4: if (state->readreq[2] != NULL) (*state->readreq[2])(state->device[2]); break; |
| 208 | | case 0x8: if (state->readreq[3] != NULL) (*state->readreq[3])(state->device[3]); break; |
| 209 | | default: |
| 210 | | logerror("%s: 06XX '%s' read in unsupported mode %02x\n",cpuexec_describe_context(device->machine),device->tag,state->command); |
| 211 | | } |
| 212 | | } |
| 206 | if (state->control & 0x10) |
| 207 | for (devnum = 0; devnum < 4; devnum++) |
| 208 | if ((state->control & (1 << devnum)) && state->readreq[devnum] != NULL) |
| 209 | (*state->readreq[devnum])(state->device[devnum]); |
| 213 | 210 | } |
| 214 | 211 | } |
| 215 | 212 | |
| r4939 | r4940 | |
| 224 | 221 | |
| 225 | 222 | static DEVICE_START( namco_06xx ) |
| 226 | 223 | { |
| 227 | | const namco_06xx_interface *config = (const namco_06xx_interface *)device->inline_config; |
| 224 | const namco_06xx_config *config = (const namco_06xx_config *)device->inline_config; |
| 228 | 225 | namco_06xx_state *state = get_safe_token(device); |
| 229 | 226 | int devnum; |
| 230 | 227 | |
| r4939 | r4940 | |
| 277 | 274 | /* allocate a timer */ |
| 278 | 275 | state->nmi_timer = timer_alloc(device->machine, nmi_generate, (void *)device); |
| 279 | 276 | |
| 280 | | state_save_register_device_item(device, 0, state->command); |
| 277 | state_save_register_device_item(device, 0, state->control); |
| 281 | 278 | } |
| 282 | 279 | |
| 283 | 280 | |
| r4939 | r4940 | |
| 288 | 285 | static DEVICE_RESET( namco_06xx ) |
| 289 | 286 | { |
| 290 | 287 | namco_06xx_state *state = get_safe_token(device); |
| 291 | | state->command = 0; |
| 288 | state->control = 0; |
| 292 | 289 | } |
| 293 | 290 | |
| 294 | 291 | |
| 295 | 292 | /*------------------------------------------------- |
| 296 | | device get info callback |
| 293 | device definition |
| 297 | 294 | -------------------------------------------------*/ |
| 298 | 295 | |
| 299 | | DEVICE_GET_INFO( namco_06xx ) |
| 300 | | { |
| 301 | | switch (state) |
| 302 | | { |
| 303 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 304 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(namco_06xx_state); break; |
| 305 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(namco_06xx_interface); break; |
| 306 | | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 296 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 307 | 297 | |
| 308 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 309 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(namco_06xx); break; |
| 310 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(namco_06xx); break; |
| 311 | | |
| 312 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 313 | | case DEVINFO_STR_NAME: strcpy(info->s, "Namco 06xx"); break; |
| 314 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Namco I/O"); break; |
| 315 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 316 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 317 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; |
| 318 | | } |
| 319 | | } |
| 298 | #define DEVTEMPLATE_ID(p,s) p##namco_06xx##s |
| 299 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET | DT_HAS_INLINE_CONFIG |
| 300 | #define DEVTEMPLATE_NAME "Namco 06xx" |
| 301 | #define DEVTEMPLATE_FAMILY "Namco I/O" |
| 302 | #include "devtempl.h" |
src/mame/drivers/pipedrm.c
| r4939 | r4940 | |
| 4 | 4 | |
| 5 | 5 | driver by Bryan McPhail & Aaron Giles |
| 6 | 6 | |
| 7 | Pipe Dreams |
| 8 | PCB# OP-11A-05 |
| 9 | OSC: |
| 10 | 12.000MHz (next to Z80B Main CPU) |
| 11 | 14.31818MHz (next to Z80B Sub CPU) |
| 12 | 8.000MHz (near YM2610 audio chip) |
| 13 | |
| 14 | Hatris coinage: |
| 15 | MAME uses the values listed in Test Mode. |
| 16 | This does NOT match what's listed in Hatris Manual: |
| 17 | |
| 18 | DIPSW-1 (from Hatris manual) |
| 19 | ------------------------------------------------------------------ |
| 20 | DipSwitch Title | Function | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
| 21 | ------------------------------------------------------------------ |
| 22 | | 1cn/1pl |off|off|off|off| |* |
| 23 | | 1cn/2pl |on |off|off|off| | |
| 24 | | 1cn/3pl |off|on |off|off| | |
| 25 | | 1cn/4pl |on |on |off|off| | |
| 26 | | 1cn/5pl |off|off|on |off| | |
| 27 | | 1cn/6pl |on |off|on |off| | |
| 28 | Coin Chute 1 | 2cn/1pl |off|on |on |off| | |
| 29 | | 3cn/1pl |on |on |on |off| | |
| 30 | | 4cn/1pl |off|off|off|on | | |
| 31 | | 5cn/1pl |on |off|off|on | | |
| 32 | | 2cn/3pl |off|on |off|on | | |
| 33 | | Multi A |on |on |off|on | | |
| 34 | | Multi B |off|off|on |on | | |
| 35 | | Multi C |on |off|on |on | | |
| 36 | | Multi D |off|on |on |on | | |
| 37 | | Multi E |on |on |on |on | | |
| 38 | ------------------------------------------------------------------ |
| 39 | | 1cn/1pl | |off|off|off|off|* |
| 40 | | 1cn/2pl | |on |off|off|off| |
| 41 | | 1cn/3pl | |off|on |off|off| |
| 42 | | 1cn/4pl | |on |on |off|off| |
| 43 | | 1cn/5pl | |off|off|on |off| |
| 44 | | 1cn/6pl | |on |off|on |off| |
| 45 | Coin Chute 2 | 2cn/1pl | |off|on |on |off| |
| 46 | | 3cn/1pl | |on |on |on |off| |
| 47 | | 4cn/1pl | |off|off|off|on | |
| 48 | | 5cn/1pl | |on |off|off|on | |
| 49 | | 2cn/3pl | |off|on |off|on | |
| 50 | | Multi A | |on |on |off|on | |
| 51 | | Multi B | |off|off|on |on | |
| 52 | | Multi C | |on |off|on |on | |
| 53 | | Multi D | |off|on |on |on | |
| 54 | | Multi E | |on |on |on |on | |
| 55 | ------------------------------------------------------------------ |
| 56 | |
| 57 | Added Multiple Coin Feature: |
| 58 | Multi A = 2cn/1pl 4cn/2pl 5cn/3pl 6cn/4pl |
| 59 | Multi B = 2cn/1pl 4cn/3pl |
| 60 | Multi C = 1cn/1pl 2cn/2pl 3cn/3pl 4cn/4pl 5cn/6pl |
| 61 | Multi D = 1cn/1pl 2cn/2pl 3cn/3pl 4cn/5pl |
| 62 | Multi E = 1cn/1pl 2cn/3pl |
| 63 | |
| 7 | 64 | **************************************************************************** |
| 8 | 65 | |
| 9 | 66 | Memory map |
| r4939 | r4940 | |
| 316 | 373 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 317 | 374 | |
| 318 | 375 | PORT_START("DSW1") /* $22 */ |
| 319 | | PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) ) |
| 376 | PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:1,2,3,4") |
| 320 | 377 | PORT_DIPSETTING( 0x06, DEF_STR( 5C_1C ) ) |
| 321 | 378 | PORT_DIPSETTING( 0x07, DEF_STR( 4C_1C ) ) |
| 322 | 379 | PORT_DIPSETTING( 0x08, DEF_STR( 3C_1C ) ) |
| r4939 | r4940 | |
| 333 | 390 | PORT_DIPSETTING( 0x0c, DEF_STR( 1C_4C ) ) |
| 334 | 391 | PORT_DIPSETTING( 0x0b, DEF_STR( 1C_5C ) ) |
| 335 | 392 | PORT_DIPSETTING( 0x0a, DEF_STR( 1C_6C ) ) |
| 336 | | PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) ) |
| 393 | PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW1:5,6,7,8") |
| 337 | 394 | PORT_DIPSETTING( 0x60, DEF_STR( 5C_1C ) ) |
| 338 | 395 | PORT_DIPSETTING( 0x70, DEF_STR( 4C_1C ) ) |
| 339 | 396 | PORT_DIPSETTING( 0x80, DEF_STR( 3C_1C ) ) |
| r4939 | r4940 | |
| 352 | 409 | PORT_DIPSETTING( 0xa0, DEF_STR( 1C_6C ) ) |
| 353 | 410 | |
| 354 | 411 | PORT_START("DSW2") /* $23 */ |
| 355 | | PORT_DIPNAME( 0x03, 0x03, DEF_STR( Difficulty ) ) |
| 412 | PORT_DIPNAME( 0x03, 0x03, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:1,2") |
| 356 | 413 | PORT_DIPSETTING( 0x02, DEF_STR( Easy ) ) |
| 357 | 414 | PORT_DIPSETTING( 0x03, DEF_STR( Normal ) ) |
| 358 | 415 | PORT_DIPSETTING( 0x01, DEF_STR( Hard ) ) |
| 359 | 416 | PORT_DIPSETTING( 0x00, "Super" ) |
| 360 | | PORT_DIPNAME( 0x0c, 0x04, DEF_STR( Lives ) ) |
| 417 | PORT_DIPNAME( 0x0c, 0x04, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW2:3,4") |
| 361 | 418 | PORT_DIPSETTING( 0x0c, "1" ) |
| 362 | 419 | PORT_DIPSETTING( 0x08, "2" ) |
| 363 | 420 | PORT_DIPSETTING( 0x04, "3" ) |
| 364 | 421 | PORT_DIPSETTING( 0x00, "4" ) |
| 365 | | PORT_DIPNAME( 0x10, 0x10, DEF_STR( Demo_Sounds ) ) |
| 422 | PORT_DIPNAME( 0x10, 0x10, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:5") |
| 366 | 423 | PORT_DIPSETTING( 0x00, DEF_STR( Off ) ) |
| 367 | 424 | PORT_DIPSETTING( 0x10, DEF_STR( On ) ) |
| 368 | | PORT_DIPNAME( 0x20, 0x20, DEF_STR( Flip_Screen ) ) |
| 425 | PORT_DIPNAME( 0x20, 0x20, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:6") |
| 369 | 426 | PORT_DIPSETTING( 0x20, DEF_STR( Off ) ) |
| 370 | 427 | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 371 | | PORT_DIPNAME( 0x40, 0x40, "Training Mode" ) |
| 428 | PORT_DIPNAME( 0x40, 0x40, "Training Mode" ) PORT_DIPLOCATION("SW2:7") |
| 372 | 429 | PORT_DIPSETTING( 0x00, DEF_STR( Off ) ) |
| 373 | 430 | PORT_DIPSETTING( 0x40, DEF_STR( On ) ) |
| 374 | | PORT_SERVICE( 0x80, IP_ACTIVE_LOW ) |
| 431 | PORT_SERVICE_DIPLOC( 0x0080, IP_ACTIVE_LOW, "SW2:8" ) |
| 375 | 432 | INPUT_PORTS_END |
| 376 | 433 | |
| 377 | 434 | |
| r4939 | r4940 | |
| 407 | 464 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 408 | 465 | |
| 409 | 466 | PORT_START("DSW1") /* $22 */ |
| 410 | | PORT_DIPNAME( 0x0f, 0x00, DEF_STR( Coin_A ) ) |
| 467 | PORT_DIPNAME( 0x0f, 0x00, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:1,2,3,4") |
| 411 | 468 | PORT_DIPSETTING( 0x09, DEF_STR( 5C_1C ) ) |
| 412 | 469 | PORT_DIPSETTING( 0x08, DEF_STR( 4C_1C ) ) |
| 413 | 470 | PORT_DIPSETTING( 0x07, DEF_STR( 3C_1C ) ) |
| r4939 | r4940 | |
| 424 | 481 | PORT_DIPSETTING( 0x03, DEF_STR( 1C_4C ) ) |
| 425 | 482 | PORT_DIPSETTING( 0x04, DEF_STR( 1C_5C ) ) |
| 426 | 483 | PORT_DIPSETTING( 0x05, DEF_STR( 1C_6C ) ) |
| 427 | | PORT_DIPNAME( 0xf0, 0x00, DEF_STR( Coin_B ) ) |
| 484 | PORT_DIPNAME( 0xf0, 0x00, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW1:5,6,7,8") |
| 428 | 485 | PORT_DIPSETTING( 0x90, DEF_STR( 5C_1C ) ) |
| 429 | 486 | PORT_DIPSETTING( 0x80, DEF_STR( 4C_1C ) ) |
| 430 | 487 | PORT_DIPSETTING( 0x70, DEF_STR( 3C_1C ) ) |
| r4939 | r4940 | |
| 443 | 500 | PORT_DIPSETTING( 0x50, DEF_STR( 1C_6C ) ) |
| 444 | 501 | |
| 445 | 502 | PORT_START("DSW2") /* $23 */ |
| 446 | | PORT_DIPNAME( 0x03, 0x00, "Hat Fall Velocity" ) |
| 503 | PORT_DIPNAME( 0x03, 0x00, "Hat Fall Velocity" ) PORT_DIPLOCATION("SW2:1,2") |
| 447 | 504 | PORT_DIPSETTING( 0x01, DEF_STR( Easy ) ) |
| 448 | 505 | PORT_DIPSETTING( 0x00, DEF_STR( Normal ) ) |
| 449 | 506 | PORT_DIPSETTING( 0x02, DEF_STR( Hard ) ) |
| 450 | 507 | PORT_DIPSETTING( 0x03, "Super" ) |
| 451 | | PORT_DIPNAME( 0x0c, 0x00, "End Line Position" ) |
| 508 | PORT_DIPNAME( 0x0c, 0x00, "End Line Position" ) PORT_DIPLOCATION("SW2:3,4") |
| 452 | 509 | PORT_DIPSETTING( 0x04, DEF_STR( Easy ) ) |
| 453 | 510 | PORT_DIPSETTING( 0x00, DEF_STR( Normal ) ) |
| 454 | 511 | PORT_DIPSETTING( 0x08, DEF_STR( Hard ) ) |
| 455 | 512 | PORT_DIPSETTING( 0x0c, "Super" ) |
| 456 | | PORT_SERVICE( 0x10, IP_ACTIVE_HIGH ) |
| 457 | | PORT_DIPNAME( 0x20, 0x00, DEF_STR( Flip_Screen ) ) |
| 513 | PORT_SERVICE_DIPLOC( 0x0010, IP_ACTIVE_HIGH, "SW2:5" ) |
| 514 | PORT_DIPNAME( 0x20, 0x00, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:6") |
| 458 | 515 | PORT_DIPSETTING( 0x00, DEF_STR( Off ) ) |
| 459 | 516 | PORT_DIPSETTING( 0x20, DEF_STR( On ) ) |
| 460 | | PORT_DIPNAME( 0x40, 0x00, DEF_STR( Demo_Sounds ) ) |
| 517 | PORT_DIPNAME( 0x40, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:7") |
| 461 | 518 | PORT_DIPSETTING( 0x40, DEF_STR( Off ) ) |
| 462 | 519 | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 463 | | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 520 | PORT_DIPUNUSED_DIPLOC( 0x0080, 0x0080, "SW2:8" ) /* Listed as "N.C." */ |
| 464 | 521 | INPUT_PORTS_END |
| 465 | 522 | |
| 466 | 523 | |
| r4939 | r4940 | |
| 633 | 690 | |
| 634 | 691 | ROM_START( pipedrm ) |
| 635 | 692 | ROM_REGION( 0x20000, "maincpu", 0 ) |
| 636 | | ROM_LOAD( "y1.u129", 0x00000, 0x08000, CRC(9b4d84a2) SHA1(82c26cf52b37ca3bcc10a534759e7bb52b1daa2d) ) |
| 637 | | ROM_LOAD( "yb.u110", 0x10000, 0x10000, CRC(7416554a) SHA1(612aff94da3ec282e200c07eae9af26a28e071bd) ) |
| 693 | ROM_LOAD( "ya.u129", 0x00000, 0x08000, CRC(9b4d84a2) SHA1(82c26cf52b37ca3bcc10a534759e7bb52b1daa2d) ) |
| 694 | ROM_LOAD( "yb.u110", 0x10000, 0x10000, CRC(7416554a) SHA1(612aff94da3ec282e200c07eae9af26a28e071bd) ) |
| 638 | 695 | |
| 639 | 696 | ROM_REGION( 0x20000, "sub", 0 ) |
| 640 | | ROM_LOAD( "4", 0x00000, 0x08000, CRC(497fad4c) SHA1(f151543a0c4a1d6d5d2de5e1dc12fd59dabcf1a8) ) |
| 641 | | ROM_LOAD( "3", 0x10000, 0x10000, CRC(4800322a) SHA1(a616c497ac18351b68b8307050a2a62c717a7873) ) |
| 697 | ROM_LOAD( "u4,u86", 0x00000, 0x08000, CRC(497fad4c) SHA1(f151543a0c4a1d6d5d2de5e1dc12fd59dabcf1a8) ) |
| 698 | ROM_LOAD( "u3.u99", 0x10000, 0x10000, CRC(4800322a) SHA1(a616c497ac18351b68b8307050a2a62c717a7873) ) |
| 642 | 699 | |
| 643 | 700 | ROM_REGION( 0x100000, "gfx1", ROMREGION_DISPOSE ) |
| 644 | | ROM_LOAD( "s73", 0x000000, 0x80000, CRC(63f4e10c) SHA1(ba935490578887080d8b16508fa6191236a8fea6) ) |
| 645 | | ROM_LOAD( "s72", 0x080000, 0x80000, CRC(4e669e97) SHA1(1de8a8cd8f8f69fa86b8fe2c73c6997e7a89c706) ) |
| 701 | ROM_LOAD( "s73", 0x000000, 0x80000, CRC(63f4e10c) SHA1(ba935490578887080d8b16508fa6191236a8fea6) ) |
| 702 | ROM_LOAD( "s72", 0x080000, 0x80000, CRC(4e669e97) SHA1(1de8a8cd8f8f69fa86b8fe2c73c6997e7a89c706) ) |
| 646 | 703 | |
| 647 | 704 | ROM_REGION( 0x100000, "gfx2", ROMREGION_DISPOSE ) |
| 648 | | ROM_LOAD( "s71", 0x000000, 0x80000, CRC(431485ee) SHA1(70a2ba5338598db9fcd9ef2be46e5cc2fd9510ee) ) |
| 705 | ROM_LOAD( "s71", 0x000000, 0x80000, CRC(431485ee) SHA1(70a2ba5338598db9fcd9ef2be46e5cc2fd9510ee) ) |
| 649 | 706 | ROM_COPY( "gfx1", 0x080000, 0x080000, 0x80000 ) |
| 650 | 707 | |
| 651 | 708 | ROM_REGION( 0x080000, "gfx3", ROMREGION_DISPOSE ) |
| 652 | | ROM_LOAD16_BYTE( "a30", 0x00000, 0x40000, CRC(50bc5e98) SHA1(b351af780d04e67a560935a9eeaedf597ac5bb1f) ) |
| 653 | | ROM_LOAD16_BYTE( "a29", 0x00001, 0x40000, CRC(a240a448) SHA1(d64169258e91eb09e8685bcdd96b16bf56e82ef1) ) |
| 709 | ROM_LOAD16_BYTE( "a30.u12", 0x00000, 0x40000, CRC(50bc5e98) SHA1(b351af780d04e67a560935a9eeaedf597ac5bb1f) ) |
| 710 | ROM_LOAD16_BYTE( "a29.u2", 0x00001, 0x40000, CRC(a240a448) SHA1(d64169258e91eb09e8685bcdd96b16bf56e82ef1) ) |
| 654 | 711 | |
| 655 | 712 | ROM_REGION( 0x80000, "ym", 0 ) |
| 656 | | ROM_LOAD( "g71", 0x00000, 0x80000, CRC(488e2fd1) SHA1(8ef8ceb2bd36a245138802f51babf62f17c30942) ) |
| 713 | ROM_LOAD( "g71.u118", 0x00000, 0x80000, CRC(488e2fd1) SHA1(8ef8ceb2bd36a245138802f51babf62f17c30942) ) |
| 657 | 714 | |
| 658 | 715 | ROM_REGION( 0x80000, "ym.deltat", 0 ) |
| 659 | | ROM_LOAD( "g72", 0x00000, 0x80000, CRC(dc3d14be) SHA1(4220f3fd13487dd861ac84b1b0d3e92125b3cc19) ) |
| 716 | ROM_LOAD( "g72.u83", 0x00000, 0x80000, CRC(dc3d14be) SHA1(4220f3fd13487dd861ac84b1b0d3e92125b3cc19) ) |
| 660 | 717 | |
| 661 | 718 | ROM_REGION( 0x0800, "plds", ROMREGION_DISPOSE ) |
| 662 | | ROM_LOAD( "palce16v8h.114", 0x0000, 0x0117, CRC(1f3a3816) SHA1(2b4d84ab98036b8861961f610b1b1ec23a653ef7) ) |
| 663 | | ROM_LOAD( "gal16v8a.115", 0x0200, 0x0117, CRC(2b32e239) SHA1(a3b9e45a1ce15ea4cc5754b2bf89cbaa416e814a) ) |
| 664 | | ROM_LOAD( "gal16v8a.116", 0x0400, 0x0117, CRC(3674f043) SHA1(06c88f65877a6575149bdd4f7cea64cd310227bd) ) |
| 665 | | ROM_LOAD( "gal16v8a.127", 0x0600, 0x0117, CRC(7115d95c) SHA1(23044039373b5a2face63d72c3fc6bf7f0c8a475) ) |
| 719 | ROM_LOAD( "palce16v8h.114", 0x0000, 0x0117, CRC(1f3a3816) SHA1(2b4d84ab98036b8861961f610b1b1ec23a653ef7) ) /* Stamped 1023 */ |
| 720 | ROM_LOAD( "gal16v8a.115", 0x0200, 0x0117, CRC(2b32e239) SHA1(a3b9e45a1ce15ea4cc5754b2bf89cbaa416e814a) ) /* Stamped 1015 */ |
| 721 | ROM_LOAD( "gal16v8a.116", 0x0400, 0x0117, CRC(3674f043) SHA1(06c88f65877a6575149bdd4f7cea64cd310227bd) ) /* Stamped 1014 */ |
| 722 | ROM_LOAD( "gal16v8a.127", 0x0600, 0x0117, CRC(7115d95c) SHA1(23044039373b5a2face63d72c3fc6bf7f0c8a475) ) /* Stamped 1016 */ |
| 666 | 723 | ROM_END |
| 667 | 724 | |
| 668 | 725 | ROM_START( pipedrmu ) |
| 669 | 726 | ROM_REGION( 0x20000, "maincpu", 0 ) |
| 670 | | ROM_LOAD( "01.u12", 0x00000, 0x08000, CRC(9fe261fb) SHA1(57beeeade8809be0a71086f55b14b1676c0b3759) ) |
| 671 | | ROM_LOAD( "02.u11", 0x10000, 0x10000, CRC(c8209b67) SHA1(cca7356d75e8091b07e3328aef523ff452abbcd8) ) |
| 727 | ROM_LOAD( "01.u129", 0x00000, 0x08000, CRC(9fe261fb) SHA1(57beeeade8809be0a71086f55b14b1676c0b3759) ) |
| 728 | ROM_LOAD( "02.u110", 0x10000, 0x10000, CRC(c8209b67) SHA1(cca7356d75e8091b07e3328aef523ff452abbcd8) ) |
| 672 | 729 | |
| 673 | 730 | ROM_REGION( 0x20000, "sub", 0 ) |
| 674 | | ROM_LOAD( "4", 0x00000, 0x08000, CRC(497fad4c) SHA1(f151543a0c4a1d6d5d2de5e1dc12fd59dabcf1a8) ) |
| 675 | | ROM_LOAD( "3", 0x10000, 0x10000, CRC(4800322a) SHA1(a616c497ac18351b68b8307050a2a62c717a7873) ) |
| 731 | ROM_LOAD( "u4,u86", 0x00000, 0x08000, CRC(497fad4c) SHA1(f151543a0c4a1d6d5d2de5e1dc12fd59dabcf1a8) ) |
| 732 | ROM_LOAD( "u3.u99", 0x10000, 0x10000, CRC(4800322a) SHA1(a616c497ac18351b68b8307050a2a62c717a7873) ) |
| 676 | 733 | |
| 677 | 734 | ROM_REGION( 0x100000, "gfx1", ROMREGION_DISPOSE ) |
| 678 | | ROM_LOAD( "s73", 0x000000, 0x80000, CRC(63f4e10c) SHA1(ba935490578887080d8b16508fa6191236a8fea6) ) |
| 679 | | ROM_LOAD( "s72", 0x080000, 0x80000, CRC(4e669e97) SHA1(1de8a8cd8f8f69fa86b8fe2c73c6997e7a89c706) ) |
| 735 | ROM_LOAD( "s73", 0x000000, 0x80000, CRC(63f4e10c) SHA1(ba935490578887080d8b16508fa6191236a8fea6) ) |
| 736 | ROM_LOAD( "s72", 0x080000, 0x80000, CRC(4e669e97) SHA1(1de8a8cd8f8f69fa86b8fe2c73c6997e7a89c706) ) |
| 680 | 737 | |
| 681 | 738 | ROM_REGION( 0x100000, "gfx2", ROMREGION_DISPOSE ) |
| 682 | | ROM_LOAD( "s71", 0x000000, 0x80000, CRC(431485ee) SHA1(70a2ba5338598db9fcd9ef2be46e5cc2fd9510ee) ) |
| 739 | ROM_LOAD( "s71", 0x000000, 0x80000, CRC(431485ee) SHA1(70a2ba5338598db9fcd9ef2be46e5cc2fd9510ee) ) |
| 683 | 740 | ROM_COPY( "gfx1", 0x080000, 0x080000, 0x80000 ) |
| 684 | 741 | |
| 685 | 742 | ROM_REGION( 0x080000, "gfx3", ROMREGION_DISPOSE ) |
| 686 | | ROM_LOAD16_BYTE( "a30", 0x00000, 0x40000, CRC(50bc5e98) SHA1(b351af780d04e67a560935a9eeaedf597ac5bb1f) ) |
| 687 | | ROM_LOAD16_BYTE( "a29", 0x00001, 0x40000, CRC(a240a448) SHA1(d64169258e91eb09e8685bcdd96b16bf56e82ef1) ) |
| 743 | ROM_LOAD16_BYTE( "a30.u12", 0x00000, 0x40000, CRC(50bc5e98) SHA1(b351af780d04e67a560935a9eeaedf597ac5bb1f) ) |
| 744 | ROM_LOAD16_BYTE( "a29.u2", 0x00001, 0x40000, CRC(a240a448) SHA1(d64169258e91eb09e8685bcdd96b16bf56e82ef1) ) |
| 688 | 745 | |
| 689 | 746 | ROM_REGION( 0x80000, "ym", 0 ) |
| 690 | | ROM_LOAD( "g71", 0x00000, 0x80000, CRC(488e2fd1) SHA1(8ef8ceb2bd36a245138802f51babf62f17c30942) ) |
| 747 | ROM_LOAD( "g71.u118", 0x00000, 0x80000, CRC(488e2fd1) SHA1(8ef8ceb2bd36a245138802f51babf62f17c30942) ) |
| 691 | 748 | |
| 692 | 749 | ROM_REGION( 0x80000, "ym.deltat", 0 ) |
| 693 | | ROM_LOAD( "g72", 0x00000, 0x80000, CRC(dc3d14be) SHA1(4220f3fd13487dd861ac84b1b0d3e92125b3cc19) ) |
| 750 | ROM_LOAD( "g72.u83", 0x00000, 0x80000, CRC(dc3d14be) SHA1(4220f3fd13487dd861ac84b1b0d3e92125b3cc19) ) |
| 694 | 751 | |
| 695 | 752 | ROM_REGION( 0x0800, "plds", ROMREGION_DISPOSE ) |
| 696 | | ROM_LOAD( "palce16v8h.114", 0x0000, 0x0117, CRC(1f3a3816) SHA1(2b4d84ab98036b8861961f610b1b1ec23a653ef7) ) |
| 697 | | ROM_LOAD( "gal16v8a.115", 0x0200, 0x0117, CRC(2b32e239) SHA1(a3b9e45a1ce15ea4cc5754b2bf89cbaa416e814a) ) |
| 698 | | ROM_LOAD( "gal16v8a.116", 0x0400, 0x0117, CRC(3674f043) SHA1(06c88f65877a6575149bdd4f7cea64cd310227bd) ) |
| 699 | | ROM_LOAD( "gal16v8a.127", 0x0600, 0x0117, CRC(7115d95c) SHA1(23044039373b5a2face63d72c3fc6bf7f0c8a475) ) |
| 753 | ROM_LOAD( "palce16v8h.114", 0x0000, 0x0117, CRC(1f3a3816) SHA1(2b4d84ab98036b8861961f610b1b1ec23a653ef7) ) /* Stamped 1023 */ |
| 754 | ROM_LOAD( "gal16v8a.115", 0x0200, 0x0117, CRC(2b32e239) SHA1(a3b9e45a1ce15ea4cc5754b2bf89cbaa416e814a) ) /* Stamped 1015 */ |
| 755 | ROM_LOAD( "gal16v8a.116", 0x0400, 0x0117, CRC(3674f043) SHA1(06c88f65877a6575149bdd4f7cea64cd310227bd) ) /* Stamped 1014 */ |
| 756 | ROM_LOAD( "gal16v8a.127", 0x0600, 0x0117, CRC(7115d95c) SHA1(23044039373b5a2face63d72c3fc6bf7f0c8a475) ) /* Stamped 1016 */ |
| 700 | 757 | ROM_END |
| 701 | 758 | |
| 702 | 759 | |
| 703 | 760 | ROM_START( pipedrmj ) |
| 704 | 761 | ROM_REGION( 0x20000, "maincpu", 0 ) |
| 705 | | ROM_LOAD( "1", 0x00000, 0x08000, CRC(dbfac46b) SHA1(98ddfaed61de28b238964445572eb398b9dd03c7) ) |
| 706 | | ROM_LOAD( "2", 0x10000, 0x10000, CRC(b7adb99a) SHA1(fdab2b99e86aa0b6b17ec95556222e5211ba55e9) ) |
| 762 | ROM_LOAD( "1.u129", 0x00000, 0x08000, CRC(dbfac46b) SHA1(98ddfaed61de28b238964445572eb398b9dd03c7) ) |
| 763 | ROM_LOAD( "2.u110", 0x10000, 0x10000, CRC(b7adb99a) SHA1(fdab2b99e86aa0b6b17ec95556222e5211ba55e9) ) |
| 707 | 764 | |
| 708 | 765 | ROM_REGION( 0x20000, "sub", 0 ) |
| 709 | | ROM_LOAD( "4", 0x00000, 0x08000, CRC(497fad4c) SHA1(f151543a0c4a1d6d5d2de5e1dc12fd59dabcf1a8) ) |
| 710 | | ROM_LOAD( "3", 0x10000, 0x10000, CRC(4800322a) SHA1(a616c497ac18351b68b8307050a2a62c717a7873) ) |
| 766 | ROM_LOAD( "u4,u86", 0x00000, 0x08000, CRC(497fad4c) SHA1(f151543a0c4a1d6d5d2de5e1dc12fd59dabcf1a8) ) |
| 767 | ROM_LOAD( "u3.u99", 0x10000, 0x10000, CRC(4800322a) SHA1(a616c497ac18351b68b8307050a2a62c717a7873) ) |
| 711 | 768 | |
| 712 | 769 | ROM_REGION( 0x100000, "gfx1", ROMREGION_DISPOSE ) |
| 713 | | ROM_LOAD( "s73", 0x000000, 0x80000, CRC(63f4e10c) SHA1(ba935490578887080d8b16508fa6191236a8fea6) ) |
| 714 | | ROM_LOAD( "s72", 0x080000, 0x80000, CRC(4e669e97) SHA1(1de8a8cd8f8f69fa86b8fe2c73c6997e7a89c706) ) |
| 770 | ROM_LOAD( "s73", 0x000000, 0x80000, CRC(63f4e10c) SHA1(ba935490578887080d8b16508fa6191236a8fea6) ) |
| 771 | ROM_LOAD( "s72", 0x080000, 0x80000, CRC(4e669e97) SHA1(1de8a8cd8f8f69fa86b8fe2c73c6997e7a89c706) ) |
| 715 | 772 | |
| 716 | 773 | ROM_REGION( 0x100000, "gfx2", ROMREGION_DISPOSE ) |
| 717 | | ROM_LOAD( "s71", 0x000000, 0x80000, CRC(431485ee) SHA1(70a2ba5338598db9fcd9ef2be46e5cc2fd9510ee) ) |
| 774 | ROM_LOAD( "s71", 0x000000, 0x80000, CRC(431485ee) SHA1(70a2ba5338598db9fcd9ef2be46e5cc2fd9510ee) ) |
| 718 | 775 | ROM_COPY( "gfx1", 0x080000, 0x080000, 0x80000 ) |
| 719 | 776 | |
| 720 | 777 | ROM_REGION( 0x080000, "gfx3", ROMREGION_DISPOSE ) |
| 721 | | ROM_LOAD16_BYTE( "a30", 0x00000, 0x40000, CRC(50bc5e98) SHA1(b351af780d04e67a560935a9eeaedf597ac5bb1f) ) |
| 722 | | ROM_LOAD16_BYTE( "a29", 0x00001, 0x40000, CRC(a240a448) SHA1(d64169258e91eb09e8685bcdd96b16bf56e82ef1) ) |
| 778 | ROM_LOAD16_BYTE( "a30.u12", 0x00000, 0x40000, CRC(50bc5e98) SHA1(b351af780d04e67a560935a9eeaedf597ac5bb1f) ) |
| 779 | ROM_LOAD16_BYTE( "a29.u2", 0x00001, 0x40000, CRC(a240a448) SHA1(d64169258e91eb09e8685bcdd96b16bf56e82ef1) ) |
| 723 | 780 | |
| 724 | 781 | ROM_REGION( 0x80000, "ym", 0 ) |
| 725 | | ROM_LOAD( "g71", 0x00000, 0x80000, CRC(488e2fd1) SHA1(8ef8ceb2bd36a245138802f51babf62f17c30942) ) |
| 782 | ROM_LOAD( "g71.u118", 0x00000, 0x80000, CRC(488e2fd1) SHA1(8ef8ceb2bd36a245138802f51babf62f17c30942) ) |
| 726 | 783 | |
| 727 | 784 | ROM_REGION( 0x80000, "ym.deltat", 0 ) |
| 728 | | ROM_LOAD( "g72", 0x00000, 0x80000, CRC(dc3d14be) SHA1(4220f3fd13487dd861ac84b1b0d3e92125b3cc19) ) |
| 785 | ROM_LOAD( "g72.u83", 0x00000, 0x80000, CRC(dc3d14be) SHA1(4220f3fd13487dd861ac84b1b0d3e92125b3cc19) ) |
| 729 | 786 | |
| 730 | 787 | ROM_REGION( 0x0800, "plds", ROMREGION_DISPOSE ) |
| 731 | | ROM_LOAD( "palce16v8h.114", 0x0000, 0x0117, CRC(1f3a3816) SHA1(2b4d84ab98036b8861961f610b1b1ec23a653ef7) ) |
| 732 | | ROM_LOAD( "gal16v8a.115", 0x0200, 0x0117, CRC(2b32e239) SHA1(a3b9e45a1ce15ea4cc5754b2bf89cbaa416e814a) ) |
| 733 | | ROM_LOAD( "gal16v8a.116", 0x0400, 0x0117, CRC(3674f043) SHA1(06c88f65877a6575149bdd4f7cea64cd310227bd) ) |
| 734 | | ROM_LOAD( "gal16v8a.127", 0x0600, 0x0117, CRC(7115d95c) SHA1(23044039373b5a2face63d72c3fc6bf7f0c8a475) ) |
| 788 | ROM_LOAD( "palce16v8h.114", 0x0000, 0x0117, CRC(1f3a3816) SHA1(2b4d84ab98036b8861961f610b1b1ec23a653ef7) ) /* Stamped 1023 */ |
| 789 | ROM_LOAD( "gal16v8a.115", 0x0200, 0x0117, CRC(2b32e239) SHA1(a3b9e45a1ce15ea4cc5754b2bf89cbaa416e814a) ) /* Stamped 1015 */ |
| 790 | ROM_LOAD( "gal16v8a.116", 0x0400, 0x0117, CRC(3674f043) SHA1(06c88f65877a6575149bdd4f7cea64cd310227bd) ) /* Stamped 1014 */ |
| 791 | ROM_LOAD( "gal16v8a.127", 0x0600, 0x0117, CRC(7115d95c) SHA1(23044039373b5a2face63d72c3fc6bf7f0c8a475) ) /* Stamped 1016 */ |
| 735 | 792 | ROM_END |
| 736 | 793 | |
| 737 | 794 | |
src/mame/drivers/megadriv.c
| r4939 | r4940 | |
| 84 | 84 | |
| 85 | 85 | #define SEGACD_CLOCK 12500000 |
| 86 | 86 | |
| 87 | #define HAZE_MD 0 // to make appear / disappear the Region DipSwitch |
| 88 | |
| 87 | 89 | /* timing details */ |
| 88 | 90 | static int megadriv_framerate; |
| 89 | 91 | static int megadrive_total_scanlines; |
| r4939 | r4940 | |
| 1443 | 1445 | UINT8 (*megadrive_io_read_data_port_ptr)(running_machine *machine, int offset); |
| 1444 | 1446 | void (*megadrive_io_write_data_port_ptr)(running_machine *machine, int offset, UINT16 data); |
| 1445 | 1447 | |
| 1446 | | INPUT_PORTS_START( megadri6 ) |
| 1447 | | PORT_START("PAD1") /* Joypad 1 (6 button + start + mode) NOT READ DIRECTLY */ |
| 1448 | /* |
| 1449 | |
| 1450 | A10001h = A0 Version register |
| 1451 | |
| 1452 | A10003h = 7F Data register for port A |
| 1453 | A10005h = 7F Data register for port B |
| 1454 | A10007h = 7F Data register for port C |
| 1455 | |
| 1456 | A10009h = 00 Ctrl register for port A |
| 1457 | A1000Bh = 00 Ctrl register for port B |
| 1458 | A1000Dh = 00 Ctrl register for port C |
| 1459 | |
| 1460 | A1000Fh = FF TxData register for port A |
| 1461 | A10011h = 00 RxData register for port A |
| 1462 | A10013h = 00 S-Ctrl register for port A |
| 1463 | |
| 1464 | A10015h = FF TxData register for port B |
| 1465 | A10017h = 00 RxData register for port B |
| 1466 | A10019h = 00 S-Ctrl register for port B |
| 1467 | |
| 1468 | A1001Bh = FF TxData register for port C |
| 1469 | A1001Dh = 00 RxData register for port C |
| 1470 | A1001Fh = 00 S-Ctrl register for port C |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | Bit 7 - (Not connected) |
| 1476 | Bit 6 - TH |
| 1477 | Bit 5 - TL |
| 1478 | Bit 4 - TR |
| 1479 | Bit 3 - RIGHT |
| 1480 | Bit 2 - LEFT |
| 1481 | Bit 1 - DOWN |
| 1482 | Bit 0 - UP |
| 1483 | |
| 1484 | |
| 1485 | */ |
| 1486 | |
| 1487 | INPUT_PORTS_START( md_common ) |
| 1488 | PORT_START("PAD1") /* Joypad 1 (3 button + start) NOT READ DIRECTLY */ |
| 1448 | 1489 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) |
| 1449 | 1490 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) |
| 1450 | 1491 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) |
| 1451 | 1492 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) |
| 1452 | | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 A") // a |
| 1453 | | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 B") // b |
| 1454 | | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 C") // c |
| 1493 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 B") // b |
| 1494 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 C") // c |
| 1495 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 A") // a |
| 1455 | 1496 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("P1 START") // start |
| 1456 | | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) PORT_NAME("P1 X") // x |
| 1457 | | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_NAME("P1 Y") // y |
| 1458 | | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(1) PORT_NAME("P1 Z") // z |
| 1459 | | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(1) PORT_NAME("P1 MODE") // mode |
| 1460 | 1497 | |
| 1461 | | |
| 1462 | | PORT_START("PAD2") /* Joypad 2 (6 button + start + mode) NOT READ DIRECTLY */ |
| 1498 | PORT_START("PAD2") /* Joypad 2 (3 button + start) NOT READ DIRECTLY */ |
| 1463 | 1499 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) |
| 1464 | 1500 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) |
| 1465 | 1501 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) |
| 1466 | 1502 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) |
| 1467 | | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 A") // a |
| 1468 | | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 B") // b |
| 1469 | | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 C") // c |
| 1503 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 B") // b |
| 1504 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 C") // c |
| 1505 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 A") // a |
| 1470 | 1506 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("P2 START") // start |
| 1471 | | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) PORT_NAME("P2 X") // x |
| 1472 | | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) PORT_NAME("P2 Y") // y |
| 1473 | | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(2) PORT_NAME("P2 Z") // z |
| 1474 | | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(2) PORT_NAME("P2 MODE") // mode |
| 1507 | INPUT_PORTS_END |
| 1475 | 1508 | |
| 1476 | | PORT_START("IN0") /* 3rd I/O port */ |
| 1477 | 1509 | |
| 1510 | INPUT_PORTS_START( megadriv ) |
| 1511 | PORT_INCLUDE( md_common ) |
| 1512 | |
| 1478 | 1513 | PORT_START("RESET") /* Buttons on Genesis Console */ |
| 1479 | 1514 | PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_NAME("Reset Button") PORT_IMPULSE(1) // reset, resets 68k (and..?) |
| 1480 | 1515 | |
| 1481 | | PORT_START("REGION") /* Buttons on Genesis Console */ |
| 1516 | #if HAZE_MD |
| 1517 | PORT_START("REGION") /* Region setting for Console */ |
| 1482 | 1518 | /* Region setting for Console */ |
| 1483 | 1519 | PORT_DIPNAME( 0x000f, 0x0000, DEF_STR( Region ) ) |
| 1484 | 1520 | PORT_DIPSETTING( 0x0000, "Use HazeMD Default Choice" ) |
| 1485 | 1521 | PORT_DIPSETTING( 0x0001, "US (NTSC, 60fps)" ) |
| 1486 | 1522 | PORT_DIPSETTING( 0x0002, "JAPAN (NTSC, 60fps)" ) |
| 1487 | 1523 | PORT_DIPSETTING( 0x0003, "EUROPE (PAL, 50fps)" ) |
| 1524 | #endif |
| 1488 | 1525 | INPUT_PORTS_END |
| 1489 | 1526 | |
| 1527 | INPUT_PORTS_START( megadri6 ) |
| 1528 | PORT_INCLUDE( megadriv ) |
| 1490 | 1529 | |
| 1530 | PORT_START("EXTRA1") /* Extra buttons for Joypad 1 (6 button + start + mode) NOT READ DIRECTLY */ |
| 1531 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(1) PORT_NAME("P1 Z") // z |
| 1532 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) PORT_NAME("P1 Y") // y |
| 1533 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) PORT_NAME("P1 X") // x |
| 1534 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(1) PORT_NAME("P1 MODE") // mode |
| 1491 | 1535 | |
| 1536 | PORT_START("EXTRA2") /* Extra buttons for Joypad 2 (6 button + start + mode) NOT READ DIRECTLY */ |
| 1537 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_PLAYER(2) PORT_NAME("P2 Z") // z |
| 1538 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) PORT_NAME("P2 Y") // y |
| 1539 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) PORT_NAME("P2 X") // x |
| 1540 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_PLAYER(2) PORT_NAME("P2 MODE") // mode |
| 1541 | INPUT_PORTS_END |
| 1492 | 1542 | |
| 1493 | 1543 | INPUT_PORTS_START( ssf2ghw ) |
| 1494 | | PORT_START("PAD1") /* Joypad 1 (6 button + start + mode) NOT READ DIRECTLY */ |
| 1495 | | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) |
| 1496 | | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) |
| 1497 | | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) |
| 1498 | | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) |
| 1499 | | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) |
| 1500 | | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) |
| 1501 | | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) |
| 1544 | PORT_INCLUDE( md_common ) |
| 1545 | |
| 1546 | PORT_MODIFY("PAD1") |
| 1547 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) |
| 1548 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) |
| 1549 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) |
| 1502 | 1550 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 ) |
| 1503 | | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) |
| 1504 | | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) |
| 1505 | | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) |
| 1506 | | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 1507 | 1551 | |
| 1552 | PORT_MODIFY("PAD2") |
| 1553 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) |
| 1554 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) |
| 1555 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) |
| 1556 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 ) |
| 1508 | 1557 | |
| 1509 | | PORT_START("PAD2") /* Joypad 1 (6 button + start + mode) NOT READ DIRECTLY */ |
| 1510 | | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) |
| 1511 | | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) |
| 1512 | | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) |
| 1513 | | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) |
| 1514 | | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) |
| 1515 | | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) |
| 1516 | | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) |
| 1517 | | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START2 ) |
| 1518 | | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) |
| 1519 | | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) |
| 1520 | | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) |
| 1521 | | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 1558 | PORT_START("EXTRA1") /* Extra buttons for Joypad 1 (6 button + start + mode) NOT READ DIRECTLY */ |
| 1559 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1) |
| 1560 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1) |
| 1561 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) |
| 1562 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 1522 | 1563 | |
| 1564 | PORT_START("EXTRA2") /* Extra buttons for Joypad 2 (6 button + start + mode) NOT READ DIRECTLY */ |
| 1565 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2) |
| 1566 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) |
| 1567 | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) |
| 1568 | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 1569 | |
| 1523 | 1570 | PORT_START("IN0") /* 3rd I/O port */ |
| 1524 | 1571 | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 ) |
| 1525 | 1572 | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN2 ) |
| 1526 | 1573 | |
| 1527 | | // PORT_START("RESET") /* Buttons on Genesis Console */ |
| 1528 | | // PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_NAME("Reset Button") PORT_IMPULSE(1) // reset, resets 68k (and..?) |
| 1529 | | |
| 1530 | | // PORT_START("REGION") /* Buttons on Genesis Console */ |
| 1531 | | // /* Region setting for Console */ |
| 1532 | | // PORT_DIPNAME( 0x000f, 0x0000, DEF_STR( Region ) ) |
| 1533 | | // PORT_DIPSETTING( 0x0000, "Use HazeMD Default Choice" ) |
| 1534 | | // PORT_DIPSETTING( 0x0001, "US (NTSC, 60fps)" ) |
| 1535 | | // PORT_DIPSETTING( 0x0002, "JAPAN (NTSC, 60fps)" ) |
| 1536 | | // PORT_DIPSETTING( 0x0003, "EUROPE (PAL, 50fps)" ) |
| 1537 | | |
| 1538 | 1574 | PORT_START("DSWA") |
| 1539 | 1575 | PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coinage ) ) |
| 1540 | 1576 | PORT_DIPSETTING( 0x01, DEF_STR( 4C_1C ) ) |
| r4939 | r4940 | |
| 1578 | 1614 | INPUT_PORTS_END |
| 1579 | 1615 | |
| 1580 | 1616 | |
| 1581 | | |
| 1582 | | |
| 1583 | | |
| 1584 | | /* |
| 1585 | | |
| 1586 | | A10001h = A0 Version register |
| 1587 | | |
| 1588 | | A10003h = 7F Data register for port A |
| 1589 | | A10005h = 7F Data register for port B |
| 1590 | | A10007h = 7F Data register for port C |
| 1591 | | |
| 1592 | | A10009h = 00 Ctrl register for port A |
| 1593 | | A1000Bh = 00 Ctrl register for port B |
| 1594 | | A1000Dh = 00 Ctrl register for port C |
| 1595 | | |
| 1596 | | A1000Fh = FF TxData register for port A |
| 1597 | | A10011h = 00 RxData register for port A |
| 1598 | | A10013h = 00 S-Ctrl register for port A |
| 1599 | | |
| 1600 | | A10015h = FF TxData register for port B |
| 1601 | | A10017h = 00 RxData register for port B |
| 1602 | | A10019h = 00 S-Ctrl register for port B |
| 1603 | | |
| 1604 | | A1001Bh = FF TxData register for port C |
| 1605 | | A1001Dh = 00 RxData register for port C |
| 1606 | | A1001Fh = 00 S-Ctrl register for port C |
| 1607 | | |
| 1608 | | |
| 1609 | | |
| 1610 | | |
| 1611 | | Bit 7 - (Not connected) |
| 1612 | | Bit 6 - TH |
| 1613 | | Bit 5 - TL |
| 1614 | | Bit 4 - TR |
| 1615 | | Bit 3 - RIGHT |
| 1616 | | Bit 2 - LEFT |
| 1617 | | Bit 1 - DOWN |
| 1618 | | Bit 0 - UP |
| 1619 | | |
| 1620 | | |
| 1621 | | */ |
| 1622 | | |
| 1623 | | INPUT_PORTS_START( megadriv ) |
| 1624 | | PORT_START("PAD1") /* Joypad 1 (3 button + start) NOT READ DIRECTLY */ |
| 1625 | | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) |
| 1626 | | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) |
| 1627 | | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) |
| 1628 | | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) |
| 1629 | | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 A") // a |
| 1630 | | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 B") // b |
| 1631 | | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 C") // c |
| 1632 | | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("P1 START") // start |
| 1633 | | |
| 1634 | | PORT_START("PAD2") /* Joypad 2 (3 button + start) NOT READ DIRECTLY */ |
| 1635 | | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) |
| 1636 | | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) |
| 1637 | | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) |
| 1638 | | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) |
| 1639 | | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 A") // a |
| 1640 | | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 B") // b |
| 1641 | | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 C") // c |
| 1642 | | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("P2 START") // start |
| 1643 | | |
| 1644 | | PORT_START("IN0") /* 3rd I/O port */ |
| 1645 | | |
| 1646 | | PORT_START("RESET") /* Buttons on Genesis Console */ |
| 1647 | | PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_NAME("Reset Button") PORT_IMPULSE(1) // reset, resets 68k (and..?) |
| 1648 | | |
| 1649 | | PORT_START("REGION") /* Region setting for Console */ |
| 1650 | | /* Region setting for Console */ |
| 1651 | | PORT_DIPNAME( 0x000f, 0x0000, DEF_STR( Region ) ) |
| 1652 | | PORT_DIPSETTING( 0x0000, "Use HazeMD Default Choice" ) |
| 1653 | | PORT_DIPSETTING( 0x0001, "US (NTSC, 60fps)" ) |
| 1654 | | PORT_DIPSETTING( 0x0002, "JAPAN (NTSC, 60fps)" ) |
| 1655 | | PORT_DIPSETTING( 0x0003, "EUROPE (PAL, 50fps)" ) |
| 1656 | | INPUT_PORTS_END |
| 1657 | | |
| 1658 | | |
| 1659 | 1617 | INPUT_PORTS_START( aladbl ) |
| 1660 | | PORT_START("PAD1") /* Joypad 1 (3 button + start) NOT READ DIRECTLY */ |
| 1661 | | PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1) |
| 1662 | | PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1) |
| 1663 | | PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1) |
| 1664 | | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1) |
| 1618 | PORT_INCLUDE( md_common ) |
| 1619 | |
| 1620 | PORT_MODIFY("PAD1") /* Joypad 1 (3 button + start) NOT READ DIRECTLY */ |
| 1665 | 1621 | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Throw") // a |
| 1666 | 1622 | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Sword") // b |
| 1667 | 1623 | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 Jump") // c |
| 1668 | 1624 | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 ) // start |
| 1669 | 1625 | |
| 1670 | | PORT_START("PAD2") /* Joypad 2 (3 button + start) NOT READ DIRECTLY - not used */ |
| 1671 | | // PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2) |
| 1672 | | // PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2) |
| 1673 | | // PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2) |
| 1674 | | // PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2) |
| 1675 | | // PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Throw") // a |
| 1676 | | // PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Sword") // b |
| 1677 | | // PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 Jump") // c |
| 1678 | | // PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START2 ) // start |
| 1626 | PORT_MODIFY("PAD2") /* Joypad 2 (3 button + start) NOT READ DIRECTLY - not used */ |
| 1627 | PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED ) |
| 1679 | 1628 | |
| 1680 | | PORT_START("IN0") /* 3rd I/O port */ |
| 1681 | | |
| 1682 | | // PORT_START("RESET") /* Buttons on Genesis Console */ |
| 1683 | | // PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_NAME("Reset Button") PORT_IMPULSE(1) // reset, resets 68k (and..?) |
| 1684 | | |
| 1685 | | // PORT_START("REGION") /* Region setting for Console */ |
| 1686 | | // /* Region setting for Console */ |
| 1687 | | // PORT_DIPNAME( 0x000f, 0x0000, DEF_STR( Region ) ) |
| 1688 | | // PORT_DIPSETTING( 0x0000, "Use HazeMD Default Choice" ) |
| 1689 | | // PORT_DIPSETTING( 0x0001, "US (NTSC, 60fps)" ) |
| 1690 | | // PORT_DIPSETTING( 0x0002, "JAPAN (NTSC, 60fps)" ) |
| 1691 | | // PORT_DIPSETTING( 0x0003, "EUROPE (PAL, 50fps)" ) |
| 1692 | | |
| 1693 | 1629 | /* As I don't know how it is on real hardware, this is more a guess than anything */ |
| 1694 | 1630 | PORT_START("MCU") |
| 1695 | 1631 | PORT_DIPNAME( 0x07, 0x01, DEF_STR( Coinage ) ) /* code at 0x1b2a50 - unsure if there are so many settings */ |
| r4939 | r4940 | |
| 1701 | 1637 | PORT_DIPSETTING( 0x05, DEF_STR( 1C_5C ) ) |
| 1702 | 1638 | PORT_DIPSETTING( 0x06, DEF_STR( 1C_6C ) ) |
| 1703 | 1639 | PORT_DIPSETTING( 0x07, DEF_STR( 1C_7C ) ) |
| 1704 | | //PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_SPECIAL ) /* to avoid it being changed and corrupting Coinage settings */ |
| 1640 | // PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_SPECIAL ) /* to avoid it being changed and corrupting Coinage settings */ |
| 1705 | 1641 | PORT_DIPNAME( 0x30, 0x00, DEF_STR( Difficulty ) ) /* code at 0x1b2680 */ |
| 1706 | 1642 | PORT_DIPSETTING( 0x10, DEF_STR( Easy ) ) /* "PRACTICE" */ |
| 1707 | 1643 | PORT_DIPSETTING( 0x00, DEF_STR( Normal ) ) /* "NORMAL" */ |
| r4939 | r4940 | |
| 1712 | 1648 | PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_IMPULSE(1) /* needed to avoid credits getting mad */ |
| 1713 | 1649 | INPUT_PORTS_END |
| 1714 | 1650 | |
| 1715 | | /* xxx_BUTTONs are used with player = 0, 1, 2, 3 so we need to return 0 for the missing 4th I/O port */ |
| 1716 | | static const char *const padnames[] = { "PAD1", "PAD2", "IN0", "UNK" }; |
| 1717 | | |
| 1718 | | #define MODE_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0800) >> 11) |
| 1719 | | #define Z_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0400) >> 10) |
| 1720 | | #define Y_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0200) >> 9 ) |
| 1721 | | #define X_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0100) >> 8 ) |
| 1722 | | |
| 1723 | | #define START_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0080) >> 7 ) |
| 1724 | | #define C_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0040) >> 6 ) |
| 1725 | | #define B_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0020) >> 5 ) |
| 1726 | | #define A_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0010) >> 4 ) |
| 1727 | | #define RIGHT_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0008) >> 3 ) |
| 1728 | | #define LEFT_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0004) >> 2 ) |
| 1729 | | #define DOWN_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0002) >> 1 ) |
| 1730 | | #define UP_BUTTON(machine,player) ((input_port_read_safe(machine, padnames[player], 0) & 0x0001) >> 0 ) |
| 1731 | | #define MD_RESET_BUTTON(machine) ((input_port_read_safe(machine, "RESET", 0x00) & 0x01) >> 0 ) |
| 1732 | | |
| 1733 | 1651 | UINT8 megadrive_io_data_regs[3]; |
| 1734 | 1652 | UINT8 megadrive_io_ctrl_regs[3]; |
| 1735 | 1653 | static UINT8 megadrive_io_tx_regs[3]; |
| r4939 | r4940 | |
| 1746 | 1664 | megadrive_io_tx_regs[1] = 0xff; |
| 1747 | 1665 | megadrive_io_tx_regs[2] = 0xff; |
| 1748 | 1666 | |
| 1749 | | if (machine->gamedrv->ipt==ipt_megadri6) |
| 1667 | if (machine->gamedrv->ipt == ipt_megadri6) |
| 1750 | 1668 | init_megadri6_io(machine); |
| 1751 | 1669 | |
| 1752 | | if (machine->gamedrv->ipt==ipt_ssf2ghw) |
| 1670 | if (machine->gamedrv->ipt == ipt_ssf2ghw) |
| 1753 | 1671 | init_megadri6_io(machine); |
| 1754 | 1672 | } |
| 1755 | 1673 | |
| 1756 | | /************* 6 button version **************************/ |
| 1674 | /************* 6 buttons version **************************/ |
| 1757 | 1675 | static UINT8 megadrive_io_read_data_port_6button(running_machine *machine, int portnum) |
| 1758 | 1676 | { |
| 1759 | | UINT8 retdata; |
| 1677 | UINT8 retdata, helper = (megadrive_io_ctrl_regs[portnum] & 0x7f) | 0xc0; // bits 6 & 7 always come from megadrive_io_data_regs |
| 1678 | static const char *pad3names[] = { "PAD1", "PAD2", "IN0", "UNK" }; |
| 1679 | static const char *pad6names[] = { "EXTRA1", "EXTRA2", "IN0", "UNK" }; |
| 1760 | 1680 | |
| 1761 | | if (megadrive_io_data_regs[portnum]&0x40) |
| 1681 | if (megadrive_io_data_regs[portnum] & 0x40) |
| 1762 | 1682 | { |
| 1763 | | if (io_stage[portnum]==2) |
| 1683 | if (io_stage[portnum] == 2) |
| 1764 | 1684 | { |
| 1765 | | retdata = ( megadrive_io_data_regs[portnum] & 0x80) | |
| 1766 | | (1 <<6) | |
| 1767 | | ((megadrive_io_ctrl_regs[portnum]&0x20)?(megadrive_io_data_regs[portnum]&0x20):(C_BUTTON(machine,portnum)<<5)) | |
| 1768 | | ((megadrive_io_ctrl_regs[portnum]&0x10)?(megadrive_io_data_regs[portnum]&0x10):(B_BUTTON(machine,portnum)<<4)) | |
| 1769 | | ((megadrive_io_ctrl_regs[portnum]&0x08)?(megadrive_io_data_regs[portnum]&0x08):(MODE_BUTTON(machine,portnum)<<3)) | |
| 1770 | | ((megadrive_io_ctrl_regs[portnum]&0x04)?(megadrive_io_data_regs[portnum]&0x04):(X_BUTTON(machine,portnum)<<2)) | |
| 1771 | | ((megadrive_io_ctrl_regs[portnum]&0x02)?(megadrive_io_data_regs[portnum]&0x02):(Y_BUTTON(machine,portnum)<<1)) | |
| 1772 | | ((megadrive_io_ctrl_regs[portnum]&0x01)?(megadrive_io_data_regs[portnum]&0x01):(Z_BUTTON(machine,portnum)<<0)); |
| 1685 | /* here we read B, C & the additional buttons */ |
| 1686 | retdata = (megadrive_io_data_regs[portnum] & helper) | |
| 1687 | (((input_port_read_safe(machine, pad3names[portnum], 0) & 0x30) | |
| 1688 | (input_port_read_safe(machine, pad6names[portnum], 0) & 0x0f)) & ~helper); |
| 1773 | 1689 | } |
| 1774 | 1690 | else |
| 1775 | 1691 | { |
| 1776 | | retdata = ( megadrive_io_data_regs[portnum] & 0x80) | |
| 1777 | | (1 << 6) | |
| 1778 | | ((megadrive_io_ctrl_regs[portnum]&0x20)?(megadrive_io_data_regs[portnum]&0x20):(C_BUTTON(machine,portnum)<<5)) | |
| 1779 | | ((megadrive_io_ctrl_regs[portnum]&0x10)?(megadrive_io_data_regs[portnum]&0x10):(B_BUTTON(machine,portnum)<<4)) | |
| 1780 | | ((megadrive_io_ctrl_regs[portnum]&0x08)?(megadrive_io_data_regs[portnum]&0x08):(RIGHT_BUTTON(machine,portnum)<<3)) | |
| 1781 | | ((megadrive_io_ctrl_regs[portnum]&0x04)?(megadrive_io_data_regs[portnum]&0x04):(LEFT_BUTTON(machine,portnum)<<2)) | |
| 1782 | | ((megadrive_io_ctrl_regs[portnum]&0x02)?(megadrive_io_data_regs[portnum]&0x02):(DOWN_BUTTON(machine,portnum)<<1)) | |
| 1783 | | ((megadrive_io_ctrl_regs[portnum]&0x01)?(megadrive_io_data_regs[portnum]&0x01):(UP_BUTTON(machine,portnum)<<0)); |
| 1692 | /* here we read B, C & the directional buttons */ |
| 1693 | retdata = (megadrive_io_data_regs[portnum] & helper) | |
| 1694 | ((input_port_read_safe(machine, pad3names[portnum], 0) & 0x3f) & ~helper); |
| 1784 | 1695 | } |
| 1785 | 1696 | } |
| 1786 | 1697 | else |
| 1787 | 1698 | { |
| 1788 | | if (io_stage[portnum]==1) |
| 1699 | if (io_stage[portnum] == 1) |
| 1789 | 1700 | { |
| 1790 | | retdata = ( megadrive_io_data_regs[portnum] & 0x80) | |
| 1791 | | ( 0<<6 ) | |
| 1792 | | ((megadrive_io_ctrl_regs[portnum]&0x20)?(megadrive_io_data_regs[portnum]&0x20):(START_BUTTON(machine,portnum)<<5)) | |
| 1793 | | ((megadrive_io_ctrl_regs[portnum]&0x10)?(megadrive_io_data_regs[portnum]&0x10):(A_BUTTON(machine,portnum)<<4)) | |
| 1794 | | ((megadrive_io_ctrl_regs[portnum]&0x08)?(megadrive_io_data_regs[portnum]&0x08):(0<<3)) | |
| 1795 | | ((megadrive_io_ctrl_regs[portnum]&0x04)?(megadrive_io_data_regs[portnum]&0x04):(0<<2)) | |
| 1796 | | ((megadrive_io_ctrl_regs[portnum]&0x02)?(megadrive_io_data_regs[portnum]&0x02):(0<<1)) | |
| 1797 | | ((megadrive_io_ctrl_regs[portnum]&0x01)?(megadrive_io_data_regs[portnum]&0x01):(0<<0)); |
| 1701 | /* here we read ((Start & A) >> 2) | 0x00 */ |
| 1702 | retdata = (megadrive_io_data_regs[portnum] & helper) | |
| 1703 | (((input_port_read_safe(machine, pad3names[portnum], 0) & 0xc0) >> 2) & ~helper); |
| 1798 | 1704 | } |
| 1799 | 1705 | else if (io_stage[portnum]==2) |
| 1800 | 1706 | { |
| 1801 | | retdata = ( megadrive_io_data_regs[portnum] & 0x80) | |
| 1802 | | ( 0<<6 ) | |
| 1803 | | ((megadrive_io_ctrl_regs[portnum]&0x20)?(megadrive_io_data_regs[portnum]&0x20):(START_BUTTON(machine,portnum)<<5)) | |
| 1804 | | ((megadrive_io_ctrl_regs[portnum]&0x10)?(megadrive_io_data_regs[portnum]&0x10):(A_BUTTON(machine,portnum)<<4)) | |
| 1805 | | ((megadrive_io_ctrl_regs[portnum]&0x08)?(megadrive_io_data_regs[portnum]&0x08):(1<<3)) | |
| 1806 | | ((megadrive_io_ctrl_regs[portnum]&0x04)?(megadrive_io_data_regs[portnum]&0x04):(1<<2)) | |
| 1807 | | ((megadrive_io_ctrl_regs[portnum]&0x02)?(megadrive_io_data_regs[portnum]&0x02):(1<<1)) | |
| 1808 | | ((megadrive_io_ctrl_regs[portnum]&0x01)?(megadrive_io_data_regs[portnum]&0x01):(1<<0)); |
| 1707 | /* here we read ((Start & A) >> 2) | 0x0f */ |
| 1708 | retdata = (megadrive_io_data_regs[portnum] & helper) | |
| 1709 | ((((input_port_read_safe(machine, pad3names[portnum], 0) & 0xc0) >> 2) | 0x0f) & ~helper); |
| 1809 | 1710 | } |
| 1810 | 1711 | else |
| 1811 | 1712 | { |
| 1812 | | retdata = ( megadrive_io_data_regs[portnum] & 0x80) | |
| 1813 | | ( 0<<6 ) | |
| 1814 | | ((megadrive_io_ctrl_regs[portnum]&0x20)?(megadrive_io_data_regs[portnum]&0x20):(START_BUTTON(machine,portnum)<<5)) | |
| 1815 | | ((megadrive_io_ctrl_regs[portnum]&0x10)?(megadrive_io_data_regs[portnum]&0x10):(A_BUTTON(machine,portnum)<<4)) | |
| 1816 | | ((megadrive_io_ctrl_regs[portnum]&0x08)?(megadrive_io_data_regs[portnum]&0x08):(0<<3)) | |
| 1817 | | ((megadrive_io_ctrl_regs[portnum]&0x04)?(megadrive_io_data_regs[portnum]&0x04):(0<<2)) | |
| 1818 | | ((megadrive_io_ctrl_regs[portnum]&0x02)?(megadrive_io_data_regs[portnum]&0x02):(DOWN_BUTTON(machine,portnum)<<1)) | |
| 1819 | | ((megadrive_io_ctrl_regs[portnum]&0x01)?(megadrive_io_data_regs[portnum]&0x01):(UP_BUTTON(machine,portnum)<<0)); |
| 1713 | /* here we read ((Start & A) >> 2) | Up and Down */ |
| 1714 | retdata = (megadrive_io_data_regs[portnum] & helper) | |
| 1715 | ((((input_port_read_safe(machine, pad3names[portnum], 0) & 0xc0) >> 2) | |
| 1716 | (input_port_read_safe(machine, pad3names[portnum], 0) & 0x02)) & ~helper); |
| 1820 | 1717 | } |
| 1821 | 1718 | } |
| 1822 | 1719 | |
| 1823 | 1720 | // mame_printf_debug("read io data port stage %d port %d %02x\n",io_stage[portnum],portnum,retdata); |
| 1824 | 1721 | |
| 1825 | | |
| 1826 | | return retdata|(retdata<<8); |
| 1722 | return retdata | (retdata << 8); |
| 1827 | 1723 | } |
| 1828 | | /************* end 6 button version ********************************************/ |
| 1829 | 1724 | |
| 1725 | |
| 1726 | /************* 3 buttons version **************************/ |
| 1830 | 1727 | static UINT8 megadrive_io_read_data_port_3button(running_machine *machine, int portnum) |
| 1831 | 1728 | { |
| 1832 | | UINT8 retdata; |
| 1729 | UINT8 retdata, helper = (megadrive_io_ctrl_regs[portnum] & 0x3f) | 0xc0; // bits 6 & 7 always come from megadrive_io_data_regs |
| 1730 | static const char *pad3names[] = { "PAD1", "PAD2", "IN0", "UNK" }; |
| 1833 | 1731 | |
| 1834 | | |
| 1835 | 1732 | if (megadrive_io_data_regs[portnum]&0x40) |
| 1836 | 1733 | { |
| 1837 | | retdata = ( megadrive_io_data_regs[portnum] & 0x80) | |
| 1838 | | ((megadrive_io_ctrl_regs[portnum]&0x40)?(megadrive_io_data_regs[portnum]&0x40):(0x40)) | |
| 1839 | | ((megadrive_io_ctrl_regs[portnum]&0x20)?(megadrive_io_data_regs[portnum]&0x20):(C_BUTTON(machine,portnum)<<5)) | |
| 1840 | | ((megadrive_io_ctrl_regs[portnum]&0x10)?(megadrive_io_data_regs[portnum]&0x10):(B_BUTTON(machine,portnum)<<4)) | |
| 1841 | | ((megadrive_io_ctrl_regs[portnum]&0x08)?(megadrive_io_data_regs[portnum]&0x08):(RIGHT_BUTTON(machine,portnum)<<3)) | |
| 1842 | | ((megadrive_io_ctrl_regs[portnum]&0x04)?(megadrive_io_data_regs[portnum]&0x04):(LEFT_BUTTON(machine,portnum)<<2)) | |
| 1843 | | ((megadrive_io_ctrl_regs[portnum]&0x02)?(megadrive_io_data_regs[portnum]&0x02):(DOWN_BUTTON(machine,portnum)<<1)) | |
| 1844 | | ((megadrive_io_ctrl_regs[portnum]&0x01)?(megadrive_io_data_regs[portnum]&0x01):(UP_BUTTON(machine,portnum)<<0)); |
| 1734 | /* here we read B, C & the directional buttons */ |
| 1735 | retdata = (megadrive_io_data_regs[portnum] & helper) | |
| 1736 | ((input_port_read_safe(machine, pad3names[portnum], 0) & 0x3f) & ~helper); |
| 1845 | 1737 | } |
| 1846 | 1738 | else |
| 1847 | 1739 | { |
| 1848 | | retdata = ( megadrive_io_data_regs[portnum] & 0x80) | |
| 1849 | | ((megadrive_io_ctrl_regs[portnum]&0x40)?(megadrive_io_data_regs[portnum]&0x40):(0x40)) | |
| 1850 | | ((megadrive_io_ctrl_regs[portnum]&0x20)?(megadrive_io_data_regs[portnum]&0x20):(START_BUTTON(machine,portnum)<<5)) | |
| 1851 | | ((megadrive_io_ctrl_regs[portnum]&0x10)?(megadrive_io_data_regs[portnum]&0x10):(A_BUTTON(machine,portnum)<<4)) | |
| 1852 | | ((megadrive_io_ctrl_regs[portnum]&0x08)?(megadrive_io_data_regs[portnum]&0x08):(0<<3)) | |
| 1853 | | ((megadrive_io_ctrl_regs[portnum]&0x04)?(megadrive_io_data_regs[portnum]&0x04):(0<<2)) | |
| 1854 | | ((megadrive_io_ctrl_regs[portnum]&0x02)?(megadrive_io_data_regs[portnum]&0x02):(DOWN_BUTTON(machine,portnum)<<1)) | |
| 1855 | | ((megadrive_io_ctrl_regs[portnum]&0x01)?(megadrive_io_data_regs[portnum]&0x01):(UP_BUTTON(machine,portnum)<<0)); |
| 1740 | /* here we read ((Start & A) >> 2) | Up and Down */ |
| 1741 | retdata = (megadrive_io_data_regs[portnum] & helper) | |
| 1742 | ((((input_port_read_safe(machine, pad3names[portnum], 0) & 0xc0) >> 2) | |
| 1743 | (input_port_read_safe(machine, pad3names[portnum], 0) & 0x02)) & ~helper); |
| 1856 | 1744 | } |
| 1857 | 1745 | |
| 1858 | 1746 | return retdata; |
| r4939 | r4940 | |
| 1863 | 1751 | { |
| 1864 | 1752 | UINT8 retdata; |
| 1865 | 1753 | |
| 1866 | | if (ctrl==0x55) |
| 1754 | if (ctrl == 0x55) |
| 1867 | 1755 | { |
| 1868 | | retdata = (1<<0) | |
| 1869 | | (1<<1) | |
| 1870 | | (A_BUTTON(machine,1)<<2) | |
| 1871 | | (1<<3) | |
| 1872 | | (A_BUTTON(machine,0)<<4) | |
| 1873 | | (1<<5) | |
| 1874 | | (1<<6) | |
| 1875 | | (1<<7); |
| 1756 | /* A keys */ |
| 1757 | retdata = ((input_port_read(machine, "PAD1") & 0x40) >> 2) | |
| 1758 | ((input_port_read(machine, "PAD2") & 0x40) >> 4) | 0xeb; |
| 1876 | 1759 | } |
| 1877 | 1760 | else |
| 1878 | 1761 | { |
| 1879 | | if (offset==0) |
| 1762 | if (offset == 0) |
| 1880 | 1763 | { |
| 1881 | | retdata = (UP_BUTTON(machine,0)<<0) | |
| 1882 | | (DOWN_BUTTON(machine,0)<<1) | |
| 1883 | | (LEFT_BUTTON(machine,0)<<2) | |
| 1884 | | (RIGHT_BUTTON(machine,0)<<3) | |
| 1885 | | (B_BUTTON(machine,0)<<4) | |
| 1886 | | (C_BUTTON(machine,0)<<5) | |
| 1887 | | (UP_BUTTON(machine,1)<<6) | |
| 1888 | | (DOWN_BUTTON(machine,1)<<7); |
| 1764 | retdata = (input_port_read(machine, "PAD1") & 0x3f) | ((input_port_read(machine, "PAD2") & 0x03) << 6); |
| 1889 | 1765 | } |
| 1890 | 1766 | else |
| 1891 | 1767 | { |
| 1892 | | retdata = (LEFT_BUTTON(machine,1)<<0) | |
| 1893 | | (RIGHT_BUTTON(machine,1)<<1) | |
| 1894 | | (B_BUTTON(machine,1)<<2) | |
| 1895 | | (C_BUTTON(machine,1)<<3) | |
| 1896 | | (1<<4) | |
| 1897 | | (1<<5) | |
| 1898 | | (1<<6) | |
| 1899 | | (1<<7); |
| 1768 | retdata = ((input_port_read(machine, "PAD2") & 0x3c) >> 2) | 0xf0; |
| 1900 | 1769 | } |
| 1901 | 1770 | |
| 1902 | 1771 | } |
| r4939 | r4940 | |
| 1908 | 1777 | READ8_HANDLER (megatech_sms_ioport_dc_r) |
| 1909 | 1778 | { |
| 1910 | 1779 | running_machine *machine = space->machine; |
| 1911 | | return (DOWN_BUTTON(machine,1) << 7) | |
| 1912 | | (UP_BUTTON(machine,1) << 6) | |
| 1913 | | (B_BUTTON(machine,0) << 5) | // TR-A |
| 1914 | | (A_BUTTON(machine,0) << 4) | // TL-A |
| 1915 | | (RIGHT_BUTTON(machine,0) << 3) | |
| 1916 | | (LEFT_BUTTON(machine,0) << 2) | |
| 1917 | | (DOWN_BUTTON(machine,0) << 1) | |
| 1918 | | (UP_BUTTON(machine,0) << 0); |
| 1780 | /* 2009-05 FP: would it be worth to give separate inputs to SMS? SMS has only 2 keys A,B (which are B,C on megadrive) */ |
| 1781 | /* bit 4: TL-A; bit 5: TR-A */ |
| 1782 | return (input_port_read(machine, "PAD1") & 0x3f) | ((input_port_read(machine, "PAD2") & 0x03) << 6); |
| 1919 | 1783 | } |
| 1920 | 1784 | |
| 1921 | 1785 | READ8_HANDLER (megatech_sms_ioport_dd_r) |
| 1922 | 1786 | { |
| 1923 | 1787 | running_machine *machine = space->machine; |
| 1924 | | return (0 << 7) | // TH-B |
| 1925 | | (0 << 6) | // TH-A |
| 1926 | | (0 << 5) | // unused |
| 1927 | | (1 << 4) | // RESET button |
| 1928 | | (B_BUTTON(machine,1) << 3) | // TR-B |
| 1929 | | (A_BUTTON(machine,1) << 2) | // TL-B |
| 1930 | | (RIGHT_BUTTON(machine,1) << 1) | |
| 1931 | | (LEFT_BUTTON(machine,1) << 0); |
| 1788 | /* 2009-05 FP: would it be worth to give separate inputs to SMS? SMS has only 2 keys A,B (which are B,C on megadrive) */ |
| 1789 | /* bit 2: TL-B; bit 3: TR-B; bit 4: RESET; bit 5: unused; bit 6: TH-A; bit 7: TH-B*/ |
| 1790 | return ((input_port_read(machine, "PAD2") & 0x3c) >> 2) | 0x10; |
| 1932 | 1791 | } |
| 1933 | 1792 | |
| 1934 | 1793 | static UINT8 megadrive_io_read_ctrl_port(int portnum) |
| r4939 | r4940 | |
| 1937 | 1796 | retdata = megadrive_io_ctrl_regs[portnum]; |
| 1938 | 1797 | //mame_printf_debug("read io ctrl port %d %02x\n",portnum,retdata); |
| 1939 | 1798 | |
| 1940 | | return retdata|(retdata<<8); |
| 1799 | return retdata | (retdata << 8); |
| 1941 | 1800 | } |
| 1942 | 1801 | |
| 1943 | 1802 | static UINT8 megadrive_io_read_tx_port(int portnum) |
| 1944 | 1803 | { |
| 1945 | 1804 | UINT8 retdata; |
| 1946 | 1805 | retdata = megadrive_io_tx_regs[portnum]; |
| 1947 | | return retdata|(retdata<<8); |
| 1806 | return retdata | (retdata << 8); |
| 1948 | 1807 | } |
| 1949 | 1808 | |
| 1950 | 1809 | static UINT8 megadrive_io_read_rx_port(int portnum) |
| r4939 | r4940 | |
| 2020 | 1879 | |
| 2021 | 1880 | } |
| 2022 | 1881 | |
| 2023 | | return retdata | (retdata<<8); |
| 1882 | return retdata | (retdata << 8); |
| 2024 | 1883 | } |
| 2025 | 1884 | |
| 2026 | 1885 | |
| r4939 | r4940 | |
| 2032 | 1891 | } |
| 2033 | 1892 | |
| 2034 | 1893 | |
| 2035 | | /******************************6 button version*****************************/ |
| 1894 | /****************************** 6 buttons version*****************************/ |
| 2036 | 1895 | |
| 2037 | 1896 | static void megadrive_io_write_data_port_6button(running_machine *machine, int portnum, UINT16 data) |
| 2038 | 1897 | { |
| r4939 | r4940 | |
| 2051 | 1910 | |
| 2052 | 1911 | } |
| 2053 | 1912 | |
| 2054 | | /***************************end 6 button version ****************************/ |
| 2055 | 1913 | |
| 1914 | /*************************** 3 buttons version ****************************/ |
| 1915 | |
| 2056 | 1916 | static void megadrive_io_write_ctrl_port(running_machine *machine, int portnum, UINT16 data) |
| 2057 | 1917 | { |
| 2058 | 1918 | megadrive_io_ctrl_regs[portnum] = data; |
| r4939 | r4940 | |
| 6065 | 5925 | megadrive_imode_odd_frame^=1; |
| 6066 | 5926 | // cputag_set_input_line(machine, "genesis_snd_z80", 0, CLEAR_LINE); // if the z80 interrupt hasn't happened by now, clear it.. |
| 6067 | 5927 | |
| 6068 | | if (MD_RESET_BUTTON(machine)) cputag_set_input_line(machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE); |
| 5928 | if (input_port_read_safe(machine, "RESET", 0x00) & 0x01) |
| 5929 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE); |
| 6069 | 5930 | |
| 6070 | 5931 | /* |
| 6071 | 5932 | int megadrive_total_scanlines = 262; |
| r4939 | r4940 | |
| 6246 | 6107 | |
| 6247 | 6108 | MDRV_SCREEN_ADD("megadriv", RASTER) |
| 6248 | 6109 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB15) |
| 6249 | | MDRV_SCREEN_REFRESH_RATE(60) |
| 6110 | MDRV_SCREEN_REFRESH_RATE(50) |
| 6250 | 6111 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) // Vblank handled manually. |
| 6251 | 6112 | MDRV_SCREEN_SIZE(64*8, 64*8) |
| 6252 | 6113 | MDRV_SCREEN_VISIBLE_AREA(0, 32*8-1, 0, 28*8-1) |
src/mame/drivers/mpu4.c
| r4939 | r4940 | |
| 462 | 462 | const device_config *pia6 = devtag_get_device(device->machine, "pia_ic6"); |
| 463 | 463 | const device_config *pia7 = devtag_get_device(device->machine, "pia_ic7"); |
| 464 | 464 | const device_config *pia8 = devtag_get_device(device->machine, "pia_ic8"); |
| 465 | const device_config *ptm6840 = devtag_get_device(device->machine, "6840ptm"); |
| 465 | 466 | |
| 466 | 467 | /* The PIA and PTM IRQ lines are all connected to a common PCB track, leading directly to the 6809 IRQ line. */ |
| 467 | 468 | int combined_state = pia6821_get_irq_a(pia3) | pia6821_get_irq_b(pia3) | |
| r4939 | r4940 | |
| 470 | 471 | pia6821_get_irq_a(pia6) | pia6821_get_irq_b(pia6) | |
| 471 | 472 | pia6821_get_irq_a(pia7) | pia6821_get_irq_b(pia7) | |
| 472 | 473 | pia6821_get_irq_a(pia8) | pia6821_get_irq_b(pia8) | |
| 473 | | ptm6840_get_irq(0); |
| 474 | ptm6840_get_irq(ptm6840); |
| 474 | 475 | |
| 475 | 476 | if (!serial_card_connected) |
| 476 | 477 | { |
| r4939 | r4940 | |
| 484 | 485 | } |
| 485 | 486 | } |
| 486 | 487 | |
| 487 | | static void cpu0_irq_m6840(running_machine *machine, int state) |
| 488 | static WRITE_LINE_DEVICE_HANDLER( cpu0_irq_m6840 ) |
| 488 | 489 | { |
| 489 | | cpu0_irq(devtag_get_device(machine, "pia_ic3"), state); |
| 490 | cpu0_irq(devtag_get_device(device->machine, "pia_ic3"), state); |
| 490 | 491 | } |
| 491 | 492 | |
| 492 | 493 | |
| r4939 | r4940 | |
| 504 | 505 | |
| 505 | 506 | |
| 506 | 507 | /* IC2 6840 PTM handler */ |
| 507 | | static WRITE8_HANDLER( ic2_o1_callback ) |
| 508 | static WRITE8_DEVICE_HANDLER( ic2_o1_callback ) |
| 508 | 509 | { |
| 509 | | ptm6840_set_c2(space->machine,0,data); |
| 510 | ptm6840_set_c2(device, 0, data); |
| 510 | 511 | |
| 511 | 512 | /* copy output value to IC2 c2 |
| 512 | 513 | this output is the clock for timer2 */ |
| 513 | 514 | } |
| 514 | 515 | |
| 515 | 516 | |
| 516 | | static WRITE8_HANDLER( ic2_o2_callback ) |
| 517 | static WRITE8_DEVICE_HANDLER( ic2_o2_callback ) |
| 517 | 518 | { |
| 518 | | const device_config *pia = devtag_get_device(space->machine, "pia_ic3"); |
| 519 | const device_config *pia = devtag_get_device(device->machine, "pia_ic3"); |
| 519 | 520 | pia6821_ca1_w(pia, 0, data); /* copy output value to IC3 ca1 */ |
| 520 | 521 | |
| 521 | 522 | /* the output from timer2 is the input clock for timer3 */ |
| 522 | | ptm6840_set_c3( space->machine, 0, data); |
| 523 | ptm6840_set_c3(device, 0, data); |
| 523 | 524 | } |
| 524 | 525 | |
| 525 | 526 | |
| 526 | | static WRITE8_HANDLER( ic2_o3_callback ) |
| 527 | static WRITE8_DEVICE_HANDLER( ic2_o3_callback ) |
| 527 | 528 | { |
| 528 | 529 | /* the output from timer3 is used as a square wave for the alarm output |
| 529 | 530 | and as an external clock source for timer 1! */ |
| 530 | 531 | |
| 531 | | ptm6840_set_c1( space->machine, 0, data); |
| 532 | ptm6840_set_c1(device, 0, data); |
| 532 | 533 | } |
| 533 | 534 | |
| 534 | 535 | |
| 535 | 536 | static const ptm6840_interface ptm_ic2_intf = |
| 536 | 537 | { |
| 537 | | MPU4_MASTER_CLOCK/4, |
| 538 | | { 0,0,0 }, |
| 539 | | { ic2_o1_callback, ic2_o2_callback, ic2_o3_callback }, |
| 540 | | cpu0_irq_m6840 |
| 538 | MPU4_MASTER_CLOCK / 4, |
| 539 | { 0, 0, 0 }, |
| 540 | { DEVCB_HANDLER(ic2_o1_callback), |
| 541 | DEVCB_HANDLER(ic2_o2_callback), |
| 542 | DEVCB_HANDLER(ic2_o3_callback) }, |
| 543 | DEVCB_LINE(cpu0_irq_m6840) |
| 541 | 544 | }; |
| 542 | 545 | |
| 543 | 546 | |
| r4939 | r4940 | |
| 1535 | 1538 | static void mpu4_config_common(running_machine *machine) |
| 1536 | 1539 | { |
| 1537 | 1540 | ic24_timer = timer_alloc(machine, ic24_timeout, NULL); |
| 1538 | | /* setup 6840ptm */ |
| 1539 | | ptm6840_config(machine, 0, &ptm_ic2_intf ); |
| 1540 | 1541 | } |
| 1541 | 1542 | |
| 1542 | 1543 | static MACHINE_START( mpu4mod2 ) |
| r4939 | r4940 | |
| 1753 | 1754 | |
| 1754 | 1755 | AM_RANGE(0x0850, 0x0850) AM_READWRITE(bankswitch_r,bankswitch_w) /* write bank (rom page select) */ |
| 1755 | 1756 | |
| 1756 | | /* AM_RANGE(0x08E0, 0x08E7) AM_READWRITE(68681_duart_r,68681_duart_w) */ |
| 1757 | /* AM_RANGE(0x08e0, 0x08e7) AM_READWRITE(68681_duart_r,68681_duart_w) */ |
| 1757 | 1758 | |
| 1758 | | AM_RANGE(0x0900, 0x0907) AM_READWRITE(ptm6840_0_r,ptm6840_0_w) /* 6840PTM */ |
| 1759 | AM_RANGE(0x0900, 0x0907) AM_DEVREADWRITE("6840ptm", ptm6840_read, ptm6840_write) /* 6840PTM */ |
| 1759 | 1760 | |
| 1760 | | AM_RANGE(0x0A00, 0x0A03) AM_DEVREADWRITE("pia_ic3", pia6821_r,pia6821_w) /* PIA6821 IC3 */ |
| 1761 | | AM_RANGE(0x0B00, 0x0B03) AM_DEVREADWRITE("pia_ic4", pia6821_r,pia6821_w) /* PIA6821 IC4 */ |
| 1762 | | AM_RANGE(0x0C00, 0x0C03) AM_DEVREADWRITE("pia_ic5", pia6821_r,pia6821_w) /* PIA6821 IC5 */ |
| 1763 | | AM_RANGE(0x0D00, 0x0D03) AM_DEVREADWRITE("pia_ic6", pia6821_r,pia6821_w) /* PIA6821 IC6 */ |
| 1764 | | AM_RANGE(0x0E00, 0x0E03) AM_DEVREADWRITE("pia_ic7", pia6821_r,pia6821_w) /* PIA6821 IC7 */ |
| 1765 | | AM_RANGE(0x0F00, 0x0F03) AM_DEVREADWRITE("pia_ic8", pia6821_r,pia6821_w) /* PIA6821 IC8 */ |
| 1761 | AM_RANGE(0x0a00, 0x0a03) AM_DEVREADWRITE("pia_ic3", pia6821_r, pia6821_w) /* PIA6821 IC3 */ |
| 1762 | AM_RANGE(0x0b00, 0x0b03) AM_DEVREADWRITE("pia_ic4", pia6821_r, pia6821_w) /* PIA6821 IC4 */ |
| 1763 | AM_RANGE(0x0c00, 0x0c03) AM_DEVREADWRITE("pia_ic5", pia6821_r, pia6821_w) /* PIA6821 IC5 */ |
| 1764 | AM_RANGE(0x0d00, 0x0d03) AM_DEVREADWRITE("pia_ic6", pia6821_r, pia6821_w) /* PIA6821 IC6 */ |
| 1765 | AM_RANGE(0x0e00, 0x0e03) AM_DEVREADWRITE("pia_ic7", pia6821_r, pia6821_w) /* PIA6821 IC7 */ |
| 1766 | AM_RANGE(0x0f00, 0x0f03) AM_DEVREADWRITE("pia_ic8", pia6821_r, pia6821_w) /* PIA6821 IC8 */ |
| 1766 | 1767 | |
| 1767 | 1768 | AM_RANGE(0x1000, 0xffff) AM_READ(SMH_BANK(1)) /* 64k paged ROM (4 pages) */ |
| 1768 | 1769 | ADDRESS_MAP_END |
| r4939 | r4940 | |
| 1776 | 1777 | |
| 1777 | 1778 | AM_RANGE(0x0880, 0x0881) AM_DEVWRITE( "ym2413", ym2413_w ) |
| 1778 | 1779 | |
| 1779 | | // AM_RANGE(0x08E0, 0x08E7) AM_READWRITE(68681_duart_r,68681_duart_w) |
| 1780 | // AM_RANGE(0x08e0, 0x08e7) AM_READWRITE(68681_duart_r,68681_duart_w) |
| 1780 | 1781 | |
| 1781 | | AM_RANGE(0x0900, 0x0907) AM_READWRITE(ptm6840_0_r,ptm6840_0_w) // 6840PTM |
| 1782 | | AM_RANGE(0x0A00, 0x0A03) AM_DEVREADWRITE("pia_ic3", pia6821_r,pia6821_w) /* PIA6821 IC3 */ |
| 1783 | | AM_RANGE(0x0B00, 0x0B03) AM_DEVREADWRITE("pia_ic4", pia6821_r,pia6821_w) /* PIA6821 IC4 */ |
| 1784 | | AM_RANGE(0x0C00, 0x0C03) AM_DEVREADWRITE("pia_ic5", pia6821_r,pia6821_w) /* PIA6821 IC5 */ |
| 1785 | | AM_RANGE(0x0D00, 0x0D03) AM_DEVREADWRITE("pia_ic6", pia6821_r,pia6821_w) /* PIA6821 IC6 */ |
| 1786 | | AM_RANGE(0x0E00, 0x0E03) AM_DEVREADWRITE("pia_ic7", pia6821_r,pia6821_w) /* PIA6821 IC7 */ |
| 1787 | | AM_RANGE(0x0F00, 0x0F03) AM_DEVREADWRITE("pia_ic8", pia6821_r,pia6821_w) /* PIA6821 IC8 */ |
| 1782 | AM_RANGE(0x0900, 0x0907) AM_DEVREADWRITE("6840ptm", ptm6840_read, ptm6840_write) /* 6840PTM */ |
| 1788 | 1783 | |
| 1784 | AM_RANGE(0x0a00, 0x0a03) AM_DEVREADWRITE("pia_ic3", pia6821_r, pia6821_w) /* PIA6821 IC3 */ |
| 1785 | AM_RANGE(0x0b00, 0x0b03) AM_DEVREADWRITE("pia_ic4", pia6821_r, pia6821_w) /* PIA6821 IC4 */ |
| 1786 | AM_RANGE(0x0c00, 0x0c03) AM_DEVREADWRITE("pia_ic5", pia6821_r, pia6821_w) /* PIA6821 IC5 */ |
| 1787 | AM_RANGE(0x0d00, 0x0d03) AM_DEVREADWRITE("pia_ic6", pia6821_r, pia6821_w) /* PIA6821 IC6 */ |
| 1788 | AM_RANGE(0x0e00, 0x0e03) AM_DEVREADWRITE("pia_ic7", pia6821_r, pia6821_w) /* PIA6821 IC7 */ |
| 1789 | AM_RANGE(0x0f00, 0x0f03) AM_DEVREADWRITE("pia_ic8", pia6821_r, pia6821_w) /* PIA6821 IC8 */ |
| 1790 | |
| 1789 | 1791 | AM_RANGE(0x1000, 0xffff) AM_READ(SMH_BANK(1)) // 64k paged ROM (4 pages) |
| 1790 | 1792 | ADDRESS_MAP_END |
| 1791 | 1793 | |
| r4939 | r4940 | |
| 1798 | 1800 | |
| 1799 | 1801 | AM_RANGE(0x0880, 0x0883) AM_DEVREADWRITE("pia_gamebd", pia6821_r,pia6821_w) // PIA6821 on game board |
| 1800 | 1802 | |
| 1801 | | // AM_RANGE(0x08C0, 0x08C7) AM_READERITE(ptm6840_1_r,ptm6840_1_w) // 6840PTM on game board |
| 1803 | // AM_RANGE(0x08c0, 0x08c7) AM_DEVREADWRITE("??", ptm6840_read, ptm6840_write) // 6840PTM on game board |
| 1802 | 1804 | |
| 1803 | | // AM_RANGE(0x08E0, 0x08E7) AM_READWRITE(68681_duart_r,68681_duart_w) |
| 1805 | // AM_RANGE(0x08e0, 0x08e7) AM_READWRITE(68681_duart_r,68681_duart_w) |
| 1804 | 1806 | |
| 1805 | | AM_RANGE(0x0900, 0x0907) AM_READWRITE(ptm6840_0_r,ptm6840_0_w) // 6840PTM |
| 1806 | | AM_RANGE(0x0A00, 0x0A03) AM_DEVREADWRITE("pia_ic3", pia6821_r,pia6821_w) /* PIA6821 IC3 */ |
| 1807 | | AM_RANGE(0x0B00, 0x0B03) AM_DEVREADWRITE("pia_ic4", pia6821_r,pia6821_w) /* PIA6821 IC4 */ |
| 1808 | | AM_RANGE(0x0C00, 0x0C03) AM_DEVREADWRITE("pia_ic5", pia6821_r,pia6821_w) /* PIA6821 IC5 */ |
| 1809 | | AM_RANGE(0x0D00, 0x0D03) AM_DEVREADWRITE("pia_ic6", pia6821_r,pia6821_w) /* PIA6821 IC6 */ |
| 1810 | | AM_RANGE(0x0E00, 0x0E03) AM_DEVREADWRITE("pia_ic7", pia6821_r,pia6821_w) /* PIA6821 IC7 */ |
| 1811 | | AM_RANGE(0x0F00, 0x0F03) AM_DEVREADWRITE("pia_ic8", pia6821_r,pia6821_w) /* PIA6821 IC8 */ |
| 1807 | AM_RANGE(0x0900, 0x0907) AM_DEVREADWRITE("6840ptm", ptm6840_read, ptm6840_write) /* 6840PTM */ |
| 1812 | 1808 | |
| 1809 | AM_RANGE(0x0a00, 0x0a03) AM_DEVREADWRITE("pia_ic3", pia6821_r, pia6821_w) /* PIA6821 IC3 */ |
| 1810 | AM_RANGE(0x0b00, 0x0b03) AM_DEVREADWRITE("pia_ic4", pia6821_r, pia6821_w) /* PIA6821 IC4 */ |
| 1811 | AM_RANGE(0x0c00, 0x0c03) AM_DEVREADWRITE("pia_ic5", pia6821_r, pia6821_w) /* PIA6821 IC5 */ |
| 1812 | AM_RANGE(0x0d00, 0x0d03) AM_DEVREADWRITE("pia_ic6", pia6821_r, pia6821_w) /* PIA6821 IC6 */ |
| 1813 | AM_RANGE(0x0e00, 0x0e03) AM_DEVREADWRITE("pia_ic7", pia6821_r, pia6821_w) /* PIA6821 IC7 */ |
| 1814 | AM_RANGE(0x0f00, 0x0f03) AM_DEVREADWRITE("pia_ic8", pia6821_r, pia6821_w) /* PIA6821 IC8 */ |
| 1815 | |
| 1813 | 1816 | AM_RANGE(0x1000, 0xffff) AM_READ(SMH_BANK(1)) // 64k paged ROM (4 pages) |
| 1814 | 1817 | ADDRESS_MAP_END |
| 1815 | 1818 | |
| r4939 | r4940 | |
| 1824 | 1827 | AM_RANGE(0x0850, 0x0850) AM_WRITE(bankswitch_w) // write bank (rom page select) |
| 1825 | 1828 | AM_RANGE(0x0880, 0x0883) AM_DEVREADWRITE("pia_gamebd", pia6821_r,pia6821_w) // PIA6821 on game board |
| 1826 | 1829 | |
| 1827 | | // AM_RANGE(0x08C0, 0x08C7) AM_READERITE(ptm6840_2_r,ptm6840_2_w) // 6840PTM on game board |
| 1830 | // AM_RANGE(0x08c0, 0x08c7) AM_DEVREADWRITE("??", ptm6840_read, ptm6840_write) // 6840PTM on game board |
| 1828 | 1831 | |
| 1829 | | // AM_RANGE(0x08E0, 0x08E7) AM_READWRITE(68681_duart_r,68681_duart_w) |
| 1832 | // AM_RANGE(0x08e0, 0x08e7) AM_READWRITE(68681_duart_r,68681_duart_w) |
| 1830 | 1833 | |
| 1831 | | AM_RANGE(0x0900, 0x0907) AM_READWRITE(ptm6840_0_r,ptm6840_0_w) // 6840PTM |
| 1832 | | AM_RANGE(0x0A00, 0x0A03) AM_DEVREADWRITE("pia_ic3", pia6821_r,pia6821_w) /* PIA6821 IC3 */ |
| 1833 | | AM_RANGE(0x0B00, 0x0B03) AM_DEVREADWRITE("pia_ic4", pia6821_r,pia6821_w) /* PIA6821 IC4 */ |
| 1834 | | AM_RANGE(0x0C00, 0x0C03) AM_DEVREADWRITE("pia_ic5", pia6821_r,pia6821_w) /* PIA6821 IC5 */ |
| 1835 | | AM_RANGE(0x0D00, 0x0D03) AM_DEVREADWRITE("pia_ic6", pia6821_r,pia6821_w) /* PIA6821 IC6 */ |
| 1836 | | AM_RANGE(0x0E00, 0x0E03) AM_DEVREADWRITE("pia_ic7", pia6821_r,pia6821_w) /* PIA6821 IC7 */ |
| 1837 | | AM_RANGE(0x0F00, 0x0F03) AM_DEVREADWRITE("pia_ic8", pia6821_r,pia6821_w) /* PIA6821 IC8 */ |
| 1834 | AM_RANGE(0x0900, 0x0907) AM_DEVREADWRITE("6840ptm", ptm6840_read, ptm6840_write) /* 6840PTM */ |
| 1838 | 1835 | |
| 1836 | AM_RANGE(0x0a00, 0x0a03) AM_DEVREADWRITE("pia_ic3", pia6821_r, pia6821_w) /* PIA6821 IC3 */ |
| 1837 | AM_RANGE(0x0b00, 0x0b03) AM_DEVREADWRITE("pia_ic4", pia6821_r, pia6821_w) /* PIA6821 IC4 */ |
| 1838 | AM_RANGE(0x0c00, 0x0c03) AM_DEVREADWRITE("pia_ic5", pia6821_r, pia6821_w) /* PIA6821 IC5 */ |
| 1839 | AM_RANGE(0x0d00, 0x0d03) AM_DEVREADWRITE("pia_ic6", pia6821_r, pia6821_w) /* PIA6821 IC6 */ |
| 1840 | AM_RANGE(0x0e00, 0x0e03) AM_DEVREADWRITE("pia_ic7", pia6821_r, pia6821_w) /* PIA6821 IC7 */ |
| 1841 | AM_RANGE(0x0f00, 0x0f03) AM_DEVREADWRITE("pia_ic8", pia6821_r, pia6821_w) /* PIA6821 IC8 */ |
| 1842 | |
| 1839 | 1843 | AM_RANGE(0x1000, 0xffff) AM_READ(SMH_BANK(1)) // 64k paged ROM (4 pages) |
| 1840 | 1844 | ADDRESS_MAP_END |
| 1841 | 1845 | |
| r4939 | r4940 | |
| 1860 | 1864 | |
| 1861 | 1865 | MDRV_TIMER_ADD_PERIODIC("50hz",gen_50hz, HZ(100)) |
| 1862 | 1866 | |
| 1867 | /* 6840 PTM */ |
| 1868 | MDRV_PTM6840_ADD("6840ptm", ptm_ic2_intf) |
| 1869 | |
| 1863 | 1870 | MDRV_PIA6821_ADD("pia_ic3", pia_ic3_intf) |
| 1864 | 1871 | MDRV_PIA6821_ADD("pia_ic4", pia_ic4_intf) |
| 1865 | 1872 | MDRV_PIA6821_ADD("pia_ic5", pia_ic5_intf) |
src/mame/drivers/suprgolf.c
| r4939 | r4940 | |
| 1 | | /*************************************************************************** |
| 1 | /************************************************************************************ |
| 2 | 2 | |
| 3 | | Super Golf |
| 3 | Super Crowns Golf |
| 4 | 4 | preliminary WIP driver |
| 5 | | by Tomasz Slanina |
| 5 | by Tomasz Slanina & Angelo Salese |
| 6 | 6 | |
| 7 | | maybe vidram banking |
| 8 | | plenty of things unknown still |
| 7 | TODO: |
| 8 | - remove the patch and understand what needs to be modified for the gfxs, game |
| 9 | doesn't crash anymore; |
| 10 | - inputs not fully understood, sometimes analog inputs gets stuck; |
| 9 | 11 | |
| 10 | | sometimes extra bits are written to bank registers.. |
| 12 | Notes: |
| 13 | - The game uses special control panel with 1 golf club shaped device to select shot |
| 14 | strength (0,1,2,3), and 6 buttons (direction L&R, select angle of club head, club |
| 15 | select, shot, and power to use items). -YO |
| 11 | 16 | |
| 12 | | its a z80 game.. i wonder if there is a palette or it should have proms |
| 13 | | -- the rest of the hardware makes me fear so |
| 17 | ************************************************************************************/ |
| 14 | 18 | |
| 15 | | ***************************************************************************/ |
| 16 | | |
| 17 | 19 | #include "driver.h" |
| 18 | 20 | #include "cpu/z80/z80.h" |
| 19 | 21 | #include "sound/2203intf.h" |
| r4939 | r4940 | |
| 21 | 23 | |
| 22 | 24 | static tilemap *suprgolf_tilemap; |
| 23 | 25 | static UINT8 *suprgolf_bg_vram; |
| 24 | | static UINT8 *suprgolf_bg_pen; |
| 26 | static UINT16 *suprgolf_bg_fb,*suprgolf_fg_fb; |
| 25 | 27 | static int suprgolf_rom_bank; |
| 26 | 28 | static UINT8 suprgolf_bg_bank; |
| 27 | | static UINT8 suprgolf_vreg; |
| 29 | static UINT8 suprgolf_vreg_bank; |
| 28 | 30 | static UINT8 msm5205next,msm_nmi_mask; |
| 31 | static UINT8 suprgolf_vreg_pen; |
| 29 | 32 | |
| 30 | 33 | static TILE_GET_INFO( get_tile_info ) |
| 31 | 34 | { |
| r4939 | r4940 | |
| 39 | 42 | 0); |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | | static READ8_HANDLER( rom_bank_select_r ) |
| 43 | | { |
| 44 | | return suprgolf_rom_bank; |
| 45 | | } |
| 46 | | |
| 47 | | static WRITE8_HANDLER( rom_bank_select_w ) |
| 48 | | { |
| 49 | | UINT8 *region_base = memory_region(space->machine, "user1"); |
| 50 | | |
| 51 | | suprgolf_rom_bank = data; |
| 52 | | |
| 53 | | //popmessage("%08x %02x",((data & 0x3f) * 0x4000),data); |
| 54 | | |
| 55 | | mame_printf_debug("ROM_BANK 0x8000 - %X @%X\n",data,cpu_get_previouspc(space->cpu)); |
| 56 | | memory_set_bankptr(space->machine, 2, region_base + (data&0x3f ) * 0x4000); |
| 57 | | |
| 58 | | msm_nmi_mask = data & 0x40; |
| 59 | | flip_screen_set(space->machine, data & 0x80); |
| 60 | | } |
| 61 | | |
| 62 | | static WRITE8_HANDLER( rom2_bank_select_w ) |
| 63 | | { |
| 64 | | UINT8 *region_base = memory_region(space->machine, "user2"); |
| 65 | | mame_printf_debug("ROM_BANK 0x4000 - %X @%X\n",data,cpu_get_previouspc(space->cpu)); |
| 66 | | // if(data == 0) data = 1; //test hack |
| 67 | | memory_set_bankptr(space->machine, 1, region_base + (data&0x0f ) * 0x4000); |
| 68 | | |
| 69 | | if(data & 0xf0) |
| 70 | | printf("Rom bank select 2 with data %02x activated\n",data); |
| 71 | | } |
| 72 | | |
| 73 | | static MACHINE_RESET( suprgolf ) |
| 74 | | { |
| 75 | | |
| 76 | | } |
| 77 | | |
| 78 | 45 | static VIDEO_START( suprgolf ) |
| 79 | 46 | { |
| 80 | 47 | suprgolf_tilemap = tilemap_create( machine, get_tile_info,tilemap_scan_rows,8,8,32,32 ); |
| 81 | 48 | paletteram = auto_alloc_array(machine, UINT8, 0x1000); |
| 82 | 49 | suprgolf_bg_vram = auto_alloc_array(machine, UINT8, 0x2000*0x20); |
| 83 | | suprgolf_bg_pen = auto_alloc_array(machine, UINT8, 0x2000*0x20); |
| 50 | suprgolf_bg_fb = auto_alloc_array(machine, UINT16, 0x2000*0x20); |
| 51 | suprgolf_fg_fb = auto_alloc_array(machine, UINT16, 0x2000*0x20); |
| 84 | 52 | |
| 85 | 53 | tilemap_set_transparent_pen(suprgolf_tilemap,15); |
| 86 | 54 | } |
| 87 | 55 | |
| 88 | | /* TODO: fix this.*/ |
| 89 | | static void bg_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect,UINT8 starting_offs) |
| 56 | static VIDEO_UPDATE( suprgolf ) |
| 90 | 57 | { |
| 91 | | int x,y,trans; |
| 92 | | UINT32 count; |
| 58 | int x,y,count,color; |
| 59 | bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); |
| 93 | 60 | |
| 94 | | count = starting_offs<<16; |
| 95 | | trans = starting_offs; |
| 96 | | |
| 97 | | for(y=0;y<256;y++) |
| 98 | 61 | { |
| 99 | | for(x=0;x<512;x+=2) |
| 100 | | { |
| 101 | | UINT16 color; |
| 62 | count = 0; |
| 102 | 63 | |
| 103 | | color = ((suprgolf_bg_pen[count] & 0xff)<<4) | ((suprgolf_bg_vram[count] & 0xf0)>>4); |
| 104 | | //color+= ((suprgolf_bg_pen[count+0x10000])<<4); |
| 105 | | //if((x)<video_screen_get_visible_area(machine)->max_x && ((y)+0)<video_screen_get_visible_area(machine)->max_y) |
| 106 | | if(x+1 < 256) |
| 64 | for(y=0;y<256;y++) |
| 65 | { |
| 66 | for(x=0;x<512;x++) |
| 107 | 67 | { |
| 108 | | if(trans) |
| 109 | | { |
| 110 | | if((suprgolf_bg_vram[count] & 0xf0) != 0xf0) |
| 111 | | *BITMAP_ADDR32(bitmap, y, x+1) = machine->pens[(color & 0x7ff)]; |
| 112 | | } |
| 113 | | else |
| 114 | | *BITMAP_ADDR32(bitmap, y, x+1) = machine->pens[(color & 0x7ff)]; |
| 68 | color = suprgolf_bg_fb[count]; |
| 69 | |
| 70 | if(x <= cliprect->max_x && y <= cliprect->max_y) |
| 71 | *BITMAP_ADDR16(bitmap, y, x) = screen->machine->pens[(color & 0x7ff)]; |
| 72 | |
| 73 | count++; |
| 115 | 74 | } |
| 75 | } |
| 76 | } |
| 116 | 77 | |
| 117 | | color = ((suprgolf_bg_pen[count] & 0xff)<<4) | (suprgolf_bg_vram[count] & 0x0f); |
| 118 | | //color+= ((suprgolf_bg_pen[count+0x10000])<<4); |
| 78 | { |
| 79 | count = 0; |
| 119 | 80 | |
| 120 | | //if((x+1)<video_screen_get_visible_area(screen)->max_x && ((y)+0)<video_screen_get_visible_area(screen)->max_y) |
| 121 | | if(x < 256) |
| 81 | for(y=0;y<256;y++) |
| 82 | { |
| 83 | for(x=0;x<512;x++) |
| 122 | 84 | { |
| 123 | | if(trans) |
| 124 | | { |
| 125 | | if((suprgolf_bg_vram[count] & 0x0f) != 0x0f) |
| 126 | | *BITMAP_ADDR32(bitmap, y, x) = machine->pens[(color & 0x7ff)]; |
| 127 | | } |
| 128 | | else |
| 129 | | *BITMAP_ADDR32(bitmap, y, x) = machine->pens[(color & 0x7ff)]; |
| 130 | | } |
| 85 | color = suprgolf_fg_fb[count]; |
| 131 | 86 | |
| 132 | | count++; |
| 87 | if(((suprgolf_fg_fb[count] & 0x0f) != 0x0f) && (x <= cliprect->max_x && y <= cliprect->max_y)) |
| 88 | *BITMAP_ADDR16(bitmap, y, x) = screen->machine->pens[(color & 0x7ff)]; |
| 89 | |
| 90 | count++; |
| 91 | } |
| 133 | 92 | } |
| 134 | 93 | } |
| 135 | | } |
| 136 | 94 | |
| 137 | | static VIDEO_UPDATE( suprgolf ) |
| 138 | | { |
| 139 | | bg_draw(screen->machine,bitmap,cliprect,0); |
| 140 | | //bg_draw(screen->machine,bitmap,cliprect,1); |
| 141 | | bg_draw(screen->machine,bitmap,cliprect,2); //this probably should be putted over the fg tilemap too. |
| 142 | | |
| 143 | 95 | tilemap_draw(bitmap,cliprect,suprgolf_tilemap,0,0); |
| 96 | |
| 144 | 97 | return 0; |
| 145 | 98 | } |
| 146 | 99 | |
| r4939 | r4940 | |
| 163 | 116 | offset>>=1; |
| 164 | 117 | datax=paletteram[offset*2]+256*paletteram[offset*2+1]; |
| 165 | 118 | |
| 166 | | b=(datax & 0x8000) ? 0 : ((datax)&0x001f)>>0; |
| 167 | | g=(datax & 0x8000) ? 0 : ((datax)&0x03e0)>>5; |
| 168 | | r=(datax & 0x8000) ? 0 : ((datax)&0x7c00)>>10; |
| 119 | b = (datax & 0x8000) ? 0 : ((datax)&0x001f)>>0; |
| 120 | g = (datax & 0x8000) ? 0 : ((datax)&0x03e0)>>5; |
| 121 | r = (datax & 0x8000) ? 0 : ((datax)&0x7c00)>>10; |
| 169 | 122 | |
| 170 | 123 | palette_set_color_rgb(space->machine, offset, pal5bit(r), pal5bit(g), pal5bit(b)); |
| 171 | 124 | } |
| r4939 | r4940 | |
| 178 | 131 | |
| 179 | 132 | static READ8_HANDLER( suprgolf_vregs_r ) |
| 180 | 133 | { |
| 181 | | return suprgolf_vreg; |
| 134 | return suprgolf_vreg_bank; |
| 182 | 135 | } |
| 183 | 136 | |
| 137 | static UINT8 suprgolf_bg_vreg_test; |
| 138 | |
| 184 | 139 | static WRITE8_HANDLER( suprgolf_vregs_w ) |
| 185 | 140 | { |
| 186 | 141 | //bits 0,1,2 and probably 3 controls the background vram banking |
| 187 | | suprgolf_vreg = data; |
| 142 | suprgolf_vreg_bank = data; |
| 188 | 143 | palette_switch = (data & 0x80); |
| 189 | 144 | suprgolf_bg_bank = (data & 0x1f); |
| 190 | 145 | |
| 146 | suprgolf_bg_vreg_test = data & 0x20; |
| 147 | |
| 191 | 148 | //if(data & 0x60) |
| 192 | 149 | // printf("Video regs with data %02x activated\n",data); |
| 193 | 150 | } |
| 194 | 151 | |
| 195 | | static UINT8 pen; |
| 196 | | |
| 197 | 152 | static READ8_HANDLER( suprgolf_bg_vram_r ) |
| 198 | 153 | { |
| 199 | 154 | return suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000]; |
| r4939 | r4940 | |
| 201 | 156 | |
| 202 | 157 | static WRITE8_HANDLER( suprgolf_bg_vram_w ) |
| 203 | 158 | { |
| 204 | | suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] = data; |
| 205 | | suprgolf_bg_pen[offset+suprgolf_bg_bank*0x2000] = data ? pen : 0; |
| 159 | static UINT8 hi_nibble,lo_nibble; |
| 160 | static UINT8 hi_dirty_dot,lo_dirty_dot; // helpers |
| 161 | |
| 162 | hi_nibble = data & 0xf0; |
| 163 | lo_nibble = data & 0x0f; |
| 164 | hi_dirty_dot = 1; |
| 165 | lo_dirty_dot = 1; |
| 166 | |
| 167 | if(hi_nibble == 0xf0) |
| 168 | { |
| 169 | hi_nibble = suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] & 0xf0; |
| 170 | if(!(suprgolf_vreg_pen & 0x80) && (!(suprgolf_bg_bank & 0x10))) |
| 171 | hi_dirty_dot = 0; |
| 172 | } |
| 173 | |
| 174 | if(lo_nibble == 0x0f) |
| 175 | { |
| 176 | lo_nibble = suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] & 0x0f; |
| 177 | if(!(suprgolf_vreg_pen & 0x80) && (!(suprgolf_bg_bank & 0x10))) |
| 178 | lo_dirty_dot = 0; |
| 179 | } |
| 180 | |
| 181 | if(suprgolf_vreg_pen & 0x80 || suprgolf_bg_bank & 0x10) |
| 182 | suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] = data; |
| 183 | else |
| 184 | suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] = hi_nibble|lo_nibble; |
| 185 | |
| 186 | if(suprgolf_bg_bank & 0x10) |
| 187 | { |
| 188 | if(hi_dirty_dot) |
| 189 | suprgolf_fg_fb[(offset+(suprgolf_bg_bank & 0x0f)*0x2000)*2+1] = (suprgolf_vreg_pen & 0x7f)<<4 | ((suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] & 0xf0)>>4); |
| 190 | if(lo_dirty_dot) |
| 191 | suprgolf_fg_fb[(offset+(suprgolf_bg_bank & 0x0f)*0x2000)*2+0] = (suprgolf_vreg_pen & 0x7f)<<4 | ((suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] & 0x0f)>>0); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | if(hi_dirty_dot) |
| 196 | suprgolf_bg_fb[(offset+(suprgolf_bg_bank & 0x0f)*0x2000)*2+1] = (suprgolf_vreg_pen & 0x7f)<<4 | ((suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] & 0xf0)>>4); |
| 197 | if(lo_dirty_dot) |
| 198 | suprgolf_bg_fb[(offset+(suprgolf_bg_bank & 0x0f)*0x2000)*2+0] = (suprgolf_vreg_pen & 0x7f)<<4 | ((suprgolf_bg_vram[offset+suprgolf_bg_bank*0x2000] & 0x0f)>>0); |
| 199 | } |
| 206 | 200 | } |
| 207 | 201 | |
| 208 | | /* maybe bit 7 isn't actually for the pen? */ |
| 209 | 202 | static WRITE8_HANDLER( suprgolf_pen_w ) |
| 210 | 203 | { |
| 211 | | pen = data; |
| 204 | suprgolf_vreg_pen = data; |
| 212 | 205 | } |
| 213 | 206 | |
| 214 | 207 | static WRITE8_HANDLER( adpcm_data_w ) |
| r4939 | r4940 | |
| 216 | 209 | msm5205next = data; |
| 217 | 210 | } |
| 218 | 211 | |
| 212 | static READ8_HANDLER( rom_bank_select_r ) |
| 213 | { |
| 214 | return suprgolf_rom_bank; |
| 215 | } |
| 216 | |
| 217 | static WRITE8_HANDLER( rom_bank_select_w ) |
| 218 | { |
| 219 | UINT8 *region_base = memory_region(space->machine, "user1"); |
| 220 | |
| 221 | suprgolf_rom_bank = data; |
| 222 | |
| 223 | //popmessage("%08x %02x",((data & 0x3f) * 0x4000),data); |
| 224 | |
| 225 | mame_printf_debug("ROM_BANK 0x8000 - %X @%X\n",data,cpu_get_previouspc(space->cpu)); |
| 226 | memory_set_bankptr(space->machine, 2, region_base + (data&0x3f ) * 0x4000); |
| 227 | |
| 228 | msm_nmi_mask = data & 0x40; |
| 229 | flip_screen_set(space->machine, data & 0x80); |
| 230 | } |
| 231 | |
| 232 | static WRITE8_HANDLER( rom2_bank_select_w ) |
| 233 | { |
| 234 | UINT8 *region_base = memory_region(space->machine, "user2"); |
| 235 | mame_printf_debug("ROM_BANK 0x4000 - %X @%X\n",data,cpu_get_previouspc(space->cpu)); |
| 236 | // if(data == 0) data = 1; //test hack |
| 237 | memory_set_bankptr(space->machine, 1, region_base + (data&0x0f ) * 0x4000); |
| 238 | |
| 239 | if(data & 0xf0) |
| 240 | printf("Rom bank select 2 with data %02x activated\n",data); |
| 241 | } |
| 242 | |
| 243 | static READ8_HANDLER( pedal_extra_bits_r ) |
| 244 | { |
| 245 | static UINT8 p1_pedal_hi,p1_sht_sw,p2_pedal_hi,p2_sht_sw; |
| 246 | |
| 247 | /* TODO: check this */ |
| 248 | p1_pedal_hi = (input_port_read(space->machine, "P1_PEDAL") & 0x10)>>3; |
| 249 | p1_sht_sw = (input_port_read(space->machine, "P1_PEDAL") & 0x80)>>7; |
| 250 | p2_pedal_hi = (input_port_read(space->machine, "P2_PEDAL") & 0x10)<<1; |
| 251 | p2_sht_sw = (input_port_read(space->machine, "P2_PEDAL") & 0x80)>>3; |
| 252 | |
| 253 | return p1_pedal_hi | p1_sht_sw | p2_pedal_hi | p2_sht_sw; |
| 254 | } |
| 255 | |
| 256 | static READ8_HANDLER( p1_r ) |
| 257 | { |
| 258 | return (input_port_read(space->machine, "P1") & 0xf0) | ((input_port_read(space->machine, "P1_PEDAL") & 0xf)); |
| 259 | } |
| 260 | |
| 261 | static READ8_HANDLER( p2_r ) |
| 262 | { |
| 263 | return (input_port_read(space->machine, "P2") & 0xf0) | ((input_port_read(space->machine, "P2_PEDAL") & 0xf)); |
| 264 | } |
| 265 | |
| 219 | 266 | static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 220 | 267 | AM_RANGE(0x0000, 0x3fff) AM_ROM |
| 221 | 268 | AM_RANGE(0x4000, 0x7fff) AM_ROMBANK(1) |
| r4939 | r4940 | |
| 227 | 274 | AM_RANGE(0xf800, 0xffff) AM_RAM |
| 228 | 275 | ADDRESS_MAP_END |
| 229 | 276 | |
| 277 | |
| 230 | 278 | static ADDRESS_MAP_START( io_map, ADDRESS_SPACE_IO, 8 ) |
| 231 | 279 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 232 | | AM_RANGE(0x00, 0x00) AM_READ_PORT("P1") |
| 233 | | AM_RANGE(0x01, 0x01) AM_READ_PORT("P2") |
| 234 | | AM_RANGE(0x02, 0x02) AM_READ_PORT("IN2") // ?? |
| 280 | AM_RANGE(0x00, 0x00) AM_READ(p1_r) |
| 281 | AM_RANGE(0x01, 0x01) AM_READ(p2_r) |
| 282 | AM_RANGE(0x02, 0x02) AM_READ(pedal_extra_bits_r) |
| 235 | 283 | // AM_RANGE(0x03, 0x03) |
| 236 | 284 | AM_RANGE(0x04, 0x04) AM_READ_PORT("SYSTEM") |
| 237 | 285 | AM_RANGE(0x05, 0x05) AM_READ(rom_bank_select_r) AM_WRITE(rom_bank_select_w) |
| 238 | | AM_RANGE(0x06, 0x06) AM_READWRITE( suprgolf_vregs_r,suprgolf_vregs_w ) // game locks up or crashes? if this doesn't return right values? |
| 286 | AM_RANGE(0x06, 0x06) AM_READWRITE( suprgolf_vregs_r,suprgolf_vregs_w ) |
| 239 | 287 | // AM_RANGE(0x07, 0x07) |
| 240 | 288 | AM_RANGE(0x08, 0x09) AM_DEVREADWRITE("ym", ym2203_r, ym2203_w) |
| 241 | 289 | AM_RANGE(0x0c, 0x0c) AM_WRITE(adpcm_data_w) |
| r4939 | r4940 | |
| 243 | 291 | |
| 244 | 292 | static INPUT_PORTS_START( suprgolf ) |
| 245 | 293 | PORT_START("P1") |
| 246 | | PORT_DIPNAME( 0x01, 0x01, "0" ) //USED! |
| 247 | | PORT_DIPSETTING( 0x01, DEF_STR( Off ) ) |
| 248 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 249 | | PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) ) |
| 250 | | PORT_DIPSETTING( 0x02, DEF_STR( Off ) ) |
| 251 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 252 | | PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) |
| 253 | | PORT_DIPSETTING( 0x04, DEF_STR( Off ) ) |
| 254 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 255 | | PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) ) |
| 256 | | PORT_DIPSETTING( 0x08, DEF_STR( Off ) ) |
| 257 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 294 | PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_SPECIAL ) /* low port of P1 Pedal */ |
| 258 | 295 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) /* D.L */ |
| 259 | 296 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) /* D.R */ |
| 260 | | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) /* CNT */ |
| 297 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) /* CNT - shot switch */ |
| 261 | 298 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) /* SEL */ |
| 262 | 299 | |
| 300 | PORT_START("P1_PEDAL") |
| 301 | PORT_BIT( 0x1f, 0x00, IPT_PEDAL ) PORT_MINMAX(0x00,0x1f) PORT_SENSITIVITY(5) PORT_KEYDELTA(5) PORT_PLAYER(1) |
| 302 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) /* release power? */ |
| 303 | |
| 263 | 304 | PORT_START("P2") |
| 264 | | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN ) //USED! |
| 265 | | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 266 | | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 267 | | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 305 | PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_SPECIAL ) /* low port of P2 Pedal */ |
| 268 | 306 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) /* D.L */ |
| 269 | 307 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2) /* D.R */ |
| 270 | | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) /* CNT */ |
| 308 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) /* CNT - shot switch */ |
| 271 | 309 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) /* SEL */ |
| 272 | 310 | |
| 273 | | PORT_START("IN2") |
| 274 | | PORT_DIPNAME( 0x01, 0x01, "2" ) |
| 275 | | PORT_DIPSETTING( 0x01, DEF_STR( Off ) ) |
| 276 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 277 | | PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) ) |
| 278 | | PORT_DIPSETTING( 0x02, DEF_STR( Off ) ) |
| 279 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 280 | | PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) |
| 281 | | PORT_DIPSETTING( 0x04, DEF_STR( Off ) ) |
| 282 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 283 | | PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) ) |
| 284 | | PORT_DIPSETTING( 0x08, DEF_STR( Off ) ) |
| 285 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 286 | | PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) ) |
| 287 | | PORT_DIPSETTING( 0x10, DEF_STR( Off ) ) |
| 288 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 289 | | PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) ) |
| 290 | | PORT_DIPSETTING( 0x20, DEF_STR( Off ) ) |
| 291 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 292 | | PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) ) |
| 293 | | PORT_DIPSETTING( 0x40, DEF_STR( Off ) ) |
| 294 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 295 | | PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) ) |
| 296 | | PORT_DIPSETTING( 0x80, DEF_STR( Off ) ) |
| 297 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 311 | PORT_START("P2_PEDAL") |
| 312 | PORT_BIT( 0x1f, 0x00, IPT_PEDAL ) PORT_MINMAX(0x00,0x1f) PORT_SENSITIVITY(5) PORT_KEYDELTA(5) PORT_PLAYER(2) |
| 313 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) /* release power? */ |
| 298 | 314 | |
| 299 | 315 | PORT_START("SYSTEM") |
| 300 | 316 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 ) /* 1P */ |
| r4939 | r4940 | |
| 310 | 326 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 ) |
| 311 | 327 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 ) |
| 312 | 328 | |
| 313 | | PORT_START("IN4") |
| 314 | | PORT_DIPNAME( 0x01, 0x01, "4" ) |
| 315 | | PORT_DIPSETTING( 0x01, DEF_STR( Off ) ) |
| 316 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 317 | | PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) ) |
| 318 | | PORT_DIPSETTING( 0x02, DEF_STR( Off ) ) |
| 319 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 320 | | PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) |
| 321 | | PORT_DIPSETTING( 0x04, DEF_STR( Off ) ) |
| 322 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 323 | | PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) ) |
| 324 | | PORT_DIPSETTING( 0x08, DEF_STR( Off ) ) |
| 325 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 326 | | PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) ) |
| 327 | | PORT_DIPSETTING( 0x10, DEF_STR( Off ) ) |
| 328 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 329 | | PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) ) |
| 330 | | PORT_DIPSETTING( 0x20, DEF_STR( Off ) ) |
| 331 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 332 | | PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) ) |
| 333 | | PORT_DIPSETTING( 0x40, DEF_STR( Off ) ) |
| 334 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 335 | | PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) ) |
| 336 | | PORT_DIPSETTING( 0x80, DEF_STR( Off ) ) |
| 337 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 338 | | |
| 339 | 329 | PORT_START("DSW0") |
| 340 | | PORT_DIPNAME( 0x03, 0x01, DEF_STR( Coinage ) ) |
| 330 | PORT_DIPNAME( 0x03, 0x01, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW1:1,2") |
| 341 | 331 | PORT_DIPSETTING( 0x03, DEF_STR( 2C_1C ) ) |
| 342 | 332 | PORT_DIPSETTING( 0x01, DEF_STR( 1C_1C ) ) |
| 343 | 333 | PORT_DIPSETTING( 0x02, DEF_STR( 1C_2C ) ) |
| 344 | 334 | PORT_DIPSETTING( 0x00, DEF_STR( 1C_5C ) ) |
| 345 | | PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) |
| 346 | | PORT_DIPSETTING( 0x04, DEF_STR( Off ) ) |
| 347 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 348 | | PORT_DIPNAME( 0x08, 0x08, "Tutorial" ) |
| 335 | PORT_DIPNAME( 0x04, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW1:3") |
| 336 | PORT_DIPSETTING( 0x00, DEF_STR( Upright ) ) |
| 337 | PORT_DIPSETTING( 0x04, DEF_STR( Cocktail ) ) |
| 338 | /* According to the manual, 4 and 5 are for Indoor Practice tries, but doesn't suit well...different version? */ |
| 339 | PORT_DIPNAME( 0x08, 0x08, "Indoor Practice" ) PORT_DIPLOCATION("SW1:4") |
| 349 | 340 | PORT_DIPSETTING( 0x00, DEF_STR( Off ) ) |
| 350 | 341 | PORT_DIPSETTING( 0x08, DEF_STR( On ) ) |
| 351 | | PORT_DIPNAME( 0x30, 0x30, "Number of Balls" ) |
| 342 | PORT_DIPNAME( 0x30, 0x30, "Number of Balls" ) PORT_DIPLOCATION("SW1:5,6") |
| 352 | 343 | PORT_DIPSETTING( 0x00, "1" ) |
| 353 | 344 | PORT_DIPSETTING( 0x10, "2" ) |
| 354 | 345 | PORT_DIPSETTING( 0x30, "3" ) |
| 355 | 346 | PORT_DIPSETTING( 0x20, "4" ) |
| 356 | | PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) ) |
| 357 | | PORT_DIPSETTING( 0x40, DEF_STR( Off ) ) |
| 358 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 359 | | PORT_DIPNAME( 0x80, 0x80, DEF_STR( Demo_Sounds ) ) |
| 347 | PORT_DIPUNUSED_DIPLOC( 0x40, 0x00, "SW1:7" ) |
| 348 | PORT_DIPNAME( 0x80, 0x80, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW1:8") |
| 360 | 349 | PORT_DIPSETTING( 0x00, DEF_STR( Off ) ) |
| 361 | 350 | PORT_DIPSETTING( 0x80, DEF_STR( On ) ) |
| 362 | 351 | |
| 363 | 352 | PORT_START("DSW1") |
| 364 | | PORT_SERVICE( 0x01, IP_ACTIVE_LOW ) |
| 365 | | PORT_DIPNAME( 0x02, 0x02, "DSW1" ) |
| 366 | | PORT_DIPSETTING( 0x02, DEF_STR( Off ) ) |
| 367 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 368 | | PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) |
| 369 | | PORT_DIPSETTING( 0x04, DEF_STR( Off ) ) |
| 370 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 371 | | PORT_DIPNAME( 0x08, 0x08, DEF_STR( Flip_Screen ) ) |
| 353 | PORT_SERVICE( 0x01, IP_ACTIVE_LOW ) PORT_DIPLOCATION("SW2:1") |
| 354 | PORT_DIPNAME( 0x06, 0x00, "Percentage of wind over 10m/s" ) PORT_DIPLOCATION("SW2:2,3") |
| 355 | PORT_DIPSETTING( 0x00, "30%" ) |
| 356 | PORT_DIPSETTING( 0x04, "40%" ) |
| 357 | PORT_DIPSETTING( 0x02, "50%" ) |
| 358 | PORT_DIPSETTING( 0x06, "60%" ) |
| 359 | PORT_DIPNAME( 0x08, 0x08, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:4") |
| 372 | 360 | PORT_DIPSETTING( 0x08, DEF_STR( Off ) ) |
| 373 | 361 | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 374 | | PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) ) |
| 375 | | PORT_DIPSETTING( 0x10, DEF_STR( Off ) ) |
| 376 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 377 | | PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) ) |
| 378 | | PORT_DIPSETTING( 0x20, DEF_STR( Off ) ) |
| 379 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 380 | | PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) ) |
| 381 | | PORT_DIPSETTING( 0x40, DEF_STR( Off ) ) |
| 382 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 383 | | PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) ) |
| 384 | | PORT_DIPSETTING( 0x80, DEF_STR( Off ) ) |
| 385 | | PORT_DIPSETTING( 0x00, DEF_STR( On ) ) |
| 362 | PORT_DIPNAME( 0x10, 0x10, DEF_STR( Allow_Continue ) ) PORT_DIPLOCATION("SW2:5") |
| 363 | PORT_DIPSETTING( 0x00, DEF_STR( No ) ) |
| 364 | PORT_DIPSETTING( 0x10, DEF_STR( Yes ) ) |
| 365 | PORT_DIPUNUSED_DIPLOC( 0x20, 0x00, "SW2:6" ) |
| 366 | PORT_DIPUNUSED_DIPLOC( 0x40, 0x00, "SW2:7" ) |
| 367 | PORT_DIPUNUSED_DIPLOC( 0x80, 0x00, "SW2:8" ) |
| 386 | 368 | INPUT_PORTS_END |
| 387 | 369 | |
| 388 | 370 | static WRITE8_DEVICE_HANDLER( suprgolf_writeA ) |
| r4939 | r4940 | |
| 453 | 435 | GFXDECODE_ENTRY( "gfx1", 0, gfxlayout, 0, 0x80 ) |
| 454 | 436 | GFXDECODE_END |
| 455 | 437 | |
| 438 | static MACHINE_RESET( suprgolf ) |
| 439 | { |
| 440 | msm_nmi_mask = 0; |
| 441 | } |
| 442 | |
| 456 | 443 | static MACHINE_DRIVER_START( suprgolf ) |
| 457 | 444 | /* basic machine hardware */ |
| 458 | 445 | MDRV_CPU_ADD("maincpu", Z80,4000000) /* guess */ |
| r4939 | r4940 | |
| 469 | 456 | MDRV_SCREEN_ADD("screen", RASTER) |
| 470 | 457 | MDRV_SCREEN_REFRESH_RATE(60) |
| 471 | 458 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500) /* not accurate */) |
| 472 | | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 459 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 473 | 460 | MDRV_SCREEN_SIZE(256, 256) |
| 474 | 461 | MDRV_SCREEN_VISIBLE_AREA(0, 255, 0, 191) |
| 475 | 462 | |
| 476 | 463 | MDRV_GFXDECODE(suprgolf) |
| 477 | | MDRV_PALETTE_LENGTH(0x1000) |
| 464 | MDRV_PALETTE_LENGTH(0x800) |
| 478 | 465 | |
| 479 | 466 | /* sound hardware */ |
| 480 | 467 | MDRV_SPEAKER_STANDARD_MONO("mono") |
| r4939 | r4940 | |
| 543 | 530 | |
| 544 | 531 | ROM_REGION( 0x70000, "gfx1", ROMREGION_DISPOSE ) |
| 545 | 532 | ROM_LOAD( "cg18.3k",0x60000, 0x10000, CRC(36edd88e) SHA1(374c95721198a88831d6f7e0b71d05e2f8465271) ) |
| 546 | | ROM_LOAD( "cg17.5f",0x50000, 0x10000, CRC(d27f87b5) SHA1(5b2927e89615589540e3853593aeff517584b6a0)) |
| 533 | ROM_LOAD( "cg17.5f",0x50000, 0x10000, CRC(d27f87b5) SHA1(5b2927e89615589540e3853593aeff517584b6a0) ) |
| 547 | 534 | ROM_LOAD( "cg16.5g",0x40000, 0x10000, CRC(0498aa2e) SHA1(988965c3a584dac17ad8c7e504fa1f1e49775611) ) |
| 548 | 535 | ROM_LOAD( "cg15.5j",0x30000, 0x10000, CRC(0fb88270) SHA1(d85a7f1bc5b3c4b13bbd887cea4c055541cbb737) ) |
| 549 | 536 | ROM_LOAD( "cg14.5k",0x20000, 0x10000, CRC(ca12e01d) SHA1(9c627fb527c8966e16dc6bdb99ec0b9728b5c5f9) ) |
| r4939 | r4940 | |
| 551 | 538 | ROM_LOAD( "cg12.6k",0x00000, 0x10000, CRC(5707b3d5) SHA1(9102a40fefb6426f2cd9d92d66fdc77e078e3f4c) ) |
| 552 | 539 | ROM_END |
| 553 | 540 | |
| 554 | | GAME( 1989, suprgolf, 0, suprgolf, suprgolf, 0, ROT0, "Nasco", "Super Crowns Golf (Japan)", GAME_NOT_WORKING | GAME_NO_COCKTAIL ) |
| 541 | static DRIVER_INIT( suprgolf ) |
| 542 | { |
| 543 | UINT8 *ROM = memory_region(machine, "user2"); |
| 544 | |
| 545 | ROM[0x74f4-0x4000] = 0x00; |
| 546 | ROM[0x74f5-0x4000] = 0x00; |
| 547 | } |
| 548 | |
| 549 | GAME( 1989, suprgolf, 0, suprgolf, suprgolf, suprgolf, ROT0, "Nasco", "Super Crowns Golf (Japan)", GAME_NOT_WORKING | GAME_IMPERFECT_GRAPHICS | GAME_NO_COCKTAIL ) |
src/mame/drivers/mpu4drvr.c
| r4939 | r4940 | |
| 365 | 365 | }; |
| 366 | 366 | |
| 367 | 367 | |
| 368 | | static void cpu1_ptm_irq(running_machine *machine, int state) |
| 368 | static WRITE_LINE_DEVICE_HANDLER( cpu1_ptm_irq ) |
| 369 | 369 | { |
| 370 | 370 | m6840_irq_state = state; |
| 371 | | update_mpu68_interrupts(machine); |
| 371 | update_mpu68_interrupts(device->machine); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | |
| 375 | | static WRITE8_HANDLER( vid_o1_callback ) |
| 375 | static WRITE8_DEVICE_HANDLER( vid_o1_callback ) |
| 376 | 376 | { |
| 377 | | ptm6840_set_c2( space->machine, 1, data); /* this output is the clock for timer2 */ |
| 377 | ptm6840_set_c2(device, 0, data); /* this output is the clock for timer2 */ |
| 378 | 378 | |
| 379 | 379 | if (data) |
| 380 | 380 | { |
| 381 | | const device_config *acia_0 = devtag_get_device(space->machine, "acia6850_0"); |
| 382 | | const device_config *acia_1 = devtag_get_device(space->machine, "acia6850_1"); |
| 381 | const device_config *acia_0 = devtag_get_device(device->machine, "acia6850_0"); |
| 382 | const device_config *acia_1 = devtag_get_device(device->machine, "acia6850_1"); |
| 383 | 383 | acia6850_tx_clock_in(acia_0); |
| 384 | 384 | acia6850_rx_clock_in(acia_0); |
| 385 | 385 | acia6850_tx_clock_in(acia_1); |
| r4939 | r4940 | |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
| 391 | | static WRITE8_HANDLER( vid_o2_callback ) |
| 391 | static WRITE8_DEVICE_HANDLER( vid_o2_callback ) |
| 392 | 392 | { |
| 393 | | ptm6840_set_c3( space->machine, 1, data); /* this output is the clock for timer3 */ |
| 393 | ptm6840_set_c3(device, 0, data); /* this output is the clock for timer3 */ |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
| 397 | | static WRITE8_HANDLER( vid_o3_callback ) |
| 397 | static WRITE8_DEVICE_HANDLER( vid_o3_callback ) |
| 398 | 398 | { |
| 399 | | ptm6840_set_c1( space->machine, 1, data); /* this output is the clock for timer1 */ |
| 399 | ptm6840_set_c1(device, 0, data); /* this output is the clock for timer1 */ |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
| 403 | 403 | static const ptm6840_interface ptm_vid_intf = |
| 404 | 404 | { |
| 405 | | VIDEO_MASTER_CLOCK/10, /* 68k E clock */ |
| 406 | | { 0,0,0 }, |
| 407 | | { vid_o1_callback, vid_o2_callback, vid_o3_callback }, |
| 408 | | cpu1_ptm_irq |
| 405 | VIDEO_MASTER_CLOCK / 10, /* 68k E clock */ |
| 406 | { 0, 0, 0 }, |
| 407 | { DEVCB_HANDLER(vid_o1_callback), |
| 408 | DEVCB_HANDLER(vid_o2_callback), |
| 409 | DEVCB_HANDLER(vid_o3_callback) }, |
| 410 | DEVCB_LINE(cpu1_ptm_irq) |
| 409 | 411 | }; |
| 410 | 412 | |
| 411 | 413 | |
| r4939 | r4940 | |
| 1381 | 1383 | { |
| 1382 | 1384 | mpu4_config_common(machine); |
| 1383 | 1385 | |
| 1384 | | ptm6840_config(machine, 1, &ptm_vid_intf ); |
| 1385 | | |
| 1386 | 1386 | /* setup communications */ |
| 1387 | | serial_card_connected=1; |
| 1387 | serial_card_connected = 1; |
| 1388 | 1388 | |
| 1389 | 1389 | /* setup 8 mechanical meters */ |
| 1390 | 1390 | Mechmtr_init(8); |
| r4939 | r4940 | |
| 1398 | 1398 | |
| 1399 | 1399 | /* setup the standard oki MSC1937 display */ |
| 1400 | 1400 | |
| 1401 | | ROC10937_init(0, MSC1937,0); |
| 1401 | ROC10937_init(0, MSC1937, 0); |
| 1402 | 1402 | } |
| 1403 | 1403 | |
| 1404 | 1404 | /* |
| r4939 | r4940 | |
| 1466 | 1466 | AM_RANGE(0xff8000, 0xff8001) AM_DEVREADWRITE8("acia6850_1", acia6850_stat_r, acia6850_ctrl_w, 0xff) |
| 1467 | 1467 | AM_RANGE(0xff8002, 0xff8003) AM_DEVREADWRITE8("acia6850_1", acia6850_data_r, acia6850_data_w, 0xff) |
| 1468 | 1468 | |
| 1469 | | AM_RANGE(0xff9000, 0xff900f) AM_READWRITE(ptm6840_1_lsb_r,ptm6840_1_lsb_w) /* 6840PTM */ |
| 1469 | /* 6840PTM */ |
| 1470 | AM_RANGE(0xff9000, 0xff900f) AM_DEVREADWRITE8("6840ptm_68k", ptm6840_read, ptm6840_write, 0xff) |
| 1470 | 1471 | |
| 1471 | 1472 | AM_RANGE(0xffd000, 0xffd00f) AM_READWRITE(characteriser16_r, characteriser16_w) /* characterizer */ |
| 1472 | 1473 | ADDRESS_MAP_END |
| 1473 | 1474 | |
| 1474 | 1475 | /* TODO: Fix up MPU4 map*/ |
| 1475 | 1476 | static ADDRESS_MAP_START( mpu4_6809_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 1476 | | AM_RANGE(0x0000, 0x07FF) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size) |
| 1477 | AM_RANGE(0x0000, 0x07ff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size) |
| 1477 | 1478 | |
| 1478 | 1479 | AM_RANGE(0x0800, 0x0800) AM_DEVREADWRITE("acia6850_0", acia6850_stat_r, acia6850_ctrl_w) |
| 1479 | 1480 | AM_RANGE(0x0801, 0x0801) AM_DEVREADWRITE("acia6850_0", acia6850_data_r, acia6850_data_w) |
| 1480 | 1481 | |
| 1481 | 1482 | AM_RANGE(0x0880, 0x0881) AM_NOP /* Could be a UART datalogger is here. */ |
| 1482 | 1483 | |
| 1483 | | AM_RANGE(0x0900, 0x0907) AM_READWRITE(ptm6840_0_r,ptm6840_0_w) /* 6840PTM */ |
| 1484 | AM_RANGE(0x0900, 0x0907) AM_DEVREADWRITE("6840ptm", ptm6840_read, ptm6840_write) /* 6840PTM */ |
| 1484 | 1485 | |
| 1485 | | AM_RANGE(0x0A00, 0x0A03) AM_DEVREADWRITE("pia_ic3", pia6821_r,pia6821_w) /* PIA6821 IC3 */ |
| 1486 | | AM_RANGE(0x0B00, 0x0B03) AM_DEVREADWRITE("pia_ic4", pia6821_r,pia6821_w) /* PIA6821 IC4 */ |
| 1487 | | AM_RANGE(0x0C00, 0x0C03) AM_DEVREADWRITE("pia_ic5", pia6821_r,pia6821_w) /* PIA6821 IC5 */ |
| 1488 | | AM_RANGE(0x0D00, 0x0D03) AM_DEVREADWRITE("pia_ic6", pia6821_r,pia6821_w) /* PIA6821 IC6 */ |
| 1489 | | AM_RANGE(0x0E00, 0x0E03) AM_DEVREADWRITE("pia_ic7", pia6821_r,pia6821_w) /* PIA6821 IC7 */ |
| 1490 | | AM_RANGE(0x0F00, 0x0F03) AM_DEVREADWRITE("pia_ic8", pia6821_r,pia6821_w) /* PIA6821 IC8 */ |
| 1486 | AM_RANGE(0x0a00, 0x0a03) AM_DEVREADWRITE("pia_ic3", pia6821_r, pia6821_w) /* PIA6821 IC3 */ |
| 1487 | AM_RANGE(0x0b00, 0x0b03) AM_DEVREADWRITE("pia_ic4", pia6821_r, pia6821_w) /* PIA6821 IC4 */ |
| 1488 | AM_RANGE(0x0c00, 0x0c03) AM_DEVREADWRITE("pia_ic5", pia6821_r, pia6821_w) /* PIA6821 IC5 */ |
| 1489 | AM_RANGE(0x0d00, 0x0d03) AM_DEVREADWRITE("pia_ic6", pia6821_r, pia6821_w) /* PIA6821 IC6 */ |
| 1490 | AM_RANGE(0x0e00, 0x0e03) AM_DEVREADWRITE("pia_ic7", pia6821_r, pia6821_w) /* PIA6821 IC7 */ |
| 1491 | AM_RANGE(0x0f00, 0x0f03) AM_DEVREADWRITE("pia_ic8", pia6821_r, pia6821_w) /* PIA6821 IC8 */ |
| 1491 | 1492 | |
| 1492 | | AM_RANGE(0x4000, 0x40FF) AM_RAM /* it actually runs code from here... */ |
| 1493 | AM_RANGE(0x4000, 0x40ff) AM_RAM /* it actually runs code from here... */ |
| 1493 | 1494 | |
| 1494 | | AM_RANGE(0xBE00, 0xBFFF) AM_RAM /* 00 written on startup */ |
| 1495 | | AM_RANGE(0xC000, 0xFFFF) AM_ROM AM_REGION("maincpu",0) /* 64k EPROM on board, only this region read */ |
| 1495 | AM_RANGE(0xbe00, 0xbfff) AM_RAM /* 00 written on startup */ |
| 1496 | AM_RANGE(0xc000, 0xffff) AM_ROM AM_REGION("maincpu",0) /* 64k EPROM on board, only this region read */ |
| 1496 | 1497 | ADDRESS_MAP_END |
| 1497 | 1498 | |
| 1498 | 1499 | static ADDRESS_MAP_START( vp_68k_map, ADDRESS_SPACE_PROGRAM, 16 ) |
| r4939 | r4940 | |
| 1522 | 1523 | AM_RANGE(0xff8000, 0xff8001) AM_DEVREADWRITE8("acia6850_1", acia6850_stat_r, acia6850_ctrl_w, 0xff) |
| 1523 | 1524 | AM_RANGE(0xff8002, 0xff8003) AM_DEVREADWRITE8("acia6850_1", acia6850_data_r, acia6850_data_w, 0xff) |
| 1524 | 1525 | |
| 1525 | | AM_RANGE(0xff9000, 0xff900f) AM_READ( ptm6840_1_lsb_r) |
| 1526 | | AM_RANGE(0xff9000, 0xff900f) AM_WRITE( ptm6840_1_lsb_w) |
| 1526 | /* 6840PTM */ |
| 1527 | AM_RANGE(0xff9000, 0xff900f) AM_DEVREADWRITE8("6840ptm_68k", ptm6840_read, ptm6840_write, 0xff) |
| 1527 | 1528 | |
| 1528 | 1529 | /* characterizer */ |
| 1529 | 1530 | /* AM_RANGE(0xffd000, 0xffd00f) AM_READWRITE(characteriser16_r, characteriser16_w) Word-based version of old CHR??? */ |
| r4939 | r4940 | |
| 1662 | 1663 | AM_RANGE(0x0800, 0x0800) AM_DEVWRITE("crtc", mc6845_address_w) |
| 1663 | 1664 | AM_RANGE(0x0801, 0x0801) AM_DEVREADWRITE("crtc", mc6845_register_r, mc6845_register_w) |
| 1664 | 1665 | |
| 1665 | | /* AM_RANGE(0x08E0, 0x08E7) AM_READWRITE(68681_duart_r,68681_duart_w) */ |
| 1666 | /* AM_RANGE(0x08e0, 0x08e7) AM_READWRITE(68681_duart_r,68681_duart_w) */ |
| 1666 | 1667 | |
| 1667 | | AM_RANGE(0x0900, 0x0907) AM_READWRITE(ptm6840_0_r,ptm6840_0_w) /* 6840PTM */ |
| 1668 | AM_RANGE(0x0900, 0x0907) AM_DEVREADWRITE("6840ptm", ptm6840_read, ptm6840_write) /* 6840PTM */ |
| 1668 | 1669 | |
| 1669 | | AM_RANGE(0x0A00, 0x0A03) AM_DEVREADWRITE("pia_ic3", pia6821_r,pia6821_w) /* PIA6821 IC3 */ |
| 1670 | | AM_RANGE(0x0B00, 0x0B03) AM_DEVREADWRITE("pia_ic4", pia6821_r,pia6821_w) /* PIA6821 IC4 */ |
| 1671 | | AM_RANGE(0x0C00, 0x0C03) AM_DEVREADWRITE("pia_ic5", pia6821_r,pia6821_w) /* PIA6821 IC5 */ |
| 1672 | | AM_RANGE(0x0D00, 0x0D03) AM_DEVREADWRITE("pia_ic6", pia6821_r,pia6821_w) /* PIA6821 IC6 */ |
| 1673 | | AM_RANGE(0x0E00, 0x0E03) AM_DEVREADWRITE("pia_ic7", pia6821_r,pia6821_w) /* PIA6821 IC7 */ |
| 1674 | | AM_RANGE(0x0F00, 0x0F03) AM_DEVREADWRITE("pia_ic8", pia6821_r,pia6821_w) /* PIA6821 IC8 */ |
| 1670 | AM_RANGE(0x0a00, 0x0a03) AM_DEVREADWRITE("pia_ic3", pia6821_r, pia6821_w) /* PIA6821 IC3 */ |
| 1671 | AM_RANGE(0x0b00, 0x0b03) AM_DEVREADWRITE("pia_ic4", pia6821_r, pia6821_w) /* PIA6821 IC4 */ |
| 1672 | AM_RANGE(0x0c00, 0x0c03) AM_DEVREADWRITE("pia_ic5", pia6821_r, pia6821_w) /* PIA6821 IC5 */ |
| 1673 | AM_RANGE(0x0d00, 0x0d03) AM_DEVREADWRITE("pia_ic6", pia6821_r, pia6821_w) /* PIA6821 IC6 */ |
| 1674 | AM_RANGE(0x0e00, 0x0e03) AM_DEVREADWRITE("pia_ic7", pia6821_r, pia6821_w) /* PIA6821 IC7 */ |
| 1675 | AM_RANGE(0x0f00, 0x0f03) AM_DEVREADWRITE("pia_ic8", pia6821_r, pia6821_w) /* PIA6821 IC8 */ |
| 1675 | 1676 | |
| 1676 | 1677 | AM_RANGE(0x1000, 0x2fff) AM_RAM AM_BASE(&dealem_videoram) |
| 1677 | 1678 | AM_RANGE(0x8000, 0xffff) AM_ROM AM_WRITENOP/* 64k paged ROM (4 pages) */ |
| r4939 | r4940 | |
| 1685 | 1686 | |
| 1686 | 1687 | MDRV_NVRAM_HANDLER(generic_0fill) /* confirm */ |
| 1687 | 1688 | |
| 1689 | /* 6840 PTM */ |
| 1690 | MDRV_PTM6840_ADD("6840ptm", ptm_ic2_intf) |
| 1691 | |
| 1688 | 1692 | MDRV_PIA6821_ADD("pia_ic3", pia_ic3_intf) |
| 1689 | 1693 | MDRV_PIA6821_ADD("pia_ic4", pia_ic4_intf) |
| 1690 | 1694 | MDRV_PIA6821_ADD("pia_ic5", pia_ic5_intf) |
| r4939 | r4940 | |
| 1712 | 1716 | |
| 1713 | 1717 | MDRV_PALETTE_LENGTH(16) |
| 1714 | 1718 | |
| 1719 | /* 6840 PTM */ |
| 1720 | MDRV_PTM6840_ADD("6840ptm_68k", ptm_vid_intf) |
| 1721 | |
| 1715 | 1722 | MDRV_SPEAKER_STANDARD_MONO("mono") |
| 1716 | 1723 | MDRV_SOUND_ADD("ay8913",AY8913, MPU4_MASTER_CLOCK/4) |
| 1717 | 1724 | MDRV_SOUND_CONFIG(ay8910_config) |
| r4939 | r4940 | |
| 1743 | 1750 | |
| 1744 | 1751 | MDRV_TIMER_ADD_PERIODIC("50hz",gen_50hz, HZ(100)) |
| 1745 | 1752 | |
| 1753 | /* 6840 PTM */ |
| 1754 | MDRV_PTM6840_ADD("6840ptm", ptm_ic2_intf) |
| 1755 | |
| 1746 | 1756 | MDRV_PIA6821_ADD("pia_ic3", pia_ic3_intf) |
| 1747 | 1757 | MDRV_PIA6821_ADD("pia_ic4", pia_ic4_intf) |
| 1748 | 1758 | MDRV_PIA6821_ADD("pia_ic5", pia_ic5_intf) |
src/mame/drivers/ksys573.c
| r4939 | r4940 | |
| 351 | 351 | static READ32_HANDLER( jamma_r ) |
| 352 | 352 | { |
| 353 | 353 | running_machine *machine = space->machine; |
| 354 | const device_config *adc0834 = devtag_get_device(space->machine, "adc0834"); |
| 354 | 355 | UINT32 data = 0; |
| 355 | 356 | |
| 356 | 357 | switch (offset) |
| r4939 | r4940 | |
| 368 | 369 | data |= ds2401_read( machine, security_cart_number ) << 14; |
| 369 | 370 | } |
| 370 | 371 | |
| 371 | | data |= adc083x_do_read( machine, 0 ) << 16; |
| 372 | data |= adc083x_do_read(adc0834, 0) << 16; |
| 372 | 373 | |
| 373 | 374 | switch( chiptype[ security_cart_number ] ) |
| 374 | 375 | { |
| r4939 | r4940 | |
| 411 | 412 | static WRITE32_HANDLER( jamma_w ) |
| 412 | 413 | { |
| 413 | 414 | running_machine *machine = space->machine; |
| 415 | const device_config *adc0834 = devtag_get_device(space->machine, "adc0834"); |
| 414 | 416 | verboselog( machine, 2, "jamma_w( %08x, %08x, %08x )\n", offset, mem_mask, data ); |
| 415 | 417 | |
| 416 | 418 | switch( offset ) |
| 417 | 419 | { |
| 418 | 420 | case 0: |
| 419 | | adc083x_cs_write( machine, 0, ( data >> 1 ) & 1 ); |
| 420 | | adc083x_clk_write( machine, 0, ( data >> 2 ) & 1 ); |
| 421 | | adc083x_di_write( machine, 0, ( data >> 0 ) & 1 ); |
| 422 | | adc083x_se_write( machine, 0, 0 ); |
| 421 | adc083x_cs_write(adc0834, 0, (data >> 1) & 1); |
| 422 | adc083x_clk_write(adc0834, 0, (data >> 2) & 1); |
| 423 | adc083x_di_write(adc0834, 0, (data >> 0) & 1); |
| 424 | adc083x_se_write(adc0834, 0, 0); |
| 423 | 425 | break; |
| 424 | 426 | |
| 425 | 427 | default: |
| r4939 | r4940 | |
| 1384 | 1386 | ADDRESS_MAP_END |
| 1385 | 1387 | |
| 1386 | 1388 | |
| 1389 | |
| 1387 | 1390 | static void flash_init( running_machine *machine ) |
| 1388 | 1391 | { |
| 1389 | 1392 | int i; |
| r4939 | r4940 | |
| 1440 | 1443 | state_save_register_global(machine, control ); |
| 1441 | 1444 | } |
| 1442 | 1445 | |
| 1443 | | static double analogue_inputs_callback( running_machine *machine, int input ) |
| 1444 | | { |
| 1445 | | switch( input ) |
| 1446 | | { |
| 1447 | | case ADC083X_CH0: |
| 1448 | | return (double) ( input_port_read_safe(machine, "analog0", 0 ) * 5 ) / 255; |
| 1449 | | case ADC083X_CH1: |
| 1450 | | return (double) ( input_port_read_safe(machine, "analog1", 0 ) * 5 ) / 255; |
| 1451 | | case ADC083X_CH2: |
| 1452 | | return (double) ( input_port_read_safe(machine, "analog2", 0 ) * 5 ) / 255; |
| 1453 | | case ADC083X_CH3: |
| 1454 | | return (double) ( input_port_read_safe(machine, "analog3", 0 ) * 5 ) / 255; |
| 1455 | | case ADC083X_AGND: |
| 1456 | | return 0; |
| 1457 | | case ADC083X_VREF: |
| 1458 | | return 5; |
| 1459 | | } |
| 1460 | | return 0; |
| 1461 | | } |
| 1462 | | |
| 1463 | 1446 | static void *atapi_get_device(void) |
| 1464 | 1447 | { |
| 1465 | 1448 | void *ret; |
| r4939 | r4940 | |
| 1570 | 1553 | state_save_register_item_array( machine, "KSYS573", NULL, 0, m_p_n_root_target ); |
| 1571 | 1554 | state_save_register_item_array( machine, "KSYS573", NULL, 0, m_p_n_root_start ); |
| 1572 | 1555 | |
| 1573 | | adc083x_init( machine, 0, ADC0834, analogue_inputs_callback ); |
| 1574 | 1556 | flash_init(machine); |
| 1575 | 1557 | } |
| 1576 | 1558 | |
| r4939 | r4940 | |
| 1662 | 1644 | |
| 1663 | 1645 | static READ32_HANDLER( ge765pwbba_r ) |
| 1664 | 1646 | { |
| 1647 | const device_config *upd4701 = devtag_get_device(space->machine, "upd4701"); |
| 1665 | 1648 | UINT32 data = 0; |
| 1666 | 1649 | |
| 1667 | | switch( offset ) |
| 1650 | switch (offset) |
| 1668 | 1651 | { |
| 1669 | 1652 | case 0x26: |
| 1670 | | uPD4701_y_add( 0, input_port_read_safe(space->machine, "uPD4701_y", 0 ) ); |
| 1671 | | uPD4701_switches_set( 0, input_port_read_safe(space->machine, "uPD4701_switches", 0 ) ); |
| 1653 | upd4701_y_add(upd4701, 0, input_port_read_safe(space->machine, "uPD4701_y", 0), 0xffff); |
| 1654 | upd4701_switches_set(upd4701, 0, input_port_read_safe(space->machine, "uPD4701_switches", 0)); |
| 1672 | 1655 | |
| 1673 | | uPD4701_cs_w( 0, 0 ); |
| 1674 | | uPD4701_xy_w( 0, 1 ); |
| 1656 | upd4701_cs_w(upd4701, 0, 0); |
| 1657 | upd4701_xy_w(upd4701, 0, 1); |
| 1675 | 1658 | |
| 1676 | | if( ACCESSING_BITS_0_7 ) |
| 1659 | if (ACCESSING_BITS_0_7) |
| 1677 | 1660 | { |
| 1678 | | uPD4701_ul_w( 0, 0 ); |
| 1679 | | data |= uPD4701_d_r( 0 ) << 0; |
| 1661 | upd4701_ul_w(upd4701, 0, 0); |
| 1662 | data |= upd4701_d_r(upd4701, 0, 0xffff) << 0; |
| 1680 | 1663 | } |
| 1681 | 1664 | |
| 1682 | | if( ACCESSING_BITS_16_23 ) |
| 1665 | if (ACCESSING_BITS_16_23) |
| 1683 | 1666 | { |
| 1684 | | uPD4701_ul_w( 0, 1 ); |
| 1685 | | data |= uPD4701_d_r( 0 ) << 16; |
| 1667 | upd4701_ul_w(upd4701, 0, 1); |
| 1668 | data |= upd4701_d_r(upd4701, 0, 0xffff) << 16; |
| 1686 | 1669 | } |
| 1687 | 1670 | |
| 1688 | | uPD4701_cs_w( 0, 1 ); |
| 1671 | upd4701_cs_w(upd4701, 0, 1); |
| 1689 | 1672 | break; |
| 1690 | 1673 | |
| 1691 | 1674 | default: |
| 1692 | | verboselog( space->machine, 0, "ge765pwbba_r: unhandled offset %08x %08x\n", offset, mem_mask ); |
| 1675 | verboselog(space->machine, 0, "ge765pwbba_r: unhandled offset %08x %08x\n", offset, mem_mask); |
| 1693 | 1676 | break; |
| 1694 | 1677 | } |
| 1695 | 1678 | |
| 1696 | | verboselog( space->machine, 2, "ge765pwbba_r( %08x, %08x ) %08x\n", offset, mem_mask, data ); |
| 1679 | verboselog(space->machine, 2, "ge765pwbba_r( %08x, %08x ) %08x\n", offset, mem_mask, data); |
| 1697 | 1680 | return data; |
| 1698 | 1681 | } |
| 1699 | 1682 | |
| 1700 | 1683 | static WRITE32_HANDLER( ge765pwbba_w ) |
| 1701 | 1684 | { |
| 1702 | | switch( offset ) |
| 1685 | const device_config *upd4701 = devtag_get_device(space->machine, "upd4701"); |
| 1686 | switch (offset) |
| 1703 | 1687 | { |
| 1704 | 1688 | case 0x04: |
| 1705 | 1689 | break; |
| 1706 | 1690 | |
| 1707 | 1691 | case 0x20: |
| 1708 | | if( ACCESSING_BITS_0_7 ) |
| 1692 | if (ACCESSING_BITS_0_7) |
| 1709 | 1693 | { |
| 1710 | | output_set_value( "motor", data & 0xff ); |
| 1694 | output_set_value("motor", data & 0xff); |
| 1711 | 1695 | } |
| 1712 | 1696 | break; |
| 1713 | 1697 | |
| 1714 | 1698 | case 0x22: |
| 1715 | | if( ACCESSING_BITS_0_7 ) |
| 1699 | if (ACCESSING_BITS_0_7) |
| 1716 | 1700 | { |
| 1717 | | output_set_value( "brake", data & 0xff ); |
| 1701 | output_set_value("brake", data & 0xff); |
| 1718 | 1702 | } |
| 1719 | 1703 | break; |
| 1720 | 1704 | |
| 1721 | 1705 | case 0x28: |
| 1722 | | if( ACCESSING_BITS_0_7 ) |
| 1706 | if (ACCESSING_BITS_0_7) |
| 1723 | 1707 | { |
| 1724 | | uPD4701_resety_w( 0, 1 ); |
| 1725 | | uPD4701_resety_w( 0, 0 ); |
| 1708 | upd4701_resety_w(upd4701, 0, 1); |
| 1709 | upd4701_resety_w(upd4701, 0, 0); |
| 1726 | 1710 | } |
| 1727 | 1711 | break; |
| 1728 | 1712 | |
| 1729 | 1713 | default: |
| 1730 | | verboselog( space->machine, 0, "ge765pwbba_w: unhandled offset %08x %08x %08x\n", offset, mem_mask, data ); |
| 1714 | verboselog(space->machine, 0, "ge765pwbba_w: unhandled offset %08x %08x %08x\n", offset, mem_mask, data); |
| 1731 | 1715 | break; |
| 1732 | 1716 | } |
| 1733 | 1717 | |
| 1734 | | verboselog( space->machine, 2, "ge765pwbba_w( %08x, %08x, %08x )\n", offset, mem_mask, data ); |
| 1718 | verboselog(space->machine, 2, "ge765pwbba_w( %08x, %08x, %08x )\n", offset, mem_mask, data); |
| 1735 | 1719 | } |
| 1736 | 1720 | |
| 1737 | 1721 | static DRIVER_INIT( ge765pwbba ) |
| 1738 | 1722 | { |
| 1739 | 1723 | DRIVER_INIT_CALL(konami573); |
| 1740 | | |
| 1741 | | uPD4701_init( machine, 0 ); |
| 1742 | | |
| 1743 | 1724 | memory_install_readwrite32_handler( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f640000, 0x1f6400ff, 0, 0, ge765pwbba_r, ge765pwbba_w ); |
| 1744 | 1725 | } |
| 1745 | 1726 | |
| r4939 | r4940 | |
| 2783 | 2764 | state_save_register_global(machine, salarymc_lamp_clk ); |
| 2784 | 2765 | } |
| 2785 | 2766 | |
| 2767 | |
| 2768 | |
| 2769 | /* ADC0834 Interface */ |
| 2770 | |
| 2771 | static double analogue_inputs_callback( const device_config *device, UINT8 input ) |
| 2772 | { |
| 2773 | switch (input) |
| 2774 | { |
| 2775 | case ADC083X_CH0: |
| 2776 | return (double)(5 * input_port_read_safe(device->machine, "analog0", 0)) / 255.0; |
| 2777 | case ADC083X_CH1: |
| 2778 | return (double)(5 * input_port_read_safe(device->machine, "analog1", 0)) / 255.0; |
| 2779 | case ADC083X_CH2: |
| 2780 | return (double)(5 * input_port_read_safe(device->machine, "analog2", 0)) / 255.0; |
| 2781 | case ADC083X_CH3: |
| 2782 | return (double)(5 * input_port_read_safe(device->machine, "analog3", 0)) / 255.0; |
| 2783 | case ADC083X_AGND: |
| 2784 | return 0; |
| 2785 | case ADC083X_VREF: |
| 2786 | return 5; |
| 2787 | } |
| 2788 | return 0; |
| 2789 | } |
| 2790 | |
| 2791 | |
| 2792 | static const adc0831_interface konami573_adc_interface = { |
| 2793 | analogue_inputs_callback |
| 2794 | }; |
| 2795 | |
| 2786 | 2796 | static MACHINE_DRIVER_START( konami573 ) |
| 2787 | 2797 | /* basic machine hardware */ |
| 2788 | 2798 | MDRV_CPU_ADD("maincpu", PSXCPU, XTAL_67_7376MHz ) |
| r4939 | r4940 | |
| 2819 | 2829 | MDRV_SOUND_ROUTE( 1, "rspeaker", 1.0 ) |
| 2820 | 2830 | |
| 2821 | 2831 | MDRV_M48T58_ADD( "m48t58" ) |
| 2832 | |
| 2833 | MDRV_ADC0834_ADD( "adc0834", konami573_adc_interface ) |
| 2822 | 2834 | MACHINE_DRIVER_END |
| 2823 | 2835 | |
| 2836 | |
| 2837 | static MACHINE_DRIVER_START( k573bait ) |
| 2838 | MDRV_IMPORT_FROM(konami573) |
| 2839 | |
| 2840 | /* Additional NEC Encoder */ |
| 2841 | MDRV_UPD4701_ADD( "upd4701" ) |
| 2842 | MACHINE_DRIVER_END |
| 2843 | |
| 2824 | 2844 | static INPUT_PORTS_START( konami573 ) |
| 2825 | 2845 | PORT_START("IN0") |
| 2826 | 2846 | PORT_BIT( 0xffffffff, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| r4939 | r4940 | |
| 3070 | 3090 | PORT_BIT( 0x08000000, IP_ACTIVE_LOW, IPT_UNUSED ) /* P2 BUTTON6 */ |
| 3071 | 3091 | INPUT_PORTS_END |
| 3072 | 3092 | |
| 3093 | |
| 3073 | 3094 | #define SYS573_BIOS_A ROM_LOAD( "700a01.22g", 0x0000000, 0x080000, CRC(11812ef8) SHA1(e1284add4aaddd5337bd7f4e27614460d52b5b48)) |
| 3074 | 3095 | |
| 3075 | 3096 | // BIOS |
| r4939 | r4940 | |
| 4542 | 4563 | GAME( 1998, sys573, 0, konami573, konami573, konami573, ROT0, "Konami", "System 573 BIOS", GAME_IS_BIOS_ROOT ) |
| 4543 | 4564 | |
| 4544 | 4565 | GAME( 1998, darkhleg, sys573, konami573, konami573, konami573, ROT0, "Konami", "Dark Horse Legend (GX706 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4545 | | GAME( 1998, fbaitbc, sys573, konami573, fbaitbc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - A Bass Challenge (GE765 VER. UAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4546 | | GAME( 1998, bassangl, fbaitbc, konami573, fbaitbc, ge765pwbba, ROT0, "Konami", "Bass Angler (GE765 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4566 | GAME( 1998, fbaitbc, sys573, k573bait, fbaitbc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - A Bass Challenge (GE765 VER. UAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4567 | GAME( 1998, bassangl, fbaitbc, k573bait, fbaitbc, ge765pwbba, ROT0, "Konami", "Bass Angler (GE765 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4547 | 4568 | GAME( 1998, pbballex, sys573, konami573, konami573, konami573, ROT0, "Konami", "Powerful Pro Baseball EX (GX802 VER. JAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4548 | 4569 | GAME( 1998, konam80s, sys573, konami573, konami573, konami573, ROT90, "Konami", "Konami 80's AC Special (GC826 VER. EAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4549 | 4570 | GAME( 1998, konam80u, konam80s, konami573, konami573, konami573, ROT90, "Konami", "Konami 80's AC Special (GC826 VER. UAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| r4939 | r4940 | |
| 4556 | 4577 | GAME( 1998, ddrja, dstage, konami573, ddr, ddr, ROT0, "Konami", "Dance Dance Revolution (GC845 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) |
| 4557 | 4578 | GAME( 1998, ddrjb, dstage, konami573, ddr, ddr, ROT0, "Konami", "Dance Dance Revolution (GC845 VER. JAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) |
| 4558 | 4579 | GAME( 1999, ddra, dstage, konami573, ddr, ddr, ROT0, "Konami", "Dance Dance Revolution (GN845 VER. AAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4559 | | GAME( 1998, fbait2bc, sys573, konami573, fbaitbc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait 2 - A Bass Challenge (GE865 VER. UAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4580 | GAME( 1998, fbait2bc, sys573, k573bait, fbaitbc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait 2 - A Bass Challenge (GE865 VER. UAB)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4560 | 4581 | GAME( 1999, drmn, sys573, konami573, drmn, drmn, ROT0, "Konami", "DrumMania (GQ881 VER. JAD)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING ) |
| 4561 | 4582 | GAME( 1999, gtrfrks, sys573, konami573, gtrfrks, gtrfrks, ROT0, "Konami", "Guitar Freaks (GQ886 VER. EAC)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4562 | 4583 | GAME( 1999, gtrfrksu, gtrfrks, konami573, gtrfrks, gtrfrks, ROT0, "Konami", "Guitar Freaks (GQ886 VER. UAC)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4563 | 4584 | GAME( 1999, gtrfrksj, gtrfrks, konami573, gtrfrks, gtrfrks, ROT0, "Konami", "Guitar Freaks (GQ886 VER. JAC)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4564 | 4585 | GAME( 1999, gtrfrksa, gtrfrks, konami573, gtrfrks, gtrfrks, ROT0, "Konami", "Guitar Freaks (GQ886 VER. AAC)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4565 | | GAME( 1999, fbaitmc, sys573, konami573, fbaitmc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - Marlin Challenge (GX889 VER. EA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4566 | | GAME( 1999, fbaitmcu, fbaitmc, konami573, fbaitmc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - Marlin Challenge (GX889 VER. UA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4567 | | GAME( 1999, fbaitmcj, fbaitmc, konami573, fbaitmc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - Marlin Challenge (GX889 VER. JA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4568 | | GAME( 1999, fbaitmca, fbaitmc, konami573, fbaitmc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - Marlin Challenge (GX889 VER. AA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4586 | GAME( 1999, fbaitmc, sys573, k573bait, fbaitmc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - Marlin Challenge (GX889 VER. EA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4587 | GAME( 1999, fbaitmcu, fbaitmc, k573bait, fbaitmc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - Marlin Challenge (GX889 VER. UA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4588 | GAME( 1999, fbaitmcj, fbaitmc, k573bait, fbaitmc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - Marlin Challenge (GX889 VER. JA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4589 | GAME( 1999, fbaitmca, fbaitmc, k573bait, fbaitmc, ge765pwbba, ROT0, "Konami", "Fisherman's Bait - Marlin Challenge (GX889 VER. AA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4569 | 4590 | GAME( 1999, ddr2m, sys573, konami573, ddr, ddr, ROT0, "Konami", "Dance Dance Revolution 2nd Mix (GN895 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4570 | 4591 | GAME( 1999, ddrbocd, ddr2m, konami573, ddr, ddr, ROT0, "Konami", "Dance Dance Revolution Best of Cool Dancers (GE892 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
| 4571 | 4592 | GAME( 1999, ddr2ml, ddr2m, konami573, ddr, ddr, ROT0, "Konami", "Dance Dance Revolution 2nd Mix - Link Ver (GE885 VER. JAA)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) |
src/emu/devtempl.h
| r0 | r4940 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | devtempl.h |
| 4 | |
| 5 | Template include for defining devices. |
| 6 | |
| 7 | Copyright Nicola Salmoria and the MAME Team. |
| 8 | Visit http://mamedev.org for licensing and usage restrictions. |
| 9 | |
| 10 | **************************************************************************** |
| 11 | |
| 12 | Typical usage is as follows: |
| 13 | |
| 14 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 15 | |
| 16 | // for a primary device.... |
| 17 | #define DEVTEMPLATE_ID(p,s) p##devicenameprefix##s |
| 18 | #define DEVTEMPLATE_FEATURES DT_HAS_xxx | DT_HAS_yyy | ... |
| 19 | #define DEVTEMPLATE_NAME "Device Name String" |
| 20 | #define DEVTEMPLATE_FAMILY "Device Family String" |
| 21 | #define DEVTEMPLATE_CLASS DEVICE_CLASS_xxxx |
| 22 | #include "devtempl.h" |
| 23 | |
| 24 | // for a derived device.... |
| 25 | #define DEVTEMPLATE_DERIVED_ID(p,s) p##derivednameprefix##s |
| 26 | #define DEVTEMPLATE_DERIVED_FEATURES DT_HAS_xxx | DT_HAS_yyy | ... |
| 27 | #define DEVTEMPLATE_NAME "Derived Name String" |
| 28 | #include "devtempl.h" |
| 29 | |
| 30 | **************************************************************************** |
| 31 | |
| 32 | Parameters are as follows: |
| 33 | |
| 34 | DEVTEMPLATE_ID(p,s) - required - macro to produce device function and |
| 35 | type names with a prefix of 'p' and a suffix of 's' |
| 36 | |
| 37 | DEVTEMPLATE_FEATURES - required - bitmask consisting of one of the |
| 38 | DT_HAS_* flags, indicating which standard-named callbacks or |
| 39 | pointers are specified by this device (everything else is assumed |
| 40 | to be NULL, which is the default) |
| 41 | |
| 42 | DEVTEMPLATE_NAME - required - a string describing the device |
| 43 | |
| 44 | DEVTEMPLATE_FAMILY - required - a string describing the device family |
| 45 | name |
| 46 | |
| 47 | DEVTEMPLATE_STATE - optional - the name of the device's state |
| 48 | structure; by default, this is assumed to be |
| 49 | DEVTEMPLATE_ID(,_state) |
| 50 | |
| 51 | DEVTEMPLATE_CLASS - optional - the device's class (default is |
| 52 | DEVICE_CLASS_PERIPHERAL) |
| 53 | |
| 54 | DEVTEMPLATE_VERSION - optional - the device's version string (default |
| 55 | is "1.0") |
| 56 | |
| 57 | DEVTEMPLATE_CREDITS - optional - the device's credit string (default |
| 58 | is "Copyright Nicola Salmoria and the MAME Team") |
| 59 | |
| 60 | DEVTEMPLATE_INLINE_CONFIG - optional - the name of the device's |
| 61 | inline configuration structure; by default, it is assumed the |
| 62 | device does not have any inline configuration |
| 63 | |
| 64 | ***************************************************************************/ |
| 65 | |
| 66 | |
| 67 | /* flag bits for DEVTEMPLATE_FEATURES */ |
| 68 | #define DT_HAS_START 0x0001 |
| 69 | #define DT_HAS_RESET 0x0002 |
| 70 | #define DT_HAS_STOP 0x0004 |
| 71 | #define DT_HAS_EXECUTE 0x0008 |
| 72 | #define DT_HAS_NVRAM 0x0010 |
| 73 | #define DT_HAS_VALIDITY_CHECK 0x0020 |
| 74 | #define DT_HAS_CUSTOM_CONFIG 0x0040 |
| 75 | #define DT_HAS_ROM_REGION 0x0080 |
| 76 | #define DT_HAS_MACHINE_CONFIG 0x0100 |
| 77 | #define DT_HAS_INLINE_CONFIG 0x0200 |
| 78 | |
| 79 | |
| 80 | /* verify core stuff is specified */ |
| 81 | #ifndef DEVTEMPLATE_ID |
| 82 | #error DEVTEMPLATE_ID must be specified! |
| 83 | #endif |
| 84 | |
| 85 | #ifndef DEVTEMPLATE_FEATURES |
| 86 | #error DEVTEMPLATE_FEATURES must be specified! |
| 87 | #endif |
| 88 | |
| 89 | #if ((DEVTEMPLATE_FEATURES & DT_HAS_START) == 0) |
| 90 | #error Device start routine is required! |
| 91 | #endif |
| 92 | |
| 93 | #ifndef DEVTEMPLATE_NAME |
| 94 | #error DEVTEMPLATE_NAME must be specified! |
| 95 | #endif |
| 96 | |
| 97 | #ifndef DEVTEMPLATE_FAMILY |
| 98 | #error DEVTEMPLATE_FAMILY must be specified! |
| 99 | #endif |
| 100 | |
| 101 | #ifdef DEVTEMPLATE_DERIVED_FEATURES |
| 102 | #ifndef DEVTEMPLATE_DERIVED_NAME |
| 103 | #error DEVTEMPLATE_DERIVED_NAME must be specified! |
| 104 | #endif |
| 105 | #endif |
| 106 | |
| 107 | |
| 108 | /* primary device case */ |
| 109 | #ifndef DEVTEMPLATE_DERIVED_FEATURES |
| 110 | |
| 111 | /* derive standard state name (unless explicitly provided) */ |
| 112 | #ifndef DEVTEMPLATE_STATE |
| 113 | #define DEVTEMPLATE_STATE DEVTEMPLATE_ID(,_state) |
| 114 | #endif |
| 115 | |
| 116 | /* default to DEVICE_CLASS_PERIPHERAL */ |
| 117 | #ifndef DEVTEMPLATE_CLASS |
| 118 | #define DEVTEMPLATE_CLASS DEVICE_CLASS_PERIPHERAL |
| 119 | #endif |
| 120 | |
| 121 | /* default to version 1.0 */ |
| 122 | #ifndef DEVTEMPLATE_VERSION |
| 123 | #define DEVTEMPLATE_VERSION "1.0" |
| 124 | #endif |
| 125 | |
| 126 | /* default to the standard copyright attribution */ |
| 127 | #ifndef DEVTEMPLATE_CREDITS |
| 128 | #define DEVTEMPLATE_CREDITS "Copyright Nicola Salmoria and the MAME Team" |
| 129 | #endif |
| 130 | |
| 131 | /* declare callback functions */ |
| 132 | static DEVICE_START( DEVTEMPLATE_ID(,) ); |
| 133 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_RESET) |
| 134 | static DEVICE_RESET( DEVTEMPLATE_ID(,) ); |
| 135 | #endif |
| 136 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_STOP) |
| 137 | static DEVICE_STOP( DEVTEMPLATE_ID(,) ); |
| 138 | #endif |
| 139 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_EXECUTE) |
| 140 | static DEVICE_EXECUTE( DEVTEMPLATE_ID(,) ); |
| 141 | #endif |
| 142 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_NVRAM) |
| 143 | static DEVICE_NVRAM( DEVTEMPLATE_ID(,) ); |
| 144 | #endif |
| 145 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_VALIDITY_CHECK) |
| 146 | static DEVICE_VALIDITY_CHECK( DEVTEMPLATE_ID(,) ); |
| 147 | #endif |
| 148 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_CUSTOM_CONFIG) |
| 149 | static DEVICE_CUSTOM_CONFIG( DEVTEMPLATE_ID(,) ); |
| 150 | #endif |
| 151 | |
| 152 | /* the actual get_info function */ |
| 153 | DEVICE_GET_INFO( DEVTEMPLATE_ID(,) ) |
| 154 | { |
| 155 | switch (state) |
| 156 | { |
| 157 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 158 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(DEVTEMPLATE_STATE); break; |
| 159 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_INLINE_CONFIG) |
| 160 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(DEVTEMPLATE_ID(,_config)); break; |
| 161 | #endif |
| 162 | case DEVINFO_INT_CLASS: info->i = DEVTEMPLATE_CLASS; break; |
| 163 | |
| 164 | /* --- the following bits of info are returned as pointers --- */ |
| 165 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_ROM_REGION) |
| 166 | case DEVINFO_PTR_ROM_REGION: info->romregion = DEVTEMPLATE_ID(rom_,); break; |
| 167 | #endif |
| 168 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_MACHINE_CONFIG) |
| 169 | case DEVINFO_PTR_MACHINE_CONFIG: info->machine_config = DEVTEMPLATE_ID(machine_config_,); break; |
| 170 | #endif |
| 171 | |
| 172 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 173 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_START) |
| 174 | case DEVINFO_FCT_START: info->start = DEVTEMPLATE_ID(device_start_,); break; |
| 175 | #endif |
| 176 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_RESET) |
| 177 | case DEVINFO_FCT_RESET: info->reset = DEVTEMPLATE_ID(device_reset_,); break; |
| 178 | #endif |
| 179 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_STOP) |
| 180 | case DEVINFO_FCT_STOP: info->stop = DEVTEMPLATE_ID(device_stop_,); break; |
| 181 | #endif |
| 182 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_EXECUTE) |
| 183 | case DEVINFO_FCT_EXECUTE: info->execute = DEVTEMPLATE_ID(device_execute_,); break; |
| 184 | #endif |
| 185 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_NVRAM) |
| 186 | case DEVINFO_FCT_NVRAM: info->nvram = DEVTEMPLATE_ID(device_nvram_,); break; |
| 187 | #endif |
| 188 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_VALIDITY_CHECK) |
| 189 | case DEVINFO_FCT_VALIDITY_CHECK: info->validity_check = DEVTEMPLATE_ID(device_validity_check_,); break; |
| 190 | #endif |
| 191 | #if ((DEVTEMPLATE_FEATURES) & DT_HAS_CUSTOM_CONFIG) |
| 192 | case DEVINFO_FCT_CUSTOM_CONFIG: info->custom_config = DEVTEMPLATE_ID(device_custom_config_,); break; |
| 193 | #endif |
| 194 | |
| 195 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 196 | case DEVINFO_STR_NAME: strcpy(info->s, DEVTEMPLATE_NAME); break; |
| 197 | case DEVINFO_STR_FAMILY: strcpy(info->s, DEVTEMPLATE_FAMILY); break; |
| 198 | case DEVINFO_STR_VERSION: strcpy(info->s, DEVTEMPLATE_VERSION); break; |
| 199 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, DEVTEMPLATE_SOURCE); break; |
| 200 | case DEVINFO_STR_CREDITS: strcpy(info->s, DEVTEMPLATE_CREDITS); break; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | |
| 205 | /* derived device case */ |
| 206 | #else |
| 207 | |
| 208 | /* declare callback functions */ |
| 209 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_START) |
| 210 | static DEVICE_START( DEVTEMPLATE_DERIVED_ID(,) ); |
| 211 | #endif |
| 212 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_RESET) |
| 213 | static DEVICE_RESET( DEVTEMPLATE_DERIVED_ID(,) ); |
| 214 | #endif |
| 215 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_STOP) |
| 216 | static DEVICE_STOP( DEVTEMPLATE_DERIVED_ID(,) ); |
| 217 | #endif |
| 218 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_EXECUTE) |
| 219 | static DEVICE_EXECUTE( DEVTEMPLATE_DERIVED_ID(,) ); |
| 220 | #endif |
| 221 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_NVRAM) |
| 222 | static DEVICE_NVRAM( DEVTEMPLATE_DERIVED_ID(,) ); |
| 223 | #endif |
| 224 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_VALIDITY_CHECK) |
| 225 | static DEVICE_VALIDITY_CHECK( DEVTEMPLATE_DERIVED_ID(,) ); |
| 226 | #endif |
| 227 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_CUSTOM_CONFIG) |
| 228 | static DEVICE_CUSTOM_CONFIG( DEVTEMPLATE_DERIVED_ID(,) ); |
| 229 | #endif |
| 230 | |
| 231 | /* the actual get_info function */ |
| 232 | DEVICE_GET_INFO( DEVTEMPLATE_DERIVED_ID(,) ) |
| 233 | { |
| 234 | switch (state) |
| 235 | { |
| 236 | /* --- the following bits of info are returned as pointers --- */ |
| 237 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_ROM_REGION) |
| 238 | case DEVINFO_PTR_ROM_REGION: info->romregion = DEVTEMPLATE_DERIVED_ID(rom_,); break; |
| 239 | #endif |
| 240 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_MACHINE_CONFIG) |
| 241 | case DEVINFO_PTR_MACHINE_CONFIG: info->machine_config = DEVTEMPLATE_DERIVED_ID(machine_config_,); break; |
| 242 | #endif |
| 243 | |
| 244 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 245 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_START) |
| 246 | case DEVINFO_FCT_START: info->start = DEVTEMPLATE_DERIVED_ID(device_start_,); break; |
| 247 | #endif |
| 248 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_RESET) |
| 249 | case DEVINFO_FCT_RESET: info->reset = DEVTEMPLATE_DERIVED_ID(device_reset_,); break; |
| 250 | #endif |
| 251 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_STOP) |
| 252 | case DEVINFO_FCT_STOP: info->stop = DEVTEMPLATE_DERIVED_ID(device_stop_,); break; |
| 253 | #endif |
| 254 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_EXECUTE) |
| 255 | case DEVINFO_FCT_EXECUTE: info->execute = DEVTEMPLATE_DERIVED_ID(device_execute_,); break; |
| 256 | #endif |
| 257 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_NVRAM) |
| 258 | case DEVINFO_FCT_NVRAM: info->nvram = DEVTEMPLATE_DERIVED_ID(device_nvram_,); break; |
| 259 | #endif |
| 260 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_VALIDITY_CHECK) |
| 261 | case DEVINFO_FCT_VALIDITY_CHECK: info->validity_check = DEVTEMPLATE_DERIVED_ID(device_validity_check_,); break; |
| 262 | #endif |
| 263 | #if ((DEVTEMPLATE_DERIVED_FEATURES) & DT_HAS_CUSTOM_CONFIG) |
| 264 | case DEVINFO_FCT_CUSTOM_CONFIG: info->custom_config = DEVTEMPLATE_DERIVED_ID(device_custom_config_,); break; |
| 265 | #endif |
| 266 | |
| 267 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 268 | case DEVINFO_STR_NAME: strcpy(info->s, DEVTEMPLATE_DERIVED_NAME); break; |
| 269 | default: DEVICE_GET_INFO_CALL(DEVTEMPLATE_ID(,)); break; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | #endif |
| 274 | |
| 275 | |
| 276 | |
| 277 | #undef DT_HAS_RESET |
| 278 | #undef DT_HAS_STOP |
| 279 | #undef DT_HAS_EXECUTE |
| 280 | #undef DT_HAS_NVRAM |
| 281 | #undef DT_HAS_VALIDITY_CHECK |
| 282 | #undef DT_HAS_CUSTOM_CONFIG |
| 283 | #undef DT_HAS_ROM_REGION |
| 284 | #undef DT_HAS_MACHINE_CONFIG |
| 285 | |
| 286 | #undef DEVTEMPLATE_DERIVED_ID |
| 287 | #undef DEVTEMPLATE_DERIVED_FEATURES |
| 288 | #undef DEVTEMPLATE_DERIVED_NAME |
src/emu/machine/adc1213x.c
| r4939 | r4940 | |
| 1 | | /* |
| 2 | | ADC12130/ADC12132/ADC12138 |
| 1 | /*************************************************************************** |
| 3 | 2 | |
| 4 | | Self-calibrating 12-bit Plus Sign Serial I/O A/D Converters with MUX and Sample/Hold |
| 3 | National Semiconductor ADC12130 / ADC12132 / ADC12138 |
| 5 | 4 | |
| 5 | Self-calibrating 12-bit Plus Sign Serial I/O A/D Converters with MUX |
| 6 | and Sample/Hold |
| 7 | |
| 6 | 8 | TODO: |
| 7 | 9 | - Only ADC12138 currently supported |
| 8 | | */ |
| 9 | 10 | |
| 11 | 2009-06 Converted to be a device |
| 12 | |
| 13 | ***************************************************************************/ |
| 14 | |
| 10 | 15 | #include "driver.h" |
| 11 | 16 | #include "adc1213x.h" |
| 12 | 17 | |
| 13 | | #define MAX_ADC1213X_CHIPS 4 |
| 14 | 18 | |
| 15 | | typedef struct |
| 19 | /*************************************************************************** |
| 20 | TYPE DEFINITIONS |
| 21 | ***************************************************************************/ |
| 22 | |
| 23 | typedef struct _adc12138_state adc12138_state; |
| 24 | struct _adc12138_state |
| 16 | 25 | { |
| 26 | adc1213x_input_convert_func input_callback_r; |
| 27 | |
| 17 | 28 | int cycle; |
| 18 | 29 | int data_out; |
| 19 | 30 | int data_in; |
| r4939 | r4940 | |
| 26 | 37 | int input_shift_reg; |
| 27 | 38 | int output_shift_reg; |
| 28 | 39 | int end_conv; |
| 40 | }; |
| 29 | 41 | |
| 30 | | double (*input_callback)(running_machine *machine, int input); |
| 31 | | } ADC1213X; |
| 32 | 42 | |
| 33 | | static ADC1213X adc1213x[MAX_ADC1213X_CHIPS]; |
| 34 | | |
| 35 | 43 | #define ADC1213X_CONV_MODE_12_MSB_FIRST 0 |
| 36 | 44 | #define ADC1213X_CONV_MODE_16_MSB_FIRST 1 |
| 37 | 45 | #define ADC1213X_CONV_MODE_12_LSB_FIRST 2 |
| r4939 | r4940 | |
| 42 | 50 | #define ADC1213X_ACQUISITION_TIME_18_CCLK 2 |
| 43 | 51 | #define ADC1213X_ACQUISITION_TIME_34_CCLK 3 |
| 44 | 52 | |
| 45 | | int adc1213x_do_r(int chip) |
| 53 | /*************************************************************************** |
| 54 | INLINE FUNCTIONS |
| 55 | ***************************************************************************/ |
| 56 | |
| 57 | INLINE adc12138_state *get_safe_token(const device_config *device) |
| 46 | 58 | { |
| 47 | | //printf("ADC: DO\n"); |
| 48 | | return adc1213x[chip].data_out; |
| 59 | assert(device != NULL); |
| 60 | assert(device->token != NULL); |
| 61 | assert((device->type == ADC12130) || (device->type == ADC12132) || (device->type == ADC12138)); |
| 62 | return (adc12138_state *)device->token; |
| 49 | 63 | } |
| 50 | 64 | |
| 51 | | void adc1213x_di_w(int chip, int state) |
| 65 | INLINE const adc12138_interface *get_interface(const device_config *device) |
| 52 | 66 | { |
| 53 | | adc1213x[chip].data_in = state & 1; |
| 67 | assert(device != NULL); |
| 68 | assert((device->type == ADC12130) || (device->type == ADC12132) || (device->type == ADC12138)); |
| 69 | return (const adc12138_interface *) device->static_config; |
| 54 | 70 | } |
| 55 | 71 | |
| 56 | | static void adc1213x_convert(running_machine *machine, int chip, int channel, int bits16, int lsbfirst) |
| 72 | |
| 73 | /*************************************************************************** |
| 74 | IMPLEMENTATION |
| 75 | ***************************************************************************/ |
| 76 | |
| 77 | /*------------------------------------------------- |
| 78 | adc1213x_di_w |
| 79 | -------------------------------------------------*/ |
| 80 | |
| 81 | WRITE8_DEVICE_HANDLER( adc1213x_di_w ) |
| 57 | 82 | { |
| 83 | adc12138_state *adc1213x = get_safe_token(device); |
| 84 | adc1213x->data_in = data & 1; |
| 85 | } |
| 86 | |
| 87 | /*------------------------------------------------- |
| 88 | adc1213x_convert |
| 89 | -------------------------------------------------*/ |
| 90 | |
| 91 | static void adc1213x_convert(const device_config *device, int channel, int bits16, int lsbfirst) |
| 92 | { |
| 93 | adc12138_state *adc1213x = get_safe_token(device); |
| 58 | 94 | int i; |
| 59 | 95 | int bits; |
| 60 | 96 | int input_value; |
| 61 | | double input; |
| 97 | double input = 0; |
| 62 | 98 | |
| 63 | 99 | if (bits16) |
| 64 | 100 | fatalerror("ADC1213X: 16-bit mode not supported\n"); |
| r4939 | r4940 | |
| 70 | 106 | { |
| 71 | 107 | case 0x8: // H L L L - CH0 (single-ended) |
| 72 | 108 | { |
| 73 | | input = adc1213x[chip].input_callback(machine, 0); |
| 109 | input = adc1213x->input_callback_r(device, 0); |
| 74 | 110 | break; |
| 75 | 111 | } |
| 76 | 112 | case 0xc: // H H L L - CH1 (single-ended) |
| 77 | 113 | { |
| 78 | | input = adc1213x[chip].input_callback(machine, 1); |
| 114 | input = adc1213x->input_callback_r(device, 1); |
| 79 | 115 | break; |
| 80 | 116 | } |
| 81 | 117 | case 0x9: // H L L H - CH2 (single-ended) |
| 82 | 118 | { |
| 83 | | input = adc1213x[chip].input_callback(machine, 2); |
| 119 | input = adc1213x->input_callback_r(device, 2); |
| 84 | 120 | break; |
| 85 | 121 | } |
| 86 | 122 | case 0xd: // H H L H - CH3 (single-ended) |
| 87 | 123 | { |
| 88 | | input = adc1213x[chip].input_callback(machine, 3); |
| 124 | input = adc1213x->input_callback_r(device, 3); |
| 89 | 125 | break; |
| 90 | 126 | } |
| 91 | 127 | case 0xa: // H L H L - CH4 (single-ended) |
| 92 | 128 | { |
| 93 | | input = adc1213x[chip].input_callback(machine, 4); |
| 129 | input = adc1213x->input_callback_r(device, 4); |
| 94 | 130 | break; |
| 95 | 131 | } |
| 96 | 132 | case 0xe: // H H H L - CH5 (single-ended) |
| 97 | 133 | { |
| 98 | | input = adc1213x[chip].input_callback(machine, 5); |
| 134 | input = adc1213x->input_callback_r(device, 5); |
| 99 | 135 | break; |
| 100 | 136 | } |
| 101 | 137 | case 0xb: // H L H H - CH6 (single-ended) |
| 102 | 138 | { |
| 103 | | input = adc1213x[chip].input_callback(machine, 6); |
| 139 | input = adc1213x->input_callback_r(device, 6); |
| 104 | 140 | break; |
| 105 | 141 | } |
| 106 | 142 | case 0xf: // H H H H - CH7 (single-ended) |
| 107 | 143 | { |
| 108 | | input = adc1213x[chip].input_callback(machine, 7); |
| 144 | input = adc1213x->input_callback_r(device, 7); |
| 109 | 145 | break; |
| 110 | 146 | } |
| 111 | 147 | default: |
| r4939 | r4940 | |
| 119 | 155 | bits = 12; |
| 120 | 156 | |
| 121 | 157 | // sign-extend if needed |
| 122 | | if (adc1213x[chip].data_out_sign) |
| 158 | if (adc1213x->data_out_sign) |
| 123 | 159 | { |
| 124 | 160 | input_value = input_value | ((input_value & 0x800) << 1); |
| 125 | 161 | bits++; |
| 126 | 162 | } |
| 127 | 163 | |
| 128 | | adc1213x[chip].output_shift_reg = 0; |
| 164 | adc1213x->output_shift_reg = 0; |
| 129 | 165 | |
| 130 | 166 | for (i=0; i < bits; i++) |
| 131 | 167 | { |
| 132 | 168 | if (input_value & (1 << ((bits-1) - i))) |
| 133 | 169 | { |
| 134 | | adc1213x[chip].output_shift_reg |= (1 << i); |
| 170 | adc1213x->output_shift_reg |= (1 << i); |
| 135 | 171 | } |
| 136 | 172 | } |
| 137 | 173 | |
| 138 | | adc1213x[chip].data_out = adc1213x[chip].output_shift_reg & 1; |
| 139 | | adc1213x[chip].output_shift_reg >>= 1; |
| 174 | adc1213x->data_out = adc1213x->output_shift_reg & 1; |
| 175 | adc1213x->output_shift_reg >>= 1; |
| 140 | 176 | } |
| 141 | 177 | |
| 142 | | void adc1213x_cs_w(running_machine *machine, int chip, int state) |
| 178 | /*------------------------------------------------- |
| 179 | adc1213x_cs_w |
| 180 | -------------------------------------------------*/ |
| 181 | |
| 182 | WRITE8_DEVICE_HANDLER( adc1213x_cs_w ) |
| 143 | 183 | { |
| 144 | | if (state) |
| 184 | adc12138_state *adc1213x = get_safe_token(device); |
| 185 | |
| 186 | if (data) |
| 145 | 187 | { |
| 146 | 188 | //printf("ADC: CS\n"); |
| 147 | 189 | |
| 148 | | if (adc1213x[chip].cycle >= 7) |
| 190 | if (adc1213x->cycle >= 7) |
| 149 | 191 | { |
| 150 | | int mode = adc1213x[chip].input_shift_reg >> (adc1213x[chip].cycle - 8); |
| 192 | int mode = adc1213x->input_shift_reg >> (adc1213x->cycle - 8); |
| 151 | 193 | |
| 152 | 194 | switch (mode & 0xf) |
| 153 | 195 | { |
| 154 | 196 | case 0x0: // X X X X L L L L - 12 or 13 Bit MSB First conversion |
| 155 | 197 | { |
| 156 | | adc1213x_convert(machine, chip, (mode >> 4) & 0xf, 0, 0); |
| 198 | adc1213x_convert(device, (mode >> 4) & 0xf, 0, 0); |
| 157 | 199 | break; |
| 158 | 200 | } |
| 159 | 201 | case 0x1: // X X X X L L L H - 16 or 17 Bit MSB First conversion |
| 160 | 202 | { |
| 161 | | adc1213x_convert(machine, chip, (mode >> 4) & 0xf, 1, 0); |
| 203 | adc1213x_convert(device, (mode >> 4) & 0xf, 1, 0); |
| 162 | 204 | break; |
| 163 | 205 | } |
| 164 | 206 | case 0x4: // X X X X L H L L - 12 or 13 Bit LSB First conversion |
| 165 | 207 | { |
| 166 | | adc1213x_convert(machine, chip, (mode >> 4) & 0xf, 0, 1); |
| 208 | adc1213x_convert(device, (mode >> 4) & 0xf, 0, 1); |
| 167 | 209 | break; |
| 168 | 210 | } |
| 169 | 211 | case 0x5: // X X X X L H L H - 16 or 17 Bit LSB First conversion |
| 170 | 212 | { |
| 171 | | adc1213x_convert(machine, chip, (mode >> 4) & 0xf, 1, 1); |
| 213 | adc1213x_convert(device, (mode >> 4) & 0xf, 1, 1); |
| 172 | 214 | break; |
| 173 | 215 | } |
| 174 | 216 | |
| r4939 | r4940 | |
| 178 | 220 | { |
| 179 | 221 | case 0x08: // L L L L H L L L - Auto cal |
| 180 | 222 | { |
| 181 | | adc1213x[chip].auto_cal = 1; |
| 223 | adc1213x->auto_cal = 1; |
| 182 | 224 | break; |
| 183 | 225 | } |
| 184 | 226 | |
| 185 | 227 | case 0x0e: // L L L L H H H L - Acquisition time 6 CCLK cycles |
| 186 | 228 | { |
| 187 | | adc1213x[chip].acq_time = ADC1213X_ACQUISITION_TIME_6_CCLK; |
| 229 | adc1213x->acq_time = ADC1213X_ACQUISITION_TIME_6_CCLK; |
| 188 | 230 | break; |
| 189 | 231 | } |
| 190 | 232 | |
| 191 | 233 | case 0x8d: // H L L L H H L H - Data out with sign |
| 192 | 234 | { |
| 193 | | adc1213x[chip].data_out_sign = 1; |
| 235 | adc1213x->data_out_sign = 1; |
| 194 | 236 | break; |
| 195 | 237 | } |
| 196 | 238 | |
| r4939 | r4940 | |
| 204 | 246 | } |
| 205 | 247 | } |
| 206 | 248 | |
| 207 | | adc1213x[chip].cycle = 0; |
| 208 | | adc1213x[chip].input_shift_reg = 0; |
| 249 | adc1213x->cycle = 0; |
| 250 | adc1213x->input_shift_reg = 0; |
| 209 | 251 | |
| 210 | | adc1213x[chip].end_conv = 0; |
| 252 | adc1213x->end_conv = 0; |
| 211 | 253 | } |
| 212 | 254 | } |
| 213 | 255 | |
| 214 | | void adc1213x_sclk_w(int chip, int state) |
| 256 | /*------------------------------------------------- |
| 257 | adc1213x_sclk_w |
| 258 | -------------------------------------------------*/ |
| 259 | |
| 260 | WRITE8_DEVICE_HANDLER( adc1213x_sclk_w ) |
| 215 | 261 | { |
| 216 | | if (state) |
| 262 | adc12138_state *adc1213x = get_safe_token(device); |
| 263 | |
| 264 | if (data) |
| 217 | 265 | { |
| 218 | | //printf("ADC: cycle %d, DI = %d\n", adc1213x[chip].cycle, adc1213x[chip].data_in); |
| 266 | //printf("ADC: cycle %d, DI = %d\n", adc1213x->cycle, adc1213x->data_in); |
| 219 | 267 | |
| 220 | | adc1213x[chip].input_shift_reg <<= 1; |
| 221 | | adc1213x[chip].input_shift_reg |= adc1213x[chip].data_in; |
| 268 | adc1213x->input_shift_reg <<= 1; |
| 269 | adc1213x->input_shift_reg |= adc1213x->data_in; |
| 222 | 270 | |
| 223 | | adc1213x[chip].data_out = adc1213x[chip].output_shift_reg & 1; |
| 224 | | adc1213x[chip].output_shift_reg >>= 1; |
| 271 | adc1213x->data_out = adc1213x->output_shift_reg & 1; |
| 272 | adc1213x->output_shift_reg >>= 1; |
| 225 | 273 | |
| 226 | | adc1213x[chip].cycle++; |
| 274 | adc1213x->cycle++; |
| 227 | 275 | } |
| 228 | 276 | } |
| 229 | 277 | |
| 230 | | void adc1213x_conv_w(int chip, int state) |
| 278 | /*------------------------------------------------- |
| 279 | adc1213x_conv_w |
| 280 | -------------------------------------------------*/ |
| 281 | |
| 282 | WRITE8_DEVICE_HANDLER( adc1213x_conv_w ) |
| 231 | 283 | { |
| 232 | | adc1213x[chip].end_conv = 1; |
| 284 | adc12138_state *adc1213x = get_safe_token(device); |
| 285 | adc1213x->end_conv = 1; |
| 233 | 286 | } |
| 234 | 287 | |
| 235 | | int adc1213x_eoc_r(int chip) |
| 288 | /*------------------------------------------------- |
| 289 | adc1213x_do_r |
| 290 | -------------------------------------------------*/ |
| 291 | |
| 292 | READ8_DEVICE_HANDLER( adc1213x_do_r ) |
| 236 | 293 | { |
| 237 | | return adc1213x[chip].end_conv; |
| 294 | adc12138_state *adc1213x = get_safe_token(device); |
| 295 | |
| 296 | //printf("ADC: DO\n"); |
| 297 | return adc1213x->data_out; |
| 238 | 298 | } |
| 239 | 299 | |
| 240 | | void adc1213x_init(int chip, double (*input_callback)( running_machine *machine, int input )) |
| 300 | /*------------------------------------------------- |
| 301 | adc1213x_eoc_r |
| 302 | -------------------------------------------------*/ |
| 303 | |
| 304 | READ8_DEVICE_HANDLER( adc1213x_eoc_r ) |
| 241 | 305 | { |
| 242 | | memset(&adc1213x[chip], 0, sizeof(ADC1213X)); |
| 306 | adc12138_state *adc1213x = get_safe_token(device); |
| 307 | return adc1213x->end_conv; |
| 308 | } |
| 243 | 309 | |
| 244 | | adc1213x[chip].conv_mode = ADC1213X_CONV_MODE_12_MSB_FIRST; |
| 245 | | adc1213x[chip].data_out_sign = 1; |
| 246 | | adc1213x[chip].auto_cal = 0; |
| 247 | | adc1213x[chip].auto_zero = 0; |
| 248 | | adc1213x[chip].acq_time = ADC1213X_ACQUISITION_TIME_10_CCLK; |
| 310 | /*------------------------------------------------- |
| 311 | DEVICE_START( adc1213x ) |
| 312 | -------------------------------------------------*/ |
| 249 | 313 | |
| 250 | | adc1213x[chip].input_callback = input_callback; |
| 314 | static DEVICE_START( adc12138 ) |
| 315 | { |
| 316 | adc12138_state *adc1213x = get_safe_token(device); |
| 317 | const adc12138_interface *intf = get_interface(device); |
| 318 | |
| 319 | /* resolve callbacks */ |
| 320 | adc1213x->input_callback_r = intf->input_callback_r; |
| 321 | |
| 322 | /* register for state saving */ |
| 323 | state_save_register_device_item(device, 0, adc1213x->cycle); |
| 324 | state_save_register_device_item(device, 0, adc1213x->data_out); |
| 325 | state_save_register_device_item(device, 0, adc1213x->data_in); |
| 326 | state_save_register_device_item(device, 0, adc1213x->conv_mode); |
| 327 | state_save_register_device_item(device, 0, adc1213x->auto_cal); |
| 328 | state_save_register_device_item(device, 0, adc1213x->auto_zero); |
| 329 | state_save_register_device_item(device, 0, adc1213x->acq_time); |
| 330 | state_save_register_device_item(device, 0, adc1213x->data_out_sign); |
| 331 | state_save_register_device_item(device, 0, adc1213x->mode); |
| 332 | state_save_register_device_item(device, 0, adc1213x->input_shift_reg); |
| 333 | state_save_register_device_item(device, 0, adc1213x->output_shift_reg); |
| 334 | state_save_register_device_item(device, 0, adc1213x->end_conv); |
| 251 | 335 | } |
| 336 | |
| 337 | |
| 338 | /*------------------------------------------------- |
| 339 | DEVICE_RESET( adc1213x ) |
| 340 | -------------------------------------------------*/ |
| 341 | |
| 342 | static DEVICE_RESET( adc12138 ) |
| 343 | { |
| 344 | adc12138_state *adc1213x = get_safe_token(device); |
| 345 | |
| 346 | adc1213x->conv_mode = ADC1213X_CONV_MODE_12_MSB_FIRST; |
| 347 | adc1213x->data_out_sign = 1; |
| 348 | adc1213x->auto_cal = 0; |
| 349 | adc1213x->auto_zero = 0; |
| 350 | adc1213x->acq_time = ADC1213X_ACQUISITION_TIME_10_CCLK; |
| 351 | } |
| 352 | |
| 353 | /*------------------------------------------------- |
| 354 | device definition |
| 355 | -------------------------------------------------*/ |
| 356 | |
| 357 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 358 | |
| 359 | #define DEVTEMPLATE_ID(p,s) p##adc12138##s |
| 360 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 361 | #define DEVTEMPLATE_NAME "A/D Converter 12138" |
| 362 | #define DEVTEMPLATE_FAMILY "National Semiconductor A/D Converters 1213x" |
| 363 | #define DEVTEMPLATE_CLASS DEVICE_CLASS_PERIPHERAL |
| 364 | #include "devtempl.h" |
| 365 | |
| 366 | #define DEVTEMPLATE_DERIVED_ID(p,s) p##adc12130##s |
| 367 | #define DEVTEMPLATE_DERIVED_FEATURES 0 |
| 368 | #define DEVTEMPLATE_DERIVED_NAME "A/D Converter 12130" |
| 369 | #include "devtempl.h" |
| 370 | |
| 371 | #define DEVTEMPLATE_DERIVED_ID(p,s) p##adc12132##s |
| 372 | #define DEVTEMPLATE_DERIVED_FEATURES 0 |
| 373 | #define DEVTEMPLATE_DERIVED_NAME "A/D Converter 12132" |
| 374 | #include "devtempl.h" |
src/emu/machine/6821pia.c
| r4939 | r4940 | |
| 11 | 11 | TYPE DEFINITIONS |
| 12 | 12 | ***************************************************************************/ |
| 13 | 13 | |
| 14 | | typedef struct _pia6821 pia6821; |
| 15 | | struct _pia6821 |
| 14 | typedef struct _pia6821_state pia6821_state; |
| 15 | struct _pia6821_state |
| 16 | 16 | { |
| 17 | 17 | devcb_resolved_read8 in_a_func; |
| 18 | 18 | devcb_resolved_read8 in_b_func; |
| r4939 | r4940 | |
| 106 | 106 | INLINE FUNCTIONS |
| 107 | 107 | ***************************************************************************/ |
| 108 | 108 | |
| 109 | | INLINE pia6821 *get_token(const device_config *device) |
| 109 | INLINE pia6821_state *get_token(const device_config *device) |
| 110 | 110 | { |
| 111 | 111 | assert(device != NULL); |
| 112 | 112 | assert((device->type == PIA6821) || (device->type == PIA6822)); |
| 113 | | return (pia6821 *) device->token; |
| 113 | return (pia6821_state *) device->token; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
| r4939 | r4940 | |
| 127 | 127 | ***************************************************************************/ |
| 128 | 128 | |
| 129 | 129 | /*------------------------------------------------- |
| 130 | | DEVICE_START( pia ) |
| 130 | DEVICE_START( pia6821 ) |
| 131 | 131 | -------------------------------------------------*/ |
| 132 | 132 | |
| 133 | | static DEVICE_START( pia ) |
| 133 | static DEVICE_START( pia6821 ) |
| 134 | 134 | { |
| 135 | | pia6821 *p = get_token(device); |
| 135 | pia6821_state *p = get_token(device); |
| 136 | 136 | const pia6821_interface *intf = get_interface(device); |
| 137 | 137 | |
| 138 | 138 | /* clear structure */ |
| r4939 | r4940 | |
| 188 | 188 | |
| 189 | 189 | |
| 190 | 190 | /*------------------------------------------------- |
| 191 | | DEVICE_RESET( pia ) |
| 191 | DEVICE_RESET( pia6821 ) |
| 192 | 192 | -------------------------------------------------*/ |
| 193 | 193 | |
| 194 | | static DEVICE_RESET( pia ) |
| 194 | static DEVICE_RESET( pia6821 ) |
| 195 | 195 | { |
| 196 | | pia6821 *p = get_token(device); |
| 196 | pia6821_state *p = get_token(device); |
| 197 | 197 | |
| 198 | 198 | /* |
| 199 | 199 | * set default read values. |
| r4939 | r4940 | |
| 253 | 253 | |
| 254 | 254 | static void update_interrupts(const device_config *device) |
| 255 | 255 | { |
| 256 | | pia6821 *p = get_token(device); |
| 256 | pia6821_state *p = get_token(device); |
| 257 | 257 | int new_state; |
| 258 | 258 | |
| 259 | 259 | /* start with IRQ A */ |
| r4939 | r4940 | |
| 282 | 282 | |
| 283 | 283 | static UINT8 get_in_a_value(const device_config *device) |
| 284 | 284 | { |
| 285 | | pia6821 *p = get_token(device); |
| 285 | pia6821_state *p = get_token(device); |
| 286 | 286 | UINT8 port_a_data = 0; |
| 287 | 287 | UINT8 ret; |
| 288 | 288 | |
| r4939 | r4940 | |
| 323 | 323 | |
| 324 | 324 | static UINT8 get_in_b_value(const device_config *device) |
| 325 | 325 | { |
| 326 | | pia6821 *p = get_token(device); |
| 326 | pia6821_state *p = get_token(device); |
| 327 | 327 | UINT8 ret; |
| 328 | 328 | |
| 329 | 329 | if (p->ddr_b == 0xff) |
| r4939 | r4940 | |
| 367 | 367 | |
| 368 | 368 | static UINT8 get_out_a_value(const device_config *device) |
| 369 | 369 | { |
| 370 | | pia6821 *p = get_token(device); |
| 370 | pia6821_state *p = get_token(device); |
| 371 | 371 | UINT8 ret; |
| 372 | 372 | |
| 373 | 373 | if (p->ddr_a == 0xff) |
| r4939 | r4940 | |
| 387 | 387 | |
| 388 | 388 | static UINT8 get_out_b_value(const device_config *device) |
| 389 | 389 | { |
| 390 | | pia6821 *p = get_token(device); |
| 390 | pia6821_state *p = get_token(device); |
| 391 | 391 | |
| 392 | 392 | /* input pins are high-impedance - we just send them as zeros for backwards compatibility */ |
| 393 | 393 | return p->out_b & p->ddr_b; |
| r4939 | r4940 | |
| 400 | 400 | |
| 401 | 401 | static void set_out_ca2(const device_config *device, int data) |
| 402 | 402 | { |
| 403 | | pia6821 *p = get_token(device); |
| 403 | pia6821_state *p = get_token(device); |
| 404 | 404 | |
| 405 | 405 | if (data != p->out_ca2) |
| 406 | 406 | { |
| r4939 | r4940 | |
| 426 | 426 | |
| 427 | 427 | static void set_out_cb2(const device_config *device, int data) |
| 428 | 428 | { |
| 429 | | pia6821 *p = get_token(device); |
| 429 | pia6821_state *p = get_token(device); |
| 430 | 430 | |
| 431 | 431 | int z = pia6821_get_output_cb2_z(device); |
| 432 | 432 | |
| r4939 | r4940 | |
| 455 | 455 | |
| 456 | 456 | static UINT8 port_a_r(const device_config *device) |
| 457 | 457 | { |
| 458 | | pia6821 *p = get_token(device); |
| 458 | pia6821_state *p = get_token(device); |
| 459 | 459 | |
| 460 | 460 | UINT8 ret = get_in_a_value(device); |
| 461 | 461 | |
| r4939 | r4940 | |
| 487 | 487 | |
| 488 | 488 | static UINT8 ddr_a_r(const device_config *device) |
| 489 | 489 | { |
| 490 | | pia6821 *p = get_token(device); |
| 490 | pia6821_state *p = get_token(device); |
| 491 | 491 | |
| 492 | 492 | UINT8 ret = p->ddr_a; |
| 493 | 493 | |
| r4939 | r4940 | |
| 503 | 503 | |
| 504 | 504 | static UINT8 port_b_r(const device_config *device) |
| 505 | 505 | { |
| 506 | | pia6821 *p = get_token(device); |
| 506 | pia6821_state *p = get_token(device); |
| 507 | 507 | |
| 508 | 508 | UINT8 ret = get_in_b_value(device); |
| 509 | 509 | |
| r4939 | r4940 | |
| 531 | 531 | |
| 532 | 532 | static UINT8 ddr_b_r(const device_config *device) |
| 533 | 533 | { |
| 534 | | pia6821 *p = get_token(device); |
| 534 | pia6821_state *p = get_token(device); |
| 535 | 535 | |
| 536 | 536 | UINT8 ret = p->ddr_b; |
| 537 | 537 | |
| r4939 | r4940 | |
| 547 | 547 | |
| 548 | 548 | static UINT8 control_a_r(const device_config *device) |
| 549 | 549 | { |
| 550 | | pia6821 *p = get_token(device); |
| 550 | pia6821_state *p = get_token(device); |
| 551 | 551 | UINT8 ret; |
| 552 | 552 | |
| 553 | 553 | /* update CA1 & CA2 if callback exists, these in turn may update IRQ's */ |
| r4939 | r4940 | |
| 589 | 589 | |
| 590 | 590 | static UINT8 control_b_r(const device_config *device) |
| 591 | 591 | { |
| 592 | | pia6821 *p = get_token(device); |
| 592 | pia6821_state *p = get_token(device); |
| 593 | 593 | UINT8 ret; |
| 594 | 594 | |
| 595 | 595 | /* update CB1 & CB2 if callback exists, these in turn may update IRQ's */ |
| r4939 | r4940 | |
| 631 | 631 | |
| 632 | 632 | READ8_DEVICE_HANDLER( pia6821_r ) |
| 633 | 633 | { |
| 634 | | pia6821 *p = get_token(device); |
| 634 | pia6821_state *p = get_token(device); |
| 635 | 635 | UINT8 ret; |
| 636 | 636 | |
| 637 | 637 | switch (offset & 0x03) |
| r4939 | r4940 | |
| 680 | 680 | |
| 681 | 681 | UINT8 pia6821_get_port_b_z_mask(const device_config *device) |
| 682 | 682 | { |
| 683 | | pia6821 *p = get_token(device); |
| 683 | pia6821_state *p = get_token(device); |
| 684 | 684 | return ~p->ddr_b; |
| 685 | 685 | } |
| 686 | 686 | |
| r4939 | r4940 | |
| 691 | 691 | |
| 692 | 692 | static void send_to_out_a_func(const device_config *device, const char* message) |
| 693 | 693 | { |
| 694 | | pia6821 *p = get_token(device); |
| 694 | pia6821_state *p = get_token(device); |
| 695 | 695 | |
| 696 | 696 | /* input pins are pulled high */ |
| 697 | 697 | UINT8 data = get_out_a_value(device); |
| r4939 | r4940 | |
| 716 | 716 | |
| 717 | 717 | static void send_to_out_b_func(const device_config *device, const char* message) |
| 718 | 718 | { |
| 719 | | pia6821 *p = get_token(device); |
| 719 | pia6821_state *p = get_token(device); |
| 720 | 720 | |
| 721 | 721 | /* input pins are high-impedance - we just send them as zeros for backwards compatibility */ |
| 722 | 722 | UINT8 data = get_out_b_value(device); |
| r4939 | r4940 | |
| 741 | 741 | |
| 742 | 742 | static void port_a_w(const device_config *device, UINT8 data) |
| 743 | 743 | { |
| 744 | | pia6821 *p = get_token(device); |
| 744 | pia6821_state *p = get_token(device); |
| 745 | 745 | |
| 746 | 746 | /* buffer the output value */ |
| 747 | 747 | p->out_a = data; |
| r4939 | r4940 | |
| 756 | 756 | |
| 757 | 757 | static void ddr_a_w(const device_config *device, UINT8 data) |
| 758 | 758 | { |
| 759 | | pia6821 *p = get_token(device); |
| 759 | pia6821_state *p = get_token(device); |
| 760 | 760 | |
| 761 | 761 | if (data == 0x00) |
| 762 | 762 | LOG(("PIA #%s: DDR A write = %02X (input mode)\n", device->tag, data)); |
| r4939 | r4940 | |
| 781 | 781 | |
| 782 | 782 | static void port_b_w(const device_config *device, UINT8 data) |
| 783 | 783 | { |
| 784 | | pia6821 *p = get_token(device); |
| 784 | pia6821_state *p = get_token(device); |
| 785 | 785 | |
| 786 | 786 | /* buffer the output value */ |
| 787 | 787 | p->out_b = data; |
| r4939 | r4940 | |
| 807 | 807 | |
| 808 | 808 | static void ddr_b_w(const device_config *device, UINT8 data) |
| 809 | 809 | { |
| 810 | | pia6821 *p = get_token(device); |
| 810 | pia6821_state *p = get_token(device); |
| 811 | 811 | |
| 812 | 812 | if (data == 0x00) |
| 813 | 813 | LOG(("PIA #%s: DDR B write = %02X (input mode)\n", device->tag, data)); |
| r4939 | r4940 | |
| 832 | 832 | |
| 833 | 833 | static void control_a_w(const device_config *device, UINT8 data) |
| 834 | 834 | { |
| 835 | | pia6821 *p = get_token(device); |
| 835 | pia6821_state *p = get_token(device); |
| 836 | 836 | |
| 837 | 837 | /* bit 7 and 6 are read only */ |
| 838 | 838 | data &= 0x3f; |
| r4939 | r4940 | |
| 868 | 868 | |
| 869 | 869 | static void control_b_w(const device_config *device, UINT8 data) |
| 870 | 870 | { |
| 871 | | pia6821 *p = get_token(device); |
| 871 | pia6821_state *p = get_token(device); |
| 872 | 872 | int temp; |
| 873 | 873 | |
| 874 | 874 | /* bit 7 and 6 are read only */ |
| r4939 | r4940 | |
| 899 | 899 | |
| 900 | 900 | WRITE8_DEVICE_HANDLER( pia6821_w ) |
| 901 | 901 | { |
| 902 | | pia6821 *p = get_token(device); |
| 902 | pia6821_state *p = get_token(device); |
| 903 | 903 | |
| 904 | 904 | switch (offset & 0x03) |
| 905 | 905 | { |
| r4939 | r4940 | |
| 945 | 945 | |
| 946 | 946 | void pia6821_set_port_a_z_mask(const device_config *device, UINT8 data) |
| 947 | 947 | { |
| 948 | | pia6821 *p = get_token(device); |
| 948 | pia6821_state *p = get_token(device); |
| 949 | 949 | |
| 950 | 950 | p->port_a_z_mask = data; |
| 951 | 951 | } |
| r4939 | r4940 | |
| 957 | 957 | |
| 958 | 958 | READ8_DEVICE_HANDLER( pia6821_porta_r ) |
| 959 | 959 | { |
| 960 | | pia6821 *p = get_token(device); |
| 960 | pia6821_state *p = get_token(device); |
| 961 | 961 | |
| 962 | 962 | return p->in_a; |
| 963 | 963 | } |
| r4939 | r4940 | |
| 969 | 969 | |
| 970 | 970 | void pia6821_set_input_a(const device_config *device, UINT8 data, UINT8 z_mask) |
| 971 | 971 | { |
| 972 | | pia6821 *p = get_token(device); |
| 972 | pia6821_state *p = get_token(device); |
| 973 | 973 | |
| 974 | 974 | assert_always(p->in_a_func.read == NULL, "pia6821_porta_w() called when in_a_func implemented"); |
| 975 | 975 | |
| r4939 | r4940 | |
| 997 | 997 | |
| 998 | 998 | UINT8 pia6821_get_output_a(const device_config *device) |
| 999 | 999 | { |
| 1000 | | pia6821 *p = get_token(device); |
| 1000 | pia6821_state *p = get_token(device); |
| 1001 | 1001 | |
| 1002 | 1002 | p->out_a_needs_pulled = FALSE; |
| 1003 | 1003 | |
| r4939 | r4940 | |
| 1011 | 1011 | |
| 1012 | 1012 | READ8_DEVICE_HANDLER( pia6821_ca1_r ) |
| 1013 | 1013 | { |
| 1014 | | pia6821 *p = get_token(device); |
| 1014 | pia6821_state *p = get_token(device); |
| 1015 | 1015 | |
| 1016 | 1016 | return p->in_ca1; |
| 1017 | 1017 | } |
| r4939 | r4940 | |
| 1023 | 1023 | |
| 1024 | 1024 | WRITE8_DEVICE_HANDLER( pia6821_ca1_w ) |
| 1025 | 1025 | { |
| 1026 | | pia6821 *p = get_token(device); |
| 1026 | pia6821_state *p = get_token(device); |
| 1027 | 1027 | |
| 1028 | 1028 | /* limit the data to 0 or 1 */ |
| 1029 | 1029 | data = data ? TRUE : FALSE; |
| r4939 | r4940 | |
| 1059 | 1059 | |
| 1060 | 1060 | READ8_DEVICE_HANDLER( pia6821_ca2_r ) |
| 1061 | 1061 | { |
| 1062 | | pia6821 *p = get_token(device); |
| 1062 | pia6821_state *p = get_token(device); |
| 1063 | 1063 | |
| 1064 | 1064 | return p->in_ca2; |
| 1065 | 1065 | } |
| r4939 | r4940 | |
| 1071 | 1071 | |
| 1072 | 1072 | WRITE8_DEVICE_HANDLER( pia6821_ca2_w ) |
| 1073 | 1073 | { |
| 1074 | | pia6821 *p = get_token(device); |
| 1074 | pia6821_state *p = get_token(device); |
| 1075 | 1075 | |
| 1076 | 1076 | /* limit the data to 0 or 1 */ |
| 1077 | 1077 | data = data ? 1 : 0; |
| r4939 | r4940 | |
| 1104 | 1104 | |
| 1105 | 1105 | int pia6821_get_output_ca2(const device_config *device) |
| 1106 | 1106 | { |
| 1107 | | pia6821 *p = get_token(device); |
| 1107 | pia6821_state *p = get_token(device); |
| 1108 | 1108 | |
| 1109 | 1109 | p->out_ca2_needs_pulled = FALSE; |
| 1110 | 1110 | |
| r4939 | r4940 | |
| 1120 | 1120 | |
| 1121 | 1121 | int pia6821_get_output_ca2_z(const device_config *device) |
| 1122 | 1122 | { |
| 1123 | | pia6821 *p = get_token(device); |
| 1123 | pia6821_state *p = get_token(device); |
| 1124 | 1124 | |
| 1125 | 1125 | p->out_ca2_needs_pulled = FALSE; |
| 1126 | 1126 | |
| r4939 | r4940 | |
| 1137 | 1137 | |
| 1138 | 1138 | READ8_DEVICE_HANDLER( pia6821_portb_r ) |
| 1139 | 1139 | { |
| 1140 | | pia6821 *p = get_token(device); |
| 1140 | pia6821_state *p = get_token(device); |
| 1141 | 1141 | |
| 1142 | 1142 | return p->in_b; |
| 1143 | 1143 | } |
| r4939 | r4940 | |
| 1149 | 1149 | |
| 1150 | 1150 | WRITE8_DEVICE_HANDLER( pia6821_portb_w ) |
| 1151 | 1151 | { |
| 1152 | | pia6821 *p = get_token(device); |
| 1152 | pia6821_state *p = get_token(device); |
| 1153 | 1153 | |
| 1154 | 1154 | assert_always(p->in_b_func.read == NULL, "pia_set_input_b() called when in_b_func implemented"); |
| 1155 | 1155 | |
| r4939 | r4940 | |
| 1166 | 1166 | |
| 1167 | 1167 | UINT8 pia6821_get_output_b(const device_config *device) |
| 1168 | 1168 | { |
| 1169 | | pia6821 *p = get_token(device); |
| 1169 | pia6821_state *p = get_token(device); |
| 1170 | 1170 | |
| 1171 | 1171 | p->out_b_needs_pulled = FALSE; |
| 1172 | 1172 | |
| r4939 | r4940 | |
| 1180 | 1180 | |
| 1181 | 1181 | READ8_DEVICE_HANDLER( pia6821_cb1_r ) |
| 1182 | 1182 | { |
| 1183 | | pia6821 *p = get_token(device); |
| 1183 | pia6821_state *p = get_token(device); |
| 1184 | 1184 | |
| 1185 | 1185 | return p->in_cb1; |
| 1186 | 1186 | } |
| r4939 | r4940 | |
| 1192 | 1192 | |
| 1193 | 1193 | WRITE8_DEVICE_HANDLER( pia6821_cb1_w ) |
| 1194 | 1194 | { |
| 1195 | | pia6821 *p = get_token(device); |
| 1195 | pia6821_state *p = get_token(device); |
| 1196 | 1196 | |
| 1197 | 1197 | /* limit the data to 0 or 1 */ |
| 1198 | 1198 | data = data ? 1 : 0; |
| r4939 | r4940 | |
| 1229 | 1229 | |
| 1230 | 1230 | READ8_DEVICE_HANDLER( pia6821_cb2_r ) |
| 1231 | 1231 | { |
| 1232 | | pia6821 *p = get_token(device); |
| 1232 | pia6821_state *p = get_token(device); |
| 1233 | 1233 | |
| 1234 | 1234 | return p->in_cb2; |
| 1235 | 1235 | } |
| r4939 | r4940 | |
| 1241 | 1241 | |
| 1242 | 1242 | WRITE8_DEVICE_HANDLER( pia6821_cb2_w ) |
| 1243 | 1243 | { |
| 1244 | | pia6821 *p = get_token(device); |
| 1244 | pia6821_state *p = get_token(device); |
| 1245 | 1245 | |
| 1246 | 1246 | /* limit the data to 0 or 1 */ |
| 1247 | 1247 | data = data ? 1 : 0; |
| r4939 | r4940 | |
| 1274 | 1274 | |
| 1275 | 1275 | int pia6821_get_output_cb2(const device_config *device) |
| 1276 | 1276 | { |
| 1277 | | pia6821 *p = get_token(device); |
| 1277 | pia6821_state *p = get_token(device); |
| 1278 | 1278 | |
| 1279 | 1279 | p->out_cb2_needs_pulled = FALSE; |
| 1280 | 1280 | |
| r4939 | r4940 | |
| 1288 | 1288 | |
| 1289 | 1289 | int pia6821_get_output_cb2_z(const device_config *device) |
| 1290 | 1290 | { |
| 1291 | | pia6821 *p = get_token(device); |
| 1291 | pia6821_state *p = get_token(device); |
| 1292 | 1292 | |
| 1293 | 1293 | return !C2_OUTPUT(p->ctl_b); |
| 1294 | 1294 | } |
| r4939 | r4940 | |
| 1300 | 1300 | |
| 1301 | 1301 | int pia6821_get_irq_a(const device_config *device) |
| 1302 | 1302 | { |
| 1303 | | pia6821 *p = get_token(device); |
| 1303 | pia6821_state *p = get_token(device); |
| 1304 | 1304 | |
| 1305 | 1305 | return p->irq_a_state; |
| 1306 | 1306 | } |
| r4939 | r4940 | |
| 1312 | 1312 | |
| 1313 | 1313 | int pia6821_get_irq_b(const device_config *device) |
| 1314 | 1314 | { |
| 1315 | | pia6821 *p = get_token(device); |
| 1315 | pia6821_state *p = get_token(device); |
| 1316 | 1316 | |
| 1317 | 1317 | return p->irq_b_state; |
| 1318 | 1318 | } |
| 1319 | 1319 | |
| 1320 | 1320 | |
| 1321 | 1321 | /*------------------------------------------------- |
| 1322 | | DEVICE_GET_INFO( pia6821 ) |
| 1322 | device definition |
| 1323 | 1323 | -------------------------------------------------*/ |
| 1324 | 1324 | |
| 1325 | | DEVICE_GET_INFO(pia6821) |
| 1326 | | { |
| 1327 | | switch (state) |
| 1328 | | { |
| 1329 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1330 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(pia6821); break; |
| 1331 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 1332 | | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 1325 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 1333 | 1326 | |
| 1334 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1335 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(pia); break; |
| 1336 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1337 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(pia); break; |
| 1327 | #define DEVTEMPLATE_ID(p,s) p##pia6821##s |
| 1328 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 1329 | #define DEVTEMPLATE_NAME "6821 PIA" |
| 1330 | #define DEVTEMPLATE_FAMILY "6821 PIA" |
| 1331 | #include "devtempl.h" |
| 1338 | 1332 | |
| 1339 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1340 | | case DEVINFO_STR_NAME: strcpy(info->s, "6821 PIA"); break; |
| 1341 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "6821 PIA"); break; |
| 1342 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 1343 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1344 | | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 1345 | | } |
| 1346 | | } |
| 1347 | | |
| 1348 | | |
| 1349 | | /*------------------------------------------------- |
| 1350 | | DEVICE_GET_INFO( pia6822 ) |
| 1351 | | -------------------------------------------------*/ |
| 1352 | | |
| 1353 | | DEVICE_GET_INFO(pia6822) |
| 1354 | | { |
| 1355 | | switch (state) |
| 1356 | | { |
| 1357 | | case DEVINFO_STR_NAME: strcpy(info->s, "6822 PIA"); break; |
| 1358 | | default: DEVICE_GET_INFO_CALL(pia6821); break; |
| 1359 | | } |
| 1360 | | } |
| 1333 | #define DEVTEMPLATE_DERIVED_ID(p,s) p##pia6822##s |
| 1334 | #define DEVTEMPLATE_DERIVED_FEATURES 0 |
| 1335 | #define DEVTEMPLATE_DERIVED_NAME "6822 PIA" |
| 1336 | #include "devtempl.h" |
src/emu/machine/6840ptm.c
| r4939 | r4940 | |
| 1 | | /********************************************************************** |
| 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | Motorola 6840 (PTM) |
| 3 | 4 | |
| 4 | | Motorola 6840 PTM interface and emulation |
| 5 | Programmable Timer Module |
| 5 | 6 | |
| 6 | | This function is a simple emulation of up to 4 MC6840 |
| 7 | | Programmable Timer Modules |
| 8 | | |
| 9 | 7 | Written By J.Wallace based on previous work by Aaron Giles, |
| 10 | 8 | 'Re-Animator' and Mathis Rosenhauer. |
| 11 | 9 | |
| r4939 | r4940 | |
| 30 | 28 | should be used instead if necessary (This should allow the VBLANK |
| 31 | 29 | clock on the MCR units to operate). |
| 32 | 30 | |
| 33 | | **********************************************************************/ |
| 34 | 31 | |
| 32 | 2009-06 Converted to be a device |
| 33 | |
| 34 | ***************************************************************************/ |
| 35 | |
| 35 | 36 | #include "driver.h" |
| 36 | 37 | #include "6840ptm.h" |
| 37 | 38 | |
| 38 | | // Defines ///////////////////////////////////////////////////////////// |
| 39 | 39 | |
| 40 | 40 | #define PTMVERBOSE 0 |
| 41 | 41 | #define PLOG(x) do { if (PTMVERBOSE) logerror x; } while (0) |
| 42 | 42 | |
| 43 | /*************************************************************************** |
| 44 | PARAMETERS / PROTOTYPES |
| 45 | ***************************************************************************/ |
| 46 | |
| 43 | 47 | enum |
| 44 | 48 | { |
| 45 | 49 | PTM_6840_CTRL1 = 0, |
| r4939 | r4940 | |
| 53 | 57 | PTM_6840_LSB3 = 7, |
| 54 | 58 | }; |
| 55 | 59 | |
| 60 | static const char *const opmode[] = |
| 61 | { |
| 62 | "000 continous mode", |
| 63 | "001 freq comparison mode", |
| 64 | "010 continous mode", |
| 65 | "011 pulse width comparison mode", |
| 66 | "100 single shot mode", |
| 67 | "101 freq comparison mode", |
| 68 | "110 single shot mode", |
| 69 | "111 pulse width comparison mode" |
| 70 | }; |
| 56 | 71 | |
| 57 | | typedef struct _ptm6840 |
| 72 | static void ptm6840_timeout(const device_config *device, int idx); |
| 73 | |
| 74 | /*************************************************************************** |
| 75 | TYPE DEFINITIONS |
| 76 | ***************************************************************************/ |
| 77 | |
| 78 | typedef struct _ptm6840_state ptm6840_state; |
| 79 | struct _ptm6840_state |
| 58 | 80 | { |
| 59 | | const ptm6840_interface *intf; |
| 81 | int internal_clock; |
| 82 | int external_clock[3]; |
| 83 | devcb_resolved_write8 out_func[3]; // function to call when output[idx] changes |
| 84 | devcb_resolved_write_line irq_func; // function called if IRQ line changes |
| 60 | 85 | |
| 61 | 86 | UINT8 control_reg[3]; |
| 62 | 87 | UINT8 output[3]; /* Output states */ |
| r4939 | r4940 | |
| 73 | 98 | UINT8 lsb_buffer; |
| 74 | 99 | UINT8 msb_buffer; |
| 75 | 100 | |
| 76 | | int internal_clock; |
| 77 | | int external_clock[3]; |
| 78 | | |
| 79 | 101 | /* Each PTM has 3 timers */ |
| 80 | 102 | emu_timer *timer[3]; |
| 81 | 103 | |
| 82 | 104 | UINT16 latch[3]; |
| 83 | 105 | UINT16 counter[3]; |
| 84 | | } ptm6840; |
| 106 | }; |
| 85 | 107 | |
| 86 | | // Local prototypes /////////////////////////////////////////////////////// |
| 87 | 108 | |
| 88 | | static void ptm6840_timeout(running_machine *machine, int which, int idx); |
| 89 | | static TIMER_CALLBACK( ptm6840_timer_cb ); |
| 109 | /*************************************************************************** |
| 110 | INLINE FUNCTIONS |
| 111 | ***************************************************************************/ |
| 90 | 112 | |
| 91 | | // Local vars ///////////////////////////////////////////////////////////// |
| 113 | INLINE ptm6840_state *get_safe_token(const device_config *device) |
| 114 | { |
| 115 | assert(device != NULL); |
| 116 | assert(device->token != NULL); |
| 117 | assert((device->type == PTM6840)); |
| 118 | return (ptm6840_state *)device->token; |
| 119 | } |
| 92 | 120 | |
| 93 | | static ptm6840 ptm[PTM_6840_MAX]; |
| 94 | | |
| 95 | | static const char *const opmode[] = |
| 121 | INLINE const ptm6840_interface *get_interface(const device_config *device) |
| 96 | 122 | { |
| 97 | | "000 continous mode", |
| 98 | | "001 freq comparison mode", |
| 99 | | "010 continous mode", |
| 100 | | "011 pulse width comparison mode", |
| 101 | | "100 single shot mode", |
| 102 | | "101 freq comparison mode", |
| 103 | | "110 single shot mode", |
| 104 | | "111 pulse width comparison mode" |
| 105 | | }; |
| 123 | assert(device != NULL); |
| 124 | assert((device->type == PTM6840)); |
| 125 | return (const ptm6840_interface *) device->static_config; |
| 126 | } |
| 106 | 127 | |
| 107 | | /////////////////////////////////////////////////////////////////////////// |
| 108 | | // // |
| 109 | | // Get enabled status // |
| 110 | | // // |
| 111 | | /////////////////////////////////////////////////////////////////////////// |
| 112 | 128 | |
| 113 | | int ptm6840_get_status(int which, int clock) |
| 129 | /*************************************************************************** |
| 130 | IMPLEMENTATION |
| 131 | ***************************************************************************/ |
| 132 | |
| 133 | /*------------------------------------------------- |
| 134 | ptm6840_get_status - Get enabled status |
| 135 | -------------------------------------------------*/ |
| 136 | |
| 137 | int ptm6840_get_status( const device_config *device, int clock ) |
| 114 | 138 | { |
| 115 | | ptm6840 *p = ptm + which; |
| 116 | | return p->enabled[clock - 1]; |
| 139 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 140 | return ptm6840->enabled[clock - 1]; |
| 117 | 141 | } |
| 118 | 142 | |
| 119 | | /////////////////////////////////////////////////////////////////////////// |
| 120 | | // // |
| 121 | | // ptm6840_get_irq: get IRQ state // |
| 122 | | // // |
| 123 | | /////////////////////////////////////////////////////////////////////////// |
| 143 | /*------------------------------------------------- |
| 144 | ptm6840_get_irq - Get IRQ state |
| 145 | -------------------------------------------------*/ |
| 124 | 146 | |
| 125 | | int ptm6840_get_irq(int which) |
| 147 | int ptm6840_get_irq( const device_config *device ) |
| 126 | 148 | { |
| 127 | | ptm6840 *p = ptm + which; |
| 128 | | return p->IRQ; |
| 149 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 150 | return ptm6840->IRQ; |
| 129 | 151 | } |
| 130 | 152 | |
| 131 | | /////////////////////////////////////////////////////////////////////////// |
| 132 | | // // |
| 133 | | // Subtract from Counter // |
| 134 | | // // |
| 135 | | /////////////////////////////////////////////////////////////////////////// |
| 153 | /*------------------------------------------------- |
| 154 | subtract_from_counter - Subtract from Counter |
| 155 | -------------------------------------------------*/ |
| 136 | 156 | |
| 137 | | static void subtract_from_counter(running_machine *machine, int which, int counter, int count) |
| 157 | static void subtract_from_counter( const device_config *device, int counter, int count ) |
| 138 | 158 | { |
| 159 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 139 | 160 | int clock; |
| 140 | 161 | attotime duration; |
| 141 | 162 | |
| 142 | | ptm6840 *currptr = ptm + which; |
| 143 | | |
| 144 | 163 | /* Determine the clock frequency for this timer */ |
| 145 | | if (currptr->control_reg[counter] & 0x02) |
| 146 | | clock = currptr->internal_clock; |
| 164 | if (ptm6840->control_reg[counter] & 0x02) |
| 165 | clock = ptm6840->internal_clock; |
| 147 | 166 | else |
| 148 | | clock = currptr->external_clock[counter]; |
| 167 | clock = ptm6840->external_clock[counter]; |
| 149 | 168 | |
| 150 | 169 | /* Dual-byte mode */ |
| 151 | | if (currptr->control_reg[counter] & 0x04) |
| 170 | if (ptm6840->control_reg[counter] & 0x04) |
| 152 | 171 | { |
| 153 | | int lsb = currptr->counter[counter] & 0xff; |
| 154 | | int msb = currptr->counter[counter] >> 8; |
| 172 | int lsb = ptm6840->counter[counter] & 0xff; |
| 173 | int msb = ptm6840->counter[counter] >> 8; |
| 155 | 174 | |
| 156 | 175 | /* Count the clocks */ |
| 157 | 176 | lsb -= count; |
| r4939 | r4940 | |
| 160 | 179 | while (lsb < 0) |
| 161 | 180 | { |
| 162 | 181 | /* Borrow from the MSB */ |
| 163 | | lsb += (currptr->latch[counter] & 0xff) + 1; |
| 182 | lsb += (ptm6840->latch[counter] & 0xff) + 1; |
| 164 | 183 | msb--; |
| 165 | 184 | |
| 166 | 185 | /* If MSB goes less than zero, we've expired */ |
| 167 | 186 | if (msb < 0) |
| 168 | 187 | { |
| 169 | | ptm6840_timeout(machine, which, counter); |
| 170 | | msb = (currptr->latch[counter] >> 8) + 1; |
| 188 | ptm6840_timeout(device, counter); |
| 189 | msb = (ptm6840->latch[counter] >> 8) + 1; |
| 171 | 190 | } |
| 172 | 191 | } |
| 173 | 192 | |
| 174 | 193 | /* Store the result */ |
| 175 | | currptr->counter[counter] = (msb << 8) | lsb; |
| 194 | ptm6840->counter[counter] = (msb << 8) | lsb; |
| 176 | 195 | } |
| 177 | 196 | |
| 178 | 197 | /* Word mode */ |
| 179 | 198 | else |
| 180 | 199 | { |
| 181 | | int word = currptr->counter[counter]; |
| 200 | int word = ptm6840->counter[counter]; |
| 182 | 201 | |
| 183 | 202 | /* Count the clocks */ |
| 184 | 203 | word -= count; |
| r4939 | r4940 | |
| 187 | 206 | while (word < 0) |
| 188 | 207 | { |
| 189 | 208 | /* Borrow from the MSB */ |
| 190 | | word += currptr->latch[counter] + 1; |
| 209 | word += ptm6840->latch[counter] + 1; |
| 191 | 210 | |
| 192 | 211 | /* We've expired */ |
| 193 | | ptm6840_timeout(machine, which, counter); |
| 212 | ptm6840_timeout(device, counter); |
| 194 | 213 | } |
| 195 | 214 | |
| 196 | 215 | /* Store the result */ |
| 197 | | currptr->counter[counter] = word; |
| 216 | ptm6840->counter[counter] = word; |
| 198 | 217 | } |
| 199 | 218 | |
| 200 | | if (currptr->enabled[counter]) |
| 219 | if (ptm6840->enabled[counter]) |
| 201 | 220 | { |
| 202 | | duration = attotime_mul(ATTOTIME_IN_HZ(clock), currptr->counter[counter]); |
| 221 | duration = attotime_mul(ATTOTIME_IN_HZ(clock), ptm6840->counter[counter]); |
| 203 | 222 | |
| 204 | 223 | if (counter == 2) |
| 205 | | duration = attotime_mul(duration, currptr->t3_divisor); |
| 224 | duration = attotime_mul(duration, ptm6840->t3_divisor); |
| 206 | 225 | |
| 207 | | timer_adjust_oneshot(currptr->timer[counter], duration, which); |
| 226 | timer_adjust_oneshot(ptm6840->timer[counter], duration, 0); |
| 208 | 227 | } |
| 209 | 228 | } |
| 210 | 229 | |
| 211 | | static void ptm_tick(running_machine *machine, int which, int counter, int count) |
| 230 | /*------------------------------------------------- |
| 231 | ptm_tick |
| 232 | -------------------------------------------------*/ |
| 233 | |
| 234 | static void ptm_tick( const device_config *device, int counter, int count ) |
| 212 | 235 | { |
| 213 | | ptm6840 *currptr = ptm + which; |
| 236 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 214 | 237 | |
| 215 | 238 | if (counter == 2) |
| 216 | 239 | { |
| 217 | | currptr->t3_scaler += count; |
| 240 | ptm6840->t3_scaler += count; |
| 218 | 241 | |
| 219 | | if ( currptr->t3_scaler > currptr->t3_divisor - 1) |
| 242 | if ( ptm6840->t3_scaler > ptm6840->t3_divisor - 1) |
| 220 | 243 | { |
| 221 | | subtract_from_counter(machine, which, counter, 1); |
| 222 | | currptr->t3_scaler = 0; |
| 244 | subtract_from_counter(device, counter, 1); |
| 245 | ptm6840->t3_scaler = 0; |
| 223 | 246 | } |
| 224 | 247 | } |
| 225 | 248 | else |
| 226 | 249 | { |
| 227 | | subtract_from_counter(machine, which, counter, count); |
| 250 | subtract_from_counter(device, counter, count); |
| 228 | 251 | } |
| 229 | 252 | } |
| 230 | 253 | |
| 231 | | /////////////////////////////////////////////////////////////////////////// |
| 232 | | // // |
| 233 | | // Update Internal Interrupts // |
| 234 | | // // |
| 235 | | /////////////////////////////////////////////////////////////////////////// |
| 254 | /*------------------------------------------------- |
| 255 | update_interrupts - Update Internal Interrupts |
| 256 | -------------------------------------------------*/ |
| 236 | 257 | |
| 237 | | INLINE void update_interrupts(running_machine *machine, int which) |
| 258 | INLINE void update_interrupts( const device_config *device ) |
| 238 | 259 | { |
| 260 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 239 | 261 | int new_state; |
| 240 | | ptm6840 *currptr = ptm + which; |
| 241 | 262 | |
| 242 | | new_state = ((currptr->status_reg & 0x01) && (currptr->control_reg[0] & 0x40)) || |
| 243 | | ((currptr->status_reg & 0x02) && (currptr->control_reg[1] & 0x40)) || |
| 244 | | ((currptr->status_reg & 0x04) && (currptr->control_reg[2] & 0x40)); |
| 263 | new_state = ((ptm6840->status_reg & 0x01) && (ptm6840->control_reg[0] & 0x40)) || |
| 264 | ((ptm6840->status_reg & 0x02) && (ptm6840->control_reg[1] & 0x40)) || |
| 265 | ((ptm6840->status_reg & 0x04) && (ptm6840->control_reg[2] & 0x40)); |
| 245 | 266 | |
| 246 | | // if (new_state != currptr->IRQ) |
| 267 | // if (new_state != ptm6840->IRQ) |
| 247 | 268 | { |
| 248 | | currptr->IRQ = new_state; |
| 269 | ptm6840->IRQ = new_state; |
| 249 | 270 | |
| 250 | | if (currptr->IRQ) |
| 251 | | currptr->status_reg |= 0x80; |
| 271 | if (ptm6840->IRQ) |
| 272 | ptm6840->status_reg |= 0x80; |
| 252 | 273 | else |
| 253 | | currptr->status_reg &= ~0x80; |
| 274 | ptm6840->status_reg &= ~0x80; |
| 254 | 275 | |
| 255 | | if (currptr->intf->irq_func) |
| 256 | | (currptr->intf->irq_func)(machine, currptr->IRQ); |
| 276 | devcb_call_write_line(&ptm6840->irq_func, ptm6840->IRQ); |
| 257 | 277 | } |
| 258 | 278 | } |
| 259 | 279 | |
| 260 | | /////////////////////////////////////////////////////////////////////////// |
| 261 | | // // |
| 262 | | // Compute Counter // |
| 263 | | // // |
| 264 | | /////////////////////////////////////////////////////////////////////////// |
| 280 | /*------------------------------------------------- |
| 281 | compute_counter - Compute Counter |
| 282 | -------------------------------------------------*/ |
| 265 | 283 | |
| 266 | | static UINT16 compute_counter(int which, int counter) |
| 284 | static UINT16 compute_counter( const device_config *device, int counter ) |
| 267 | 285 | { |
| 268 | | ptm6840 *currptr = ptm + which; |
| 269 | | |
| 286 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 270 | 287 | int clock; |
| 271 | | int remaining=0; |
| 288 | int remaining = 0; |
| 272 | 289 | |
| 273 | 290 | /* If there's no timer, return the count */ |
| 274 | | if (!currptr->enabled[counter]) |
| 291 | if (!ptm6840->enabled[counter]) |
| 275 | 292 | { |
| 276 | | PLOG(("MC6840 #%d: read counter(%d): %d\n", which, counter, currptr->counter[counter])); |
| 277 | | return currptr->counter[counter]; |
| 293 | PLOG(("MC6840 #%s: read counter(%d): %d\n", device->tag, counter, ptm6840->counter[counter])); |
| 294 | return ptm6840->counter[counter]; |
| 278 | 295 | } |
| 279 | 296 | |
| 280 | 297 | /* determine the clock frequency for this timer */ |
| 281 | | if (currptr->control_reg[counter] & 0x02) |
| 298 | if (ptm6840->control_reg[counter] & 0x02) |
| 282 | 299 | { |
| 283 | | clock = currptr->internal_clock; |
| 284 | | PLOG(("MC6840 #%d: %d internal clock freq %d \n", which, counter, clock)); |
| 300 | clock = ptm6840->internal_clock; |
| 301 | PLOG(("MC6840 #%s: %d internal clock freq %d \n", device->tag, counter, clock)); |
| 285 | 302 | } |
| 286 | 303 | else |
| 287 | 304 | { |
| 288 | | clock = currptr->external_clock[counter]; |
| 289 | | PLOG(("MC6840 #%d: %d external clock freq %d \n", which, counter, clock)); |
| 305 | clock = ptm6840->external_clock[counter]; |
| 306 | PLOG(("MC6840 #%s: %d external clock freq %d \n", device->tag, counter, clock)); |
| 290 | 307 | } |
| 291 | 308 | /* See how many are left */ |
| 292 | | remaining = attotime_to_double(attotime_mul(timer_timeleft(currptr->timer[counter]), clock)); |
| 309 | remaining = attotime_to_double(attotime_mul(timer_timeleft(ptm6840->timer[counter]), clock)); |
| 293 | 310 | |
| 294 | 311 | /* Adjust the count for dual byte mode */ |
| 295 | | if (currptr->control_reg[counter] & 0x04) |
| 312 | if (ptm6840->control_reg[counter] & 0x04) |
| 296 | 313 | { |
| 297 | | int divisor = (currptr->counter[counter] & 0xff) + 1; |
| 314 | int divisor = (ptm6840->counter[counter] & 0xff) + 1; |
| 298 | 315 | int msb = remaining / divisor; |
| 299 | 316 | int lsb = remaining % divisor; |
| 300 | 317 | remaining = (msb << 8) | lsb; |
| 301 | 318 | } |
| 302 | | PLOG(("MC6840 #%d: read counter(%d): %d\n", which, counter, remaining)); |
| 319 | PLOG(("MC6840 #%s: read counter(%d): %d\n", device->tag, counter, remaining)); |
| 303 | 320 | return remaining; |
| 304 | 321 | } |
| 305 | 322 | |
| 306 | | /////////////////////////////////////////////////////////////////////////// |
| 307 | | // // |
| 308 | | // Reload Counter // |
| 309 | | // // |
| 310 | | /////////////////////////////////////////////////////////////////////////// |
| 323 | /*------------------------------------------------- |
| 324 | reload_count - Reload Counter |
| 325 | -------------------------------------------------*/ |
| 311 | 326 | |
| 312 | | static void reload_count(running_machine *machine, int which, int idx) |
| 327 | static void reload_count( const device_config *device, int idx ) |
| 313 | 328 | { |
| 314 | | /* temporary hack until this is converted to a device */ |
| 315 | | const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); |
| 329 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 316 | 330 | int clock; |
| 317 | 331 | int count; |
| 318 | 332 | attotime duration; |
| 319 | | ptm6840 *currptr = ptm + which; |
| 320 | 333 | |
| 321 | 334 | /* Copy the latched value in */ |
| 322 | | currptr->counter[idx] = currptr->latch[idx]; |
| 335 | ptm6840->counter[idx] = ptm6840->latch[idx]; |
| 323 | 336 | |
| 324 | 337 | /* Determine the clock frequency for this timer */ |
| 325 | | if (currptr->control_reg[idx] & 0x02) |
| 338 | if (ptm6840->control_reg[idx] & 0x02) |
| 326 | 339 | { |
| 327 | | clock = currptr->internal_clock; |
| 328 | | PLOG(("MC6840 #%d: %d internal clock freq %d \n", which,idx, clock)); |
| 340 | clock = ptm6840->internal_clock; |
| 341 | PLOG(("MC6840 #%s: %d internal clock freq %d \n", device->tag, idx, clock)); |
| 329 | 342 | } |
| 330 | 343 | else |
| 331 | 344 | { |
| 332 | | clock = currptr->external_clock[idx]; |
| 333 | | PLOG(("MC6840 #%d: %d external clock freq %d \n", which,idx, clock)); |
| 345 | clock = ptm6840->external_clock[idx]; |
| 346 | PLOG(("MC6840 #%s: %d external clock freq %d \n", device->tag, idx, clock)); |
| 334 | 347 | } |
| 335 | 348 | |
| 336 | 349 | /* Determine the number of clock periods before we expire */ |
| 337 | | count = currptr->counter[idx]; |
| 338 | | if (currptr->control_reg[idx] & 0x04) |
| 350 | count = ptm6840->counter[idx]; |
| 351 | if (ptm6840->control_reg[idx] & 0x04) |
| 339 | 352 | count = ((count >> 8) + 1) * ((count & 0xff) + 1); |
| 340 | 353 | else |
| 341 | 354 | count = count + 1; |
| 342 | 355 | |
| 343 | | currptr->fired[idx]=0; |
| 356 | ptm6840->fired[idx] = 0; |
| 344 | 357 | |
| 345 | | if ((currptr->mode[idx] == 4)||(currptr->mode[idx] == 6)) |
| 358 | if ((ptm6840->mode[idx] == 4) || (ptm6840->mode[idx] == 6)) |
| 346 | 359 | { |
| 347 | | currptr->output[idx] = 1; |
| 348 | | if ( currptr->intf->out_func[idx] ) currptr->intf->out_func[idx](space, 0, currptr->output[idx]); |
| 360 | ptm6840->output[idx] = 1; |
| 361 | if (ptm6840->out_func[idx].write != NULL) |
| 362 | devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]); |
| 349 | 363 | } |
| 350 | 364 | |
| 351 | 365 | /* Set the timer */ |
| 352 | | PLOG(("MC6840 #%d: reload_count(%d): clock = %d count = %d\n", which, idx, clock, count)); |
| 366 | PLOG(("MC6840 #%s: reload_count(%d): clock = %d count = %d\n", device->tag, idx, clock, count)); |
| 353 | 367 | |
| 354 | 368 | duration = attotime_mul(ATTOTIME_IN_HZ(clock), count); |
| 355 | | if (idx == 2) duration = attotime_mul(duration, currptr->t3_divisor); |
| 356 | | PLOG(("MC6840 #%d: reload_count(%d): output = %lf\n", which, idx, attotime_to_double(duration))); |
| 369 | if (idx == 2) |
| 370 | duration = attotime_mul(duration, ptm6840->t3_divisor); |
| 357 | 371 | |
| 358 | | if (!(currptr->control_reg[idx] & 0x02)) |
| 372 | PLOG(("MC6840 #%s: reload_count(%d): output = %lf\n", device->tag, idx, attotime_to_double(duration))); |
| 373 | |
| 374 | if (!(ptm6840->control_reg[idx] & 0x02)) |
| 359 | 375 | { |
| 360 | | if (!currptr->intf->external_clock[idx]) |
| 376 | if (!ptm6840->external_clock[idx]) |
| 361 | 377 | { |
| 362 | | currptr->enabled[idx] = 0; |
| 363 | | timer_enable(currptr->timer[idx],FALSE); |
| 378 | ptm6840->enabled[idx] = 0; |
| 379 | timer_enable(ptm6840->timer[idx],FALSE); |
| 364 | 380 | } |
| 365 | 381 | } |
| 366 | 382 | else |
| 367 | 383 | { |
| 368 | | currptr->enabled[idx] = 1; |
| 369 | | timer_adjust_oneshot(currptr->timer[idx], duration, which); |
| 370 | | timer_enable(currptr->timer[idx],TRUE); |
| 384 | ptm6840->enabled[idx] = 1; |
| 385 | timer_adjust_oneshot(ptm6840->timer[idx], duration, 0); |
| 386 | timer_enable(ptm6840->timer[idx], TRUE); |
| 371 | 387 | } |
| 372 | 388 | } |
| 373 | 389 | |
| 374 | | /////////////////////////////////////////////////////////////////////////// |
| 375 | | // // |
| 376 | | // Configure Timer // |
| 377 | | // // |
| 378 | | /////////////////////////////////////////////////////////////////////////// |
| 379 | 390 | |
| 380 | | void ptm6840_config(running_machine *machine, int which, const ptm6840_interface *intf) |
| 381 | | { |
| 382 | | int i; |
| 383 | | ptm6840 *currptr = ptm + which; |
| 391 | /*------------------------------------------------- |
| 392 | ptm6840_read - Read Timer |
| 393 | -------------------------------------------------*/ |
| 384 | 394 | |
| 385 | | assert_always(mame_get_phase(machine) == MAME_PHASE_INIT, "Can only call ptm6840_config at init time!"); |
| 386 | | assert_always((which >= 0) && (which < PTM_6840_MAX), "ptm6840_config called on an invalid PTM!"); |
| 387 | | assert_always(intf, "ptm6840_config called with an invalid interface!"); |
| 388 | | ptm[which].intf = intf; |
| 389 | | ptm[which].internal_clock = currptr->intf->internal_clock; |
| 390 | | |
| 391 | | for (i = 0; i < 3; i++) |
| 392 | | { |
| 393 | | if ( currptr->intf->external_clock[i] ) |
| 394 | | ptm[which].external_clock[i] = currptr->intf->external_clock[i]; |
| 395 | | else |
| 396 | | ptm[which].external_clock[i] = 1; |
| 397 | | } |
| 398 | | |
| 399 | | for (i = 0; i < 3; i++) |
| 400 | | { |
| 401 | | ptm[which].timer[i] = timer_alloc(machine, ptm6840_timer_cb, (void*)(FPTR)i); |
| 402 | | timer_enable(ptm[which].timer[i], FALSE); |
| 403 | | } |
| 404 | | |
| 405 | | state_save_register_item(machine, "6840ptm", NULL, which, currptr->lsb_buffer); |
| 406 | | state_save_register_item(machine, "6840ptm", NULL, which, currptr->msb_buffer); |
| 407 | | state_save_register_item(machine, "6840ptm", NULL, which, currptr->status_read_since_int); |
| 408 | | state_save_register_item(machine, "6840ptm", NULL, which, currptr->status_reg); |
| 409 | | state_save_register_item(machine, "6840ptm", NULL, which, currptr->t3_divisor); |
| 410 | | state_save_register_item(machine, "6840ptm", NULL, which, currptr->t3_scaler); |
| 411 | | state_save_register_item(machine, "6840ptm", NULL, which, currptr->internal_clock); |
| 412 | | state_save_register_item(machine, "6840ptm", NULL, which, currptr->IRQ); |
| 413 | | |
| 414 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->control_reg); |
| 415 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->output); |
| 416 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->gate); |
| 417 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->clock); |
| 418 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->mode); |
| 419 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->fired); |
| 420 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->enabled); |
| 421 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->external_clock); |
| 422 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->counter); |
| 423 | | state_save_register_item_array(machine, "6840ptm", NULL, which, currptr->latch); |
| 424 | | |
| 425 | | ptm6840_reset(which); |
| 426 | | } |
| 427 | | |
| 428 | | /////////////////////////////////////////////////////////////////////////// |
| 429 | | // // |
| 430 | | // Reset Timer // |
| 431 | | // // |
| 432 | | /////////////////////////////////////////////////////////////////////////// |
| 433 | | |
| 434 | | void ptm6840_reset(int which) |
| 395 | READ8_DEVICE_HANDLER( ptm6840_read ) |
| 435 | 396 | { |
| 436 | | int i; |
| 437 | | |
| 438 | | ptm[which].control_reg[2] = 0; |
| 439 | | ptm[which].control_reg[1] = 0; |
| 440 | | ptm[which].control_reg[0] = 1; |
| 441 | | ptm[which].status_reg = 0; |
| 442 | | ptm[which].t3_divisor = 1; |
| 443 | | ptm[which].status_read_since_int = 0; |
| 444 | | ptm[which].IRQ = 0; |
| 445 | | |
| 446 | | for (i = 0; i < 3; i++) |
| 447 | | { |
| 448 | | ptm[which].counter[i] = 0xffff; |
| 449 | | ptm[which].latch[i] = 0xffff; |
| 450 | | ptm[which].output[i] = 0; |
| 451 | | ptm[which].fired[i] = 0; |
| 452 | | } |
| 453 | | } |
| 454 | | |
| 455 | | /////////////////////////////////////////////////////////////////////////// |
| 456 | | // // |
| 457 | | // Read Timer // |
| 458 | | // // |
| 459 | | /////////////////////////////////////////////////////////////////////////// |
| 460 | | |
| 461 | | int ptm6840_read(running_machine *machine, int which, int offset) |
| 462 | | { |
| 397 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 463 | 398 | int val; |
| 464 | | ptm6840 *currptr = ptm + which; |
| 465 | 399 | |
| 466 | 400 | switch ( offset ) |
| 467 | 401 | { |
| r4939 | r4940 | |
| 473 | 407 | |
| 474 | 408 | case PTM_6840_STATUS: |
| 475 | 409 | { |
| 476 | | PLOG(("%s: MC6840 #%d: Status read = %04X\n", cpuexec_describe_context(machine), which, currptr->status_reg)); |
| 477 | | currptr->status_read_since_int |= currptr->status_reg & 0x07; |
| 478 | | val = currptr->status_reg; |
| 410 | PLOG(("%s: MC6840 #%s: Status read = %04X\n", cpuexec_describe_context(device->machine), device->tag, ptm6840->status_reg)); |
| 411 | ptm6840->status_read_since_int |= ptm6840->status_reg & 0x07; |
| 412 | val = ptm6840->status_reg; |
| 479 | 413 | break; |
| 480 | 414 | } |
| 481 | 415 | |
| r4939 | r4940 | |
| 484 | 418 | case PTM_6840_MSBBUF3: |
| 485 | 419 | { |
| 486 | 420 | int idx = (offset - 2) / 2; |
| 487 | | int result = compute_counter(which, idx); |
| 421 | int result = compute_counter(device, idx); |
| 488 | 422 | |
| 489 | 423 | /* Clear the interrupt if the status has been read */ |
| 490 | | if (currptr->status_read_since_int & (1 << idx)) |
| 424 | if (ptm6840->status_read_since_int & (1 << idx)) |
| 491 | 425 | { |
| 492 | | currptr->status_reg &= ~(1 << idx); |
| 493 | | update_interrupts(machine, which); |
| 426 | ptm6840->status_reg &= ~(1 << idx); |
| 427 | update_interrupts(device); |
| 494 | 428 | } |
| 495 | 429 | |
| 496 | | currptr->lsb_buffer = result & 0xff; |
| 430 | ptm6840->lsb_buffer = result & 0xff; |
| 497 | 431 | |
| 498 | | PLOG(("%s: MC6840 #%d: Counter %d read = %04X\n", cpuexec_describe_context(machine), which, idx, result >> 8)); |
| 432 | PLOG(("%s: MC6840 #%s: Counter %d read = %04X\n", cpuexec_describe_context(device->machine), device->tag, idx, result >> 8)); |
| 499 | 433 | val = result >> 8; |
| 500 | 434 | break; |
| 501 | 435 | } |
| r4939 | r4940 | |
| 504 | 438 | case PTM_6840_LSB2: |
| 505 | 439 | case PTM_6840_LSB3: |
| 506 | 440 | { |
| 507 | | val = currptr->lsb_buffer; |
| 441 | val = ptm6840->lsb_buffer; |
| 508 | 442 | break; |
| 509 | 443 | } |
| 510 | 444 | |
| r4939 | r4940 | |
| 518 | 452 | return val; |
| 519 | 453 | } |
| 520 | 454 | |
| 521 | | /////////////////////////////////////////////////////////////////////////// |
| 522 | | // // |
| 523 | | // Write Timer // |
| 524 | | // // |
| 525 | | /////////////////////////////////////////////////////////////////////////// |
| 455 | /*------------------------------------------------- |
| 456 | ptm6840_write - Write Timer |
| 457 | -------------------------------------------------*/ |
| 526 | 458 | |
| 527 | | void ptm6840_write (running_machine *machine, int which, int offset, int data) |
| 459 | WRITE8_DEVICE_HANDLER( ptm6840_write ) |
| 528 | 460 | { |
| 529 | | /* temporary hack until this is converted to a device */ |
| 530 | | const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); |
| 531 | | ptm6840 *currptr = ptm + which; |
| 532 | | |
| 461 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 533 | 462 | int idx; |
| 534 | 463 | int i; |
| 535 | 464 | UINT8 diffs; |
| r4939 | r4940 | |
| 539 | 468 | case PTM_6840_CTRL1: |
| 540 | 469 | case PTM_6840_CTRL2: |
| 541 | 470 | { |
| 542 | | idx = (offset == 1) ? 1 : (currptr->control_reg[1] & 0x01) ? 0 : 2; |
| 543 | | diffs = data ^ currptr->control_reg[idx]; |
| 544 | | currptr->t3_divisor = (currptr->control_reg[2] & 0x01) ? 8 : 1; |
| 545 | | currptr->mode[idx] = (data >> 3) & 0x07; |
| 546 | | currptr->control_reg[idx] = data; |
| 471 | idx = (offset == 1) ? 1 : (ptm6840->control_reg[1] & 0x01) ? 0 : 2; |
| 472 | diffs = data ^ ptm6840->control_reg[idx]; |
| 473 | ptm6840->t3_divisor = (ptm6840->control_reg[2] & 0x01) ? 8 : 1; |
| 474 | ptm6840->mode[idx] = (data >> 3) & 0x07; |
| 475 | ptm6840->control_reg[idx] = data; |
| 547 | 476 | |
| 548 | | PLOG(("MC6840 #%d : Control register %d selected\n", which, idx)); |
| 549 | | PLOG(("operation mode = %s\n", opmode[ currptr->mode[idx] ])); |
| 550 | | PLOG(("value = %04X\n", currptr->control_reg[idx])); |
| 551 | | PLOG(("t3divisor = %d\n", currptr->t3_divisor)); |
| 477 | PLOG(("MC6840 #%s : Control register %d selected\n", device->tag, idx)); |
| 478 | PLOG(("operation mode = %s\n", opmode[ ptm6840->mode[idx] ])); |
| 479 | PLOG(("value = %04X\n", ptm6840->control_reg[idx])); |
| 480 | PLOG(("t3divisor = %d\n", ptm6840->t3_divisor)); |
| 552 | 481 | |
| 553 | | if (!(currptr->control_reg[idx] & 0x80 )) |
| 482 | if (!(ptm6840->control_reg[idx] & 0x80 )) |
| 554 | 483 | { |
| 555 | 484 | /* Output cleared */ |
| 556 | | if ( currptr->intf ) |
| 557 | | { |
| 558 | | if ( currptr->intf->out_func[idx] ) |
| 559 | | currptr->intf->out_func[idx](space, 0, 0); |
| 560 | | } |
| 485 | if (ptm6840->out_func[idx].write != NULL) |
| 486 | devcb_call_write8(&ptm6840->out_func[idx], 0, 0); |
| 561 | 487 | } |
| 562 | 488 | /* Reset? */ |
| 563 | 489 | if (idx == 0 && (diffs & 0x01)) |
| r4939 | r4940 | |
| 565 | 491 | /* Holding reset down */ |
| 566 | 492 | if (data & 0x01) |
| 567 | 493 | { |
| 568 | | PLOG(("MC6840 #%d : Timer reset\n", which)); |
| 494 | PLOG(("MC6840 #%s : Timer reset\n", device->tag)); |
| 569 | 495 | for (i = 0; i < 3; i++) |
| 570 | 496 | { |
| 571 | | timer_enable(currptr->timer[i], FALSE); |
| 572 | | currptr->enabled[i] = 0; |
| 497 | timer_enable(ptm6840->timer[i], FALSE); |
| 498 | ptm6840->enabled[i] = 0; |
| 573 | 499 | } |
| 574 | 500 | } |
| 575 | 501 | /* Releasing reset */ |
| 576 | 502 | else |
| 577 | 503 | { |
| 578 | 504 | for (i = 0; i < 3; i++) |
| 579 | | reload_count(machine, which, i); |
| 505 | reload_count(device, i); |
| 580 | 506 | } |
| 581 | 507 | |
| 582 | | currptr->status_reg = 0; |
| 583 | | update_interrupts(machine, which); |
| 508 | ptm6840->status_reg = 0; |
| 509 | update_interrupts(device); |
| 584 | 510 | |
| 585 | 511 | /* Changing the clock source? (e.g. Zwackery) */ |
| 586 | 512 | if (diffs & 0x02) |
| 587 | | reload_count(machine, which, idx); |
| 513 | reload_count(device, idx); |
| 588 | 514 | } |
| 589 | 515 | break; |
| 590 | 516 | } |
| r4939 | r4940 | |
| 593 | 519 | case PTM_6840_MSBBUF2: |
| 594 | 520 | case PTM_6840_MSBBUF3: |
| 595 | 521 | { |
| 596 | | PLOG(("MC6840 #%d msbbuf%d = %02X\n", which, offset / 2, data)); |
| 597 | | currptr->msb_buffer = data; |
| 522 | PLOG(("MC6840 #%s msbbuf%d = %02X\n", device->tag, offset / 2, data)); |
| 523 | ptm6840->msb_buffer = data; |
| 598 | 524 | break; |
| 599 | 525 | } |
| 600 | 526 | |
| r4939 | r4940 | |
| 603 | 529 | case PTM_6840_LSB3: |
| 604 | 530 | { |
| 605 | 531 | idx = (offset - 3) / 2; |
| 606 | | currptr->latch[idx] = (currptr->msb_buffer << 8) | (data & 0xff); |
| 532 | ptm6840->latch[idx] = (ptm6840->msb_buffer << 8) | (data & 0xff); |
| 607 | 533 | |
| 608 | 534 | /* Clear the interrupt */ |
| 609 | | currptr->status_reg &= ~(1 << idx); |
| 610 | | update_interrupts(machine, which); |
| 535 | ptm6840->status_reg &= ~(1 << idx); |
| 536 | update_interrupts(device); |
| 611 | 537 | |
| 612 | 538 | /* Reload the count if in an appropriate mode */ |
| 613 | | if (!(currptr->control_reg[idx] & 0x10)) |
| 614 | | reload_count(machine, which,idx); |
| 539 | if (!(ptm6840->control_reg[idx] & 0x10)) |
| 540 | reload_count(device,idx); |
| 615 | 541 | |
| 616 | | PLOG(("%s:MC6840 #%d: Counter %d latch = %04X\n", cpuexec_describe_context(machine), which, idx, currptr->latch[idx])); |
| 542 | PLOG(("%s:MC6840 #%s: Counter %d latch = %04X\n", cpuexec_describe_context(device->machine), device->tag, idx, ptm6840->latch[idx])); |
| 617 | 543 | break; |
| 618 | 544 | } |
| 619 | 545 | } |
| 620 | 546 | } |
| 621 | 547 | |
| 622 | | /////////////////////////////////////////////////////////////////////////// |
| 623 | | // // |
| 624 | | // ptm6840_timeout: called if timer is mature // |
| 625 | | // // |
| 626 | | /////////////////////////////////////////////////////////////////////////// |
| 548 | /*------------------------------------------------- |
| 549 | ptm6840_timeout - Called if timer is mature |
| 550 | -------------------------------------------------*/ |
| 627 | 551 | |
| 628 | | static void ptm6840_timeout(running_machine *machine, int which, int idx) |
| 552 | static void ptm6840_timeout( const device_config *device, int idx ) |
| 629 | 553 | { |
| 630 | | /* temporary hack until this is converted to a device */ |
| 631 | | const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); |
| 632 | | ptm6840 *p = ptm + which; |
| 554 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 633 | 555 | |
| 634 | | PLOG(("**ptm6840 %d t%d timeout**\n", which, idx + 1)); |
| 556 | PLOG(("**ptm6840 %s t%d timeout**\n", device->tag, idx + 1)); |
| 635 | 557 | |
| 636 | | if ( p->control_reg[idx] & 0x40 ) |
| 558 | if ( ptm6840->control_reg[idx] & 0x40 ) |
| 637 | 559 | { |
| 638 | 560 | /* Interrupt enabled */ |
| 639 | | p->status_reg |= (1 << idx); |
| 640 | | p->status_read_since_int &= ~(1 << idx); |
| 641 | | update_interrupts(machine, which); |
| 561 | ptm6840->status_reg |= (1 << idx); |
| 562 | ptm6840->status_read_since_int &= ~(1 << idx); |
| 563 | update_interrupts(device); |
| 642 | 564 | } |
| 643 | 565 | |
| 644 | | if ( p->control_reg[idx] & 0x80 ) |
| 566 | if ( ptm6840->control_reg[idx] & 0x80 ) |
| 645 | 567 | { |
| 646 | | /* Output enabled */ |
| 647 | | if ( p->intf ) |
| 568 | if ((ptm6840->mode[idx] == 0)||(ptm6840->mode[idx] == 2)) |
| 648 | 569 | { |
| 649 | | if ((p->mode[idx] == 0)||(p->mode[idx] == 2)) |
| 650 | | { |
| 651 | | p->output[idx] = p->output[idx]?0:1; |
| 652 | | PLOG(("**ptm6840 %d t%d output %d **\n", which, idx + 1, p->output[idx])); |
| 570 | ptm6840->output[idx] = ptm6840->output[idx] ? 0 : 1; |
| 571 | PLOG(("**ptm6840 %s t%d output %d **\n", device->tag, idx + 1, ptm6840->output[idx])); |
| 653 | 572 | |
| 654 | | if ( p->intf->out_func[idx] ) |
| 655 | | p->intf->out_func[idx](space, 0, p->output[idx]); |
| 656 | | } |
| 657 | | if ((p->mode[idx] == 4)||(p->mode[idx] == 6)) |
| 573 | if (ptm6840->out_func[idx].write != NULL) |
| 574 | devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]); |
| 575 | } |
| 576 | if ((ptm6840->mode[idx] == 4)||(ptm6840->mode[idx] == 6)) |
| 577 | { |
| 578 | if (!ptm6840->fired[idx]) |
| 658 | 579 | { |
| 659 | | if (!p->fired[idx]) |
| 660 | | { |
| 661 | | p->output[idx] = 1; |
| 662 | | PLOG(("**ptm6840 %d t%d output %d **\n", which, idx + 1, p->output[idx])); |
| 580 | ptm6840->output[idx] = 1; |
| 581 | PLOG(("**ptm6840 %s t%d output %d **\n", device->tag, idx + 1, ptm6840->output[idx])); |
| 663 | 582 | |
| 664 | | if ( p->intf->out_func[idx] ) |
| 665 | | p->intf->out_func[idx](space, 0, p->output[idx]); |
| 583 | if (ptm6840->out_func[idx].write != NULL) |
| 584 | devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]); |
| 666 | 585 | |
| 667 | | /* No changes in output until reinit */ |
| 668 | | p->fired[idx] = 1; |
| 669 | | } |
| 586 | /* No changes in output until reinit */ |
| 587 | ptm6840->fired[idx] = 1; |
| 670 | 588 | } |
| 671 | 589 | } |
| 672 | 590 | } |
| 673 | | p->enabled[idx]= 0; |
| 674 | | reload_count(machine, which, idx); |
| 591 | ptm6840->enabled[idx]= 0; |
| 592 | reload_count(device, idx); |
| 675 | 593 | } |
| 676 | 594 | |
| 677 | | static TIMER_CALLBACK( ptm6840_timer_cb ) { ptm6840_timeout(machine, param, (int)(FPTR)ptr); } |
| 595 | /*------------------------------------------------- |
| 596 | TIMER_CALLBACKs for Timer 1, 2 & 3 |
| 597 | -------------------------------------------------*/ |
| 678 | 598 | |
| 679 | | /////////////////////////////////////////////////////////////////////////// |
| 680 | | // // |
| 681 | | // ptm6840_set_gate: set gate status (0 or 1) // |
| 682 | | // // |
| 683 | | /////////////////////////////////////////////////////////////////////////// |
| 599 | static TIMER_CALLBACK( ptm6840_timer1_cb ) |
| 600 | { |
| 601 | const device_config *device = (const device_config *)ptr; |
| 602 | ptm6840_timeout(device, 0); |
| 603 | } |
| 684 | 604 | |
| 685 | | INLINE void ptm6840_set_gate(running_machine *machine, int which, int state, int idx) |
| 605 | static TIMER_CALLBACK( ptm6840_timer2_cb ) |
| 686 | 606 | { |
| 687 | | ptm6840 *p = ptm + which; |
| 607 | const device_config *device = (const device_config *)ptr; |
| 608 | ptm6840_timeout(device, 1); |
| 609 | } |
| 688 | 610 | |
| 689 | | if ( (p->mode[idx] == 0) || (p->mode[idx] == 2) || (p->mode[0] == 4) || (p->mode[idx] == 6) ) |
| 611 | static TIMER_CALLBACK( ptm6840_timer3_cb ) |
| 612 | { |
| 613 | const device_config *device = (const device_config *)ptr; |
| 614 | ptm6840_timeout(device, 2); |
| 615 | } |
| 616 | |
| 617 | |
| 618 | /*------------------------------------------------- |
| 619 | ptm6840_set_gate - set gate status (0 or 1) |
| 620 | -------------------------------------------------*/ |
| 621 | |
| 622 | INLINE void ptm6840_set_gate( const device_config *device, int state, int idx ) |
| 623 | { |
| 624 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 625 | |
| 626 | if ( (ptm6840->mode[idx] == 0) || (ptm6840->mode[idx] == 2) || (ptm6840->mode[0] == 4) || (ptm6840->mode[idx] == 6) ) |
| 690 | 627 | { |
| 691 | | if (state == 0 && p->gate[idx]) |
| 692 | | reload_count(machine, which,idx); |
| 628 | if (state == 0 && ptm6840->gate[idx]) |
| 629 | reload_count(device,idx); |
| 693 | 630 | } |
| 694 | | p->gate[idx] = state; |
| 631 | ptm6840->gate[idx] = state; |
| 695 | 632 | } |
| 696 | 633 | |
| 697 | | void ptm6840_set_g1(running_machine *machine, int which, int state) { ptm6840_set_gate(machine, which, state, 0); } |
| 698 | | void ptm6840_set_g2(running_machine *machine, int which, int state) { ptm6840_set_gate(machine, which, state, 1); } |
| 699 | | void ptm6840_set_g3(running_machine *machine, int which, int state) { ptm6840_set_gate(machine, which, state, 2); } |
| 634 | /*------------------------------------------------- |
| 635 | WRITE8_DEVICE_HANDLERs for Gate 1, 2 & 3 |
| 636 | -------------------------------------------------*/ |
| 700 | 637 | |
| 701 | | /////////////////////////////////////////////////////////////////////////// |
| 702 | | // // |
| 703 | | // ptm6840_set_clock: set clock status (0 or 1) // |
| 704 | | // // |
| 705 | | /////////////////////////////////////////////////////////////////////////// |
| 638 | WRITE8_DEVICE_HANDLER( ptm6840_set_g1 ) |
| 639 | { |
| 640 | ptm6840_set_gate(device, data, 0); |
| 641 | } |
| 706 | 642 | |
| 707 | | INLINE void ptm6840_set_clock(running_machine *machine, int which, int state, int idx) |
| 643 | WRITE8_DEVICE_HANDLER( ptm6840_set_g2 ) |
| 708 | 644 | { |
| 709 | | ptm6840 *p = ptm + which; |
| 645 | ptm6840_set_gate(device, data, 1); |
| 646 | } |
| 710 | 647 | |
| 711 | | p->clock[idx] = state; |
| 648 | WRITE8_DEVICE_HANDLER( ptm6840_set_g3 ) |
| 649 | { |
| 650 | ptm6840_set_gate(device, data, 2); |
| 651 | } |
| 712 | 652 | |
| 713 | | if (!(p->control_reg[idx] & 0x02)) |
| 653 | /*------------------------------------------------- |
| 654 | ptm6840_set_clock - set clock status (0 or 1) |
| 655 | -------------------------------------------------*/ |
| 656 | |
| 657 | INLINE void ptm6840_set_clock( const device_config *device, int state, int idx ) |
| 658 | { |
| 659 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 660 | |
| 661 | ptm6840->clock[idx] = state; |
| 662 | |
| 663 | if (!(ptm6840->control_reg[idx] & 0x02)) |
| 714 | 664 | { |
| 715 | 665 | if (state) |
| 716 | | ptm_tick(machine, which, idx, 1); |
| 666 | ptm_tick(device, idx, 1); |
| 717 | 667 | } |
| 718 | 668 | } |
| 719 | 669 | |
| 720 | | /////////////////////////////////////////////////////////////////////////// |
| 721 | | // // |
| 722 | | // ptm6840_get_count: get count value // |
| 723 | | // // |
| 724 | | /////////////////////////////////////////////////////////////////////////// |
| 670 | /*------------------------------------------------- |
| 671 | WRITE8_DEVICE_HANDLERs for Clock 1, 2 & 3 |
| 672 | -------------------------------------------------*/ |
| 725 | 673 | |
| 726 | | UINT16 ptm6840_get_count(int which,int counter) |
| 674 | WRITE8_DEVICE_HANDLER( ptm6840_set_c1 ) |
| 727 | 675 | { |
| 728 | | return compute_counter(which, counter); |
| 676 | ptm6840_set_clock(device, data, 0); |
| 729 | 677 | } |
| 730 | 678 | |
| 731 | | /////////////////////////////////////////////////////////////////////////// |
| 732 | | // // |
| 733 | | // ptm6840_set_ext_clock: set external clock frequency // |
| 734 | | // // |
| 735 | | /////////////////////////////////////////////////////////////////////////// |
| 679 | WRITE8_DEVICE_HANDLER( ptm6840_set_c2 ) |
| 680 | { |
| 681 | ptm6840_set_clock(device, data, 1); |
| 682 | } |
| 736 | 683 | |
| 737 | | void ptm6840_set_ext_clock(int which, int counter, int clock) |
| 684 | WRITE8_DEVICE_HANDLER( ptm6840_set_c3 ) |
| 738 | 685 | { |
| 739 | | ptm6840 *currptr = ptm + which; |
| 740 | | currptr->external_clock[counter] = clock; |
| 686 | ptm6840_set_clock(device, data, 2); |
| 687 | } |
| 741 | 688 | |
| 742 | | if (!(currptr->control_reg[counter] & 0x02)) |
| 689 | |
| 690 | /*------------------------------------------------- |
| 691 | ptm6840_get_count - get count value |
| 692 | -------------------------------------------------*/ |
| 693 | |
| 694 | UINT16 ptm6840_get_count( const device_config *device, int counter ) |
| 695 | { |
| 696 | return compute_counter(device, counter); |
| 697 | } |
| 698 | |
| 699 | /*------------------------------------------------------------ |
| 700 | ptm6840_set_ext_clock - set external clock frequency |
| 701 | ------------------------------------------------------------*/ |
| 702 | |
| 703 | void ptm6840_set_ext_clock( const device_config *device, int counter, int clock ) |
| 704 | { |
| 705 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 706 | |
| 707 | ptm6840->external_clock[counter] = clock; |
| 708 | |
| 709 | if (!(ptm6840->control_reg[counter] & 0x02)) |
| 743 | 710 | { |
| 744 | | if (!currptr->intf->external_clock[counter]) |
| 711 | if (!ptm6840->external_clock[counter]) |
| 745 | 712 | { |
| 746 | | currptr->enabled[counter] = 0; |
| 747 | | timer_enable(currptr->timer[counter], FALSE); |
| 713 | ptm6840->enabled[counter] = 0; |
| 714 | timer_enable(ptm6840->timer[counter], FALSE); |
| 748 | 715 | } |
| 749 | 716 | } |
| 750 | 717 | else |
| r4939 | r4940 | |
| 753 | 720 | attotime duration; |
| 754 | 721 | |
| 755 | 722 | /* Determine the number of clock periods before we expire */ |
| 756 | | count = currptr->counter[counter]; |
| 723 | count = ptm6840->counter[counter]; |
| 757 | 724 | |
| 758 | | if (currptr->control_reg[counter] & 0x04) |
| 725 | if (ptm6840->control_reg[counter] & 0x04) |
| 759 | 726 | count = ((count >> 8) + 1) * ((count & 0xff) + 1); |
| 760 | 727 | else |
| 761 | 728 | count = count + 1; |
| r4939 | r4940 | |
| 763 | 730 | duration = attotime_mul(ATTOTIME_IN_HZ(clock), count); |
| 764 | 731 | |
| 765 | 732 | if (counter == 2) |
| 766 | | duration = attotime_mul(duration, currptr->t3_divisor); |
| 733 | duration = attotime_mul(duration, ptm6840->t3_divisor); |
| 767 | 734 | |
| 768 | | currptr->enabled[counter] = 1; |
| 769 | | timer_adjust_oneshot(currptr->timer[counter], duration, which); |
| 770 | | timer_enable(currptr->timer[counter], TRUE); |
| 735 | ptm6840->enabled[counter] = 1; |
| 736 | timer_adjust_oneshot(ptm6840->timer[counter], duration, 0); |
| 737 | timer_enable(ptm6840->timer[counter], TRUE); |
| 771 | 738 | } |
| 772 | 739 | } |
| 773 | 740 | |
| 774 | | /////////////////////////////////////////////////////////////////////////// |
| 775 | | // // |
| 776 | | // ptm6840_get_ext_clock: get external clock frequency // |
| 777 | | // // |
| 778 | | /////////////////////////////////////////////////////////////////////////// |
| 741 | /*------------------------------------------------------------ |
| 742 | ptm6840_get_ext_clock - get external clock frequency |
| 743 | ------------------------------------------------------------*/ |
| 779 | 744 | |
| 780 | | int ptm6840_get_ext_clock(int which, int counter) |
| 745 | int ptm6840_get_ext_clock( const device_config *device, int counter ) |
| 781 | 746 | { |
| 782 | | ptm6840 *currptr = ptm + which; |
| 783 | | return currptr->external_clock[counter]; |
| 747 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 748 | return ptm6840->external_clock[counter]; |
| 784 | 749 | } |
| 785 | 750 | |
| 786 | | void ptm6840_set_c1(running_machine *machine, int which, int state) { ptm6840_set_clock(machine, which, state, 0); } |
| 787 | | void ptm6840_set_c2(running_machine *machine, int which, int state) { ptm6840_set_clock(machine, which, state, 1); } |
| 788 | | void ptm6840_set_c3(running_machine *machine, int which, int state) { ptm6840_set_clock(machine, which, state, 2); } |
| 789 | 751 | |
| 790 | | ///////////////////////////////////////////////////////////////////////////////// |
| 752 | /*------------------------------------------------- |
| 753 | DEVICE_START( ptm6840 ) |
| 754 | -------------------------------------------------*/ |
| 791 | 755 | |
| 792 | | READ8_HANDLER( ptm6840_0_r ) { return ptm6840_read(space->machine, 0, offset); } |
| 793 | | READ8_HANDLER( ptm6840_1_r ) { return ptm6840_read(space->machine, 1, offset); } |
| 794 | | READ8_HANDLER( ptm6840_2_r ) { return ptm6840_read(space->machine, 2, offset); } |
| 795 | | READ8_HANDLER( ptm6840_3_r ) { return ptm6840_read(space->machine, 3, offset); } |
| 756 | static DEVICE_START( ptm6840 ) |
| 757 | { |
| 758 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 759 | const ptm6840_interface *intf = get_interface(device); |
| 760 | int i; |
| 796 | 761 | |
| 797 | | WRITE8_HANDLER( ptm6840_0_w ) { ptm6840_write(space->machine, 0, offset, data); } |
| 798 | | WRITE8_HANDLER( ptm6840_1_w ) { ptm6840_write(space->machine, 1, offset, data); } |
| 799 | | WRITE8_HANDLER( ptm6840_2_w ) { ptm6840_write(space->machine, 2, offset, data); } |
| 800 | | WRITE8_HANDLER( ptm6840_3_w ) { ptm6840_write(space->machine, 3, offset, data); } |
| 762 | ptm6840->internal_clock = intf->internal_clock; |
| 801 | 763 | |
| 802 | | READ16_HANDLER( ptm6840_0_msb_r ) { return ptm6840_read(space->machine, 0, offset) << 8; } |
| 803 | | READ16_HANDLER( ptm6840_1_msb_r ) { return ptm6840_read(space->machine, 1, offset) << 8; } |
| 804 | | READ16_HANDLER( ptm6840_2_msb_r ) { return ptm6840_read(space->machine, 2, offset) << 8; } |
| 805 | | READ16_HANDLER( ptm6840_3_msb_r ) { return ptm6840_read(space->machine, 3, offset) << 8; } |
| 764 | /* resolve callbacks */ |
| 765 | for (i = 0; i < 3; i++) |
| 766 | { |
| 767 | devcb_resolve_write8(&ptm6840->out_func[i], &intf->out_func[i], device); |
| 768 | } |
| 806 | 769 | |
| 807 | | WRITE16_HANDLER( ptm6840_0_msb_w ) { if (ACCESSING_BITS_8_15) ptm6840_write(space->machine, 0, offset, data >> 8); } |
| 808 | | WRITE16_HANDLER( ptm6840_1_msb_w ) { if (ACCESSING_BITS_8_15) ptm6840_write(space->machine, 1, offset, data >> 8); } |
| 809 | | WRITE16_HANDLER( ptm6840_2_msb_w ) { if (ACCESSING_BITS_8_15) ptm6840_write(space->machine, 2, offset, data >> 8); } |
| 810 | | WRITE16_HANDLER( ptm6840_3_msb_w ) { if (ACCESSING_BITS_8_15) ptm6840_write(space->machine, 3, offset, data >> 8); } |
| 770 | for (i = 0; i < 3; i++) |
| 771 | { |
| 772 | if ( intf->external_clock[i] ) |
| 773 | ptm6840->external_clock[i] = intf->external_clock[i]; |
| 774 | else |
| 775 | ptm6840->external_clock[i] = 1; |
| 776 | } |
| 811 | 777 | |
| 812 | | READ16_HANDLER( ptm6840_0_lsb_r ) { return ptm6840_read(space->machine, 0, offset); } |
| 813 | | READ16_HANDLER( ptm6840_1_lsb_r ) { return ptm6840_read(space->machine, 1, offset); } |
| 814 | | READ16_HANDLER( ptm6840_2_lsb_r ) { return ptm6840_read(space->machine, 2, offset); } |
| 815 | | READ16_HANDLER( ptm6840_3_lsb_r ) { return ptm6840_read(space->machine, 3, offset); } |
| 816 | 778 | |
| 817 | | WRITE16_HANDLER( ptm6840_0_lsb_w ) { if (ACCESSING_BITS_0_7) ptm6840_write(space->machine, 0, offset, data & 0xff); } |
| 818 | | WRITE16_HANDLER( ptm6840_1_lsb_w ) { if (ACCESSING_BITS_0_7) ptm6840_write(space->machine, 1, offset, data & 0xff); } |
| 819 | | WRITE16_HANDLER( ptm6840_2_lsb_w ) { if (ACCESSING_BITS_0_7) ptm6840_write(space->machine, 2, offset, data & 0xff); } |
| 820 | | WRITE16_HANDLER( ptm6840_3_lsb_w ) { if (ACCESSING_BITS_0_7) ptm6840_write(space->machine, 3, offset, data & 0xff); } |
| 779 | ptm6840->timer[0] = timer_alloc(device->machine, ptm6840_timer1_cb, (void *)device); |
| 780 | ptm6840->timer[1] = timer_alloc(device->machine, ptm6840_timer2_cb, (void *)device); |
| 781 | ptm6840->timer[2] = timer_alloc(device->machine, ptm6840_timer3_cb, (void *)device); |
| 782 | |
| 783 | for (i = 0; i < 3; i++) |
| 784 | { |
| 785 | timer_enable(ptm6840->timer[i], FALSE); |
| 786 | } |
| 787 | |
| 788 | devcb_resolve_write_line(&ptm6840->irq_func, &intf->irq_func, device); |
| 789 | |
| 790 | /* register for state saving */ |
| 791 | state_save_register_device_item(device, 0, ptm6840->lsb_buffer); |
| 792 | state_save_register_device_item(device, 0, ptm6840->msb_buffer); |
| 793 | state_save_register_device_item(device, 0, ptm6840->status_read_since_int); |
| 794 | state_save_register_device_item(device, 0, ptm6840->status_reg); |
| 795 | state_save_register_device_item(device, 0, ptm6840->t3_divisor); |
| 796 | state_save_register_device_item(device, 0, ptm6840->t3_scaler); |
| 797 | state_save_register_device_item(device, 0, ptm6840->internal_clock); |
| 798 | state_save_register_device_item(device, 0, ptm6840->IRQ); |
| 799 | |
| 800 | state_save_register_device_item_array(device, 0, ptm6840->control_reg); |
| 801 | state_save_register_device_item_array(device, 0, ptm6840->output); |
| 802 | state_save_register_device_item_array(device, 0, ptm6840->gate); |
| 803 | state_save_register_device_item_array(device, 0, ptm6840->clock); |
| 804 | state_save_register_device_item_array(device, 0, ptm6840->mode); |
| 805 | state_save_register_device_item_array(device, 0, ptm6840->fired); |
| 806 | state_save_register_device_item_array(device, 0, ptm6840->enabled); |
| 807 | state_save_register_device_item_array(device, 0, ptm6840->external_clock); |
| 808 | state_save_register_device_item_array(device, 0, ptm6840->counter); |
| 809 | state_save_register_device_item_array(device, 0, ptm6840->latch); |
| 810 | } |
| 811 | |
| 812 | /*------------------------------------------------- |
| 813 | DEVICE_RESET( ptm6840 ) |
| 814 | -------------------------------------------------*/ |
| 815 | |
| 816 | static DEVICE_RESET( ptm6840 ) |
| 817 | { |
| 818 | ptm6840_state *ptm6840 = get_safe_token(device); |
| 819 | int i; |
| 820 | |
| 821 | ptm6840->control_reg[2] = 0; |
| 822 | ptm6840->control_reg[1] = 0; |
| 823 | ptm6840->control_reg[0] = 1; |
| 824 | ptm6840->status_reg = 0; |
| 825 | ptm6840->t3_divisor = 1; |
| 826 | ptm6840->status_read_since_int = 0; |
| 827 | ptm6840->IRQ = 0; |
| 828 | |
| 829 | for (i = 0; i < 3; i++) |
| 830 | { |
| 831 | ptm6840->counter[i] = 0xffff; |
| 832 | ptm6840->latch[i] = 0xffff; |
| 833 | ptm6840->output[i] = 0; |
| 834 | ptm6840->fired[i] = 0; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | /*------------------------------------------------- |
| 839 | device definition |
| 840 | -------------------------------------------------*/ |
| 841 | |
| 842 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 843 | |
| 844 | #define DEVTEMPLATE_ID(p,s) p##ptm6840##s |
| 845 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 846 | #define DEVTEMPLATE_NAME "6840 PTM" |
| 847 | #define DEVTEMPLATE_FAMILY "Motorola Programmable Timer Modules" |
| 848 | #define DEVTEMPLATE_CLASS DEVICE_CLASS_PERIPHERAL |
| 849 | #include "devtempl.h" |
src/emu/machine/pd4990a.c
| r4939 | r4940 | |
| 1 | | /* |
| 2 | | * Emulation for the NEC PD4990A. |
| 3 | | * |
| 4 | | * The PD4990A is a serial I/O Calendar & Clock IC used in the |
| 5 | | * NEO GEO and probably a couple of other machines. |
| 1 | /*************************************************************************** |
| 6 | 2 | |
| 3 | NEC uPD4990A |
| 7 | 4 | |
| 8 | | Completed by ElSemi. |
| 5 | Serial I/O Calendar & Clock IC used in the |
| 6 | NEO GEO and probably a couple of other machines. |
| 9 | 7 | |
| 10 | | I haven't found any schematics for this device |
| 11 | | so I had to make some assumptions about how it works. |
| 12 | 8 | |
| 13 | | The three input bits seem to be used for a serial protocol |
| 9 | Completed by ElSemi. |
| 14 | 10 | |
| 11 | I haven't found any schematics for this device |
| 12 | so I had to make some assumptions about how it works. |
| 13 | |
| 14 | The three input bits seem to be used for a serial protocol |
| 15 | |
| 15 | 16 | bit 0 - data |
| 16 | 17 | bit 1 - clock |
| 17 | 18 | bit 2 - command end (?) |
| 18 | 19 | |
| 19 | | the commands I've found so far are: |
| 20 | the commands I've found so far are: |
| 20 | 21 | |
| 21 | | 0x0 - ?? sent after 2 |
| 22 | | 0x1 - Reset the (probable) shift register used for output |
| 23 | | 0x2 - Store the contents of the shift reg to the current date |
| 24 | | 0x3 - Load Shift register with current date |
| 22 | 0x0 - ?? sent after 2 |
| 23 | 0x1 - Reset the (probable) shift register used for output |
| 24 | 0x2 - Store the contents of the shift reg to the current date |
| 25 | 0x3 - Load Shift register with current date |
| 25 | 26 | |
| 26 | | 0x7 - Switch test bit every frame |
| 27 | | 0x8 - Switch test bit every half-second |
| 27 | 0x7 - Switch test bit every frame |
| 28 | 0x8 - Switch test bit every half-second |
| 28 | 29 | |
| 29 | 30 | |
| 31 | 2009-06 Converted to be a device |
| 30 | 32 | |
| 31 | | */ |
| 33 | ***************************************************************************/ |
| 32 | 34 | |
| 33 | 35 | #include "driver.h" |
| 34 | 36 | #include "machine/pd4990a.h" |
| 35 | 37 | |
| 36 | 38 | |
| 37 | | /* Set the data in the chip to Monday 09/09/73 00:00:00 */ |
| 38 | | /* If you ever read this Leejanne, you know what I mean :-) */ |
| 39 | | static const struct pd4990a_s pd4990a_initval = |
| 39 | /*************************************************************************** |
| 40 | CONSTANTS |
| 41 | ***************************************************************************/ |
| 42 | |
| 43 | #define DATA_BIT 0x01 |
| 44 | #define CLOCK_BIT 0x02 |
| 45 | #define END_BIT 0x04 |
| 46 | |
| 47 | /*************************************************************************** |
| 48 | TYPE DEFINITIONS |
| 49 | ***************************************************************************/ |
| 50 | |
| 51 | typedef struct _upd4990a_state upd4990a_state; |
| 52 | struct _upd4990a_state |
| 40 | 53 | { |
| 41 | | 0x00, /* seconds BCD */ |
| 42 | | 0x00, /* minutes BCD */ |
| 43 | | 0x00, /* hours BCD */ |
| 44 | | 0x09, /* days BCD */ |
| 45 | | 9, /* month Hexadecimal form */ |
| 46 | | 0x73, /* year BCD */ |
| 47 | | 1 /* weekday BCD */ |
| 54 | int seconds; /* seconds BCD */ |
| 55 | int minutes; /* minutes BCD */ |
| 56 | int hours; /* hours BCD */ |
| 57 | int days; /* days BCD */ |
| 58 | int month; /* month Hexadecimal form */ |
| 59 | int year; /* year BCD */ |
| 60 | int weekday; /* weekday BCD */ |
| 61 | |
| 62 | UINT32 shiftlo; |
| 63 | UINT32 shifthi; |
| 64 | |
| 65 | int retraces; /* Assumes 60 retraces a second */ |
| 66 | int testwaits; |
| 67 | int maxwaits; /* Switch test every frame*/ |
| 68 | int testbit; /* Pulses a bit in order to simulate test output */ |
| 69 | |
| 70 | int outputbit; |
| 71 | int bitno; |
| 72 | INT8 reading; |
| 73 | INT8 writing; |
| 74 | |
| 75 | int clock_line; |
| 76 | int command_line; //?? |
| 48 | 77 | }; |
| 49 | 78 | |
| 50 | | struct pd4990a_s pd4990a; |
| 51 | 79 | |
| 52 | | static UINT32 shiftlo,shifthi; |
| 53 | 80 | |
| 54 | | static int retraces = 0; /* Assumes 60 retraces a second */ |
| 55 | | static int testwaits= 0; |
| 56 | | static int maxwaits= 0; /*switch test every frame*/ |
| 57 | | static int testbit = 0; /* Pulses a bit in order to simulate */ |
| 58 | | /* test output */ |
| 59 | | static int outputbit=0; |
| 60 | | static int bitno=0; |
| 61 | | static INT8 reading=0; |
| 62 | | static INT8 writting=0; |
| 81 | /*************************************************************************** |
| 82 | INLINE FUNCTIONS |
| 83 | ***************************************************************************/ |
| 63 | 84 | |
| 64 | | static int clock_line=0; |
| 65 | | static int command_line=0; //?? |
| 85 | INLINE upd4990a_state *get_safe_token(const device_config *device) |
| 86 | { |
| 87 | assert(device != NULL); |
| 88 | assert(device->token != NULL); |
| 89 | assert((device->type == UPD4990A)); |
| 90 | return (upd4990a_state *)device->token; |
| 91 | } |
| 66 | 92 | |
| 67 | | #define DATA_BIT 0x1 |
| 68 | | #define CLOCK_BIT 0x2 |
| 69 | | #define END_BIT 0x4 |
| 93 | INLINE UINT8 convert_to_bcd(int val) |
| 94 | { |
| 95 | return ((val / 10) << 4) | (val % 10); |
| 96 | } |
| 70 | 97 | |
| 71 | | void pd4990a_addretrace() |
| 98 | |
| 99 | /*************************************************************************** |
| 100 | IMPLEMENTATION |
| 101 | ***************************************************************************/ |
| 102 | |
| 103 | /*------------------------------------------------- |
| 104 | upd4990a_increment_month |
| 105 | -------------------------------------------------*/ |
| 106 | |
| 107 | void upd4990a_increment_month( const device_config *device ) |
| 72 | 108 | { |
| 73 | | ++testwaits; |
| 74 | | if(testwaits>=maxwaits) |
| 109 | upd4990a_state *upd4990a = get_safe_token(device); |
| 110 | |
| 111 | upd4990a->month++; |
| 112 | if (upd4990a->month == 13) |
| 75 | 113 | { |
| 76 | | testbit ^= 1; |
| 77 | | testwaits=0; |
| 114 | upd4990a->month = 1; |
| 115 | upd4990a->year++; |
| 116 | if ((upd4990a->year & 0x0f) >= 10) |
| 117 | { |
| 118 | upd4990a->year &= 0xf0; |
| 119 | upd4990a->year += 0x10; |
| 120 | } |
| 121 | if (upd4990a->year == 0xA0) |
| 122 | upd4990a->year = 0; |
| 78 | 123 | } |
| 79 | | retraces++; |
| 80 | | if (retraces < 60) |
| 81 | | return; |
| 82 | | retraces = 0; |
| 83 | | pd4990a.seconds++; |
| 84 | | if ( (pd4990a.seconds & 0x0f) < 10 ) |
| 85 | | return; |
| 86 | | pd4990a.seconds &= 0xf0; |
| 87 | | pd4990a.seconds += 0x10; |
| 88 | | if (pd4990a.seconds < 0x60) |
| 89 | | return; |
| 90 | | pd4990a.seconds = 0; |
| 91 | | pd4990a.minutes++; |
| 92 | | if ( (pd4990a.minutes & 0x0f) < 10 ) |
| 93 | | return; |
| 94 | | pd4990a.minutes &= 0xf0; |
| 95 | | pd4990a.minutes += 0x10; |
| 96 | | if (pd4990a.minutes < 0x60) |
| 97 | | return; |
| 98 | | pd4990a.minutes = 0; |
| 99 | | pd4990a.hours++; |
| 100 | | if ( (pd4990a.hours & 0x0f) < 10 ) |
| 101 | | return; |
| 102 | | pd4990a.hours &= 0xf0; |
| 103 | | pd4990a.hours += 0x10; |
| 104 | | if (pd4990a.hours < 0x24) |
| 105 | | return; |
| 106 | | pd4990a.hours = 0; |
| 107 | | pd4990a_increment_day(); |
| 108 | 124 | } |
| 109 | 125 | |
| 110 | | void pd4990a_increment_day(void) |
| 126 | /*------------------------------------------------- |
| 127 | upd4990a_increment_day |
| 128 | -------------------------------------------------*/ |
| 129 | |
| 130 | void upd4990a_increment_day( const device_config *device ) |
| 111 | 131 | { |
| 132 | upd4990a_state *upd4990a = get_safe_token(device); |
| 112 | 133 | int real_year; |
| 113 | 134 | |
| 114 | | pd4990a.days++; |
| 115 | | if ((pd4990a.days & 0x0f) >= 10) |
| 135 | upd4990a->days++; |
| 136 | if ((upd4990a->days & 0x0f) >= 10) |
| 116 | 137 | { |
| 117 | | pd4990a.days &= 0xf0; |
| 118 | | pd4990a.days += 0x10; |
| 138 | upd4990a->days &= 0xf0; |
| 139 | upd4990a->days += 0x10; |
| 119 | 140 | } |
| 120 | 141 | |
| 121 | | pd4990a.weekday++; |
| 122 | | if (pd4990a.weekday == 7) |
| 123 | | pd4990a.weekday=0; |
| 142 | upd4990a->weekday++; |
| 143 | if (upd4990a->weekday == 7) |
| 144 | upd4990a->weekday = 0; |
| 124 | 145 | |
| 125 | | switch(pd4990a.month) |
| 146 | switch (upd4990a->month) |
| 126 | 147 | { |
| 127 | | case 1: case 3: case 5: case 7: case 8: case 10: case 12: |
| 128 | | if (pd4990a.days == 0x32) |
| 129 | | { |
| 130 | | pd4990a.days = 1; |
| 131 | | pd4990a_increment_month(); |
| 132 | | } |
| 133 | | break; |
| 134 | | case 2: |
| 135 | | real_year = (pd4990a.year>>4)*10 + (pd4990a.year&0xf); |
| 136 | | if ((real_year % 4) && (!(real_year % 100) || (real_year % 400))) |
| 137 | | { |
| 138 | | if (pd4990a.days == 0x29) |
| 148 | case 1: case 3: case 5: case 7: case 8: case 10: case 12: |
| 149 | if (upd4990a->days == 0x32) |
| 139 | 150 | { |
| 140 | | pd4990a.days = 1; |
| 141 | | pd4990a_increment_month(); |
| 151 | upd4990a->days = 1; |
| 152 | upd4990a_increment_month(device); |
| 142 | 153 | } |
| 143 | | } |
| 144 | | else |
| 145 | | { |
| 146 | | if (pd4990a.days == 0x30) |
| 154 | break; |
| 155 | case 2: |
| 156 | real_year = (upd4990a->year >> 4) * 10 + (upd4990a->year & 0xf); |
| 157 | if ((real_year % 4) && (!(real_year % 100) || (real_year % 400))) |
| 147 | 158 | { |
| 148 | | pd4990a.days = 1; |
| 149 | | pd4990a_increment_month(); |
| 159 | if (upd4990a->days == 0x29) |
| 160 | { |
| 161 | upd4990a->days = 1; |
| 162 | upd4990a_increment_month(device); |
| 163 | } |
| 150 | 164 | } |
| 151 | | } |
| 152 | | break; |
| 153 | | case 4: case 6: case 9: case 11: |
| 154 | | if (pd4990a.days == 0x31) |
| 155 | | { |
| 156 | | pd4990a.days = 1; |
| 157 | | pd4990a_increment_month(); |
| 158 | | } |
| 159 | | break; |
| 165 | else |
| 166 | { |
| 167 | if (upd4990a->days == 0x30) |
| 168 | { |
| 169 | upd4990a->days = 1; |
| 170 | upd4990a_increment_month(device); |
| 171 | } |
| 172 | } |
| 173 | break; |
| 174 | case 4: case 6: case 9: case 11: |
| 175 | if (upd4990a->days == 0x31) |
| 176 | { |
| 177 | upd4990a->days = 1; |
| 178 | upd4990a_increment_month(device); |
| 179 | } |
| 180 | break; |
| 160 | 181 | } |
| 161 | 182 | } |
| 162 | 183 | |
| 163 | | void pd4990a_increment_month(void) |
| 184 | /*------------------------------------------------- |
| 185 | upd4990a_addretrace |
| 186 | -------------------------------------------------*/ |
| 187 | |
| 188 | void upd4990a_addretrace( const device_config *device ) |
| 164 | 189 | { |
| 165 | | pd4990a.month++; |
| 166 | | if (pd4990a.month == 13) |
| 190 | upd4990a_state *upd4990a = get_safe_token(device); |
| 191 | |
| 192 | ++upd4990a->testwaits; |
| 193 | if(upd4990a->testwaits >= upd4990a->maxwaits) |
| 167 | 194 | { |
| 168 | | pd4990a.month = 1; |
| 169 | | pd4990a.year++; |
| 170 | | if ( (pd4990a.year & 0x0f) >= 10 ) |
| 171 | | { |
| 172 | | pd4990a.year &= 0xf0; |
| 173 | | pd4990a.year += 0x10; |
| 174 | | } |
| 175 | | if (pd4990a.year == 0xA0) |
| 176 | | pd4990a.year = 0; |
| 195 | upd4990a->testbit ^= 1; |
| 196 | upd4990a->testwaits = 0; |
| 177 | 197 | } |
| 198 | |
| 199 | upd4990a->retraces++; |
| 200 | if (upd4990a->retraces < 60) |
| 201 | return; |
| 202 | |
| 203 | upd4990a->retraces = 0; |
| 204 | upd4990a->seconds++; |
| 205 | if ((upd4990a->seconds & 0x0f) < 10) |
| 206 | return; |
| 207 | |
| 208 | upd4990a->seconds &= 0xf0; |
| 209 | upd4990a->seconds += 0x10; |
| 210 | if (upd4990a->seconds < 0x60) |
| 211 | return; |
| 212 | |
| 213 | upd4990a->seconds = 0; |
| 214 | upd4990a->minutes++; |
| 215 | if ((upd4990a->minutes & 0x0f) < 10) |
| 216 | return; |
| 217 | |
| 218 | upd4990a->minutes &= 0xf0; |
| 219 | upd4990a->minutes += 0x10; |
| 220 | if (upd4990a->minutes < 0x60) |
| 221 | return; |
| 222 | |
| 223 | upd4990a->minutes = 0; |
| 224 | upd4990a->hours++; |
| 225 | if ((upd4990a->hours & 0x0f) < 10) |
| 226 | return; |
| 227 | |
| 228 | upd4990a->hours &= 0xf0; |
| 229 | upd4990a->hours += 0x10; |
| 230 | if (upd4990a->hours < 0x24) |
| 231 | return; |
| 232 | |
| 233 | upd4990a->hours = 0; |
| 234 | upd4990a_increment_day(device); |
| 178 | 235 | } |
| 179 | 236 | |
| 180 | | READ8_HANDLER( pd4990a_testbit_r ) |
| 237 | /*------------------------------------------------- |
| 238 | upd4990a_testbit_r |
| 239 | -------------------------------------------------*/ |
| 240 | |
| 241 | READ8_DEVICE_HANDLER( upd4990a_testbit_r ) |
| 181 | 242 | { |
| 182 | | return (testbit); |
| 243 | upd4990a_state *upd4990a = get_safe_token(device); |
| 244 | return upd4990a->testbit; |
| 183 | 245 | } |
| 184 | 246 | |
| 185 | | READ8_HANDLER( pd4990a_databit_r ) |
| 247 | /*------------------------------------------------- |
| 248 | upd4990a_databit_r |
| 249 | -------------------------------------------------*/ |
| 250 | |
| 251 | READ8_DEVICE_HANDLER( upd4990a_databit_r ) |
| 186 | 252 | { |
| 187 | | return (outputbit); |
| 253 | upd4990a_state *upd4990a = get_safe_token(device); |
| 254 | return upd4990a->outputbit; |
| 188 | 255 | } |
| 189 | 256 | |
| 190 | | static void pd4990a_readbit(void) |
| 257 | /*------------------------------------------------- |
| 258 | upd4990a_readbit |
| 259 | -------------------------------------------------*/ |
| 260 | |
| 261 | static void upd4990a_readbit( const device_config *device ) |
| 191 | 262 | { |
| 192 | | switch(bitno) |
| 263 | upd4990a_state *upd4990a = get_safe_token(device); |
| 264 | |
| 265 | switch (upd4990a->bitno) |
| 193 | 266 | { |
| 194 | 267 | case 0x00: case 0x01: case 0x02: case 0x03: |
| 195 | 268 | case 0x04: case 0x05: case 0x06: case 0x07: |
| 196 | | outputbit=(pd4990a.seconds >> bitno) & 0x01; |
| 269 | upd4990a->outputbit = (upd4990a->seconds >> upd4990a->bitno) & 0x01; |
| 197 | 270 | break; |
| 198 | 271 | case 0x08: case 0x09: case 0x0a: case 0x0b: |
| 199 | 272 | case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 200 | | outputbit=(pd4990a.minutes >> (bitno-0x08)) & 0x01; |
| 273 | upd4990a->outputbit = (upd4990a->minutes >> (upd4990a->bitno - 0x08)) & 0x01; |
| 201 | 274 | break; |
| 202 | 275 | case 0x10: case 0x11: case 0x12: case 0x13: |
| 203 | 276 | case 0x14: case 0x15: case 0x16: case 0x17: |
| 204 | | outputbit=(pd4990a.hours >> (bitno-0x10)) & 0x01; |
| 277 | upd4990a->outputbit = (upd4990a->hours >> (upd4990a->bitno - 0x10)) & 0x01; |
| 205 | 278 | break; |
| 206 | 279 | case 0x18: case 0x19: case 0x1a: case 0x1b: |
| 207 | 280 | case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 208 | | outputbit=(pd4990a.days >> (bitno-0x18)) & 0x01; |
| 281 | upd4990a->outputbit = (upd4990a->days >> (upd4990a->bitno - 0x18)) & 0x01; |
| 209 | 282 | break; |
| 210 | 283 | case 0x20: case 0x21: case 0x22: case 0x23: |
| 211 | | outputbit=(pd4990a.weekday >> (bitno-0x20)) & 0x01; |
| 284 | upd4990a->outputbit = (upd4990a->weekday >> (upd4990a->bitno - 0x20)) & 0x01; |
| 212 | 285 | break; |
| 213 | 286 | case 0x24: case 0x25: case 0x26: case 0x27: |
| 214 | | outputbit=(pd4990a.month >> (bitno-0x24)) & 0x01; |
| 287 | upd4990a->outputbit = (upd4990a->month >> (upd4990a->bitno - 0x24)) & 0x01; |
| 215 | 288 | break; |
| 216 | 289 | case 0x28: case 0x29: case 0x2a: case 0x2b: |
| 217 | 290 | case 0x2c: case 0x2d: case 0x2e: case 0x2f: |
| 218 | | outputbit=(pd4990a.year >> (bitno-0x28)) & 0x01; |
| 291 | upd4990a->outputbit = (upd4990a->year >> (upd4990a->bitno - 0x28)) & 0x01; |
| 219 | 292 | break; |
| 220 | 293 | case 0x30: case 0x31: case 0x32: case 0x33: |
| 221 | 294 | //unknown |
| r4939 | r4940 | |
| 223 | 296 | } |
| 224 | 297 | } |
| 225 | 298 | |
| 299 | /*------------------------------------------------- |
| 300 | upd4990a_resetbitstream |
| 301 | -------------------------------------------------*/ |
| 226 | 302 | |
| 303 | static void upd4990a_resetbitstream( const device_config *device ) |
| 304 | { |
| 305 | upd4990a_state *upd4990a = get_safe_token(device); |
| 227 | 306 | |
| 228 | | |
| 229 | | static void pd4990a_resetbitstream(void) |
| 230 | | { |
| 231 | | shiftlo=0; |
| 232 | | shifthi=0; |
| 233 | | bitno=0; |
| 307 | upd4990a->shiftlo = 0; |
| 308 | upd4990a->shifthi = 0; |
| 309 | upd4990a->bitno = 0; |
| 234 | 310 | } |
| 235 | 311 | |
| 236 | | static void pd4990a_writebit(UINT8 bit) |
| 312 | /*------------------------------------------------- |
| 313 | upd4990a_writebit |
| 314 | -------------------------------------------------*/ |
| 315 | |
| 316 | static void upd4990a_writebit( const device_config *device , UINT8 bit ) |
| 237 | 317 | { |
| 238 | | if(bitno<=31) //low part |
| 239 | | shiftlo|=bit<<bitno; |
| 318 | upd4990a_state *upd4990a = get_safe_token(device); |
| 319 | if (upd4990a->bitno <= 31) //low part |
| 320 | upd4990a->shiftlo |= bit << upd4990a->bitno; |
| 240 | 321 | else //high part |
| 241 | | shifthi|=bit<<(bitno-32); |
| 322 | upd4990a->shifthi |= bit << (upd4990a->bitno - 32); |
| 242 | 323 | } |
| 243 | 324 | |
| 244 | | static void pd4990a_nextbit(void) |
| 325 | /*------------------------------------------------- |
| 326 | upd4990a_nextbit |
| 327 | -------------------------------------------------*/ |
| 328 | |
| 329 | static void upd4990a_nextbit( const device_config *device ) |
| 245 | 330 | { |
| 246 | | ++bitno; |
| 247 | | if(reading) |
| 248 | | pd4990a_readbit(); |
| 249 | | if(reading && bitno==0x34) |
| 331 | upd4990a_state *upd4990a = get_safe_token(device); |
| 332 | ++upd4990a->bitno; |
| 333 | |
| 334 | if (upd4990a->reading) |
| 335 | upd4990a_readbit(device); |
| 336 | |
| 337 | if (upd4990a->reading && upd4990a->bitno == 0x34) |
| 250 | 338 | { |
| 251 | | reading=0; |
| 252 | | pd4990a_resetbitstream(); |
| 339 | upd4990a->reading = 0; |
| 340 | upd4990a_resetbitstream(device); |
| 253 | 341 | } |
| 254 | 342 | |
| 255 | 343 | } |
| 256 | 344 | |
| 257 | | static UINT8 pd4990a_getcommand(void) |
| 345 | /*------------------------------------------------- |
| 346 | upd4990a_getcommand |
| 347 | -------------------------------------------------*/ |
| 348 | |
| 349 | static UINT8 upd4990a_getcommand( const device_config *device ) |
| 258 | 350 | { |
| 351 | upd4990a_state *upd4990a = get_safe_token(device); |
| 259 | 352 | //Warning: problems if the 4 bits are in different |
| 260 | 353 | //parts, It's very strange that this case could happen. |
| 261 | | if(bitno<=31) |
| 262 | | return shiftlo>>(bitno-4); |
| 354 | if(upd4990a->bitno <= 31) |
| 355 | return upd4990a->shiftlo >> (upd4990a->bitno - 4); |
| 263 | 356 | else |
| 264 | | return shifthi>>(bitno-32-4); |
| 357 | return upd4990a->shifthi >> (upd4990a->bitno - 32 - 4); |
| 265 | 358 | } |
| 266 | 359 | |
| 267 | | static void pd4990a_update_date(void) |
| 360 | /*------------------------------------------------- |
| 361 | upd4990a_update_date |
| 362 | -------------------------------------------------*/ |
| 363 | |
| 364 | static void upd4990a_update_date( const device_config *device ) |
| 268 | 365 | { |
| 269 | | pd4990a.seconds=(shiftlo>>0 )&0xff; |
| 270 | | pd4990a.minutes=(shiftlo>>8 )&0xff; |
| 271 | | pd4990a.hours =(shiftlo>>16)&0xff; |
| 272 | | pd4990a.days =(shiftlo>>24)&0xff; |
| 273 | | pd4990a.weekday=(shifthi>>0 )&0x0f; |
| 274 | | pd4990a.month =(shifthi>>4 )&0x0f; |
| 275 | | pd4990a.year =(shifthi>>8 )&0xff; |
| 366 | upd4990a_state *upd4990a = get_safe_token(device); |
| 367 | |
| 368 | upd4990a->seconds = (upd4990a->shiftlo >> 0 ) & 0xff; |
| 369 | upd4990a->minutes = (upd4990a->shiftlo >> 8 ) & 0xff; |
| 370 | upd4990a->hours = (upd4990a->shiftlo >> 16) & 0xff; |
| 371 | upd4990a->days = (upd4990a->shiftlo >> 24) & 0xff; |
| 372 | upd4990a->weekday = (upd4990a->shifthi >> 0 ) & 0x0f; |
| 373 | upd4990a->month = (upd4990a->shifthi >> 4 ) & 0x0f; |
| 374 | upd4990a->year = (upd4990a->shifthi >> 8 ) & 0xff; |
| 276 | 375 | } |
| 277 | 376 | |
| 278 | | static void pd4990a_process_command(void) |
| 377 | /*------------------------------------------------- |
| 378 | upd4990a_process_command |
| 379 | -------------------------------------------------*/ |
| 380 | |
| 381 | static void upd4990a_process_command( const device_config *device ) |
| 279 | 382 | { |
| 280 | | switch(pd4990a_getcommand()) |
| 383 | upd4990a_state *upd4990a = get_safe_token(device); |
| 384 | |
| 385 | switch(upd4990a_getcommand(device)) |
| 281 | 386 | { |
| 282 | 387 | case 0x1: //load output register |
| 283 | | bitno=0; |
| 284 | | if(reading) |
| 285 | | pd4990a_readbit(); //prepare first bit |
| 286 | | shiftlo=0; |
| 287 | | shifthi=0; |
| 388 | upd4990a->bitno = 0; |
| 389 | if (upd4990a->reading) |
| 390 | upd4990a_readbit(device); //prepare first bit |
| 391 | upd4990a->shiftlo = 0; |
| 392 | upd4990a->shifthi = 0; |
| 288 | 393 | break; |
| 289 | 394 | case 0x2: |
| 290 | | writting=0; //store register to current date |
| 291 | | pd4990a_update_date(); |
| 395 | upd4990a->writing = 0; //store register to current date |
| 396 | upd4990a_update_date(device); |
| 292 | 397 | break; |
| 293 | 398 | case 0x3: //start reading |
| 294 | | reading=1; |
| 399 | upd4990a->reading = 1; |
| 295 | 400 | break; |
| 296 | 401 | case 0x7: //switch testbit every frame |
| 297 | | maxwaits=1; |
| 402 | upd4990a->maxwaits = 1; |
| 298 | 403 | break; |
| 299 | 404 | case 0x8: //switch testbit every half-second |
| 300 | | maxwaits=30; |
| 405 | upd4990a->maxwaits = 30; |
| 301 | 406 | break; |
| 302 | 407 | } |
| 303 | | pd4990a_resetbitstream(); |
| 408 | upd4990a_resetbitstream(device); |
| 304 | 409 | } |
| 305 | 410 | |
| 411 | /*------------------------------------------------- |
| 412 | upd4990a_serial_control |
| 413 | -------------------------------------------------*/ |
| 306 | 414 | |
| 307 | | static void pd4990a_serial_control(UINT8 data) |
| 415 | static void upd4990a_serial_control( const device_config *device, UINT8 data ) |
| 308 | 416 | { |
| 417 | upd4990a_state *upd4990a = get_safe_token(device); |
| 418 | |
| 309 | 419 | //Check for command end |
| 310 | | if(command_line && !(data&END_BIT)) //end of command |
| 420 | if(upd4990a->command_line && !(data & END_BIT)) //end of command |
| 311 | 421 | { |
| 312 | | pd4990a_process_command(); |
| 422 | upd4990a_process_command(device); |
| 313 | 423 | } |
| 314 | | command_line=data&END_BIT; |
| 424 | upd4990a->command_line = data & END_BIT; |
| 315 | 425 | |
| 316 | | if(clock_line && !(data&CLOCK_BIT)) //clock lower edge |
| 426 | if(upd4990a->clock_line && !(data & CLOCK_BIT)) //clock lower edge |
| 317 | 427 | { |
| 318 | | pd4990a_writebit(data&DATA_BIT); |
| 319 | | pd4990a_nextbit(); |
| 428 | upd4990a_writebit(device, data & DATA_BIT); |
| 429 | upd4990a_nextbit(device); |
| 320 | 430 | } |
| 321 | | clock_line=data&CLOCK_BIT; |
| 431 | upd4990a->clock_line = data & CLOCK_BIT; |
| 322 | 432 | } |
| 323 | 433 | |
| 324 | | WRITE16_HANDLER( pd4990a_control_16_w ) |
| 434 | /*------------------------------------------------- |
| 435 | upd4990a_control_16_w |
| 436 | -------------------------------------------------*/ |
| 437 | |
| 438 | WRITE16_DEVICE_HANDLER( upd4990a_control_16_w ) |
| 325 | 439 | { |
| 326 | | pd4990a_serial_control(data&0x7); |
| 440 | upd4990a_serial_control(device, data & 0x7); |
| 327 | 441 | } |
| 328 | 442 | |
| 329 | | void pd4990a_init(running_machine *machine) |
| 443 | |
| 444 | /*------------------------------------------------- |
| 445 | DEVICE_START( upd4990a ) |
| 446 | -------------------------------------------------*/ |
| 447 | |
| 448 | static DEVICE_START( upd4990a ) |
| 330 | 449 | { |
| 331 | | pd4990a = pd4990a_initval; |
| 332 | | shiftlo = 0; |
| 333 | | shifthi = 0; |
| 334 | | retraces = 0; |
| 335 | | testwaits = 0; |
| 336 | | maxwaits = 1; |
| 337 | | testbit = 0; |
| 338 | | outputbit = 0; |
| 339 | | bitno = 0; |
| 340 | | reading = 0; |
| 341 | | writting = 0; |
| 342 | | clock_line = 0; |
| 343 | | command_line =0; |
| 450 | upd4990a_state *upd4990a = get_safe_token(device); |
| 344 | 451 | |
| 345 | | state_save_register_item(machine, "pd4990a", NULL, 0, pd4990a.seconds); |
| 346 | | state_save_register_item(machine, "pd4990a", NULL, 0, pd4990a.minutes); |
| 347 | | state_save_register_item(machine, "pd4990a", NULL, 0, pd4990a.hours); |
| 348 | | state_save_register_item(machine, "pd4990a", NULL, 0, pd4990a.days); |
| 349 | | state_save_register_item(machine, "pd4990a", NULL, 0, pd4990a.month); |
| 350 | | state_save_register_item(machine, "pd4990a", NULL, 0, pd4990a.year); |
| 351 | | state_save_register_item(machine, "pd4990a", NULL, 0, pd4990a.weekday); |
| 452 | mame_system_time curtime, *systime = &curtime; |
| 453 | mame_get_current_datetime(device->machine, &curtime); |
| 352 | 454 | |
| 353 | | state_save_register_item(machine, "pd4990a", NULL, 0, shiftlo); |
| 354 | | state_save_register_item(machine, "pd4990a", NULL, 0, shifthi); |
| 455 | #if 0 |
| 456 | upd4990a->seconds = 0x00; |
| 457 | upd4990a->minutes = 0x00; |
| 458 | upd4990a->hours = 0x00; |
| 459 | upd4990a->days = 0x09; |
| 460 | upd4990a->month = 9; |
| 461 | upd4990a->year = 0x73; |
| 462 | upd4990a->weekday = 1; |
| 463 | #endif |
| 464 | /* HACK: load time counter from system time */ |
| 465 | upd4990a->seconds = convert_to_bcd(systime->local_time.second); |
| 466 | upd4990a->minutes = convert_to_bcd(systime->local_time.minute); |
| 467 | upd4990a->hours = convert_to_bcd(systime->local_time.hour); |
| 468 | upd4990a->days = convert_to_bcd(systime->local_time.mday); |
| 469 | upd4990a->month = systime->local_time.month + 1; |
| 470 | upd4990a->year = ((((systime->local_time.year - 1900) % 100) / 10) << 4) | ((systime->local_time.year - 1900) % 10); |
| 471 | upd4990a->weekday = systime->local_time.weekday; |
| 355 | 472 | |
| 356 | | state_save_register_item(machine, "pd4990a", NULL, 0, retraces); |
| 357 | | state_save_register_item(machine, "pd4990a", NULL, 0, testwaits); |
| 358 | | state_save_register_item(machine, "pd4990a", NULL, 0, maxwaits); |
| 359 | | state_save_register_item(machine, "pd4990a", NULL, 0, testbit); |
| 473 | /* register for state saving */ |
| 474 | state_save_register_device_item(device, 0, upd4990a->seconds); |
| 475 | state_save_register_device_item(device, 0, upd4990a->minutes); |
| 476 | state_save_register_device_item(device, 0, upd4990a->hours); |
| 477 | state_save_register_device_item(device, 0, upd4990a->days); |
| 478 | state_save_register_device_item(device, 0, upd4990a->month); |
| 479 | state_save_register_device_item(device, 0, upd4990a->year); |
| 480 | state_save_register_device_item(device, 0, upd4990a->weekday); |
| 360 | 481 | |
| 361 | | state_save_register_item(machine, "pd4990a", NULL, 0, outputbit); |
| 362 | | state_save_register_item(machine, "pd4990a", NULL, 0, bitno); |
| 363 | | state_save_register_item(machine, "pd4990a", NULL, 0, reading); |
| 364 | | state_save_register_item(machine, "pd4990a", NULL, 0, writting); |
| 482 | state_save_register_device_item(device, 0, upd4990a->shiftlo); |
| 483 | state_save_register_device_item(device, 0, upd4990a->shifthi); |
| 365 | 484 | |
| 366 | | state_save_register_item(machine, "pd4990a", NULL, 0, clock_line); |
| 367 | | state_save_register_item(machine, "pd4990a", NULL, 0, command_line); |
| 485 | state_save_register_device_item(device, 0, upd4990a->retraces); |
| 486 | state_save_register_device_item(device, 0, upd4990a->testwaits); |
| 487 | state_save_register_device_item(device, 0, upd4990a->maxwaits); |
| 488 | state_save_register_device_item(device, 0, upd4990a->testbit); |
| 489 | |
| 490 | state_save_register_device_item(device, 0, upd4990a->outputbit); |
| 491 | state_save_register_device_item(device, 0, upd4990a->bitno); |
| 492 | state_save_register_device_item(device, 0, upd4990a->reading); |
| 493 | state_save_register_device_item(device, 0, upd4990a->writing); |
| 494 | |
| 495 | state_save_register_device_item(device, 0, upd4990a->clock_line); |
| 496 | state_save_register_device_item(device, 0, upd4990a->command_line); |
| 368 | 497 | } |
| 498 | |
| 499 | |
| 500 | /*------------------------------------------------- |
| 501 | DEVICE_RESET( upd4990a ) |
| 502 | -------------------------------------------------*/ |
| 503 | |
| 504 | static DEVICE_RESET( upd4990a ) |
| 505 | { |
| 506 | upd4990a_state *upd4990a = get_safe_token(device); |
| 507 | |
| 508 | upd4990a->shiftlo = 0; |
| 509 | upd4990a->shifthi = 0; |
| 510 | |
| 511 | upd4990a->retraces = 0; |
| 512 | upd4990a->testwaits = 0; |
| 513 | upd4990a->maxwaits = 1; |
| 514 | upd4990a->testbit = 0; |
| 515 | |
| 516 | upd4990a->outputbit = 0; |
| 517 | upd4990a->bitno = 0; |
| 518 | upd4990a->reading = 0; |
| 519 | upd4990a->writing = 0; |
| 520 | |
| 521 | upd4990a->clock_line = 0; |
| 522 | upd4990a->command_line = 0; |
| 523 | } |
| 524 | |
| 525 | /*------------------------------------------------- |
| 526 | device definition |
| 527 | -------------------------------------------------*/ |
| 528 | |
| 529 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 530 | |
| 531 | #define DEVTEMPLATE_ID(p,s) p##upd4990a##s |
| 532 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 533 | #define DEVTEMPLATE_NAME "NEC uPD4990A" |
| 534 | #define DEVTEMPLATE_FAMILY "NEC uPD4990A Calendar & Clock" |
| 535 | #define DEVTEMPLATE_CLASS DEVICE_CLASS_PERIPHERAL |
| 536 | #include "devtempl.h" |
src/emu/machine/rp5h01.c
| r4939 | r4940 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | RP5H01 |
| 4 | |
| 5 | |
| 6 | 2009-06 Converted to be a device |
| 7 | |
| 8 | ***************************************************************************/ |
| 9 | |
| 1 | 10 | #include "driver.h" |
| 2 | 11 | #include "machine/rp5h01.h" |
| 3 | 12 | |
| 4 | | /****************************************************************************/ |
| 5 | 13 | |
| 6 | | /* local copy of the interface pointer */ |
| 7 | | static const struct RP5H01_interface *intf; |
| 14 | /*************************************************************************** |
| 15 | PARAMETERS |
| 16 | ***************************************************************************/ |
| 8 | 17 | |
| 9 | 18 | /* these also work as the address masks */ |
| 10 | 19 | enum { |
| r4939 | r4940 | |
| 12 | 21 | COUNTER_MODE_7_BITS = 0x7f |
| 13 | 22 | }; |
| 14 | 23 | |
| 15 | | typedef struct _RP5H01 { |
| 24 | |
| 25 | /*************************************************************************** |
| 26 | TYPE DEFINITIONS |
| 27 | ***************************************************************************/ |
| 28 | |
| 29 | typedef struct _rp5h01_state rp5h01_state; |
| 30 | struct _rp5h01_state |
| 31 | { |
| 16 | 32 | int counter; |
| 17 | 33 | int counter_mode; /* test pin */ |
| 18 | 34 | int enabled; /* chip enable */ |
| 19 | 35 | int old_reset; /* reset pin state (level-triggered) */ |
| 20 | 36 | int old_clock; /* clock pin state (level-triggered) */ |
| 21 | 37 | UINT8 *data; |
| 22 | | } RP5H01; |
| 38 | }; |
| 23 | 39 | |
| 24 | | static RP5H01 RP5H01_state[MAX_RP5H01]; |
| 40 | /*************************************************************************** |
| 41 | INLINE FUNCTIONS |
| 42 | ***************************************************************************/ |
| 25 | 43 | |
| 26 | | /****************************************************************************/ |
| 44 | INLINE rp5h01_state *get_safe_token(const device_config *device) |
| 45 | { |
| 46 | assert(device != NULL); |
| 47 | assert(device->token != NULL); |
| 48 | assert((device->type == RP5H01)); |
| 49 | return (rp5h01_state *)device->token; |
| 50 | } |
| 27 | 51 | |
| 28 | | int RP5H01_init( running_machine *machine, const struct RP5H01_interface *interface ) { |
| 29 | | int i; |
| 30 | | |
| 31 | | /* setup our local copy of the interface */ |
| 32 | | intf = interface; |
| 33 | | |
| 34 | | if ( intf->num > MAX_RP5H01 ) { |
| 35 | | logerror( "Requested number of RP5H01's is bigger than the supported amount\n" ); |
| 36 | | return -1; |
| 37 | | } |
| 38 | | |
| 39 | | /* initialize the state */ |
| 40 | | for( i = 0; i < intf->num; i++ ) { |
| 41 | | RP5H01_state[i].counter = 0; |
| 42 | | RP5H01_state[i].counter_mode = COUNTER_MODE_6_BITS; |
| 43 | | RP5H01_state[i].data = &( memory_region( machine, intf->region[i] )[ intf->offset[i] ] ); |
| 44 | | RP5H01_state[i].enabled = 0; |
| 45 | | RP5H01_state[i].old_reset = -1; |
| 46 | | RP5H01_state[i].old_clock = -1; |
| 47 | | } |
| 48 | | |
| 49 | | return 0; |
| 52 | INLINE const rp5h01_interface *get_interface(const device_config *device) |
| 53 | { |
| 54 | assert(device != NULL); |
| 55 | assert((device->type == RP5H01)); |
| 56 | return (const rp5h01_interface *) device->static_config; |
| 50 | 57 | } |
| 51 | 58 | |
| 52 | | /****************************************************************************/ |
| 59 | /*************************************************************************** |
| 60 | IMPLEMENTATION |
| 61 | ***************************************************************************/ |
| 53 | 62 | |
| 54 | | void RP5H01_enable_w( int which, int data ) { |
| 55 | | RP5H01 *chip; |
| 63 | /*------------------------------------------------- |
| 64 | rp5h01_enable_w |
| 65 | -------------------------------------------------*/ |
| 56 | 66 | |
| 57 | | if ( which >= intf->num ) { |
| 58 | | logerror( "RP5H01_enable: trying to access an unmapped chip\n" ); |
| 59 | | return; |
| 60 | | } |
| 67 | WRITE8_DEVICE_HANDLER( rp5h01_enable_w ) |
| 68 | { |
| 69 | rp5h01_state *rp5h01 = get_safe_token(device); |
| 61 | 70 | |
| 62 | | /* get the chip */ |
| 63 | | chip = &RP5H01_state[which]; |
| 64 | | |
| 65 | 71 | /* process the /CE signal and enable/disable the IC */ |
| 66 | | chip->enabled = ( data == 0 ) ? 1 : 0; |
| 72 | rp5h01->enabled = (data == 0) ? 1 : 0; |
| 67 | 73 | } |
| 68 | 74 | |
| 69 | | void RP5H01_reset_w( int which, int data ) { |
| 70 | | RP5H01 *chip; |
| 71 | | int newstate = ( data == 0 ) ? 0 : 1; |
| 75 | /*------------------------------------------------- |
| 76 | rp5h01_reset_w |
| 77 | -------------------------------------------------*/ |
| 72 | 78 | |
| 73 | | if ( which >= intf->num ) { |
| 74 | | logerror( "RP5H01_enable: trying to access an unmapped chip\n" ); |
| 75 | | return; |
| 76 | | } |
| 79 | WRITE8_DEVICE_HANDLER( rp5h01_reset_w ) |
| 80 | { |
| 81 | rp5h01_state *rp5h01 = get_safe_token(device); |
| 82 | int newstate = (data == 0) ? 0 : 1; |
| 77 | 83 | |
| 78 | | /* get the chip */ |
| 79 | | chip = &RP5H01_state[which]; |
| 80 | | |
| 81 | 84 | /* if it's not enabled, ignore */ |
| 82 | | if ( !chip->enabled ) |
| 85 | if (!rp5h01->enabled) |
| 83 | 86 | return; |
| 84 | 87 | |
| 85 | 88 | /* now look for a 0->1 transition */ |
| 86 | | if ( chip->old_reset == 0 && newstate == 1 ) { |
| 89 | if (rp5h01->old_reset == 0 && newstate == 1) |
| 90 | { |
| 87 | 91 | /* reset the counter */ |
| 88 | | chip->counter = 0; |
| 92 | rp5h01->counter = 0; |
| 89 | 93 | } |
| 90 | 94 | |
| 91 | 95 | /* update the pin */ |
| 92 | | chip->old_reset = newstate; |
| 96 | rp5h01->old_reset = newstate; |
| 93 | 97 | } |
| 94 | 98 | |
| 95 | | void RP5H01_clock_w( int which, int data ) { |
| 96 | | RP5H01 *chip; |
| 97 | | int newstate = ( data == 0 ) ? 0 : 1; |
| 99 | /*------------------------------------------------- |
| 100 | rp5h01_clock_w |
| 101 | -------------------------------------------------*/ |
| 98 | 102 | |
| 99 | | if ( which >= intf->num ) { |
| 100 | | logerror( "RP5H01_enable: trying to access an unmapped chip\n" ); |
| 101 | | return; |
| 102 | | } |
| 103 | WRITE8_DEVICE_HANDLER( rp5h01_clock_w ) |
| 104 | { |
| 105 | rp5h01_state *rp5h01 = get_safe_token(device); |
| 106 | int newstate = (data == 0) ? 0 : 1; |
| 103 | 107 | |
| 104 | | /* get the chip */ |
| 105 | | chip = &RP5H01_state[which]; |
| 106 | | |
| 107 | 108 | /* if it's not enabled, ignore */ |
| 108 | | if ( !chip->enabled ) |
| 109 | if (!rp5h01->enabled) |
| 109 | 110 | return; |
| 110 | 111 | |
| 111 | 112 | /* now look for a 1->0 transition */ |
| 112 | | if ( chip->old_clock == 1 && newstate == 0 ) { |
| 113 | if (rp5h01->old_clock == 1 && newstate == 0) |
| 114 | { |
| 113 | 115 | /* increment the counter, and mask it with the mode */ |
| 114 | | chip->counter++; |
| 116 | rp5h01->counter++; |
| 115 | 117 | } |
| 116 | 118 | |
| 117 | 119 | /* update the pin */ |
| 118 | | chip->old_clock = newstate; |
| 120 | rp5h01->old_clock = newstate; |
| 119 | 121 | } |
| 120 | 122 | |
| 121 | | void RP5H01_test_w( int which, int data ) { |
| 122 | | RP5H01 *chip; |
| 123 | /*------------------------------------------------- |
| 124 | rp5h01_test_w |
| 125 | -------------------------------------------------*/ |
| 123 | 126 | |
| 124 | | if ( which >= intf->num ) { |
| 125 | | logerror( "RP5H01_enable: trying to access an unmapped chip\n" ); |
| 126 | | return; |
| 127 | | } |
| 127 | WRITE8_DEVICE_HANDLER( rp5h01_test_w ) |
| 128 | { |
| 129 | rp5h01_state *rp5h01 = get_safe_token(device); |
| 128 | 130 | |
| 129 | | /* get the chip */ |
| 130 | | chip = &RP5H01_state[which]; |
| 131 | | |
| 132 | 131 | /* if it's not enabled, ignore */ |
| 133 | | if ( !chip->enabled ) |
| 132 | if (!rp5h01->enabled) |
| 134 | 133 | return; |
| 135 | 134 | |
| 136 | 135 | /* process the test signal and change the counter mode */ |
| 137 | | chip->counter_mode = ( data == 0 ) ? COUNTER_MODE_6_BITS : COUNTER_MODE_7_BITS; |
| 136 | rp5h01->counter_mode = (data == 0) ? COUNTER_MODE_6_BITS : COUNTER_MODE_7_BITS; |
| 138 | 137 | } |
| 139 | 138 | |
| 140 | | int RP5H01_counter_r( int which ) { |
| 141 | | RP5H01 *chip; |
| 139 | /*------------------------------------------------- |
| 140 | rp5h01_counter_r |
| 141 | -------------------------------------------------*/ |
| 142 | 142 | |
| 143 | | if ( which >= intf->num ) { |
| 144 | | logerror( "RP5H01_enable: trying to access an unmapped chip\n" ); |
| 145 | | return 0; |
| 146 | | } |
| 143 | READ8_DEVICE_HANDLER( rp5h01_counter_r ) |
| 144 | { |
| 145 | rp5h01_state *rp5h01 = get_safe_token(device); |
| 147 | 146 | |
| 148 | | /* get the chip */ |
| 149 | | chip = &RP5H01_state[which]; |
| 150 | | |
| 151 | 147 | /* if it's not enabled, ignore */ |
| 152 | | if ( !chip->enabled ) |
| 148 | if (!rp5h01->enabled) |
| 153 | 149 | return 0; /* ? (should be high impedance) */ |
| 154 | 150 | |
| 155 | 151 | /* return A5 */ |
| 156 | | return ( chip->counter >> 5 ) & 1; |
| 152 | return (rp5h01->counter >> 5) & 1; |
| 157 | 153 | } |
| 158 | 154 | |
| 159 | | int RP5H01_data_r( int which ) { |
| 160 | | RP5H01 *chip; |
| 161 | | int byte, bit; |
| 155 | /*------------------------------------------------- |
| 156 | rp5h01_data_r |
| 157 | -------------------------------------------------*/ |
| 162 | 158 | |
| 163 | | if ( which >= intf->num ) { |
| 164 | | logerror( "RP5H01_enable: trying to access an unmapped chip\n" ); |
| 165 | | return 0; |
| 166 | | } |
| 159 | READ8_DEVICE_HANDLER( rp5h01_data_r ) |
| 160 | { |
| 161 | rp5h01_state *rp5h01 = get_safe_token(device); |
| 162 | int byte, bit; |
| 167 | 163 | |
| 168 | | /* get the chip */ |
| 169 | | chip = &RP5H01_state[which]; |
| 170 | | |
| 171 | 164 | /* if it's not enabled, ignore */ |
| 172 | | if ( !chip->enabled ) |
| 165 | if (!rp5h01->enabled) |
| 173 | 166 | return 0; /* ? (should be high impedance) */ |
| 174 | 167 | |
| 175 | 168 | /* get the byte offset and bit offset */ |
| 176 | | byte = ( chip->counter & chip->counter_mode) >> 3; |
| 177 | | bit = 7 - ( chip->counter & 7 ); |
| 169 | byte = (rp5h01->counter & rp5h01->counter_mode) >> 3; |
| 170 | bit = 7 - (rp5h01->counter & 7); |
| 178 | 171 | |
| 179 | 172 | /* return the data */ |
| 180 | | return ( chip->data[byte] >> bit ) & 1; |
| 173 | return (rp5h01->data[byte] >> bit) & 1; |
| 181 | 174 | } |
| 182 | 175 | |
| 183 | | /****************************************************************************/ |
| 176 | /*------------------------------------------------- |
| 177 | DEVICE_START( rp5h01 ) |
| 178 | -------------------------------------------------*/ |
| 184 | 179 | |
| 185 | | WRITE8_HANDLER( RP5H01_0_enable_w ) { |
| 186 | | RP5H01_enable_w( 0, data ); |
| 187 | | } |
| 180 | static DEVICE_START( rp5h01 ) |
| 181 | { |
| 182 | rp5h01_state *rp5h01 = get_safe_token(device); |
| 183 | const rp5h01_interface *intf = get_interface(device); |
| 188 | 184 | |
| 189 | | WRITE8_HANDLER( RP5H01_0_reset_w ) { |
| 190 | | RP5H01_reset_w( 0, data ); |
| 191 | | } |
| 185 | rp5h01->data = &(memory_region(device->machine, intf->region)[intf->offset]); |
| 192 | 186 | |
| 193 | | WRITE8_HANDLER( RP5H01_0_clock_w ) { |
| 194 | | RP5H01_clock_w( 0, data ); |
| 187 | /* register for state saving */ |
| 188 | state_save_register_device_item(device, 0, rp5h01->counter); |
| 189 | state_save_register_device_item(device, 0, rp5h01->counter_mode); |
| 190 | state_save_register_device_item(device, 0, rp5h01->enabled); |
| 191 | state_save_register_device_item(device, 0, rp5h01->old_reset); |
| 192 | state_save_register_device_item(device, 0, rp5h01->old_clock); |
| 195 | 193 | } |
| 196 | 194 | |
| 197 | | WRITE8_HANDLER( RP5H01_0_test_w ) { |
| 198 | | RP5H01_test_w( 0, data ); |
| 199 | | } |
| 195 | /*------------------------------------------------- |
| 196 | DEVICE_RESET( rp5h01 ) |
| 197 | -------------------------------------------------*/ |
| 200 | 198 | |
| 201 | | READ8_HANDLER( RP5H01_0_counter_r ) { |
| 202 | | return RP5H01_counter_r( 0 ); |
| 199 | static DEVICE_RESET( rp5h01 ) |
| 200 | { |
| 201 | rp5h01_state *rp5h01 = get_safe_token(device); |
| 202 | |
| 203 | rp5h01->counter = 0; |
| 204 | rp5h01->counter_mode = COUNTER_MODE_6_BITS; |
| 205 | rp5h01->enabled = 0; |
| 206 | rp5h01->old_reset = -1; |
| 207 | rp5h01->old_clock = -1; |
| 203 | 208 | } |
| 204 | 209 | |
| 205 | | READ8_HANDLER( RP5H01_0_data_r ) { |
| 206 | | return RP5H01_data_r( 0 ); |
| 207 | | } |
| 210 | /*------------------------------------------------- |
| 211 | device definition |
| 212 | -------------------------------------------------*/ |
| 213 | |
| 214 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 215 | |
| 216 | #define DEVTEMPLATE_ID(p,s) p##rp5h01##s |
| 217 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 218 | #define DEVTEMPLATE_NAME "RP5H01" |
| 219 | #define DEVTEMPLATE_FAMILY "RP5H01" |
| 220 | #define DEVTEMPLATE_CLASS DEVICE_CLASS_PERIPHERAL |
| 221 | #include "devtempl.h" |
src/emu/machine/adc083x.c
| r4939 | r4940 | |
| 1 | | /* |
| 2 | | * ADC0831/ADC0832/ADC0834/ADC0838 |
| 3 | | * |
| 4 | | * 8-Bit Serial I/O A/D Converters with Muliplexer Options |
| 5 | | * |
| 6 | | */ |
| 1 | /*************************************************************************** |
| 7 | 2 | |
| 8 | | #include <stdarg.h> |
| 3 | National Semiconductor ADC0831 / ADC0832 / ADC0834 / ADC0838 |
| 4 | |
| 5 | 8-Bit serial I/O A/D Converters with Muliplexer Options |
| 6 | |
| 7 | |
| 8 | 2009-06 Converted to be a device |
| 9 | |
| 10 | ***************************************************************************/ |
| 11 | |
| 9 | 12 | #include "driver.h" |
| 10 | | #include "machine/adc083x.h" |
| 13 | #include "adc083x.h" |
| 11 | 14 | |
| 12 | | #define VERBOSE_LEVEL ( 0 ) |
| 15 | #define VERBOSE_LEVEL (0) |
| 13 | 16 | |
| 14 | 17 | INLINE void ATTR_PRINTF(3,4) verboselog( running_machine *machine, int n_level, const char *s_fmt, ... ) |
| 15 | 18 | { |
| 16 | | if( VERBOSE_LEVEL >= n_level ) |
| 19 | if (VERBOSE_LEVEL >= n_level) |
| 17 | 20 | { |
| 18 | 21 | va_list v; |
| 19 | 22 | char buf[ 32768 ]; |
| 20 | | va_start( v, s_fmt ); |
| 21 | | vsprintf( buf, s_fmt, v ); |
| 22 | | va_end( v ); |
| 23 | | logerror( "%s: %s", cpuexec_describe_context(machine), buf ); |
| 23 | va_start(v, s_fmt); |
| 24 | vsprintf(buf, s_fmt, v); |
| 25 | va_end(v); |
| 26 | logerror("%s: %s", cpuexec_describe_context(machine), buf); |
| 24 | 27 | } |
| 25 | 28 | } |
| 26 | 29 | |
| 27 | | struct adc083x_chip |
| 30 | /*************************************************************************** |
| 31 | PARAMETERS |
| 32 | ***************************************************************************/ |
| 33 | |
| 34 | enum |
| 28 | 35 | { |
| 29 | | int type; |
| 30 | | double (*input_callback)(running_machine *machine, int input); |
| 31 | | INT32 CS; |
| 32 | | INT32 CLK; |
| 33 | | INT32 DI; |
| 34 | | INT32 SE; |
| 35 | | INT32 SARS; |
| 36 | | INT32 DO; |
| 37 | | INT32 SGL; |
| 38 | | INT32 ODD; |
| 39 | | INT32 SEL1; |
| 40 | | INT32 SEL0; |
| 36 | STATE_IDLE, |
| 37 | STATE_WAIT_FOR_START, |
| 38 | STATE_SHIFT_MUX, |
| 39 | STATE_MUX_SETTLE, |
| 40 | STATE_OUTPUT_MSB_FIRST, |
| 41 | STATE_WAIT_FOR_SE, |
| 42 | STATE_OUTPUT_LSB_FIRST, |
| 43 | STATE_FINISHED |
| 44 | }; |
| 45 | |
| 46 | /*************************************************************************** |
| 47 | TYPE DEFINITIONS |
| 48 | ***************************************************************************/ |
| 49 | |
| 50 | typedef struct _adc0831_state adc0831_state; |
| 51 | struct _adc0831_state |
| 52 | { |
| 53 | adc083x_input_convert_func input_callback_r; |
| 54 | |
| 55 | INT32 cs; |
| 56 | INT32 clk; |
| 57 | INT32 di; |
| 58 | INT32 se; |
| 59 | INT32 sars; |
| 60 | INT32 _do; |
| 61 | INT32 sgl; |
| 62 | INT32 odd; |
| 63 | INT32 sel1; |
| 64 | INT32 sel0; |
| 41 | 65 | INT32 state; |
| 42 | 66 | INT32 bit; |
| 43 | 67 | INT32 output; |
| 44 | 68 | INT32 mux_bits; |
| 45 | 69 | }; |
| 46 | 70 | |
| 47 | | #define STATE_IDLE ( 0 ) |
| 48 | | #define STATE_WAIT_FOR_START ( 1 ) |
| 49 | | #define STATE_SHIFT_MUX ( 2 ) |
| 50 | | #define STATE_MUX_SETTLE ( 3 ) |
| 51 | | #define STATE_OUTPUT_MSB_FIRST ( 4 ) |
| 52 | | #define STATE_WAIT_FOR_SE ( 5 ) |
| 53 | | #define STATE_OUTPUT_LSB_FIRST ( 6 ) |
| 54 | | #define STATE_FINISHED ( 7 ) |
| 55 | 71 | |
| 56 | | static struct adc083x_chip adc083x[ MAX_ADC083X_CHIPS ]; |
| 57 | 72 | |
| 58 | | void adc083x_init( running_machine *machine, int chip, int type, double (*input_callback)(running_machine *machine, int input) ) |
| 73 | /*************************************************************************** |
| 74 | INLINE FUNCTIONS |
| 75 | ***************************************************************************/ |
| 76 | |
| 77 | INLINE adc0831_state *get_safe_token(const device_config *device) |
| 59 | 78 | { |
| 60 | | struct adc083x_chip *c; |
| 79 | assert(device != NULL); |
| 80 | assert(device->token != NULL); |
| 81 | assert((device->type == ADC0831) || (device->type == ADC0832) || (device->type == ADC0834) || (device->type == ADC0838)); |
| 82 | return (adc0831_state *)device->token; |
| 83 | } |
| 61 | 84 | |
| 62 | | if( chip >= MAX_ADC083X_CHIPS ) |
| 63 | | { |
| 64 | | verboselog( machine, 0, "adc083x_init( %d ) chip out of range\n", chip ); |
| 65 | | return; |
| 66 | | } |
| 85 | INLINE const adc0831_interface *get_interface(const device_config *device) |
| 86 | { |
| 87 | assert(device != NULL); |
| 88 | assert((device->type == ADC0831) || (device->type == ADC0832) || (device->type == ADC0834) || (device->type == ADC0838)); |
| 89 | return (const adc0831_interface *) device->static_config; |
| 90 | } |
| 67 | 91 | |
| 68 | | c = &adc083x[ chip ]; |
| 69 | 92 | |
| 70 | | c->type = type; |
| 71 | | c->input_callback = input_callback; |
| 72 | | c->CS = 0; |
| 73 | | c->CLK = 0; |
| 74 | | c->DI = 0; |
| 75 | | c->SE = 0; |
| 76 | | if( c->type == ADC0834 || c->type == ADC0838 ) |
| 77 | | { |
| 78 | | c->SARS = 1; |
| 79 | | } |
| 80 | | else |
| 81 | | { |
| 82 | | c->SARS = 0; |
| 83 | | } |
| 84 | | c->DO = 1; |
| 85 | | c->SGL = 0; |
| 86 | | c->ODD = 0; |
| 87 | | c->SEL1 = 0; |
| 88 | | c->SEL0 = 0; |
| 89 | | c->state = STATE_IDLE; |
| 90 | | c->bit = 0; |
| 91 | | c->output = 0; |
| 93 | /*************************************************************************** |
| 94 | IMPLEMENTATION |
| 95 | ***************************************************************************/ |
| 92 | 96 | |
| 93 | | switch( c->type ) |
| 94 | | { |
| 95 | | case ADC0831: |
| 96 | | c->mux_bits = 0; |
| 97 | | break; |
| 98 | | case ADC0832: |
| 99 | | c->mux_bits = 2; |
| 100 | | break; |
| 101 | | case ADC0834: |
| 102 | | c->mux_bits = 3; |
| 103 | | break; |
| 104 | | case ADC0838: |
| 105 | | c->mux_bits = 4; |
| 106 | | break; |
| 107 | | } |
| 97 | /*------------------------------------------------- |
| 98 | adc083x_cs_write |
| 99 | -------------------------------------------------*/ |
| 108 | 100 | |
| 109 | | state_save_register_item( machine, "adc083x", NULL, chip, c->CS ); |
| 110 | | state_save_register_item( machine, "adc083x", NULL, chip, c->CLK ); |
| 111 | | state_save_register_item( machine, "adc083x", NULL, chip, c->DI ); |
| 112 | | state_save_register_item( machine, "adc083x", NULL, chip, c->SE ); |
| 113 | | state_save_register_item( machine, "adc083x", NULL, chip, c->SARS ); |
| 114 | | state_save_register_item( machine, "adc083x", NULL, chip, c->DO ); |
| 115 | | state_save_register_item( machine, "adc083x", NULL, chip, c->SGL ); |
| 116 | | state_save_register_item( machine, "adc083x", NULL, chip, c->ODD ); |
| 117 | | state_save_register_item( machine, "adc083x", NULL, chip, c->SEL1 ); |
| 118 | | state_save_register_item( machine, "adc083x", NULL, chip, c->SEL0 ); |
| 119 | | state_save_register_item( machine, "adc083x", NULL, chip, c->state ); |
| 120 | | state_save_register_item( machine, "adc083x", NULL, chip, c->bit ); |
| 121 | | state_save_register_item( machine, "adc083x", NULL, chip, c->output ); |
| 122 | | } |
| 123 | | |
| 124 | | void adc083x_cs_write( running_machine *machine, int chip, int cs ) |
| 101 | WRITE8_DEVICE_HANDLER( adc083x_cs_write ) |
| 125 | 102 | { |
| 126 | | struct adc083x_chip *c; |
| 103 | adc0831_state *adc083x = get_safe_token(device); |
| 127 | 104 | |
| 128 | | if( chip >= MAX_ADC083X_CHIPS ) |
| 105 | if (adc083x->cs != data) |
| 129 | 106 | { |
| 130 | | verboselog( machine, 0, "adc083x_cs_write( %d ) chip out of range\n", chip ); |
| 131 | | return; |
| 107 | verboselog(device->machine, 2, "adc083x_cs_write( %s, %d )\n", device->tag, data); |
| 132 | 108 | } |
| 133 | 109 | |
| 134 | | c = &adc083x[ chip ]; |
| 135 | | |
| 136 | | if( c->CS != cs ) |
| 110 | if (adc083x->cs == 0 && data != 0) |
| 137 | 111 | { |
| 138 | | verboselog( machine, 2, "adc083x_cs_write( %d, %d )\n", chip, cs ); |
| 139 | | } |
| 140 | | |
| 141 | | if( c->CS == 0 && cs != 0 ) |
| 142 | | { |
| 143 | | c->state = STATE_IDLE; |
| 144 | | if( c->type == ADC0834 || c->type == ADC0838 ) |
| 112 | adc083x->state = STATE_IDLE; |
| 113 | if (device->type == ADC0834 || device->type == ADC0838) |
| 145 | 114 | { |
| 146 | | c->SARS = 1; |
| 115 | adc083x->sars = 1; |
| 147 | 116 | } |
| 148 | | c->DO = 1; |
| 117 | adc083x->_do = 1; |
| 149 | 118 | } |
| 150 | | if( c->CS != 0 && cs == 0 ) |
| 119 | if (adc083x->cs != 0 && data == 0) |
| 151 | 120 | { |
| 152 | | if( c->type == ADC0831 ) |
| 121 | if (device->type == ADC0831) |
| 153 | 122 | { |
| 154 | | c->state = STATE_MUX_SETTLE; |
| 123 | adc083x->state = STATE_MUX_SETTLE; |
| 155 | 124 | } |
| 156 | 125 | else |
| 157 | 126 | { |
| 158 | | c->state = STATE_WAIT_FOR_START; |
| 127 | adc083x->state = STATE_WAIT_FOR_START; |
| 159 | 128 | } |
| 160 | | if( c->type == ADC0834 || c->type == ADC0838 ) |
| 129 | |
| 130 | if (device->type == ADC0834 || device->type == ADC0838) |
| 161 | 131 | { |
| 162 | | c->SARS = 1; |
| 132 | adc083x->sars = 1; |
| 163 | 133 | } |
| 164 | | c->DO = 1; |
| 134 | adc083x->_do = 1; |
| 165 | 135 | } |
| 166 | 136 | |
| 167 | | c->CS = cs; |
| 137 | adc083x->cs = data; |
| 168 | 138 | } |
| 169 | 139 | |
| 170 | | static int adc083x_conversion( running_machine *machine, int chip ) |
| 140 | /*------------------------------------------------- |
| 141 | adc083x_conversion |
| 142 | -------------------------------------------------*/ |
| 143 | |
| 144 | static UINT8 adc083x_conversion( const device_config *device ) |
| 171 | 145 | { |
| 172 | | struct adc083x_chip *c = &adc083x[ chip ]; |
| 146 | adc0831_state *adc083x = get_safe_token(device); |
| 173 | 147 | int result; |
| 174 | 148 | int positive_channel = ADC083X_AGND; |
| 175 | 149 | int negative_channel = ADC083X_AGND; |
| 176 | 150 | double positive = 0; |
| 177 | 151 | double negative = 0; |
| 178 | | double gnd = c->input_callback( machine, ADC083X_AGND ); |
| 179 | | double vref = c->input_callback( machine, ADC083X_VREF ); |
| 152 | double vref = adc083x->input_callback_r(device, ADC083X_VREF); |
| 153 | double gnd = adc083x->input_callback_r(device, ADC083X_VREF); |
| 180 | 154 | |
| 181 | | switch( c->type ) |
| 155 | if (device->type == ADC0831) |
| 182 | 156 | { |
| 183 | | case ADC0831: |
| 184 | 157 | positive_channel = ADC083X_CH0; |
| 185 | 158 | negative_channel = ADC083X_CH1; |
| 186 | | break; |
| 187 | | case ADC0832: |
| 188 | | positive_channel = ADC083X_CH0 + c->ODD; |
| 189 | | if( c->SGL == 0 ) |
| 159 | } |
| 160 | |
| 161 | else if (device->type == ADC0832) |
| 162 | { |
| 163 | positive_channel = ADC083X_CH0 + adc083x->odd; |
| 164 | if (adc083x->sgl == 0) |
| 190 | 165 | { |
| 191 | 166 | negative_channel = positive_channel ^ 1; |
| 192 | 167 | } |
| r4939 | r4940 | |
| 194 | 169 | { |
| 195 | 170 | negative_channel = ADC083X_AGND; |
| 196 | 171 | } |
| 197 | | break; |
| 198 | | case ADC0834: |
| 199 | | positive_channel = ADC083X_CH0 + c->ODD + ( c->SEL1 * 2 ); |
| 200 | | if( c->SGL == 0 ) |
| 172 | } |
| 173 | else if (device->type == ADC0834) |
| 174 | { |
| 175 | positive_channel = ADC083X_CH0 + adc083x->odd + (adc083x->sel1 * 2); |
| 176 | if (adc083x->sgl == 0) |
| 201 | 177 | { |
| 202 | 178 | negative_channel = positive_channel ^ 1; |
| 203 | 179 | } |
| r4939 | r4940 | |
| 205 | 181 | { |
| 206 | 182 | negative_channel = ADC083X_AGND; |
| 207 | 183 | } |
| 208 | | break; |
| 209 | | case ADC0838: |
| 210 | | positive_channel = ADC083X_CH0 + c->ODD + ( c->SEL0 * 2 ) + ( c->SEL1 * 4 ); |
| 211 | | if( c->SGL == 0 ) |
| 184 | } |
| 185 | else if (device->type == ADC0838) |
| 186 | { |
| 187 | positive_channel = ADC083X_CH0 + adc083x->odd + (adc083x->sel0 * 2) + (adc083x->sel1 * 4); |
| 188 | if (adc083x->sgl == 0) |
| 212 | 189 | { |
| 213 | 190 | negative_channel = positive_channel ^ 1; |
| 214 | 191 | } |
| r4939 | r4940 | |
| 216 | 193 | { |
| 217 | 194 | negative_channel = ADC083X_COM; |
| 218 | 195 | } |
| 219 | | break; |
| 220 | 196 | } |
| 221 | 197 | |
| 222 | | if( positive_channel != ADC083X_AGND ) |
| 198 | if (positive_channel != ADC083X_AGND) |
| 223 | 199 | { |
| 224 | | positive = c->input_callback( machine, positive_channel ) - gnd; |
| 200 | positive = adc083x->input_callback_r(device, positive_channel) - gnd; |
| 225 | 201 | } |
| 226 | | if( negative_channel != ADC083X_AGND ) |
| 202 | if (negative_channel != ADC083X_AGND) |
| 227 | 203 | { |
| 228 | | negative = c->input_callback( machine, negative_channel ) - gnd; |
| 204 | negative = adc083x->input_callback_r(device, negative_channel) - gnd; |
| 229 | 205 | } |
| 230 | 206 | |
| 231 | | result = (int)( ( ( positive - negative ) * 255 ) / vref ); |
| 232 | | if( result < 0 ) |
| 207 | result = (int)(((positive - negative) * 255) / vref); |
| 208 | logerror("%d", result); |
| 209 | if (result < 0) |
| 233 | 210 | { |
| 234 | 211 | result = 0; |
| 235 | 212 | } |
| 236 | | else if( result > 255 ) |
| 213 | else if (result > 255) |
| 237 | 214 | { |
| 238 | 215 | result = 255; |
| 239 | 216 | } |
| r4939 | r4940 | |
| 241 | 218 | return result; |
| 242 | 219 | } |
| 243 | 220 | |
| 244 | | void adc083x_clk_write( running_machine *machine, int chip, int clk ) |
| 221 | /*------------------------------------------------- |
| 222 | adc083x_clk_write |
| 223 | -------------------------------------------------*/ |
| 224 | |
| 225 | WRITE8_DEVICE_HANDLER( adc083x_clk_write ) |
| 245 | 226 | { |
| 246 | | struct adc083x_chip *c; |
| 227 | adc0831_state *adc083x = get_safe_token(device); |
| 247 | 228 | |
| 248 | | if( chip >= MAX_ADC083X_CHIPS ) |
| 229 | if (adc083x->clk != data) |
| 249 | 230 | { |
| 250 | | verboselog( machine, 0, "adc083x_clk_write( %d ) chip out of range\n", chip ); |
| 251 | | return; |
| 231 | verboselog(device->machine, 2, "adc083x_clk_write( %s, %d )\n", device->tag, data); |
| 252 | 232 | } |
| 253 | 233 | |
| 254 | | c = &adc083x[ chip ]; |
| 255 | | |
| 256 | | if( c->CLK != clk ) |
| 234 | if (adc083x->cs == 0) |
| 257 | 235 | { |
| 258 | | verboselog( machine, 2, "adc083x_clk_write( %d, %d )\n", chip, clk ); |
| 259 | | } |
| 260 | | |
| 261 | | if( c->CS == 0 ) |
| 262 | | { |
| 263 | | if( c->CLK == 0 && clk != 0 ) |
| 236 | if (adc083x->clk == 0 && data != 0) |
| 264 | 237 | { |
| 265 | | switch( c->state ) |
| 238 | switch (adc083x->state) |
| 266 | 239 | { |
| 267 | 240 | case STATE_WAIT_FOR_START: |
| 268 | | if( c->DI != 0 ) |
| 241 | if (adc083x->di != 0) |
| 269 | 242 | { |
| 270 | | verboselog( machine, 1, "adc083x %d got start bit\n", chip ); |
| 271 | | c->state = STATE_SHIFT_MUX; |
| 272 | | c->SARS = 0; |
| 273 | | c->SGL = 0; |
| 274 | | c->ODD = 0; |
| 275 | | c->SEL1 = 0; |
| 276 | | c->SEL0 = 0; |
| 277 | | c->bit = 0; |
| 243 | verboselog(device->machine, 1, "adc083x %s got start bit\n", device->tag); |
| 244 | adc083x->state = STATE_SHIFT_MUX; |
| 245 | adc083x->sars = 0; |
| 246 | adc083x->sgl = 0; |
| 247 | adc083x->odd = 0; |
| 248 | adc083x->sel1 = 0; |
| 249 | adc083x->sel0 = 0; |
| 250 | adc083x->bit = 0; |
| 278 | 251 | } |
| 279 | 252 | else |
| 280 | 253 | { |
| 281 | | verboselog( machine, 1, "adc083x %d not start bit\n", chip ); |
| 254 | verboselog(device->machine, 1, "adc083x %s not start bit\n", device->tag); |
| 282 | 255 | } |
| 283 | 256 | break; |
| 284 | 257 | case STATE_SHIFT_MUX: |
| 285 | | switch( c->bit ) |
| 258 | switch (adc083x->bit) |
| 286 | 259 | { |
| 287 | 260 | case 0: |
| 288 | | if( c->DI != 0 ) |
| 261 | if (adc083x->di != 0) |
| 289 | 262 | { |
| 290 | | c->SGL = 1; |
| 263 | adc083x->sgl = 1; |
| 291 | 264 | } |
| 292 | | verboselog( machine, 1, "adc083x %d SGL <- %d\n", chip, c->SGL ); |
| 265 | verboselog(device->machine, 1, "adc083x %s sgl <- %d\n", device->tag, adc083x->sgl); |
| 293 | 266 | break; |
| 294 | 267 | case 1: |
| 295 | | if( c->DI != 0 ) |
| 268 | if (adc083x->di != 0) |
| 296 | 269 | { |
| 297 | | c->ODD = 1; |
| 270 | adc083x->odd = 1; |
| 298 | 271 | } |
| 299 | | verboselog( machine, 1, "adc083x %d ODD <- %d\n", chip, c->ODD ); |
| 272 | verboselog(device->machine, 1, "adc083x %s odd <- %d\n", device->tag, adc083x->odd); |
| 300 | 273 | break; |
| 301 | 274 | case 2: |
| 302 | | if( c->DI != 0 ) |
| 275 | if (adc083x->di != 0) |
| 303 | 276 | { |
| 304 | | c->SEL1 = 1; |
| 277 | adc083x->sel1 = 1; |
| 305 | 278 | } |
| 306 | | verboselog( machine, 1, "adc083x %d SEL1 <- %d\n", chip, c->SEL1 ); |
| 279 | verboselog(device->machine, 1, "adc083x %s sel1 <- %d\n", device->tag, adc083x->sel1); |
| 307 | 280 | break; |
| 308 | 281 | case 3: |
| 309 | | if( c->DI != 0 ) |
| 282 | if (adc083x->di != 0) |
| 310 | 283 | { |
| 311 | | c->SEL0 = 1; |
| 284 | adc083x->sel0 = 1; |
| 312 | 285 | } |
| 313 | | verboselog( machine, 1, "adc083x %d SEL0 <- %d\n", chip, c->SEL0 ); |
| 286 | verboselog(device->machine, 1, "adc083x %s sel0 <- %d\n", device->tag, adc083x->sel0); |
| 314 | 287 | break; |
| 315 | 288 | } |
| 316 | | c->bit++; |
| 317 | | if( c->bit == c->mux_bits ) |
| 289 | adc083x->bit++; |
| 290 | if (adc083x->bit == adc083x->mux_bits) |
| 318 | 291 | { |
| 319 | | c->state = STATE_MUX_SETTLE; |
| 292 | adc083x->state = STATE_MUX_SETTLE; |
| 320 | 293 | } |
| 321 | 294 | break; |
| 322 | 295 | case STATE_WAIT_FOR_SE: |
| 323 | | c->SARS = 0; |
| 324 | | if( c->type == ADC0838 && c->SE != 0 ) |
| 296 | adc083x->sars = 0; |
| 297 | if (device->type == ADC0838 && adc083x->se != 0) |
| 325 | 298 | { |
| 326 | | verboselog( machine, 1, "adc083x %d not SE\n", chip ); |
| 299 | verboselog(device->machine, 1, "adc083x %s not se\n", device->tag); |
| 327 | 300 | } |
| 328 | 301 | else |
| 329 | 302 | { |
| 330 | | verboselog( machine, 1, "adc083x %d got SE\n", chip ); |
| 331 | | c->state = STATE_OUTPUT_LSB_FIRST; |
| 332 | | c->bit = 1; |
| 303 | verboselog(device->machine, 1, "adc083x %s got se\n", device->tag); |
| 304 | adc083x->state = STATE_OUTPUT_LSB_FIRST; |
| 305 | adc083x->bit = 1; |
| 333 | 306 | } |
| 334 | 307 | break; |
| 335 | 308 | } |
| 336 | 309 | } |
| 337 | | if( c->CLK != 0 && clk == 0 ) |
| 310 | if (adc083x->clk != 0 && data == 0) |
| 338 | 311 | { |
| 339 | | switch( c->state ) |
| 312 | switch (adc083x->state) |
| 340 | 313 | { |
| 341 | 314 | case STATE_MUX_SETTLE: |
| 342 | | verboselog( machine, 1, "adc083x %d mux settle\n", chip ); |
| 343 | | c->output = adc083x_conversion( machine, chip ); |
| 344 | | c->state = STATE_OUTPUT_MSB_FIRST; |
| 345 | | c->bit = 7; |
| 346 | | if( c->type == ADC0834 || c->type == ADC0838 ) |
| 315 | verboselog(device->machine, 1, "adc083x %s mux settle\n", device->tag); |
| 316 | adc083x->output = adc083x_conversion(device); |
| 317 | adc083x->state = STATE_OUTPUT_MSB_FIRST; |
| 318 | adc083x->bit = 7; |
| 319 | if (device->type == ADC0834 || device->type == ADC0838) |
| 347 | 320 | { |
| 348 | | c->SARS = 1; |
| 321 | adc083x->sars = 1; |
| 349 | 322 | } |
| 350 | | c->DO = 0; |
| 323 | adc083x->_do = 0; |
| 351 | 324 | break; |
| 352 | 325 | case STATE_OUTPUT_MSB_FIRST: |
| 353 | | c->DO = ( c->output >> c->bit ) & 1; |
| 354 | | verboselog( machine, 1, "adc083x %d msb %d -> %d\n", chip, c->bit, c->DO ); |
| 355 | | c->bit--; |
| 356 | | if( c->bit < 0 ) |
| 326 | adc083x->_do = (adc083x->output >> adc083x->bit) & 1; |
| 327 | verboselog(device->machine, 1, "adc083x %s msb %d -> %d\n", device->tag, adc083x->bit, adc083x->_do); |
| 328 | adc083x->bit--; |
| 329 | if (adc083x->bit < 0) |
| 357 | 330 | { |
| 358 | | if( c->type == ADC0831 ) |
| 331 | if (device->type == ADC0831) |
| 359 | 332 | { |
| 360 | | c->state = STATE_FINISHED; |
| 333 | adc083x->state = STATE_FINISHED; |
| 361 | 334 | } |
| 362 | 335 | else |
| 363 | 336 | { |
| 364 | | c->state = STATE_WAIT_FOR_SE; |
| 337 | adc083x->state = STATE_WAIT_FOR_SE; |
| 365 | 338 | } |
| 366 | 339 | } |
| 367 | 340 | break; |
| 368 | 341 | case STATE_OUTPUT_LSB_FIRST: |
| 369 | | c->DO = ( c->output >> c->bit ) & 1; |
| 370 | | verboselog( machine, 1, "adc083x %d lsb %d -> %d\n", chip, c->bit, c->DO ); |
| 371 | | c->bit++; |
| 372 | | if( c->bit == 8 ) |
| 342 | adc083x->_do = (adc083x->output >> adc083x->bit) & 1; |
| 343 | verboselog(device->machine, 1, "adc083x %s lsb %d -> %d\n", device->tag, adc083x->bit, adc083x->_do); |
| 344 | adc083x->bit++; |
| 345 | if (adc083x->bit == 8) |
| 373 | 346 | { |
| 374 | | c->state = STATE_FINISHED; |
| 347 | adc083x->state = STATE_FINISHED; |
| 375 | 348 | } |
| 376 | 349 | break; |
| 377 | 350 | case STATE_FINISHED: |
| 378 | | c->state = STATE_IDLE; |
| 379 | | c->DO = 0; |
| 351 | adc083x->state = STATE_IDLE; |
| 352 | adc083x->_do = 0; |
| 380 | 353 | break; |
| 381 | 354 | } |
| 382 | 355 | } |
| 383 | 356 | } |
| 384 | 357 | |
| 385 | | c->CLK = clk; |
| 358 | adc083x->clk = data; |
| 386 | 359 | } |
| 387 | 360 | |
| 388 | | void adc083x_di_write( running_machine *machine, int chip, int di ) |
| 361 | /*------------------------------------------------- |
| 362 | adc083x_di_write |
| 363 | -------------------------------------------------*/ |
| 364 | |
| 365 | WRITE8_DEVICE_HANDLER( adc083x_di_write ) |
| 389 | 366 | { |
| 390 | | struct adc083x_chip *c; |
| 367 | adc0831_state *adc083x = get_safe_token(device); |
| 391 | 368 | |
| 392 | | if( chip >= MAX_ADC083X_CHIPS ) |
| 369 | if (adc083x->di != data) |
| 393 | 370 | { |
| 394 | | verboselog( machine, 0, "adc083x_di_write( %d ) chip out of range\n", chip ); |
| 395 | | return; |
| 371 | verboselog(device->machine, 2, "adc083x_di_write( %s, %d )\n", device->tag, data); |
| 396 | 372 | } |
| 397 | 373 | |
| 398 | | c = &adc083x[ chip ]; |
| 374 | adc083x->di = data; |
| 375 | } |
| 399 | 376 | |
| 400 | | if( c->DI != di ) |
| 377 | /*------------------------------------------------- |
| 378 | adc083x_se_write |
| 379 | -------------------------------------------------*/ |
| 380 | |
| 381 | WRITE8_DEVICE_HANDLER( adc083x_se_write ) |
| 382 | { |
| 383 | adc0831_state *adc083x = get_safe_token(device); |
| 384 | |
| 385 | if (adc083x->se != data) |
| 401 | 386 | { |
| 402 | | verboselog( machine, 2, "adc083x_di_write( %d, %d )\n", chip, di ); |
| 387 | verboselog(device->machine, 2, "adc083x_se_write( %s, %d )\n", device->tag, data); |
| 403 | 388 | } |
| 404 | 389 | |
| 405 | | c->DI = di; |
| 390 | adc083x->se = data; |
| 406 | 391 | } |
| 407 | 392 | |
| 408 | | void adc083x_se_write( running_machine *machine, int chip, int se ) |
| 393 | /*------------------------------------------------- |
| 394 | adc083x_sars_read |
| 395 | -------------------------------------------------*/ |
| 396 | |
| 397 | READ8_DEVICE_HANDLER( adc083x_sars_read ) |
| 409 | 398 | { |
| 410 | | struct adc083x_chip *c; |
| 399 | adc0831_state *adc083x = get_safe_token(device); |
| 411 | 400 | |
| 412 | | if( chip >= MAX_ADC083X_CHIPS ) |
| 413 | | { |
| 414 | | verboselog( machine, 0, "adc083x_se_write( %d ) chip out of range\n", chip ); |
| 415 | | return; |
| 416 | | } |
| 401 | verboselog(device->machine, 1, "adc083x_sars_read( %s ) %d\n", device->tag, adc083x->sars); |
| 402 | return adc083x->sars; |
| 403 | } |
| 417 | 404 | |
| 418 | | c = &adc083x[ chip ]; |
| 405 | /*------------------------------------------------- |
| 406 | adc083x_do_read |
| 407 | -------------------------------------------------*/ |
| 419 | 408 | |
| 420 | | if( c->SE != se ) |
| 421 | | { |
| 422 | | verboselog( machine, 2, "adc083x_se_write( %d, %d )\n", chip, se ); |
| 423 | | } |
| 409 | READ8_DEVICE_HANDLER( adc083x_do_read ) |
| 410 | { |
| 411 | adc0831_state *adc083x = get_safe_token(device); |
| 424 | 412 | |
| 425 | | c->SE = se; |
| 413 | verboselog(device->machine, 1, "adc083x_sars_read( %s ) %d\n", device->tag, adc083x->_do); |
| 414 | return adc083x->_do; |
| 426 | 415 | } |
| 427 | 416 | |
| 428 | | int adc083x_sars_read( running_machine *machine, int chip ) |
| 417 | |
| 418 | /*------------------------------------------------- |
| 419 | DEVICE_START( adc083x ) |
| 420 | -------------------------------------------------*/ |
| 421 | |
| 422 | static DEVICE_START( adc0831 ) |
| 429 | 423 | { |
| 430 | | struct adc083x_chip *c; |
| 424 | adc0831_state *adc083x = get_safe_token(device); |
| 425 | const adc0831_interface *intf = get_interface(device); |
| 431 | 426 | |
| 432 | | if( chip >= MAX_ADC083X_CHIPS ) |
| 427 | if (device->type == ADC0831) |
| 433 | 428 | { |
| 434 | | verboselog( machine, 0, "adc083x_sars_read( %d ) chip out of range\n", chip ); |
| 435 | | return 0; |
| 429 | adc083x->sars = 1; |
| 430 | adc083x->mux_bits = 0; |
| 436 | 431 | } |
| 432 | else if (device->type == ADC0832) |
| 433 | { |
| 434 | adc083x->sars = 1; |
| 435 | adc083x->mux_bits = 2; |
| 436 | } |
| 437 | else if (device->type == ADC0834) |
| 438 | { |
| 439 | adc083x->sars = 0; |
| 440 | adc083x->mux_bits = 3; |
| 441 | } |
| 442 | else if (device->type == ADC0838) |
| 443 | { |
| 444 | adc083x->sars = 0; |
| 445 | adc083x->mux_bits = 4; |
| 446 | } |
| 437 | 447 | |
| 438 | | c = &adc083x[ chip ]; |
| 448 | /* resolve callbacks */ |
| 449 | adc083x->input_callback_r = intf->input_callback_r; |
| 439 | 450 | |
| 440 | | verboselog( machine, 1, "adc083x_sars_read( %d ) %d\n", chip, c->SARS ); |
| 441 | | return c->SARS; |
| 451 | /* register for state saving */ |
| 452 | state_save_register_device_item(device, 0, adc083x->cs); |
| 453 | state_save_register_device_item(device, 0, adc083x->clk); |
| 454 | state_save_register_device_item(device, 0, adc083x->di); |
| 455 | state_save_register_device_item(device, 0, adc083x->se); |
| 456 | state_save_register_device_item(device, 0, adc083x->sars); |
| 457 | state_save_register_device_item(device, 0, adc083x->_do); |
| 458 | state_save_register_device_item(device, 0, adc083x->sgl); |
| 459 | state_save_register_device_item(device, 0, adc083x->odd); |
| 460 | state_save_register_device_item(device, 0, adc083x->sel1); |
| 461 | state_save_register_device_item(device, 0, adc083x->sel0); |
| 462 | state_save_register_device_item(device, 0, adc083x->state); |
| 463 | state_save_register_device_item(device, 0, adc083x->bit); |
| 464 | state_save_register_device_item(device, 0, adc083x->output); |
| 465 | state_save_register_device_item(device, 0, adc083x->mux_bits); |
| 442 | 466 | } |
| 443 | 467 | |
| 444 | | int adc083x_do_read( running_machine *machine, int chip ) |
| 468 | |
| 469 | /*------------------------------------------------- |
| 470 | DEVICE_RESET( adc083x ) |
| 471 | -------------------------------------------------*/ |
| 472 | |
| 473 | static DEVICE_RESET( adc0831 ) |
| 445 | 474 | { |
| 446 | | struct adc083x_chip *c; |
| 475 | adc0831_state *adc083x = get_safe_token(device); |
| 447 | 476 | |
| 448 | | if( chip >= MAX_ADC083X_CHIPS ) |
| 449 | | { |
| 450 | | verboselog( machine, 0, "adc083x_do_read( %d ) chip out of range\n", chip ); |
| 451 | | return 0; |
| 452 | | } |
| 477 | adc083x->cs = 0; |
| 478 | adc083x->clk = 0; |
| 479 | adc083x->di = 0; |
| 480 | adc083x->se = 0; |
| 481 | adc083x->_do = 1; |
| 482 | adc083x->sgl = 0; |
| 483 | adc083x->odd = 0; |
| 484 | adc083x->sel1 = 0; |
| 485 | adc083x->sel0 = 0; |
| 486 | adc083x->state = STATE_IDLE; |
| 487 | adc083x->bit = 0; |
| 488 | adc083x->output = 0; |
| 489 | } |
| 453 | 490 | |
| 454 | | c = &adc083x[ chip ]; |
| 491 | /*------------------------------------------------- |
| 492 | device definition |
| 493 | -------------------------------------------------*/ |
| 455 | 494 | |
| 456 | | verboselog( machine, 1, "adc083x_do_read( %d ) %d\n", chip, c->DO ); |
| 457 | | return c->DO; |
| 458 | | } |
| 495 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 496 | |
| 497 | #define DEVTEMPLATE_ID(p,s) p##adc0831##s |
| 498 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 499 | #define DEVTEMPLATE_NAME "A/D Converters 0831" |
| 500 | #define DEVTEMPLATE_FAMILY "National Semiconductor A/D Converters 083x" |
| 501 | #define DEVTEMPLATE_CLASS DEVICE_CLASS_PERIPHERAL |
| 502 | #include "devtempl.h" |
| 503 | |
| 504 | #define DEVTEMPLATE_DERIVED_ID(p,s) p##adc0832##s |
| 505 | #define DEVTEMPLATE_DERIVED_FEATURES 0 |
| 506 | #define DEVTEMPLATE_DERIVED_NAME "A/D Converters 0832" |
| 507 | #include "devtempl.h" |
| 508 | |
| 509 | #define DEVTEMPLATE_DERIVED_ID(p,s) p##adc0834##s |
| 510 | #define DEVTEMPLATE_DERIVED_FEATURES 0 |
| 511 | #define DEVTEMPLATE_DERIVED_NAME "A/D Converters 0834" |
| 512 | #include "devtempl.h" |
| 513 | |
| 514 | #define DEVTEMPLATE_DERIVED_ID(p,s) p##adc0838##s |
| 515 | #define DEVTEMPLATE_DERIVED_FEATURES 0 |
| 516 | #define DEVTEMPLATE_DERIVED_NAME "A/D Converters 0838" |
| 517 | #include "devtempl.h" |
src/emu/machine/upd4701.c
| r4939 | r4940 | |
| 1 | | /* |
| 2 | | * uPD4701 |
| 3 | | * |
| 4 | | * Incremental Encoder Control |
| 5 | | * |
| 6 | | */ |
| 1 | /*************************************************************************** |
| 7 | 2 | |
| 3 | NEC uPD4701 |
| 4 | |
| 5 | Incremental Encoder Control |
| 6 | |
| 7 | 2009-06 Converted to be a device |
| 8 | |
| 9 | ***************************************************************************/ |
| 10 | |
| 8 | 11 | #include "driver.h" |
| 9 | | #include "machine/upd4701.h" |
| 12 | #include "upd4701.h" |
| 10 | 13 | |
| 11 | | struct uPD4701_chip |
| 14 | /*************************************************************************** |
| 15 | TYPE DEFINITIONS |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | typedef struct _upd4701_state upd4701_state; |
| 19 | struct _upd4701_state |
| 12 | 20 | { |
| 13 | 21 | int cs; |
| 14 | 22 | int xy; |
| r4939 | r4940 | |
| 26 | 34 | int cf; |
| 27 | 35 | }; |
| 28 | 36 | |
| 29 | | static struct uPD4701_chip uPD4701[ UPD4701_MAXCHIP ]; |
| 37 | /* x,y increments can be 12bit (see MASK_COUNTER), hence we need a couple of |
| 38 | 16bit handlers in the following */ |
| 30 | 39 | |
| 31 | 40 | #define MASK_SWITCHES ( 7 ) |
| 32 | 41 | #define MASK_COUNTER ( 0xfff ) |
| 33 | 42 | |
| 34 | | void uPD4701_init( running_machine *machine, int chip ) |
| 35 | | { |
| 36 | | struct uPD4701_chip *c; |
| 37 | 43 | |
| 38 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 39 | | { |
| 40 | | logerror( "uPD4701_init( machine, %d ) invalid chip\n", chip ); |
| 41 | | return; |
| 42 | | } |
| 44 | /*************************************************************************** |
| 45 | INLINE FUNCTIONS |
| 46 | ***************************************************************************/ |
| 43 | 47 | |
| 44 | | c = &uPD4701[ chip ]; |
| 45 | | |
| 46 | | c->cs = 1; |
| 47 | | c->xy = 0; |
| 48 | | c->ul = 0; |
| 49 | | c->resetx = 0; |
| 50 | | c->resety = 0; |
| 51 | | c->latchx = 0; |
| 52 | | c->latchy = 0; |
| 53 | | c->startx = 0; |
| 54 | | c->starty = 0; |
| 55 | | c->x = 0; |
| 56 | | c->y = 0; |
| 57 | | c->switches = 0; |
| 58 | | c->latchswitches = 0; |
| 59 | | c->cf = 1; |
| 60 | | |
| 61 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->cs ); |
| 62 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->xy ); |
| 63 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->ul ); |
| 64 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->resetx ); |
| 65 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->resety ); |
| 66 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->latchx ); |
| 67 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->latchy ); |
| 68 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->startx ); |
| 69 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->starty ); |
| 70 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->x ); |
| 71 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->y ); |
| 72 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->switches ); |
| 73 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->latchswitches ); |
| 74 | | state_save_register_item( machine, "uPD4701", NULL, chip, c->cf ); |
| 48 | INLINE upd4701_state *get_safe_token(const device_config *device) |
| 49 | { |
| 50 | assert(device != NULL); |
| 51 | assert(device->token != NULL); |
| 52 | assert((device->type == UPD4701)); |
| 53 | return (upd4701_state *)device->token; |
| 75 | 54 | } |
| 76 | 55 | |
| 77 | | void uPD4701_ul_w( int chip, int ul ) |
| 78 | | { |
| 79 | | struct uPD4701_chip *c; |
| 80 | 56 | |
| 81 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 82 | | { |
| 83 | | logerror( "uPD4701_ul_w( %d ) invalid chip\n", chip ); |
| 84 | | return; |
| 85 | | } |
| 57 | /*************************************************************************** |
| 58 | IMPLEMENTATION |
| 59 | ***************************************************************************/ |
| 86 | 60 | |
| 87 | | c = &uPD4701[ chip ]; |
| 88 | | c->ul = ul; |
| 89 | | } |
| 61 | /*------------------------------------------------- |
| 62 | upd4701_ul_w |
| 63 | -------------------------------------------------*/ |
| 90 | 64 | |
| 91 | | void uPD4701_xy_w( int chip, int xy ) |
| 65 | WRITE8_DEVICE_HANDLER( upd4701_ul_w ) |
| 92 | 66 | { |
| 93 | | struct uPD4701_chip *c; |
| 67 | upd4701_state *upd4701 = get_safe_token(device); |
| 68 | upd4701->ul = data; |
| 69 | } |
| 94 | 70 | |
| 95 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 96 | | { |
| 97 | | logerror( "uPD4701_xy_w( %d ) invalid chip\n", chip ); |
| 98 | | return; |
| 99 | | } |
| 71 | /*------------------------------------------------- |
| 72 | upd4701_xy_w |
| 73 | -------------------------------------------------*/ |
| 100 | 74 | |
| 101 | | c = &uPD4701[ chip ]; |
| 102 | | c->xy = xy; |
| 75 | WRITE8_DEVICE_HANDLER( upd4701_xy_w ) |
| 76 | { |
| 77 | upd4701_state *upd4701 = get_safe_token(device); |
| 78 | upd4701->xy = data; |
| 103 | 79 | } |
| 104 | 80 | |
| 105 | | void uPD4701_cs_w( int chip, int cs ) |
| 81 | /*------------------------------------------------- |
| 82 | upd4701_cs_w |
| 83 | -------------------------------------------------*/ |
| 84 | |
| 85 | WRITE8_DEVICE_HANDLER( upd4701_cs_w ) |
| 106 | 86 | { |
| 107 | | struct uPD4701_chip *c; |
| 87 | upd4701_state *upd4701 = get_safe_token(device); |
| 108 | 88 | |
| 109 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 89 | if (data != upd4701->cs) |
| 110 | 90 | { |
| 111 | | logerror( "uPD4701_cs_w( %d ) invalid chip\n", chip ); |
| 112 | | return; |
| 113 | | } |
| 91 | upd4701->cs = data; |
| 114 | 92 | |
| 115 | | c = &uPD4701[ chip ]; |
| 116 | | if( cs != c->cs ) |
| 117 | | { |
| 118 | | c->cs = cs; |
| 119 | | |
| 120 | | if( !c->cs ) |
| 93 | if (!upd4701->cs) |
| 121 | 94 | { |
| 122 | | c->latchx = ( c->x - c->startx ) & MASK_COUNTER; |
| 123 | | c->latchy = ( c->y - c->starty ) & MASK_COUNTER; |
| 95 | upd4701->latchx = (upd4701->x - upd4701->startx) & MASK_COUNTER; |
| 96 | upd4701->latchy = (upd4701->y - upd4701->starty) & MASK_COUNTER; |
| 124 | 97 | |
| 125 | | c->latchswitches = ( ~c->switches ) & MASK_SWITCHES; |
| 126 | | if( c->latchswitches != 0 ) |
| 98 | upd4701->latchswitches = (~upd4701->switches) & MASK_SWITCHES; |
| 99 | if (upd4701->latchswitches != 0) |
| 127 | 100 | { |
| 128 | | c->latchswitches |= 8; |
| 101 | upd4701->latchswitches |= 8; |
| 129 | 102 | } |
| 130 | 103 | |
| 131 | | c->cf = 1; |
| 104 | upd4701->cf = 1; |
| 132 | 105 | } |
| 133 | 106 | } |
| 134 | 107 | } |
| 135 | 108 | |
| 136 | | void uPD4701_resetx_w( int chip, int resetx ) |
| 109 | /*------------------------------------------------- |
| 110 | upd4701_resetx_w |
| 111 | -------------------------------------------------*/ |
| 112 | |
| 113 | WRITE8_DEVICE_HANDLER( upd4701_resetx_w ) |
| 137 | 114 | { |
| 138 | | struct uPD4701_chip *c; |
| 115 | upd4701_state *upd4701 = get_safe_token(device); |
| 139 | 116 | |
| 140 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 117 | if (upd4701->resetx != data) |
| 141 | 118 | { |
| 142 | | logerror( "uPD4701_resetx_w( %d ) invalid chip\n", chip ); |
| 143 | | return; |
| 119 | upd4701->resetx = data; |
| 120 | |
| 121 | if (upd4701->resetx) |
| 122 | { |
| 123 | upd4701->startx = upd4701->x; |
| 124 | } |
| 144 | 125 | } |
| 126 | } |
| 145 | 127 | |
| 146 | | c = &uPD4701[ chip ]; |
| 147 | | if( c->resetx != resetx ) |
| 128 | /*------------------------------------------------- |
| 129 | upd4701_resety_w |
| 130 | -------------------------------------------------*/ |
| 131 | |
| 132 | WRITE8_DEVICE_HANDLER( upd4701_resety_w ) |
| 133 | { |
| 134 | upd4701_state *upd4701 = get_safe_token(device); |
| 135 | |
| 136 | if (upd4701->resety != data) |
| 148 | 137 | { |
| 149 | | c->resetx = resetx; |
| 138 | upd4701->resety = data; |
| 150 | 139 | |
| 151 | | if( c->resetx ) |
| 140 | if (upd4701->resety) |
| 152 | 141 | { |
| 153 | | c->startx = c->x; |
| 142 | upd4701->starty = upd4701->y; |
| 154 | 143 | } |
| 155 | 144 | } |
| 156 | 145 | } |
| 157 | 146 | |
| 158 | | void uPD4701_resety_w( int chip, int resety ) |
| 147 | /*------------------------------------------------- |
| 148 | upd4701_x_add |
| 149 | -------------------------------------------------*/ |
| 150 | |
| 151 | WRITE16_DEVICE_HANDLER( upd4701_x_add ) |
| 159 | 152 | { |
| 160 | | struct uPD4701_chip *c; |
| 153 | upd4701_state *upd4701 = get_safe_token(device); |
| 161 | 154 | |
| 162 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 155 | if (!upd4701->resetx && data != 0) |
| 163 | 156 | { |
| 164 | | logerror( "uPD4701_resety_w( %d ) invalid chip\n", chip ); |
| 165 | | return; |
| 157 | upd4701->x += data; |
| 158 | |
| 159 | if (upd4701->cs) |
| 160 | { |
| 161 | upd4701->cf = 0; |
| 162 | } |
| 166 | 163 | } |
| 164 | } |
| 167 | 165 | |
| 168 | | c = &uPD4701[ chip ]; |
| 169 | | if( c->resety != resety ) |
| 166 | /*------------------------------------------------- |
| 167 | upd4701_y_add |
| 168 | -------------------------------------------------*/ |
| 169 | |
| 170 | WRITE16_DEVICE_HANDLER( upd4701_y_add ) |
| 171 | { |
| 172 | upd4701_state *upd4701 = get_safe_token(device); |
| 173 | |
| 174 | if (!upd4701->resety && data != 0) |
| 170 | 175 | { |
| 171 | | c->resety = resety; |
| 176 | upd4701->y += data; |
| 172 | 177 | |
| 173 | | if( c->resety ) |
| 178 | if (upd4701->cs) |
| 174 | 179 | { |
| 175 | | c->starty = c->y; |
| 180 | upd4701->cf = 0; |
| 176 | 181 | } |
| 177 | 182 | } |
| 178 | 183 | } |
| 179 | 184 | |
| 180 | | int uPD4701_d_r( int chip ) |
| 185 | /*------------------------------------------------- |
| 186 | upd4701_switches_set |
| 187 | -------------------------------------------------*/ |
| 188 | |
| 189 | WRITE8_DEVICE_HANDLER( upd4701_switches_set ) |
| 181 | 190 | { |
| 191 | upd4701_state *upd4701 = get_safe_token(device); |
| 192 | upd4701->switches = data; |
| 193 | } |
| 194 | |
| 195 | /*------------------------------------------------- |
| 196 | upd4701_d_r |
| 197 | -------------------------------------------------*/ |
| 198 | |
| 199 | READ16_DEVICE_HANDLER( upd4701_d_r ) |
| 200 | { |
| 201 | upd4701_state *upd4701 = get_safe_token(device); |
| 182 | 202 | int data; |
| 183 | | struct uPD4701_chip *c; |
| 184 | 203 | |
| 185 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 204 | if (upd4701->cs) |
| 186 | 205 | { |
| 187 | | logerror( "uPD4701_d_r( %d ) invalid chip\n", chip ); |
| 188 | | return 0; |
| 189 | | } |
| 190 | | |
| 191 | | c = &uPD4701[ chip ]; |
| 192 | | if( c->cs ) |
| 193 | | { |
| 194 | 206 | return 0xff; |
| 195 | 207 | } |
| 196 | 208 | |
| 197 | | if( c->xy ) |
| 209 | if (upd4701->xy) |
| 198 | 210 | { |
| 199 | | data = c->latchy; |
| 211 | data = upd4701->latchy; |
| 200 | 212 | } |
| 201 | 213 | else |
| 202 | 214 | { |
| 203 | | data = c->latchx; |
| 215 | data = upd4701->latchx; |
| 204 | 216 | } |
| 205 | 217 | |
| 206 | | data |= c->latchswitches << 12; |
| 218 | data |= upd4701->latchswitches << 12; |
| 207 | 219 | |
| 208 | | if( c->ul ) |
| 220 | if (upd4701->ul) |
| 209 | 221 | { |
| 210 | 222 | return data >> 8; |
| 211 | 223 | } |
| r4939 | r4940 | |
| 215 | 227 | } |
| 216 | 228 | } |
| 217 | 229 | |
| 218 | | int uPD4701_sf_r( int chip ) |
| 230 | /*------------------------------------------------- |
| 231 | upd4701_sf_r |
| 232 | -------------------------------------------------*/ |
| 233 | |
| 234 | READ8_DEVICE_HANDLER( upd4701_sf_r ) |
| 219 | 235 | { |
| 220 | | struct uPD4701_chip *c; |
| 236 | upd4701_state *upd4701 = get_safe_token(device); |
| 221 | 237 | |
| 222 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 238 | if ((upd4701->switches & MASK_SWITCHES) != MASK_SWITCHES) |
| 223 | 239 | { |
| 224 | | logerror( "uPD4701_sf_r( %d ) invalid chip\n", chip ); |
| 225 | 240 | return 0; |
| 226 | 241 | } |
| 227 | 242 | |
| 228 | | c = &uPD4701[ chip ]; |
| 229 | | if( ( c->switches & MASK_SWITCHES ) != MASK_SWITCHES ) |
| 230 | | { |
| 231 | | return 0; |
| 232 | | } |
| 233 | | |
| 234 | 243 | return 1; |
| 235 | 244 | } |
| 236 | 245 | |
| 237 | | int uPD4701_cf_r( int chip ) |
| 246 | /*------------------------------------------------- |
| 247 | upd4701_cf_r |
| 248 | -------------------------------------------------*/ |
| 249 | |
| 250 | READ8_DEVICE_HANDLER( upd4701_cf_r ) |
| 238 | 251 | { |
| 239 | | struct uPD4701_chip *c; |
| 252 | upd4701_state *upd4701 = get_safe_token(device); |
| 253 | return upd4701->cf; |
| 254 | } |
| 240 | 255 | |
| 241 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 242 | | { |
| 243 | | logerror( "uPD4701_cf_r( %d ) invalid chip\n", chip ); |
| 244 | | return 0; |
| 245 | | } |
| 256 | /*------------------------------------------------- |
| 257 | DEVICE_START( upd4701 ) |
| 258 | -------------------------------------------------*/ |
| 246 | 259 | |
| 247 | | c = &uPD4701[ chip ]; |
| 248 | | return c->cf; |
| 249 | | } |
| 250 | | |
| 251 | | void uPD4701_x_add( int chip, int dx ) |
| 260 | static DEVICE_START( upd4701 ) |
| 252 | 261 | { |
| 253 | | struct uPD4701_chip *c; |
| 262 | upd4701_state *upd4701 = get_safe_token(device); |
| 254 | 263 | |
| 255 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 256 | | { |
| 257 | | logerror( "uPD4701_x_add( %d ) invalid chip\n", chip ); |
| 258 | | return; |
| 259 | | } |
| 264 | /* register for state saving */ |
| 265 | state_save_register_device_item(device, 0, upd4701->cs); |
| 266 | state_save_register_device_item(device, 0, upd4701->xy); |
| 267 | state_save_register_device_item(device, 0, upd4701->ul); |
| 268 | state_save_register_device_item(device, 0, upd4701->resetx); |
| 269 | state_save_register_device_item(device, 0, upd4701->resety); |
| 270 | state_save_register_device_item(device, 0, upd4701->latchx); |
| 271 | state_save_register_device_item(device, 0, upd4701->latchy); |
| 272 | state_save_register_device_item(device, 0, upd4701->startx); |
| 273 | state_save_register_device_item(device, 0, upd4701->starty); |
| 274 | state_save_register_device_item(device, 0, upd4701->x); |
| 275 | state_save_register_device_item(device, 0, upd4701->y); |
| 276 | state_save_register_device_item(device, 0, upd4701->switches); |
| 277 | state_save_register_device_item(device, 0, upd4701->latchswitches); |
| 278 | state_save_register_device_item(device, 0, upd4701->cf); |
| 279 | } |
| 260 | 280 | |
| 261 | | c = &uPD4701[ chip ]; |
| 262 | | if( !c->resetx && dx != 0 ) |
| 263 | | { |
| 264 | | c->x += dx; |
| 281 | /*------------------------------------------------- |
| 282 | DEVICE_RESET( upd4701 ) |
| 283 | -------------------------------------------------*/ |
| 265 | 284 | |
| 266 | | if( c->cs ) |
| 267 | | { |
| 268 | | c->cf = 0; |
| 269 | | } |
| 270 | | } |
| 271 | | } |
| 272 | | |
| 273 | | void uPD4701_y_add( int chip, int dy ) |
| 285 | static DEVICE_RESET( upd4701 ) |
| 274 | 286 | { |
| 275 | | struct uPD4701_chip *c; |
| 287 | upd4701_state *upd4701 = get_safe_token(device); |
| 276 | 288 | |
| 277 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 278 | | { |
| 279 | | logerror( "uPD4701_y_add( %d ) invalid chip\n", chip ); |
| 280 | | return; |
| 281 | | } |
| 282 | | |
| 283 | | c = &uPD4701[ chip ]; |
| 284 | | if( !c->resety && dy != 0 ) |
| 285 | | { |
| 286 | | c->y += dy; |
| 287 | | |
| 288 | | if( c->cs ) |
| 289 | | { |
| 290 | | c->cf = 0; |
| 291 | | } |
| 292 | | } |
| 289 | upd4701->cs = 1; |
| 290 | upd4701->xy = 0; |
| 291 | upd4701->ul = 0; |
| 292 | upd4701->resetx = 0; |
| 293 | upd4701->resety = 0; |
| 294 | upd4701->latchx = 0; |
| 295 | upd4701->latchy = 0; |
| 296 | upd4701->startx = 0; |
| 297 | upd4701->starty = 0; |
| 298 | upd4701->x = 0; |
| 299 | upd4701->y = 0; |
| 300 | upd4701->switches = 0; |
| 301 | upd4701->latchswitches = 0; |
| 302 | upd4701->cf = 1; |
| 293 | 303 | } |
| 294 | 304 | |
| 295 | | void uPD4701_switches_set( int chip, int switches ) |
| 296 | | { |
| 297 | | struct uPD4701_chip *c; |
| 305 | /*------------------------------------------------- |
| 306 | device definition |
| 307 | -------------------------------------------------*/ |
| 298 | 308 | |
| 299 | | if( chip < 0 || chip >= UPD4701_MAXCHIP ) |
| 300 | | { |
| 301 | | logerror( "uPD4701_switches_set( %d ) invalid chip\n", chip ); |
| 302 | | return; |
| 303 | | } |
| 309 | static const char *DEVTEMPLATE_SOURCE = __FILE__; |
| 304 | 310 | |
| 305 | | c = &uPD4701[ chip ]; |
| 306 | | c->switches = switches; |
| 307 | | } |
| 311 | #define DEVTEMPLATE_ID(p,s) p##upd4701##s |
| 312 | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 313 | #define DEVTEMPLATE_NAME "NEC uPD4701 Encoder" |
| 314 | #define DEVTEMPLATE_FAMILY "NEC uPD4701 Encoder" |
| 315 | #define DEVTEMPLATE_CLASS DEVICE_CLASS_PERIPHERAL |
| 316 | #include "devtempl.h" |