src/mess/machine/gb.c
| r9785 | r9786 | |
| 247 | 247 | gb_state *state = machine->driver_data<gb_state>(); |
| 248 | 248 | machine->add_notifier(MACHINE_NOTIFY_EXIT, gb_machine_stop); |
| 249 | 249 | |
| 250 | state->sgb_packets = -1; |
| 251 | |
| 250 | 252 | /* Allocate the serial timer, and disable it */ |
| 251 | 253 | state->gb_serial_timer = timer_alloc(machine, gb_serial_timer_proc , NULL); |
| 252 | 254 | timer_enable( state->gb_serial_timer, 0 ); |
| r9785 | r9786 | |
| 919 | 921 | WRITE8_HANDLER ( sgb_io_w ) |
| 920 | 922 | { |
| 921 | 923 | gb_state *state = space->machine->driver_data<gb_state>(); |
| 922 | | static UINT8 sgb_bitcount = 0, sgb_bytecount = 0, sgb_start = 0, sgb_rest = 0; |
| 923 | | static UINT8 sgb_controller_no = 0, sgb_controller_mode = 0; |
| 924 | | static INT8 sgb_packets = -1; |
| 925 | | static UINT8 sgb_data[112]; |
| 926 | | static UINT32 sgb_atf; |
| 924 | UINT8 *sgb_data = state->sgb_data; |
| 927 | 925 | |
| 928 | 926 | switch( offset ) |
| 929 | 927 | { |
| r9785 | r9786 | |
| 931 | 929 | switch (data & 0x30) |
| 932 | 930 | { |
| 933 | 931 | case 0x00: /* start condition */ |
| 934 | | if (sgb_start) |
| 932 | if (state->sgb_start) |
| 935 | 933 | logerror("SGB: Start condition before end of transfer ??\n"); |
| 936 | | sgb_bitcount = 0; |
| 937 | | sgb_start = 1; |
| 938 | | sgb_rest = 0; |
| 934 | state->sgb_bitcount = 0; |
| 935 | state->sgb_start = 1; |
| 936 | state->sgb_rest = 0; |
| 939 | 937 | JOYPAD = 0x0F & ((input_port_read(space->machine, "INPUTS") >> 4) | input_port_read(space->machine, "INPUTS") | 0xF0); |
| 940 | 938 | break; |
| 941 | 939 | case 0x10: /* data true */ |
| 942 | | if (sgb_rest) |
| 940 | if (state->sgb_rest) |
| 943 | 941 | { |
| 944 | 942 | /* We should test for this case , but the code below won't |
| 945 | 943 | work with the current setup */ |
| 946 | 944 | #if 0 |
| 947 | | if (sgb_bytecount == 16) |
| 945 | if (state->sgb_bytecount == 16) |
| 948 | 946 | { |
| 949 | 947 | logerror("SGB: end of block is not zero!"); |
| 950 | | sgb_start = 0; |
| 948 | state->sgb_start = 0; |
| 951 | 949 | } |
| 952 | 950 | #endif |
| 953 | | sgb_data[sgb_bytecount] >>= 1; |
| 954 | | sgb_data[sgb_bytecount] |= 0x80; |
| 955 | | sgb_bitcount++; |
| 956 | | if (sgb_bitcount == 8) |
| 951 | sgb_data[state->sgb_bytecount] >>= 1; |
| 952 | sgb_data[state->sgb_bytecount] |= 0x80; |
| 953 | state->sgb_bitcount++; |
| 954 | if (state->sgb_bitcount == 8) |
| 957 | 955 | { |
| 958 | | sgb_bitcount = 0; |
| 959 | | sgb_bytecount++; |
| 956 | state->sgb_bitcount = 0; |
| 957 | state->sgb_bytecount++; |
| 960 | 958 | } |
| 961 | | sgb_rest = 0; |
| 959 | state->sgb_rest = 0; |
| 962 | 960 | } |
| 963 | 961 | JOYPAD = 0x1F & ((input_port_read(space->machine, "INPUTS") >> 4) | 0xF0); |
| 964 | 962 | break; |
| 965 | 963 | case 0x20: /* data false */ |
| 966 | | if (sgb_rest) |
| 964 | if (state->sgb_rest) |
| 967 | 965 | { |
| 968 | | if( sgb_bytecount == 16 && sgb_packets == -1 ) |
| 966 | if( state->sgb_bytecount == 16 && state->sgb_packets == -1 ) |
| 969 | 967 | { |
| 970 | 968 | #ifdef MAME_DEBUG |
| 971 | 969 | logerror("SGB: %s (%02X) pkts: %d data: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", |
| r9785 | r9786 | |
| 974 | 972 | sgb_data[8], sgb_data[9], sgb_data[10], sgb_data[11], |
| 975 | 973 | sgb_data[12], sgb_data[13], sgb_data[14], sgb_data[15]); |
| 976 | 974 | #endif |
| 977 | | sgb_packets = sgb_data[0] & 0x07; |
| 978 | | sgb_start = 0; |
| 975 | state->sgb_packets = sgb_data[0] & 0x07; |
| 976 | state->sgb_start = 0; |
| 979 | 977 | } |
| 980 | | if (sgb_bytecount == (sgb_packets << 4) ) |
| 978 | if (state->sgb_bytecount == (state->sgb_packets << 4) ) |
| 981 | 979 | { |
| 982 | 980 | switch( sgb_data[0] >> 3 ) |
| 983 | 981 | { |
| r9785 | r9786 | |
| 1246 | 1244 | /* Attribute File */ |
| 1247 | 1245 | if( sgb_data[9] & 0x40 ) |
| 1248 | 1246 | state->sgb_window_mask = 0; |
| 1249 | | sgb_atf = (sgb_data[9] & 0x3f) * (18 * 5); |
| 1247 | state->sgb_atf = (sgb_data[9] & 0x3f) * (18 * 5); |
| 1250 | 1248 | if( sgb_data[9] & 0x80 ) |
| 1251 | 1249 | { |
| 1252 | 1250 | for( J = 0; J < 18; J++ ) |
| 1253 | 1251 | { |
| 1254 | 1252 | for( I = 0; I < 5; I++ ) |
| 1255 | 1253 | { |
| 1256 | | state->sgb_pal_map[I * 4][J] = (state->sgb_atf_data[(J * 5) + sgb_atf + I] & 0xC0) >> 6; |
| 1257 | | state->sgb_pal_map[(I * 4) + 1][J] = (state->sgb_atf_data[(J * 5) + sgb_atf + I] & 0x30) >> 4; |
| 1258 | | state->sgb_pal_map[(I * 4) + 2][J] = (state->sgb_atf_data[(J * 5) + sgb_atf + I] & 0xC) >> 2; |
| 1259 | | state->sgb_pal_map[(I * 4) + 3][J] = state->sgb_atf_data[(J * 5) + sgb_atf + I] & 0x3; |
| 1254 | state->sgb_pal_map[I * 4][J] = (state->sgb_atf_data[(J * 5) + state->sgb_atf + I] & 0xC0) >> 6; |
| 1255 | state->sgb_pal_map[(I * 4) + 1][J] = (state->sgb_atf_data[(J * 5) + state->sgb_atf + I] & 0x30) >> 4; |
| 1256 | state->sgb_pal_map[(I * 4) + 2][J] = (state->sgb_atf_data[(J * 5) + state->sgb_atf + I] & 0xC) >> 2; |
| 1257 | state->sgb_pal_map[(I * 4) + 3][J] = state->sgb_atf_data[(J * 5) + state->sgb_atf + I] & 0x3; |
| 1260 | 1258 | } |
| 1261 | 1259 | } |
| 1262 | 1260 | } |
| r9785 | r9786 | |
| 1291 | 1289 | break; |
| 1292 | 1290 | case 0x11: /* MLT_REQ - Multi controller request */ |
| 1293 | 1291 | if (sgb_data[1] == 0x00) |
| 1294 | | sgb_controller_mode = 0; |
| 1292 | state->sgb_controller_mode = 0; |
| 1295 | 1293 | else if (sgb_data[1] == 0x01) |
| 1296 | | sgb_controller_mode = 2; |
| 1294 | state->sgb_controller_mode = 2; |
| 1297 | 1295 | break; |
| 1298 | 1296 | case 0x12: /* JUMP */ |
| 1299 | 1297 | /* Not Implemented */ |
| r9785 | r9786 | |
| 1339 | 1337 | /* Attribute File */ |
| 1340 | 1338 | if( sgb_data[1] & 0x40 ) |
| 1341 | 1339 | state->sgb_window_mask = 0; |
| 1342 | | sgb_atf = (sgb_data[1] & 0x3f) * (18 * 5); |
| 1340 | state->sgb_atf = (sgb_data[1] & 0x3f) * (18 * 5); |
| 1343 | 1341 | for( J = 0; J < 18; J++ ) |
| 1344 | 1342 | { |
| 1345 | 1343 | for( I = 0; I < 5; I++ ) |
| 1346 | 1344 | { |
| 1347 | | state->sgb_pal_map[I * 4][J] = (state->sgb_atf_data[(J * 5) + sgb_atf + I] & 0xC0) >> 6; |
| 1348 | | state->sgb_pal_map[(I * 4) + 1][J] = (state->sgb_atf_data[(J * 5) + sgb_atf + I] & 0x30) >> 4; |
| 1349 | | state->sgb_pal_map[(I * 4) + 2][J] = (state->sgb_atf_data[(J * 5) + sgb_atf + I] & 0xC) >> 2; |
| 1350 | | state->sgb_pal_map[(I * 4) + 3][J] = state->sgb_atf_data[(J * 5) + sgb_atf + I] & 0x3; |
| 1345 | state->sgb_pal_map[I * 4][J] = (state->sgb_atf_data[(J * 5) + state->sgb_atf + I] & 0xC0) >> 6; |
| 1346 | state->sgb_pal_map[(I * 4) + 1][J] = (state->sgb_atf_data[(J * 5) + state->sgb_atf + I] & 0x30) >> 4; |
| 1347 | state->sgb_pal_map[(I * 4) + 2][J] = (state->sgb_atf_data[(J * 5) + state->sgb_atf + I] & 0xC) >> 2; |
| 1348 | state->sgb_pal_map[(I * 4) + 3][J] = state->sgb_atf_data[(J * 5) + state->sgb_atf + I] & 0x3; |
| 1351 | 1349 | } |
| 1352 | 1350 | } |
| 1353 | 1351 | } |
| r9785 | r9786 | |
| 1371 | 1369 | logerror( "SGB: Unknown Command 0x%02x!\n", sgb_data[0] >> 3 ); |
| 1372 | 1370 | } |
| 1373 | 1371 | |
| 1374 | | sgb_start = 0; |
| 1375 | | sgb_bytecount = 0; |
| 1376 | | sgb_packets = -1; |
| 1372 | state->sgb_start = 0; |
| 1373 | state->sgb_bytecount = 0; |
| 1374 | state->sgb_packets = -1; |
| 1377 | 1375 | } |
| 1378 | | if( sgb_start ) |
| 1376 | if( state->sgb_start ) |
| 1379 | 1377 | { |
| 1380 | | sgb_data[sgb_bytecount] >>= 1; |
| 1381 | | sgb_bitcount++; |
| 1382 | | if (sgb_bitcount == 8) |
| 1378 | sgb_data[state->sgb_bytecount] >>= 1; |
| 1379 | state->sgb_bitcount++; |
| 1380 | if (state->sgb_bitcount == 8) |
| 1383 | 1381 | { |
| 1384 | | sgb_bitcount = 0; |
| 1385 | | sgb_bytecount++; |
| 1382 | state->sgb_bitcount = 0; |
| 1383 | state->sgb_bytecount++; |
| 1386 | 1384 | } |
| 1387 | 1385 | } |
| 1388 | | sgb_rest = 0; |
| 1386 | state->sgb_rest = 0; |
| 1389 | 1387 | } |
| 1390 | 1388 | JOYPAD = 0x2F & (input_port_read(space->machine, "INPUTS") | 0xF0); |
| 1391 | 1389 | break; |
| 1392 | 1390 | case 0x30: /* rest condition */ |
| 1393 | | if (sgb_start) |
| 1394 | | sgb_rest = 1; |
| 1395 | | if (sgb_controller_mode) |
| 1391 | if (state->sgb_start) |
| 1392 | state->sgb_rest = 1; |
| 1393 | if (state->sgb_controller_mode) |
| 1396 | 1394 | { |
| 1397 | | sgb_controller_no++; |
| 1398 | | if (sgb_controller_no == sgb_controller_mode) |
| 1399 | | sgb_controller_no = 0; |
| 1400 | | JOYPAD = 0x3F - sgb_controller_no; |
| 1395 | state->sgb_controller_no++; |
| 1396 | if (state->sgb_controller_no == state->sgb_controller_mode) |
| 1397 | state->sgb_controller_no = 0; |
| 1398 | JOYPAD = 0x3F - state->sgb_controller_no; |
| 1401 | 1399 | } |
| 1402 | 1400 | else |
| 1403 | 1401 | JOYPAD = 0x3F; |
src/mess/machine/kay_kbd.c
| r9785 | r9786 | |
| 17 | 17 | |
| 18 | 18 | #include "emu.h" |
| 19 | 19 | #include "sound/beep.h" |
| 20 | | #include "kay_kbd.h" |
| 20 | #include "includes/kaypro.h" |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | /* |
| r9785 | r9786 | |
| 57 | 57 | * producing a "clicking" sound for user feedback. Additionally, this buzzer can be activated |
| 58 | 58 | * for a longer period by sending a 0x04 byte to the keyboard. This is used by the ROM soft |
| 59 | 59 | * terminal to alert the user in case of a BEL. |
| 60 | | * |
| 60 | * |
| 61 | 61 | * 2008-05 FP: |
| 62 | 62 | * Small note about natural keyboard support: currently, |
| 63 | 63 | * - "Line Feed" is mapped to the 'End' key |
| 64 | 64 | * - "Keypad ," is not mapped |
| 65 | 65 | */ |
| 66 | 66 | |
| 67 | typedef struct _kay_kbd_t |
| 68 | { |
| 69 | running_device *beeper; |
| 70 | UINT8 buff[16]; |
| 71 | UINT8 head; |
| 72 | UINT8 tail; |
| 73 | UINT8 beep_on; |
| 74 | UINT8 control_status; |
| 75 | UINT8 keyrows[10]; |
| 76 | int lastrow; |
| 77 | int mask; |
| 78 | int key; |
| 79 | int repeat; |
| 80 | int repeater; |
| 81 | } kay_kbd_t; |
| 82 | |
| 67 | 83 | INPUT_PORTS_START( kay_kbd ) |
| 68 | 84 | PORT_START("ROW0") |
| 69 | 85 | PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_ESC) PORT_CHAR(UCHAR_MAMEKEY(ESC)) |
| r9785 | r9786 | |
| 164 | 180 | INPUT_PORTS_END |
| 165 | 181 | |
| 166 | 182 | static void kay_kbd_in( running_machine *machine, UINT8 data ); |
| 167 | | static running_device *kay_kbd_beeper; |
| 168 | | static UINT8 kbd_buff[16]; |
| 169 | | static UINT8 kbd_head = 0; |
| 170 | | static UINT8 kbd_tail = 0; |
| 171 | | static UINT8 beep_on = 0; |
| 172 | | static UINT8 control_status = 0; |
| 173 | | static UINT8 keyrows[10] = { 0,0,0,0,0,0,0,0,0,0 }; |
| 183 | |
| 174 | 184 | static const UINT8 keyboard[8][10][8] = { |
| 175 | 185 | { /* normal */ |
| 176 | 186 | { 27,'1','2','3','4','5','6','7'}, |
| r9785 | r9786 | |
| 272 | 282 | |
| 273 | 283 | MACHINE_RESET( kay_kbd ) |
| 274 | 284 | { |
| 285 | kaypro_state *state = machine->driver_data<kaypro_state>(); |
| 286 | kay_kbd_t *kbd = state->kbd = auto_alloc_clear(machine, kay_kbd_t); |
| 287 | |
| 275 | 288 | /* disable CapsLock LED initially */ |
| 276 | 289 | set_led_status(machine, 1, 1); |
| 277 | 290 | set_led_status(machine, 1, 0); |
| 278 | | kay_kbd_beeper = machine->device("beep"); |
| 279 | | beep_on = 1; |
| 280 | | control_status = 0x14; |
| 281 | | beep_set_state(kay_kbd_beeper, 0); |
| 282 | | beep_set_frequency(kay_kbd_beeper, 950); /* piezo-device needs to be measured */ |
| 283 | | kbd_head = kbd_tail = 0; /* init buffer */ |
| 291 | kbd->beeper = machine->device("beep"); |
| 292 | kbd->beep_on = 1; |
| 293 | kbd->control_status = 0x14; |
| 294 | beep_set_state(kbd->beeper, 0); |
| 295 | beep_set_frequency(kbd->beeper, 950); /* piezo-device needs to be measured */ |
| 296 | kbd->head = kbd->tail = 0; /* init buffer */ |
| 284 | 297 | } |
| 285 | 298 | |
| 286 | 299 | /****************************************************** |
| r9785 | r9786 | |
| 292 | 305 | ******************************************************/ |
| 293 | 306 | INTERRUPT_GEN( kay_kbd_interrupt ) |
| 294 | 307 | { |
| 308 | kaypro_state *state = device->machine->driver_data<kaypro_state>(); |
| 309 | kay_kbd_t *kbd = state->kbd; |
| 295 | 310 | int mod, row, col, chg, newval; |
| 296 | | static int lastrow = 0, mask = 0x00, key = 0x00, repeat = 0, repeater = 0; |
| 311 | UINT8 *keyrows = kbd->keyrows; |
| 297 | 312 | |
| 298 | | if( repeat ) |
| 313 | if( kbd->repeat ) |
| 299 | 314 | { |
| 300 | | if( !--repeat ) |
| 301 | | repeater = 4; |
| 315 | if( !--kbd->repeat ) |
| 316 | kbd->repeater = 4; |
| 302 | 317 | } |
| 303 | 318 | else |
| 304 | | if( repeater ) |
| 319 | if( kbd->repeater ) |
| 305 | 320 | { |
| 306 | | repeat = repeater; |
| 321 | kbd->repeat = kbd->repeater; |
| 307 | 322 | } |
| 308 | 323 | |
| 309 | 324 | row = 9; |
| r9785 | r9786 | |
| 323 | 338 | |
| 324 | 339 | if (row >= 0) |
| 325 | 340 | { |
| 326 | | repeater = 0x00; |
| 327 | | mask = 0x00; |
| 328 | | key = 0x00; |
| 329 | | lastrow = row; |
| 341 | kbd->repeater = 0x00; |
| 342 | kbd->mask = 0x00; |
| 343 | kbd->key = 0x00; |
| 344 | kbd->lastrow = row; |
| 330 | 345 | /* CapsLock LED */ |
| 331 | 346 | if( row == 3 && chg == 0x80 ) |
| 332 | | set_led_status(device->machine, 1, (keyrows[3] & 0x80) ? 0 : 1); |
| 347 | set_led_status(device->machine, 1, (kbd->keyrows[3] & 0x80) ? 0 : 1); |
| 333 | 348 | |
| 334 | 349 | if (newval & chg) /* key(s) pressed ? */ |
| 335 | 350 | { |
| r9785 | r9786 | |
| 348 | 363 | mod |= 4; |
| 349 | 364 | |
| 350 | 365 | /* find newval key */ |
| 351 | | mask = 0x01; |
| 366 | kbd->mask = 0x01; |
| 352 | 367 | for (col = 0; col < 8; col ++) |
| 353 | 368 | { |
| 354 | | if (chg & mask) |
| 369 | if (chg & kbd->mask) |
| 355 | 370 | { |
| 356 | | newval &= mask; |
| 357 | | key = keyboard[mod][row][col]; |
| 371 | newval &= kbd->mask; |
| 372 | kbd->key = keyboard[mod][row][col]; |
| 358 | 373 | break; |
| 359 | 374 | } |
| 360 | | mask <<= 1; |
| 375 | kbd->mask <<= 1; |
| 361 | 376 | } |
| 362 | | if( key ) /* normal key */ |
| 377 | if( kbd->key ) /* normal key */ |
| 363 | 378 | { |
| 364 | | repeater = 30; |
| 365 | | kay_kbd_in(device->machine, key); |
| 379 | kbd->repeater = 30; |
| 380 | kay_kbd_in(device->machine, kbd->key); |
| 366 | 381 | } |
| 367 | 382 | else |
| 368 | 383 | if( (row == 0) && (chg == 0x04) ) /* Ctrl-@ (NUL) */ |
| r9785 | r9786 | |
| 371 | 386 | } |
| 372 | 387 | else |
| 373 | 388 | { |
| 374 | | keyrows[row] = newval; |
| 389 | kbd->keyrows[row] = newval; |
| 375 | 390 | } |
| 376 | | repeat = repeater; |
| 391 | kbd->repeat = kbd->repeater; |
| 377 | 392 | } |
| 378 | | else if ( key && (keyrows[lastrow] & mask) && repeat == 0 ) |
| 393 | else if ( kbd->key && (keyrows[kbd->lastrow] & kbd->mask) && kbd->repeat == 0 ) |
| 379 | 394 | { |
| 380 | | kay_kbd_in(device->machine, key); |
| 395 | kay_kbd_in(device->machine, kbd->key); |
| 381 | 396 | } |
| 382 | 397 | } |
| 383 | 398 | |
| r9785 | r9786 | |
| 391 | 406 | static WRITE8_HANDLER ( kaypro2_const_w ) |
| 392 | 407 | { |
| 393 | 408 | if (data & 1) |
| 394 | | kbd_head = kbd_tail = 0; |
| 409 | kbd->head = kbd->tail = 0; |
| 395 | 410 | } |
| 396 | 411 | |
| 397 | 412 | #endif |
| r9785 | r9786 | |
| 403 | 418 | ******************************************************/ |
| 404 | 419 | static void kay_kbd_in( running_machine *machine, UINT8 data ) |
| 405 | 420 | { |
| 421 | kaypro_state *state = machine->driver_data<kaypro_state>(); |
| 422 | kay_kbd_t *kbd = state->kbd; |
| 406 | 423 | UINT8 kbd_head_old; |
| 407 | 424 | |
| 408 | | kbd_head_old = kbd_head; |
| 409 | | kbd_buff[kbd_head] = data; |
| 410 | | kbd_head = (kbd_head + 1) % sizeof(kbd_buff); |
| 425 | kbd_head_old = kbd->head; |
| 426 | kbd->buff[kbd->head] = data; |
| 427 | kbd->head = (kbd->head + 1) % sizeof(kbd->buff); |
| 411 | 428 | /* will the buffer overflow ? */ |
| 412 | | if (kbd_head == kbd_tail) |
| 429 | if (kbd->head == kbd->tail) |
| 413 | 430 | { |
| 414 | | kbd_head = kbd_head_old; |
| 431 | kbd->head = kbd_head_old; |
| 415 | 432 | kay_kbd_d_w(machine, 4); |
| 416 | 433 | } |
| 417 | 434 | else |
| r9785 | r9786 | |
| 419 | 436 | } |
| 420 | 437 | |
| 421 | 438 | |
| 422 | | UINT8 kay_kbd_c_r( void ) |
| 439 | UINT8 kay_kbd_c_r( running_machine *machine ) |
| 423 | 440 | { |
| 424 | 441 | /* d4 transmit buffer empty - 1=ok to send |
| 425 | 442 | d2 appears to be receive buffer empty - 1=ok to receive |
| 426 | 443 | d0 keyboard buffer empty - 1=key waiting to be used */ |
| 427 | 444 | |
| 428 | | UINT8 data = control_status; |
| 445 | kaypro_state *state = machine->driver_data<kaypro_state>(); |
| 446 | kay_kbd_t *kbd = state->kbd; |
| 447 | UINT8 data = kbd->control_status; |
| 429 | 448 | |
| 430 | | if( kbd_head != kbd_tail ) |
| 449 | if( kbd->head != kbd->tail ) |
| 431 | 450 | data++; |
| 432 | 451 | |
| 433 | 452 | return data; |
| 434 | 453 | } |
| 435 | 454 | |
| 436 | | UINT8 kay_kbd_d_r( void ) |
| 455 | UINT8 kay_kbd_d_r( running_machine *machine ) |
| 437 | 456 | { |
| 438 | 457 | /* return next key in buffer */ |
| 439 | 458 | |
| 459 | kaypro_state *state = machine->driver_data<kaypro_state>(); |
| 460 | kay_kbd_t *kbd = state->kbd; |
| 440 | 461 | UINT8 data = 0; |
| 441 | 462 | |
| 442 | | if (kbd_tail != kbd_head) |
| 463 | if (kbd->tail != kbd->head) |
| 443 | 464 | { |
| 444 | | data = kbd_buff[kbd_tail]; |
| 445 | | kbd_tail = (kbd_tail + 1) % sizeof(kbd_buff); |
| 465 | data = kbd->buff[kbd->tail]; |
| 466 | kbd->tail = (kbd->tail + 1) % sizeof(kbd->buff); |
| 446 | 467 | } |
| 447 | 468 | |
| 448 | 469 | return data; |
| r9785 | r9786 | |
| 450 | 471 | |
| 451 | 472 | static TIMER_CALLBACK( kay_kbd_beepoff ) |
| 452 | 473 | { |
| 453 | | beep_set_state(kay_kbd_beeper, 0); |
| 454 | | control_status |= 4; |
| 474 | kaypro_state *state = machine->driver_data<kaypro_state>(); |
| 475 | kay_kbd_t *kbd = state->kbd; |
| 476 | beep_set_state(kbd->beeper, 0); |
| 477 | kbd->control_status |= 4; |
| 455 | 478 | } |
| 456 | 479 | |
| 457 | 480 | void kay_kbd_d_w( running_machine *machine, UINT8 data ) |
| r9785 | r9786 | |
| 463 | 486 | 08 - mute |
| 464 | 487 | 16 - unmute */ |
| 465 | 488 | |
| 489 | kaypro_state *state = machine->driver_data<kaypro_state>(); |
| 490 | kay_kbd_t *kbd = state->kbd; |
| 466 | 491 | UINT16 length = 0; |
| 467 | 492 | |
| 468 | 493 | if (data & 0x10) |
| 469 | | beep_on = 1; |
| 494 | kbd->beep_on = 1; |
| 470 | 495 | else |
| 471 | 496 | if (data & 0x08) |
| 472 | | beep_on = 0; |
| 497 | kbd->beep_on = 0; |
| 473 | 498 | else |
| 474 | | if (beep_on) |
| 499 | if (kbd->beep_on) |
| 475 | 500 | { |
| 476 | 501 | if (data & 0x04) |
| 477 | 502 | length = 400; |
| r9785 | r9786 | |
| 484 | 509 | |
| 485 | 510 | if (length) |
| 486 | 511 | { |
| 487 | | control_status &= 0xfb; |
| 512 | kbd->control_status &= 0xfb; |
| 488 | 513 | timer_set(machine, ATTOTIME_IN_MSEC(length), NULL, 0, kay_kbd_beepoff); |
| 489 | | beep_set_state(kay_kbd_beeper, 1); |
| 514 | beep_set_state(kbd->beeper, 1); |
| 490 | 515 | } |
| 491 | 516 | } |
| 492 | 517 | } |
src/mess/machine/microtan.c
| r9785 | r9786 | |
| 33 | 33 | |
| 34 | 34 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 35 | 35 | |
| 36 | | static UINT8 microtan_keypad_column; |
| 37 | | static UINT8 microtan_keyboard_ascii; |
| 38 | 36 | |
| 39 | | static emu_timer *microtan_timer = NULL; |
| 40 | 37 | |
| 41 | | static int via_0_irq_line = CLEAR_LINE; |
| 42 | | static int via_1_irq_line = CLEAR_LINE; |
| 43 | | static int kbd_irq_line = CLEAR_LINE; |
| 44 | 38 | |
| 45 | | static UINT8 keyrows[10] = { 0,0,0,0,0,0,0,0,0,0 }; |
| 46 | 39 | static const char keyboard[8][9][8] = { |
| 47 | 40 | { /* normal */ |
| 48 | 41 | { 27,'1','2','3','4','5','6','7'}, |
| r9785 | r9786 | |
| 153 | 146 | |
| 154 | 147 | static void microtan_set_irq_line(running_machine *machine) |
| 155 | 148 | { |
| 149 | microtan_state *state = machine->driver_data<microtan_state>(); |
| 156 | 150 | /* The 6502 IRQ line is active low and probably driven |
| 157 | 151 | by open collector outputs (guess). Since MAME/MESS use |
| 158 | 152 | a non-0 value for ASSERT_LINE we OR the signals here */ |
| 159 | | cputag_set_input_line(machine, "maincpu", 0, via_0_irq_line | via_1_irq_line | kbd_irq_line); |
| 153 | cputag_set_input_line(machine, "maincpu", 0, state->via_0_irq_line | state->via_1_irq_line | state->kbd_irq_line); |
| 160 | 154 | } |
| 161 | 155 | |
| 162 | 156 | static running_device *cassette_device_image(running_machine *machine) |
| r9785 | r9786 | |
| 233 | 227 | |
| 234 | 228 | static void via_0_irq(running_device *device, int state) |
| 235 | 229 | { |
| 230 | microtan_state *drvstate = device->machine->driver_data<microtan_state>(); |
| 236 | 231 | LOG(("microtan_via_0_irq %d\n", state)); |
| 237 | | via_0_irq_line = state; |
| 232 | drvstate->via_0_irq_line = state; |
| 238 | 233 | microtan_set_irq_line(device->machine); |
| 239 | 234 | } |
| 240 | 235 | |
| r9785 | r9786 | |
| 305 | 300 | |
| 306 | 301 | static void via_1_irq(running_device *device, int state) |
| 307 | 302 | { |
| 303 | microtan_state *drvstate = device->machine->driver_data<microtan_state>(); |
| 308 | 304 | LOG(("microtan_via_1_irq %d\n", state)); |
| 309 | | via_1_irq_line = state; |
| 305 | drvstate->via_1_irq_line = state; |
| 310 | 306 | microtan_set_irq_line(device->machine); |
| 311 | 307 | } |
| 312 | 308 | |
| r9785 | r9786 | |
| 364 | 360 | |
| 365 | 361 | READ8_HANDLER ( microtan_bffx_r ) |
| 366 | 362 | { |
| 363 | microtan_state *state = space->machine->driver_data<microtan_state>(); |
| 367 | 364 | int data = 0xff; |
| 368 | 365 | switch( offset & 3 ) |
| 369 | 366 | { |
| 370 | 367 | case 0: /* BFF0: read enables chunky graphics */ |
| 371 | | microtan_chunky_graphics = 1; |
| 368 | state->chunky_graphics = 1; |
| 372 | 369 | LOG(("microtan_bff0_r: -> %02x (chunky graphics on)\n", data)); |
| 373 | 370 | break; |
| 374 | 371 | case 1: /* BFF1: read undefined (?) */ |
| r9785 | r9786 | |
| 378 | 375 | LOG(("microtan_bff2_r: -> %02x\n", data)); |
| 379 | 376 | break; |
| 380 | 377 | default: /* BFF3: read keyboard ASCII value */ |
| 381 | | data = microtan_keyboard_ascii; |
| 378 | data = state->keyboard_ascii; |
| 382 | 379 | LOG(("microtan_bff3_r: -> %02x (keyboard ASCII)\n", data)); |
| 383 | 380 | } |
| 384 | 381 | return data; |
| r9785 | r9786 | |
| 393 | 390 | |
| 394 | 391 | WRITE8_HANDLER ( microtan_bffx_w ) |
| 395 | 392 | { |
| 393 | microtan_state *state = space->machine->driver_data<microtan_state>(); |
| 396 | 394 | switch( offset & 3 ) |
| 397 | 395 | { |
| 398 | 396 | case 0: /* BFF0: write reset keyboard interrupt flag */ |
| 399 | 397 | /* This removes bit 7 from the ASCII value of the last key pressed. */ |
| 400 | 398 | LOG(("microtan_bff0_w: %d <- %02x (keyboard IRQ clear )\n", offset, data)); |
| 401 | | microtan_keyboard_ascii &= ~0x80; |
| 402 | | kbd_irq_line = CLEAR_LINE; |
| 399 | state->keyboard_ascii &= ~0x80; |
| 400 | state->kbd_irq_line = CLEAR_LINE; |
| 403 | 401 | microtan_set_irq_line(space->machine); |
| 404 | 402 | break; |
| 405 | 403 | case 1: /* BFF1: write delayed NMI */ |
| r9785 | r9786 | |
| 408 | 406 | break; |
| 409 | 407 | case 2: /* BFF2: write keypad column write (what is this meant for?) */ |
| 410 | 408 | LOG(("microtan_bff2_w: %d <- %02x (keypad column)\n", offset, data)); |
| 411 | | microtan_keypad_column = data; |
| 409 | state->keypad_column = data; |
| 412 | 410 | break; |
| 413 | 411 | default: /* BFF3: write disable chunky graphics */ |
| 414 | 412 | LOG(("microtan_bff3_w: %d <- %02x (chunky graphics off)\n", offset, data)); |
| 415 | | microtan_chunky_graphics = 0; |
| 413 | state->chunky_graphics = 0; |
| 416 | 414 | } |
| 417 | 415 | } |
| 418 | 416 | |
| 419 | 417 | static void store_key(running_machine *machine, int key) |
| 420 | 418 | { |
| 419 | microtan_state *state = machine->driver_data<microtan_state>(); |
| 421 | 420 | LOG(("microtan: store key '%c'\n", key)); |
| 422 | | microtan_keyboard_ascii = key | 0x80; |
| 423 | | kbd_irq_line = ASSERT_LINE; |
| 421 | state->keyboard_ascii = key | 0x80; |
| 422 | state->kbd_irq_line = ASSERT_LINE; |
| 424 | 423 | microtan_set_irq_line(machine); |
| 425 | 424 | } |
| 426 | 425 | |
| 427 | 426 | INTERRUPT_GEN( microtan_interrupt ) |
| 428 | 427 | { |
| 428 | microtan_state *state = device->machine->driver_data<microtan_state>(); |
| 429 | 429 | int mod, row, col, chg, newvar; |
| 430 | | static int lastrow = 0, mask = 0x00, key = 0x00, repeat = 0, repeater = 0; |
| 431 | 430 | static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7", "ROW8" }; |
| 432 | 431 | |
| 433 | | if( repeat ) |
| 432 | if( state->repeat ) |
| 434 | 433 | { |
| 435 | | if( !--repeat ) |
| 436 | | repeater = 4; |
| 434 | if( !--state->repeat ) |
| 435 | state->repeater = 4; |
| 437 | 436 | } |
| 438 | | else if( repeater ) |
| 437 | else if( state->repeater ) |
| 439 | 438 | { |
| 440 | | repeat = repeater; |
| 439 | state->repeat = state->repeater; |
| 441 | 440 | } |
| 442 | 441 | |
| 443 | 442 | |
| 444 | 443 | row = 9; |
| 445 | 444 | newvar = input_port_read(device->machine, "ROW8"); |
| 446 | | chg = keyrows[--row] ^ newvar; |
| 445 | chg = state->keyrows[--row] ^ newvar; |
| 447 | 446 | |
| 448 | 447 | while ( !chg && row > 0) |
| 449 | 448 | { |
| 450 | 449 | newvar = input_port_read(device->machine, keynames[row - 1]); |
| 451 | | chg = keyrows[--row] ^ newvar; |
| 450 | chg = state->keyrows[--row] ^ newvar; |
| 452 | 451 | } |
| 453 | 452 | if (!chg) |
| 454 | 453 | --row; |
| 455 | 454 | |
| 456 | 455 | if (row >= 0) |
| 457 | 456 | { |
| 458 | | repeater = 0x00; |
| 459 | | mask = 0x00; |
| 460 | | key = 0x00; |
| 461 | | lastrow = row; |
| 457 | state->repeater = 0x00; |
| 458 | state->mask = 0x00; |
| 459 | state->key = 0x00; |
| 460 | state->lastrow = row; |
| 462 | 461 | /* CapsLock LED */ |
| 463 | 462 | if( row == 3 && chg == 0x80 ) |
| 464 | | set_led_status(device->machine, 1, (keyrows[3] & 0x80) ? 0 : 1); |
| 463 | set_led_status(device->machine, 1, (state->keyrows[3] & 0x80) ? 0 : 1); |
| 465 | 464 | |
| 466 | 465 | if (newvar & chg) /* key(s) pressed ? */ |
| 467 | 466 | { |
| 468 | 467 | mod = 0; |
| 469 | 468 | |
| 470 | 469 | /* Shift modifier */ |
| 471 | | if ( (keyrows[5] & 0x10) || (keyrows[6] & 0x80) ) |
| 470 | if ( (state->keyrows[5] & 0x10) || (state->keyrows[6] & 0x80) ) |
| 472 | 471 | mod |= 1; |
| 473 | 472 | |
| 474 | 473 | /* Control modifier */ |
| 475 | | if (keyrows[3] & 0x40) |
| 474 | if (state->keyrows[3] & 0x40) |
| 476 | 475 | mod |= 2; |
| 477 | 476 | |
| 478 | 477 | /* CapsLock modifier */ |
| 479 | | if (keyrows[3] & 0x80) |
| 478 | if (state->keyrows[3] & 0x80) |
| 480 | 479 | mod |= 4; |
| 481 | 480 | |
| 482 | 481 | /* find newvar key */ |
| 483 | | mask = 0x01; |
| 482 | state->mask = 0x01; |
| 484 | 483 | for (col = 0; col < 8; col ++) |
| 485 | 484 | { |
| 486 | | if (chg & mask) |
| 485 | if (chg & state->mask) |
| 487 | 486 | { |
| 488 | | newvar &= mask; |
| 489 | | key = keyboard[mod][row][col]; |
| 487 | newvar &= state->mask; |
| 488 | state->key = keyboard[mod][row][col]; |
| 490 | 489 | break; |
| 491 | 490 | } |
| 492 | | mask <<= 1; |
| 491 | state->mask <<= 1; |
| 493 | 492 | } |
| 494 | | if( key ) /* normal key */ |
| 493 | if( state->key ) /* normal key */ |
| 495 | 494 | { |
| 496 | | repeater = 30; |
| 497 | | store_key(device->machine, key); |
| 495 | state->repeater = 30; |
| 496 | store_key(device->machine, state->key); |
| 498 | 497 | } |
| 499 | 498 | else |
| 500 | 499 | if( (row == 0) && (chg == 0x04) ) /* Ctrl-@ (NUL) */ |
| 501 | 500 | store_key(device->machine, 0); |
| 502 | | keyrows[row] |= newvar; |
| 501 | state->keyrows[row] |= newvar; |
| 503 | 502 | } |
| 504 | 503 | else |
| 505 | 504 | { |
| 506 | | keyrows[row] = newvar; |
| 505 | state->keyrows[row] = newvar; |
| 507 | 506 | } |
| 508 | | repeat = repeater; |
| 507 | state->repeat = state->repeater; |
| 509 | 508 | } |
| 510 | 509 | else |
| 511 | | if ( key && (keyrows[lastrow] & mask) && repeat == 0 ) |
| 510 | if ( state->key && (state->keyrows[state->lastrow] & state->mask) && state->repeat == 0 ) |
| 512 | 511 | { |
| 513 | | store_key(device->machine, key); |
| 512 | store_key(device->machine, state->key); |
| 514 | 513 | } |
| 515 | 514 | } |
| 516 | 515 | |
| 517 | 516 | DRIVER_INIT( microtan ) |
| 518 | 517 | { |
| 518 | microtan_state *state = machine->driver_data<microtan_state>(); |
| 519 | 519 | UINT8 *dst = memory_region(machine, "gfx2"); |
| 520 | 520 | int i; |
| 521 | 521 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| r9785 | r9786 | |
| 570 | 570 | break; |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | | microtan_timer = timer_alloc(machine, microtan_read_cassette, NULL); |
| 573 | state->timer = timer_alloc(machine, microtan_read_cassette, NULL); |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | MACHINE_RESET( microtan ) |
| 577 | 577 | { |
| 578 | | int i; |
| 578 | microtan_state *state = machine->driver_data<microtan_state>(); |
| 579 | int i; |
| 579 | 580 | static const char *const keynames[] = { "ROW0", "ROW1", "ROW2", "ROW3", "ROW4", "ROW5", "ROW6", "ROW7", "ROW8" }; |
| 580 | 581 | |
| 581 | 582 | for (i = 1; i < 10; i++) |
| 582 | 583 | { |
| 583 | | keyrows[i] = input_port_read(machine, keynames[i-1]); |
| 584 | state->keyrows[i] = input_port_read(machine, keynames[i-1]); |
| 584 | 585 | } |
| 585 | | set_led_status(machine, 1, (keyrows[3] & 0x80) ? 0 : 1); |
| 586 | set_led_status(machine, 1, (state->keyrows[3] & 0x80) ? 0 : 1); |
| 586 | 587 | } |
src/mess/machine/intv.c
| r9785 | r9786 | |
| 6 | 6 | #define INTELLIVOICE_MASK 0x02 |
| 7 | 7 | #define ECS_MASK 0x01 |
| 8 | 8 | |
| 9 | | UINT8 intv_gramdirty; |
| 10 | | UINT8 intv_gram[512]; |
| 11 | | UINT8 intv_gramdirtybytes[512]; |
| 12 | 9 | |
| 13 | | UINT16 *intvkbd_dualport_ram; |
| 14 | 10 | |
| 15 | 11 | WRITE16_HANDLER ( intvkbd_dualport16_w ) |
| 16 | 12 | { |
| 13 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 17 | 14 | unsigned char *RAM; |
| 18 | 15 | |
| 19 | | COMBINE_DATA(&intvkbd_dualport_ram[offset]); |
| 16 | COMBINE_DATA(&state->intvkbd_dualport_ram[offset]); |
| 20 | 17 | |
| 21 | 18 | /* copy the LSB over to the 6502 OP RAM, in case they are opcodes */ |
| 22 | 19 | RAM = memory_region(space->machine, "keyboard"); |
| r9785 | r9786 | |
| 25 | 22 | |
| 26 | 23 | READ8_HANDLER ( intvkbd_dualport8_lsb_r ) |
| 27 | 24 | { |
| 28 | | return (UINT8) (intvkbd_dualport_ram[offset] >> 0); |
| 25 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 26 | return (UINT8) (state->intvkbd_dualport_ram[offset] >> 0); |
| 29 | 27 | } |
| 30 | 28 | |
| 31 | 29 | WRITE8_HANDLER ( intvkbd_dualport8_lsb_w ) |
| 32 | 30 | { |
| 31 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 33 | 32 | unsigned char *RAM; |
| 34 | 33 | |
| 35 | | intvkbd_dualport_ram[offset] &= ~0x00FF; |
| 36 | | intvkbd_dualport_ram[offset] |= ((UINT16) data) << 0; |
| 34 | state->intvkbd_dualport_ram[offset] &= ~0x00FF; |
| 35 | state->intvkbd_dualport_ram[offset] |= ((UINT16) data) << 0; |
| 37 | 36 | |
| 38 | 37 | /* copy over to the 6502 OP RAM, in case they are opcodes */ |
| 39 | 38 | RAM = memory_region(space->machine, "keyboard"); |
| 40 | 39 | RAM[offset] = data; |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | | static int intvkbd_keyboard_col; |
| 44 | | static int tape_int_pending; |
| 45 | | static int sr1_int_pending; |
| 46 | 42 | |
| 47 | | int intvkbd_text_blanked; |
| 48 | 43 | |
| 49 | 44 | READ8_HANDLER ( intvkbd_dualport8_msb_r ) |
| 50 | 45 | { |
| 46 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 51 | 47 | unsigned char rv; |
| 52 | 48 | |
| 53 | 49 | if (offset < 0x100) |
| r9785 | r9786 | |
| 79 | 75 | logerror("TAPE: Read %02x from 0x40%02x - Clocked Comp (339/13)\n",rv,offset); |
| 80 | 76 | break; |
| 81 | 77 | case 0x006: |
| 82 | | if (sr1_int_pending) |
| 78 | if (state->sr1_int_pending) |
| 83 | 79 | rv = 0x00; |
| 84 | 80 | else |
| 85 | 81 | rv = 0x80; |
| 86 | 82 | logerror("TAPE: Read %02x from 0x40%02x - SR1 Int Pending\n",rv,offset); |
| 87 | 83 | break; |
| 88 | 84 | case 0x007: |
| 89 | | if (tape_int_pending) |
| 85 | if (state->tape_int_pending) |
| 90 | 86 | rv = 0x00; |
| 91 | 87 | else |
| 92 | 88 | rv = 0x80; |
| r9785 | r9786 | |
| 94 | 90 | break; |
| 95 | 91 | case 0x060: /* Keyboard Read */ |
| 96 | 92 | rv = 0xff; |
| 97 | | if (intvkbd_keyboard_col == 0) |
| 93 | if (state->intvkbd_keyboard_col == 0) |
| 98 | 94 | rv = input_port_read(space->machine, "ROW0"); |
| 99 | | if (intvkbd_keyboard_col == 1) |
| 95 | if (state->intvkbd_keyboard_col == 1) |
| 100 | 96 | rv = input_port_read(space->machine, "ROW1"); |
| 101 | | if (intvkbd_keyboard_col == 2) |
| 97 | if (state->intvkbd_keyboard_col == 2) |
| 102 | 98 | rv = input_port_read(space->machine, "ROW2"); |
| 103 | | if (intvkbd_keyboard_col == 3) |
| 99 | if (state->intvkbd_keyboard_col == 3) |
| 104 | 100 | rv = input_port_read(space->machine, "ROW3"); |
| 105 | | if (intvkbd_keyboard_col == 4) |
| 101 | if (state->intvkbd_keyboard_col == 4) |
| 106 | 102 | rv = input_port_read(space->machine, "ROW4"); |
| 107 | | if (intvkbd_keyboard_col == 5) |
| 103 | if (state->intvkbd_keyboard_col == 5) |
| 108 | 104 | rv = input_port_read(space->machine, "ROW5"); |
| 109 | | if (intvkbd_keyboard_col == 6) |
| 105 | if (state->intvkbd_keyboard_col == 6) |
| 110 | 106 | rv = input_port_read(space->machine, "ROW6"); |
| 111 | | if (intvkbd_keyboard_col == 7) |
| 107 | if (state->intvkbd_keyboard_col == 7) |
| 112 | 108 | rv = input_port_read(space->machine, "ROW7"); |
| 113 | | if (intvkbd_keyboard_col == 8) |
| 109 | if (state->intvkbd_keyboard_col == 8) |
| 114 | 110 | rv = input_port_read(space->machine, "ROW8"); |
| 115 | | if (intvkbd_keyboard_col == 9) |
| 111 | if (state->intvkbd_keyboard_col == 9) |
| 116 | 112 | rv = input_port_read(space->machine, "ROW9"); |
| 117 | 113 | break; |
| 118 | 114 | case 0x80: |
| 119 | 115 | rv = 0x00; |
| 120 | 116 | logerror("TAPE: Read %02x from 0x40%02x, clear tape int pending\n",rv,offset); |
| 121 | | tape_int_pending = 0; |
| 117 | state->tape_int_pending = 0; |
| 122 | 118 | break; |
| 123 | 119 | case 0xa0: |
| 124 | 120 | rv = 0x00; |
| 125 | 121 | logerror("TAPE: Read %02x from 0x40%02x, clear SR1 int pending\n",rv,offset); |
| 126 | | sr1_int_pending = 0; |
| 122 | state->sr1_int_pending = 0; |
| 127 | 123 | break; |
| 128 | 124 | case 0xc0: |
| 129 | 125 | case 0xc1: |
| r9785 | r9786 | |
| 145 | 141 | rv = intvkbd_tms9927_r(space, offset-0xc0); |
| 146 | 142 | break; |
| 147 | 143 | default: |
| 148 | | rv = (intvkbd_dualport_ram[offset]&0x0300)>>8; |
| 144 | rv = (state->intvkbd_dualport_ram[offset]&0x0300)>>8; |
| 149 | 145 | logerror("Unknown read %02x from 0x40%02x\n",rv,offset); |
| 150 | 146 | break; |
| 151 | 147 | } |
| 152 | 148 | return rv; |
| 153 | 149 | } |
| 154 | 150 | else |
| 155 | | return (intvkbd_dualport_ram[offset]&0x0300)>>8; |
| 151 | return (state->intvkbd_dualport_ram[offset]&0x0300)>>8; |
| 156 | 152 | } |
| 157 | 153 | |
| 158 | | static int tape_interrupts_enabled; |
| 159 | | static int tape_unknown_write[6]; |
| 160 | | static int tape_motor_mode; |
| 161 | 154 | static const char *const tape_motor_mode_desc[8] = |
| 162 | 155 | { |
| 163 | 156 | "IDLE", "IDLE", "IDLE", "IDLE", |
| r9785 | r9786 | |
| 166 | 159 | |
| 167 | 160 | WRITE8_HANDLER ( intvkbd_dualport8_msb_w ) |
| 168 | 161 | { |
| 162 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 169 | 163 | unsigned int mask; |
| 170 | 164 | |
| 171 | 165 | if (offset < 0x100) |
| r9785 | r9786 | |
| 173 | 167 | switch (offset) |
| 174 | 168 | { |
| 175 | 169 | case 0x020: |
| 176 | | tape_motor_mode &= 3; |
| 170 | state->tape_motor_mode &= 3; |
| 177 | 171 | if (data & 1) |
| 178 | | tape_motor_mode |= 4; |
| 179 | | logerror("TAPE: Motor Mode: %s\n",tape_motor_mode_desc[tape_motor_mode]); |
| 172 | state->tape_motor_mode |= 4; |
| 173 | logerror("TAPE: Motor Mode: %s\n",tape_motor_mode_desc[state->tape_motor_mode]); |
| 180 | 174 | break; |
| 181 | 175 | case 0x021: |
| 182 | | tape_motor_mode &= 5; |
| 176 | state->tape_motor_mode &= 5; |
| 183 | 177 | if (data & 1) |
| 184 | | tape_motor_mode |= 2; |
| 185 | | logerror("TAPE: Motor Mode: %s\n",tape_motor_mode_desc[tape_motor_mode]); |
| 178 | state->tape_motor_mode |= 2; |
| 179 | logerror("TAPE: Motor Mode: %s\n",tape_motor_mode_desc[state->tape_motor_mode]); |
| 186 | 180 | break; |
| 187 | 181 | case 0x022: |
| 188 | | tape_motor_mode &= 6; |
| 182 | state->tape_motor_mode &= 6; |
| 189 | 183 | if (data & 1) |
| 190 | | tape_motor_mode |= 1; |
| 191 | | logerror("TAPE: Motor Mode: %s\n",tape_motor_mode_desc[tape_motor_mode]); |
| 184 | state->tape_motor_mode |= 1; |
| 185 | logerror("TAPE: Motor Mode: %s\n",tape_motor_mode_desc[state->tape_motor_mode]); |
| 192 | 186 | break; |
| 193 | 187 | case 0x023: |
| 194 | 188 | case 0x024: |
| 195 | 189 | case 0x025: |
| 196 | 190 | case 0x026: |
| 197 | 191 | case 0x027: |
| 198 | | tape_unknown_write[offset - 0x23] = (data & 1); |
| 192 | state->tape_unknown_write[offset - 0x23] = (data & 1); |
| 199 | 193 | break; |
| 200 | 194 | case 0x040: |
| 201 | | tape_unknown_write[5] = (data & 1); |
| 195 | state->tape_unknown_write[5] = (data & 1); |
| 202 | 196 | break; |
| 203 | 197 | case 0x041: |
| 204 | 198 | if (data & 1) |
| 205 | 199 | logerror("TAPE: Tape Interrupts Enabled\n"); |
| 206 | 200 | else |
| 207 | 201 | logerror("TAPE: Tape Interrupts Disabled\n"); |
| 208 | | tape_interrupts_enabled = (data & 1); |
| 202 | state->tape_interrupts_enabled = (data & 1); |
| 209 | 203 | break; |
| 210 | 204 | case 0x042: |
| 211 | 205 | if (data & 1) |
| r9785 | r9786 | |
| 215 | 209 | break; |
| 216 | 210 | case 0x043: |
| 217 | 211 | if (data & 0x01) |
| 218 | | intvkbd_text_blanked = 0; |
| 212 | state->intvkbd_text_blanked = 0; |
| 219 | 213 | else |
| 220 | | intvkbd_text_blanked = 1; |
| 214 | state->intvkbd_text_blanked = 1; |
| 221 | 215 | break; |
| 222 | 216 | case 0x044: |
| 223 | | intvkbd_keyboard_col &= 0x0e; |
| 224 | | intvkbd_keyboard_col |= (data&0x01); |
| 217 | state->intvkbd_keyboard_col &= 0x0e; |
| 218 | state->intvkbd_keyboard_col |= (data&0x01); |
| 225 | 219 | break; |
| 226 | 220 | case 0x045: |
| 227 | | intvkbd_keyboard_col &= 0x0d; |
| 228 | | intvkbd_keyboard_col |= ((data&0x01)<<1); |
| 221 | state->intvkbd_keyboard_col &= 0x0d; |
| 222 | state->intvkbd_keyboard_col |= ((data&0x01)<<1); |
| 229 | 223 | break; |
| 230 | 224 | case 0x046: |
| 231 | | intvkbd_keyboard_col &= 0x0b; |
| 232 | | intvkbd_keyboard_col |= ((data&0x01)<<2); |
| 225 | state->intvkbd_keyboard_col &= 0x0b; |
| 226 | state->intvkbd_keyboard_col |= ((data&0x01)<<2); |
| 233 | 227 | break; |
| 234 | 228 | case 0x047: |
| 235 | | intvkbd_keyboard_col &= 0x07; |
| 236 | | intvkbd_keyboard_col |= ((data&0x01)<<3); |
| 229 | state->intvkbd_keyboard_col &= 0x07; |
| 230 | state->intvkbd_keyboard_col |= ((data&0x01)<<3); |
| 237 | 231 | break; |
| 238 | 232 | case 0x80: |
| 239 | 233 | logerror("TAPE: Write to 0x40%02x, clear tape int pending\n",offset); |
| 240 | | tape_int_pending = 0; |
| 234 | state->tape_int_pending = 0; |
| 241 | 235 | break; |
| 242 | 236 | case 0xa0: |
| 243 | 237 | logerror("TAPE: Write to 0x40%02x, clear SR1 int pending\n",offset); |
| 244 | | sr1_int_pending = 0; |
| 238 | state->sr1_int_pending = 0; |
| 245 | 239 | break; |
| 246 | 240 | case 0xc0: |
| 247 | 241 | case 0xc1: |
| r9785 | r9786 | |
| 269 | 263 | } |
| 270 | 264 | else |
| 271 | 265 | { |
| 272 | | mask = intvkbd_dualport_ram[offset] & 0x00ff; |
| 273 | | intvkbd_dualport_ram[offset] = mask | ((data<<8)&0x0300); |
| 266 | mask = state->intvkbd_dualport_ram[offset] & 0x00ff; |
| 267 | state->intvkbd_dualport_ram[offset] = mask | ((data<<8)&0x0300); |
| 274 | 268 | } |
| 275 | 269 | } |
| 276 | 270 | |
| 277 | 271 | READ16_HANDLER( intv_gram_r ) |
| 278 | 272 | { |
| 279 | | //logerror("read: %d = GRAM(%d)\n",intv_gram[offset],offset); |
| 280 | | return (int)intv_gram[offset]; |
| 273 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 274 | //logerror("read: %d = GRAM(%d)\n",state->gram[offset],offset); |
| 275 | return (int)state->gram[offset]; |
| 281 | 276 | } |
| 282 | 277 | |
| 283 | 278 | WRITE16_HANDLER( intv_gram_w ) |
| 284 | 279 | { |
| 280 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 285 | 281 | data &= 0xFF; |
| 286 | 282 | |
| 287 | | intv_gram[offset] = data; |
| 288 | | intv_gramdirtybytes[offset] = 1; |
| 289 | | intv_gramdirty = 1; |
| 283 | state->gram[offset] = data; |
| 284 | state->gramdirtybytes[offset] = 1; |
| 285 | state->gramdirty = 1; |
| 290 | 286 | } |
| 291 | 287 | |
| 292 | | static unsigned char intv_ram8[256]; |
| 293 | 288 | |
| 294 | 289 | READ16_HANDLER( intv_ram8_r ) |
| 295 | 290 | { |
| 296 | | //logerror("%x = ram8_r(%x)\n",intv_ram8[offset],offset); |
| 297 | | return (int)intv_ram8[offset]; |
| 291 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 292 | //logerror("%x = ram8_r(%x)\n",state->ram8[offset],offset); |
| 293 | return (int)state->ram8[offset]; |
| 298 | 294 | } |
| 299 | 295 | |
| 300 | 296 | WRITE16_HANDLER( intv_ram8_w ) |
| 301 | 297 | { |
| 298 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 302 | 299 | //logerror("ram8_w(%x) = %x\n",offset,data); |
| 303 | | intv_ram8[offset] = data&0xff; |
| 300 | state->ram8[offset] = data&0xff; |
| 304 | 301 | } |
| 305 | 302 | |
| 306 | | UINT16 intv_ram16[0x160]; |
| 307 | 303 | |
| 308 | 304 | READ16_HANDLER( intv_ram16_r ) |
| 309 | 305 | { |
| 310 | | //logerror("%x = ram16_r(%x)\n",intv_ram16[offset],offset); |
| 311 | | return (int)intv_ram16[offset]; |
| 306 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 307 | //logerror("%x = ram16_r(%x)\n",state->ram16[offset],offset); |
| 308 | return (int)state->ram16[offset]; |
| 312 | 309 | } |
| 313 | 310 | |
| 314 | 311 | WRITE16_HANDLER( intv_ram16_w ) |
| 315 | 312 | { |
| 313 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 316 | 314 | //logerror("%g: WRITING TO GRAM offset = %d\n",timer_get_time(machine),offset); |
| 317 | 315 | //logerror("ram16_w(%x) = %x\n",offset,data); |
| 318 | | intv_ram16[offset] = data&0xffff; |
| 316 | state->ram16[offset] = data&0xffff; |
| 319 | 317 | } |
| 320 | 318 | |
| 321 | 319 | static int intv_load_rom_file(device_image_interface &image) |
| r9785 | r9786 | |
| 497 | 495 | |
| 498 | 496 | INTERRUPT_GEN( intv_interrupt ) |
| 499 | 497 | { |
| 498 | intv_state *state = device->machine->driver_data<intv_state>(); |
| 500 | 499 | cputag_set_input_line(device->machine, "maincpu", CP1610_INT_INTRM, ASSERT_LINE); |
| 501 | | sr1_int_pending = 1; |
| 500 | state->sr1_int_pending = 1; |
| 502 | 501 | timer_set(device->machine, device->machine->device<cpu_device>("maincpu")->cycles_to_attotime(3791), NULL, 0, intv_interrupt_complete); |
| 503 | 502 | intv_stic_screenrefresh(device->machine); |
| 504 | 503 | } |
src/mess/video/intv.c
| r9785 | r9786 | |
| 4 | 4 | #define FOREGROUND_BIT 0x0010 |
| 5 | 5 | |
| 6 | 6 | /* initialized to non-zero, because we divide by it */ |
| 7 | | static UINT8 tms9927_num_rows; |
| 8 | 7 | |
| 9 | 8 | INLINE void intv_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color) |
| 10 | 9 | { |
| r9785 | r9786 | |
| 13 | 12 | |
| 14 | 13 | VIDEO_START( intv ) |
| 15 | 14 | { |
| 15 | intv_state *state = machine->driver_data<intv_state>(); |
| 16 | 16 | //int i,j,k; |
| 17 | 17 | |
| 18 | | tms9927_num_rows = 25; |
| 18 | state->tms9927_num_rows = 25; |
| 19 | 19 | VIDEO_START_CALL(generic_bitmapped); |
| 20 | 20 | |
| 21 | 21 | #if 0 |
| 22 | 22 | for (i = 0; i < 8; i++) { |
| 23 | | struct intv_sprite_type* s = &intv_sprite[i]; |
| 23 | intv_sprite_type* s = &state->sprite[i]; |
| 24 | 24 | s->visible = 0; |
| 25 | 25 | s->xpos = 0; |
| 26 | 26 | s->ypos = 0; |
| r9785 | r9786 | |
| 39 | 39 | s->dirty = 1; |
| 40 | 40 | for (j = 0; j < 16; j++) { |
| 41 | 41 | for (k = 0; k < 128; k++) { |
| 42 | | intv_sprite_buffers[i][j][k] = 0; |
| 42 | state->sprite_buffers[i][j][k] = 0; |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | | intv_collision_registers[i] = 0; |
| 45 | state->collision_registers[i] = 0; |
| 46 | 46 | } |
| 47 | 47 | for(i = 0; i < 4; i++) { |
| 48 | | intv_color_stack[i] = 0; |
| 48 | state->color_stack[i] = 0; |
| 49 | 49 | } |
| 50 | | intv_color_stack_mode = 0; |
| 51 | | intv_color_stack_offset = 0; |
| 52 | | intv_stic_handshake = 0; |
| 53 | | intv_border_color = 0; |
| 54 | | intv_col_delay = 0; |
| 55 | | intv_row_delay = 0; |
| 56 | | intv_left_edge_inhibit = 0; |
| 57 | | intv_top_edge_inhibit = 0; |
| 50 | state->color_stack_mode = 0; |
| 51 | state->color_stack_offset = 0; |
| 52 | state->stic_handshake = 0; |
| 53 | state->border_color = 0; |
| 54 | state->col_delay = 0; |
| 55 | state->row_delay = 0; |
| 56 | state->left_edge_inhibit = 0; |
| 57 | state->top_edge_inhibit = 0; |
| 58 | 58 | |
| 59 | | intv_gramdirty = 1; |
| 59 | state->gramdirty = 1; |
| 60 | 60 | for(i=0;i<64;i++) { |
| 61 | | intv_gram[i] = 0; |
| 62 | | intv_gramdirtybytes[i] = 1; |
| 61 | state->gram[i] = 0; |
| 62 | state->gramdirtybytes[i] = 1; |
| 63 | 63 | } |
| 64 | 64 | #endif |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
| 68 | | static int sprites_collide(int spriteNum0, int spriteNum1) { |
| 68 | static int sprites_collide(intv_state *state, int spriteNum0, int spriteNum1) { |
| 69 | 69 | INT16 x1, x2, y1, y2, w1, w2, h1, h2, x0, y0, r0y, r1y, |
| 70 | 70 | width, height, x, y; |
| 71 | 71 | |
| 72 | | struct intv_sprite_type* s1 = &intv_sprite[spriteNum0]; |
| 73 | | struct intv_sprite_type* s2 = &intv_sprite[spriteNum1]; |
| 72 | intv_sprite_type* s1 = &state->sprite[spriteNum0]; |
| 73 | intv_sprite_type* s2 = &state->sprite[spriteNum1]; |
| 74 | 74 | |
| 75 | 75 | x1 = s1->xpos-8; x2 = s2->xpos-8; |
| 76 | 76 | y1 = (s1->ypos-8)<<1; y2 = (s2->ypos-8)<<1; |
| r9785 | r9786 | |
| 92 | 92 | height = MIN(y1+h1, y2+h2) - y0; |
| 93 | 93 | for (x = 0; x < width; x++) { |
| 94 | 94 | for (y = 0; y < height; y++) { |
| 95 | | if (intv_sprite_buffers[spriteNum0][x0-x1+x][r0y+y] && |
| 96 | | intv_sprite_buffers[spriteNum1][x0-x2+x][r1y+y]) |
| 95 | if (state->sprite_buffers[spriteNum0][x0-x1+x][r0y+y] && |
| 96 | state->sprite_buffers[spriteNum1][x0-x2+x][r1y+y]) |
| 97 | 97 | return TRUE; |
| 98 | 98 | } |
| 99 | 99 | } |
| r9785 | r9786 | |
| 101 | 101 | return FALSE; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | | static void determine_sprite_collisions(void) |
| 104 | static void determine_sprite_collisions(intv_state *state) |
| 105 | 105 | { |
| 106 | 106 | //check sprite to sprite collisions |
| 107 | 107 | int i, j; |
| 108 | 108 | for (i = 0; i < 7; i++) { |
| 109 | | struct intv_sprite_type* s1 = &intv_sprite[i]; |
| 109 | intv_sprite_type* s1 = &state->sprite[i]; |
| 110 | 110 | if (s1->xpos == 0 || !s1->coll) |
| 111 | 111 | continue; |
| 112 | 112 | |
| 113 | 113 | for (j = i+1; j < 8; j++) { |
| 114 | | struct intv_sprite_type* s2 = &intv_sprite[j]; |
| 114 | intv_sprite_type* s2 = &state->sprite[j]; |
| 115 | 115 | if (s2->xpos == 0 || !s2->coll) |
| 116 | 116 | continue; |
| 117 | 117 | |
| 118 | | if (sprites_collide(i, j)) { |
| 118 | if (sprites_collide(state, i, j)) { |
| 119 | 119 | s1->collision |= (1 << j); |
| 120 | 120 | s2->collision |= (1 << i); |
| 121 | 121 | } |
| r9785 | r9786 | |
| 125 | 125 | |
| 126 | 126 | static void render_sprites(running_machine *machine) |
| 127 | 127 | { |
| 128 | intv_state *state = machine->driver_data<intv_state>(); |
| 128 | 129 | INT32 cardMemoryLocation, pixelSize; |
| 129 | 130 | INT32 spritePixelHeight; |
| 130 | 131 | INT32 nextMemoryLocation; |
| r9785 | r9786 | |
| 137 | 138 | UINT8* memory = memory_region(machine, "maincpu"); |
| 138 | 139 | |
| 139 | 140 | for (i = 0; i < 8; i++) { |
| 140 | | struct intv_sprite_type* s = &intv_sprite[i]; |
| 141 | intv_sprite_type* s = &state->sprite[i]; |
| 141 | 142 | |
| 142 | 143 | if (s->grom) |
| 143 | 144 | cardMemoryLocation = (s->card << 3); |
| r9785 | r9786 | |
| 152 | 153 | if (s->grom) |
| 153 | 154 | nextData = memory[(0x3000+nextMemoryLocation)<<1]; |
| 154 | 155 | else if (nextMemoryLocation < 0x200) |
| 155 | | nextData = intv_gram[nextMemoryLocation]; |
| 156 | nextData = state->gram[nextMemoryLocation]; |
| 156 | 157 | else |
| 157 | 158 | nextData = 0xFFFF; |
| 158 | 159 | nextX = (s->xflip ? (s->doublex ? 15 : 7) : 0); |
| 159 | 160 | nextY = (s->yflip ? (spritePixelHeight - j - 1) : j); |
| 160 | 161 | xInc = (s->xflip ? -1: 1); |
| 161 | | intv_sprite_buffers[i][nextX][nextY] = ((nextData & 0x0080) != 0); |
| 162 | | intv_sprite_buffers[i][nextX + xInc][nextY] = (s->doublex |
| 162 | state->sprite_buffers[i][nextX][nextY] = ((nextData & 0x0080) != 0); |
| 163 | state->sprite_buffers[i][nextX + xInc][nextY] = (s->doublex |
| 163 | 164 | ? ((nextData & 0x0080) != 0) |
| 164 | 165 | : ((nextData & 0x0040) != 0)); |
| 165 | | intv_sprite_buffers[i][nextX + (2*xInc)][nextY] = (s->doublex |
| 166 | state->sprite_buffers[i][nextX + (2*xInc)][nextY] = (s->doublex |
| 166 | 167 | ? ((nextData & 0x0040) != 0) |
| 167 | 168 | : ((nextData & 0x0020) != 0)); |
| 168 | | intv_sprite_buffers[i][nextX + (3*xInc)][nextY] = (s->doublex |
| 169 | state->sprite_buffers[i][nextX + (3*xInc)][nextY] = (s->doublex |
| 169 | 170 | ? ((nextData & 0x0040) != 0) |
| 170 | 171 | : ((nextData & 0x0010) != 0)); |
| 171 | | intv_sprite_buffers[i][nextX + (4*xInc)][nextY] = (s->doublex |
| 172 | state->sprite_buffers[i][nextX + (4*xInc)][nextY] = (s->doublex |
| 172 | 173 | ? ((nextData & 0x0020) != 0) |
| 173 | 174 | : ((nextData & 0x0008) != 0)); |
| 174 | | intv_sprite_buffers[i][nextX + (5*xInc)][nextY] = (s->doublex |
| 175 | state->sprite_buffers[i][nextX + (5*xInc)][nextY] = (s->doublex |
| 175 | 176 | ? ((nextData & 0x0020) != 0) |
| 176 | 177 | : ((nextData & 0x0004) != 0)); |
| 177 | | intv_sprite_buffers[i][nextX + (6*xInc)][nextY] = (s->doublex |
| 178 | state->sprite_buffers[i][nextX + (6*xInc)][nextY] = (s->doublex |
| 178 | 179 | ? ((nextData & 0x0010) != 0) |
| 179 | 180 | : ((nextData & 0x0002) != 0)); |
| 180 | | intv_sprite_buffers[i][nextX + (7*xInc)][nextY] = (s->doublex |
| 181 | state->sprite_buffers[i][nextX + (7*xInc)][nextY] = (s->doublex |
| 181 | 182 | ? ((nextData & 0x0010) != 0) |
| 182 | 183 | : ((nextData & 0x0001) != 0)); |
| 183 | 184 | if (!s->doublex) |
| 184 | 185 | continue; |
| 185 | 186 | |
| 186 | | intv_sprite_buffers[i][nextX + (8*xInc)][nextY] = |
| 187 | state->sprite_buffers[i][nextX + (8*xInc)][nextY] = |
| 187 | 188 | ((nextData & 0x0008) != 0); |
| 188 | | intv_sprite_buffers[i][nextX + (9*xInc)][nextY] = |
| 189 | state->sprite_buffers[i][nextX + (9*xInc)][nextY] = |
| 189 | 190 | ((nextData & 0x0008) != 0); |
| 190 | | intv_sprite_buffers[i][nextX + (10*xInc)][nextY] = |
| 191 | state->sprite_buffers[i][nextX + (10*xInc)][nextY] = |
| 191 | 192 | ((nextData & 0x0004) != 0); |
| 192 | | intv_sprite_buffers[i][nextX + (11*xInc)][nextY] = |
| 193 | state->sprite_buffers[i][nextX + (11*xInc)][nextY] = |
| 193 | 194 | ((nextData & 0x0004) != 0); |
| 194 | | intv_sprite_buffers[i][nextX + (12*xInc)][nextY] = |
| 195 | state->sprite_buffers[i][nextX + (12*xInc)][nextY] = |
| 195 | 196 | ((nextData & 0x0002) != 0); |
| 196 | | intv_sprite_buffers[i][nextX + (13*xInc)][nextY] = |
| 197 | state->sprite_buffers[i][nextX + (13*xInc)][nextY] = |
| 197 | 198 | ((nextData & 0x0002) != 0); |
| 198 | | intv_sprite_buffers[i][nextX + (14*xInc)][nextY] = |
| 199 | state->sprite_buffers[i][nextX + (14*xInc)][nextY] = |
| 199 | 200 | ((nextData & 0x0001) != 0); |
| 200 | | intv_sprite_buffers[i][nextX + (15*xInc)][nextY] = |
| 201 | state->sprite_buffers[i][nextX + (15*xInc)][nextY] = |
| 201 | 202 | ((nextData & 0x0001) != 0); |
| 202 | 203 | } |
| 203 | 204 | |
| r9785 | r9786 | |
| 267 | 268 | |
| 268 | 269 | static void render_color_stack_mode(running_machine *machine, bitmap_t *bitmap) |
| 269 | 270 | { |
| 271 | intv_state *state = machine->driver_data<intv_state>(); |
| 270 | 272 | UINT8 h, csPtr = 0, nexty = 0; |
| 271 | 273 | UINT16 nextCard, nextx = 0; |
| 272 | 274 | UINT8 *ram = memory_region(machine, "maincpu"); |
| 273 | 275 | |
| 274 | 276 | for (h = 0; h < 240; h++) { |
| 275 | | nextCard = intv_ram16[h]; |
| 277 | nextCard = state->ram16[h]; |
| 276 | 278 | |
| 277 | 279 | //colored squares mode |
| 278 | 280 | if ((nextCard & 0x1800) == 0x1000) { |
| 279 | | UINT8 csColor = intv_color_stack[csPtr]; |
| 281 | UINT8 csColor = state->color_stack[csPtr]; |
| 280 | 282 | UINT8 color0 = nextCard & 0x0007; |
| 281 | 283 | UINT8 color1 = (nextCard & 0x0038) >> 3; |
| 282 | 284 | UINT8 color2 = (nextCard & 0x01C0) >> 6; |
| r9785 | r9786 | |
| 300 | 302 | |
| 301 | 303 | fgcolor = ((nextCard & 0x1000) >> 9) | |
| 302 | 304 | (nextCard & 0x0007) | FOREGROUND_BIT; |
| 303 | | bgcolor = intv_color_stack[csPtr] & 0x0F; |
| 305 | bgcolor = state->color_stack[csPtr] & 0x0F; |
| 304 | 306 | |
| 305 | 307 | isGrom = !(nextCard & 0x0800); |
| 306 | 308 | if (isGrom) { |
| r9785 | r9786 | |
| 312 | 314 | } |
| 313 | 315 | else { |
| 314 | 316 | memoryLocation = (nextCard & 0x01F8); |
| 315 | | memory = intv_gram; |
| 317 | memory = state->gram; |
| 316 | 318 | for (j = 0; j < 16; j+=2) |
| 317 | 319 | render_line(machine, bitmap, memory[memoryLocation+(j>>1)], |
| 318 | 320 | nextx, nexty+j, fgcolor, bgcolor); |
| r9785 | r9786 | |
| 328 | 330 | |
| 329 | 331 | static void render_fg_bg_mode(running_machine *machine, bitmap_t *bitmap) |
| 330 | 332 | { |
| 333 | intv_state *state = machine->driver_data<intv_state>(); |
| 331 | 334 | UINT8 i, j, isGrom, fgcolor, bgcolor, nexty = 0; |
| 332 | 335 | UINT16 nextCard, memoryLocation, nextx = 0; |
| 333 | 336 | UINT8* memory; |
| 334 | 337 | UINT8* ram = memory_region(machine, "maincpu"); |
| 335 | 338 | |
| 336 | 339 | for (i = 0; i < 240; i++) { |
| 337 | | nextCard = intv_ram16[i]; |
| 340 | nextCard = state->ram16[i]; |
| 338 | 341 | fgcolor = (nextCard & 0x0007) | FOREGROUND_BIT; |
| 339 | 342 | bgcolor = ((nextCard & 0x2000) >> 11) | |
| 340 | 343 | ((nextCard & 0x1600) >> 9); |
| r9785 | r9786 | |
| 349 | 352 | } |
| 350 | 353 | else { |
| 351 | 354 | memoryLocation = (nextCard & 0x01F8); |
| 352 | | memory = intv_gram; |
| 355 | memory = state->gram; |
| 353 | 356 | for (j = 0; j < 16; j+=2) |
| 354 | 357 | render_line(machine, bitmap, memory[memoryLocation+(j>>1)], |
| 355 | 358 | nextx, nexty+j, fgcolor, bgcolor); |
| r9785 | r9786 | |
| 365 | 368 | |
| 366 | 369 | static void copy_sprites_to_background(running_machine *machine, bitmap_t *bitmap) |
| 367 | 370 | { |
| 371 | intv_state *state = machine->driver_data<intv_state>(); |
| 368 | 372 | UINT8 width, currentPixel; |
| 369 | 373 | UINT8 borderCollision, foregroundCollision; |
| 370 | 374 | UINT8 spritePixelHeight, x, y; |
| r9785 | r9786 | |
| 372 | 376 | INT32 nextX; |
| 373 | 377 | |
| 374 | 378 | for (i = 7; i >= 0; i--) { |
| 375 | | struct intv_sprite_type *s = &intv_sprite[i]; |
| 379 | intv_sprite_type *s = &state->sprite[i]; |
| 376 | 380 | if (s->xpos == 0 || |
| 377 | 381 | (!s->coll && !s->visible)) |
| 378 | 382 | continue; |
| r9785 | r9786 | |
| 390 | 394 | for (y = 0; y < spritePixelHeight; y++) { |
| 391 | 395 | for (x = 0; x < width; x++) { |
| 392 | 396 | //if this sprite pixel is not on, then don't paint it |
| 393 | | if (!intv_sprite_buffers[i][x][y]) |
| 397 | if (!state->sprite_buffers[i][x][y]) |
| 394 | 398 | continue; |
| 395 | 399 | |
| 396 | 400 | nextX = leftX + (x<<1); |
| 397 | 401 | //if the next pixel location is on the border, then we |
| 398 | 402 | //have a border collision and we can ignore painting it |
| 399 | | if (nextX < (intv_row_delay ? 8 : 0) || nextX > 317 || |
| 400 | | nextY < (intv_col_delay ? 16 : 0) || nextY > 191) |
| 403 | if (nextX < (state->row_delay ? 8 : 0) || nextX > 317 || |
| 404 | nextY < (state->col_delay ? 16 : 0) || nextY > 191) |
| 401 | 405 | { |
| 402 | 406 | borderCollision = TRUE; |
| 403 | 407 | continue; |
| r9785 | r9786 | |
| 432 | 436 | |
| 433 | 437 | static void render_background(running_machine *machine, bitmap_t *bitmap) |
| 434 | 438 | { |
| 435 | | if (intv_color_stack_mode) |
| 439 | intv_state *state = machine->driver_data<intv_state>(); |
| 440 | if (state->color_stack_mode) |
| 436 | 441 | render_color_stack_mode(machine, bitmap); |
| 437 | 442 | else |
| 438 | 443 | render_fg_bg_mode(machine, bitmap); |
| r9785 | r9786 | |
| 441 | 446 | #ifdef UNUSED_CODE |
| 442 | 447 | static void draw_background(running_machine *machine, bitmap_t *bitmap, int transparency) |
| 443 | 448 | { |
| 449 | intv_state *state = machine->driver_data<intv_state>(); |
| 444 | 450 | // First, draw the background |
| 445 | 451 | int offs = 0; |
| 446 | 452 | int value = 0; |
| r9785 | r9786 | |
| 456 | 462 | |
| 457 | 463 | int j; |
| 458 | 464 | |
| 459 | | if (intv_color_stack_mode == 1) |
| 465 | if (state->color_stack_mode == 1) |
| 460 | 466 | { |
| 461 | | intv_color_stack_offset = 0; |
| 467 | state->color_stack_offset = 0; |
| 462 | 468 | for(row = 0; row < 12; row++) |
| 463 | 469 | { |
| 464 | 470 | for(col = 0; col < 20; col++) |
| 465 | 471 | { |
| 466 | | value = intv_ram16[offs]; |
| 472 | value = state->ram16[offs]; |
| 467 | 473 | |
| 468 | 474 | n_bit = value & 0x2000; |
| 469 | 475 | p_bit = value & 0x1000; |
| r9785 | r9786 | |
| 476 | 482 | colorc = (value>>6)&0x7; |
| 477 | 483 | colord = ((n_bit>>11)&0x4) + ((value>>9)&0x3); |
| 478 | 484 | // color 7 if the top of the color stack in this mode |
| 479 | | if (colora == 7) colora = intv_color_stack[3]; |
| 480 | | if (colorb == 7) colorb = intv_color_stack[3]; |
| 481 | | if (colorc == 7) colorc = intv_color_stack[3]; |
| 482 | | if (colord == 7) colord = intv_color_stack[3]; |
| 485 | if (colora == 7) colora = state->color_stack[3]; |
| 486 | if (colorb == 7) colorb = state->color_stack[3]; |
| 487 | if (colorc == 7) colorc = state->color_stack[3]; |
| 488 | if (colord == 7) colord = state->color_stack[3]; |
| 483 | 489 | plot_box(bitmap,col*16,row*16,8,8,(colora<<1)+1); |
| 484 | 490 | plot_box(bitmap,col*16+8,row*16,8,8,(colorb<<1)+1); |
| 485 | 491 | plot_box(bitmap,col*16,row*16+8,8,8,(colorc<<1)+1); |
| r9785 | r9786 | |
| 489 | 495 | { |
| 490 | 496 | if (n_bit) // next color |
| 491 | 497 | { |
| 492 | | intv_color_stack_offset += 1; |
| 493 | | intv_color_stack_offset &= 3; |
| 498 | state->color_stack_offset += 1; |
| 499 | state->color_stack_offset &= 3; |
| 494 | 500 | } |
| 495 | 501 | |
| 496 | 502 | if (p_bit) // pastel color set |
| r9785 | r9786 | |
| 498 | 504 | else |
| 499 | 505 | fgcolor = value&0x7; |
| 500 | 506 | |
| 501 | | bgcolor = intv_color_stack[intv_color_stack_offset]; |
| 507 | bgcolor = state->color_stack[state->color_stack_offset]; |
| 502 | 508 | code = (value>>3)&0xff; |
| 503 | 509 | |
| 504 | 510 | if (g_bit) // read from gram |
| 505 | 511 | { |
| 506 | 512 | code %= 64; // keep from going outside the array |
| 507 | | //if (intv_gramdirtybytes[code] == 1) |
| 513 | //if (state->gramdirtybytes[code] == 1) |
| 508 | 514 | { |
| 509 | 515 | decodechar(machine->gfx[1], |
| 510 | 516 | code, |
| 511 | | intv_gram, |
| 517 | state->gram, |
| 512 | 518 | machine->config->gfxdecodeinfo[1].gfxlayout); |
| 513 | | intv_gramdirtybytes[code] = 0; |
| 519 | state->gramdirtybytes[code] = 0; |
| 514 | 520 | } |
| 515 | 521 | // Draw GRAM char |
| 516 | 522 | drawgfx(bitmap,machine->gfx[1], |
| r9785 | r9786 | |
| 552 | 558 | { |
| 553 | 559 | for(col = 0; col < 20; col++) |
| 554 | 560 | { |
| 555 | | value = intv_ram16[offs]; |
| 561 | value = state->ram16[offs]; |
| 556 | 562 | fgcolor = value & 0x07; |
| 557 | 563 | bgcolor = ((value & 0x2000)>>11)+((value & 0x1600)>>9); |
| 558 | 564 | code = (value & 0x01f8)>>3; |
| 559 | 565 | |
| 560 | 566 | if (value & 0x0800) // read for GRAM |
| 561 | 567 | { |
| 562 | | //if (intv_gramdirtybytes[code] == 1) |
| 568 | //if (state->gramdirtybytes[code] == 1) |
| 563 | 569 | { |
| 564 | 570 | decodechar(machine->gfx[1], |
| 565 | 571 | code, |
| 566 | | intv_gram, |
| 572 | state->gram, |
| 567 | 573 | machine->config->gfxdecodeinfo[1].gfxlayout); |
| 568 | | intv_gramdirtybytes[code] = 0; |
| 574 | state->gramdirtybytes[code] = 0; |
| 569 | 575 | } |
| 570 | 576 | // Draw GRAM char |
| 571 | 577 | drawgfx(bitmap,machine->gfx[1], |
| r9785 | r9786 | |
| 593 | 599 | #ifdef UNUSED_FUNCTION |
| 594 | 600 | static void draw_sprites(running_machine *machine, bitmap_t *bitmap, int behind_foreground) |
| 595 | 601 | { |
| 602 | intv_state *state = machine->driver_data<intv_state>(); |
| 596 | 603 | int i; |
| 597 | 604 | int code; |
| 598 | 605 | |
| 599 | 606 | for(i=7;i>=0;--i) |
| 600 | 607 | { |
| 601 | | struct intv_sprite_type *s = &intv_sprite[i]; |
| 608 | intv_sprite_type *s = &state->sprite[i]; |
| 602 | 609 | if (s->visible && (s->behind_foreground == behind_foreground)) |
| 603 | 610 | { |
| 604 | 611 | code = s->card; |
| r9785 | r9786 | |
| 607 | 614 | code %= 64; // keep from going outside the array |
| 608 | 615 | if (s->yres == 1) |
| 609 | 616 | { |
| 610 | | //if (intv_gramdirtybytes[code] == 1) |
| 617 | //if (state->gramdirtybytes[code] == 1) |
| 611 | 618 | { |
| 612 | 619 | decodechar(machine->gfx[1], |
| 613 | 620 | code, |
| 614 | | intv_gram, |
| 621 | state->gram, |
| 615 | 622 | machine->config->gfxdecodeinfo[1].gfxlayout); |
| 616 | | intv_gramdirtybytes[code] = 0; |
| 623 | state->gramdirtybytes[code] = 0; |
| 617 | 624 | } |
| 618 | 625 | // Draw GRAM char |
| 619 | 626 | drawgfxzoom_transpen(bitmap,&machine->screen[0].visarea,machine->gfx[1], |
| r9785 | r9786 | |
| 625 | 632 | } |
| 626 | 633 | else |
| 627 | 634 | { |
| 628 | | //if ((intv_gramdirtybytes[code] == 1) || (intv_gramdirtybytes[code+1] == 1)) |
| 635 | //if ((state->gramdirtybytes[code] == 1) || (state->gramdirtybytes[code+1] == 1)) |
| 629 | 636 | { |
| 630 | 637 | decodechar(machine->gfx[1], |
| 631 | 638 | code, |
| 632 | | intv_gram, |
| 639 | state->gram, |
| 633 | 640 | machine->config->gfxdecodeinfo[1].gfxlayout); |
| 634 | 641 | decodechar(machine->gfx[1], |
| 635 | 642 | code+1, |
| 636 | | intv_gram, |
| 643 | state->gram, |
| 637 | 644 | machine->config->gfxdecodeinfo[1].gfxlayout); |
| 638 | | intv_gramdirtybytes[code] = 0; |
| 639 | | intv_gramdirtybytes[code+1] = 0; |
| 645 | state->gramdirtybytes[code] = 0; |
| 646 | state->gramdirtybytes[code+1] = 0; |
| 640 | 647 | } |
| 641 | 648 | // Draw GRAM char |
| 642 | 649 | drawgfxzoom_transpen(bitmap,&machine->screen[0].visarea,machine->gfx[1], |
| r9785 | r9786 | |
| 688 | 695 | |
| 689 | 696 | static void draw_borders(running_machine *machine, bitmap_t *bm) |
| 690 | 697 | { |
| 691 | | if (intv_left_edge_inhibit) |
| 692 | | plot_box(bm, 0, 0, 16-intv_col_delay*2, 16*12, (intv_border_color<<1)+1); |
| 698 | intv_state *state = machine->driver_data<intv_state>(); |
| 699 | if (state->left_edge_inhibit) |
| 700 | plot_box(bm, 0, 0, 16-state->col_delay*2, 16*12, (state->border_color<<1)+1); |
| 693 | 701 | |
| 694 | | if (intv_top_edge_inhibit) |
| 695 | | plot_box(bm, 0, 0, 16*20, 16-intv_row_delay*2, (intv_border_color<<1)+1); |
| 702 | if (state->top_edge_inhibit) |
| 703 | plot_box(bm, 0, 0, 16*20, 16-state->row_delay*2, (state->border_color<<1)+1); |
| 696 | 704 | } |
| 697 | 705 | |
| 698 | | static int col_delay = 0; |
| 699 | | static int row_delay = 0; |
| 700 | | |
| 701 | 706 | void intv_stic_screenrefresh(running_machine *machine) |
| 702 | 707 | { |
| 708 | intv_state *state = machine->driver_data<intv_state>(); |
| 703 | 709 | int i; |
| 704 | 710 | |
| 705 | | if (intv_stic_handshake != 0) |
| 711 | if (state->stic_handshake != 0) |
| 706 | 712 | { |
| 707 | | intv_stic_handshake = 0; |
| 713 | state->stic_handshake = 0; |
| 708 | 714 | // Render the background |
| 709 | 715 | render_background(machine, machine->generic.tmpbitmap); |
| 710 | 716 | // Render the sprites into their buffers |
| 711 | 717 | render_sprites(machine); |
| 712 | | for (i = 0; i < 8; i++) intv_sprite[i].collision = 0; |
| 718 | for (i = 0; i < 8; i++) state->sprite[i].collision = 0; |
| 713 | 719 | // Copy the sprites to the background |
| 714 | 720 | copy_sprites_to_background(machine, machine->generic.tmpbitmap); |
| 715 | | determine_sprite_collisions(); |
| 716 | | for (i = 0; i < 8; i++) intv_collision_registers[i] |= intv_sprite[i].collision; |
| 721 | determine_sprite_collisions(state); |
| 722 | for (i = 0; i < 8; i++) state->collision_registers[i] |= state->sprite[i].collision; |
| 717 | 723 | /* draw the screen borders if enabled */ |
| 718 | 724 | draw_borders(machine, machine->generic.tmpbitmap); |
| 719 | 725 | } |
| 720 | 726 | else |
| 721 | 727 | { |
| 722 | 728 | /* STIC disabled, just fill with border color */ |
| 723 | | bitmap_fill(machine->generic.tmpbitmap, NULL, (intv_border_color<<1)+1); |
| 729 | bitmap_fill(machine->generic.tmpbitmap, NULL, (state->border_color<<1)+1); |
| 724 | 730 | } |
| 725 | | col_delay = intv_col_delay; |
| 726 | | row_delay = intv_row_delay; |
| 727 | 731 | } |
| 728 | 732 | |
| 729 | 733 | |
| 730 | 734 | /* very rudimentary support for the tms9927 character generator IC */ |
| 731 | 735 | |
| 732 | | static UINT8 tms9927_cursor_col; |
| 733 | | static UINT8 tms9927_cursor_row; |
| 734 | | static UINT8 tms9927_last_row; |
| 735 | 736 | |
| 736 | 737 | READ8_HANDLER( intvkbd_tms9927_r ) |
| 737 | 738 | { |
| 739 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 738 | 740 | UINT8 rv; |
| 739 | 741 | switch (offset) |
| 740 | 742 | { |
| 741 | 743 | case 8: |
| 742 | | rv = tms9927_cursor_row; |
| 744 | rv = state->tms9927_cursor_row; |
| 743 | 745 | break; |
| 744 | 746 | case 9: |
| 745 | 747 | /* note: this is 1-based */ |
| 746 | | rv = tms9927_cursor_col; |
| 748 | rv = state->tms9927_cursor_col; |
| 747 | 749 | break; |
| 748 | 750 | case 11: |
| 749 | | tms9927_last_row = (tms9927_last_row + 1) % tms9927_num_rows; |
| 750 | | rv = tms9927_last_row; |
| 751 | state->tms9927_last_row = (state->tms9927_last_row + 1) % state->tms9927_num_rows; |
| 752 | rv = state->tms9927_last_row; |
| 751 | 753 | break; |
| 752 | 754 | default: |
| 753 | 755 | rv = 0; |
| r9785 | r9786 | |
| 757 | 759 | |
| 758 | 760 | WRITE8_HANDLER( intvkbd_tms9927_w ) |
| 759 | 761 | { |
| 762 | intv_state *state = space->machine->driver_data<intv_state>(); |
| 760 | 763 | switch (offset) |
| 761 | 764 | { |
| 762 | 765 | case 3: |
| 763 | | tms9927_num_rows = (data & 0x3f) + 1; |
| 766 | state->tms9927_num_rows = (data & 0x3f) + 1; |
| 764 | 767 | break; |
| 765 | 768 | case 6: |
| 766 | | tms9927_last_row = data; |
| 769 | state->tms9927_last_row = data; |
| 767 | 770 | break; |
| 768 | 771 | case 11: |
| 769 | | tms9927_last_row = (tms9927_last_row + 1) % tms9927_num_rows; |
| 772 | state->tms9927_last_row = (state->tms9927_last_row + 1) % state->tms9927_num_rows; |
| 770 | 773 | break; |
| 771 | 774 | case 12: |
| 772 | 775 | /* note: this is 1-based */ |
| 773 | | tms9927_cursor_col = data; |
| 776 | state->tms9927_cursor_col = data; |
| 774 | 777 | break; |
| 775 | 778 | case 13: |
| 776 | | tms9927_cursor_row = data; |
| 779 | state->tms9927_cursor_row = data; |
| 777 | 780 | break; |
| 778 | 781 | } |
| 779 | 782 | } |
| r9785 | r9786 | |
| 790 | 793 | VIDEO_UPDATE_CALL(generic_bitmapped); |
| 791 | 794 | |
| 792 | 795 | /* if the intvkbd text is not blanked, overlay it */ |
| 793 | | if (!intvkbd_text_blanked) |
| 796 | if (!state->intvkbd_text_blanked) |
| 794 | 797 | { |
| 795 | | current_row = (tms9927_last_row + 1) % tms9927_num_rows; |
| 798 | current_row = (state->tms9927_last_row + 1) % state->tms9927_num_rows; |
| 796 | 799 | for(y=0;y<24;y++) |
| 797 | 800 | { |
| 798 | 801 | for(x=0;x<40;x++) |
| r9785 | r9786 | |
| 805 | 808 | 0,0, |
| 806 | 809 | x<<3,y<<3, 0); |
| 807 | 810 | } |
| 808 | | if (current_row == tms9927_cursor_row) |
| 811 | if (current_row == state->tms9927_cursor_row) |
| 809 | 812 | { |
| 810 | 813 | /* draw the cursor as a solid white block */ |
| 811 | 814 | /* (should use a filled rect here!) */ |
| r9785 | r9786 | |
| 814 | 817 | 191, /* a block */ |
| 815 | 818 | 7, /* white */ |
| 816 | 819 | 0,0, |
| 817 | | (tms9927_cursor_col-1)<<3,y<<3, 0); |
| 820 | (state->tms9927_cursor_col-1)<<3,y<<3, 0); |
| 818 | 821 | } |
| 819 | | current_row = (current_row + 1) % tms9927_num_rows; |
| 822 | current_row = (current_row + 1) % state->tms9927_num_rows; |
| 820 | 823 | } |
| 821 | 824 | } |
| 822 | 825 | |
| 823 | 826 | #if 0 |
| 824 | 827 | // debugging |
| 825 | | c = tape_motor_mode_desc[tape_motor_mode][0]; |
| 828 | c = tape_motor_mode_desc[state->tape_motor_mode][0]; |
| 826 | 829 | drawgfx_transpen(bitmap,&machine->screen[0].visarea, machine->gfx[1], |
| 827 | 830 | c, |
| 828 | 831 | 1, |
| r9785 | r9786 | |
| 831 | 834 | for(y=0;y<5;y++) |
| 832 | 835 | { |
| 833 | 836 | drawgfx_transpen(bitmap,&machine->screen[0].visarea, machine->gfx[1], |
| 834 | | tape_unknown_write[y]+'0', |
| 837 | state->tape_unknown_write[y]+'0', |
| 835 | 838 | 1, |
| 836 | 839 | 0,0, |
| 837 | 840 | 0*8,(y+2)*8, 0); |
| 838 | 841 | } |
| 839 | 842 | drawgfx_transpen(bitmap,&machine->screen[0].visarea, machine->gfx[1], |
| 840 | | tape_unknown_write[5]+'0', |
| 843 | state->tape_unknown_write[5]+'0', |
| 841 | 844 | 1, |
| 842 | 845 | 0,0, |
| 843 | 846 | 0*8,8*8, 0); |
| 844 | 847 | drawgfx_transpen(bitmap,&machine->screen[0].visarea, machine->gfx[1], |
| 845 | | tape_interrupts_enabled+'0', |
| 848 | state->tape_interrupts_enabled+'0', |
| 846 | 849 | 1, |
| 847 | 850 | 0,0, |
| 848 | 851 | 0*8,10*8, 0); |