src/mess/machine/coco.c
| r9722 | r9723 | |
| 122 | 122 | ***************************************************************************/ |
| 123 | 123 | |
| 124 | 124 | /*common vars/calls */ |
| 125 | | static UINT8 *coco_rom; |
| 126 | | static int dclg_state, dclg_output_h, dclg_output_v, dclg_timer; |
| 127 | | static UINT8 (*update_keyboard)(running_machine *machine); |
| 128 | | static emu_timer *update_keyboard_timer; |
| 129 | | static emu_timer *mux_sel1_timer; |
| 130 | | static emu_timer *mux_sel2_timer; |
| 131 | | static UINT8 mux_sel1, mux_sel2; |
| 132 | | static UINT8 bitbanger_output_value; |
| 133 | | static UINT8 bitbanger_input_value; |
| 134 | | static UINT8 dac_value; |
| 135 | 125 | |
| 136 | 126 | static WRITE8_DEVICE_HANDLER( d_pia1_pb_w ); |
| 137 | 127 | static WRITE8_DEVICE_HANDLER( d_pia1_pa_w ); |
| r9722 | r9723 | |
| 158 | 148 | static READ8_DEVICE_HANDLER ( d_pia1_pb_r_coco2 ); |
| 159 | 149 | |
| 160 | 150 | /* CoCo 3 specific */ |
| 161 | | UINT8 coco3_gimereg[16]; |
| 162 | | static int coco3_enable_64k; |
| 163 | | static UINT8 coco3_mmu[16]; |
| 164 | | static UINT8 coco3_interupt_line; |
| 165 | | static UINT8 gime_firq, gime_irq; |
| 166 | 151 | |
| 167 | 152 | static WRITE_LINE_DEVICE_HANDLER( coco3_pia0_irq_a ); |
| 168 | 153 | static WRITE_LINE_DEVICE_HANDLER( coco3_pia0_irq_b ); |
| r9722 | r9723 | |
| 185 | 170 | static WRITE8_DEVICE_HANDLER ( dgnalpha_pia2_pa_w ); |
| 186 | 171 | static WRITE_LINE_DEVICE_HANDLER( d_pia2_firq_a ); |
| 187 | 172 | static WRITE_LINE_DEVICE_HANDLER( d_pia2_firq_b ); |
| 188 | | static int dgnalpha_just_reset; /* Reset flag used to ignore first NMI after reset */ |
| 189 | 173 | |
| 190 | | /* Dragon Plus specific */ |
| 191 | | static int dragon_plus_reg; /* Dragon plus control reg */ |
| 192 | | |
| 193 | 174 | /* Memory map related CoCo 1/2 and Dragons only */ |
| 194 | | static UINT8 *bas_rom_bank; /* Dragon 64 / Alpha rom bank in use, basic rom bank on coco */ |
| 195 | | static UINT8 *bottom_32k; /* ram to be mapped into bottom 32K */ |
| 196 | 175 | static void setup_memory_map(running_machine *machine); |
| 197 | 176 | |
| 198 | 177 | |
| r9722 | r9723 | |
| 942 | 921 | |
| 943 | 922 | static void coco3_recalc_irq(running_machine *machine) |
| 944 | 923 | { |
| 945 | | if ((coco3_gimereg[0] & 0x20) && gime_irq) |
| 924 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 925 | if ((state->gimereg[0] & 0x20) && state->gime_irq) |
| 946 | 926 | cputag_set_input_line(machine, "maincpu", M6809_IRQ_LINE, ASSERT_LINE); |
| 947 | 927 | else |
| 948 | 928 | d_recalc_irq(machine); |
| r9722 | r9723 | |
| 950 | 930 | |
| 951 | 931 | static void coco3_recalc_firq(running_machine *machine) |
| 952 | 932 | { |
| 953 | | if ((coco3_gimereg[0] & 0x10) && gime_firq) |
| 933 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 934 | if ((state->gimereg[0] & 0x10) && state->gime_firq) |
| 954 | 935 | cputag_set_input_line(machine, "maincpu", M6809_FIRQ_LINE, ASSERT_LINE); |
| 955 | 936 | else |
| 956 | 937 | d_recalc_firq(machine); |
| r9722 | r9723 | |
| 1009 | 990 | |
| 1010 | 991 | static void coco3_raise_interrupt(running_machine *machine, UINT8 mask, int state) |
| 1011 | 992 | { |
| 993 | coco3_state *drvstate = machine->driver_data<coco3_state>(); |
| 1012 | 994 | int lowtohigh; |
| 1013 | 995 | |
| 1014 | | lowtohigh = state && ((coco3_interupt_line & mask) == 0); |
| 996 | lowtohigh = state && ((drvstate->interupt_line & mask) == 0); |
| 1015 | 997 | |
| 1016 | 998 | if (state) |
| 1017 | | coco3_interupt_line |= mask; |
| 999 | drvstate->interupt_line |= mask; |
| 1018 | 1000 | else |
| 1019 | | coco3_interupt_line &= ~mask; |
| 1001 | drvstate->interupt_line &= ~mask; |
| 1020 | 1002 | |
| 1021 | 1003 | if (lowtohigh) |
| 1022 | 1004 | { |
| 1023 | | if ((coco3_gimereg[0] & 0x20) && (coco3_gimereg[2] & mask)) |
| 1005 | if ((drvstate->gimereg[0] & 0x20) && (drvstate->gimereg[2] & mask)) |
| 1024 | 1006 | { |
| 1025 | | gime_irq |= (coco3_gimereg[2] & mask); |
| 1007 | drvstate->gime_irq |= (drvstate->gimereg[2] & mask); |
| 1026 | 1008 | coco3_recalc_irq(machine); |
| 1027 | 1009 | |
| 1028 | 1010 | if (LOG_INT_COCO3) |
| 1029 | 1011 | logerror("CoCo3 Interrupt: Raising IRQ; scanline=%i\n", machine->primary_screen->vpos()); |
| 1030 | 1012 | } |
| 1031 | | if ((coco3_gimereg[0] & 0x10) && (coco3_gimereg[3] & mask)) |
| 1013 | if ((drvstate->gimereg[0] & 0x10) && (drvstate->gimereg[3] & mask)) |
| 1032 | 1014 | { |
| 1033 | | gime_firq |= (coco3_gimereg[3] & mask); |
| 1015 | drvstate->gime_firq |= (drvstate->gimereg[3] & mask); |
| 1034 | 1016 | coco3_recalc_firq(machine); |
| 1035 | 1017 | |
| 1036 | 1018 | if (LOG_INT_COCO3) |
| r9722 | r9723 | |
| 1081 | 1063 | coco3_recalc_irq(machine); |
| 1082 | 1064 | } |
| 1083 | 1065 | |
| 1084 | | static timer_fired_func recalc_interrupts; |
| 1085 | 1066 | |
| 1086 | 1067 | #ifdef UNUSED_FUNCTION |
| 1087 | 1068 | void coco_set_halt_line(running_machine *machine, int halt_line) |
| 1088 | 1069 | { |
| 1070 | coco_state *state = machine->driver_data<coco_state>(); |
| 1089 | 1071 | cpunum_set_input_line(machine, 0, INPUT_LINE_HALT, halt_line); |
| 1090 | 1072 | if (halt_line == CLEAR_LINE) |
| 1091 | | timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(1), NULL, 0, recalc_interrupts); |
| 1073 | timer_set(machine, machine->device<cpu_device>("maincpu")->cycles_to_attotime(1), NULL, 0, state->recalc_interrupts); |
| 1092 | 1074 | } |
| 1093 | 1075 | #endif |
| 1094 | 1076 | |
| r9722 | r9723 | |
| 1097 | 1079 | Hires Joystick |
| 1098 | 1080 | ***************************************************************************/ |
| 1099 | 1081 | |
| 1100 | | static int coco_hiresjoy_ca = 1; |
| 1101 | | static attotime coco_hiresjoy_xtransitiontime; |
| 1102 | | static attotime coco_hiresjoy_ytransitiontime; |
| 1103 | 1082 | |
| 1104 | 1083 | static attotime coco_hiresjoy_computetransitiontime( running_machine *machine, UINT8 port, UINT8 axis ) |
| 1105 | 1084 | { |
| r9722 | r9723 | |
| 1129 | 1108 | |
| 1130 | 1109 | static void coco_hiresjoy_w( running_machine *machine, int data, UINT8 port ) |
| 1131 | 1110 | { |
| 1132 | | if (!data && coco_hiresjoy_ca) |
| 1111 | coco_state *state = machine->driver_data<coco_state>(); |
| 1112 | if (!data && state->hiresjoy_ca) |
| 1133 | 1113 | { |
| 1134 | 1114 | /* Hi to lo */ |
| 1135 | | coco_hiresjoy_xtransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 0); |
| 1136 | | coco_hiresjoy_ytransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 1); |
| 1115 | state->hiresjoy_xtransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 0); |
| 1116 | state->hiresjoy_ytransitiontime = coco_hiresjoy_computetransitiontime(machine, port, 1); |
| 1137 | 1117 | } |
| 1138 | | else if (data && !coco_hiresjoy_ca) |
| 1118 | else if (data && !state->hiresjoy_ca) |
| 1139 | 1119 | { |
| 1140 | 1120 | /* Lo to hi */ |
| 1141 | | coco_hiresjoy_xtransitiontime = attotime_zero; |
| 1142 | | coco_hiresjoy_ytransitiontime = attotime_zero; |
| 1121 | state->hiresjoy_xtransitiontime = attotime_zero; |
| 1122 | state->hiresjoy_ytransitiontime = attotime_zero; |
| 1143 | 1123 | } |
| 1144 | | coco_hiresjoy_ca = data; |
| 1145 | | (*update_keyboard)(machine); |
| 1124 | state->hiresjoy_ca = data; |
| 1125 | (*state->update_keyboard)(machine); |
| 1146 | 1126 | } |
| 1147 | 1127 | |
| 1148 | 1128 | static int coco_hiresjoy_readone( running_machine *machine, attotime transitiontime ) |
| r9722 | r9723 | |
| 1152 | 1132 | |
| 1153 | 1133 | static int coco_hiresjoy_rx( running_machine *machine ) |
| 1154 | 1134 | { |
| 1155 | | return coco_hiresjoy_readone(machine, coco_hiresjoy_xtransitiontime); |
| 1135 | coco_state *state = machine->driver_data<coco_state>(); |
| 1136 | return coco_hiresjoy_readone(machine, state->hiresjoy_xtransitiontime); |
| 1156 | 1137 | } |
| 1157 | 1138 | |
| 1158 | 1139 | static int coco_hiresjoy_ry( running_machine *machine ) |
| 1159 | 1140 | { |
| 1160 | | return coco_hiresjoy_readone(machine, coco_hiresjoy_ytransitiontime); |
| 1141 | coco_state *state = machine->driver_data<coco_state>(); |
| 1142 | return coco_hiresjoy_readone(machine, state->hiresjoy_ytransitiontime); |
| 1161 | 1143 | } |
| 1162 | 1144 | |
| 1163 | 1145 | /*************************************************************************** |
| r9722 | r9723 | |
| 1211 | 1193 | int soundmux_status = 0; |
| 1212 | 1194 | if (pia6821_get_output_cb2(state->pia_1)) |
| 1213 | 1195 | soundmux_status |= SOUNDMUX_STATUS_ENABLE; |
| 1214 | | if (mux_sel1) |
| 1196 | if (state->mux_sel1) |
| 1215 | 1197 | soundmux_status |= SOUNDMUX_STATUS_SEL1; |
| 1216 | | if (mux_sel2) |
| 1198 | if (state->mux_sel2) |
| 1217 | 1199 | soundmux_status |= SOUNDMUX_STATUS_SEL2; |
| 1218 | 1200 | return soundmux_status; |
| 1219 | 1201 | } |
| r9722 | r9723 | |
| 1324 | 1306 | |
| 1325 | 1307 | static WRITE8_DEVICE_HANDLER( d_pia0_ca2_w ) |
| 1326 | 1308 | { |
| 1327 | | timer_adjust_oneshot(mux_sel1_timer, JOYSTICK_MUX_DELAY, data); |
| 1309 | coco_state *state = device->machine->driver_data<coco_state>(); |
| 1310 | timer_adjust_oneshot(state->mux_sel1_timer, JOYSTICK_MUX_DELAY, data); |
| 1328 | 1311 | } |
| 1329 | 1312 | |
| 1330 | 1313 | static TIMER_CALLBACK( coco_update_sel1_timerproc ) |
| 1331 | 1314 | { |
| 1332 | | mux_sel1 = param; |
| 1333 | | (*update_keyboard)(machine); |
| 1315 | coco_state *state = machine->driver_data<coco_state>(); |
| 1316 | state->mux_sel1 = param; |
| 1317 | (*state->update_keyboard)(machine); |
| 1334 | 1318 | soundmux_update(machine); |
| 1335 | 1319 | } |
| 1336 | 1320 | |
| 1337 | 1321 | static WRITE8_DEVICE_HANDLER( d_pia0_cb2_w ) |
| 1338 | 1322 | { |
| 1339 | | timer_adjust_oneshot(mux_sel2_timer, JOYSTICK_MUX_DELAY, data); |
| 1323 | coco_state *state = device->machine->driver_data<coco_state>(); |
| 1324 | timer_adjust_oneshot(state->mux_sel2_timer, JOYSTICK_MUX_DELAY, data); |
| 1340 | 1325 | } |
| 1341 | 1326 | |
| 1342 | 1327 | static TIMER_CALLBACK( coco_update_sel2_timerproc ) |
| 1343 | 1328 | { |
| 1344 | | mux_sel2 = param; |
| 1345 | | (*update_keyboard)(machine); |
| 1329 | coco_state *state = machine->driver_data<coco_state>(); |
| 1330 | state->mux_sel2 = param; |
| 1331 | (*state->update_keyboard)(machine); |
| 1346 | 1332 | soundmux_update(machine); |
| 1347 | 1333 | } |
| 1348 | 1334 | |
| r9722 | r9723 | |
| 1384 | 1370 | |
| 1385 | 1371 | |
| 1386 | 1372 | pia0_pb = pia6821_get_output_b(state->pia_0); |
| 1387 | | joystick_axis = mux_sel1; |
| 1388 | | joystick = mux_sel2; |
| 1373 | joystick_axis = state->mux_sel1; |
| 1374 | joystick = state->mux_sel2; |
| 1389 | 1375 | |
| 1390 | 1376 | /* which kind of controller is selected? */ |
| 1391 | 1377 | joy_mask = joystick ? 0xf0 : 0x0f; |
| r9722 | r9723 | |
| 1440 | 1426 | if ((machine->primary_screen->vpos() == input_port_read_safe(machine, portnames[joystick][ctrl][1], 0))) |
| 1441 | 1427 | { |
| 1442 | 1428 | /* If gun is pointing at the current scan line, set hit bit and cache horizontal timer value */ |
| 1443 | | dclg_output_h |= 0x02; |
| 1444 | | dclg_timer = input_port_read_safe(machine, portnames[joystick][ctrl][0], 0) << 1; |
| 1429 | state->dclg_output_h |= 0x02; |
| 1430 | state->dclg_timer = input_port_read_safe(machine, portnames[joystick][ctrl][0], 0) << 1; |
| 1445 | 1431 | } |
| 1446 | 1432 | |
| 1447 | | if ((dac >> 2) <= dclg_table[(joystick_axis ? dclg_output_h : dclg_output_v) & 0x03]) |
| 1433 | if ((dac >> 2) <= dclg_table[(joystick_axis ? state->dclg_output_h : state->dclg_output_v) & 0x03]) |
| 1448 | 1434 | porta |= 0x80; |
| 1449 | 1435 | |
| 1450 | | if ((dclg_state == 7)) |
| 1436 | if ((state->dclg_state == 7)) |
| 1451 | 1437 | { |
| 1452 | 1438 | /* While in state 7, prepare to chech next video frame for a hit */ |
| 1453 | 1439 | dclg_time = machine->primary_screen->time_until_pos(input_port_read_safe(machine, portnames[joystick][ctrl][1], 0), 0); |
| r9722 | r9723 | |
| 1462 | 1448 | if (attotime_compare(dclg_time, attotime_zero)) |
| 1463 | 1449 | { |
| 1464 | 1450 | /* schedule lightgun events */ |
| 1465 | | timer_reset(update_keyboard_timer, dclg_time); |
| 1451 | timer_reset(state->update_keyboard_timer, dclg_time); |
| 1466 | 1452 | } |
| 1467 | 1453 | else |
| 1468 | 1454 | { |
| 1469 | 1455 | /* schedule hires joystick events */ |
| 1470 | | attotime xtrans = get_relative_time(machine, coco_hiresjoy_xtransitiontime); |
| 1471 | | attotime ytrans = get_relative_time(machine, coco_hiresjoy_ytransitiontime); |
| 1456 | attotime xtrans = get_relative_time(machine, state->hiresjoy_xtransitiontime); |
| 1457 | attotime ytrans = get_relative_time(machine, state->hiresjoy_ytransitiontime); |
| 1472 | 1458 | |
| 1473 | | timer_reset(update_keyboard_timer, |
| 1459 | timer_reset(state->update_keyboard_timer, |
| 1474 | 1460 | (attotime_compare(xtrans, ytrans) > 0) ? ytrans : xtrans); |
| 1475 | 1461 | } |
| 1476 | 1462 | |
| r9722 | r9723 | |
| 1495 | 1481 | |
| 1496 | 1482 | |
| 1497 | 1483 | /* three functions that update the keyboard in varying ways */ |
| 1498 | | static WRITE8_DEVICE_HANDLER( d_pia0_pb_w ) { (*update_keyboard)(device->machine); } |
| 1499 | | INPUT_CHANGED( coco_keyboard_changed ) { (*update_keyboard)(field->port->machine); } |
| 1500 | | static TIMER_CALLBACK( coco_update_keyboard_timerproc ) { (*update_keyboard)(machine); } |
| 1484 | static WRITE8_DEVICE_HANDLER( d_pia0_pb_w ) |
| 1485 | { |
| 1486 | coco_state *state = device->machine->driver_data<coco_state>(); |
| 1487 | (*state->update_keyboard)(device->machine); |
| 1488 | } |
| 1501 | 1489 | |
| 1490 | INPUT_CHANGED( coco_keyboard_changed ) |
| 1491 | { |
| 1492 | coco_state *state = field->port->machine->driver_data<coco_state>(); |
| 1493 | (*state->update_keyboard)(field->port->machine); |
| 1494 | } |
| 1495 | |
| 1496 | static TIMER_CALLBACK( coco_update_keyboard_timerproc ) |
| 1497 | { |
| 1498 | coco_state *state = machine->driver_data<coco_state>(); |
| 1499 | (*state->update_keyboard)(machine); |
| 1500 | } |
| 1501 | |
| 1502 | 1502 | static WRITE8_DEVICE_HANDLER( d_pia0_pa_w ) |
| 1503 | 1503 | { |
| 1504 | 1504 | UINT8 ctrl = input_port_read_safe(device->machine, "ctrl_sel", 0x00); |
| r9722 | r9723 | |
| 1538 | 1538 | } |
| 1539 | 1539 | |
| 1540 | 1540 | /* Printer output functions used by d_pia1_pa_w */ |
| 1541 | | static void (*printer_out)(running_machine *machine, int data); |
| 1542 | 1541 | |
| 1543 | 1542 | /* Printer output for the CoCo, output to bitbanger port */ |
| 1544 | 1543 | static void printer_out_coco(running_machine *machine, int data) |
| 1545 | 1544 | { |
| 1546 | | bitbanger_output_value = (data & 2) >> 1; |
| 1547 | | bitbanger_output(bitbanger_image(machine), bitbanger_output_value); |
| 1545 | coco_state *state = machine->driver_data<coco_state>(); |
| 1546 | state->bitbanger_output_value = (data & 2) >> 1; |
| 1547 | bitbanger_output(bitbanger_image(machine), state->bitbanger_output_value); |
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | /* Printer output for the Dragon, output to Paralel port */ |
| r9722 | r9723 | |
| 1561 | 1561 | |
| 1562 | 1562 | static WRITE8_DEVICE_HANDLER ( d_pia1_pa_w ) |
| 1563 | 1563 | { |
| 1564 | coco_state *state = device->machine->driver_data<coco_state>(); |
| 1564 | 1565 | /* |
| 1565 | 1566 | * This port appears at $FF20 |
| 1566 | 1567 | * |
| r9722 | r9723 | |
| 1569 | 1570 | * 1: Serial out (CoCo), Printer strobe (Dragon) |
| 1570 | 1571 | */ |
| 1571 | 1572 | UINT8 dac = pia6821_get_output_a(device) & 0xfc; |
| 1572 | | static int dclg_previous_bit; |
| 1573 | 1573 | UINT8 ctrl = input_port_read_safe(device->machine, "ctrl_sel", 0x00); |
| 1574 | 1574 | UINT8 hires = input_port_read_safe(device->machine, "hires_intf", 0x00); |
| 1575 | | dac_value = dac >> 2; |
| 1575 | state->dac_value = dac >> 2; |
| 1576 | 1576 | |
| 1577 | 1577 | coco_sound_update(device->machine); |
| 1578 | 1578 | |
| r9722 | r9723 | |
| 1581 | 1581 | { |
| 1582 | 1582 | int dclg_this_bit = ((data & 2) >> 1); |
| 1583 | 1583 | |
| 1584 | | if (dclg_previous_bit == 1) |
| 1584 | if (state->dclg_previous_bit == 1) |
| 1585 | 1585 | { |
| 1586 | 1586 | if (dclg_this_bit == 0) |
| 1587 | 1587 | { |
| 1588 | 1588 | /* Clock Diecom Light gun interface on a high to low transistion */ |
| 1589 | | dclg_state++; |
| 1590 | | dclg_state &= 0x0f; |
| 1589 | state->dclg_state++; |
| 1590 | state->dclg_state &= 0x0f; |
| 1591 | 1591 | |
| 1592 | 1592 | /* Clear hit bit for every transistion */ |
| 1593 | | dclg_output_h &= ~0x02; |
| 1593 | state->dclg_output_h &= ~0x02; |
| 1594 | 1594 | |
| 1595 | | if (dclg_state > 7) |
| 1595 | if (state->dclg_state > 7) |
| 1596 | 1596 | { |
| 1597 | 1597 | /* Bit shift timer data on state 8 thru 15 */ |
| 1598 | | if (((dclg_timer >> (dclg_state - 8 + 1)) & 0x01) == 1) |
| 1599 | | dclg_output_v |= 0x01; |
| 1598 | if (((state->dclg_timer >> (state->dclg_state - 8 + 1)) & 0x01) == 1) |
| 1599 | state->dclg_output_v |= 0x01; |
| 1600 | 1600 | else |
| 1601 | | dclg_output_v &= ~0x01; |
| 1601 | state->dclg_output_v &= ~0x01; |
| 1602 | 1602 | |
| 1603 | 1603 | /* Bit 9 of timer is only avaiable if state == 8*/ |
| 1604 | | if (dclg_state == 8 && (((dclg_timer >> 9) & 0x01) == 1)) |
| 1605 | | dclg_output_v |= 0x02; |
| 1604 | if (state->dclg_state == 8 && (((state->dclg_timer >> 9) & 0x01) == 1)) |
| 1605 | state->dclg_output_v |= 0x02; |
| 1606 | 1606 | else |
| 1607 | | dclg_output_v &= ~0x02; |
| 1607 | state->dclg_output_v &= ~0x02; |
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | /* During state 15, this bit is high. */ |
| 1611 | | if (dclg_state == 15) |
| 1612 | | dclg_output_h |= 0x01; |
| 1611 | if (state->dclg_state == 15) |
| 1612 | state->dclg_output_h |= 0x01; |
| 1613 | 1613 | else |
| 1614 | | dclg_output_h &= ~0x01; |
| 1614 | state->dclg_output_h &= ~0x01; |
| 1615 | 1615 | } |
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | | dclg_previous_bit = dclg_this_bit; |
| 1618 | state->dclg_previous_bit = dclg_this_bit; |
| 1619 | 1619 | |
| 1620 | 1620 | } |
| 1621 | 1621 | else |
| r9722 | r9723 | |
| 1623 | 1623 | cassette_output(cassette_device_image(device->machine), ((int) dac - 0x80) / 128.0); |
| 1624 | 1624 | } |
| 1625 | 1625 | |
| 1626 | | (*update_keyboard)(device->machine); |
| 1626 | (*state->update_keyboard)(device->machine); |
| 1627 | 1627 | |
| 1628 | 1628 | /* Hi-Res Joystick (either in Left or in Right Port) writes here */ |
| 1629 | 1629 | if ((ctrl & 0x0f) == 0x01 && hires == 0x01) |
| r9722 | r9723 | |
| 1632 | 1632 | coco_hiresjoy_w(device->machine, dac >= 0x80, 1); |
| 1633 | 1633 | |
| 1634 | 1634 | /* Handle printer output, serial for CoCos, parallel for Dragons */ |
| 1635 | | printer_out(device->machine, data); |
| 1635 | (*state->printer_out)(device->machine, data); |
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | 1638 | /* |
| r9722 | r9723 | |
| 1724 | 1724 | /* on the alpha switches between the Boot/Diagnostic rom and the basic rom */ |
| 1725 | 1725 | static void dragon_page_rom(running_machine *machine, int romswitch) |
| 1726 | 1726 | { |
| 1727 | coco_state *state = machine->driver_data<coco_state>(); |
| 1727 | 1728 | UINT8 *bank; |
| 1728 | 1729 | |
| 1729 | 1730 | if (romswitch) |
| 1730 | | bank = coco_rom; /* This is the 32k mode basic(64)/boot rom(alpha) */ |
| 1731 | bank = state->rom; /* This is the 32k mode basic(64)/boot rom(alpha) */ |
| 1731 | 1732 | else |
| 1732 | | bank = coco_rom + 0x8000; /* This is the 64k mode basic(64)/basic rom(alpha) */ |
| 1733 | bank = state->rom + 0x8000; /* This is the 64k mode basic(64)/basic rom(alpha) */ |
| 1733 | 1734 | |
| 1734 | | bas_rom_bank = bank; /* Record which rom we are using so that the irq routine */ |
| 1735 | state->bas_rom_bank = bank; /* Record which rom we are using so that the irq routine */ |
| 1735 | 1736 | /* uses the vectors from the correct rom ! (alpha) */ |
| 1736 | 1737 | |
| 1737 | 1738 | setup_memory_map(machine); /* Setup memory map as needed */ |
| r9722 | r9723 | |
| 1748 | 1749 | |
| 1749 | 1750 | if (state) |
| 1750 | 1751 | { |
| 1751 | | if(dgnalpha_just_reset) |
| 1752 | if(cstate->dgnalpha_just_reset) |
| 1752 | 1753 | { |
| 1753 | | dgnalpha_just_reset = 0; |
| 1754 | cstate->dgnalpha_just_reset = 0; |
| 1754 | 1755 | } |
| 1755 | 1756 | else |
| 1756 | 1757 | { |
| r9722 | r9723 | |
| 1839 | 1840 | |
| 1840 | 1841 | static READ8_DEVICE_HANDLER ( d_pia1_pa_r ) |
| 1841 | 1842 | { |
| 1843 | coco_state *state = device->machine->driver_data<coco_state>(); |
| 1842 | 1844 | UINT8 result; |
| 1843 | 1845 | |
| 1844 | 1846 | result = cassette_input(cassette_device_image(device->machine)) >= 0 ? 1 : 0; |
| 1845 | | result |= bitbanger_output_value << 1; |
| 1846 | | result |= dac_value << 2; |
| 1847 | result |= state->bitbanger_output_value << 1; |
| 1848 | result |= state->dac_value << 2; |
| 1847 | 1849 | |
| 1848 | 1850 | return result; |
| 1849 | 1851 | } |
| 1850 | 1852 | |
| 1851 | 1853 | void coco_bitbanger_callback(running_machine *machine, UINT8 bit) |
| 1852 | 1854 | { |
| 1853 | | bitbanger_input_value = bit; |
| 1855 | coco_state *state = machine->driver_data<coco_state>(); |
| 1856 | state->bitbanger_input_value = bit; |
| 1854 | 1857 | } |
| 1855 | 1858 | |
| 1856 | 1859 | void coco3_bitbanger_callback(running_machine *machine, UINT8 bit) |
| 1857 | 1860 | { |
| 1861 | coco_state *state = machine->driver_data<coco_state>(); |
| 1858 | 1862 | /* rant: this interrupt is next to useless. It would be useful information to know when a |
| 1859 | 1863 | start bit (high to low) occurs, but this interrupt activates in the opposite situation. |
| 1860 | 1864 | */ |
| 1861 | 1865 | |
| 1862 | | if( bitbanger_input_value == 0 && bit == 1) |
| 1866 | if( state->bitbanger_input_value == 0 && bit == 1) |
| 1863 | 1867 | { |
| 1864 | | bitbanger_input_value = bit; |
| 1868 | state->bitbanger_input_value = bit; |
| 1865 | 1869 | coco3_raise_interrupt(machine, COCO3_INT_EI2, 0); |
| 1866 | 1870 | coco3_raise_interrupt(machine, COCO3_INT_EI2, 1); |
| 1867 | 1871 | } |
| 1868 | 1872 | else |
| 1869 | 1873 | { |
| 1870 | | bitbanger_input_value = bit; |
| 1874 | state->bitbanger_input_value = bit; |
| 1871 | 1875 | } |
| 1872 | 1876 | } |
| 1873 | 1877 | |
| r9722 | r9723 | |
| 1893 | 1897 | else |
| 1894 | 1898 | result = 0x00; /* 4K Rams */ |
| 1895 | 1899 | |
| 1896 | | result += bitbanger_input_value; |
| 1900 | result += state->bitbanger_input_value; |
| 1897 | 1901 | |
| 1898 | 1902 | return result; |
| 1899 | 1903 | } |
| r9722 | r9723 | |
| 1933 | 1937 | else |
| 1934 | 1938 | result = (pia6821_get_output_b(state->pia_0) & 0x40) >> 4; /* 32/64K: wire output of pia0_pb6 to input pia1_pb2 */ |
| 1935 | 1939 | |
| 1936 | | result += bitbanger_input_value; |
| 1940 | result += state->bitbanger_input_value; |
| 1937 | 1941 | |
| 1938 | 1942 | return result; |
| 1939 | 1943 | } |
| r9722 | r9723 | |
| 1964 | 1968 | */ |
| 1965 | 1969 | WRITE8_HANDLER ( dgnplus_reg_w ) |
| 1966 | 1970 | { |
| 1971 | coco_state *state = space->machine->driver_data<coco_state>(); |
| 1967 | 1972 | int map; |
| 1968 | 1973 | |
| 1969 | | dragon_plus_reg = data; |
| 1970 | | |
| 1971 | 1974 | map = (data & 0x06)>>1; |
| 1972 | 1975 | |
| 1973 | 1976 | switch (map) |
| 1974 | 1977 | { |
| 1975 | | case 0x00 : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break; |
| 1976 | | case 0x01 : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x10000]; break; |
| 1977 | | case 0x02 : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x18000]; break; |
| 1978 | | case 0x03 : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break; |
| 1979 | | default : bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break; // Just to shut the compiler up ! |
| 1978 | case 0x00 : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break; |
| 1979 | case 0x01 : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x10000]; break; |
| 1980 | case 0x02 : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x18000]; break; |
| 1981 | case 0x03 : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break; |
| 1982 | default : state->bottom_32k=&messram_get_ptr(space->machine->device("messram"))[0x00000]; break; // Just to shut the compiler up ! |
| 1980 | 1983 | } |
| 1981 | 1984 | |
| 1982 | 1985 | setup_memory_map(space->machine); |
| r9722 | r9723 | |
| 2017 | 2020 | |
| 2018 | 2021 | READ8_HANDLER(dgnalpha_mapped_irq_r) |
| 2019 | 2022 | { |
| 2020 | | return bas_rom_bank[0x3ff0 + offset]; |
| 2023 | coco_state *state = space->machine->driver_data<coco_state>(); |
| 2024 | return state->bas_rom_bank[0x3ff0 + offset]; |
| 2021 | 2025 | } |
| 2022 | 2026 | |
| 2023 | 2027 | static void setup_memory_map(running_machine *machine) |
| r9722 | r9723 | |
| 2110 | 2114 | { |
| 2111 | 2115 | /* This deals with the bottom 32K page switch and the Dragon Plus paged ram */ |
| 2112 | 2116 | if(block_index<8) |
| 2113 | | memory_set_bankptr(machine, bank, &bottom_32k[memmap[wbank-1].start]); |
| 2117 | memory_set_bankptr(machine, bank, &state->bottom_32k[memmap[wbank-1].start]); |
| 2114 | 2118 | else |
| 2115 | 2119 | memory_set_bankptr(machine, bank,&messram_get_ptr(machine->device("messram"))[memmap[wbank-1].start]); |
| 2116 | 2120 | |
| r9722 | r9723 | |
| 2135 | 2139 | /* as this may be in a different block of coco_rom, in the Dragon 64 and Alpha */ |
| 2136 | 2140 | /* as these machines have mutiple bios roms that can ocupy this area */ |
| 2137 | 2141 | if (block_index < 4) |
| 2138 | | offset = &bas_rom_bank[0x1000*block_index]; |
| 2142 | offset = &state->bas_rom_bank[0x1000*block_index]; |
| 2139 | 2143 | else |
| 2140 | 2144 | offset = &cart_rom[(0x1000*(block_index-4)) % cart_length]; |
| 2141 | 2145 | |
| r9722 | r9723 | |
| 2148 | 2152 | |
| 2149 | 2153 | static SAM6883_SET_PAGE_ONE_MODE( d_sam_set_pageonemode ) |
| 2150 | 2154 | { |
| 2155 | coco_state *state = device->machine->driver_data<coco_state>(); |
| 2151 | 2156 | /* Page mode - allowed switching between the low 32k and the high 32k, |
| 2152 | 2157 | * assuming that 64k wasn't enabled |
| 2153 | 2158 | * |
| r9722 | r9723 | |
| 2158 | 2163 | if (!sam6883_maptype(device)) // Ignored in maptype 1 |
| 2159 | 2164 | { |
| 2160 | 2165 | if((messram_get_size(device->machine->device("messram"))>0x8000) && val) |
| 2161 | | bottom_32k=&messram_get_ptr(device->machine->device("messram"))[0x8000]; |
| 2166 | state->bottom_32k=&messram_get_ptr(device->machine->device("messram"))[0x8000]; |
| 2162 | 2167 | else |
| 2163 | | bottom_32k=messram_get_ptr(device->machine->device("messram")); |
| 2168 | state->bottom_32k=messram_get_ptr(device->machine->device("messram")); |
| 2164 | 2169 | |
| 2165 | 2170 | setup_memory_map(device->machine); |
| 2166 | 2171 | } |
| r9722 | r9723 | |
| 2217 | 2222 | FAQ agrees with this |
| 2218 | 2223 | ***************************************************************************/ |
| 2219 | 2224 | |
| 2220 | | static emu_timer *coco3_gime_timer; |
| 2221 | 2225 | |
| 2222 | 2226 | static void coco3_timer_reset(running_machine *machine) |
| 2223 | 2227 | { |
| 2228 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 2224 | 2229 | /* reset the timer; take the value stored in $FF94-5 and start the timer ticking */ |
| 2225 | 2230 | UINT16 timer_value; |
| 2226 | 2231 | m6847_timing_type timing; |
| 2227 | 2232 | attotime delay_time; |
| 2228 | 2233 | |
| 2229 | 2234 | /* value is from 0-4095 */ |
| 2230 | | timer_value = ((coco3_gimereg[4] & 0x0F) * 0x100) | coco3_gimereg[5]; |
| 2235 | timer_value = ((state->gimereg[4] & 0x0F) * 0x100) | state->gimereg[5]; |
| 2231 | 2236 | |
| 2232 | 2237 | if (timer_value > 0) |
| 2233 | 2238 | { |
| r9722 | r9723 | |
| 2238 | 2243 | timer_value += 2; /* the 1986 GIME reset to the value plus two */ |
| 2239 | 2244 | |
| 2240 | 2245 | /* choose which timing clock source */ |
| 2241 | | timing = (coco3_gimereg[1] & 0x20) ? M6847_CLOCK : M6847_HSYNC; |
| 2246 | timing = (state->gimereg[1] & 0x20) ? M6847_CLOCK : M6847_HSYNC; |
| 2242 | 2247 | |
| 2243 | 2248 | /* determine the delay time */ |
| 2244 | 2249 | delay_time = coco6847_time_delay(machine, timing, timer_value); |
| r9722 | r9723 | |
| 2246 | 2251 | logerror("coco3_reset_timer(): delay_time=%g\n", attotime_to_double(delay_time)); |
| 2247 | 2252 | |
| 2248 | 2253 | /* and adjust the timer */ |
| 2249 | | timer_adjust_oneshot(coco3_gime_timer, delay_time, 0); |
| 2254 | timer_adjust_oneshot(state->gime_timer, delay_time, 0); |
| 2250 | 2255 | } |
| 2251 | 2256 | else |
| 2252 | 2257 | { |
| 2253 | 2258 | /* timer is shut off */ |
| 2254 | | timer_reset(coco3_gime_timer, attotime_never); |
| 2259 | timer_reset(state->gime_timer, attotime_never); |
| 2255 | 2260 | if (LOG_TIMER) |
| 2256 | 2261 | logerror("coco3_reset_timer(): timer is off\n"); |
| 2257 | 2262 | } |
| r9722 | r9723 | |
| 2262 | 2267 | static TIMER_CALLBACK(coco3_timer_proc) |
| 2263 | 2268 | { |
| 2264 | 2269 | coco3_timer_reset(machine); |
| 2265 | | coco3_vh_blink(); |
| 2270 | coco3_vh_blink(machine); |
| 2266 | 2271 | coco3_raise_interrupt(machine, COCO3_INT_TMR, 1); |
| 2267 | 2272 | coco3_raise_interrupt(machine, COCO3_INT_TMR, 0); |
| 2268 | 2273 | } |
| r9722 | r9723 | |
| 2271 | 2276 | |
| 2272 | 2277 | static void coco3_timer_init(running_machine *machine) |
| 2273 | 2278 | { |
| 2274 | | coco3_gime_timer = timer_alloc(machine, coco3_timer_proc, NULL); |
| 2279 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 2280 | state->gime_timer = timer_alloc(machine, coco3_timer_proc, NULL); |
| 2275 | 2281 | } |
| 2276 | 2282 | |
| 2277 | 2283 | |
| r9722 | r9723 | |
| 2286 | 2292 | |
| 2287 | 2293 | static SAM6883_SET_MAP_TYPE( d_sam_set_maptype ) |
| 2288 | 2294 | { |
| 2295 | coco_state *state = device->machine->driver_data<coco_state>(); |
| 2289 | 2296 | if(val) |
| 2290 | | bottom_32k=messram_get_ptr(device->machine->device("messram")); // Always reset, when in maptype 1 |
| 2297 | state->bottom_32k=messram_get_ptr(device->machine->device("messram")); // Always reset, when in maptype 1 |
| 2291 | 2298 | |
| 2292 | 2299 | setup_memory_map(device->machine); |
| 2293 | 2300 | } |
| r9722 | r9723 | |
| 2323 | 2330 | */ |
| 2324 | 2331 | offs_t coco3_mmu_translate(running_machine *machine,int bank, int offset) |
| 2325 | 2332 | { |
| 2333 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 2326 | 2334 | int forceram; |
| 2327 | 2335 | UINT32 block; |
| 2328 | 2336 | offs_t result; |
| r9722 | r9723 | |
| 2330 | 2338 | /* Bank 8 is the 0xfe00 block; and it is treated differently */ |
| 2331 | 2339 | if (bank == 8) |
| 2332 | 2340 | { |
| 2333 | | if (coco3_gimereg[0] & 8) |
| 2341 | if (state->gimereg[0] & 8) |
| 2334 | 2342 | { |
| 2335 | 2343 | /* this GIME register fixes logical addresses $FExx to physical |
| 2336 | 2344 | * addresses $7FExx ($1FExx if 128k */ |
| r9722 | r9723 | |
| 2347 | 2355 | } |
| 2348 | 2356 | |
| 2349 | 2357 | /* Perform the MMU lookup */ |
| 2350 | | if (coco3_gimereg[0] & 0x40) |
| 2358 | if (state->gimereg[0] & 0x40) |
| 2351 | 2359 | { |
| 2352 | | if (coco3_gimereg[1] & 1) |
| 2360 | if (state->gimereg[1] & 1) |
| 2353 | 2361 | bank += 8; |
| 2354 | | block = coco3_mmu[bank]; |
| 2355 | | block |= ((UINT32) ((coco3_gimereg[11] >> 4) & 0x03)) << 8; |
| 2362 | block = state->mmu[bank]; |
| 2363 | block |= ((UINT32) ((state->gimereg[11] >> 4) & 0x03)) << 8; |
| 2356 | 2364 | } |
| 2357 | 2365 | else |
| 2358 | 2366 | { |
| r9722 | r9723 | |
| 2371 | 2379 | * |
| 2372 | 2380 | * This is the level where ROM is mapped, according to Tepolt (p21) |
| 2373 | 2381 | */ |
| 2374 | | if (((block & 0x3f) >= 0x3c) && !coco3_enable_64k && !forceram) |
| 2382 | if (((block & 0x3f) >= 0x3c) && !state->enable_64k && !forceram) |
| 2375 | 2383 | { |
| 2376 | 2384 | static const UINT8 rommap[4][4] = |
| 2377 | 2385 | { |
| r9722 | r9723 | |
| 2380 | 2388 | { 0, 1, 2, 3 }, |
| 2381 | 2389 | { 4, 5, 6, 7 } |
| 2382 | 2390 | }; |
| 2383 | | block = rommap[coco3_gimereg[0] & 3][(block & 0x3f) - 0x3c]; |
| 2391 | block = rommap[state->gimereg[0] & 3][(block & 0x3f) - 0x3c]; |
| 2384 | 2392 | result = (block * 0x2000 + offset) | 0x80000000; |
| 2385 | 2393 | } |
| 2386 | 2394 | else |
| r9722 | r9723 | |
| 2394 | 2402 | |
| 2395 | 2403 | static void coco3_mmu_update(running_machine *machine, int lowblock, int hiblock) |
| 2396 | 2404 | { |
| 2405 | coco_state *state = machine->driver_data<coco_state>(); |
| 2397 | 2406 | static const struct |
| 2398 | 2407 | { |
| 2399 | 2408 | offs_t start; |
| r9722 | r9723 | |
| 2429 | 2438 | if (offset & 0x8000) |
| 2430 | 2439 | readbank = &cart_rom[offset & ~0x80008000]; |
| 2431 | 2440 | else |
| 2432 | | readbank = &coco_rom[offset & ~0x80000000]; |
| 2441 | readbank = &state->rom[offset & ~0x80000000]; |
| 2433 | 2442 | memory_unmap_write(space, bank_info[i].start, bank_info[i].end, 0, 0); |
| 2434 | 2443 | } |
| 2435 | 2444 | else |
| r9722 | r9723 | |
| 2455 | 2464 | |
| 2456 | 2465 | READ8_HANDLER(coco3_mmu_r) |
| 2457 | 2466 | { |
| 2467 | coco3_state *state = space->machine->driver_data<coco3_state>(); |
| 2458 | 2468 | /* The high two bits are floating (high resistance). Therefore their |
| 2459 | 2469 | * value is undefined. But we are exposing them anyways here |
| 2460 | 2470 | */ |
| 2461 | | return coco3_mmu[offset]; |
| 2471 | return state->mmu[offset]; |
| 2462 | 2472 | } |
| 2463 | 2473 | |
| 2464 | 2474 | |
| 2465 | 2475 | |
| 2466 | 2476 | WRITE8_HANDLER(coco3_mmu_w) |
| 2467 | 2477 | { |
| 2468 | | coco3_mmu[offset] = data; |
| 2478 | coco3_state *state = space->machine->driver_data<coco3_state>(); |
| 2479 | state->mmu[offset] = data; |
| 2469 | 2480 | |
| 2470 | 2481 | /* Did we modify the live MMU bank? */ |
| 2471 | | if ((offset >> 3) == (coco3_gimereg[1] & 1)) |
| 2482 | if ((offset >> 3) == (state->gimereg[1] & 1)) |
| 2472 | 2483 | { |
| 2473 | 2484 | offset &= 7; |
| 2474 | 2485 | coco3_mmu_update(space->machine, offset, (offset == 7) ? 8 : offset); |
| r9722 | r9723 | |
| 2483 | 2494 | |
| 2484 | 2495 | READ8_HANDLER(coco3_gime_r) |
| 2485 | 2496 | { |
| 2497 | coco3_state *state = space->machine->driver_data<coco3_state>(); |
| 2486 | 2498 | UINT8 result = 0; |
| 2487 | 2499 | |
| 2488 | 2500 | switch(offset) { |
| 2489 | 2501 | case 2: /* Read pending IRQs */ |
| 2490 | | result = gime_irq; |
| 2502 | result = state->gime_irq; |
| 2491 | 2503 | if (result) { |
| 2492 | | gime_irq = 0; |
| 2504 | state->gime_irq = 0; |
| 2493 | 2505 | coco3_recalc_irq(space->machine); |
| 2494 | 2506 | } |
| 2495 | 2507 | break; |
| 2496 | 2508 | |
| 2497 | 2509 | case 3: /* Read pending FIRQs */ |
| 2498 | | result = gime_firq; |
| 2510 | result = state->gime_firq; |
| 2499 | 2511 | if (result) { |
| 2500 | | gime_firq = 0; |
| 2512 | state->gime_firq = 0; |
| 2501 | 2513 | coco3_recalc_firq(space->machine); |
| 2502 | 2514 | } |
| 2503 | 2515 | break; |
| r9722 | r9723 | |
| 2511 | 2523 | break; |
| 2512 | 2524 | |
| 2513 | 2525 | default: |
| 2514 | | result = coco3_gimereg[offset]; |
| 2526 | result = state->gimereg[offset]; |
| 2515 | 2527 | break; |
| 2516 | 2528 | } |
| 2517 | 2529 | return result; |
| r9722 | r9723 | |
| 2521 | 2533 | |
| 2522 | 2534 | WRITE8_HANDLER(coco3_gime_w) |
| 2523 | 2535 | { |
| 2536 | coco3_state *state = space->machine->driver_data<coco3_state>(); |
| 2524 | 2537 | /* take note if timer was $0000; see $FF95 for details */ |
| 2525 | | int timer_was_off = (coco3_gimereg[4] == 0x00) && (coco3_gimereg[5] == 0x00); |
| 2526 | | coco3_gimereg[offset] = data; |
| 2538 | int timer_was_off = (state->gimereg[4] == 0x00) && (state->gimereg[5] == 0x00); |
| 2539 | state->gimereg[offset] = data; |
| 2527 | 2540 | |
| 2528 | 2541 | if (LOG_GIME) |
| 2529 | 2542 | logerror("CoCo3 GIME: $%04x <== $%02x pc=$%04x\n", offset + 0xff90, data, cpu_get_pc(space->cpu)); |
| r9722 | r9723 | |
| 2544 | 2557 | */ |
| 2545 | 2558 | coco3_mmu_update(space->machine, 0, 8); |
| 2546 | 2559 | { |
| 2547 | | if (coco3_gimereg[0] & 0x04) |
| 2560 | if (state->gimereg[0] & 0x04) |
| 2548 | 2561 | { |
| 2549 | 2562 | running_device *device = cococart_device(space->machine); |
| 2550 | 2563 | memory_install_read8_device_handler(space, device, 0xFF40, 0xFF5F, 0, 0, coco_cartridge_r); |
| r9722 | r9723 | |
| 2632 | 2645 | /* $FF95 Timer register LSB |
| 2633 | 2646 | * Bits 0-7 Low order eight bits of the timer |
| 2634 | 2647 | */ |
| 2635 | | if (timer_was_off && (coco3_gimereg[5] != 0x00)) |
| 2648 | if (timer_was_off && (state->gimereg[5] != 0x00)) |
| 2636 | 2649 | { |
| 2637 | 2650 | /* Writes to $FF95 do not cause the timer to reset, but MESS |
| 2638 | 2651 | * will invoke coco3_timer_reset() if $FF94/5 was previously |
| r9722 | r9723 | |
| 2713 | 2726 | static SAM6883_GET_RAMBASE( coco3_sam_get_rambase ) |
| 2714 | 2727 | { |
| 2715 | 2728 | UINT32 video_base; |
| 2716 | | video_base = coco3_get_video_base(0xE0, 0x3F); |
| 2729 | video_base = coco3_get_video_base(device->machine, 0xE0, 0x3F); |
| 2717 | 2730 | return &messram_get_ptr(device->machine->device("messram"))[video_base % messram_get_size(device->machine->device("messram"))]; |
| 2718 | 2731 | } |
| 2719 | 2732 | |
| r9722 | r9723 | |
| 2722 | 2735 | |
| 2723 | 2736 | static SAM6883_SET_MAP_TYPE( coco3_sam_set_maptype ) |
| 2724 | 2737 | { |
| 2725 | | coco3_enable_64k = val; |
| 2738 | coco3_state *state = device->machine->driver_data<coco3_state>(); |
| 2739 | state->enable_64k = val; |
| 2726 | 2740 | coco3_mmu_update(device->machine, 4, 8); |
| 2727 | 2741 | } |
| 2728 | 2742 | |
| r9722 | r9723 | |
| 2836 | 2850 | state->pia_2 = machine->device("pia_2"); |
| 2837 | 2851 | |
| 2838 | 2852 | /* clear static variables */ |
| 2839 | | coco_hiresjoy_ca = 1; |
| 2840 | | coco_hiresjoy_xtransitiontime = attotime_zero; |
| 2841 | | coco_hiresjoy_ytransitiontime = attotime_zero; |
| 2853 | state->hiresjoy_ca = 1; |
| 2854 | state->hiresjoy_xtransitiontime = attotime_zero; |
| 2855 | state->hiresjoy_ytransitiontime = attotime_zero; |
| 2842 | 2856 | |
| 2843 | 2857 | /* set up function pointers */ |
| 2844 | | update_keyboard = coco_update_keyboard; |
| 2845 | | recalc_interrupts = init->recalc_interrupts_; |
| 2858 | state->update_keyboard = coco_update_keyboard; |
| 2859 | state->recalc_interrupts = init->recalc_interrupts_; |
| 2846 | 2860 | |
| 2847 | 2861 | /* this timer is used to schedule keyboard updating */ |
| 2848 | | update_keyboard_timer = timer_alloc(machine, coco_update_keyboard_timerproc, NULL); |
| 2862 | state->update_keyboard_timer = timer_alloc(machine, coco_update_keyboard_timerproc, NULL); |
| 2849 | 2863 | |
| 2850 | 2864 | /* these are the timers to delay the MUX switching */ |
| 2851 | | mux_sel1_timer = timer_alloc(machine, coco_update_sel1_timerproc, NULL); |
| 2852 | | mux_sel2_timer = timer_alloc(machine, coco_update_sel2_timerproc, NULL); |
| 2865 | state->mux_sel1_timer = timer_alloc(machine, coco_update_sel1_timerproc, NULL); |
| 2866 | state->mux_sel2_timer = timer_alloc(machine, coco_update_sel2_timerproc, NULL); |
| 2853 | 2867 | |
| 2854 | 2868 | /* setup ROM */ |
| 2855 | | coco_rom = memory_region(machine, "maincpu"); |
| 2869 | state->rom = memory_region(machine, "maincpu"); |
| 2856 | 2870 | |
| 2857 | 2871 | /* setup default rom bank */ |
| 2858 | | bas_rom_bank = coco_rom; |
| 2872 | state->bas_rom_bank = state->rom; |
| 2859 | 2873 | |
| 2860 | 2874 | /* setup default pointer for botom 32K of ram */ |
| 2861 | | bottom_32k = messram_get_ptr(machine->device("messram")); |
| 2875 | state->bottom_32k = messram_get_ptr(machine->device("messram")); |
| 2862 | 2876 | |
| 2863 | 2877 | /* setup printer output callback */ |
| 2864 | | printer_out = init->printer_out_; |
| 2878 | state->printer_out = init->printer_out_; |
| 2865 | 2879 | if (machine->device<cpu_device>("maincpu")->debug()) { |
| 2866 | 2880 | machine->device<cpu_device>("maincpu")->debug()->set_dasm_override(coco_dasm_override); |
| 2867 | 2881 | } |
| 2868 | 2882 | |
| 2869 | 2883 | /* setup printer input line to "space", this is what a Tandy printer would do */ |
| 2870 | | bitbanger_output_value = 1; |
| 2871 | | bitbanger_input_value = 0; |
| 2872 | | dac_value = 0; |
| 2884 | state->bitbanger_output_value = 1; |
| 2885 | state->bitbanger_input_value = 0; |
| 2886 | state->dac_value = 0; |
| 2873 | 2887 | |
| 2874 | | state_save_register_global(machine, mux_sel1); |
| 2875 | | state_save_register_global(machine, mux_sel2); |
| 2888 | state_save_register_global(machine, state->mux_sel1); |
| 2889 | state_save_register_global(machine, state->mux_sel2); |
| 2876 | 2890 | } |
| 2877 | 2891 | |
| 2878 | 2892 | /* Setup for hardware common to CoCo 1/2 & Dragon machines, calls genertic_init_machine, to process */ |
| r9722 | r9723 | |
| 2971 | 2985 | |
| 2972 | 2986 | MACHINE_RESET( dgnalpha ) |
| 2973 | 2987 | { |
| 2988 | coco_state *state = machine->driver_data<coco_state>(); |
| 2974 | 2989 | running_device *fdc = machine->device("wd2797"); |
| 2975 | 2990 | wd17xx_set_complete_command_delay(fdc,20); |
| 2976 | 2991 | |
| 2977 | | /* dgnalpha_just_reset, is here to flag that we should ignore the first irq generated */ |
| 2992 | /* state->dgnalpha_just_reset, is here to flag that we should ignore the first irq generated */ |
| 2978 | 2993 | /* by the WD2797, it is reset to 0 after the first inurrupt */ |
| 2979 | | dgnalpha_just_reset=1; |
| 2994 | state->dgnalpha_just_reset=1; |
| 2980 | 2995 | |
| 2981 | 2996 | /* need to specify lightgun crosshairs */ |
| 2982 | 2997 | timer_set(machine, attotime_zero, NULL, 0, update_lightgun_timer_callback); |
| r9722 | r9723 | |
| 3024 | 3039 | |
| 3025 | 3040 | MACHINE_RESET( coco3 ) |
| 3026 | 3041 | { |
| 3042 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 3027 | 3043 | int i; |
| 3028 | 3044 | |
| 3029 | 3045 | /* Tepolt verifies that the GIME registers are all cleared on initialization */ |
| 3030 | | coco3_enable_64k = 0; |
| 3031 | | gime_irq = 0; |
| 3032 | | gime_firq = 0; |
| 3046 | state->enable_64k = 0; |
| 3047 | state->gime_irq = 0; |
| 3048 | state->gime_firq = 0; |
| 3033 | 3049 | for (i = 0; i < 8; i++) |
| 3034 | 3050 | { |
| 3035 | | coco3_mmu[i] = coco3_mmu[i + 8] = 56 + i; |
| 3036 | | coco3_gimereg[i] = 0; |
| 3051 | state->mmu[i] = state->mmu[i + 8] = 56 + i; |
| 3052 | state->gimereg[i] = 0; |
| 3037 | 3053 | } |
| 3038 | 3054 | coco3_mmu_update(machine, 0, 8); |
| 3039 | 3055 | } |
| r9722 | r9723 | |
| 3045 | 3061 | |
| 3046 | 3062 | MACHINE_START( coco3 ) |
| 3047 | 3063 | { |
| 3064 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 3048 | 3065 | machine_init_interface init; |
| 3049 | 3066 | |
| 3050 | 3067 | /* Setup machine initialization */ |
| r9722 | r9723 | |
| 3055 | 3072 | generic_init_machine(machine, &init); |
| 3056 | 3073 | |
| 3057 | 3074 | /* CoCo 3 specific function pointers */ |
| 3058 | | update_keyboard = coco3_update_keyboard; |
| 3075 | state->update_keyboard = coco3_update_keyboard; |
| 3059 | 3076 | |
| 3060 | 3077 | coco3_timer_init(machine); |
| 3061 | 3078 | |
| 3062 | | coco3_interupt_line = 0; |
| 3079 | state->interupt_line = 0; |
| 3063 | 3080 | |
| 3064 | 3081 | /* set up state save variables */ |
| 3065 | | state_save_register_global_array(machine, coco3_mmu); |
| 3066 | | state_save_register_global_array(machine, coco3_gimereg); |
| 3067 | | state_save_register_global(machine, coco3_interupt_line); |
| 3068 | | state_save_register_global(machine, gime_irq); |
| 3069 | | state_save_register_global(machine, gime_firq); |
| 3082 | state_save_register_global_array(machine, state->mmu); |
| 3083 | state_save_register_global_array(machine, state->gimereg); |
| 3084 | state_save_register_global(machine, state->interupt_line); |
| 3085 | state_save_register_global(machine, state->gime_irq); |
| 3086 | state_save_register_global(machine, state->gime_firq); |
| 3070 | 3087 | state_save_register_postload(machine, coco3_state_postload, NULL); |
| 3071 | 3088 | |
| 3072 | 3089 | /* need to specify lightgun crosshairs */ |
src/mess/video/coco3.c
| r9722 | r9723 | |
| 45 | 45 | * |
| 46 | 46 | *************************************/ |
| 47 | 47 | |
| 48 | | typedef struct _coco3_scanline_record coco3_scanline_record; |
| 49 | | struct _coco3_scanline_record |
| 50 | | { |
| 51 | | UINT8 ff98; |
| 52 | | UINT8 ff99; |
| 53 | | UINT8 ff9a; |
| 54 | | UINT8 index; |
| 55 | 48 | |
| 56 | | UINT8 palette[16]; |
| 57 | 49 | |
| 58 | | UINT8 data[160]; |
| 59 | | }; |
| 60 | | |
| 61 | | typedef struct _coco3_video coco3_video; |
| 62 | | struct _coco3_video |
| 63 | | { |
| 64 | | /* Info set up on initialization */ |
| 65 | | UINT32 composite_palette[64]; |
| 66 | | UINT32 rgb_palette[64]; |
| 67 | | UINT8 fontdata[128][8]; |
| 68 | | emu_timer *gime_fs_timer; |
| 69 | | |
| 70 | | /* CoCo 3 palette status */ |
| 71 | | UINT8 palette_ram[16]; |
| 72 | | UINT32 palette_colors[16]; |
| 73 | | |
| 74 | | /* Incidentals */ |
| 75 | | UINT32 legacy_video; |
| 76 | | UINT32 top_border_scanlines; |
| 77 | | UINT32 display_scanlines; |
| 78 | | UINT32 video_position; |
| 79 | | UINT8 line_in_row; |
| 80 | | UINT8 blink; |
| 81 | | UINT8 dirty[2]; |
| 82 | | UINT8 video_type; |
| 83 | | |
| 84 | | /* video state; every scanline the video state for the scanline is copied |
| 85 | | * here and only rendered in VIDEO_UPDATE */ |
| 86 | | coco3_scanline_record scanlines[384]; |
| 87 | | }; |
| 88 | | |
| 89 | | static coco3_video *video; |
| 90 | | |
| 91 | | |
| 92 | | |
| 93 | 50 | /************************************* |
| 94 | 51 | * |
| 95 | 52 | * Parameters |
| r9722 | r9723 | |
| 107 | 64 | * |
| 108 | 65 | *************************************/ |
| 109 | 66 | |
| 110 | | static void color_batch(UINT32 *results, const UINT8 *indexes, int count) |
| 67 | static void color_batch(coco3_state *state, UINT32 *results, const UINT8 *indexes, int count) |
| 111 | 68 | { |
| 69 | coco3_video *video = state->video; |
| 112 | 70 | UINT32 c; |
| 113 | 71 | const UINT32 *current_palette; |
| 114 | 72 | int is_black_white; |
| r9722 | r9723 | |
| 124 | 82 | { |
| 125 | 83 | /* Composite/TV */ |
| 126 | 84 | current_palette = video->composite_palette; |
| 127 | | is_black_white = (coco3_gimereg[8] & 0x10) ? TRUE : FALSE; |
| 85 | is_black_white = (state->gimereg[8] & 0x10) ? TRUE : FALSE; |
| 128 | 86 | } |
| 129 | 87 | |
| 130 | 88 | for (i = 0; i < count; i++) |
| r9722 | r9723 | |
| 149 | 107 | |
| 150 | 108 | |
| 151 | 109 | |
| 152 | | static UINT32 color(UINT8 index) |
| 110 | static UINT32 color(coco3_state *state, UINT8 index) |
| 153 | 111 | { |
| 154 | 112 | UINT32 c; |
| 155 | | color_batch(&c, &index, 1); |
| 113 | color_batch(state, &c, &index, 1); |
| 156 | 114 | return c; |
| 157 | 115 | } |
| 158 | 116 | |
| 159 | 117 | |
| 160 | 118 | |
| 161 | | INLINE UINT8 get_char_info(const coco3_scanline_record *scanline_record, |
| 119 | INLINE UINT8 get_char_info(coco3_video *video, const coco3_scanline_record *scanline_record, |
| 162 | 120 | int i, int has_attrs, UINT32 *bg, UINT32 *fg) |
| 163 | 121 | { |
| 164 | 122 | UINT8 byte, attr, char_data = 0x00; |
| r9722 | r9723 | |
| 225 | 183 | |
| 226 | 184 | |
| 227 | 185 | |
| 228 | | static void wide_text_mode(UINT32 *line, const coco3_scanline_record *scanline_record, |
| 186 | static void wide_text_mode(coco3_video *video, UINT32 *line, const coco3_scanline_record *scanline_record, |
| 229 | 187 | int char_count, int has_attrs) |
| 230 | 188 | { |
| 231 | 189 | int i; |
| r9722 | r9723 | |
| 234 | 192 | |
| 235 | 193 | for (i = 0; i < char_count; i++) |
| 236 | 194 | { |
| 237 | | char_data = get_char_info(scanline_record, i, has_attrs, &bg, &fg); |
| 195 | char_data = get_char_info(video, scanline_record, i, has_attrs, &bg, &fg); |
| 238 | 196 | |
| 239 | 197 | line[i * 16 + 0] = line[i * 16 + 1] = (char_data & 0x80) ? fg : bg; |
| 240 | 198 | line[i * 16 + 2] = line[i * 16 + 3] = (char_data & 0x40) ? fg : bg; |
| r9722 | r9723 | |
| 249 | 207 | |
| 250 | 208 | |
| 251 | 209 | |
| 252 | | static void narrow_text_mode(UINT32 *line, const coco3_scanline_record *scanline_record, |
| 210 | static void narrow_text_mode(coco3_video *video, UINT32 *line, const coco3_scanline_record *scanline_record, |
| 253 | 211 | int char_count, int has_attrs) |
| 254 | 212 | { |
| 255 | 213 | int i; |
| r9722 | r9723 | |
| 258 | 216 | |
| 259 | 217 | for (i = 0; i < char_count; i++) |
| 260 | 218 | { |
| 261 | | char_data = get_char_info(scanline_record, i, has_attrs, &bg, &fg); |
| 219 | char_data = get_char_info(video, scanline_record, i, has_attrs, &bg, &fg); |
| 262 | 220 | |
| 263 | 221 | line[i * 8 + 0] = (char_data & 0x80) ? fg : bg; |
| 264 | 222 | line[i * 8 + 1] = (char_data & 0x40) ? fg : bg; |
| r9722 | r9723 | |
| 273 | 231 | |
| 274 | 232 | |
| 275 | 233 | |
| 276 | | INLINE void graphics_mode(UINT32 *RESTRICT line, const coco3_scanline_record *scanline_record, |
| 234 | INLINE void graphics_mode(coco3_state *state, UINT32 *RESTRICT line, const coco3_scanline_record *scanline_record, |
| 277 | 235 | int byte_count, int bpp, int pixel_width) |
| 278 | 236 | { |
| 279 | 237 | int i, j, k; |
| r9722 | r9723 | |
| 281 | 239 | UINT32 c; |
| 282 | 240 | UINT32 colors[16]; |
| 283 | 241 | |
| 284 | | color_batch(colors, scanline_record->palette, 1 << bpp); |
| 242 | color_batch(state, colors, scanline_record->palette, 1 << bpp); |
| 285 | 243 | |
| 286 | 244 | for (i = 0; i < byte_count; i++) |
| 287 | 245 | { |
| r9722 | r9723 | |
| 305 | 263 | |
| 306 | 264 | |
| 307 | 265 | |
| 308 | | static void coco3_render_scanline(bitmap_t *bitmap, int scanline) |
| 266 | static void coco3_render_scanline(running_machine *machine, bitmap_t *bitmap, int scanline) |
| 309 | 267 | { |
| 268 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 269 | coco3_video *video = state->video; |
| 310 | 270 | const coco3_scanline_record *scanline_record; |
| 311 | 271 | UINT32 *line; |
| 312 | 272 | UINT32 border_color; |
| r9722 | r9723 | |
| 315 | 275 | /* get the basics */ |
| 316 | 276 | line = BITMAP_ADDR32(bitmap, scanline, 0); |
| 317 | 277 | scanline_record = &video->scanlines[scanline]; |
| 318 | | border_color = color(scanline_record->ff9a); |
| 278 | border_color = color(state, scanline_record->ff9a); |
| 319 | 279 | |
| 320 | 280 | scanline -= video->top_border_scanlines; |
| 321 | 281 | if ((scanline >= 0) && (scanline < video->display_scanlines)) |
| r9722 | r9723 | |
| 326 | 286 | /* graphics */ |
| 327 | 287 | switch(scanline_record->ff99 & 0x1F) |
| 328 | 288 | { |
| 329 | | case 0x00: graphics_mode(&line[64], scanline_record, 16, 1, 4); break; |
| 330 | | case 0x01: graphics_mode(&line[64], scanline_record, 16, 2, 8); break; |
| 331 | | case 0x02: graphics_mode(&line[64], scanline_record, 16, 4, 16); break; |
| 289 | case 0x00: graphics_mode(state, &line[64], scanline_record, 16, 1, 4); break; |
| 290 | case 0x01: graphics_mode(state, &line[64], scanline_record, 16, 2, 8); break; |
| 291 | case 0x02: graphics_mode(state, &line[64], scanline_record, 16, 4, 16); break; |
| 332 | 292 | case 0x03: graphics_none(&line[64], 512); break; |
| 333 | | case 0x04: graphics_mode(&line[ 0], scanline_record, 20, 1, 4); break; |
| 334 | | case 0x05: graphics_mode(&line[ 0], scanline_record, 20, 2, 8); break; |
| 335 | | case 0x06: graphics_mode(&line[ 0], scanline_record, 20, 4, 16); break; |
| 293 | case 0x04: graphics_mode(state, &line[ 0], scanline_record, 20, 1, 4); break; |
| 294 | case 0x05: graphics_mode(state, &line[ 0], scanline_record, 20, 2, 8); break; |
| 295 | case 0x06: graphics_mode(state, &line[ 0], scanline_record, 20, 4, 16); break; |
| 336 | 296 | case 0x07: graphics_none(&line[ 0], 640); break; |
| 337 | | case 0x08: graphics_mode(&line[64], scanline_record, 32, 1, 2); break; |
| 338 | | case 0x09: graphics_mode(&line[64], scanline_record, 32, 2, 4); break; |
| 339 | | case 0x0A: graphics_mode(&line[64], scanline_record, 32, 4, 8); break; |
| 297 | case 0x08: graphics_mode(state, &line[64], scanline_record, 32, 1, 2); break; |
| 298 | case 0x09: graphics_mode(state, &line[64], scanline_record, 32, 2, 4); break; |
| 299 | case 0x0A: graphics_mode(state, &line[64], scanline_record, 32, 4, 8); break; |
| 340 | 300 | case 0x0B: graphics_none(&line[64], 512); break; |
| 341 | | case 0x0C: graphics_mode(&line[ 0], scanline_record, 40, 1, 2); break; |
| 342 | | case 0x0D: graphics_mode(&line[ 0], scanline_record, 40, 2, 4); break; |
| 343 | | case 0x0E: graphics_mode(&line[ 0], scanline_record, 40, 4, 8); break; |
| 301 | case 0x0C: graphics_mode(state, &line[ 0], scanline_record, 40, 1, 2); break; |
| 302 | case 0x0D: graphics_mode(state, &line[ 0], scanline_record, 40, 2, 4); break; |
| 303 | case 0x0E: graphics_mode(state, &line[ 0], scanline_record, 40, 4, 8); break; |
| 344 | 304 | case 0x0F: graphics_none(&line[ 0], 640); break; |
| 345 | | case 0x10: graphics_mode(&line[64], scanline_record, 64, 1, 1); break; |
| 346 | | case 0x11: graphics_mode(&line[64], scanline_record, 64, 2, 2); break; |
| 347 | | case 0x12: graphics_mode(&line[64], scanline_record, 64, 4, 4); break; |
| 305 | case 0x10: graphics_mode(state, &line[64], scanline_record, 64, 1, 1); break; |
| 306 | case 0x11: graphics_mode(state, &line[64], scanline_record, 64, 2, 2); break; |
| 307 | case 0x12: graphics_mode(state, &line[64], scanline_record, 64, 4, 4); break; |
| 348 | 308 | case 0x13: graphics_none(&line[64], 512); break; |
| 349 | | case 0x14: graphics_mode(&line[ 0], scanline_record, 80, 1, 1); break; |
| 350 | | case 0x15: graphics_mode(&line[ 0], scanline_record, 80, 2, 2); break; |
| 351 | | case 0x16: graphics_mode(&line[ 0], scanline_record, 80, 4, 4); break; |
| 309 | case 0x14: graphics_mode(state, &line[ 0], scanline_record, 80, 1, 1); break; |
| 310 | case 0x15: graphics_mode(state, &line[ 0], scanline_record, 80, 2, 2); break; |
| 311 | case 0x16: graphics_mode(state, &line[ 0], scanline_record, 80, 4, 4); break; |
| 352 | 312 | case 0x17: graphics_none(&line[ 0], 640); break; |
| 353 | 313 | case 0x18: graphics_none(&line[64], 512); break; |
| 354 | | case 0x19: graphics_mode(&line[64], scanline_record, 128, 2, 1); break; |
| 355 | | case 0x1A: graphics_mode(&line[64], scanline_record, 128, 4, 2); break; |
| 314 | case 0x19: graphics_mode(state, &line[64], scanline_record, 128, 2, 1); break; |
| 315 | case 0x1A: graphics_mode(state, &line[64], scanline_record, 128, 4, 2); break; |
| 356 | 316 | case 0x1B: graphics_none(&line[64], 512); break; |
| 357 | 317 | case 0x1C: graphics_none(&line[ 0], 640); break; |
| 358 | | case 0x1D: graphics_mode(&line[ 0], scanline_record, 160, 2, 1); break; |
| 359 | | case 0x1E: graphics_mode(&line[ 0], scanline_record, 160, 4, 2); break; |
| 318 | case 0x1D: graphics_mode(state, &line[ 0], scanline_record, 160, 2, 1); break; |
| 319 | case 0x1E: graphics_mode(state, &line[ 0], scanline_record, 160, 4, 2); break; |
| 360 | 320 | case 0x1F: graphics_none(&line[ 0], 640); break; |
| 361 | 321 | } |
| 362 | 322 | } |
| r9722 | r9723 | |
| 365 | 325 | /* text */ |
| 366 | 326 | switch(scanline_record->ff99 & 0x15) |
| 367 | 327 | { |
| 368 | | case 0x00: wide_text_mode(&line[64], scanline_record, 32, FALSE); break; |
| 369 | | case 0x01: wide_text_mode(&line[64], scanline_record, 32, TRUE); break; |
| 370 | | case 0x04: wide_text_mode(&line[ 0], scanline_record, 40, FALSE); break; |
| 371 | | case 0x05: wide_text_mode(&line[ 0], scanline_record, 40, TRUE); break; |
| 372 | | case 0x10: narrow_text_mode(&line[64], scanline_record, 64, FALSE); break; |
| 373 | | case 0x11: narrow_text_mode(&line[64], scanline_record, 64, TRUE); break; |
| 374 | | case 0x14: narrow_text_mode(&line[ 0], scanline_record, 80, FALSE); break; |
| 375 | | case 0x15: narrow_text_mode(&line[ 0], scanline_record, 80, TRUE); break; |
| 328 | case 0x00: wide_text_mode(video, &line[64], scanline_record, 32, FALSE); break; |
| 329 | case 0x01: wide_text_mode(video, &line[64], scanline_record, 32, TRUE); break; |
| 330 | case 0x04: wide_text_mode(video, &line[ 0], scanline_record, 40, FALSE); break; |
| 331 | case 0x05: wide_text_mode(video, &line[ 0], scanline_record, 40, TRUE); break; |
| 332 | case 0x10: narrow_text_mode(video, &line[64], scanline_record, 64, FALSE); break; |
| 333 | case 0x11: narrow_text_mode(video, &line[64], scanline_record, 64, TRUE); break; |
| 334 | case 0x14: narrow_text_mode(video, &line[ 0], scanline_record, 80, FALSE); break; |
| 335 | case 0x15: narrow_text_mode(video, &line[ 0], scanline_record, 80, TRUE); break; |
| 376 | 336 | } |
| 377 | 337 | } |
| 378 | 338 | |
| r9722 | r9723 | |
| 397 | 357 | |
| 398 | 358 | VIDEO_UPDATE( coco3 ) |
| 399 | 359 | { |
| 360 | coco3_state *state = screen->machine->driver_data<coco3_state>(); |
| 361 | coco3_video *video = state->video; |
| 400 | 362 | int i, row; |
| 401 | 363 | UINT32 *line; |
| 402 | 364 | UINT32 rc = 0; |
| r9722 | r9723 | |
| 417 | 379 | |
| 418 | 380 | /* set all of the palette colors */ |
| 419 | 381 | for (i = 0; i < 16; i++) |
| 420 | | video->palette_colors[i] = color(video->palette_ram[i]); |
| 382 | video->palette_colors[i] = color(state, video->palette_ram[i]); |
| 421 | 383 | |
| 422 | 384 | if (video->legacy_video) |
| 423 | 385 | { |
| r9722 | r9723 | |
| 441 | 403 | if (video->dirty[video->video_type]) |
| 442 | 404 | { |
| 443 | 405 | for (row = cliprect->min_y; row <= cliprect->max_y; row++) |
| 444 | | coco3_render_scanline(bitmap, row); |
| 406 | coco3_render_scanline(screen->machine, bitmap, row); |
| 445 | 407 | video->dirty[video->video_type] = FALSE; |
| 446 | 408 | } |
| 447 | 409 | else |
| r9722 | r9723 | |
| 460 | 422 | * |
| 461 | 423 | *************************************/ |
| 462 | 424 | |
| 463 | | static void coco3_set_dirty(void) |
| 425 | static void coco3_set_dirty(running_machine *machine) |
| 464 | 426 | { |
| 427 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 428 | coco3_video *video = state->video; |
| 465 | 429 | int i; |
| 466 | 430 | for (i = 0; i < ARRAY_LENGTH(video->dirty); i++) |
| 467 | 431 | video->dirty[i] = TRUE; |
| r9722 | r9723 | |
| 471 | 435 | |
| 472 | 436 | static int coco3_new_frame(running_machine *machine) |
| 473 | 437 | { |
| 438 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 439 | coco3_video *video = state->video; |
| 474 | 440 | int gime_field_sync = 0; |
| 475 | 441 | |
| 476 | 442 | /* changing from non-legacy to legacy video? */ |
| 477 | | if (!video->legacy_video && (coco3_gimereg[0] & 0x80)) |
| 478 | | coco3_set_dirty(); |
| 443 | if (!video->legacy_video && (state->gimereg[0] & 0x80)) |
| 444 | coco3_set_dirty(machine); |
| 479 | 445 | |
| 480 | | video->legacy_video = (coco3_gimereg[0] & 0x80) ? TRUE : FALSE; |
| 481 | | video->line_in_row = (coco3_gimereg[12] & 0x0F); |
| 446 | video->legacy_video = (state->gimereg[0] & 0x80) ? TRUE : FALSE; |
| 447 | video->line_in_row = (state->gimereg[12] & 0x0F); |
| 482 | 448 | |
| 483 | 449 | if (!video->legacy_video) |
| 484 | 450 | { |
| 485 | 451 | /* CoCo 3 video */ |
| 486 | | switch(coco3_gimereg[9] & 0x60) |
| 452 | switch(state->gimereg[9] & 0x60) |
| 487 | 453 | { |
| 488 | 454 | case 0x00: /* 192 lines */ |
| 489 | 455 | video->top_border_scanlines = 26; |
| r9722 | r9723 | |
| 509 | 475 | gime_field_sync = video->top_border_scanlines + video->display_scanlines; |
| 510 | 476 | break; |
| 511 | 477 | } |
| 512 | | video->video_position = coco3_get_video_base(0xFF, 0xFF); |
| 478 | video->video_position = coco3_get_video_base(machine, 0xFF, 0xFF); |
| 513 | 479 | } |
| 514 | 480 | else |
| 515 | 481 | { |
| r9722 | r9723 | |
| 540 | 506 | |
| 541 | 507 | static void coco3_prepare_scanline(running_machine *machine, int scanline) |
| 542 | 508 | { |
| 509 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 510 | coco3_video *video = state->video; |
| 543 | 511 | static const UINT32 lines_per_row[] = { 1, 1, 2, 8, 9, 10, 11, ~0 }; |
| 544 | 512 | static const UINT32 gfx_bytes_per_row[] = { 16, 20, 32, 40, 64, 80, 128, 160 }; |
| 545 | 513 | UINT32 video_offset, video_data_size; |
| r9722 | r9723 | |
| 554 | 522 | |
| 555 | 523 | /* copy the basics */ |
| 556 | 524 | scanline_record = &video->scanlines[scanline]; |
| 557 | | memcpy_dirty(&dirty, &scanline_record->ff98, &coco3_gimereg[8], 1); |
| 558 | | memcpy_dirty(&dirty, &scanline_record->ff99, &coco3_gimereg[9], 1); |
| 559 | | memcpy_dirty(&dirty, &scanline_record->ff9a, &coco3_gimereg[10], 1); |
| 525 | memcpy_dirty(&dirty, &scanline_record->ff98, &state->gimereg[8], 1); |
| 526 | memcpy_dirty(&dirty, &scanline_record->ff99, &state->gimereg[9], 1); |
| 527 | memcpy_dirty(&dirty, &scanline_record->ff9a, &state->gimereg[10], 1); |
| 560 | 528 | |
| 561 | 529 | /* is this a display scanline? */ |
| 562 | 530 | scanline -= video->top_border_scanlines; |
| r9722 | r9723 | |
| 567 | 535 | |
| 568 | 536 | /* get ready to copy the video memory; get position and offsets */ |
| 569 | 537 | video_data = &messram_get_ptr(machine->device("messram"))[video->video_position % messram_get_size(machine->device("messram"))]; |
| 570 | | video_offset = (coco3_gimereg[15] & 0x7F) * 2; |
| 538 | video_offset = (state->gimereg[15] & 0x7F) * 2; |
| 571 | 539 | video_data_size = sizeof(scanline_record->data); |
| 572 | 540 | |
| 573 | 541 | /* FF9F offsets wrap around every 256 bytes, even if bit 7 is not set. |
| r9722 | r9723 | |
| 581 | 549 | video->line_in_row++; |
| 582 | 550 | |
| 583 | 551 | /* do we have to advance to the next row? */ |
| 584 | | if (video->line_in_row >= lines_per_row[coco3_gimereg[8] & 0x07]) |
| 552 | if (video->line_in_row >= lines_per_row[state->gimereg[8] & 0x07]) |
| 585 | 553 | { |
| 586 | 554 | /* on to the next row */ |
| 587 | 555 | video->line_in_row = 0; |
| 588 | 556 | |
| 589 | | if (coco3_gimereg[15] & 0x80) |
| 557 | if (state->gimereg[15] & 0x80) |
| 590 | 558 | { |
| 591 | 559 | /* FF9F scrolling mode */ |
| 592 | 560 | bytes_per_row = 256; |
| 593 | 561 | } |
| 594 | | else if (coco3_gimereg[8] & 0x80) |
| 562 | else if (state->gimereg[8] & 0x80) |
| 595 | 563 | { |
| 596 | 564 | /* calc bytes per row for graphics */ |
| 597 | | bytes_per_row = gfx_bytes_per_row[(coco3_gimereg[9] & 0x1C) >> 2]; |
| 565 | bytes_per_row = gfx_bytes_per_row[(state->gimereg[9] & 0x1C) >> 2]; |
| 598 | 566 | } |
| 599 | 567 | else |
| 600 | 568 | { |
| 601 | 569 | /* calc bytes per row for text */ |
| 602 | 570 | bytes_per_row = 32; |
| 603 | | if (coco3_gimereg[9] & 0x04) |
| 571 | if (state->gimereg[9] & 0x04) |
| 604 | 572 | bytes_per_row += 8; |
| 605 | | if (coco3_gimereg[9] & 0x10) |
| 573 | if (state->gimereg[9] & 0x10) |
| 606 | 574 | bytes_per_row *= 2; |
| 607 | | if (coco3_gimereg[9] & 0x01) |
| 575 | if (state->gimereg[9] & 0x01) |
| 608 | 576 | bytes_per_row *= 2; |
| 609 | 577 | } |
| 610 | 578 | |
| r9722 | r9723 | |
| 620 | 588 | } |
| 621 | 589 | } |
| 622 | 590 | if (dirty) |
| 623 | | coco3_set_dirty(); |
| 591 | coco3_set_dirty(machine); |
| 624 | 592 | } |
| 625 | 593 | |
| 626 | 594 | |
| r9722 | r9723 | |
| 639 | 607 | |
| 640 | 608 | |
| 641 | 609 | |
| 642 | | UINT32 coco3_get_video_base(UINT8 ff9d_mask, UINT8 ff9e_mask) |
| 610 | UINT32 coco3_get_video_base(running_machine *machine, UINT8 ff9d_mask, UINT8 ff9e_mask) |
| 643 | 611 | { |
| 612 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 644 | 613 | /* The purpose of the ff9d_mask and ff9e_mask is to mask out bits that are |
| 645 | 614 | * ignored in lo-res mode. Specifically, $FF9D is masked with $E0, and |
| 646 | 615 | * $FF9E is masked with $3F |
| 647 | 616 | * |
| 648 | 617 | * John Kowalski confirms this behavior |
| 649 | 618 | */ |
| 650 | | return ((offs_t) (coco3_gimereg[14] & ff9e_mask) * 0x00008) |
| 651 | | | ((offs_t) (coco3_gimereg[13] & ff9d_mask) * 0x00800) |
| 652 | | | ((offs_t) (coco3_gimereg[11] & 0x0F) * 0x80000); |
| 619 | return ((offs_t) (state->gimereg[14] & ff9e_mask) * 0x00008) |
| 620 | | ((offs_t) (state->gimereg[13] & ff9d_mask) * 0x00800) |
| 621 | | ((offs_t) (state->gimereg[11] & 0x0F) * 0x80000); |
| 653 | 622 | } |
| 654 | 623 | |
| 655 | 624 | |
| r9722 | r9723 | |
| 785 | 754 | |
| 786 | 755 | static STATE_POSTLOAD( coco3_video_postload ) |
| 787 | 756 | { |
| 788 | | coco3_set_dirty(); |
| 757 | coco3_set_dirty(machine); |
| 789 | 758 | } |
| 790 | 759 | |
| 791 | 760 | |
| r9722 | r9723 | |
| 797 | 766 | |
| 798 | 767 | static void internal_video_start_coco3(running_machine *machine, m6847_type type) |
| 799 | 768 | { |
| 769 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 770 | coco3_video *video; |
| 800 | 771 | int i; |
| 801 | 772 | m6847_config cfg; |
| 802 | 773 | const UINT8 *rom; |
| 803 | 774 | |
| 804 | 775 | /* allocate video */ |
| 805 | | video = auto_alloc_clear(machine, coco3_video); |
| 806 | | coco3_set_dirty(); |
| 776 | state->video = video = auto_alloc_clear(machine, coco3_video); |
| 777 | coco3_set_dirty(machine); |
| 807 | 778 | |
| 808 | 779 | /* initialize palette */ |
| 809 | 780 | for (i = 0; i < 64; i++) |
| r9722 | r9723 | |
| 867 | 838 | |
| 868 | 839 | |
| 869 | 840 | |
| 870 | | void coco3_vh_blink(void) |
| 841 | void coco3_vh_blink(running_machine *machine) |
| 871 | 842 | { |
| 843 | coco3_state *state = machine->driver_data<coco3_state>(); |
| 844 | coco3_video *video = state->video; |
| 872 | 845 | video->blink = !video->blink; |
| 873 | | coco3_set_dirty(); |
| 846 | coco3_set_dirty(machine); |
| 874 | 847 | } |