src/mess/machine/ti85.c
| r9675 | r9676 | |
| 27 | 27 | TI_86 |
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | | static UINT8 ti_calculator_model; |
| 31 | 30 | |
| 32 | | UINT8 ti85_timer_interrupt_mask; |
| 33 | | static UINT8 ti85_timer_interrupt_status; |
| 34 | 31 | |
| 35 | | static UINT8 ti85_ON_interrupt_mask; |
| 36 | | static UINT8 ti85_ON_interrupt_status; |
| 37 | | static UINT8 ti85_ON_pressed; |
| 38 | 32 | |
| 39 | | static UINT8 ti8x_memory_page_1; |
| 40 | | static UINT8 ti8x_memory_page_2; |
| 41 | 33 | |
| 42 | | UINT8 ti85_LCD_memory_base; |
| 43 | | UINT8 ti85_LCD_contrast; |
| 44 | | UINT8 ti85_LCD_status; |
| 45 | | static UINT8 ti85_LCD_mask; |
| 46 | 34 | |
| 47 | | static UINT8 ti85_power_mode; |
| 48 | | static UINT8 ti85_keypad_mask; |
| 49 | 35 | |
| 50 | | static UINT8 ti85_video_buffer_width; |
| 51 | | static UINT8 ti85_interrupt_speed; |
| 52 | | static UINT8 ti85_port4_bit0; |
| 53 | 36 | |
| 54 | | static UINT8 ti81_port_7_data; |
| 55 | 37 | |
| 56 | | static UINT8 *ti8x_ram = NULL; |
| 57 | 38 | |
| 58 | | static UINT8 ti85_PCR; |
| 59 | 39 | |
| 60 | | static UINT8 ti85_red_out = 0x00; |
| 61 | | static UINT8 ti85_white_out = 0x00; |
| 62 | 40 | |
| 63 | | static UINT8 ti82_video_mode; |
| 64 | | static UINT8 ti82_video_x; |
| 65 | | static UINT8 ti82_video_y; |
| 66 | | static UINT8 ti82_video_dir; |
| 67 | | static UINT8 ti82_video_scroll; |
| 68 | | static UINT8 ti82_video_bit; |
| 69 | | static UINT8 ti82_video_col; |
| 70 | | static UINT8 ti8x_port2; |
| 71 | | static UINT8 ti83p_port4; |
| 72 | | UINT8 ti82_video_buffer[0x300]; |
| 73 | 41 | |
| 74 | 42 | |
| 75 | 43 | static TIMER_CALLBACK(ti85_timer_callback) |
| 76 | 44 | { |
| 45 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 77 | 46 | if (input_port_read(machine, "ON") & 0x01) |
| 78 | 47 | { |
| 79 | | if (ti85_ON_interrupt_mask && !ti85_ON_pressed) |
| 48 | if (state->ON_interrupt_mask && !state->ON_pressed) |
| 80 | 49 | { |
| 81 | 50 | cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE); |
| 82 | | ti85_ON_interrupt_status = 1; |
| 83 | | if (!ti85_timer_interrupt_mask) ti85_timer_interrupt_mask = 1; |
| 51 | state->ON_interrupt_status = 1; |
| 52 | if (!state->timer_interrupt_mask) state->timer_interrupt_mask = 1; |
| 84 | 53 | } |
| 85 | | ti85_ON_pressed = 1; |
| 54 | state->ON_pressed = 1; |
| 86 | 55 | return; |
| 87 | 56 | } |
| 88 | 57 | else |
| 89 | | ti85_ON_pressed = 0; |
| 90 | | if (ti85_timer_interrupt_mask) |
| 58 | state->ON_pressed = 0; |
| 59 | if (state->timer_interrupt_mask) |
| 91 | 60 | { |
| 92 | 61 | cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE); |
| 93 | | ti85_timer_interrupt_status = 1; |
| 62 | state->timer_interrupt_status = 1; |
| 94 | 63 | } |
| 95 | 64 | } |
| 96 | 65 | |
| 97 | 66 | static void update_ti85_memory (running_machine *machine) |
| 98 | 67 | { |
| 99 | | memory_set_bankptr(machine, "bank2",memory_region(machine, "maincpu") + 0x010000 + 0x004000*ti8x_memory_page_1); |
| 68 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 69 | memory_set_bankptr(machine, "bank2",memory_region(machine, "maincpu") + 0x010000 + 0x004000*state->ti8x_memory_page_1); |
| 100 | 70 | } |
| 101 | 71 | |
| 102 | 72 | static void update_ti83p_memory (running_machine *machine) |
| 103 | 73 | { |
| 74 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 104 | 75 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 105 | 76 | |
| 106 | | if (ti8x_memory_page_1 & 0x40) |
| 77 | if (state->ti8x_memory_page_1 & 0x40) |
| 107 | 78 | { |
| 108 | | if (ti83p_port4 & 1) |
| 79 | if (state->ti83p_port4 & 1) |
| 109 | 80 | { |
| 110 | 81 | |
| 111 | | memory_set_bankptr(machine, "bank3", ti8x_ram + 0x004000*(ti8x_memory_page_1&0x01)); |
| 82 | memory_set_bankptr(machine, "bank3", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_1&0x01)); |
| 112 | 83 | memory_install_write_bank(space, 0x8000, 0xbfff, 0, 0, "bank3"); |
| 113 | 84 | } |
| 114 | 85 | else |
| 115 | 86 | { |
| 116 | | memory_set_bankptr(machine, "bank2", ti8x_ram + 0x004000*(ti8x_memory_page_1&0x01)); |
| 87 | memory_set_bankptr(machine, "bank2", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_1&0x01)); |
| 117 | 88 | memory_install_write_bank(space, 0x4000, 0x7fff, 0, 0, "bank2"); |
| 118 | 89 | } |
| 119 | 90 | } |
| 120 | 91 | else |
| 121 | 92 | { |
| 122 | | if (ti83p_port4 & 1) |
| 93 | if (state->ti83p_port4 & 1) |
| 123 | 94 | { |
| 124 | | memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_1&0x1f)); |
| 95 | memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_1&0x1f)); |
| 125 | 96 | memory_unmap_write(space, 0x8000, 0xbfff, 0, 0); |
| 126 | 97 | } |
| 127 | 98 | else |
| 128 | 99 | { |
| 129 | | memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_1&0x1f)); |
| 100 | memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_1&0x1f)); |
| 130 | 101 | memory_unmap_write(space, 0x4000, 0x7fff, 0, 0); |
| 131 | 102 | } |
| 132 | 103 | } |
| 133 | 104 | |
| 134 | | if (ti8x_memory_page_2 & 0x40) |
| 105 | if (state->ti8x_memory_page_2 & 0x40) |
| 135 | 106 | { |
| 136 | | if (ti83p_port4 & 1) |
| 107 | if (state->ti83p_port4 & 1) |
| 137 | 108 | { |
| 138 | | memory_set_bankptr(machine, "bank4", ti8x_ram + 0x004000*(ti8x_memory_page_2&0x01)); |
| 109 | memory_set_bankptr(machine, "bank4", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_2&0x01)); |
| 139 | 110 | memory_install_write_bank(space, 0xc000, 0xffff, 0, 0, "bank4"); |
| 140 | 111 | } |
| 141 | 112 | else |
| 142 | 113 | { |
| 143 | | memory_set_bankptr(machine, "bank3", ti8x_ram + 0x004000*(ti8x_memory_page_2&0x01)); |
| 114 | memory_set_bankptr(machine, "bank3", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_2&0x01)); |
| 144 | 115 | memory_install_write_bank(space, 0x8000, 0xbfff, 0, 0, "bank3"); |
| 145 | 116 | } |
| 146 | 117 | |
| 147 | 118 | } |
| 148 | 119 | else |
| 149 | 120 | { |
| 150 | | if (ti83p_port4 & 1) |
| 121 | if (state->ti83p_port4 & 1) |
| 151 | 122 | { |
| 152 | | memory_set_bankptr(machine, "bank4", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_2&0x1f)); |
| 123 | memory_set_bankptr(machine, "bank4", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_2&0x1f)); |
| 153 | 124 | memory_unmap_write(space, 0xc000, 0xffff, 0, 0); |
| 154 | 125 | } |
| 155 | 126 | else |
| 156 | 127 | { |
| 157 | | memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_2&0x1f)); |
| 128 | memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_2&0x1f)); |
| 158 | 129 | memory_unmap_write(space, 0x8000, 0xbfff, 0, 0); |
| 159 | 130 | } |
| 160 | 131 | } |
| r9675 | r9676 | |
| 162 | 133 | |
| 163 | 134 | static void update_ti86_memory (running_machine *machine) |
| 164 | 135 | { |
| 136 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 165 | 137 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 166 | 138 | |
| 167 | | if (ti8x_memory_page_1 & 0x40) |
| 139 | if (state->ti8x_memory_page_1 & 0x40) |
| 168 | 140 | { |
| 169 | | memory_set_bankptr(machine, "bank2", ti8x_ram + 0x004000*(ti8x_memory_page_1&0x07)); |
| 141 | memory_set_bankptr(machine, "bank2", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_1&0x07)); |
| 170 | 142 | memory_install_write_bank(space, 0x4000, 0x7fff, 0, 0, "bank2"); |
| 171 | 143 | } |
| 172 | 144 | else |
| 173 | 145 | { |
| 174 | | memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_1&0x0f)); |
| 146 | memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_1&0x0f)); |
| 175 | 147 | memory_unmap_write(space, 0x4000, 0x7fff, 0, 0); |
| 176 | 148 | } |
| 177 | 149 | |
| 178 | | if (ti8x_memory_page_2 & 0x40) |
| 150 | if (state->ti8x_memory_page_2 & 0x40) |
| 179 | 151 | { |
| 180 | | memory_set_bankptr(machine, "bank3", ti8x_ram + 0x004000*(ti8x_memory_page_2&0x07)); |
| 152 | memory_set_bankptr(machine, "bank3", state->ti8x_ram + 0x004000*(state->ti8x_memory_page_2&0x07)); |
| 181 | 153 | memory_install_write_bank(space, 0x8000, 0xbfff, 0, 0, "bank3"); |
| 182 | 154 | } |
| 183 | 155 | else |
| 184 | 156 | { |
| 185 | | memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(ti8x_memory_page_2&0x0f)); |
| 157 | memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0x010000 + 0x004000*(state->ti8x_memory_page_2&0x0f)); |
| 186 | 158 | memory_unmap_write(space, 0x8000, 0xbfff, 0, 0); |
| 187 | 159 | } |
| 188 | 160 | |
| r9675 | r9676 | |
| 194 | 166 | |
| 195 | 167 | MACHINE_START( ti81 ) |
| 196 | 168 | { |
| 169 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 197 | 170 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 198 | 171 | UINT8 *mem = memory_region(machine, "maincpu"); |
| 199 | 172 | |
| 200 | | ti85_timer_interrupt_mask = 0; |
| 201 | | ti85_timer_interrupt_status = 0; |
| 202 | | ti85_ON_interrupt_mask = 0; |
| 203 | | ti85_ON_interrupt_status = 0; |
| 204 | | ti85_ON_pressed = 0; |
| 205 | | ti85_power_mode = 0; |
| 206 | | ti85_keypad_mask = 0; |
| 207 | | ti8x_memory_page_1 = 0; |
| 208 | | ti85_LCD_memory_base = 0; |
| 209 | | ti85_LCD_status = 0; |
| 210 | | ti85_LCD_mask = 0; |
| 211 | | ti85_video_buffer_width = 0; |
| 212 | | ti85_interrupt_speed = 0; |
| 213 | | ti85_port4_bit0 = 0; |
| 214 | | ti81_port_7_data = 0; |
| 173 | state->timer_interrupt_mask = 0; |
| 174 | state->timer_interrupt_status = 0; |
| 175 | state->ON_interrupt_mask = 0; |
| 176 | state->ON_interrupt_status = 0; |
| 177 | state->ON_pressed = 0; |
| 178 | state->power_mode = 0; |
| 179 | state->keypad_mask = 0; |
| 180 | state->ti8x_memory_page_1 = 0; |
| 181 | state->LCD_memory_base = 0; |
| 182 | state->LCD_status = 0; |
| 183 | state->LCD_mask = 0; |
| 184 | state->video_buffer_width = 0; |
| 185 | state->interrupt_speed = 0; |
| 186 | state->port4_bit0 = 0; |
| 187 | state->ti81_port_7_data = 0; |
| 215 | 188 | |
| 216 | | if (ti_calculator_model == TI_81) |
| 189 | if (state->ti_calculator_model == TI_81) |
| 217 | 190 | memset(mem+0x8000, 0, sizeof(unsigned char)*0x8000); |
| 218 | 191 | |
| 219 | | ti_calculator_model = TI_81; |
| 192 | state->ti_calculator_model = TI_81; |
| 220 | 193 | |
| 221 | 194 | timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback); |
| 222 | 195 | |
| r9675 | r9676 | |
| 228 | 201 | |
| 229 | 202 | MACHINE_START( ti82 ) |
| 230 | 203 | { |
| 204 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 231 | 205 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 232 | 206 | UINT8 *mem = memory_region(machine, "maincpu"); |
| 233 | 207 | |
| 234 | | ti85_timer_interrupt_mask = 0; |
| 235 | | ti85_timer_interrupt_status = 0; |
| 236 | | ti85_ON_interrupt_mask = 0; |
| 237 | | ti85_ON_interrupt_status = 0; |
| 238 | | ti85_ON_pressed = 0; |
| 239 | | ti8x_memory_page_1 = 0; |
| 240 | | ti85_LCD_status = 0; |
| 241 | | ti85_LCD_mask = 0; |
| 242 | | ti85_power_mode = 0; |
| 243 | | ti85_keypad_mask = 0; |
| 244 | | ti85_video_buffer_width = 0; |
| 245 | | ti85_interrupt_speed = 0; |
| 246 | | ti85_port4_bit0 = 0; |
| 247 | | ti82_video_mode = 0; |
| 248 | | ti82_video_x = 0; |
| 249 | | ti82_video_y = 0; |
| 250 | | ti82_video_dir = 0; |
| 251 | | ti82_video_scroll = 0; |
| 252 | | ti82_video_bit = 0; |
| 253 | | ti82_video_col = 0; |
| 254 | | memset(ti82_video_buffer, 0x00, 0x300); |
| 208 | state->timer_interrupt_mask = 0; |
| 209 | state->timer_interrupt_status = 0; |
| 210 | state->ON_interrupt_mask = 0; |
| 211 | state->ON_interrupt_status = 0; |
| 212 | state->ON_pressed = 0; |
| 213 | state->ti8x_memory_page_1 = 0; |
| 214 | state->LCD_status = 0; |
| 215 | state->LCD_mask = 0; |
| 216 | state->power_mode = 0; |
| 217 | state->keypad_mask = 0; |
| 218 | state->video_buffer_width = 0; |
| 219 | state->interrupt_speed = 0; |
| 220 | state->port4_bit0 = 0; |
| 221 | state->ti82_video_mode = 0; |
| 222 | state->ti82_video_x = 0; |
| 223 | state->ti82_video_y = 0; |
| 224 | state->ti82_video_dir = 0; |
| 225 | state->ti82_video_scroll = 0; |
| 226 | state->ti82_video_bit = 0; |
| 227 | state->ti82_video_col = 0; |
| 228 | memset(state->ti82_video_buffer, 0x00, 0x300); |
| 255 | 229 | |
| 256 | | if (ti_calculator_model == TI_82) |
| 230 | if (state->ti_calculator_model == TI_82) |
| 257 | 231 | memset(mem+0x8000, 0, sizeof(unsigned char)*0x8000); |
| 258 | 232 | |
| 259 | | ti_calculator_model = TI_82; |
| 233 | state->ti_calculator_model = TI_82; |
| 260 | 234 | |
| 261 | 235 | timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback); |
| 262 | 236 | |
| r9675 | r9676 | |
| 269 | 243 | |
| 270 | 244 | MACHINE_START( ti85 ) |
| 271 | 245 | { |
| 246 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 272 | 247 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 273 | 248 | UINT8 *mem = memory_region(machine, "maincpu"); |
| 274 | 249 | |
| 275 | | ti85_timer_interrupt_mask = 0; |
| 276 | | ti85_timer_interrupt_status = 0; |
| 277 | | ti85_ON_interrupt_mask = 0; |
| 278 | | ti85_ON_interrupt_status = 0; |
| 279 | | ti85_ON_pressed = 0; |
| 280 | | ti8x_memory_page_1 = 0; |
| 281 | | ti85_LCD_memory_base = 0; |
| 282 | | ti85_LCD_status = 0; |
| 283 | | ti85_LCD_mask = 0; |
| 284 | | ti85_power_mode = 0; |
| 285 | | ti85_keypad_mask = 0; |
| 286 | | ti85_video_buffer_width = 0; |
| 287 | | ti85_interrupt_speed = 0; |
| 288 | | ti85_port4_bit0 = 0; |
| 250 | state->timer_interrupt_mask = 0; |
| 251 | state->timer_interrupt_status = 0; |
| 252 | state->ON_interrupt_mask = 0; |
| 253 | state->ON_interrupt_status = 0; |
| 254 | state->ON_pressed = 0; |
| 255 | state->ti8x_memory_page_1 = 0; |
| 256 | state->LCD_memory_base = 0; |
| 257 | state->LCD_status = 0; |
| 258 | state->LCD_mask = 0; |
| 259 | state->power_mode = 0; |
| 260 | state->keypad_mask = 0; |
| 261 | state->video_buffer_width = 0; |
| 262 | state->interrupt_speed = 0; |
| 263 | state->port4_bit0 = 0; |
| 289 | 264 | |
| 290 | | if (ti_calculator_model == TI_85) |
| 265 | if (state->ti_calculator_model == TI_85) |
| 291 | 266 | memset(mem+0x8000, 0, sizeof(unsigned char)*0x8000); |
| 292 | 267 | |
| 293 | | ti_calculator_model = TI_85; |
| 268 | state->ti_calculator_model = TI_85; |
| 294 | 269 | |
| 295 | 270 | timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback); |
| 296 | 271 | |
| r9675 | r9676 | |
| 303 | 278 | |
| 304 | 279 | MACHINE_RESET( ti85 ) |
| 305 | 280 | { |
| 306 | | ti85_red_out = 0x00; |
| 307 | | ti85_white_out = 0x00; |
| 308 | | ti85_PCR = 0xc0; |
| 281 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 282 | state->red_out = 0x00; |
| 283 | state->white_out = 0x00; |
| 284 | state->PCR = 0xc0; |
| 309 | 285 | } |
| 310 | 286 | |
| 311 | 287 | |
| 312 | 288 | MACHINE_START( ti83p ) |
| 313 | 289 | { |
| 290 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 314 | 291 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 315 | 292 | UINT8 *mem = memory_region(machine, "maincpu"); |
| 316 | 293 | |
| 317 | | ti85_timer_interrupt_mask = 0; |
| 318 | | ti85_timer_interrupt_status = 0; |
| 319 | | ti85_ON_interrupt_mask = 0; |
| 320 | | ti85_ON_interrupt_status = 0; |
| 321 | | ti85_ON_pressed = 0; |
| 322 | | ti8x_memory_page_1 = 0; |
| 323 | | ti8x_memory_page_2 = 0; |
| 324 | | ti85_LCD_memory_base = 0; |
| 325 | | ti85_LCD_status = 0; |
| 326 | | ti85_LCD_mask = 0; |
| 327 | | ti85_power_mode = 0; |
| 328 | | ti85_keypad_mask = 0; |
| 329 | | ti85_video_buffer_width = 0; |
| 330 | | ti85_interrupt_speed = 0; |
| 331 | | ti85_port4_bit0 = 0; |
| 332 | | ti82_video_mode = 0; |
| 333 | | ti82_video_x = 0; |
| 334 | | ti82_video_y = 0; |
| 335 | | ti82_video_dir = 0; |
| 336 | | ti82_video_scroll = 0; |
| 337 | | ti82_video_bit = 0; |
| 338 | | ti82_video_col = 0; |
| 339 | | memset(ti82_video_buffer, 0x00, 0x300); |
| 294 | state->timer_interrupt_mask = 0; |
| 295 | state->timer_interrupt_status = 0; |
| 296 | state->ON_interrupt_mask = 0; |
| 297 | state->ON_interrupt_status = 0; |
| 298 | state->ON_pressed = 0; |
| 299 | state->ti8x_memory_page_1 = 0; |
| 300 | state->ti8x_memory_page_2 = 0; |
| 301 | state->LCD_memory_base = 0; |
| 302 | state->LCD_status = 0; |
| 303 | state->LCD_mask = 0; |
| 304 | state->power_mode = 0; |
| 305 | state->keypad_mask = 0; |
| 306 | state->video_buffer_width = 0; |
| 307 | state->interrupt_speed = 0; |
| 308 | state->port4_bit0 = 0; |
| 309 | state->ti82_video_mode = 0; |
| 310 | state->ti82_video_x = 0; |
| 311 | state->ti82_video_y = 0; |
| 312 | state->ti82_video_dir = 0; |
| 313 | state->ti82_video_scroll = 0; |
| 314 | state->ti82_video_bit = 0; |
| 315 | state->ti82_video_col = 0; |
| 316 | memset(state->ti82_video_buffer, 0x00, 0x300); |
| 340 | 317 | |
| 341 | | ti8x_ram = auto_alloc_array(machine, UINT8, 32*1024); |
| 318 | state->ti8x_ram = auto_alloc_array(machine, UINT8, 32*1024); |
| 342 | 319 | { |
| 343 | 320 | memory_unmap_write(space, 0x0000, 0x3fff, 0, 0); |
| 344 | 321 | memory_unmap_write(space, 0x4000, 0x7fff, 0, 0); |
| r9675 | r9676 | |
| 347 | 324 | memory_set_bankptr(machine, "bank1", mem + 0x010000); |
| 348 | 325 | memory_set_bankptr(machine, "bank2", mem + 0x010000); |
| 349 | 326 | memory_set_bankptr(machine, "bank3", mem + 0x010000); |
| 350 | | memory_set_bankptr(machine, "bank4", ti8x_ram); |
| 327 | memory_set_bankptr(machine, "bank4", state->ti8x_ram); |
| 351 | 328 | |
| 352 | | if (ti_calculator_model == TI_83p) |
| 353 | | memset(ti8x_ram, 0, sizeof(unsigned char)*32*1024); |
| 329 | if (state->ti_calculator_model == TI_83p) |
| 330 | memset(state->ti8x_ram, 0, sizeof(unsigned char)*32*1024); |
| 354 | 331 | |
| 355 | 332 | // memset(mem + 0x83000, 0xff, 0x1000); |
| 356 | 333 | |
| 357 | | ti_calculator_model = TI_83p; |
| 334 | state->ti_calculator_model = TI_83p; |
| 358 | 335 | |
| 359 | 336 | timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback); |
| 360 | 337 | } |
| r9675 | r9676 | |
| 363 | 340 | |
| 364 | 341 | MACHINE_START( ti86 ) |
| 365 | 342 | { |
| 343 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 366 | 344 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 367 | 345 | UINT8 *mem = memory_region(machine, "maincpu"); |
| 368 | 346 | |
| 369 | | ti85_timer_interrupt_mask = 0; |
| 370 | | ti85_timer_interrupt_status = 0; |
| 371 | | ti85_ON_interrupt_mask = 0; |
| 372 | | ti85_ON_interrupt_status = 0; |
| 373 | | ti85_ON_pressed = 0; |
| 374 | | ti8x_memory_page_1 = 0; |
| 375 | | ti8x_memory_page_2 = 0; |
| 376 | | ti85_LCD_memory_base = 0; |
| 377 | | ti85_LCD_status = 0; |
| 378 | | ti85_LCD_mask = 0; |
| 379 | | ti85_power_mode = 0; |
| 380 | | ti85_keypad_mask = 0; |
| 381 | | ti85_video_buffer_width = 0; |
| 382 | | ti85_interrupt_speed = 0; |
| 383 | | ti85_port4_bit0 = 0; |
| 347 | state->timer_interrupt_mask = 0; |
| 348 | state->timer_interrupt_status = 0; |
| 349 | state->ON_interrupt_mask = 0; |
| 350 | state->ON_interrupt_status = 0; |
| 351 | state->ON_pressed = 0; |
| 352 | state->ti8x_memory_page_1 = 0; |
| 353 | state->ti8x_memory_page_2 = 0; |
| 354 | state->LCD_memory_base = 0; |
| 355 | state->LCD_status = 0; |
| 356 | state->LCD_mask = 0; |
| 357 | state->power_mode = 0; |
| 358 | state->keypad_mask = 0; |
| 359 | state->video_buffer_width = 0; |
| 360 | state->interrupt_speed = 0; |
| 361 | state->port4_bit0 = 0; |
| 384 | 362 | |
| 385 | | ti8x_ram = auto_alloc_array(machine, UINT8, 128*1024); |
| 363 | state->ti8x_ram = auto_alloc_array(machine, UINT8, 128*1024); |
| 386 | 364 | { |
| 387 | 365 | memory_unmap_write(space, 0x0000, 0x3fff, 0, 0); |
| 388 | 366 | |
| 389 | 367 | memory_set_bankptr(machine, "bank1", mem + 0x010000); |
| 390 | 368 | memory_set_bankptr(machine, "bank2", mem + 0x014000); |
| 391 | 369 | |
| 392 | | memory_set_bankptr(machine, "bank4", ti8x_ram); |
| 370 | memory_set_bankptr(machine, "bank4", state->ti8x_ram); |
| 393 | 371 | |
| 394 | | if (ti_calculator_model == TI_86) |
| 395 | | memset(ti8x_ram, 0, sizeof(unsigned char)*128*1024); |
| 372 | if (state->ti_calculator_model == TI_86) |
| 373 | memset(state->ti8x_ram, 0, sizeof(unsigned char)*128*1024); |
| 396 | 374 | |
| 397 | | ti_calculator_model = TI_86; |
| 375 | state->ti_calculator_model = TI_86; |
| 398 | 376 | |
| 399 | 377 | timer_pulse(machine, ATTOTIME_IN_HZ(200), NULL, 0, ti85_timer_callback); |
| 400 | 378 | } |
| r9675 | r9676 | |
| 410 | 388 | |
| 411 | 389 | READ8_HANDLER ( ti8x_keypad_r ) |
| 412 | 390 | { |
| 391 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 413 | 392 | int data = 0xff; |
| 414 | 393 | int port; |
| 415 | 394 | int bit; |
| 416 | 395 | static const char *const bitnames[] = { "BIT0", "BIT1", "BIT2", "BIT3", "BIT4", "BIT5", "BIT6", "BIT7" }; |
| 417 | 396 | |
| 418 | | if (ti85_keypad_mask == 0x7f) return data; |
| 397 | if (state->keypad_mask == 0x7f) return data; |
| 419 | 398 | |
| 420 | 399 | for (bit = 0; bit < 7; bit++) |
| 421 | 400 | { |
| 422 | | if (~ti85_keypad_mask&(0x01<<bit)) |
| 401 | if (~state->keypad_mask&(0x01<<bit)) |
| 423 | 402 | { |
| 424 | 403 | for (port = 0; port < 8; port++) |
| 425 | 404 | { |
| r9675 | r9676 | |
| 437 | 416 | |
| 438 | 417 | READ8_HANDLER ( ti85_port_0003_r ) |
| 439 | 418 | { |
| 419 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 440 | 420 | int data = 0; |
| 441 | 421 | |
| 442 | | if (ti85_LCD_status) |
| 443 | | data |= ti85_LCD_mask; |
| 444 | | if (ti85_ON_interrupt_status) |
| 422 | if (state->LCD_status) |
| 423 | data |= state->LCD_mask; |
| 424 | if (state->ON_interrupt_status) |
| 445 | 425 | data |= 0x01; |
| 446 | | if (ti85_timer_interrupt_status) |
| 426 | if (state->timer_interrupt_status) |
| 447 | 427 | data |= 0x04; |
| 448 | | if (!ti85_ON_pressed) |
| 428 | if (!state->ON_pressed) |
| 449 | 429 | data |= 0x08; |
| 450 | | ti85_ON_interrupt_status = 0; |
| 451 | | ti85_timer_interrupt_status = 0; |
| 430 | state->ON_interrupt_status = 0; |
| 431 | state->timer_interrupt_status = 0; |
| 452 | 432 | return data; |
| 453 | 433 | } |
| 454 | 434 | |
| r9675 | r9676 | |
| 459 | 439 | |
| 460 | 440 | READ8_HANDLER ( ti85_port_0005_r ) |
| 461 | 441 | { |
| 462 | | return ti8x_memory_page_1; |
| 442 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 443 | return state->ti8x_memory_page_1; |
| 463 | 444 | } |
| 464 | 445 | |
| 465 | 446 | READ8_HANDLER ( ti85_port_0006_r ) |
| 466 | 447 | { |
| 467 | | return ti85_power_mode; |
| 448 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 449 | return state->power_mode; |
| 468 | 450 | } |
| 469 | 451 | |
| 470 | 452 | READ8_HANDLER ( ti85_port_0007_r ) |
| 471 | 453 | { |
| 454 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 472 | 455 | running_device *ti85serial = space->machine->device("ti85serial"); |
| 473 | 456 | |
| 474 | 457 | ti85_update_serial(ti85serial); |
| 475 | | return (ti85_white_out<<3) |
| 476 | | | (ti85_red_out<<2) |
| 477 | | | ((ti85serial_white_in(ti85serial,0)&(1-ti85_white_out))<<1) |
| 478 | | | (ti85serial_red_in(ti85serial,0)&(1-ti85_red_out)) |
| 479 | | | ti85_PCR; |
| 458 | return (state->white_out<<3) |
| 459 | | (state->red_out<<2) |
| 460 | | ((ti85serial_white_in(ti85serial,0)&(1-state->white_out))<<1) |
| 461 | | (ti85serial_red_in(ti85serial,0)&(1-state->red_out)) |
| 462 | | state->PCR; |
| 480 | 463 | } |
| 481 | 464 | |
| 482 | 465 | READ8_HANDLER ( ti82_port_0000_r ) |
| r9675 | r9676 | |
| 486 | 469 | |
| 487 | 470 | READ8_HANDLER ( ti82_port_0002_r ) |
| 488 | 471 | { |
| 489 | | return ti8x_port2; |
| 472 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 473 | return state->ti8x_port2; |
| 490 | 474 | } |
| 491 | 475 | |
| 492 | 476 | READ8_HANDLER ( ti82_port_0010_r ) |
| r9675 | r9676 | |
| 496 | 480 | |
| 497 | 481 | READ8_HANDLER ( ti82_port_0011_r ) |
| 498 | 482 | { |
| 483 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 499 | 484 | UINT8* ti82_video; |
| 500 | 485 | UINT8 ti82_port11; |
| 501 | 486 | |
| 502 | | if(ti82_video_dir == 4) |
| 503 | | ++ti82_video_y; |
| 504 | | if(ti82_video_dir == 5) |
| 505 | | --ti82_video_y; |
| 506 | | if(ti82_video_dir == 6) |
| 507 | | ++ti82_video_x; |
| 508 | | if(ti82_video_dir == 7) |
| 509 | | --ti82_video_x; |
| 487 | if(state->ti82_video_dir == 4) |
| 488 | ++state->ti82_video_y; |
| 489 | if(state->ti82_video_dir == 5) |
| 490 | --state->ti82_video_y; |
| 491 | if(state->ti82_video_dir == 6) |
| 492 | ++state->ti82_video_x; |
| 493 | if(state->ti82_video_dir == 7) |
| 494 | --state->ti82_video_x; |
| 510 | 495 | |
| 511 | | if(ti82_video_mode) |
| 512 | | ti82_port11 = ti82_video_buffer[(12*ti82_video_y)+ti82_video_x]; |
| 496 | if(state->ti82_video_mode) |
| 497 | ti82_port11 = state->ti82_video_buffer[(12*state->ti82_video_y)+state->ti82_video_x]; |
| 513 | 498 | else |
| 514 | 499 | { |
| 515 | | ti82_video_col = ti82_video_x * 6; |
| 516 | | ti82_video_bit = ti82_video_col & 7; |
| 517 | | ti82_video = &ti82_video_buffer[(ti82_video_y*12)+(ti82_video_col>>3)]; |
| 518 | | ti82_port11 = ((((*ti82_video)<<8)+ti82_video[1])>>(10-ti82_video_bit)); |
| 500 | state->ti82_video_col = state->ti82_video_x * 6; |
| 501 | state->ti82_video_bit = state->ti82_video_col & 7; |
| 502 | ti82_video = &state->ti82_video_buffer[(state->ti82_video_y*12)+(state->ti82_video_col>>3)]; |
| 503 | ti82_port11 = ((((*ti82_video)<<8)+ti82_video[1])>>(10-state->ti82_video_bit)); |
| 519 | 504 | } |
| 520 | 505 | |
| 521 | | if(ti82_video_dir == 4) |
| 522 | | ti82_video_y-=2; |
| 523 | | if(ti82_video_dir == 5) |
| 524 | | ti82_video_y+=2; |
| 525 | | if(ti82_video_dir == 6) |
| 526 | | ti82_video_x-=2; |
| 527 | | if(ti82_video_dir == 7) |
| 528 | | ti82_video_x+=2; |
| 506 | if(state->ti82_video_dir == 4) |
| 507 | state->ti82_video_y-=2; |
| 508 | if(state->ti82_video_dir == 5) |
| 509 | state->ti82_video_y+=2; |
| 510 | if(state->ti82_video_dir == 6) |
| 511 | state->ti82_video_x-=2; |
| 512 | if(state->ti82_video_dir == 7) |
| 513 | state->ti82_video_x+=2; |
| 529 | 514 | |
| 530 | | ti82_video_x &= 15; |
| 531 | | ti82_video_y &= 63; |
| 515 | state->ti82_video_x &= 15; |
| 516 | state->ti82_video_y &= 63; |
| 532 | 517 | |
| 533 | 518 | return ti82_port11; |
| 534 | 519 | } |
| 535 | 520 | |
| 536 | 521 | READ8_HANDLER ( ti86_port_0005_r ) |
| 537 | 522 | { |
| 538 | | return ti8x_memory_page_1; |
| 523 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 524 | return state->ti8x_memory_page_1; |
| 539 | 525 | } |
| 540 | 526 | |
| 541 | 527 | READ8_HANDLER ( ti86_port_0006_r ) |
| 542 | 528 | { |
| 543 | | return ti8x_memory_page_2; |
| 529 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 530 | return state->ti8x_memory_page_2; |
| 544 | 531 | } |
| 545 | 532 | |
| 546 | 533 | READ8_HANDLER ( ti83_port_0000_r ) |
| 547 | 534 | { |
| 548 | | return ((ti8x_memory_page_1 & 0x08) << 1) | 0x0C; |
| 535 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 536 | return ((state->ti8x_memory_page_1 & 0x08) << 1) | 0x0C; |
| 549 | 537 | } |
| 550 | 538 | |
| 551 | 539 | READ8_HANDLER ( ti83_port_0002_r ) |
| 552 | 540 | { |
| 553 | | return ti8x_port2; |
| 541 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 542 | return state->ti8x_port2; |
| 554 | 543 | } |
| 555 | 544 | |
| 556 | 545 | READ8_HANDLER ( ti83_port_0003_r ) |
| 557 | 546 | { |
| 547 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 558 | 548 | int data = 0; |
| 559 | 549 | |
| 560 | | if (ti85_LCD_status) |
| 561 | | data |= ti85_LCD_mask; |
| 562 | | if (ti85_ON_interrupt_status) |
| 550 | if (state->LCD_status) |
| 551 | data |= state->LCD_mask; |
| 552 | if (state->ON_interrupt_status) |
| 563 | 553 | data |= 0x01; |
| 564 | | if (!ti85_ON_pressed) |
| 554 | if (!state->ON_pressed) |
| 565 | 555 | data |= 0x08; |
| 566 | | ti85_ON_interrupt_status = 0; |
| 567 | | ti85_timer_interrupt_status = 0; |
| 556 | state->ON_interrupt_status = 0; |
| 557 | state->timer_interrupt_status = 0; |
| 568 | 558 | return data; |
| 569 | 559 | } |
| 570 | 560 | |
| 571 | 561 | READ8_HANDLER ( ti83p_port_0002_r ) |
| 572 | 562 | { |
| 573 | | return ti8x_port2|3; |
| 563 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 564 | return state->ti8x_port2|3; |
| 574 | 565 | } |
| 575 | 566 | |
| 576 | 567 | WRITE8_HANDLER ( ti81_port_0007_w ) |
| 577 | 568 | { |
| 578 | | ti81_port_7_data = data; |
| 569 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 570 | state->ti81_port_7_data = data; |
| 579 | 571 | } |
| 580 | 572 | |
| 581 | 573 | WRITE8_HANDLER ( ti85_port_0000_w ) |
| 582 | 574 | { |
| 583 | | ti85_LCD_memory_base = data; |
| 575 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 576 | state->LCD_memory_base = data; |
| 584 | 577 | } |
| 585 | 578 | |
| 586 | 579 | WRITE8_HANDLER ( ti8x_keypad_w ) |
| 587 | 580 | { |
| 588 | | ti85_keypad_mask = data&0x7f; |
| 581 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 582 | state->keypad_mask = data&0x7f; |
| 589 | 583 | } |
| 590 | 584 | |
| 591 | 585 | WRITE8_HANDLER ( ti85_port_0002_w ) |
| 592 | 586 | { |
| 593 | | ti85_LCD_contrast = data&0x1f; |
| 587 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 588 | state->LCD_contrast = data&0x1f; |
| 594 | 589 | } |
| 595 | 590 | |
| 596 | 591 | WRITE8_HANDLER ( ti85_port_0003_w ) |
| 597 | 592 | { |
| 598 | | if (ti85_LCD_status && !(data&0x08)) ti85_timer_interrupt_mask = 0; |
| 599 | | ti85_ON_interrupt_mask = data&0x01; |
| 600 | | // ti85_timer_interrupt_mask = data&0x04; |
| 601 | | ti85_LCD_mask = data&0x02; |
| 602 | | ti85_LCD_status = data&0x08; |
| 593 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 594 | if (state->LCD_status && !(data&0x08)) state->timer_interrupt_mask = 0; |
| 595 | state->ON_interrupt_mask = data&0x01; |
| 596 | // state->timer_interrupt_mask = data&0x04; |
| 597 | state->LCD_mask = data&0x02; |
| 598 | state->LCD_status = data&0x08; |
| 603 | 599 | } |
| 604 | 600 | |
| 605 | 601 | WRITE8_HANDLER ( ti85_port_0004_w ) |
| 606 | 602 | { |
| 607 | | ti85_video_buffer_width = (data>>3)&0x03; |
| 608 | | ti85_interrupt_speed = (data>>1)&0x03; |
| 609 | | ti85_port4_bit0 = data&0x01; |
| 603 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 604 | state->video_buffer_width = (data>>3)&0x03; |
| 605 | state->interrupt_speed = (data>>1)&0x03; |
| 606 | state->port4_bit0 = data&0x01; |
| 610 | 607 | } |
| 611 | 608 | |
| 612 | 609 | WRITE8_HANDLER ( ti85_port_0005_w ) |
| 613 | 610 | { |
| 614 | | ti8x_memory_page_1 = data; |
| 611 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 612 | state->ti8x_memory_page_1 = data; |
| 615 | 613 | update_ti85_memory(space->machine); |
| 616 | 614 | } |
| 617 | 615 | |
| 618 | 616 | WRITE8_HANDLER ( ti85_port_0006_w ) |
| 619 | 617 | { |
| 620 | | ti85_power_mode = data; |
| 618 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 619 | state->power_mode = data; |
| 621 | 620 | } |
| 622 | 621 | |
| 623 | 622 | WRITE8_HANDLER ( ti85_port_0007_w ) |
| 624 | 623 | { |
| 624 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 625 | 625 | running_device *speaker = space->machine->device("speaker"); |
| 626 | 626 | running_device *ti85serial = space->machine->device("ti85serial"); |
| 627 | 627 | |
| 628 | 628 | speaker_level_w(speaker, ( (data>>2)|(data>>3) ) & 0x01); |
| 629 | | ti85_red_out=(data>>2)&0x01; |
| 630 | | ti85_white_out=(data>>3)&0x01; |
| 631 | | ti85serial_red_out( ti85serial, 0, ti85_red_out ); |
| 632 | | ti85serial_white_out( ti85serial, 0, ti85_white_out ); |
| 629 | state->red_out=(data>>2)&0x01; |
| 630 | state->white_out=(data>>3)&0x01; |
| 631 | ti85serial_red_out( ti85serial, 0, state->red_out ); |
| 632 | ti85serial_white_out( ti85serial, 0, state->white_out ); |
| 633 | 633 | ti85_update_serial(ti85serial); |
| 634 | | ti85_PCR = data&0xf0; |
| 634 | state->PCR = data&0xf0; |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | WRITE8_HANDLER ( ti86_port_0005_w ) |
| 638 | 638 | { |
| 639 | | ti8x_memory_page_1 = data&((data&0x40)?0x47:0x4f); |
| 639 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 640 | state->ti8x_memory_page_1 = data&((data&0x40)?0x47:0x4f); |
| 640 | 641 | update_ti86_memory(space->machine); |
| 641 | 642 | } |
| 642 | 643 | |
| 643 | 644 | WRITE8_HANDLER ( ti86_port_0006_w ) |
| 644 | 645 | { |
| 645 | | ti8x_memory_page_2 = data&((data&0x40)?0x47:0x4f); |
| 646 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 647 | state->ti8x_memory_page_2 = data&((data&0x40)?0x47:0x4f); |
| 646 | 648 | update_ti86_memory(space->machine); |
| 647 | 649 | } |
| 648 | 650 | |
| r9675 | r9676 | |
| 653 | 655 | |
| 654 | 656 | WRITE8_HANDLER ( ti82_port_0002_w ) |
| 655 | 657 | { |
| 656 | | ti8x_memory_page_1 = (data & 0x07); |
| 658 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 659 | state->ti8x_memory_page_1 = (data & 0x07); |
| 657 | 660 | update_ti85_memory(space->machine); |
| 658 | | ti8x_port2 = data; |
| 661 | state->ti8x_port2 = data; |
| 659 | 662 | } |
| 660 | 663 | |
| 661 | 664 | WRITE8_HANDLER ( ti82_port_0010_w ) |
| 662 | 665 | { |
| 666 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 663 | 667 | if (data == 0x00 || data == 0x01) |
| 664 | | ti82_video_mode = data; |
| 668 | state->ti82_video_mode = data; |
| 665 | 669 | if (data >= 0x04 && data <= 0x07) |
| 666 | | ti82_video_dir = data; |
| 670 | state->ti82_video_dir = data; |
| 667 | 671 | if (data >= 0x20 && data <= 0x30) |
| 668 | | ti82_video_x = data - 0x20; |
| 672 | state->ti82_video_x = data - 0x20; |
| 669 | 673 | if (data >= 0x40 && data <= 0x7F) |
| 670 | | ti82_video_scroll = data - 0x40; |
| 674 | state->ti82_video_scroll = data - 0x40; |
| 671 | 675 | if (data >= 0x80 && data <= 0xBF) |
| 672 | | ti82_video_y = data - 0x80; |
| 676 | state->ti82_video_y = data - 0x80; |
| 673 | 677 | if (data >= 0xD8) |
| 674 | | ti85_LCD_contrast = data - 0xD8; |
| 678 | state->LCD_contrast = data - 0xD8; |
| 675 | 679 | } |
| 676 | 680 | |
| 677 | 681 | WRITE8_HANDLER ( ti82_port_0011_w ) |
| 678 | 682 | { |
| 683 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 679 | 684 | UINT8* ti82_video; |
| 680 | 685 | |
| 681 | | if(ti82_video_mode) |
| 682 | | ti82_video_buffer[(12*ti82_video_y)+ti82_video_x] = data; |
| 686 | if(state->ti82_video_mode) |
| 687 | state->ti82_video_buffer[(12*state->ti82_video_y)+state->ti82_video_x] = data; |
| 683 | 688 | else |
| 684 | 689 | { |
| 685 | 690 | data = data<<0x02; |
| 686 | | ti82_video_col = ti82_video_x * 6; |
| 687 | | ti82_video_bit = ti82_video_col & 0x07; |
| 688 | | ti82_video = &ti82_video_buffer[(ti82_video_y*12)+(ti82_video_col>>3)]; |
| 689 | | *ti82_video = (*ti82_video & ~(0xFC>>ti82_video_bit)) | (data>>ti82_video_bit); |
| 690 | | if(ti82_video_bit>0x02) |
| 691 | | ti82_video[1] = (ti82_video[1] & ~(0xFC<<(8-ti82_video_bit))) | (data<<(8-ti82_video_bit)); |
| 691 | state->ti82_video_col = state->ti82_video_x * 6; |
| 692 | state->ti82_video_bit = state->ti82_video_col & 0x07; |
| 693 | ti82_video = &state->ti82_video_buffer[(state->ti82_video_y*12)+(state->ti82_video_col>>3)]; |
| 694 | *ti82_video = (*ti82_video & ~(0xFC>>state->ti82_video_bit)) | (data>>state->ti82_video_bit); |
| 695 | if(state->ti82_video_bit>0x02) |
| 696 | ti82_video[1] = (ti82_video[1] & ~(0xFC<<(8-state->ti82_video_bit))) | (data<<(8-state->ti82_video_bit)); |
| 692 | 697 | } |
| 693 | 698 | |
| 694 | | if(ti82_video_dir == 0x04) |
| 695 | | --ti82_video_y; |
| 696 | | if(ti82_video_dir == 0x05) |
| 697 | | ++ti82_video_y; |
| 698 | | if(ti82_video_dir == 0x06) |
| 699 | | --ti82_video_x; |
| 700 | | if(ti82_video_dir == 0x07) |
| 701 | | ++ti82_video_x; |
| 699 | if(state->ti82_video_dir == 0x04) |
| 700 | --state->ti82_video_y; |
| 701 | if(state->ti82_video_dir == 0x05) |
| 702 | ++state->ti82_video_y; |
| 703 | if(state->ti82_video_dir == 0x06) |
| 704 | --state->ti82_video_x; |
| 705 | if(state->ti82_video_dir == 0x07) |
| 706 | ++state->ti82_video_x; |
| 702 | 707 | |
| 703 | | ti82_video_x &= 15; |
| 704 | | ti82_video_y &= 63; |
| 708 | state->ti82_video_x &= 15; |
| 709 | state->ti82_video_y &= 63; |
| 705 | 710 | } |
| 706 | 711 | |
| 707 | 712 | WRITE8_HANDLER ( ti83_port_0000_w ) |
| 708 | 713 | { |
| 709 | | ti8x_memory_page_1 = (ti8x_memory_page_1 & 7) | ((data & 16) >> 1); |
| 714 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 715 | state->ti8x_memory_page_1 = (state->ti8x_memory_page_1 & 7) | ((data & 16) >> 1); |
| 710 | 716 | update_ti85_memory(space->machine); |
| 711 | 717 | } |
| 712 | 718 | |
| 713 | 719 | WRITE8_HANDLER ( ti83_port_0002_w ) |
| 714 | 720 | { |
| 715 | | ti8x_memory_page_1 = (ti8x_memory_page_1 & 8) | (data & 7); |
| 721 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 722 | state->ti8x_memory_page_1 = (state->ti8x_memory_page_1 & 8) | (data & 7); |
| 716 | 723 | update_ti85_memory(space->machine); |
| 717 | | ti8x_port2 = data; |
| 724 | state->ti8x_port2 = data; |
| 718 | 725 | } |
| 719 | 726 | |
| 720 | 727 | WRITE8_HANDLER ( ti83_port_0003_w ) |
| 721 | 728 | { |
| 722 | | if (ti85_LCD_status && !(data&0x08)) ti85_timer_interrupt_mask = 0; |
| 723 | | ti85_ON_interrupt_mask = data&0x01; |
| 724 | | //ti85_timer_interrupt_mask = data&0x04; |
| 725 | | ti85_LCD_mask = data&0x02; |
| 726 | | ti85_LCD_status = data&0x08; |
| 729 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 730 | if (state->LCD_status && !(data&0x08)) state->timer_interrupt_mask = 0; |
| 731 | state->ON_interrupt_mask = data&0x01; |
| 732 | //state->timer_interrupt_mask = data&0x04; |
| 733 | state->LCD_mask = data&0x02; |
| 734 | state->LCD_status = data&0x08; |
| 727 | 735 | } |
| 728 | 736 | |
| 729 | 737 | WRITE8_HANDLER ( ti83p_port_0002_w ) |
| 730 | 738 | { |
| 731 | | ti8x_port2 = data; |
| 739 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 740 | state->ti8x_port2 = data; |
| 732 | 741 | } |
| 733 | 742 | |
| 734 | 743 | WRITE8_HANDLER ( ti83p_port_0003_w ) |
| 735 | 744 | { |
| 736 | | ti85_LCD_mask = (data&0x08) >> 2; |
| 737 | | ti85_ON_interrupt_mask = data & 0x01; |
| 745 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 746 | state->LCD_mask = (data&0x08) >> 2; |
| 747 | state->ON_interrupt_mask = data & 0x01; |
| 738 | 748 | } |
| 739 | 749 | |
| 740 | 750 | WRITE8_HANDLER ( ti83p_port_0004_w ) |
| 741 | 751 | { |
| 742 | | if ((data & 1) && !(ti83p_port4 & 1)) |
| 752 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 753 | if ((data & 1) && !(state->ti83p_port4 & 1)) |
| 743 | 754 | { |
| 744 | | ti8x_memory_page_1 = 0x1f; |
| 745 | | ti8x_memory_page_2 = 0x1f; |
| 755 | state->ti8x_memory_page_1 = 0x1f; |
| 756 | state->ti8x_memory_page_2 = 0x1f; |
| 746 | 757 | } |
| 747 | | else if (!(data & 1) && (ti83p_port4 & 1)) |
| 758 | else if (!(data & 1) && (state->ti83p_port4 & 1)) |
| 748 | 759 | { |
| 749 | | ti8x_memory_page_1 = 0x1f; |
| 750 | | ti8x_memory_page_2 = 0x40; |
| 760 | state->ti8x_memory_page_1 = 0x1f; |
| 761 | state->ti8x_memory_page_2 = 0x40; |
| 751 | 762 | } |
| 752 | 763 | update_ti83p_memory(space->machine); |
| 753 | | ti83p_port4 = data; |
| 764 | state->ti83p_port4 = data; |
| 754 | 765 | } |
| 755 | 766 | |
| 756 | 767 | WRITE8_HANDLER ( ti83p_port_0006_w ) |
| 757 | 768 | { |
| 758 | | ti8x_memory_page_1 = data & ((data&0x40) ? 0x41 : 0x5f); |
| 769 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 770 | state->ti8x_memory_page_1 = data & ((data&0x40) ? 0x41 : 0x5f); |
| 759 | 771 | update_ti83p_memory(space->machine); |
| 760 | 772 | } |
| 761 | 773 | |
| 762 | 774 | WRITE8_HANDLER ( ti83p_port_0007_w ) |
| 763 | 775 | { |
| 764 | | ti8x_memory_page_2 = data & ((data&0x40) ? 0x41 : 0x5f); |
| 776 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 777 | state->ti8x_memory_page_2 = data & ((data&0x40) ? 0x41 : 0x5f); |
| 765 | 778 | update_ti83p_memory(space->machine); |
| 766 | 779 | } |
| 767 | 780 | |
| 768 | 781 | WRITE8_HANDLER ( ti83p_port_0010_w ) |
| 769 | 782 | { |
| 783 | ti85_state *state = space->machine->driver_data<ti85_state>(); |
| 770 | 784 | if (data == 0x00 || data == 0x01) |
| 771 | | ti82_video_mode = data; |
| 785 | state->ti82_video_mode = data; |
| 772 | 786 | if (data == 0x02 || data == 0x03) |
| 773 | | ti85_LCD_status = data - 0x02; |
| 787 | state->LCD_status = data - 0x02; |
| 774 | 788 | if (data >= 0x04 && data <= 0x07) |
| 775 | | ti82_video_dir = data; |
| 789 | state->ti82_video_dir = data; |
| 776 | 790 | if (data >= 0x20 && data <= 0x30) |
| 777 | | ti82_video_x = data - 0x20; |
| 791 | state->ti82_video_x = data - 0x20; |
| 778 | 792 | if (data >= 0x40 && data <= 0x7F) |
| 779 | | ti82_video_scroll = data - 0x40; |
| 793 | state->ti82_video_scroll = data - 0x40; |
| 780 | 794 | if (data >= 0x80 && data <= 0xBF) |
| 781 | | ti82_video_y = data - 0x80; |
| 795 | state->ti82_video_y = data - 0x80; |
| 782 | 796 | if (data >= 0xc8) |
| 783 | | ti85_LCD_contrast = data - 0xc8; |
| 797 | state->LCD_contrast = data - 0xc8; |
| 784 | 798 | |
| 785 | 799 | } |
| 786 | 800 | |
| 787 | 801 | /* NVRAM functions */ |
| 788 | 802 | NVRAM_HANDLER( ti83p ) |
| 789 | 803 | { |
| 804 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 790 | 805 | if (read_or_write) |
| 791 | 806 | { |
| 792 | | mame_fwrite(file, ti8x_ram, sizeof(unsigned char)*32*1024); |
| 807 | mame_fwrite(file, state->ti8x_ram, sizeof(unsigned char)*32*1024); |
| 793 | 808 | } |
| 794 | 809 | else |
| 795 | 810 | { |
| 796 | 811 | if (file) |
| 797 | 812 | { |
| 798 | | mame_fread(file, ti8x_ram, sizeof(unsigned char)*32*1024); |
| 813 | mame_fread(file, state->ti8x_ram, sizeof(unsigned char)*32*1024); |
| 799 | 814 | cpu_set_reg(machine->device("maincpu"), Z80_PC,0x0c59); |
| 800 | 815 | } |
| 801 | 816 | else |
| 802 | | memset(ti8x_ram, 0, sizeof(unsigned char)*32*1024); |
| 817 | memset(state->ti8x_ram, 0, sizeof(unsigned char)*32*1024); |
| 803 | 818 | } |
| 804 | 819 | } |
| 805 | 820 | |
| 806 | 821 | NVRAM_HANDLER( ti86 ) |
| 807 | 822 | { |
| 823 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 808 | 824 | if (read_or_write) |
| 809 | 825 | { |
| 810 | | mame_fwrite(file, ti8x_ram, sizeof(unsigned char)*128*1024); |
| 826 | mame_fwrite(file, state->ti8x_ram, sizeof(unsigned char)*128*1024); |
| 811 | 827 | } |
| 812 | 828 | else |
| 813 | 829 | { |
| 814 | 830 | if (file) |
| 815 | 831 | { |
| 816 | | mame_fread(file, ti8x_ram, sizeof(unsigned char)*128*1024); |
| 832 | mame_fread(file, state->ti8x_ram, sizeof(unsigned char)*128*1024); |
| 817 | 833 | cpu_set_reg(machine->device("maincpu"), Z80_PC,0x0c59); |
| 818 | 834 | } |
| 819 | 835 | else |
| 820 | | memset(ti8x_ram, 0, sizeof(unsigned char)*128*1024); |
| 836 | memset(state->ti8x_ram, 0, sizeof(unsigned char)*128*1024); |
| 821 | 837 | } |
| 822 | 838 | } |
| 823 | 839 | |
| r9675 | r9676 | |
| 882 | 898 | |
| 883 | 899 | static void ti85_setup_snapshot (running_machine *machine, UINT8 * data) |
| 884 | 900 | { |
| 901 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 885 | 902 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 886 | 903 | int i; |
| 887 | 904 | unsigned char lo,hi; |
| r9675 | r9676 | |
| 893 | 910 | for (i = 0; i < 0x8000; i++) |
| 894 | 911 | space->write_byte(i + 0x8000, data[i+0x94]); |
| 895 | 912 | |
| 896 | | ti85_keypad_mask = hdw[0x00]&0x7f; |
| 913 | state->keypad_mask = hdw[0x00]&0x7f; |
| 897 | 914 | |
| 898 | | ti8x_memory_page_1 = hdw[0x08]&0xff; |
| 915 | state->ti8x_memory_page_1 = hdw[0x08]&0xff; |
| 899 | 916 | update_ti85_memory(machine); |
| 900 | 917 | |
| 901 | | ti85_power_mode = hdw[0x14]&0xff; |
| 918 | state->power_mode = hdw[0x14]&0xff; |
| 902 | 919 | |
| 903 | 920 | lo = hdw[0x28] & 0x0ff; |
| 904 | 921 | hi = hdw[0x29] & 0x0ff; |
| 905 | | ti85_LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8; |
| 922 | state->LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8; |
| 906 | 923 | |
| 907 | | ti85_LCD_status = hdw[0x2c]&0xff ? 0 : 0x08; |
| 908 | | if (ti85_LCD_status) ti85_LCD_mask = 0x02; |
| 924 | state->LCD_status = hdw[0x2c]&0xff ? 0 : 0x08; |
| 925 | if (state->LCD_status) state->LCD_mask = 0x02; |
| 909 | 926 | |
| 910 | | ti85_LCD_contrast = hdw[0x30]&0xff; |
| 927 | state->LCD_contrast = hdw[0x30]&0xff; |
| 911 | 928 | |
| 912 | | ti85_timer_interrupt_mask = !hdw[0x38]; |
| 913 | | ti85_timer_interrupt_status = 0; |
| 929 | state->timer_interrupt_mask = !hdw[0x38]; |
| 930 | state->timer_interrupt_status = 0; |
| 914 | 931 | |
| 915 | | ti85_ON_interrupt_mask = !ti85_LCD_status && ti85_timer_interrupt_status; |
| 916 | | ti85_ON_interrupt_status = 0; |
| 917 | | ti85_ON_pressed = 0; |
| 932 | state->ON_interrupt_mask = !state->LCD_status && state->timer_interrupt_status; |
| 933 | state->ON_interrupt_status = 0; |
| 934 | state->ON_pressed = 0; |
| 918 | 935 | |
| 919 | | ti85_video_buffer_width = 0x02; |
| 920 | | ti85_interrupt_speed = 0x03; |
| 936 | state->video_buffer_width = 0x02; |
| 937 | state->interrupt_speed = 0x03; |
| 921 | 938 | } |
| 922 | 939 | |
| 923 | 940 | static void ti86_setup_snapshot (running_machine *machine, UINT8 * data) |
| 924 | 941 | { |
| 942 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 925 | 943 | unsigned char lo,hi; |
| 926 | 944 | unsigned char * hdw = data + 0x20000 + 0x94; |
| 927 | 945 | |
| 928 | 946 | ti8x_snapshot_setup_registers (machine, data); |
| 929 | 947 | |
| 930 | 948 | /* Memory dump */ |
| 931 | | memcpy(ti8x_ram, data+0x94, 0x20000); |
| 949 | memcpy(state->ti8x_ram, data+0x94, 0x20000); |
| 932 | 950 | |
| 933 | | ti85_keypad_mask = hdw[0x00]&0x7f; |
| 951 | state->keypad_mask = hdw[0x00]&0x7f; |
| 934 | 952 | |
| 935 | | ti8x_memory_page_1 = hdw[0x04]&0xff ? 0x40 : 0x00; |
| 936 | | ti8x_memory_page_1 |= hdw[0x08]&0x0f; |
| 953 | state->ti8x_memory_page_1 = hdw[0x04]&0xff ? 0x40 : 0x00; |
| 954 | state->ti8x_memory_page_1 |= hdw[0x08]&0x0f; |
| 937 | 955 | |
| 938 | | ti8x_memory_page_2 = hdw[0x0c]&0xff ? 0x40 : 0x00; |
| 939 | | ti8x_memory_page_2 |= hdw[0x10]&0x0f; |
| 956 | state->ti8x_memory_page_2 = hdw[0x0c]&0xff ? 0x40 : 0x00; |
| 957 | state->ti8x_memory_page_2 |= hdw[0x10]&0x0f; |
| 940 | 958 | |
| 941 | 959 | update_ti86_memory(machine); |
| 942 | 960 | |
| 943 | 961 | lo = hdw[0x2c] & 0x0ff; |
| 944 | 962 | hi = hdw[0x2d] & 0x0ff; |
| 945 | | ti85_LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8; |
| 963 | state->LCD_memory_base = (((hi << 8) | lo)-0xc000)>>8; |
| 946 | 964 | |
| 947 | | ti85_LCD_status = hdw[0x30]&0xff ? 0 : 0x08; |
| 948 | | if (ti85_LCD_status) ti85_LCD_mask = 0x02; |
| 965 | state->LCD_status = hdw[0x30]&0xff ? 0 : 0x08; |
| 966 | if (state->LCD_status) state->LCD_mask = 0x02; |
| 949 | 967 | |
| 950 | | ti85_LCD_contrast = hdw[0x34]&0xff; |
| 968 | state->LCD_contrast = hdw[0x34]&0xff; |
| 951 | 969 | |
| 952 | | ti85_timer_interrupt_mask = !hdw[0x3c]; |
| 953 | | ti85_timer_interrupt_status = 0; |
| 970 | state->timer_interrupt_mask = !hdw[0x3c]; |
| 971 | state->timer_interrupt_status = 0; |
| 954 | 972 | |
| 955 | | ti85_ON_interrupt_mask = !ti85_LCD_status && ti85_timer_interrupt_status; |
| 956 | | ti85_ON_interrupt_status = 0; |
| 957 | | ti85_ON_pressed = 0; |
| 973 | state->ON_interrupt_mask = !state->LCD_status && state->timer_interrupt_status; |
| 974 | state->ON_interrupt_status = 0; |
| 975 | state->ON_pressed = 0; |
| 958 | 976 | |
| 959 | | ti85_video_buffer_width = 0x02; |
| 960 | | ti85_interrupt_speed = 0x03; |
| 977 | state->video_buffer_width = 0x02; |
| 978 | state->interrupt_speed = 0x03; |
| 961 | 979 | } |
| 962 | 980 | |
| 963 | 981 | SNAPSHOT_LOAD( ti8x ) |
| 964 | 982 | { |
| 983 | ti85_state *state = image.device().machine->driver_data<ti85_state>(); |
| 965 | 984 | int expected_snapshot_size = 0; |
| 966 | 985 | UINT8 *ti8x_snapshot_data; |
| 967 | 986 | |
| 968 | | switch (ti_calculator_model) |
| 987 | switch (state->ti_calculator_model) |
| 969 | 988 | { |
| 970 | 989 | case TI_85: expected_snapshot_size = TI85_SNAPSHOT_SIZE; break; |
| 971 | 990 | case TI_86: expected_snapshot_size = TI86_SNAPSHOT_SIZE; break; |
| r9675 | r9676 | |
| 984 | 1003 | |
| 985 | 1004 | image.fread( ti8x_snapshot_data, snapshot_size); |
| 986 | 1005 | |
| 987 | | switch (ti_calculator_model) |
| 1006 | switch (state->ti_calculator_model) |
| 988 | 1007 | { |
| 989 | 1008 | case TI_85: ti85_setup_snapshot(image.device().machine, ti8x_snapshot_data); break; |
| 990 | 1009 | case TI_86: ti86_setup_snapshot(image.device().machine, ti8x_snapshot_data); break; |
src/mess/video/ti85.c
| r9675 | r9676 | |
| 38 | 38 | #define TI73_SCREEN_Y_SIZE 64 |
| 39 | 39 | #define TI73_NUMBER_OF_FRAMES 6 |
| 40 | 40 | |
| 41 | | static int ti_video_memory_size; |
| 42 | | static int ti_screen_x_size; |
| 43 | | static int ti_screen_y_size; |
| 44 | | static int ti_number_of_frames; |
| 45 | 41 | |
| 46 | | static UINT8 * ti85_frames; |
| 47 | 42 | |
| 48 | 43 | static const unsigned char ti85_colors[32*7][3] = |
| 49 | 44 | { |
| r9675 | r9676 | |
| 119 | 114 | |
| 120 | 115 | PALETTE_INIT( ti85 ) |
| 121 | 116 | { |
| 117 | ti85_state *state = machine->driver_data<ti85_state>(); |
| 122 | 118 | UINT8 i, j, r, g, b; |
| 123 | 119 | |
| 124 | 120 | machine->colortable = colortable_alloc(machine, 224); |
| r9675 | r9676 | |
| 135 | 131 | |
| 136 | 132 | if (!strncmp(machine->gamedrv->name, "ti81", 4)) |
| 137 | 133 | { |
| 138 | | ti_video_memory_size = TI81_VIDEO_MEMORY_SIZE; |
| 139 | | ti_screen_x_size = TI81_SCREEN_X_SIZE; |
| 140 | | ti_screen_y_size = TI81_SCREEN_Y_SIZE; |
| 141 | | ti_number_of_frames = TI81_NUMBER_OF_FRAMES; |
| 134 | state->ti_video_memory_size = TI81_VIDEO_MEMORY_SIZE; |
| 135 | state->ti_screen_x_size = TI81_SCREEN_X_SIZE; |
| 136 | state->ti_screen_y_size = TI81_SCREEN_Y_SIZE; |
| 137 | state->ti_number_of_frames = TI81_NUMBER_OF_FRAMES; |
| 142 | 138 | } |
| 143 | 139 | else if (!strncmp(machine->gamedrv->name, "ti85", 4)) |
| 144 | 140 | { |
| 145 | | ti_video_memory_size = TI85_VIDEO_MEMORY_SIZE; |
| 146 | | ti_screen_x_size = TI85_SCREEN_X_SIZE; |
| 147 | | ti_screen_y_size = TI85_SCREEN_Y_SIZE; |
| 148 | | ti_number_of_frames = TI85_NUMBER_OF_FRAMES; |
| 141 | state->ti_video_memory_size = TI85_VIDEO_MEMORY_SIZE; |
| 142 | state->ti_screen_x_size = TI85_SCREEN_X_SIZE; |
| 143 | state->ti_screen_y_size = TI85_SCREEN_Y_SIZE; |
| 144 | state->ti_number_of_frames = TI85_NUMBER_OF_FRAMES; |
| 149 | 145 | } |
| 150 | 146 | else if (!strncmp(machine->gamedrv->name, "ti82", 4)) |
| 151 | 147 | { |
| 152 | | ti_video_memory_size = TI82_VIDEO_MEMORY_SIZE; |
| 153 | | ti_screen_x_size = TI82_SCREEN_X_SIZE; |
| 154 | | ti_screen_y_size = TI82_SCREEN_Y_SIZE; |
| 155 | | ti_number_of_frames = TI82_NUMBER_OF_FRAMES; |
| 148 | state->ti_video_memory_size = TI82_VIDEO_MEMORY_SIZE; |
| 149 | state->ti_screen_x_size = TI82_SCREEN_X_SIZE; |
| 150 | state->ti_screen_y_size = TI82_SCREEN_Y_SIZE; |
| 151 | state->ti_number_of_frames = TI82_NUMBER_OF_FRAMES; |
| 156 | 152 | } |
| 157 | 153 | else if (!strncmp(machine->gamedrv->name, "ti83p", 5)) |
| 158 | 154 | { |
| 159 | | ti_video_memory_size = TI83_VIDEO_MEMORY_SIZE; |
| 160 | | ti_screen_x_size = TI83_SCREEN_X_SIZE; |
| 161 | | ti_screen_y_size = TI83_SCREEN_Y_SIZE; |
| 162 | | ti_number_of_frames = TI83_NUMBER_OF_FRAMES; |
| 155 | state->ti_video_memory_size = TI83_VIDEO_MEMORY_SIZE; |
| 156 | state->ti_screen_x_size = TI83_SCREEN_X_SIZE; |
| 157 | state->ti_screen_y_size = TI83_SCREEN_Y_SIZE; |
| 158 | state->ti_number_of_frames = TI83_NUMBER_OF_FRAMES; |
| 163 | 159 | } |
| 164 | 160 | else if (!strncmp(machine->gamedrv->name, "ti83", 4)) |
| 165 | 161 | { |
| 166 | | ti_video_memory_size = TI83_VIDEO_MEMORY_SIZE; |
| 167 | | ti_screen_x_size = TI83_SCREEN_X_SIZE; |
| 168 | | ti_screen_y_size = TI83_SCREEN_Y_SIZE; |
| 169 | | ti_number_of_frames = TI83_NUMBER_OF_FRAMES; |
| 162 | state->ti_video_memory_size = TI83_VIDEO_MEMORY_SIZE; |
| 163 | state->ti_screen_x_size = TI83_SCREEN_X_SIZE; |
| 164 | state->ti_screen_y_size = TI83_SCREEN_Y_SIZE; |
| 165 | state->ti_number_of_frames = TI83_NUMBER_OF_FRAMES; |
| 170 | 166 | } |
| 171 | 167 | else if (!strncmp(machine->gamedrv->name, "ti86", 4)) |
| 172 | 168 | { |
| 173 | | ti_video_memory_size = TI86_VIDEO_MEMORY_SIZE; |
| 174 | | ti_screen_x_size = TI86_SCREEN_X_SIZE; |
| 175 | | ti_screen_y_size = TI86_SCREEN_Y_SIZE; |
| 176 | | ti_number_of_frames = TI86_NUMBER_OF_FRAMES; |
| 169 | state->ti_video_memory_size = TI86_VIDEO_MEMORY_SIZE; |
| 170 | state->ti_screen_x_size = TI86_SCREEN_X_SIZE; |
| 171 | state->ti_screen_y_size = TI86_SCREEN_Y_SIZE; |
| 172 | state->ti_number_of_frames = TI86_NUMBER_OF_FRAMES; |
| 177 | 173 | } |
| 178 | 174 | else if (!strncmp(machine->gamedrv->name, "ti73", 4)) |
| 179 | 175 | { |
| 180 | | ti_video_memory_size = TI73_VIDEO_MEMORY_SIZE; |
| 181 | | ti_screen_x_size = TI73_SCREEN_X_SIZE; |
| 182 | | ti_screen_y_size = TI73_SCREEN_Y_SIZE; |
| 183 | | ti_number_of_frames = TI73_NUMBER_OF_FRAMES; |
| 176 | state->ti_video_memory_size = TI73_VIDEO_MEMORY_SIZE; |
| 177 | state->ti_screen_x_size = TI73_SCREEN_X_SIZE; |
| 178 | state->ti_screen_y_size = TI73_SCREEN_Y_SIZE; |
| 179 | state->ti_number_of_frames = TI73_NUMBER_OF_FRAMES; |
| 184 | 180 | } |
| 185 | 181 | else |
| 186 | 182 | { |
| r9675 | r9676 | |
| 188 | 184 | return; |
| 189 | 185 | } |
| 190 | 186 | |
| 191 | | ti85_frames = auto_alloc_array_clear(machine, UINT8, ti_number_of_frames*ti_video_memory_size); |
| 187 | state->frames = auto_alloc_array_clear(machine, UINT8, state->ti_number_of_frames*state->ti_video_memory_size); |
| 192 | 188 | } |
| 193 | 189 | |
| 194 | 190 | VIDEO_START( ti85 ) |
| r9675 | r9676 | |
| 197 | 193 | |
| 198 | 194 | VIDEO_UPDATE( ti85 ) |
| 199 | 195 | { |
| 196 | ti85_state *state = screen->machine->driver_data<ti85_state>(); |
| 200 | 197 | address_space *space = cputag_get_address_space(screen->machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 201 | 198 | int x,y,b; |
| 202 | 199 | int brightnes; |
| 203 | 200 | int lcdmem; |
| 204 | 201 | |
| 205 | | if (!ti85_LCD_status || !ti85_timer_interrupt_mask) |
| 202 | if (!state->LCD_status || !state->timer_interrupt_mask) |
| 206 | 203 | { |
| 207 | | for (y=0; y<ti_screen_y_size; y++) |
| 208 | | for (x=0; x<ti_screen_x_size; x++) |
| 204 | for (y=0; y<state->ti_screen_y_size; y++) |
| 205 | for (x=0; x<state->ti_screen_x_size; x++) |
| 209 | 206 | for (b=0; b<8; b++) |
| 210 | | *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[ti85_LCD_contrast&0x1f][6]; |
| 207 | *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[state->LCD_contrast&0x1f][6]; |
| 211 | 208 | return 0; |
| 212 | 209 | } |
| 213 | 210 | |
| 214 | | lcdmem = ((ti85_LCD_memory_base & 0x3F) + 0xc0) << 0x08; |
| 211 | lcdmem = ((state->LCD_memory_base & 0x3F) + 0xc0) << 0x08; |
| 215 | 212 | |
| 216 | | memcpy (ti85_frames, ti85_frames+ti_video_memory_size, sizeof (UINT8) * (ti_number_of_frames-1) * ti_video_memory_size); |
| 213 | memcpy (state->frames, state->frames+state->ti_video_memory_size, sizeof (UINT8) * (state->ti_number_of_frames-1) * state->ti_video_memory_size); |
| 217 | 214 | |
| 218 | | for (y=0; y<ti_screen_y_size; y++) |
| 219 | | for (x=0; x<ti_screen_x_size; x++) |
| 220 | | *(ti85_frames+(ti_number_of_frames-1)*ti_video_memory_size+y*ti_screen_x_size+x) = space->read_byte(lcdmem+y*ti_screen_x_size+x); |
| 215 | for (y=0; y<state->ti_screen_y_size; y++) |
| 216 | for (x=0; x<state->ti_screen_x_size; x++) |
| 217 | *(state->frames+(state->ti_number_of_frames-1)*state->ti_video_memory_size+y*state->ti_screen_x_size+x) = space->read_byte(lcdmem+y*state->ti_screen_x_size+x); |
| 221 | 218 | |
| 222 | | for (y=0; y<ti_screen_y_size; y++) |
| 223 | | for (x=0; x<ti_screen_x_size; x++) |
| 219 | for (y=0; y<state->ti_screen_y_size; y++) |
| 220 | for (x=0; x<state->ti_screen_x_size; x++) |
| 224 | 221 | for (b=0; b<8; b++) |
| 225 | 222 | { |
| 226 | | brightnes = ((*(ti85_frames+0*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 227 | | + ((*(ti85_frames+1*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 228 | | + ((*(ti85_frames+2*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 229 | | + ((*(ti85_frames+3*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 230 | | + ((*(ti85_frames+4*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 231 | | + ((*(ti85_frames+5*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01); |
| 223 | brightnes = ((*(state->frames+0*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 224 | + ((*(state->frames+1*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 225 | + ((*(state->frames+2*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 226 | + ((*(state->frames+3*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 227 | + ((*(state->frames+4*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 228 | + ((*(state->frames+5*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01); |
| 232 | 229 | |
| 233 | | *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[ti85_LCD_contrast&0x1f][brightnes]; |
| 230 | *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[state->LCD_contrast&0x1f][brightnes]; |
| 234 | 231 | } |
| 235 | 232 | return 0; |
| 236 | 233 | } |
| 237 | 234 | |
| 238 | 235 | VIDEO_UPDATE( ti82 ) |
| 239 | 236 | { |
| 237 | ti85_state *state = screen->machine->driver_data<ti85_state>(); |
| 240 | 238 | //for now use the ti85_palette |
| 241 | 239 | |
| 242 | 240 | int x,y,b; |
| 243 | 241 | int brightnes; |
| 244 | 242 | |
| 245 | | if (!ti85_LCD_status || !ti85_timer_interrupt_mask) |
| 243 | if (!state->LCD_status || !state->timer_interrupt_mask) |
| 246 | 244 | { |
| 247 | | for (y=0; y<ti_screen_y_size; y++) |
| 248 | | for (x=0; x<ti_screen_x_size; x++) |
| 245 | for (y=0; y<state->ti_screen_y_size; y++) |
| 246 | for (x=0; x<state->ti_screen_x_size; x++) |
| 249 | 247 | for (b=0; b<8; b++) |
| 250 | | *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[ti85_LCD_contrast&0x1f][6]; |
| 248 | *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[state->LCD_contrast&0x1f][6]; |
| 251 | 249 | return 0; |
| 252 | 250 | } |
| 253 | 251 | |
| 254 | | memcpy (ti85_frames, ti85_frames+ti_video_memory_size, sizeof (UINT8) * (ti_number_of_frames-1) * ti_video_memory_size); |
| 252 | memcpy (state->frames, state->frames+state->ti_video_memory_size, sizeof (UINT8) * (state->ti_number_of_frames-1) * state->ti_video_memory_size); |
| 255 | 253 | |
| 256 | | for (y=0; y<ti_screen_y_size; y++) |
| 257 | | for (x=0; x<ti_screen_x_size; x++) |
| 258 | | *(ti85_frames+(ti_number_of_frames-1)*ti_video_memory_size+y*ti_screen_x_size+x) = ti82_video_buffer[ y*ti_screen_x_size+x]; |
| 254 | for (y=0; y<state->ti_screen_y_size; y++) |
| 255 | for (x=0; x<state->ti_screen_x_size; x++) |
| 256 | *(state->frames+(state->ti_number_of_frames-1)*state->ti_video_memory_size+y*state->ti_screen_x_size+x) = state->ti82_video_buffer[ y*state->ti_screen_x_size+x]; |
| 259 | 257 | |
| 260 | | for (y=0; y<ti_screen_y_size; y++) |
| 261 | | for (x=0; x<ti_screen_x_size; x++) |
| 258 | for (y=0; y<state->ti_screen_y_size; y++) |
| 259 | for (x=0; x<state->ti_screen_x_size; x++) |
| 262 | 260 | for (b=0; b<8; b++) |
| 263 | 261 | { |
| 264 | | brightnes = ((*(ti85_frames+0*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 265 | | + ((*(ti85_frames+1*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 266 | | + ((*(ti85_frames+2*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 267 | | + ((*(ti85_frames+3*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 268 | | + ((*(ti85_frames+4*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 269 | | + ((*(ti85_frames+5*ti_video_memory_size+y*ti_screen_x_size+x)>>(7-b)) & 0x01); |
| 262 | brightnes = ((*(state->frames+0*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 263 | + ((*(state->frames+1*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 264 | + ((*(state->frames+2*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 265 | + ((*(state->frames+3*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 266 | + ((*(state->frames+4*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01) |
| 267 | + ((*(state->frames+5*state->ti_video_memory_size+y*state->ti_screen_x_size+x)>>(7-b)) & 0x01); |
| 270 | 268 | |
| 271 | | *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[ti85_LCD_contrast&0x1f][brightnes]; |
| 269 | *BITMAP_ADDR16(bitmap, y, x*8+b) = ti85_palette[state->LCD_contrast&0x1f][brightnes]; |
| 272 | 270 | } |
| 273 | 271 | return 0; |
| 274 | 272 | } |
src/mess/drivers/pc6001.c
| r9675 | r9676 | |
| 133 | 133 | #include "devices/cartslot.h" |
| 134 | 134 | #include "formats/p6001_cas.h" |
| 135 | 135 | |
| 136 | | static UINT8 *pc6001_ram; |
| 137 | | static UINT8 *pc6001_video_ram; |
| 138 | | static UINT8 irq_vector = 0x00; |
| 139 | | static UINT8 cas_switch,sys_latch; |
| 140 | | static UINT8 timer_irq_mask; |
| 141 | | static UINT32 cas_offset; |
| 142 | | static UINT32 cas_maxsize; |
| 143 | | static emu_timer *timer_irq_timer; |
| 144 | | static UINT16 timer_hz_div; |
| 136 | |
| 137 | class pc6001_state : public driver_device |
| 138 | { |
| 139 | public: |
| 140 | pc6001_state(running_machine &machine, const driver_device_config_base &config) |
| 141 | : driver_device(machine, config) { } |
| 142 | |
| 143 | UINT8 *ram; |
| 144 | UINT8 *video_ram; |
| 145 | UINT8 irq_vector; |
| 146 | UINT8 cas_switch; |
| 147 | UINT8 sys_latch; |
| 148 | UINT8 timer_irq_mask; |
| 149 | UINT32 cas_offset; |
| 150 | UINT32 cas_maxsize; |
| 151 | emu_timer *timer_irq_timer; |
| 152 | UINT16 timer_hz_div; |
| 153 | UINT8 ex_vram_bank; |
| 154 | UINT8 bgcol_bank; |
| 155 | UINT8 exgfx_text_mode; |
| 156 | UINT8 exgfx_bitmap_mode; |
| 157 | UINT8 exgfx_2bpp_mode; |
| 158 | UINT8 bank_r0; |
| 159 | UINT8 bank_r1; |
| 160 | UINT8 gfx_bank_on; |
| 161 | UINT8 bank_w; |
| 162 | UINT8 bank_opt; |
| 163 | UINT8 timer_irq_mask2; |
| 164 | UINT8 timer_irq_vector; |
| 165 | UINT32 cgrom_bank_addr; |
| 166 | UINT8 sr_video_mode; |
| 167 | UINT8 port_c_8255; |
| 168 | UINT8 cur_keycode; |
| 169 | UINT8 sr_bank_r[8]; |
| 170 | UINT8 sr_bank_w[8]; |
| 171 | UINT8 kludge; |
| 172 | UINT32 old_key1; |
| 173 | UINT32 old_key2; |
| 174 | UINT32 old_key3; |
| 175 | }; |
| 176 | |
| 177 | |
| 145 | 178 | /* PC6001mk2 specific */ |
| 146 | | static UINT8 ex_vram_bank, bgcol_bank,exgfx_text_mode,exgfx_bitmap_mode,exgfx_2bpp_mode; |
| 147 | | static UINT8 bank_r0,bank_r1,gfx_bank_on,bank_w,bank_opt; |
| 148 | | static UINT8 timer_irq_mask2, timer_irq_vector; |
| 149 | | static UINT32 cgrom_bank_addr; |
| 150 | 179 | /* PC6001SR specific */ |
| 151 | | static UINT8 sr_video_mode; |
| 152 | 180 | |
| 153 | 181 | #define IRQ_LOG (0) |
| 154 | 182 | |
| 155 | 183 | static VIDEO_START( pc6001 ) |
| 156 | 184 | { |
| 185 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 157 | 186 | #if 0 |
| 158 | 187 | m6847_config cfg; |
| 159 | 188 | |
| r9675 | r9676 | |
| 164 | 193 | cfg.get_char_rom = pc6001_get_char_rom; |
| 165 | 194 | m6847_init(machine, &cfg); |
| 166 | 195 | #endif |
| 167 | | pc6001_video_ram = auto_alloc_array(machine, UINT8, 0x4000); |
| 196 | state->video_ram = auto_alloc_array(machine, UINT8, 0x4000); |
| 168 | 197 | } |
| 169 | 198 | |
| 170 | 199 | /* this is known as gfx mode 4 */ |
| 171 | 200 | static void draw_gfx_mode4(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int attr) |
| 172 | 201 | { |
| 202 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 173 | 203 | int x,y,xi; |
| 174 | 204 | int fgcol,color; |
| 175 | 205 | int col_setting; |
| r9675 | r9676 | |
| 191 | 221 | { |
| 192 | 222 | for(x=0;x<32;x++) |
| 193 | 223 | { |
| 194 | | int tile = pc6001_video_ram[(x+(y*32))+0x200]; |
| 224 | int tile = state->video_ram[(x+(y*32))+0x200]; |
| 195 | 225 | |
| 196 | 226 | if(col_setting == 0x00) //monochrome |
| 197 | 227 | { |
| r9675 | r9676 | |
| 222 | 252 | |
| 223 | 253 | static void draw_bitmap_2bpp(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect, int attr) |
| 224 | 254 | { |
| 255 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 225 | 256 | int color,x,y,xi,yi; |
| 226 | 257 | |
| 227 | 258 | int shrink_x = 2*4; |
| r9675 | r9676 | |
| 233 | 264 | { |
| 234 | 265 | for(x=0;x<w;x++) |
| 235 | 266 | { |
| 236 | | int tile = pc6001_video_ram[(x+(y*32))+0x200]; |
| 267 | int tile = state->video_ram[(x+(y*32))+0x200]; |
| 237 | 268 | |
| 238 | 269 | for(yi=0;yi<shrink_y;yi++) |
| 239 | 270 | { |
| r9675 | r9676 | |
| 343 | 374 | |
| 344 | 375 | static void pc6001_screen_draw(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect, int has_mc6847) |
| 345 | 376 | { |
| 377 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 346 | 378 | int x,y; |
| 347 | 379 | int tile,attr; |
| 348 | 380 | |
| 349 | | attr = pc6001_video_ram[0]; |
| 381 | attr = state->video_ram[0]; |
| 350 | 382 | |
| 351 | 383 | draw_border(machine,bitmap,cliprect,attr,has_mc6847); |
| 352 | 384 | |
| r9675 | r9676 | |
| 367 | 399 | { |
| 368 | 400 | for(x=0;x<32;x++) |
| 369 | 401 | { |
| 370 | | tile = pc6001_video_ram[(x+(y*32))+0x200]; |
| 371 | | attr = pc6001_video_ram[(x+(y*32)) & 0x1ff]; |
| 402 | tile = state->video_ram[(x+(y*32))+0x200]; |
| 403 | attr = state->video_ram[(x+(y*32)) & 0x1ff]; |
| 372 | 404 | |
| 373 | 405 | if(attr & 0x40) |
| 374 | 406 | { |
| r9675 | r9676 | |
| 392 | 424 | |
| 393 | 425 | static VIDEO_UPDATE( pc6001m2 ) |
| 394 | 426 | { |
| 427 | pc6001_state *state = screen->machine->driver_data<pc6001_state>(); |
| 395 | 428 | int x,y,tile,attr; |
| 396 | 429 | |
| 397 | 430 | /* note: bitmap mode have priority over everything else, check American Truck */ |
| 398 | | if(exgfx_bitmap_mode) |
| 431 | if(state->exgfx_bitmap_mode) |
| 399 | 432 | { |
| 400 | 433 | int count,color,i; |
| 401 | 434 | |
| r9675 | r9676 | |
| 419 | 452 | color |= pal_num[(pen[0] & 3) | ((pen[1] & 3) << 2)]; |
| 420 | 453 | */ |
| 421 | 454 | |
| 422 | | pen[0] = pc6001_video_ram[count+0x0000] >> (6-i*2) & 3; |
| 423 | | pen[1] = pc6001_video_ram[count+0x2000] >> (6-i*2) & 3; |
| 455 | pen[0] = state->video_ram[count+0x0000] >> (6-i*2) & 3; |
| 456 | pen[1] = state->video_ram[count+0x2000] >> (6-i*2) & 3; |
| 424 | 457 | |
| 425 | 458 | color = 0x10; |
| 426 | 459 | color |= ((pen[0] & 1) << 2); |
| r9675 | r9676 | |
| 438 | 471 | } |
| 439 | 472 | } |
| 440 | 473 | } |
| 441 | | else if(exgfx_2bpp_mode) |
| 474 | else if(state->exgfx_2bpp_mode) |
| 442 | 475 | { |
| 443 | 476 | int count,color,i; |
| 444 | 477 | |
| r9675 | r9676 | |
| 459 | 492 | color |= pal_num[(pen[0] & 1) | ((pen[1] & 1) << 1)]; |
| 460 | 493 | */ |
| 461 | 494 | |
| 462 | | pen[0] = pc6001_video_ram[count+0x0000] >> (7-i) & 1; |
| 463 | | pen[1] = pc6001_video_ram[count+0x2000] >> (7-i) & 1; |
| 495 | pen[0] = state->video_ram[count+0x0000] >> (7-i) & 1; |
| 496 | pen[1] = state->video_ram[count+0x2000] >> (7-i) & 1; |
| 464 | 497 | |
| 465 | | if(bgcol_bank & 4) //PC-6001 emulation mode |
| 498 | if(state->bgcol_bank & 4) //PC-6001 emulation mode |
| 466 | 499 | { |
| 467 | 500 | color = 0x08; |
| 468 | 501 | color |= (pen[0]) | (pen[1]<<1); |
| 469 | | color |= (bgcol_bank & 1) << 2; |
| 502 | color |= (state->bgcol_bank & 1) << 2; |
| 470 | 503 | } |
| 471 | 504 | else //Mk-2 mode |
| 472 | 505 | { |
| 473 | 506 | color = 0x10; |
| 474 | 507 | color |= ((pen[0] & 1) << 2); |
| 475 | 508 | color |= ((pen[1] & 1) >> 0); |
| 476 | | color |= ((bgcol_bank & 1) << 1); |
| 477 | | color |= ((bgcol_bank & 2) << 2); |
| 509 | color |= ((state->bgcol_bank & 1) << 1); |
| 510 | color |= ((state->bgcol_bank & 2) << 2); |
| 478 | 511 | } |
| 479 | 512 | |
| 480 | 513 | if ((x+i) <= screen->visible_area().max_x && (y) <= screen->visible_area().max_y) |
| r9675 | r9676 | |
| 486 | 519 | } |
| 487 | 520 | |
| 488 | 521 | } |
| 489 | | else if(exgfx_text_mode) |
| 522 | else if(state->exgfx_text_mode) |
| 490 | 523 | { |
| 491 | 524 | int xi,yi,pen,fgcol,bgcol,color; |
| 492 | 525 | UINT8 *gfx_data = memory_region(screen->machine, "gfx1"); |
| r9675 | r9676 | |
| 502 | 535 | ---- xxxx fg color |
| 503 | 536 | Note that the exgfx banks a different gfx ROM |
| 504 | 537 | */ |
| 505 | | tile = pc6001_video_ram[(x+(y*40))+0x400] + 0x200; |
| 506 | | attr = pc6001_video_ram[(x+(y*40)) & 0x3ff]; |
| 538 | tile = state->video_ram[(x+(y*40))+0x400] + 0x200; |
| 539 | attr = state->video_ram[(x+(y*40)) & 0x3ff]; |
| 507 | 540 | tile+= ((attr & 0x80) << 1); |
| 508 | 541 | |
| 509 | 542 | for(yi=0;yi<12;yi++) |
| r9675 | r9676 | |
| 513 | 546 | pen = gfx_data[(tile*0x10)+yi]>>(7-xi) & 1; |
| 514 | 547 | |
| 515 | 548 | fgcol = (attr & 0x0f) + 0x10; |
| 516 | | bgcol = ((attr & 0x70) >> 4) + 0x10 + ((bgcol_bank & 2) << 2); |
| 549 | bgcol = ((attr & 0x70) >> 4) + 0x10 + ((state->bgcol_bank & 2) << 2); |
| 517 | 550 | |
| 518 | 551 | color = pen ? fgcol : bgcol; |
| 519 | 552 | |
| r9675 | r9676 | |
| 526 | 559 | } |
| 527 | 560 | else |
| 528 | 561 | { |
| 529 | | attr = pc6001_video_ram[0]; |
| 562 | attr = state->video_ram[0]; |
| 530 | 563 | pc6001_screen_draw(screen->machine,bitmap,cliprect,0); |
| 531 | 564 | } |
| 532 | 565 | |
| r9675 | r9676 | |
| 535 | 568 | |
| 536 | 569 | static VIDEO_UPDATE( pc6001sr ) |
| 537 | 570 | { |
| 571 | pc6001_state *state = screen->machine->driver_data<pc6001_state>(); |
| 538 | 572 | int x,y,tile,attr; |
| 539 | 573 | int xi,yi,pen,fgcol,bgcol,color; |
| 540 | 574 | UINT8 *gfx_data = memory_region(screen->machine, "gfx1"); |
| 541 | 575 | |
| 542 | 576 | |
| 543 | | if(sr_video_mode & 8) // text mode |
| 577 | if(state->sr_video_mode & 8) // text mode |
| 544 | 578 | { |
| 545 | 579 | for(y=0;y<20;y++) |
| 546 | 580 | { |
| 547 | 581 | for(x=0;x<40;x++) |
| 548 | 582 | { |
| 549 | | tile = pc6001_video_ram[(x+(y*40))*2+0]; |
| 550 | | attr = pc6001_video_ram[(x+(y*40))*2+1]; |
| 583 | tile = state->video_ram[(x+(y*40))*2+0]; |
| 584 | attr = state->video_ram[(x+(y*40))*2+1]; |
| 551 | 585 | tile+= ((attr & 0x80) << 1); |
| 552 | 586 | |
| 553 | 587 | for(yi=0;yi<12;yi++) |
| r9675 | r9676 | |
| 557 | 591 | pen = gfx_data[(tile*0x10)+yi]>>(7-xi) & 1; |
| 558 | 592 | |
| 559 | 593 | fgcol = (attr & 0x0f) + 0x10; |
| 560 | | bgcol = ((attr & 0x70) >> 4) + 0x10 + ((bgcol_bank & 2) << 2); |
| 594 | bgcol = ((attr & 0x70) >> 4) + 0x10 + ((state->bgcol_bank & 2) << 2); |
| 561 | 595 | |
| 562 | 596 | color = pen ? fgcol : bgcol; |
| 563 | 597 | |
| r9675 | r9676 | |
| 578 | 612 | { |
| 579 | 613 | for(x=0;x<320;x+=4) |
| 580 | 614 | { |
| 581 | | color = pc6001_video_ram[count] & 0x0f; |
| 615 | color = state->video_ram[count] & 0x0f; |
| 582 | 616 | |
| 583 | 617 | if ((x+0) <= screen->visible_area().max_x && (y+0) <= screen->visible_area().max_y) |
| 584 | 618 | *BITMAP_ADDR16(bitmap, (y+0), (x+0)) = screen->machine->pens[color+0x10]; |
| 585 | 619 | |
| 586 | | color = (pc6001_video_ram[count] & 0xf0) >> 4; |
| 620 | color = (state->video_ram[count] & 0xf0) >> 4; |
| 587 | 621 | |
| 588 | 622 | if ((x+1) <= screen->visible_area().max_x && (y+0) <= screen->visible_area().max_y) |
| 589 | 623 | *BITMAP_ADDR16(bitmap, (y+0), (x+1)) = screen->machine->pens[color+0x10]; |
| 590 | 624 | |
| 591 | | color = pc6001_video_ram[count+1] & 0x0f; |
| 625 | color = state->video_ram[count+1] & 0x0f; |
| 592 | 626 | |
| 593 | 627 | if ((x+2) <= screen->visible_area().max_x && (y+0) <= screen->visible_area().max_y) |
| 594 | 628 | *BITMAP_ADDR16(bitmap, (y+0), (x+2)) = screen->machine->pens[color+0x10]; |
| 595 | 629 | |
| 596 | | color = (pc6001_video_ram[count+1] & 0xf0) >> 4; |
| 630 | color = (state->video_ram[count+1] & 0xf0) >> 4; |
| 597 | 631 | |
| 598 | 632 | if ((x+3) <= screen->visible_area().max_x && (y+0) <= screen->visible_area().max_y) |
| 599 | 633 | *BITMAP_ADDR16(bitmap, (y+0), (x+3)) = screen->machine->pens[color+0x10]; |
| 600 | 634 | |
| 601 | | color = pc6001_video_ram[count+2] & 0x0f; |
| 635 | color = state->video_ram[count+2] & 0x0f; |
| 602 | 636 | |
| 603 | 637 | if ((x+0) <= screen->visible_area().max_x && (y+1) <= screen->visible_area().max_y) |
| 604 | 638 | *BITMAP_ADDR16(bitmap, (y+1), (x+0)) = screen->machine->pens[color+0x10]; |
| 605 | 639 | |
| 606 | | color = (pc6001_video_ram[count+2] & 0xf0) >> 4; |
| 640 | color = (state->video_ram[count+2] & 0xf0) >> 4; |
| 607 | 641 | |
| 608 | 642 | if ((x+1) <= screen->visible_area().max_x && (y+1) <= screen->visible_area().max_y) |
| 609 | 643 | *BITMAP_ADDR16(bitmap, (y+1), (x+1)) = screen->machine->pens[color+0x10]; |
| 610 | 644 | |
| 611 | | color = pc6001_video_ram[count+3] & 0x0f; |
| 645 | color = state->video_ram[count+3] & 0x0f; |
| 612 | 646 | |
| 613 | 647 | if ((x+2) <= screen->visible_area().max_x && (y+1) <= screen->visible_area().max_y) |
| 614 | 648 | *BITMAP_ADDR16(bitmap, (y+1), (x+2)) = screen->machine->pens[color+0x10]; |
| 615 | 649 | |
| 616 | | color = (pc6001_video_ram[count+3] & 0xf0) >> 4; |
| 650 | color = (state->video_ram[count+3] & 0xf0) >> 4; |
| 617 | 651 | |
| 618 | 652 | if ((x+3) <= screen->visible_area().max_x && (y+1) <= screen->visible_area().max_y) |
| 619 | 653 | *BITMAP_ADDR16(bitmap, (y+1), (x+3)) = screen->machine->pens[color+0x10]; |
| r9675 | r9676 | |
| 629 | 663 | |
| 630 | 664 | static WRITE8_HANDLER ( pc6001_system_latch_w ) |
| 631 | 665 | { |
| 666 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 632 | 667 | UINT16 startaddr[] = {0xC000, 0xE000, 0x8000, 0xA000 }; |
| 633 | 668 | |
| 634 | | pc6001_video_ram = pc6001_ram + startaddr[(data >> 1) & 0x03] - 0x8000; |
| 669 | state->video_ram = state->ram + startaddr[(data >> 1) & 0x03] - 0x8000; |
| 635 | 670 | |
| 636 | | if((!(sys_latch & 8)) && data & 0x8) //PLAY tape cmd |
| 671 | if((!(state->sys_latch & 8)) && data & 0x8) //PLAY tape cmd |
| 637 | 672 | { |
| 638 | | cas_switch = 1; |
| 673 | state->cas_switch = 1; |
| 639 | 674 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR); |
| 640 | 675 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_PLAY,CASSETTE_MASK_UISTATE); |
| 641 | 676 | } |
| 642 | | if((sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd |
| 677 | if((state->sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd |
| 643 | 678 | { |
| 644 | | cas_switch = 0; |
| 679 | state->cas_switch = 0; |
| 645 | 680 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR); |
| 646 | 681 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_STOPPED,CASSETTE_MASK_UISTATE); |
| 647 | | //irq_vector = 0x00; |
| 682 | //state->irq_vector = 0x00; |
| 648 | 683 | //cputag_set_input_line(space->machine,"maincpu", 0, ASSERT_LINE); |
| 649 | 684 | } |
| 650 | 685 | |
| 651 | | sys_latch = data; |
| 652 | | timer_irq_mask = data & 1; |
| 686 | state->sys_latch = data; |
| 687 | state->timer_irq_mask = data & 1; |
| 653 | 688 | //printf("%02x\n",data); |
| 654 | 689 | } |
| 655 | 690 | |
| 656 | 691 | #if 0 |
| 657 | 692 | static ATTR_CONST UINT8 pc6001_get_attributes(running_machine *machine, UINT8 c,int scanline, int pos) |
| 658 | 693 | { |
| 694 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 659 | 695 | UINT8 result = 0x00; |
| 660 | | UINT8 val = pc6001_video_ram [(scanline / 12) * 0x20 + pos]; |
| 696 | UINT8 val = state->video_ram [(scanline / 12) * 0x20 + pos]; |
| 661 | 697 | |
| 662 | 698 | if (val & 0x01) { |
| 663 | 699 | result |= M6847_INV; |
| r9675 | r9676 | |
| 671 | 707 | |
| 672 | 708 | static const UINT8 *pc6001_get_video_ram(running_machine *machine, int scanline) |
| 673 | 709 | { |
| 674 | | return pc6001_video_ram +0x0200+ (scanline / 12) * 0x20; |
| 710 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 711 | return state->video_ram +0x0200+ (scanline / 12) * 0x20; |
| 675 | 712 | } |
| 676 | 713 | |
| 677 | 714 | static UINT8 pc6001_get_char_rom(running_machine *machine, UINT8 ch, int line) |
| r9675 | r9676 | |
| 681 | 718 | } |
| 682 | 719 | #endif |
| 683 | 720 | |
| 684 | | static UINT8 port_c_8255,cur_keycode; |
| 685 | 721 | |
| 686 | 722 | static READ8_DEVICE_HANDLER(nec_ppi8255_r) |
| 687 | 723 | { |
| 724 | pc6001_state *state = device->machine->driver_data<pc6001_state>(); |
| 688 | 725 | if (offset==2) |
| 689 | | return port_c_8255; |
| 726 | return state->port_c_8255; |
| 690 | 727 | else if(offset==0) |
| 691 | 728 | { |
| 692 | 729 | UINT8 res; |
| 693 | | res = cur_keycode; |
| 694 | | //cur_keycode = 0; |
| 730 | res = state->cur_keycode; |
| 731 | //state->cur_keycode = 0; |
| 695 | 732 | return res; |
| 696 | 733 | } |
| 697 | 734 | |
| r9675 | r9676 | |
| 700 | 737 | |
| 701 | 738 | static WRITE8_DEVICE_HANDLER(nec_ppi8255_w) |
| 702 | 739 | { |
| 740 | pc6001_state *state = device->machine->driver_data<pc6001_state>(); |
| 703 | 741 | if (offset==3) |
| 704 | 742 | { |
| 705 | 743 | if(data & 1) |
| 706 | | port_c_8255 |= 1<<((data>>1)&0x07); |
| 744 | state->port_c_8255 |= 1<<((data>>1)&0x07); |
| 707 | 745 | else |
| 708 | | port_c_8255 &= ~(1<<((data>>1)&0x07)); |
| 746 | state->port_c_8255 &= ~(1<<((data>>1)&0x07)); |
| 709 | 747 | |
| 710 | 748 | switch(data) { |
| 711 | | case 0x08: port_c_8255 |= 0x88; break; |
| 712 | | case 0x09: port_c_8255 &= 0xf7; break; |
| 713 | | case 0x0c: port_c_8255 |= 0x28; break; |
| 714 | | case 0x0d: port_c_8255 &= 0xf7; break; |
| 749 | case 0x08: state->port_c_8255 |= 0x88; break; |
| 750 | case 0x09: state->port_c_8255 &= 0xf7; break; |
| 751 | case 0x0c: state->port_c_8255 |= 0x28; break; |
| 752 | case 0x0d: state->port_c_8255 &= 0xf7; break; |
| 715 | 753 | default: break; |
| 716 | 754 | } |
| 717 | 755 | |
| 718 | | port_c_8255 |= 0xa8; |
| 756 | state->port_c_8255 |= 0xa8; |
| 719 | 757 | |
| 720 | 758 | { |
| 721 | 759 | UINT8 *gfx_data = memory_region(device->machine, "gfx1"); |
| r9675 | r9676 | |
| 737 | 775 | AM_RANGE(0x0000, 0x3fff) AM_ROM AM_WRITENOP |
| 738 | 776 | AM_RANGE(0x4000, 0x5fff) AM_ROM AM_REGION("cart_img",0) |
| 739 | 777 | AM_RANGE(0x6000, 0x7fff) AM_ROMBANK("bank1") |
| 740 | | AM_RANGE(0x8000, 0xffff) AM_RAM AM_BASE(&pc6001_ram) |
| 778 | AM_RANGE(0x8000, 0xffff) AM_RAM AM_BASE_MEMBER(pc6001_state, ram) |
| 741 | 779 | ADDRESS_MAP_END |
| 742 | 780 | |
| 743 | 781 | static ADDRESS_MAP_START( pc6001_io , ADDRESS_SPACE_IO, 8) |
| r9675 | r9676 | |
| 932 | 970 | |
| 933 | 971 | static WRITE8_HANDLER( pc6001m2_bank_r0_w ) |
| 934 | 972 | { |
| 973 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 935 | 974 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 936 | 975 | UINT8 *gfx_data = memory_region(space->machine, "gfx1"); |
| 937 | 976 | |
| 938 | 977 | // bankaddress = 0x10000 + (0x4000 * ((data & 0x40)>>6)); |
| 939 | 978 | // memory_set_bankptr(space->machine, 1, &ROM[bankaddress]); |
| 940 | 979 | |
| 941 | | bank_r0 = data; |
| 980 | state->bank_r0 = data; |
| 942 | 981 | |
| 943 | | // printf("%02x BANK | %02x\n",data,bank_opt); |
| 944 | | memory_set_bankptr(space->machine, "bank1", &ROM[banksw_table_r0[(data & 0xf)+(bank_opt*0x10)][0]]); |
| 945 | | memory_set_bankptr(space->machine, "bank2", &ROM[banksw_table_r0[(data & 0xf)+(bank_opt*0x10)][1]]); |
| 946 | | memory_set_bankptr(space->machine, "bank3", &ROM[banksw_table_r0[((data & 0xf0)>>4)+(bank_opt*0x10)][2]]); |
| 947 | | if(!gfx_bank_on) |
| 948 | | memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][3]]); |
| 982 | // printf("%02x BANK | %02x\n",data,state->bank_opt); |
| 983 | memory_set_bankptr(space->machine, "bank1", &ROM[banksw_table_r0[(data & 0xf)+(state->bank_opt*0x10)][0]]); |
| 984 | memory_set_bankptr(space->machine, "bank2", &ROM[banksw_table_r0[(data & 0xf)+(state->bank_opt*0x10)][1]]); |
| 985 | memory_set_bankptr(space->machine, "bank3", &ROM[banksw_table_r0[((data & 0xf0)>>4)+(state->bank_opt*0x10)][2]]); |
| 986 | if(!state->gfx_bank_on) |
| 987 | memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]); |
| 949 | 988 | else |
| 950 | | memory_set_bankptr(space->machine, "bank4", &gfx_data[cgrom_bank_addr]); |
| 989 | memory_set_bankptr(space->machine, "bank4", &gfx_data[state->cgrom_bank_addr]); |
| 951 | 990 | } |
| 952 | 991 | |
| 953 | 992 | static WRITE8_HANDLER( pc6001m2_bank_r1_w ) |
| 954 | 993 | { |
| 994 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 955 | 995 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 956 | 996 | |
| 957 | 997 | // bankaddress = 0x10000 + (0x4000 * ((data & 0x40)>>6)); |
| 958 | 998 | // memory_set_bankptr(space->machine, 1, &ROM[bankaddress]); |
| 959 | 999 | |
| 960 | | bank_r1 = data; |
| 1000 | state->bank_r1 = data; |
| 961 | 1001 | |
| 962 | 1002 | // printf("%02x BANK\n",data); |
| 963 | | memory_set_bankptr(space->machine, "bank5", &ROM[banksw_table_r1[(data & 0xf)+(bank_opt*0x10)][0]]); |
| 964 | | memory_set_bankptr(space->machine, "bank6", &ROM[banksw_table_r1[(data & 0xf)+(bank_opt*0x10)][1]]); |
| 965 | | memory_set_bankptr(space->machine, "bank7", &ROM[banksw_table_r1[((data & 0xf0)>>4)+(bank_opt*0x10)][2]]); |
| 966 | | memory_set_bankptr(space->machine, "bank8", &ROM[banksw_table_r1[((data & 0xf0)>>4)+(bank_opt*0x10)][3]]); |
| 1003 | memory_set_bankptr(space->machine, "bank5", &ROM[banksw_table_r1[(data & 0xf)+(state->bank_opt*0x10)][0]]); |
| 1004 | memory_set_bankptr(space->machine, "bank6", &ROM[banksw_table_r1[(data & 0xf)+(state->bank_opt*0x10)][1]]); |
| 1005 | memory_set_bankptr(space->machine, "bank7", &ROM[banksw_table_r1[((data & 0xf0)>>4)+(state->bank_opt*0x10)][2]]); |
| 1006 | memory_set_bankptr(space->machine, "bank8", &ROM[banksw_table_r1[((data & 0xf0)>>4)+(state->bank_opt*0x10)][3]]); |
| 967 | 1007 | } |
| 968 | 1008 | |
| 969 | 1009 | static WRITE8_HANDLER( pc6001m2_bank_w0_w ) |
| 970 | 1010 | { |
| 971 | | bank_w = data; |
| 1011 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1012 | state->bank_w = data; |
| 972 | 1013 | } |
| 973 | 1014 | |
| 974 | 1015 | static WRITE8_HANDLER( pc6001m2_opt_bank_w ) |
| 975 | 1016 | { |
| 1017 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 976 | 1018 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 977 | 1019 | UINT8 *gfx_data = memory_region(space->machine, "gfx1"); |
| 978 | 1020 | |
| r9675 | r9676 | |
| 982 | 1024 | 2 - KANJI ROM bank 1 |
| 983 | 1025 | 3 - TVROM / VOICE ROM |
| 984 | 1026 | */ |
| 985 | | bank_opt = data & 3; |
| 1027 | state->bank_opt = data & 3; |
| 986 | 1028 | |
| 987 | | memory_set_bankptr(space->machine, "bank1", &ROM[banksw_table_r0[(bank_r0 & 0xf)+(bank_opt*0x10)][0]]); |
| 988 | | memory_set_bankptr(space->machine, "bank2", &ROM[banksw_table_r0[(bank_r0 & 0xf)+(bank_opt*0x10)][1]]); |
| 989 | | memory_set_bankptr(space->machine, "bank3", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][2]]); |
| 990 | | if(!gfx_bank_on) |
| 991 | | memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][3]]); |
| 1029 | memory_set_bankptr(space->machine, "bank1", &ROM[banksw_table_r0[(state->bank_r0 & 0xf)+(state->bank_opt*0x10)][0]]); |
| 1030 | memory_set_bankptr(space->machine, "bank2", &ROM[banksw_table_r0[(state->bank_r0 & 0xf)+(state->bank_opt*0x10)][1]]); |
| 1031 | memory_set_bankptr(space->machine, "bank3", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][2]]); |
| 1032 | if(!state->gfx_bank_on) |
| 1033 | memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]); |
| 992 | 1034 | else |
| 993 | | memory_set_bankptr(space->machine, "bank4", &gfx_data[cgrom_bank_addr]); |
| 994 | | memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][3]]); |
| 995 | | memory_set_bankptr(space->machine, "bank5", &ROM[banksw_table_r1[(bank_r1 & 0xf)+(bank_opt*0x10)][0]]); |
| 996 | | memory_set_bankptr(space->machine, "bank6", &ROM[banksw_table_r1[(bank_r1 & 0xf)+(bank_opt*0x10)][1]]); |
| 997 | | memory_set_bankptr(space->machine, "bank7", &ROM[banksw_table_r1[((bank_r1 & 0xf0)>>4)+(bank_opt*0x10)][2]]); |
| 998 | | memory_set_bankptr(space->machine, "bank8", &ROM[banksw_table_r1[((bank_r1 & 0xf0)>>4)+(bank_opt*0x10)][3]]); |
| 1035 | memory_set_bankptr(space->machine, "bank4", &gfx_data[state->cgrom_bank_addr]); |
| 1036 | memory_set_bankptr(space->machine, "bank4", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]); |
| 1037 | memory_set_bankptr(space->machine, "bank5", &ROM[banksw_table_r1[(state->bank_r1 & 0xf)+(state->bank_opt*0x10)][0]]); |
| 1038 | memory_set_bankptr(space->machine, "bank6", &ROM[banksw_table_r1[(state->bank_r1 & 0xf)+(state->bank_opt*0x10)][1]]); |
| 1039 | memory_set_bankptr(space->machine, "bank7", &ROM[banksw_table_r1[((state->bank_r1 & 0xf0)>>4)+(state->bank_opt*0x10)][2]]); |
| 1040 | memory_set_bankptr(space->machine, "bank8", &ROM[banksw_table_r1[((state->bank_r1 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]); |
| 999 | 1041 | |
| 1000 | 1042 | } |
| 1001 | 1043 | |
| 1002 | | static WRITE8_HANDLER( work_ram0_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x01) ? WRAM(0) : EXWRAM(0))] = data; } |
| 1003 | | static WRITE8_HANDLER( work_ram1_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x01) ? WRAM(1) : EXWRAM(1))] = data; } |
| 1004 | | static WRITE8_HANDLER( work_ram2_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x04) ? WRAM(2) : EXWRAM(2))] = data; } |
| 1005 | | static WRITE8_HANDLER( work_ram3_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x04) ? WRAM(3) : EXWRAM(3))] = data; } |
| 1006 | | static WRITE8_HANDLER( work_ram4_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x10) ? WRAM(4) : EXWRAM(4))] = data; } |
| 1007 | | static WRITE8_HANDLER( work_ram5_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x10) ? WRAM(5) : EXWRAM(5))] = data; } |
| 1008 | | static WRITE8_HANDLER( work_ram6_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x40) ? WRAM(6) : EXWRAM(6))] = data; } |
| 1009 | | static WRITE8_HANDLER( work_ram7_w ) { UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((bank_w & 0x40) ? WRAM(7) : EXWRAM(7))] = data; } |
| 1044 | static WRITE8_HANDLER( work_ram0_w ) |
| 1045 | { |
| 1046 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1047 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 1048 | ROM[offset+((state->bank_w & 0x01) ? WRAM(0) : EXWRAM(0))] = data; |
| 1049 | } |
| 1010 | 1050 | |
| 1051 | static WRITE8_HANDLER( work_ram1_w ) |
| 1052 | { |
| 1053 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1054 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 1055 | ROM[offset+((state->bank_w & 0x01) ? WRAM(1) : EXWRAM(1))] = data; |
| 1056 | } |
| 1057 | |
| 1058 | static WRITE8_HANDLER( work_ram2_w ) |
| 1059 | { |
| 1060 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1061 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 1062 | ROM[offset+((state->bank_w & 0x04) ? WRAM(2) : EXWRAM(2))] = data; |
| 1063 | } |
| 1064 | |
| 1065 | static WRITE8_HANDLER( work_ram3_w ) |
| 1066 | { |
| 1067 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1068 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 1069 | ROM[offset+((state->bank_w & 0x04) ? WRAM(3) : EXWRAM(3))] = data; |
| 1070 | } |
| 1071 | |
| 1072 | static WRITE8_HANDLER( work_ram4_w ) |
| 1073 | { |
| 1074 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1075 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 1076 | ROM[offset+((state->bank_w & 0x10) ? WRAM(4) : EXWRAM(4))] = data; |
| 1077 | } |
| 1078 | |
| 1079 | static WRITE8_HANDLER( work_ram5_w ) |
| 1080 | { |
| 1081 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1082 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 1083 | ROM[offset+((state->bank_w & 0x10) ? WRAM(5) : EXWRAM(5))] = data; |
| 1084 | } |
| 1085 | |
| 1086 | static WRITE8_HANDLER( work_ram6_w ) |
| 1087 | { |
| 1088 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((state->bank_w & 0x40) ? WRAM(6) : EXWRAM(6))] = data; |
| 1089 | } |
| 1090 | |
| 1091 | static WRITE8_HANDLER( work_ram7_w ) |
| 1092 | { |
| 1093 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); UINT8 *ROM = memory_region(space->machine, "maincpu"); ROM[offset+((state->bank_w & 0x40) ? WRAM(7) : EXWRAM(7))] = data; |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1011 | 1097 | static WRITE8_DEVICE_HANDLER(necmk2_ppi8255_w) |
| 1012 | 1098 | { |
| 1099 | pc6001_state *state = device->machine->driver_data<pc6001_state>(); |
| 1013 | 1100 | if (offset==3) |
| 1014 | 1101 | { |
| 1015 | 1102 | if(data & 1) |
| 1016 | | port_c_8255 |= 1<<((data>>1)&0x07); |
| 1103 | state->port_c_8255 |= 1<<((data>>1)&0x07); |
| 1017 | 1104 | else |
| 1018 | | port_c_8255 &= ~(1<<((data>>1)&0x07)); |
| 1105 | state->port_c_8255 &= ~(1<<((data>>1)&0x07)); |
| 1019 | 1106 | |
| 1020 | 1107 | switch(data) { |
| 1021 | | case 0x08: port_c_8255 |= 0x88; break; |
| 1022 | | case 0x09: port_c_8255 &= 0xf7; break; |
| 1023 | | case 0x0c: port_c_8255 |= 0x28; break; |
| 1024 | | case 0x0d: port_c_8255 &= 0xf7; break; |
| 1108 | case 0x08: state->port_c_8255 |= 0x88; break; |
| 1109 | case 0x09: state->port_c_8255 &= 0xf7; break; |
| 1110 | case 0x0c: state->port_c_8255 |= 0x28; break; |
| 1111 | case 0x0d: state->port_c_8255 &= 0xf7; break; |
| 1025 | 1112 | default: break; |
| 1026 | 1113 | } |
| 1027 | 1114 | |
| 1028 | | port_c_8255 |= 0xa8; |
| 1115 | state->port_c_8255 |= 0xa8; |
| 1029 | 1116 | |
| 1030 | 1117 | { |
| 1031 | 1118 | UINT8 *ROM = memory_region(device->machine, "maincpu"); |
| r9675 | r9676 | |
| 1035 | 1122 | |
| 1036 | 1123 | if((data & 0x0f) == 0x05) |
| 1037 | 1124 | { |
| 1038 | | gfx_bank_on = 0; |
| 1039 | | memory_set_bankptr(device->machine, "bank4", &ROM[banksw_table_r0[((bank_r0 & 0xf0)>>4)+(bank_opt*0x10)][3]]); |
| 1125 | state->gfx_bank_on = 0; |
| 1126 | memory_set_bankptr(device->machine, "bank4", &ROM[banksw_table_r0[((state->bank_r0 & 0xf0)>>4)+(state->bank_opt*0x10)][3]]); |
| 1040 | 1127 | } |
| 1041 | 1128 | if((data & 0x0f) == 0x04) |
| 1042 | 1129 | { |
| 1043 | | gfx_bank_on = 1; |
| 1044 | | memory_set_bankptr(device->machine, "bank4", &gfx_data[cgrom_bank_addr]); |
| 1130 | state->gfx_bank_on = 1; |
| 1131 | memory_set_bankptr(device->machine, "bank4", &gfx_data[state->cgrom_bank_addr]); |
| 1045 | 1132 | } |
| 1046 | 1133 | } |
| 1047 | 1134 | } |
| r9675 | r9676 | |
| 1050 | 1137 | |
| 1051 | 1138 | static void vram_bank_change(running_machine *machine,UINT8 vram_bank) |
| 1052 | 1139 | { |
| 1140 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 1053 | 1141 | UINT8 *work_ram = memory_region(machine, "maincpu"); |
| 1054 | 1142 | |
| 1055 | 1143 | // popmessage("%02x",vram_bank); |
| 1056 | 1144 | |
| 1057 | 1145 | switch(vram_bank & 0x66) |
| 1058 | 1146 | { |
| 1059 | | case 0x00: pc6001_video_ram = work_ram + 0x8000 + 0x28000; break; //4 color mode |
| 1060 | | case 0x02: pc6001_video_ram = work_ram + 0xc000 + 0x28000; break; |
| 1061 | | case 0x04: pc6001_video_ram = work_ram + 0x8000 + 0x28000; break; |
| 1062 | | case 0x06: pc6001_video_ram = work_ram + 0xc000 + 0x28000; break; |
| 1063 | | case 0x20: pc6001_video_ram = work_ram + 0xc000 + 0x28000; break; //4 color mode |
| 1064 | | case 0x22: pc6001_video_ram = work_ram + 0xe000 + 0x28000; break; |
| 1065 | | case 0x24: pc6001_video_ram = work_ram + 0xc000 + 0x28000; break; |
| 1066 | | case 0x26: pc6001_video_ram = work_ram + 0xe000 + 0x28000; break; |
| 1067 | | case 0x40: pc6001_video_ram = work_ram + 0x0000 + 0x28000; break; //4 color mode |
| 1068 | | case 0x42: pc6001_video_ram = work_ram + 0x8000 + 0x28000; break; |
| 1069 | | case 0x44: pc6001_video_ram = work_ram + 0x0000 + 0x28000; break; |
| 1070 | | case 0x46: pc6001_video_ram = work_ram + 0x8000 + 0x28000; break; |
| 1071 | | case 0x60: pc6001_video_ram = work_ram + 0x4000 + 0x28000; break; //4 color mode |
| 1072 | | case 0x62: pc6001_video_ram = work_ram + 0xa000 + 0x28000; break; |
| 1073 | | case 0x64: pc6001_video_ram = work_ram + 0x4000 + 0x28000; break; |
| 1074 | | case 0x66: pc6001_video_ram = work_ram + 0xa000 + 0x28000; break; |
| 1147 | case 0x00: state->video_ram = work_ram + 0x8000 + 0x28000; break; //4 color mode |
| 1148 | case 0x02: state->video_ram = work_ram + 0xc000 + 0x28000; break; |
| 1149 | case 0x04: state->video_ram = work_ram + 0x8000 + 0x28000; break; |
| 1150 | case 0x06: state->video_ram = work_ram + 0xc000 + 0x28000; break; |
| 1151 | case 0x20: state->video_ram = work_ram + 0xc000 + 0x28000; break; //4 color mode |
| 1152 | case 0x22: state->video_ram = work_ram + 0xe000 + 0x28000; break; |
| 1153 | case 0x24: state->video_ram = work_ram + 0xc000 + 0x28000; break; |
| 1154 | case 0x26: state->video_ram = work_ram + 0xe000 + 0x28000; break; |
| 1155 | case 0x40: state->video_ram = work_ram + 0x0000 + 0x28000; break; //4 color mode |
| 1156 | case 0x42: state->video_ram = work_ram + 0x8000 + 0x28000; break; |
| 1157 | case 0x44: state->video_ram = work_ram + 0x0000 + 0x28000; break; |
| 1158 | case 0x46: state->video_ram = work_ram + 0x8000 + 0x28000; break; |
| 1159 | case 0x60: state->video_ram = work_ram + 0x4000 + 0x28000; break; //4 color mode |
| 1160 | case 0x62: state->video_ram = work_ram + 0xa000 + 0x28000; break; |
| 1161 | case 0x64: state->video_ram = work_ram + 0x4000 + 0x28000; break; |
| 1162 | case 0x66: state->video_ram = work_ram + 0xa000 + 0x28000; break; |
| 1075 | 1163 | } |
| 1076 | 1164 | } |
| 1077 | 1165 | |
| 1078 | 1166 | static WRITE8_HANDLER ( pc6001m2_system_latch_w ) |
| 1079 | 1167 | { |
| 1080 | | if((!(sys_latch & 8)) && data & 0x8) //PLAY tape cmd |
| 1168 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1169 | if((!(state->sys_latch & 8)) && data & 0x8) //PLAY tape cmd |
| 1081 | 1170 | { |
| 1082 | | cas_switch = 1; |
| 1171 | state->cas_switch = 1; |
| 1083 | 1172 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR); |
| 1084 | 1173 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_PLAY,CASSETTE_MASK_UISTATE); |
| 1085 | 1174 | } |
| 1086 | | if((sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd |
| 1175 | if((state->sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd |
| 1087 | 1176 | { |
| 1088 | | cas_switch = 0; |
| 1177 | state->cas_switch = 0; |
| 1089 | 1178 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR); |
| 1090 | 1179 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_STOPPED,CASSETTE_MASK_UISTATE); |
| 1091 | | //irq_vector = 0x00; |
| 1180 | //state->irq_vector = 0x00; |
| 1092 | 1181 | //cputag_set_input_line(space->machine,"maincpu", 0, ASSERT_LINE); |
| 1093 | 1182 | } |
| 1094 | 1183 | |
| 1095 | | sys_latch = data; |
| 1184 | state->sys_latch = data; |
| 1096 | 1185 | |
| 1097 | | timer_irq_mask = data & 1; |
| 1098 | | vram_bank_change(space->machine,(ex_vram_bank & 0x06) | ((sys_latch & 0x06) << 4)); |
| 1186 | state->timer_irq_mask = data & 1; |
| 1187 | vram_bank_change(space->machine,(state->ex_vram_bank & 0x06) | ((state->sys_latch & 0x06) << 4)); |
| 1099 | 1188 | |
| 1100 | 1189 | //printf("%02x B0\n",data); |
| 1101 | 1190 | } |
| r9675 | r9676 | |
| 1103 | 1192 | |
| 1104 | 1193 | static WRITE8_HANDLER( pc6001m2_vram_bank_w ) |
| 1105 | 1194 | { |
| 1195 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1106 | 1196 | // UINT32 startaddr[] = {WRAM(6), WRAM(6), WRAM(0), WRAM(4) }; |
| 1107 | 1197 | |
| 1108 | | ex_vram_bank = data; |
| 1109 | | vram_bank_change(space->machine,(ex_vram_bank & 0x06) | ((sys_latch & 0x06) << 4)); |
| 1198 | state->ex_vram_bank = data; |
| 1199 | vram_bank_change(space->machine,(state->ex_vram_bank & 0x06) | ((state->sys_latch & 0x06) << 4)); |
| 1110 | 1200 | |
| 1111 | | exgfx_text_mode = ((data & 2) == 0); |
| 1112 | | cgrom_bank_addr = (data & 2) ? 0x0000 : 0x2000; |
| 1201 | state->exgfx_text_mode = ((data & 2) == 0); |
| 1202 | state->cgrom_bank_addr = (data & 2) ? 0x0000 : 0x2000; |
| 1113 | 1203 | |
| 1114 | | exgfx_bitmap_mode = (data & 8); |
| 1115 | | exgfx_2bpp_mode = ((data & 6) == 0); |
| 1204 | state->exgfx_bitmap_mode = (data & 8); |
| 1205 | state->exgfx_2bpp_mode = ((data & 6) == 0); |
| 1116 | 1206 | |
| 1117 | 1207 | { |
| 1118 | 1208 | /* Apparently bitmap modes changes the screen res to 320 x 200 */ |
| r9675 | r9676 | |
| 1120 | 1210 | rectangle visarea = space->machine->primary_screen->visible_area(); |
| 1121 | 1211 | int y_height; |
| 1122 | 1212 | |
| 1123 | | y_height = (exgfx_bitmap_mode || exgfx_2bpp_mode) ? 200 : 240; |
| 1213 | y_height = (state->exgfx_bitmap_mode || state->exgfx_2bpp_mode) ? 200 : 240; |
| 1124 | 1214 | |
| 1125 | 1215 | visarea.min_x = visarea.min_y = 0; |
| 1126 | 1216 | visarea.max_y = (y_height) - 1; |
| r9675 | r9676 | |
| 1132 | 1222 | |
| 1133 | 1223 | // popmessage("%02x",data); |
| 1134 | 1224 | |
| 1135 | | // pc6001_video_ram = work_ram + startaddr[(data >> 1) & 0x03]; |
| 1225 | // state->video_ram = work_ram + startaddr[(data >> 1) & 0x03]; |
| 1136 | 1226 | } |
| 1137 | 1227 | |
| 1138 | 1228 | static WRITE8_HANDLER( pc6001m2_col_bank_w ) |
| 1139 | 1229 | { |
| 1140 | | bgcol_bank = (data & 7); |
| 1230 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1231 | state->bgcol_bank = (data & 7); |
| 1141 | 1232 | } |
| 1142 | 1233 | |
| 1143 | 1234 | /* voice synth is a NEC uPD7752 sound chip (currently unemulated) */ |
| r9675 | r9676 | |
| 1181 | 1272 | |
| 1182 | 1273 | static WRITE8_HANDLER( pc6001m2_0xf3_w ) |
| 1183 | 1274 | { |
| 1275 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1184 | 1276 | /* |
| 1185 | 1277 | x--- ---- M1 (?) wait setting |
| 1186 | 1278 | -x-- ---- ROM wait setting |
| r9675 | r9676 | |
| 1191 | 1283 | ---- --x- custom irq 2 mask |
| 1192 | 1284 | ---- ---x custom irq 1 mask |
| 1193 | 1285 | */ |
| 1194 | | timer_irq_mask2 = data & 4; |
| 1286 | state->timer_irq_mask2 = data & 4; |
| 1195 | 1287 | } |
| 1196 | 1288 | |
| 1197 | 1289 | static TIMER_CALLBACK(audio_callback) |
| 1198 | 1290 | { |
| 1199 | | if(cas_switch == 0 && ((timer_irq_mask == 0) || (timer_irq_mask2 == 0))) |
| 1291 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 1292 | if(state->cas_switch == 0 && ((state->timer_irq_mask == 0) || (state->timer_irq_mask2 == 0))) |
| 1200 | 1293 | { |
| 1201 | | if(IRQ_LOG) printf("Timer IRQ called %02x\n",timer_irq_vector); |
| 1202 | | irq_vector = timer_irq_vector; |
| 1294 | if(IRQ_LOG) printf("Timer IRQ called %02x\n",state->timer_irq_vector); |
| 1295 | state->irq_vector = state->timer_irq_vector; |
| 1203 | 1296 | cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE); |
| 1204 | 1297 | } |
| 1205 | 1298 | } |
| r9675 | r9676 | |
| 1207 | 1300 | |
| 1208 | 1301 | static WRITE8_HANDLER( pc6001m2_timer_adj_w ) |
| 1209 | 1302 | { |
| 1210 | | timer_hz_div = data; |
| 1211 | | attotime period = ATTOTIME_IN_HZ((487.5*4)/(timer_hz_div+1)); |
| 1212 | | timer_adjust_periodic(timer_irq_timer, period, 0, period); |
| 1303 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1304 | state->timer_hz_div = data; |
| 1305 | attotime period = ATTOTIME_IN_HZ((487.5*4)/(state->timer_hz_div+1)); |
| 1306 | timer_adjust_periodic(state->timer_irq_timer, period, 0, period); |
| 1213 | 1307 | } |
| 1214 | 1308 | |
| 1215 | 1309 | static WRITE8_HANDLER( pc6001m2_timer_irqv_w ) |
| 1216 | 1310 | { |
| 1217 | | timer_irq_vector = data; |
| 1311 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1312 | state->timer_irq_vector = data; |
| 1218 | 1313 | } |
| 1219 | 1314 | |
| 1220 | 1315 | static READ8_HANDLER( pc6001m2_bank_r0_r ) |
| 1221 | 1316 | { |
| 1222 | | return bank_r0; |
| 1317 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1318 | return state->bank_r0; |
| 1223 | 1319 | } |
| 1224 | 1320 | |
| 1225 | 1321 | static READ8_HANDLER( pc6001m2_bank_r1_r ) |
| 1226 | 1322 | { |
| 1227 | | return bank_r1; |
| 1323 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1324 | return state->bank_r1; |
| 1228 | 1325 | } |
| 1229 | 1326 | |
| 1230 | 1327 | static READ8_HANDLER( pc6001m2_bank_w0_r ) |
| 1231 | 1328 | { |
| 1232 | | return bank_w; |
| 1329 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1330 | return state->bank_w; |
| 1233 | 1331 | } |
| 1234 | 1332 | |
| 1235 | 1333 | static ADDRESS_MAP_START(pc6001m2_map, ADDRESS_SPACE_PROGRAM, 8) |
| r9675 | r9676 | |
| 1325 | 1423 | ADDRESS_MAP_END |
| 1326 | 1424 | |
| 1327 | 1425 | /* PC-6001 SR */ |
| 1328 | | static UINT8 sr_bank_r[8],sr_bank_w[8]; |
| 1329 | 1426 | |
| 1330 | 1427 | #define SR_SYSROM_1(_v_) \ |
| 1331 | 1428 | 0x10000+(0x1000*_v_) \ |
| r9675 | r9676 | |
| 1353 | 1450 | |
| 1354 | 1451 | static READ8_HANDLER( pc6001sr_bank_rn_r ) |
| 1355 | 1452 | { |
| 1356 | | return sr_bank_r[offset]; |
| 1453 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1454 | return state->sr_bank_r[offset]; |
| 1357 | 1455 | } |
| 1358 | 1456 | |
| 1359 | 1457 | static WRITE8_HANDLER( pc6001sr_bank_rn_w ) |
| 1360 | 1458 | { |
| 1459 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1361 | 1460 | const char* bank_name[8] = { "bank1","bank2","bank3", "bank4", "bank5", "bank6", "bank7", "bank8" }; |
| 1362 | 1461 | UINT8 *ROM = memory_region(space->machine, "maincpu"); |
| 1363 | 1462 | UINT8 bank_num; |
| 1364 | 1463 | |
| 1365 | | sr_bank_r[offset] = data; |
| 1464 | state->sr_bank_r[offset] = data; |
| 1366 | 1465 | bank_num = data & 0x0f; |
| 1367 | 1466 | |
| 1368 | 1467 | switch(data & 0xf0) |
| r9675 | r9676 | |
| 1380 | 1479 | |
| 1381 | 1480 | static READ8_HANDLER( pc6001sr_bank_wn_r ) |
| 1382 | 1481 | { |
| 1383 | | return sr_bank_w[offset]; |
| 1482 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1483 | return state->sr_bank_w[offset]; |
| 1384 | 1484 | } |
| 1385 | 1485 | |
| 1386 | 1486 | static WRITE8_HANDLER( pc6001sr_bank_wn_w ) |
| 1387 | 1487 | { |
| 1388 | | sr_bank_w[offset] = data; |
| 1488 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1489 | state->sr_bank_w[offset] = data; |
| 1389 | 1490 | } |
| 1390 | 1491 | |
| 1391 | 1492 | #define SR_WRAM_BANK_W(_v_) \ |
| 1392 | 1493 | { \ |
| 1494 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); \ |
| 1393 | 1495 | UINT8 *ROM = memory_region(space->machine, "maincpu"); \ |
| 1394 | 1496 | UINT8 bank_num; \ |
| 1395 | | bank_num = sr_bank_w[_v_] & 0x0f; \ |
| 1396 | | if((sr_bank_w[_v_] & 0xf0) != 0x20) \ |
| 1497 | bank_num = state->sr_bank_w[_v_] & 0x0f; \ |
| 1498 | if((state->sr_bank_w[_v_] & 0xf0) != 0x20) \ |
| 1397 | 1499 | ROM[offset+(SR_WRAM0(bank_num))] = data; \ |
| 1398 | 1500 | else \ |
| 1399 | 1501 | ROM[offset+(SR_EXRAM0(bank_num))] = data; \ |
| r9675 | r9676 | |
| 1410 | 1512 | |
| 1411 | 1513 | static WRITE8_HANDLER( pc6001sr_mode_w ) |
| 1412 | 1514 | { |
| 1413 | | sr_video_mode = data; |
| 1515 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1516 | state->sr_video_mode = data; |
| 1414 | 1517 | |
| 1415 | 1518 | if(data & 1) |
| 1416 | 1519 | assert("PC-6001SR in Mk-2 compatibility mode not yet supported!\n"); |
| r9675 | r9676 | |
| 1418 | 1521 | |
| 1419 | 1522 | static WRITE8_HANDLER( pc6001sr_vram_bank_w ) |
| 1420 | 1523 | { |
| 1524 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1421 | 1525 | UINT8 *work_ram = memory_region(space->machine, "maincpu"); |
| 1422 | 1526 | |
| 1423 | | pc6001_video_ram = work_ram + 0x70000 + ((data & 0x0f)*0x1000); |
| 1527 | state->video_ram = work_ram + 0x70000 + ((data & 0x0f)*0x1000); |
| 1424 | 1528 | } |
| 1425 | 1529 | |
| 1426 | 1530 | static WRITE8_HANDLER ( pc6001sr_system_latch_w ) |
| 1427 | 1531 | { |
| 1428 | | if((!(sys_latch & 8)) && data & 0x8) //PLAY tape cmd |
| 1532 | pc6001_state *state = space->machine->driver_data<pc6001_state>(); |
| 1533 | if((!(state->sys_latch & 8)) && data & 0x8) //PLAY tape cmd |
| 1429 | 1534 | { |
| 1430 | | cas_switch = 1; |
| 1535 | state->cas_switch = 1; |
| 1431 | 1536 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR); |
| 1432 | 1537 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_PLAY,CASSETTE_MASK_UISTATE); |
| 1433 | 1538 | } |
| 1434 | | if((sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd |
| 1539 | if((state->sys_latch & 8) && ((data & 0x8) == 0)) //STOP tape cmd |
| 1435 | 1540 | { |
| 1436 | | cas_switch = 0; |
| 1541 | state->cas_switch = 0; |
| 1437 | 1542 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_MOTOR_DISABLED,CASSETTE_MASK_MOTOR); |
| 1438 | 1543 | //cassette_change_state(space->machine->device("cass" ),CASSETTE_STOPPED,CASSETTE_MASK_UISTATE); |
| 1439 | | //irq_vector = 0x00; |
| 1544 | //state->irq_vector = 0x00; |
| 1440 | 1545 | //cputag_set_input_line(space->machine,"maincpu", 0, ASSERT_LINE); |
| 1441 | 1546 | } |
| 1442 | 1547 | |
| 1443 | | sys_latch = data; |
| 1548 | state->sys_latch = data; |
| 1444 | 1549 | |
| 1445 | | timer_irq_mask = data & 1; |
| 1446 | | //vram_bank_change(space->machine,(ex_vram_bank & 0x06) | ((sys_latch & 0x06) << 4)); |
| 1550 | state->timer_irq_mask = data & 1; |
| 1551 | //vram_bank_change(space->machine,(state->ex_vram_bank & 0x06) | ((state->sys_latch & 0x06) << 4)); |
| 1447 | 1552 | |
| 1448 | 1553 | //printf("%02x B0\n",data); |
| 1449 | 1554 | } |
| 1450 | 1555 | |
| 1451 | 1556 | static WRITE8_DEVICE_HANDLER(necsr_ppi8255_w) |
| 1452 | 1557 | { |
| 1558 | pc6001_state *state = device->machine->driver_data<pc6001_state>(); |
| 1453 | 1559 | if (offset==3) |
| 1454 | 1560 | { |
| 1455 | 1561 | if(data & 1) |
| 1456 | | port_c_8255 |= 1<<((data>>1)&0x07); |
| 1562 | state->port_c_8255 |= 1<<((data>>1)&0x07); |
| 1457 | 1563 | else |
| 1458 | | port_c_8255 &= ~(1<<((data>>1)&0x07)); |
| 1564 | state->port_c_8255 &= ~(1<<((data>>1)&0x07)); |
| 1459 | 1565 | |
| 1460 | 1566 | switch(data) { |
| 1461 | | case 0x08: port_c_8255 |= 0x88; break; |
| 1462 | | case 0x09: port_c_8255 &= 0xf7; break; |
| 1463 | | case 0x0c: port_c_8255 |= 0x28; break; |
| 1464 | | case 0x0d: port_c_8255 &= 0xf7; break; |
| 1567 | case 0x08: state->port_c_8255 |= 0x88; break; |
| 1568 | case 0x09: state->port_c_8255 &= 0xf7; break; |
| 1569 | case 0x0c: state->port_c_8255 |= 0x28; break; |
| 1570 | case 0x0d: state->port_c_8255 &= 0xf7; break; |
| 1465 | 1571 | default: break; |
| 1466 | 1572 | } |
| 1467 | 1573 | |
| 1468 | | port_c_8255 |= 0xa8; |
| 1574 | state->port_c_8255 |= 0xa8; |
| 1469 | 1575 | |
| 1470 | 1576 | if(0) |
| 1471 | 1577 | { |
| r9675 | r9676 | |
| 1687 | 1793 | |
| 1688 | 1794 | static INTERRUPT_GEN( pc6001_interrupt ) |
| 1689 | 1795 | { |
| 1690 | | cur_keycode = check_joy_press(device->machine); |
| 1796 | pc6001_state *state = device->machine->driver_data<pc6001_state>(); |
| 1797 | state->cur_keycode = check_joy_press(device->machine); |
| 1691 | 1798 | if(IRQ_LOG) printf("Stick IRQ called 0x16\n"); |
| 1692 | | irq_vector = 0x16; |
| 1799 | state->irq_vector = 0x16; |
| 1693 | 1800 | cpu_set_input_line(device, 0, ASSERT_LINE); |
| 1694 | 1801 | } |
| 1695 | 1802 | |
| 1696 | 1803 | static INTERRUPT_GEN( pc6001sr_interrupt ) |
| 1697 | 1804 | { |
| 1698 | | static UINT8 kludge; |
| 1805 | pc6001_state *state = device->machine->driver_data<pc6001_state>(); |
| 1806 | state->kludge^= 1; |
| 1699 | 1807 | |
| 1700 | | kludge^= 1; |
| 1701 | | |
| 1702 | | cur_keycode = check_joy_press(device->machine); |
| 1808 | state->cur_keycode = check_joy_press(device->machine); |
| 1703 | 1809 | if(IRQ_LOG) printf("VRTC IRQ called 0x16\n"); |
| 1704 | | irq_vector = (kludge) ? 0x22 : 0x16; |
| 1810 | state->irq_vector = (state->kludge) ? 0x22 : 0x16; |
| 1705 | 1811 | cpu_set_input_line(device, 0, ASSERT_LINE); |
| 1706 | 1812 | } |
| 1707 | 1813 | |
| 1708 | 1814 | static IRQ_CALLBACK ( pc6001_irq_callback ) |
| 1709 | 1815 | { |
| 1816 | pc6001_state *state = device->machine->driver_data<pc6001_state>(); |
| 1710 | 1817 | cpu_set_input_line(device, 0, CLEAR_LINE); |
| 1711 | | return irq_vector; |
| 1818 | return state->irq_vector; |
| 1712 | 1819 | } |
| 1713 | 1820 | |
| 1714 | 1821 | static READ8_DEVICE_HANDLER (pc6001_8255_porta_r ) |
| r9675 | r9676 | |
| 1852 | 1959 | |
| 1853 | 1960 | static TIMER_CALLBACK(cassette_callback) |
| 1854 | 1961 | { |
| 1855 | | if(cas_switch == 1) |
| 1962 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 1963 | if(state->cas_switch == 1) |
| 1856 | 1964 | { |
| 1857 | 1965 | #if 0 |
| 1858 | 1966 | static UINT8 cas_data_i = 0x80,cas_data_poll; |
| 1859 | | //cur_keycode = gfx_data[cas_offset++]; |
| 1967 | //state->cur_keycode = gfx_data[state->cas_offset++]; |
| 1860 | 1968 | if(cassette_input(machine->device("cass")) > 0.03) |
| 1861 | 1969 | cas_data_poll|= cas_data_i; |
| 1862 | 1970 | else |
| 1863 | 1971 | cas_data_poll&=~cas_data_i; |
| 1864 | 1972 | if(cas_data_i == 1) |
| 1865 | 1973 | { |
| 1866 | | cur_keycode = cas_data_poll; |
| 1974 | state->cur_keycode = cas_data_poll; |
| 1867 | 1975 | cas_data_i = 0x80; |
| 1868 | 1976 | /* data ready, poll irq */ |
| 1869 | | irq_vector = 0x08; |
| 1977 | state->irq_vector = 0x08; |
| 1870 | 1978 | cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE); |
| 1871 | 1979 | } |
| 1872 | 1980 | else |
| r9675 | r9676 | |
| 1874 | 1982 | #else |
| 1875 | 1983 | UINT8 *cas_data = memory_region(machine, "cas"); |
| 1876 | 1984 | |
| 1877 | | cur_keycode = cas_data[cas_offset++]; |
| 1878 | | popmessage("%04x %04x",cas_offset,cas_maxsize); |
| 1879 | | if(cas_offset > cas_maxsize) |
| 1985 | state->cur_keycode = cas_data[state->cas_offset++]; |
| 1986 | popmessage("%04x %04x",state->cas_offset,state->cas_maxsize); |
| 1987 | if(state->cas_offset > state->cas_maxsize) |
| 1880 | 1988 | { |
| 1881 | | cas_offset = 0; |
| 1882 | | cas_switch = 0; |
| 1989 | state->cas_offset = 0; |
| 1990 | state->cas_switch = 0; |
| 1883 | 1991 | if(IRQ_LOG) printf("Tape-E IRQ 0x12\n"); |
| 1884 | | irq_vector = 0x12; |
| 1992 | state->irq_vector = 0x12; |
| 1885 | 1993 | cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE); |
| 1886 | 1994 | } |
| 1887 | 1995 | else |
| 1888 | 1996 | { |
| 1889 | 1997 | if(IRQ_LOG) printf("Tape-D IRQ 0x08\n"); |
| 1890 | | irq_vector = 0x08; |
| 1998 | state->irq_vector = 0x08; |
| 1891 | 1999 | cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE); |
| 1892 | 2000 | } |
| 1893 | 2001 | #endif |
| r9675 | r9676 | |
| 1896 | 2004 | |
| 1897 | 2005 | static TIMER_CALLBACK(keyboard_callback) |
| 1898 | 2006 | { |
| 2007 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 1899 | 2008 | address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1900 | 2009 | UINT32 key1 = input_port_read(machine,"key1"); |
| 1901 | 2010 | UINT32 key2 = input_port_read(machine,"key2"); |
| 1902 | 2011 | UINT32 key3 = input_port_read(machine,"key3"); |
| 1903 | | static UINT32 old_key1,old_key2,old_key3; |
| 1904 | 2012 | // UINT8 p1_key = input_port_read(machine, "P1");; |
| 1905 | 2013 | |
| 1906 | | if(cas_switch == 0) |
| 2014 | if(state->cas_switch == 0) |
| 1907 | 2015 | { |
| 1908 | | if((key1 != old_key1) || (key2 != old_key2) || (key3 != old_key3)) |
| 2016 | if((key1 != state->old_key1) || (key2 != state->old_key2) || (key3 != state->old_key3)) |
| 1909 | 2017 | { |
| 1910 | | cur_keycode = check_keyboard_press(space->machine); |
| 2018 | state->cur_keycode = check_keyboard_press(space->machine); |
| 1911 | 2019 | if(IRQ_LOG) printf("KEY IRQ 0x02\n"); |
| 1912 | | irq_vector = 0x02; |
| 2020 | state->irq_vector = 0x02; |
| 1913 | 2021 | cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE); |
| 1914 | | old_key1 = key1; |
| 1915 | | old_key2 = key2; |
| 1916 | | old_key3 = key3; |
| 2022 | state->old_key1 = key1; |
| 2023 | state->old_key2 = key2; |
| 2024 | state->old_key3 = key3; |
| 1917 | 2025 | } |
| 1918 | 2026 | #if 0 |
| 1919 | 2027 | else /* joypad polling */ |
| 1920 | 2028 | { |
| 1921 | | cur_keycode = check_joy_press(space->machine); |
| 1922 | | if(cur_keycode) |
| 2029 | state->cur_keycode = check_joy_press(space->machine); |
| 2030 | if(state->cur_keycode) |
| 1923 | 2031 | { |
| 1924 | | irq_vector = 0x16; |
| 2032 | state->irq_vector = 0x16; |
| 1925 | 2033 | cputag_set_input_line(machine,"maincpu", 0, ASSERT_LINE); |
| 1926 | 2034 | } |
| 1927 | 2035 | } |
| r9675 | r9676 | |
| 1931 | 2039 | |
| 1932 | 2040 | static MACHINE_START(pc6001) |
| 1933 | 2041 | { |
| 2042 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 1934 | 2043 | /* TODO: accurate timing on this */ |
| 1935 | 2044 | timer_pulse(machine, ATTOTIME_IN_HZ(250), NULL, 0, keyboard_callback); |
| 1936 | 2045 | |
| 1937 | 2046 | timer_pulse(machine, ATTOTIME_IN_HZ(1200/12), NULL, 0, cassette_callback); //1200 bauds / (1 start bit -> 8 data bits -> 3 stop bits) |
| 1938 | 2047 | |
| 1939 | | timer_hz_div = 3; |
| 2048 | state->timer_hz_div = 3; |
| 1940 | 2049 | { |
| 1941 | | attotime period = ATTOTIME_IN_HZ((487.5*4)/(timer_hz_div+1)); |
| 1942 | | timer_irq_timer = timer_alloc(machine, audio_callback, NULL); |
| 1943 | | timer_adjust_periodic(timer_irq_timer, period, 0, period); |
| 2050 | attotime period = ATTOTIME_IN_HZ((487.5*4)/(state->timer_hz_div+1)); |
| 2051 | state->timer_irq_timer = timer_alloc(machine, audio_callback, NULL); |
| 2052 | timer_adjust_periodic(state->timer_irq_timer, period, 0, period); |
| 1944 | 2053 | } |
| 1945 | 2054 | } |
| 1946 | 2055 | |
| 1947 | 2056 | static MACHINE_RESET(pc6001) |
| 1948 | 2057 | { |
| 2058 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 1949 | 2059 | UINT8 *work_ram = memory_region(machine, "maincpu"); |
| 1950 | 2060 | |
| 1951 | | pc6001_video_ram = work_ram + 0xc000; |
| 2061 | state->video_ram = work_ram + 0xc000; |
| 1952 | 2062 | |
| 1953 | | port_c_8255=0; |
| 2063 | state->port_c_8255=0; |
| 1954 | 2064 | |
| 1955 | 2065 | cpu_set_irq_callback(machine->device("maincpu"),pc6001_irq_callback); |
| 1956 | | cas_switch = 0; |
| 1957 | | cas_offset = 0; |
| 1958 | | timer_irq_mask = 1; |
| 1959 | | timer_irq_mask2 = 1; |
| 1960 | | timer_irq_vector = 0x06; // actually vector is fixed in plain PC-6001 |
| 1961 | | timer_hz_div = 3; |
| 2066 | state->cas_switch = 0; |
| 2067 | state->cas_offset = 0; |
| 2068 | state->timer_irq_mask = 1; |
| 2069 | state->timer_irq_mask2 = 1; |
| 2070 | state->timer_irq_vector = 0x06; // actually vector is fixed in plain PC-6001 |
| 2071 | state->timer_hz_div = 3; |
| 1962 | 2072 | } |
| 1963 | 2073 | |
| 1964 | 2074 | static MACHINE_RESET(pc6001m2) |
| 1965 | 2075 | { |
| 2076 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 1966 | 2077 | UINT8 *work_ram = memory_region(machine, "maincpu"); |
| 1967 | 2078 | |
| 1968 | | pc6001_video_ram = work_ram + 0xc000 + 0x28000; |
| 2079 | state->video_ram = work_ram + 0xc000 + 0x28000; |
| 1969 | 2080 | |
| 1970 | | port_c_8255=0; |
| 2081 | state->port_c_8255=0; |
| 1971 | 2082 | |
| 1972 | 2083 | cpu_set_irq_callback(machine->device("maincpu"),pc6001_irq_callback); |
| 1973 | | cas_switch = 0; |
| 1974 | | cas_offset = 0; |
| 2084 | state->cas_switch = 0; |
| 2085 | state->cas_offset = 0; |
| 1975 | 2086 | |
| 1976 | 2087 | /* set default bankswitch */ |
| 1977 | 2088 | { |
| 1978 | 2089 | UINT8 *ROM = memory_region(machine, "maincpu"); |
| 1979 | | bank_r0 = 0x71; |
| 2090 | state->bank_r0 = 0x71; |
| 1980 | 2091 | memory_set_bankptr(machine, "bank1", &ROM[BASICROM(0)]); |
| 1981 | 2092 | memory_set_bankptr(machine, "bank2", &ROM[BASICROM(1)]); |
| 1982 | 2093 | memory_set_bankptr(machine, "bank3", &ROM[EXROM(0)]); |
| 1983 | 2094 | memory_set_bankptr(machine, "bank4", &ROM[EXROM(1)]); |
| 1984 | | bank_r1 = 0xdd; |
| 2095 | state->bank_r1 = 0xdd; |
| 1985 | 2096 | memory_set_bankptr(machine, "bank5", &ROM[WRAM(4)]); |
| 1986 | 2097 | memory_set_bankptr(machine, "bank6", &ROM[WRAM(5)]); |
| 1987 | 2098 | memory_set_bankptr(machine, "bank7", &ROM[WRAM(6)]); |
| 1988 | 2099 | memory_set_bankptr(machine, "bank8", &ROM[WRAM(7)]); |
| 1989 | | bank_opt = 0x02; //tv rom |
| 1990 | | bank_w = 0x50; //enable write to work ram 4,5,6,7 |
| 1991 | | gfx_bank_on = 0; |
| 2100 | state->bank_opt = 0x02; //tv rom |
| 2101 | state->bank_w = 0x50; //enable write to work ram 4,5,6,7 |
| 2102 | state->gfx_bank_on = 0; |
| 1992 | 2103 | } |
| 1993 | 2104 | |
| 1994 | | timer_irq_mask = 1; |
| 1995 | | timer_irq_mask2 = 1; |
| 1996 | | timer_irq_vector = 0x06; |
| 2105 | state->timer_irq_mask = 1; |
| 2106 | state->timer_irq_mask2 = 1; |
| 2107 | state->timer_irq_vector = 0x06; |
| 1997 | 2108 | } |
| 1998 | 2109 | |
| 1999 | 2110 | static MACHINE_RESET(pc6001sr) |
| 2000 | 2111 | { |
| 2112 | pc6001_state *state = machine->driver_data<pc6001_state>(); |
| 2001 | 2113 | UINT8 *work_ram = memory_region(machine, "maincpu"); |
| 2002 | 2114 | |
| 2003 | | pc6001_video_ram = work_ram + 0x70000; |
| 2115 | state->video_ram = work_ram + 0x70000; |
| 2004 | 2116 | |
| 2005 | | port_c_8255=0; |
| 2117 | state->port_c_8255=0; |
| 2006 | 2118 | |
| 2007 | 2119 | cpu_set_irq_callback(machine->device("maincpu"),pc6001_irq_callback); |
| 2008 | | cas_switch = 0; |
| 2009 | | cas_offset = 0; |
| 2120 | state->cas_switch = 0; |
| 2121 | state->cas_offset = 0; |
| 2010 | 2122 | |
| 2011 | 2123 | /* set default bankswitch */ |
| 2012 | 2124 | { |
| 2013 | 2125 | UINT8 *ROM = memory_region(machine, "maincpu"); |
| 2014 | | sr_bank_r[0] = 0xf8; memory_set_bankptr(machine, "bank1", &ROM[SR_SYSROM_1(0x08)]); |
| 2015 | | sr_bank_r[1] = 0xfa; memory_set_bankptr(machine, "bank2", &ROM[SR_SYSROM_1(0x0a)]); |
| 2016 | | sr_bank_r[2] = 0xb0; memory_set_bankptr(machine, "bank3", &ROM[SR_EXROM1(0x00)]); |
| 2017 | | sr_bank_r[3] = 0xc0; memory_set_bankptr(machine, "bank4", &ROM[SR_EXROM0(0x00)]); |
| 2018 | | sr_bank_r[4] = 0x08; memory_set_bankptr(machine, "bank5", &ROM[SR_WRAM0(0x08)]); |
| 2019 | | sr_bank_r[5] = 0x0a; memory_set_bankptr(machine, "bank6", &ROM[SR_WRAM0(0x0a)]); |
| 2020 | | sr_bank_r[6] = 0x0c; memory_set_bankptr(machine, "bank7", &ROM[SR_WRAM0(0x0c)]); |
| 2021 | | sr_bank_r[7] = 0x0e; memory_set_bankptr(machine, "bank8", &ROM[SR_WRAM0(0x0e)]); |
| 2022 | | // bank_opt = 0x02; //tv rom |
| 2126 | state->sr_bank_r[0] = 0xf8; memory_set_bankptr(machine, "bank1", &ROM[SR_SYSROM_1(0x08)]); |
| 2127 | state->sr_bank_r[1] = 0xfa; memory_set_bankptr(machine, "bank2", &ROM[SR_SYSROM_1(0x0a)]); |
| 2128 | state->sr_bank_r[2] = 0xb0; memory_set_bankptr(machine, "bank3", &ROM[SR_EXROM1(0x00)]); |
| 2129 | state->sr_bank_r[3] = 0xc0; memory_set_bankptr(machine, "bank4", &ROM[SR_EXROM0(0x00)]); |
| 2130 | state->sr_bank_r[4] = 0x08; memory_set_bankptr(machine, "bank5", &ROM[SR_WRAM0(0x08)]); |
| 2131 | state->sr_bank_r[5] = 0x0a; memory_set_bankptr(machine, "bank6", &ROM[SR_WRAM0(0x0a)]); |
| 2132 | state->sr_bank_r[6] = 0x0c; memory_set_bankptr(machine, "bank7", &ROM[SR_WRAM0(0x0c)]); |
| 2133 | state->sr_bank_r[7] = 0x0e; memory_set_bankptr(machine, "bank8", &ROM[SR_WRAM0(0x0e)]); |
| 2134 | // state->bank_opt = 0x02; //tv rom |
| 2023 | 2135 | |
| 2024 | 2136 | /* enable default work RAM writes */ |
| 2025 | | sr_bank_w[0] = 0x00; |
| 2026 | | sr_bank_w[1] = 0x02; |
| 2027 | | sr_bank_w[2] = 0x04; |
| 2028 | | sr_bank_w[3] = 0x06; |
| 2029 | | sr_bank_w[4] = 0x08; |
| 2030 | | sr_bank_w[5] = 0x0a; |
| 2031 | | sr_bank_w[6] = 0x0c; |
| 2032 | | sr_bank_w[7] = 0x0e; |
| 2137 | state->sr_bank_w[0] = 0x00; |
| 2138 | state->sr_bank_w[1] = 0x02; |
| 2139 | state->sr_bank_w[2] = 0x04; |
| 2140 | state->sr_bank_w[3] = 0x06; |
| 2141 | state->sr_bank_w[4] = 0x08; |
| 2142 | state->sr_bank_w[5] = 0x0a; |
| 2143 | state->sr_bank_w[6] = 0x0c; |
| 2144 | state->sr_bank_w[7] = 0x0e; |
| 2033 | 2145 | |
| 2034 | | gfx_bank_on = 0; |
| 2146 | state->gfx_bank_on = 0; |
| 2035 | 2147 | } |
| 2036 | 2148 | |
| 2037 | | timer_irq_mask = 1; |
| 2038 | | timer_irq_mask2 = 1; |
| 2039 | | timer_irq_vector = 0x06; |
| 2149 | state->timer_irq_mask = 1; |
| 2150 | state->timer_irq_mask2 = 1; |
| 2151 | state->timer_irq_vector = 0x06; |
| 2040 | 2152 | } |
| 2041 | 2153 | |
| 2042 | 2154 | static const rgb_t defcolors[] = |
| r9675 | r9676 | |
| 2106 | 2218 | |
| 2107 | 2219 | static DEVICE_IMAGE_LOAD( pc6001_cass ) |
| 2108 | 2220 | { |
| 2221 | pc6001_state *state = image.device().machine->driver_data<pc6001_state>(); |
| 2109 | 2222 | UINT8 *cas = memory_region(image.device().machine, "cas"); |
| 2110 | 2223 | UINT32 size; |
| 2111 | 2224 | |
| r9675 | r9676 | |
| 2116 | 2229 | return IMAGE_INIT_FAIL; |
| 2117 | 2230 | } |
| 2118 | 2231 | |
| 2119 | | cas_maxsize = size; |
| 2232 | state->cas_maxsize = size; |
| 2120 | 2233 | |
| 2121 | 2234 | return IMAGE_INIT_PASS; |
| 2122 | 2235 | } |
| r9675 | r9676 | |
| 2152 | 2265 | |
| 2153 | 2266 | #define PC6001_MAIN_CLOCK 7987200 |
| 2154 | 2267 | |
| 2155 | | static MACHINE_CONFIG_START( pc6001, driver_device ) |
| 2268 | static MACHINE_CONFIG_START( pc6001, pc6001_state ) |
| 2156 | 2269 | /* basic machine hardware */ |
| 2157 | 2270 | MDRV_CPU_ADD("maincpu",Z80, PC6001_MAIN_CLOCK / 2) // ~4 Mhz |
| 2158 | 2271 | MDRV_CPU_PROGRAM_MAP(pc6001_map) |
src/mess/drivers/pc88va.c
| r9675 | r9676 | |
| 25 | 25 | #include "machine/upd765.h" |
| 26 | 26 | #include "sound/2203intf.h" |
| 27 | 27 | |
| 28 | | static UINT16 *palram; |
| 29 | | static UINT16 bank_reg; |
| 30 | | static UINT16 screen_ctrl_reg; |
| 31 | | static UINT8 timer3_io_reg; |
| 32 | | static emu_timer *t3_mouse_timer; |
| 33 | | static struct |
| 28 | typedef struct |
| 34 | 29 | { |
| 35 | 30 | UINT16 tvram_vreg_offset; |
| 36 | 31 | UINT16 attr_offset; |
| r9675 | r9676 | |
| 44 | 39 | UINT16 cur_pos_x,cur_pos_y; |
| 45 | 40 | UINT8 curn; |
| 46 | 41 | UINT8 curn_blink; |
| 47 | | }tsp; |
| 48 | | static UINT16 video_pri_reg[2]; |
| 42 | } tsp_t; |
| 49 | 43 | |
| 50 | | static UINT8 backupram_wp; |
| 51 | 44 | |
| 45 | class pc88va_state : public driver_device |
| 46 | { |
| 47 | public: |
| 48 | pc88va_state(running_machine &machine, const driver_device_config_base &config) |
| 49 | : driver_device(machine, config) { } |
| 50 | |
| 51 | UINT16 *palram; |
| 52 | UINT16 bank_reg; |
| 53 | UINT16 screen_ctrl_reg; |
| 54 | UINT8 timer3_io_reg; |
| 55 | emu_timer *t3_mouse_timer; |
| 56 | tsp_t tsp; |
| 57 | UINT16 video_pri_reg[2]; |
| 58 | UINT8 backupram_wp; |
| 59 | UINT8 cmd; |
| 60 | UINT8 buf_size; |
| 61 | UINT8 buf_index; |
| 62 | UINT8 buf_ram[16]; |
| 63 | UINT8 portc_test; |
| 64 | }; |
| 65 | |
| 66 | |
| 52 | 67 | static VIDEO_START( pc88va ) |
| 53 | 68 | { |
| 54 | 69 | |
| r9675 | r9676 | |
| 56 | 71 | |
| 57 | 72 | static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 58 | 73 | { |
| 74 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 59 | 75 | UINT16 *tvram = (UINT16 *)memory_region(machine, "tvram"); |
| 60 | 76 | int offs,i; |
| 61 | 77 | |
| 62 | | offs = tsp.spr_offset; |
| 78 | offs = state->tsp.spr_offset; |
| 63 | 79 | for(i=0;i<(0x100);i+=(8)) |
| 64 | 80 | { |
| 65 | 81 | int xp,yp,sw,md,xsize,ysize,spda,fg_col,bc; |
| r9675 | r9676 | |
| 165 | 181 | |
| 166 | 182 | static void draw_text(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 167 | 183 | { |
| 184 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 168 | 185 | UINT8 *tvram = memory_region(machine, "tvram"); |
| 169 | 186 | UINT8 *kanji = memory_region(machine, "kanji"); |
| 170 | 187 | int xi,yi; |
| r9675 | r9676 | |
| 179 | 196 | UINT8 fg_col,bg_col,secret,reverse,blink,dwidc,dwid,uline,hline; |
| 180 | 197 | UINT8 screen_fg_col,screen_bg_col; |
| 181 | 198 | |
| 182 | | count = (tvram[tsp.tvram_vreg_offset+0] | tvram[tsp.tvram_vreg_offset+1] << 8); |
| 199 | count = (tvram[state->tsp.tvram_vreg_offset+0] | tvram[state->tsp.tvram_vreg_offset+1] << 8); |
| 183 | 200 | |
| 184 | | attr_mode = tvram[tsp.tvram_vreg_offset+0xa] & 0x1f; |
| 201 | attr_mode = tvram[state->tsp.tvram_vreg_offset+0xa] & 0x1f; |
| 185 | 202 | /* Note: bug in docs has the following two reversed */ |
| 186 | | screen_fg_col = (tvram[tsp.tvram_vreg_offset+0xb] & 0xf0) >> 4; |
| 187 | | screen_bg_col = tvram[tsp.tvram_vreg_offset+0xb] & 0x0f; |
| 203 | screen_fg_col = (tvram[state->tsp.tvram_vreg_offset+0xb] & 0xf0) >> 4; |
| 204 | screen_bg_col = tvram[state->tsp.tvram_vreg_offset+0xb] & 0x0f; |
| 188 | 205 | |
| 189 | 206 | for(y=0;y<13;y++) |
| 190 | 207 | { |
| r9675 | r9676 | |
| 196 | 213 | |
| 197 | 214 | tile_num = calc_kanji_rom_addr(jis1,jis2,x,y); |
| 198 | 215 | |
| 199 | | attr = (tvram[count+tsp.attr_offset] & 0x00ff); |
| 216 | attr = (tvram[count+state->tsp.attr_offset] & 0x00ff); |
| 200 | 217 | |
| 201 | 218 | fg_col = bg_col = reverse = blink = secret = dwidc = dwid = uline = hline = 0; |
| 202 | 219 | |
| r9675 | r9676 | |
| 345 | 362 | |
| 346 | 363 | static VIDEO_UPDATE( pc88va ) |
| 347 | 364 | { |
| 365 | pc88va_state *state = screen->machine->driver_data<pc88va_state>(); |
| 348 | 366 | UINT8 pri,cur_pri_lv; |
| 349 | 367 | UINT32 screen_pri; |
| 350 | 368 | bitmap_fill(bitmap, cliprect, 0); |
| 351 | 369 | |
| 352 | | if(tsp.disp_on == 0) // don't bother if we are under DSPOFF command |
| 370 | if(state->tsp.disp_on == 0) // don't bother if we are under DSPOFF command |
| 353 | 371 | return 0; |
| 354 | 372 | |
| 355 | 373 | /* |
| 356 | | video_pri_reg[0] |
| 374 | state->video_pri_reg[0] |
| 357 | 375 | xxxx ---- ---- ---- priority 3 |
| 358 | 376 | ---- xxxx ---- ---- priority 2 |
| 359 | 377 | ---- ---- xxxx ---- priority 1 |
| 360 | 378 | ---- ---- ---- xxxx priority 0 |
| 361 | | video_pri_reg[1] |
| 379 | state->video_pri_reg[1] |
| 362 | 380 | ---- ---- xxxx ---- priority 5 |
| 363 | 381 | ---- ---- ---- xxxx priority 4 |
| 364 | 382 | |
| 365 | 383 | Note that orthogonality level is actually REVERSED than the level number it indicates, so we have to play a little with the data for an easier usage ... |
| 366 | 384 | */ |
| 367 | 385 | |
| 368 | | screen_pri = (video_pri_reg[1] & 0x00f0) >> 4; // priority 5 |
| 369 | | screen_pri|= (video_pri_reg[1] & 0x000f) << 4; // priority 4 |
| 370 | | screen_pri|= (video_pri_reg[0] & 0xf000) >> 4; // priority 3 |
| 371 | | screen_pri|= (video_pri_reg[0] & 0x0f00) << 4; // priority 2 |
| 372 | | screen_pri|= (video_pri_reg[0] & 0x00f0) << 12; // priority 1 |
| 373 | | screen_pri|= (video_pri_reg[0] & 0x000f) << 20; // priority 0 |
| 386 | screen_pri = (state->video_pri_reg[1] & 0x00f0) >> 4; // priority 5 |
| 387 | screen_pri|= (state->video_pri_reg[1] & 0x000f) << 4; // priority 4 |
| 388 | screen_pri|= (state->video_pri_reg[0] & 0xf000) >> 4; // priority 3 |
| 389 | screen_pri|= (state->video_pri_reg[0] & 0x0f00) << 4; // priority 2 |
| 390 | screen_pri|= (state->video_pri_reg[0] & 0x00f0) << 12; // priority 1 |
| 391 | screen_pri|= (state->video_pri_reg[0] & 0x000f) << 20; // priority 0 |
| 374 | 392 | |
| 375 | 393 | for(pri=0;pri<6;pri++) |
| 376 | 394 | { |
| r9675 | r9676 | |
| 388 | 406 | switch(cur_pri_lv & 3) // (palette color mode) |
| 389 | 407 | { |
| 390 | 408 | case 0: draw_text(screen->machine,bitmap,cliprect); break; |
| 391 | | case 1: if(tsp.spr_on) { draw_sprites(screen->machine,bitmap,cliprect); } break; |
| 409 | case 1: if(state->tsp.spr_on) { draw_sprites(screen->machine,bitmap,cliprect); } break; |
| 392 | 410 | case 2: /* A = graphic 0 */ break; |
| 393 | 411 | case 3: /* B = graphic 1 */ break; |
| 394 | 412 | } |
| r9675 | r9676 | |
| 401 | 419 | |
| 402 | 420 | static READ16_HANDLER( sys_mem_r ) |
| 403 | 421 | { |
| 404 | | switch((bank_reg & 0xf00) >> 8) |
| 422 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 423 | switch((state->bank_reg & 0xf00) >> 8) |
| 405 | 424 | { |
| 406 | 425 | case 0: // select bus slot |
| 407 | 426 | return 0xffff; |
| r9675 | r9676 | |
| 426 | 445 | UINT16 *knj_ram = (UINT16 *)memory_region(space->machine, "kanji"); |
| 427 | 446 | UINT32 knj_offset; |
| 428 | 447 | |
| 429 | | knj_offset = (offset + (((bank_reg & 0x100) >> 8)*0x20000)); |
| 448 | knj_offset = (offset + (((state->bank_reg & 0x100) >> 8)*0x20000)); |
| 430 | 449 | |
| 431 | 450 | /* 0x00000 - 0x3ffff Kanji ROM 1*/ |
| 432 | 451 | /* 0x40000 - 0x4ffff Kanji ROM 2*/ |
| r9675 | r9676 | |
| 442 | 461 | UINT16 *dic_rom = (UINT16 *)memory_region(space->machine, "dictionary"); |
| 443 | 462 | UINT32 dic_offset; |
| 444 | 463 | |
| 445 | | dic_offset = (offset + (((bank_reg & 0x100) >> 8)*0x20000)); |
| 464 | dic_offset = (offset + (((state->bank_reg & 0x100) >> 8)*0x20000)); |
| 446 | 465 | |
| 447 | 466 | return dic_rom[dic_offset]; |
| 448 | 467 | } |
| r9675 | r9676 | |
| 453 | 472 | |
| 454 | 473 | static WRITE16_HANDLER( sys_mem_w ) |
| 455 | 474 | { |
| 456 | | switch((bank_reg & 0xf00) >> 8) |
| 475 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 476 | switch((state->bank_reg & 0xf00) >> 8) |
| 457 | 477 | { |
| 458 | 478 | case 0: // select bus slot |
| 459 | 479 | break; |
| r9675 | r9676 | |
| 478 | 498 | UINT16 *knj_ram = (UINT16 *)memory_region(space->machine, "kanji"); |
| 479 | 499 | UINT32 knj_offset; |
| 480 | 500 | |
| 481 | | knj_offset = ((offset) + (((bank_reg & 0x100) >> 8)*0x20000)); |
| 501 | knj_offset = ((offset) + (((state->bank_reg & 0x100) >> 8)*0x20000)); |
| 482 | 502 | |
| 483 | 503 | if(knj_offset >= 0x50000/2 && knj_offset <= 0x53fff/2) // TODO: there's an area that can be write protected |
| 484 | 504 | { |
| r9675 | r9676 | |
| 520 | 540 | return 0x00; |
| 521 | 541 | } |
| 522 | 542 | |
| 523 | | static UINT8 cmd,buf_size,buf_index; |
| 524 | | static UINT8 buf_ram[16]; |
| 525 | 543 | |
| 526 | 544 | #define SYNC 0x10 |
| 527 | 545 | #define DSPON 0x12 |
| r9675 | r9676 | |
| 539 | 557 | |
| 540 | 558 | static WRITE8_HANDLER( idp_command_w ) |
| 541 | 559 | { |
| 560 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 542 | 561 | switch(data) |
| 543 | 562 | { |
| 544 | 563 | /* 0x10 - SYNC: sets CRTC values */ |
| 545 | | case SYNC: cmd = SYNC; buf_size = 14; buf_index = 0; break; |
| 564 | case SYNC: state->cmd = SYNC; state->buf_size = 14; state->buf_index = 0; break; |
| 546 | 565 | |
| 547 | 566 | /* 0x12 - DSPON: set DiSPlay ON and set up tvram table vreg */ |
| 548 | | case DSPON: cmd = DSPON; buf_size = 3; buf_index = 0; break; |
| 567 | case DSPON: state->cmd = DSPON; state->buf_size = 3; state->buf_index = 0; break; |
| 549 | 568 | |
| 550 | 569 | /* 0x13 - DSPOFF: set DiSPlay OFF */ |
| 551 | | case DSPOFF: cmd = DSPOFF; tsp.disp_on = 0; break; |
| 570 | case DSPOFF: state->cmd = DSPOFF; state->tsp.disp_on = 0; break; |
| 552 | 571 | |
| 553 | 572 | /* 0x14 - DSPDEF: set DiSPlay DEFinitions */ |
| 554 | | case DSPDEF: cmd = DSPDEF; buf_size = 6; buf_index = 0; break; |
| 573 | case DSPDEF: state->cmd = DSPDEF; state->buf_size = 6; state->buf_index = 0; break; |
| 555 | 574 | |
| 556 | 575 | /* 0x15 - CURDEF: set CURsor DEFinition */ |
| 557 | | case CURDEF: cmd = CURDEF; buf_size = 1; buf_index = 0; break; |
| 576 | case CURDEF: state->cmd = CURDEF; state->buf_size = 1; state->buf_index = 0; break; |
| 558 | 577 | |
| 559 | 578 | /* 0x16 - ACTSCR: ??? */ |
| 560 | | case ACTSCR: cmd = ACTSCR; buf_size = 1; buf_index = 0; break; |
| 579 | case ACTSCR: state->cmd = ACTSCR; state->buf_size = 1; state->buf_index = 0; break; |
| 561 | 580 | |
| 562 | 581 | /* 0x15 - CURS: set CURSor position */ |
| 563 | | case CURS: cmd = CURS; buf_size = 4; buf_index = 0; break; |
| 582 | case CURS: state->cmd = CURS; state->buf_size = 4; state->buf_index = 0; break; |
| 564 | 583 | |
| 565 | 584 | /* 0x8c - EMUL: set 3301 EMULation */ |
| 566 | | case EMUL: cmd = EMUL; buf_size = 4; buf_index = 0; break; |
| 585 | case EMUL: state->cmd = EMUL; state->buf_size = 4; state->buf_index = 0; break; |
| 567 | 586 | |
| 568 | 587 | /* 0x88 - EXIT: ??? */ |
| 569 | | case EXIT: cmd = EXIT; break; |
| 588 | case EXIT: state->cmd = EXIT; break; |
| 570 | 589 | |
| 571 | 590 | /* 0x82 - SPRON: set SPRite ON */ |
| 572 | | case SPRON: cmd = SPRON; buf_size = 3; buf_index = 0; break; |
| 591 | case SPRON: state->cmd = SPRON; state->buf_size = 3; state->buf_index = 0; break; |
| 573 | 592 | |
| 574 | 593 | /* 0x83 - SPROFF: set SPRite OFF */ |
| 575 | | case SPROFF: cmd = SPROFF; tsp.spr_on = 0; break; |
| 594 | case SPROFF: state->cmd = SPROFF; state->tsp.spr_on = 0; break; |
| 576 | 595 | |
| 577 | 596 | /* 0x85 - SPRSW: ??? */ |
| 578 | | case SPRSW: cmd = SPRSW; buf_size = 1; buf_index = 0; break; |
| 597 | case SPRSW: state->cmd = SPRSW; state->buf_size = 1; state->buf_index = 0; break; |
| 579 | 598 | |
| 580 | 599 | /* 0x81 - SPROV: set SPRite OVerflow information */ |
| 581 | 600 | /* |
| r9675 | r9676 | |
| 583 | 602 | --x- ---- Sprite Collision flag |
| 584 | 603 | ---x xxxx First sprite that caused Sprite Over event |
| 585 | 604 | */ |
| 586 | | case SPROV: cmd = SPROV; /* TODO: where it returns the info? */ break; |
| 605 | case SPROV: state->cmd = SPROV; /* TODO: where it returns the info? */ break; |
| 587 | 606 | |
| 588 | 607 | /* TODO: 0x89 shouldn't trigger, should be one of the above commands */ |
| 589 | | default: cmd = 0x00; printf("PC=%05x: Unknown IDP %02x cmd set\n",cpu_get_pc(space->cpu),data); break; |
| 608 | default: state->cmd = 0x00; printf("PC=%05x: Unknown IDP %02x cmd set\n",cpu_get_pc(space->cpu),data); break; |
| 590 | 609 | } |
| 591 | 610 | } |
| 592 | 611 | |
| r9675 | r9676 | |
| 601 | 620 | /* TODO: very preliminary, needs something showable first */ |
| 602 | 621 | static void execute_sync_cmd(running_machine *machine) |
| 603 | 622 | { |
| 623 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 604 | 624 | /* |
| 605 | 625 | ???? ???? [0] - unknown |
| 606 | 626 | ???? ???? [1] - unknown |
| r9675 | r9676 | |
| 628 | 648 | //printf("V border end: %d\n",(sync_cmd[0xc])); |
| 629 | 649 | //printf("V blank end: %d\n",(sync_cmd[0xd])); |
| 630 | 650 | |
| 631 | | x_vis_area = buf_ram[4] * 4; |
| 632 | | y_vis_area = (buf_ram[0xa])|((buf_ram[0xb] & 0x40)<<2); |
| 651 | x_vis_area = state->buf_ram[4] * 4; |
| 652 | y_vis_area = (state->buf_ram[0xa])|((state->buf_ram[0xb] & 0x40)<<2); |
| 633 | 653 | |
| 634 | 654 | visarea.min_x = 0; |
| 635 | 655 | visarea.min_y = 0; |
| r9675 | r9676 | |
| 648 | 668 | |
| 649 | 669 | static void execute_dspon_cmd(running_machine *machine) |
| 650 | 670 | { |
| 671 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 651 | 672 | /* |
| 652 | 673 | [0] text table offset (hi word) |
| 653 | 674 | [1] unknown |
| 654 | 675 | [2] unknown |
| 655 | 676 | */ |
| 656 | | tsp.tvram_vreg_offset = buf_ram[0] << 8; |
| 657 | | tsp.disp_on = 1; |
| 677 | state->tsp.tvram_vreg_offset = state->buf_ram[0] << 8; |
| 678 | state->tsp.disp_on = 1; |
| 658 | 679 | } |
| 659 | 680 | |
| 660 | 681 | static void execute_dspdef_cmd(running_machine *machine) |
| 661 | 682 | { |
| 683 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 662 | 684 | /* |
| 663 | 685 | [0] attr offset (lo word) |
| 664 | 686 | [1] attr offset (hi word) |
| r9675 | r9676 | |
| 667 | 689 | [4] hline vertical position |
| 668 | 690 | [5] blink number |
| 669 | 691 | */ |
| 670 | | tsp.attr_offset = buf_ram[0] | buf_ram[1] << 8; |
| 671 | | tsp.pitch = (buf_ram[2] & 0xf0) >> 4; |
| 672 | | tsp.line_height = buf_ram[3] + 1; |
| 673 | | tsp.h_line_pos = buf_ram[4]; |
| 674 | | tsp.blink = (buf_ram[5] & 0xf8) >> 3; |
| 692 | state->tsp.attr_offset = state->buf_ram[0] | state->buf_ram[1] << 8; |
| 693 | state->tsp.pitch = (state->buf_ram[2] & 0xf0) >> 4; |
| 694 | state->tsp.line_height = state->buf_ram[3] + 1; |
| 695 | state->tsp.h_line_pos = state->buf_ram[4]; |
| 696 | state->tsp.blink = (state->buf_ram[5] & 0xf8) >> 3; |
| 675 | 697 | } |
| 676 | 698 | |
| 677 | 699 | static void execute_curdef_cmd(running_machine *machine) |
| 678 | 700 | { |
| 701 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 679 | 702 | /* |
| 680 | 703 | xxxx x--- [0] Sprite Cursor number (sprite RAM entry) |
| 681 | 704 | ---- --x- [0] show cursor bit (actively modifies the spriteram entry) |
| r9675 | r9676 | |
| 683 | 706 | */ |
| 684 | 707 | |
| 685 | 708 | /* TODO: needs basic sprite emulation */ |
| 686 | | tsp.curn = (buf_ram[0] & 0xf8); |
| 687 | | tsp.curn_blink = (buf_ram[0] & 1); |
| 709 | state->tsp.curn = (state->buf_ram[0] & 0xf8); |
| 710 | state->tsp.curn_blink = (state->buf_ram[0] & 1); |
| 688 | 711 | |
| 689 | | tsp_sprite_enable(machine, 0xa0000 + tsp.spr_offset + tsp.curn, (buf_ram[0] & 2) << 8); |
| 712 | tsp_sprite_enable(machine, 0xa0000 + state->tsp.spr_offset + state->tsp.curn, (state->buf_ram[0] & 2) << 8); |
| 690 | 713 | } |
| 691 | 714 | |
| 692 | 715 | static void execute_actscr_cmd(running_machine *machine) |
| 693 | 716 | { |
| 717 | //pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 694 | 718 | /* |
| 695 | 719 | This command assigns a strip where the cursor is located. |
| 696 | 720 | xxxx xxxx [0] strip ID * 32 (???) |
| 697 | 721 | */ |
| 698 | 722 | |
| 699 | 723 | /* TODO: no idea about this command */ |
| 700 | | //printf("ACTSCR: %02x\n",buf_ram[0]); |
| 724 | //printf("ACTSCR: %02x\n",state->buf_ram[0]); |
| 701 | 725 | } |
| 702 | 726 | |
| 703 | 727 | static void execute_curs_cmd(running_machine *machine) |
| 704 | 728 | { |
| 729 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 705 | 730 | /* |
| 706 | 731 | [0] Cursor Position Y (lo word) |
| 707 | 732 | [1] Cursor Position Y (hi word) |
| r9675 | r9676 | |
| 709 | 734 | [3] Cursor Position X (hi word) |
| 710 | 735 | */ |
| 711 | 736 | |
| 712 | | tsp.cur_pos_y = buf_ram[0] | buf_ram[1] << 8; |
| 713 | | tsp.cur_pos_x = buf_ram[2] | buf_ram[3] << 8; |
| 737 | state->tsp.cur_pos_y = state->buf_ram[0] | state->buf_ram[1] << 8; |
| 738 | state->tsp.cur_pos_x = state->buf_ram[2] | state->buf_ram[3] << 8; |
| 714 | 739 | } |
| 715 | 740 | |
| 716 | 741 | static void execute_emul_cmd(running_machine *machine) |
| r9675 | r9676 | |
| 728 | 753 | |
| 729 | 754 | static void execute_spron_cmd(running_machine *machine) |
| 730 | 755 | { |
| 756 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 731 | 757 | /* |
| 732 | 758 | [0] Sprite Table Offset (hi word) |
| 733 | 759 | [1] (unknown / reserved) |
| r9675 | r9676 | |
| 735 | 761 | ---- --x- [2] MG: all sprites are 2x zoomed vertically when 1 |
| 736 | 762 | ---- ---x [2] GR: 1 to enable the group collision detection |
| 737 | 763 | */ |
| 738 | | tsp.spr_offset = buf_ram[0] << 8; |
| 739 | | tsp.spr_on = 1; |
| 740 | | printf("SPR TABLE %02x %02x %02x\n",buf_ram[0],buf_ram[1],buf_ram[2]); |
| 764 | state->tsp.spr_offset = state->buf_ram[0] << 8; |
| 765 | state->tsp.spr_on = 1; |
| 766 | printf("SPR TABLE %02x %02x %02x\n",state->buf_ram[0],state->buf_ram[1],state->buf_ram[2]); |
| 741 | 767 | } |
| 742 | 768 | |
| 743 | 769 | static void execute_sprsw_cmd(running_machine *machine) |
| 744 | 770 | { |
| 771 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 745 | 772 | /* |
| 746 | 773 | Toggle an individual sprite in the sprite ram entry |
| 747 | 774 | [0] xxxx x--- target sprite number |
| 748 | 775 | [0] ---- --x- sprite off/on switch |
| 749 | 776 | */ |
| 750 | 777 | |
| 751 | | tsp_sprite_enable(machine, 0xa0000 + tsp.spr_offset + (buf_ram[0] & 0xf8), (buf_ram[0] & 2) << 8); |
| 778 | tsp_sprite_enable(machine, 0xa0000 + state->tsp.spr_offset + (state->buf_ram[0] & 0xf8), (state->buf_ram[0] & 2) << 8); |
| 752 | 779 | } |
| 753 | 780 | |
| 754 | 781 | static WRITE8_HANDLER( idp_param_w ) |
| 755 | 782 | { |
| 756 | | if(cmd == DSPOFF || cmd == EXIT || cmd == SPROFF || cmd == SPROV) // no param commands |
| 783 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 784 | if(state->cmd == DSPOFF || state->cmd == EXIT || state->cmd == SPROFF || state->cmd == SPROV) // no param commands |
| 757 | 785 | return; |
| 758 | 786 | |
| 759 | | buf_ram[buf_index] = data; |
| 760 | | buf_index++; |
| 787 | state->buf_ram[state->buf_index] = data; |
| 788 | state->buf_index++; |
| 761 | 789 | |
| 762 | | if(buf_index >= buf_size) |
| 790 | if(state->buf_index >= state->buf_size) |
| 763 | 791 | { |
| 764 | | buf_index = 0; |
| 765 | | switch(cmd) |
| 792 | state->buf_index = 0; |
| 793 | switch(state->cmd) |
| 766 | 794 | { |
| 767 | 795 | case SYNC: execute_sync_cmd(space->machine); break; |
| 768 | 796 | case DSPON: execute_dspon_cmd(space->machine); break; |
| r9675 | r9676 | |
| 783 | 811 | |
| 784 | 812 | static WRITE16_HANDLER( palette_ram_w ) |
| 785 | 813 | { |
| 814 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 786 | 815 | int r,g,b; |
| 787 | | COMBINE_DATA(&palram[offset]); |
| 816 | COMBINE_DATA(&state->palram[offset]); |
| 788 | 817 | |
| 789 | | b = (palram[offset] & 0x001e) >> 1; |
| 790 | | r = (palram[offset] & 0x03c0) >> 6; |
| 791 | | g = (palram[offset] & 0x7800) >> 11; |
| 818 | b = (state->palram[offset] & 0x001e) >> 1; |
| 819 | r = (state->palram[offset] & 0x03c0) >> 6; |
| 820 | g = (state->palram[offset] & 0x7800) >> 11; |
| 792 | 821 | |
| 793 | 822 | palette_set_color_rgb(space->machine,offset,pal4bit(r),pal4bit(g),pal4bit(b)); |
| 794 | 823 | } |
| r9675 | r9676 | |
| 805 | 834 | |
| 806 | 835 | static READ16_HANDLER( bios_bank_r ) |
| 807 | 836 | { |
| 808 | | return bank_reg; |
| 837 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 838 | return state->bank_reg; |
| 809 | 839 | } |
| 810 | 840 | |
| 811 | 841 | static WRITE16_HANDLER( bios_bank_w ) |
| 812 | 842 | { |
| 843 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 813 | 844 | /* |
| 814 | 845 | -x-- ---- ---- ---- SMM (compatibility mode) |
| 815 | 846 | ---x ---- ---- ---- GMSP (VRAM drawing Mode) |
| r9675 | r9676 | |
| 818 | 849 | ---- ---- ---- xxxx RBC0 (0xe0000 - 0xeffff ROM bank) |
| 819 | 850 | */ |
| 820 | 851 | if ((mem_mask&0xffff) == 0xffff) |
| 821 | | bank_reg = data; |
| 852 | state->bank_reg = data; |
| 822 | 853 | else if ((mem_mask & 0xffff) == 0xff00) |
| 823 | | bank_reg = (data & 0xff00) | (bank_reg & 0x00ff); |
| 854 | state->bank_reg = (data & 0xff00) | (state->bank_reg & 0x00ff); |
| 824 | 855 | else if ((mem_mask & 0xffff) == 0x00ff) |
| 825 | | bank_reg = (data & 0x00ff) | (bank_reg & 0xff00); |
| 856 | state->bank_reg = (data & 0x00ff) | (state->bank_reg & 0xff00); |
| 826 | 857 | |
| 827 | 858 | |
| 828 | 859 | /* RBC1 */ |
| 829 | 860 | { |
| 830 | 861 | UINT8 *ROM10 = memory_region(space->machine, "rom10"); |
| 831 | 862 | |
| 832 | | if((bank_reg & 0xe0) == 0x00) |
| 833 | | memory_set_bankptr(space->machine, "rom10_bank", &ROM10[(bank_reg & 0x10) ? 0x10000 : 0x00000]); |
| 863 | if((state->bank_reg & 0xe0) == 0x00) |
| 864 | memory_set_bankptr(space->machine, "rom10_bank", &ROM10[(state->bank_reg & 0x10) ? 0x10000 : 0x00000]); |
| 834 | 865 | } |
| 835 | 866 | |
| 836 | 867 | /* RBC0 */ |
| 837 | 868 | { |
| 838 | 869 | UINT8 *ROM00 = memory_region(space->machine, "rom00"); |
| 839 | 870 | |
| 840 | | memory_set_bankptr(space->machine, "rom00_bank", &ROM00[(bank_reg & 0xf)*0x10000]); // TODO: docs says that only 0 - 5 are used, dunno why ... |
| 871 | memory_set_bankptr(space->machine, "rom00_bank", &ROM00[(state->bank_reg & 0xf)*0x10000]); // TODO: docs says that only 0 - 5 are used, dunno why ... |
| 841 | 872 | } |
| 842 | 873 | } |
| 843 | 874 | |
| r9675 | r9676 | |
| 859 | 890 | |
| 860 | 891 | static WRITE16_HANDLER( backupram_wp_1_w ) |
| 861 | 892 | { |
| 862 | | backupram_wp = 1; |
| 893 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 894 | state->backupram_wp = 1; |
| 863 | 895 | } |
| 864 | 896 | |
| 865 | 897 | static WRITE16_HANDLER( backupram_wp_0_w ) |
| 866 | 898 | { |
| 867 | | backupram_wp = 0; |
| 899 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 900 | state->backupram_wp = 0; |
| 868 | 901 | } |
| 869 | 902 | |
| 870 | 903 | static READ8_HANDLER( hdd_status_r ) |
| r9675 | r9676 | |
| 938 | 971 | |
| 939 | 972 | static READ16_HANDLER( screen_ctrl_r ) |
| 940 | 973 | { |
| 941 | | return screen_ctrl_reg; |
| 974 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 975 | return state->screen_ctrl_reg; |
| 942 | 976 | } |
| 943 | 977 | |
| 944 | 978 | static WRITE16_HANDLER( screen_ctrl_w ) |
| 945 | 979 | { |
| 946 | | screen_ctrl_reg = data; |
| 980 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 981 | state->screen_ctrl_reg = data; |
| 947 | 982 | } |
| 948 | 983 | |
| 949 | 984 | static TIMER_CALLBACK( t3_mouse_callback ) |
| 950 | 985 | { |
| 951 | | if(timer3_io_reg & 0x80) |
| 986 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 987 | if(state->timer3_io_reg & 0x80) |
| 952 | 988 | { |
| 953 | 989 | pic8259_ir5_w(machine->device("pic8259_slave"), 1); |
| 954 | | timer_adjust_oneshot(t3_mouse_timer, ATTOTIME_IN_HZ(120 >> (timer3_io_reg & 3)), 0); |
| 990 | timer_adjust_oneshot(state->t3_mouse_timer, ATTOTIME_IN_HZ(120 >> (state->timer3_io_reg & 3)), 0); |
| 955 | 991 | } |
| 956 | 992 | } |
| 957 | 993 | |
| 958 | 994 | static WRITE8_HANDLER( timer3_ctrl_reg_w ) |
| 959 | 995 | { |
| 996 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 960 | 997 | /* |
| 961 | 998 | x--- ---- MINTEN (TCU irq enable) |
| 962 | 999 | ---- --xx general purpose timer 3 interval (120, 60, 30, 15) |
| 963 | 1000 | */ |
| 964 | | timer3_io_reg = data; |
| 1001 | state->timer3_io_reg = data; |
| 965 | 1002 | |
| 966 | 1003 | if(data & 0x80) |
| 967 | | timer_adjust_oneshot(t3_mouse_timer, ATTOTIME_IN_HZ(120 >> (timer3_io_reg & 3)), 0); |
| 1004 | timer_adjust_oneshot(state->t3_mouse_timer, ATTOTIME_IN_HZ(120 >> (state->timer3_io_reg & 3)), 0); |
| 968 | 1005 | else |
| 969 | 1006 | { |
| 970 | 1007 | pic8259_ir5_w(space->machine->device("pic8259_slave"), 0); |
| 971 | | timer_adjust_oneshot(t3_mouse_timer, attotime_never, 0); |
| 1008 | timer_adjust_oneshot(state->t3_mouse_timer, attotime_never, 0); |
| 972 | 1009 | } |
| 973 | 1010 | } |
| 974 | 1011 | |
| 975 | 1012 | static WRITE16_HANDLER( video_pri_w ) |
| 976 | 1013 | { |
| 977 | | COMBINE_DATA(&video_pri_reg[offset]); |
| 1014 | pc88va_state *state = space->machine->driver_data<pc88va_state>(); |
| 1015 | COMBINE_DATA(&state->video_pri_reg[offset]); |
| 978 | 1016 | } |
| 979 | 1017 | |
| 980 | 1018 | static READ8_HANDLER( backupram_dsw_r ) |
| r9675 | r9676 | |
| 1056 | 1094 | AM_RANGE(0x0220, 0x023f) AM_RAM // Frame buffer 1 control parameter |
| 1057 | 1095 | AM_RANGE(0x0240, 0x025f) AM_RAM // Frame buffer 2 control parameter |
| 1058 | 1096 | AM_RANGE(0x0260, 0x027f) AM_RAM // Frame buffer 3 control parameter |
| 1059 | | AM_RANGE(0x0300, 0x033f) AM_RAM_WRITE(palette_ram_w) AM_BASE(&palram) // Palette RAM (xBBBBxRRRRxGGGG format) |
| 1097 | AM_RANGE(0x0300, 0x033f) AM_RAM_WRITE(palette_ram_w) AM_BASE_MEMBER(pc88va_state, palram) // Palette RAM (xBBBBxRRRRxGGGG format) |
| 1060 | 1098 | |
| 1061 | 1099 | // AM_RANGE(0x0500, 0x05ff) GVRAM |
| 1062 | 1100 | // AM_RANGE(0x1000, 0xfeff) user area (???) |
| r9675 | r9676 | |
| 1314 | 1352 | |
| 1315 | 1353 | static READ8_DEVICE_HANDLER( fdd_portc_r ) |
| 1316 | 1354 | { |
| 1317 | | static UINT8 test1,test2; |
| 1355 | pc88va_state *state = device->machine->driver_data<pc88va_state>(); |
| 1356 | state->portc_test^=5; |
| 1318 | 1357 | |
| 1319 | | test1^=4; |
| 1320 | | test2^=1; |
| 1321 | | |
| 1322 | | return 0xff ^ test1 ^ test2; |
| 1358 | return 0xff ^ state->portc_test; |
| 1323 | 1359 | } |
| 1324 | 1360 | |
| 1325 | 1361 | static WRITE8_DEVICE_HANDLER( fdd_porta_w ) |
| r9675 | r9676 | |
| 1428 | 1464 | |
| 1429 | 1465 | static MACHINE_START( pc88va ) |
| 1430 | 1466 | { |
| 1467 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 1431 | 1468 | cpu_set_irq_callback(machine->device("maincpu"), pc88va_irq_callback); |
| 1432 | 1469 | |
| 1433 | | t3_mouse_timer = timer_alloc(machine, t3_mouse_callback, 0); |
| 1434 | | timer_adjust_oneshot(t3_mouse_timer, attotime_never, 0); |
| 1470 | state->t3_mouse_timer = timer_alloc(machine, t3_mouse_callback, 0); |
| 1471 | timer_adjust_oneshot(state->t3_mouse_timer, attotime_never, 0); |
| 1435 | 1472 | } |
| 1436 | 1473 | |
| 1437 | 1474 | static MACHINE_RESET( pc88va ) |
| 1438 | 1475 | { |
| 1476 | pc88va_state *state = machine->driver_data<pc88va_state>(); |
| 1439 | 1477 | UINT8 *ROM00 = memory_region(machine, "rom00"); |
| 1440 | 1478 | UINT8 *ROM10 = memory_region(machine, "rom10"); |
| 1441 | 1479 | |
| 1442 | 1480 | memory_set_bankptr(machine, "rom10_bank", &ROM10[0x00000]); |
| 1443 | 1481 | memory_set_bankptr(machine, "rom00_bank", &ROM00[0x00000]); |
| 1444 | 1482 | |
| 1445 | | bank_reg = 0x4100; |
| 1446 | | backupram_wp = 1; |
| 1483 | state->bank_reg = 0x4100; |
| 1484 | state->backupram_wp = 1; |
| 1447 | 1485 | |
| 1448 | 1486 | /* default palette */ |
| 1449 | 1487 | { |
| r9675 | r9676 | |
| 1452 | 1490 | palette_set_color_rgb(machine,i,pal1bit((i & 2) >> 1),pal1bit((i & 4) >> 2),pal1bit(i & 1)); |
| 1453 | 1491 | } |
| 1454 | 1492 | |
| 1455 | | tsp.tvram_vreg_offset = 0; |
| 1493 | state->tsp.tvram_vreg_offset = 0; |
| 1456 | 1494 | } |
| 1457 | 1495 | |
| 1458 | 1496 | static INTERRUPT_GEN( pc88va_vrtc_irq ) |
| r9675 | r9676 | |
| 1532 | 1570 | NULL |
| 1533 | 1571 | }; |
| 1534 | 1572 | |
| 1535 | | static MACHINE_CONFIG_START( pc88va, driver_device ) |
| 1573 | static MACHINE_CONFIG_START( pc88va, pc88va_state ) |
| 1536 | 1574 | |
| 1537 | 1575 | MDRV_CPU_ADD("maincpu", V30, 8000000) /* 8 MHz */ |
| 1538 | 1576 | MDRV_CPU_PROGRAM_MAP(pc88va_map) |
src/mess/drivers/pc98.c
| r9675 | r9676 | |
| 231 | 231 | #include "machine/8237dma.h" |
| 232 | 232 | #include "machine/pic8259.h" |
| 233 | 233 | |
| 234 | | static UINT32 *pc9801_vram; |
| 235 | | static UINT32 *gfx_bitmap_ram; |
| 236 | | static UINT32 *work_ram_banked; |
| 237 | | static UINT8 ems_bank; |
| 238 | | static UINT8 wram_bank; |
| 239 | 234 | |
| 235 | class pc98_state : public driver_device |
| 236 | { |
| 237 | public: |
| 238 | pc98_state(running_machine &machine, const driver_device_config_base &config) |
| 239 | : driver_device(machine, config) { } |
| 240 | 240 | |
| 241 | UINT32 *pc9801_vram; |
| 242 | UINT32 *gfx_bitmap_ram; |
| 243 | UINT32 *work_ram_banked; |
| 244 | UINT8 ems_bank; |
| 245 | UINT8 wram_bank; |
| 246 | UINT8 rom_bank; |
| 247 | UINT8 gate_a20; |
| 248 | UINT8 wram_latch_reg; |
| 249 | UINT8 portb_tmp; |
| 250 | int dma_channel; |
| 251 | UINT8 dma_offset[2][4]; |
| 252 | UINT8 at_pages[0x10]; |
| 253 | }; |
| 254 | |
| 255 | |
| 256 | |
| 241 | 257 | static VIDEO_START( pc9801 ) |
| 242 | 258 | { |
| 243 | | gfx_bitmap_ram = auto_alloc_array(machine, UINT32, 0x18000*2); |
| 244 | | work_ram_banked = auto_alloc_array(machine, UINT32, 0x2000*0xfe); //shouldn't be here |
| 259 | pc98_state *state = machine->driver_data<pc98_state>(); |
| 260 | state->gfx_bitmap_ram = auto_alloc_array(machine, UINT32, 0x18000*2); |
| 261 | state->work_ram_banked = auto_alloc_array(machine, UINT32, 0x2000*0xfe); //shouldn't be here |
| 245 | 262 | } |
| 246 | 263 | |
| 247 | 264 | /* |
| r9675 | r9676 | |
| 256 | 273 | |
| 257 | 274 | static VIDEO_UPDATE( pc9801 ) |
| 258 | 275 | { |
| 276 | pc98_state *state = screen->machine->driver_data<pc98_state>(); |
| 259 | 277 | // const gfx_element *gfx = screen->machine->gfx[0]; |
| 260 | 278 | int y,x; |
| 261 | 279 | int yi,xi; |
| r9675 | r9676 | |
| 271 | 289 | { |
| 272 | 290 | int tile,attr,pen[3],pen_mask,color; |
| 273 | 291 | |
| 274 | | tile = (pc9801_vram[(x+y*40)] & 0x00ff0000) >> 16; |
| 275 | | attr = (pc9801_vram[((x+y*40)+0x2000/4)] & 0x00ff0000) >> 16; |
| 292 | tile = (state->pc9801_vram[(x+y*40)] & 0x00ff0000) >> 16; |
| 293 | attr = (state->pc9801_vram[((x+y*40)+0x2000/4)] & 0x00ff0000) >> 16; |
| 276 | 294 | |
| 277 | 295 | pen_mask = (attr & 0xe0)>>5; |
| 278 | 296 | |
| r9675 | r9676 | |
| 288 | 306 | if(((x*2+1)*8+xi)<screen->machine->primary_screen->visible_area().max_x && (y*8+yi)<screen->machine->primary_screen->visible_area().max_y) |
| 289 | 307 | *BITMAP_ADDR16(bitmap, y*8+yi, (x*2+1)*8+xi) = screen->machine->pens[color]; |
| 290 | 308 | |
| 291 | | tile = (pc9801_vram[(x+y*40)] & 0x000000ff) >> 0; |
| 292 | | attr = (pc9801_vram[((x+y*40)+0x2000/4)] & 0x000000ff) >> 0; |
| 309 | tile = (state->pc9801_vram[(x+y*40)] & 0x000000ff) >> 0; |
| 310 | attr = (state->pc9801_vram[((x+y*40)+0x2000/4)] & 0x000000ff) >> 0; |
| 293 | 311 | |
| 294 | 312 | pen_mask = (attr & 0xe0)>>5; |
| 295 | 313 | |
| r9675 | r9676 | |
| 427 | 445 | crtc_cmd_w(space,0,data); |
| 428 | 446 | } |
| 429 | 447 | |
| 430 | | static UINT8 rom_bank; |
| 431 | 448 | |
| 432 | 449 | static WRITE8_HANDLER( ems_sel_w ) |
| 433 | 450 | { |
| 451 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 434 | 452 | // printf("%02x %02x\n",offset,data); |
| 435 | 453 | |
| 436 | 454 | if(offset == 1) |
| r9675 | r9676 | |
| 439 | 457 | |
| 440 | 458 | if(data == 0x00 || data == 0x10) |
| 441 | 459 | { |
| 442 | | rom_bank = 1; |
| 460 | state->rom_bank = 1; |
| 443 | 461 | memory_set_bankptr(space->machine, "bank1", &ROM[0x20000]); |
| 444 | 462 | } |
| 445 | 463 | |
| 446 | 464 | if(data == 0x02 || data == 0x12) |
| 447 | 465 | { |
| 448 | | rom_bank = 0; |
| 466 | state->rom_bank = 0; |
| 449 | 467 | memory_set_bankptr(space->machine, "bank1", &ROM[0x00000]); |
| 450 | 468 | } |
| 451 | 469 | } |
| r9675 | r9676 | |
| 453 | 471 | if(offset == 3) |
| 454 | 472 | { |
| 455 | 473 | if(data == 0x22) |
| 456 | | ems_bank = 1; |
| 474 | state->ems_bank = 1; |
| 457 | 475 | if(data == 0x20) |
| 458 | | ems_bank = 0; |
| 476 | state->ems_bank = 0; |
| 459 | 477 | //printf("%02x %02x\n",offset,data); |
| 460 | 478 | } |
| 461 | 479 | } |
| 462 | 480 | |
| 463 | 481 | static WRITE8_HANDLER( rom_bank_w ) |
| 464 | 482 | { |
| 483 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 465 | 484 | UINT8 *ROM = memory_region(space->machine, "cpudata"); |
| 466 | 485 | |
| 467 | | // printf("%08x %04x %08x\n",ROM[offset+(rom_bank*0x20000/4)],offset+(rom_bank*0x20000/4),data); |
| 486 | // printf("%08x %04x %08x\n",ROM[offset+(state->rom_bank*0x20000/4)],offset+(state->rom_bank*0x20000/4),data); |
| 468 | 487 | |
| 469 | 488 | /* NOP any attempt to write on ROM (TODO: why it's overwriting here anyway? Doesn't make sense...) */ |
| 470 | | if((rom_bank == 0 && offset < 0x8000) || (rom_bank == 1 && offset < 0x18000)) |
| 471 | | ROM[offset+(rom_bank*0x20000)] = data; |
| 489 | if((state->rom_bank == 0 && offset < 0x8000) || (state->rom_bank == 1 && offset < 0x18000)) |
| 490 | ROM[offset+(state->rom_bank*0x20000)] = data; |
| 472 | 491 | } |
| 473 | 492 | |
| 474 | 493 | static READ8_HANDLER( port_70_r ) |
| r9675 | r9676 | |
| 520 | 539 | } |
| 521 | 540 | } |
| 522 | 541 | |
| 523 | | static UINT8 gate_a20; |
| 524 | 542 | |
| 525 | 543 | static READ8_HANDLER( port_f0_r ) |
| 526 | 544 | { |
| 545 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 527 | 546 | if(offset == 0x02) |
| 528 | | return (gate_a20 ^ 1) | 0x2e; |
| 547 | return (state->gate_a20 ^ 1) | 0x2e; |
| 529 | 548 | else if(offset == 0x06) |
| 530 | | return (gate_a20 ^ 1) | 0x5e; |
| 549 | return (state->gate_a20 ^ 1) | 0x5e; |
| 531 | 550 | |
| 532 | 551 | return 0x00; |
| 533 | 552 | } |
| 534 | 553 | |
| 535 | 554 | static WRITE8_HANDLER( port_f0_w ) |
| 536 | 555 | { |
| 556 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 537 | 557 | if(offset == 0x00) |
| 538 | 558 | { |
| 539 | 559 | //cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE); |
| r9675 | r9676 | |
| 541 | 561 | |
| 542 | 562 | if(offset == 0x02) |
| 543 | 563 | { |
| 544 | | gate_a20 = 1; |
| 545 | | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, gate_a20); |
| 564 | state->gate_a20 = 1; |
| 565 | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, state->gate_a20); |
| 546 | 566 | } |
| 547 | 567 | if(offset == 0x06) |
| 548 | 568 | { |
| 549 | 569 | if(data == 0x02) |
| 550 | 570 | { |
| 551 | | gate_a20 = 1; |
| 552 | | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, gate_a20); |
| 571 | state->gate_a20 = 1; |
| 572 | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, state->gate_a20); |
| 553 | 573 | } |
| 554 | 574 | else if(data == 0x03) |
| 555 | 575 | { |
| 556 | | gate_a20 = 0; |
| 557 | | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, gate_a20); |
| 576 | state->gate_a20 = 0; |
| 577 | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_A20, state->gate_a20); |
| 558 | 578 | } |
| 559 | 579 | } |
| 560 | 580 | } |
| 561 | 581 | |
| 562 | | static UINT8 wram_latch_reg; |
| 563 | 582 | |
| 564 | 583 | static READ8_HANDLER( wram_sel_r ) |
| 565 | 584 | { |
| 566 | | return (wram_bank << 1) | wram_latch_reg; |
| 585 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 586 | return (state->wram_bank << 1) | state->wram_latch_reg; |
| 567 | 587 | } |
| 568 | 588 | |
| 569 | 589 | static WRITE8_HANDLER( wram_sel_w ) |
| 570 | 590 | { |
| 571 | | wram_bank = (data & 0xfe) >> 1; |
| 572 | | wram_latch_reg = data & 1; //<- correct? |
| 573 | | //printf("%02x\n",wram_bank); |
| 591 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 592 | state->wram_bank = (data & 0xfe) >> 1; |
| 593 | state->wram_latch_reg = data & 1; //<- correct? |
| 594 | //printf("%02x\n",state->wram_bank); |
| 574 | 595 | } |
| 575 | 596 | |
| 576 | 597 | static READ8_HANDLER( pc98_mouse_r ) |
| r9675 | r9676 | |
| 582 | 603 | return 0xff; |
| 583 | 604 | } |
| 584 | 605 | |
| 585 | | static READ32_HANDLER( gfx_bitmap_ram_r ) { return gfx_bitmap_ram[offset+ems_bank*0x18000/4]; } |
| 586 | | static WRITE32_HANDLER( gfx_bitmap_ram_w ) { COMBINE_DATA(&gfx_bitmap_ram[offset+ems_bank*0x18000/4]); } |
| 606 | static READ32_HANDLER( gfx_bitmap_ram_r ) |
| 607 | { |
| 608 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 609 | return state->gfx_bitmap_ram[offset+state->ems_bank*0x18000/4]; |
| 610 | } |
| 587 | 611 | |
| 588 | | static READ32_HANDLER( wram_bank_r ) { return work_ram_banked[offset+wram_bank*0x2000/4]; } |
| 589 | | static WRITE32_HANDLER( wram_bank_w ) { COMBINE_DATA(&work_ram_banked[offset+wram_bank*0x2000/4]); } |
| 612 | static WRITE32_HANDLER( gfx_bitmap_ram_w ) |
| 613 | { |
| 614 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 615 | COMBINE_DATA(&state->gfx_bitmap_ram[offset+state->ems_bank*0x18000/4]); |
| 616 | } |
| 590 | 617 | |
| 591 | | static READ32_HANDLER( wram_ide_r ) { return work_ram_banked[offset+4*0x2000/4]; } //todo: ide hookup & calculate the correct bank number here |
| 592 | | static WRITE32_HANDLER( wram_ide_w ) { COMBINE_DATA(&work_ram_banked[offset+4*0x2000/4]); } |
| 618 | static READ32_HANDLER( wram_bank_r ) |
| 619 | { |
| 620 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 621 | return state->work_ram_banked[offset+state->wram_bank*0x2000/4]; |
| 622 | } |
| 593 | 623 | |
| 624 | static WRITE32_HANDLER( wram_bank_w ) |
| 625 | { |
| 626 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 627 | COMBINE_DATA(&state->work_ram_banked[offset+state->wram_bank*0x2000/4]); |
| 628 | } |
| 629 | |
| 630 | static READ32_HANDLER( wram_ide_r ) //todo: ide hookup & calculate the correct bank number here |
| 631 | { |
| 632 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 633 | return state->work_ram_banked[offset+4*0x2000/4]; |
| 634 | } |
| 635 | |
| 636 | static WRITE32_HANDLER( wram_ide_w ) |
| 637 | { |
| 638 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 639 | COMBINE_DATA(&state->work_ram_banked[offset+4*0x2000/4]); |
| 640 | } |
| 641 | |
| 594 | 642 | static ADDRESS_MAP_START( pc9801_mem, ADDRESS_SPACE_PROGRAM, 32) |
| 595 | 643 | AM_RANGE(0x00000000, 0x0007ffff) AM_RAM |
| 596 | 644 | AM_RANGE(0x00080000, 0x0009ffff) AM_READWRITE(wram_bank_r,wram_bank_w) |
| 597 | | AM_RANGE(0x000a0000, 0x000a3fff) AM_RAM AM_BASE(&pc9801_vram) //vram + attr |
| 645 | AM_RANGE(0x000a0000, 0x000a3fff) AM_RAM AM_BASE_MEMBER(pc98_state, pc9801_vram) //vram + attr |
| 598 | 646 | AM_RANGE(0x000a4000, 0x000a4fff) AM_RAM //cg window |
| 599 | 647 | AM_RANGE(0x000a5000, 0x000a7fff) AM_RAM //??? (presumably another work ram bank) |
| 600 | 648 | AM_RANGE(0x000a8000, 0x000bffff) AM_READWRITE(gfx_bitmap_ram_r,gfx_bitmap_ram_w) |
| r9675 | r9676 | |
| 687 | 735 | #include "cpu/i386/i386priv.h" |
| 688 | 736 | |
| 689 | 737 | |
| 738 | |
| 690 | 739 | static MACHINE_RESET(pc9801) |
| 691 | 740 | { |
| 741 | pc98_state *state = machine->driver_data<pc98_state>(); |
| 692 | 742 | UINT8 *ROM = memory_region(machine, "cpudata"); |
| 693 | 743 | |
| 694 | 744 | cpu_set_irq_callback(machine->device("maincpu"), irq_callback); |
| 695 | 745 | |
| 696 | 746 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_A20, 0); |
| 697 | 747 | |
| 698 | | gate_a20 = 0; |
| 748 | state->gate_a20 = 0; |
| 699 | 749 | cpu_set_reg(machine->device("maincpu"), I386_EIP, 0xffff0+0x10000); |
| 700 | 750 | |
| 701 | 751 | memory_set_bankptr(machine, "bank1", &ROM[0x20000]); |
| 702 | 752 | |
| 703 | | wram_bank = 0; |
| 704 | | rom_bank = 1; |
| 753 | state->wram_bank = 0; |
| 754 | state->rom_bank = 1; |
| 705 | 755 | } |
| 706 | 756 | |
| 707 | 757 | /************************************************************* |
| r9675 | r9676 | |
| 765 | 815 | |
| 766 | 816 | static READ8_DEVICE_HANDLER( pc98_portb_r ) |
| 767 | 817 | { |
| 768 | | static UINT8 tmp; |
| 769 | | |
| 770 | | tmp ^= 1; //<- actually related to the RTC somehow |
| 818 | pc98_state *state = device->machine->driver_data<pc98_state>(); |
| 819 | state->portb_tmp ^= 1; //<- actually related to the RTC somehow |
| 771 | 820 | //printf("PPI Port B read\n"); |
| 772 | | return 0xf8 | tmp; //bit 2 seems used for error stuff (returns parity error or ems error on different spots), don't know the real use of it... |
| 821 | return 0xf8 | state->portb_tmp; //bit 2 seems used for error stuff (returns parity error or ems error on different spots), don't know the real use of it... |
| 773 | 822 | } |
| 774 | 823 | |
| 775 | 824 | static READ8_DEVICE_HANDLER( pc98_portc_r ) |
| r9675 | r9676 | |
| 860 | 909 | palette_set_color_rgb(machine, i+0x000, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0)); |
| 861 | 910 | } |
| 862 | 911 | |
| 863 | | static int dma_channel; |
| 864 | | static UINT8 dma_offset[2][4]; |
| 865 | 912 | |
| 866 | 913 | #if 0 |
| 867 | | static UINT8 at_pages[0x10]; |
| 868 | 914 | |
| 869 | 915 | |
| 870 | 916 | static READ8_HANDLER(at_page8_r) |
| 871 | 917 | { |
| 872 | | UINT8 data = at_pages[offset % 0x10]; |
| 918 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 919 | UINT8 data = state->at_pages[offset % 0x10]; |
| 873 | 920 | |
| 874 | 921 | switch(offset % 8) { |
| 875 | 922 | case 1: |
| 876 | | data = dma_offset[(offset / 8) & 1][2]; |
| 923 | data = state->dma_offset[(offset / 8) & 1][2]; |
| 877 | 924 | break; |
| 878 | 925 | case 2: |
| 879 | | data = dma_offset[(offset / 8) & 1][3]; |
| 926 | data = state->dma_offset[(offset / 8) & 1][3]; |
| 880 | 927 | break; |
| 881 | 928 | case 3: |
| 882 | | data = dma_offset[(offset / 8) & 1][1]; |
| 929 | data = state->dma_offset[(offset / 8) & 1][1]; |
| 883 | 930 | break; |
| 884 | 931 | case 7: |
| 885 | | data = dma_offset[(offset / 8) & 1][0]; |
| 932 | data = state->dma_offset[(offset / 8) & 1][0]; |
| 886 | 933 | break; |
| 887 | 934 | } |
| 888 | 935 | return data; |
| r9675 | r9676 | |
| 891 | 938 | |
| 892 | 939 | static WRITE8_HANDLER(at_page8_w) |
| 893 | 940 | { |
| 894 | | at_pages[offset % 0x10] = data; |
| 941 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 942 | state->at_pages[offset % 0x10] = data; |
| 895 | 943 | |
| 896 | 944 | switch(offset % 8) { |
| 897 | 945 | case 1: |
| 898 | | dma_offset[(offset / 8) & 1][2] = data; |
| 946 | state->dma_offset[(offset / 8) & 1][2] = data; |
| 899 | 947 | break; |
| 900 | 948 | case 2: |
| 901 | | dma_offset[(offset / 8) & 1][3] = data; |
| 949 | state->dma_offset[(offset / 8) & 1][3] = data; |
| 902 | 950 | break; |
| 903 | 951 | case 3: |
| 904 | | dma_offset[(offset / 8) & 1][1] = data; |
| 952 | state->dma_offset[(offset / 8) & 1][1] = data; |
| 905 | 953 | break; |
| 906 | 954 | case 7: |
| 907 | | dma_offset[(offset / 8) & 1][0] = data; |
| 955 | state->dma_offset[(offset / 8) & 1][0] = data; |
| 908 | 956 | break; |
| 909 | 957 | } |
| 910 | 958 | } |
| r9675 | r9676 | |
| 921 | 969 | |
| 922 | 970 | static READ8_HANDLER( pc_dma_read_byte ) |
| 923 | 971 | { |
| 924 | | offs_t page_offset = (((offs_t) dma_offset[0][dma_channel]) << 16) |
| 972 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 973 | offs_t page_offset = (((offs_t) state->dma_offset[0][state->dma_channel]) << 16) |
| 925 | 974 | & 0xFF0000; |
| 926 | 975 | |
| 927 | 976 | return space->read_byte(page_offset + offset); |
| r9675 | r9676 | |
| 930 | 979 | |
| 931 | 980 | static WRITE8_HANDLER( pc_dma_write_byte ) |
| 932 | 981 | { |
| 933 | | offs_t page_offset = (((offs_t) dma_offset[0][dma_channel]) << 16) |
| 982 | pc98_state *state = space->machine->driver_data<pc98_state>(); |
| 983 | offs_t page_offset = (((offs_t) state->dma_offset[0][state->dma_channel]) << 16) |
| 934 | 984 | & 0xFF0000; |
| 935 | 985 | |
| 936 | 986 | space->write_byte(page_offset + offset, data); |
| r9675 | r9676 | |
| 938 | 988 | |
| 939 | 989 | static void set_dma_channel(running_device *device, int channel, int state) |
| 940 | 990 | { |
| 941 | | if (!state) dma_channel = channel; |
| 991 | pc98_state *drvstate = device->machine->driver_data<pc98_state>(); |
| 992 | if (!state) drvstate->dma_channel = channel; |
| 942 | 993 | } |
| 943 | 994 | |
| 944 | 995 | static WRITE_LINE_DEVICE_HANDLER( pc_dack0_w ) { set_dma_channel(device, 0, state); } |
| r9675 | r9676 | |
| 959 | 1010 | |
| 960 | 1011 | /* I suspect the dump for pc9801 comes from a i386 later model... the original machine would use a i8086 @ 5Mhz CPU (see notes at top) */ |
| 961 | 1012 | /* More investigations are required, but in the meanwhile I set a I386 as main CPU */ |
| 962 | | static MACHINE_CONFIG_START( pc9801, driver_device ) |
| 1013 | static MACHINE_CONFIG_START( pc9801, pc98_state ) |
| 963 | 1014 | /* basic machine hardware */ |
| 964 | 1015 | MDRV_CPU_ADD("maincpu", I386, 16000000) |
| 965 | 1016 | MDRV_CPU_PROGRAM_MAP(pc9801_mem) |
src/mess/drivers/pcw16.c
| r9675 | r9676 | |
| 107 | 107 | #include "devices/messram.h" |
| 108 | 108 | |
| 109 | 109 | // interrupt counter |
| 110 | | static unsigned long pcw16_interrupt_counter; |
| 111 | 110 | /* controls which bank of 2mb address space is paged into memory */ |
| 112 | | static int pcw16_banks[4]; |
| 113 | 111 | |
| 114 | 112 | // output of 4-bit port from Anne ASIC |
| 115 | | static int pcw16_4_bit_port; |
| 116 | 113 | // code defining which INT fdc is connected to |
| 117 | | static int pcw16_fdc_int_code; |
| 118 | 114 | // interrupt bits |
| 119 | 115 | // bit 7: ?? |
| 120 | 116 | // bit 6: fdc |
| r9675 | r9676 | |
| 123 | 119 | // bit 2: Vsync state |
| 124 | 120 | // bit 1: keyboard int |
| 125 | 121 | // bit 0: Display ints |
| 126 | | static int pcw16_system_status; |
| 127 | 122 | |
| 128 | 123 | // debugging - write ram as seen by cpu |
| 129 | 124 | static void pcw16_refresh_ints(running_machine *machine) |
| 130 | 125 | { |
| 126 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 131 | 127 | /* any bits set excluding vsync */ |
| 132 | | if ((pcw16_system_status & (~0x04))!=0) |
| 128 | if ((state->system_status & (~0x04))!=0) |
| 133 | 129 | { |
| 134 | 130 | cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE); |
| 135 | 131 | } |
| r9675 | r9676 | |
| 142 | 138 | |
| 143 | 139 | static TIMER_CALLBACK(pcw16_timer_callback) |
| 144 | 140 | { |
| 141 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 145 | 142 | /* do not increment past 15 */ |
| 146 | | if (pcw16_interrupt_counter!=15) |
| 143 | if (state->interrupt_counter!=15) |
| 147 | 144 | { |
| 148 | | pcw16_interrupt_counter++; |
| 145 | state->interrupt_counter++; |
| 149 | 146 | /* display int */ |
| 150 | | pcw16_system_status |= (1<<0); |
| 147 | state->system_status |= (1<<0); |
| 151 | 148 | } |
| 152 | 149 | |
| 153 | | if (pcw16_interrupt_counter!=0) |
| 150 | if (state->interrupt_counter!=0) |
| 154 | 151 | { |
| 155 | 152 | pcw16_refresh_ints(machine); |
| 156 | 153 | } |
| r9675 | r9676 | |
| 166 | 163 | |
| 167 | 164 | static WRITE8_HANDLER(pcw16_palette_w) |
| 168 | 165 | { |
| 169 | | pcw16_colour_palette[offset & 0x0f] = data & 31; |
| 166 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 167 | state->colour_palette[offset & 0x0f] = data & 31; |
| 170 | 168 | } |
| 171 | 169 | |
| 172 | | static char *pcw16_mem_ptr[4]; |
| 173 | 170 | |
| 174 | 171 | static const char *pcw16_write_handler_dram[4] = |
| 175 | 172 | { |
| r9675 | r9676 | |
| 195 | 192 | /* read flash0 */ |
| 196 | 193 | static int pcw16_flash0_bank_handler_r(running_machine *machine, int bank, int offset) |
| 197 | 194 | { |
| 195 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 198 | 196 | intel_e28f008sa_device *flash = machine->device<intel_e28f008sa_device>("flash0"); |
| 199 | | int flash_offset = (pcw16_banks[bank]<<14) | offset; |
| 197 | int flash_offset = (state->banks[bank]<<14) | offset; |
| 200 | 198 | return flash->read(flash_offset); |
| 201 | 199 | } |
| 202 | 200 | |
| 203 | 201 | /* read flash1 */ |
| 204 | 202 | static int pcw16_flash1_bank_handler_r(running_machine *machine, int bank, int offset) |
| 205 | 203 | { |
| 204 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 206 | 205 | intel_e28f008sa_device *flash = machine->device<intel_e28f008sa_device>("flash1"); |
| 207 | | int flash_offset = ((pcw16_banks[bank]&0x03f)<<14) | offset; |
| 206 | int flash_offset = ((state->banks[bank]&0x03f)<<14) | offset; |
| 208 | 207 | |
| 209 | 208 | return flash->read(flash_offset); |
| 210 | 209 | } |
| r9675 | r9676 | |
| 270 | 269 | /* write flash0 */ |
| 271 | 270 | static void pcw16_flash0_bank_handler_w(running_machine *machine, int bank, int offset, int data) |
| 272 | 271 | { |
| 272 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 273 | 273 | intel_e28f008sa_device *flash = machine->device<intel_e28f008sa_device>("flash0"); |
| 274 | 274 | |
| 275 | | int flash_offset = (pcw16_banks[bank]<<14) | offset; |
| 275 | int flash_offset = (state->banks[bank]<<14) | offset; |
| 276 | 276 | |
| 277 | 277 | flash->write(flash_offset, data); |
| 278 | 278 | } |
| r9675 | r9676 | |
| 280 | 280 | /* read flash1 */ |
| 281 | 281 | static void pcw16_flash1_bank_handler_w(running_machine *machine, int bank, int offset, int data) |
| 282 | 282 | { |
| 283 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 283 | 284 | intel_e28f008sa_device *flash = machine->device<intel_e28f008sa_device>("flash1"); |
| 284 | 285 | |
| 285 | | int flash_offset = ((pcw16_banks[bank]&0x03f)<<14) | offset; |
| 286 | int flash_offset = ((state->banks[bank]&0x03f)<<14) | offset; |
| 286 | 287 | |
| 287 | 288 | flash->write(flash_offset,data); |
| 288 | 289 | } |
| r9675 | r9676 | |
| 406 | 407 | |
| 407 | 408 | static void pcw16_update_bank(running_machine *machine, int bank) |
| 408 | 409 | { |
| 410 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 409 | 411 | unsigned char *mem_ptr = messram_get_ptr(machine->device("messram")); |
| 410 | 412 | int bank_id = 0; |
| 411 | 413 | int bank_offs = 0; |
| r9675 | r9676 | |
| 413 | 415 | char bank2[10]; |
| 414 | 416 | |
| 415 | 417 | /* get memory bank */ |
| 416 | | bank_id = pcw16_banks[bank]; |
| 418 | bank_id = state->banks[bank]; |
| 417 | 419 | |
| 418 | 420 | |
| 419 | 421 | if ((bank_id & 0x080)==0) |
| r9675 | r9676 | |
| 452 | 454 | } |
| 453 | 455 | |
| 454 | 456 | mem_ptr = mem_ptr + ((bank_id - bank_offs)<<14); |
| 455 | | pcw16_mem_ptr[bank] = (char*)mem_ptr; |
| 457 | state->mem_ptr[bank] = (char*)mem_ptr; |
| 456 | 458 | sprintf(bank1,"bank%d",(bank+1)); |
| 457 | 459 | sprintf(bank2,"bank%d",(bank+5)); |
| 458 | 460 | memory_set_bankptr(machine, bank1, mem_ptr); |
| r9675 | r9676 | |
| 499 | 501 | |
| 500 | 502 | static READ8_HANDLER(pcw16_bankhw_r) |
| 501 | 503 | { |
| 504 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 502 | 505 | // logerror("bank r: %d \n", offset); |
| 503 | 506 | |
| 504 | | return pcw16_banks[offset]; |
| 507 | return state->banks[offset]; |
| 505 | 508 | } |
| 506 | 509 | |
| 507 | 510 | static WRITE8_HANDLER(pcw16_bankhw_w) |
| 508 | 511 | { |
| 512 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 509 | 513 | //logerror("bank w: %d block: %02x\n", offset, data); |
| 510 | 514 | |
| 511 | | pcw16_banks[offset] = data; |
| 515 | state->banks[offset] = data; |
| 512 | 516 | |
| 513 | 517 | pcw16_update_memory(space->machine); |
| 514 | 518 | } |
| 515 | 519 | |
| 516 | 520 | static WRITE8_HANDLER(pcw16_video_control_w) |
| 517 | 521 | { |
| 522 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 518 | 523 | //logerror("video control w: %02x\n", data); |
| 519 | 524 | |
| 520 | | pcw16_video_control = data; |
| 525 | state->video_control = data; |
| 521 | 526 | } |
| 522 | 527 | |
| 523 | 528 | /* PCW16 KEYBOARD */ |
| 524 | 529 | |
| 525 | 530 | //unsigned char pcw16_keyboard_status; |
| 526 | | static unsigned char pcw16_keyboard_data_shift; |
| 527 | 531 | |
| 528 | 532 | |
| 529 | 533 | |
| r9675 | r9676 | |
| 540 | 544 | #define PCW16_KEYBOARD_CLOCK (1<<0) |
| 541 | 545 | |
| 542 | 546 | /* parity table. Used to set parity bit in keyboard status register */ |
| 543 | | static int pcw16_keyboard_parity_table[256]; |
| 544 | 547 | |
| 545 | | static int pcw16_keyboard_bits = 0; |
| 546 | | static int pcw16_keyboard_bits_output = 0; |
| 547 | 548 | |
| 548 | | static int pcw16_keyboard_state = 0; |
| 549 | | static int pcw16_keyboard_previous_state=0; |
| 550 | | static void pcw16_keyboard_reset(void); |
| 549 | static void pcw16_keyboard_reset(pcw16_state *state); |
| 551 | 550 | static void pcw16_keyboard_int(running_machine *, int); |
| 552 | 551 | |
| 553 | 552 | static void pcw16_keyboard_init(running_machine *machine) |
| 554 | 553 | { |
| 554 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 555 | 555 | int i; |
| 556 | 556 | int b; |
| 557 | 557 | |
| r9675 | r9676 | |
| 572 | 572 | data = data>>1; |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | | pcw16_keyboard_parity_table[i] = sum & 0x01; |
| 575 | state->keyboard_parity_table[i] = sum & 0x01; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | |
| 579 | 579 | /* clear int */ |
| 580 | 580 | pcw16_keyboard_int(machine, 0); |
| 581 | 581 | /* reset state */ |
| 582 | | pcw16_keyboard_state = 0; |
| 582 | state->keyboard_state = 0; |
| 583 | 583 | /* reset ready for transmit */ |
| 584 | | pcw16_keyboard_reset(); |
| 584 | pcw16_keyboard_reset(state); |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | | static void pcw16_keyboard_refresh_outputs(void) |
| 587 | static void pcw16_keyboard_refresh_outputs(pcw16_state *state) |
| 588 | 588 | { |
| 589 | 589 | /* generate output bits */ |
| 590 | | pcw16_keyboard_bits_output = pcw16_keyboard_bits; |
| 590 | state->keyboard_bits_output = state->keyboard_bits; |
| 591 | 591 | |
| 592 | 592 | /* force clock low? */ |
| 593 | | if (pcw16_keyboard_state & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK) |
| 593 | if (state->keyboard_state & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK) |
| 594 | 594 | { |
| 595 | | pcw16_keyboard_bits_output &= ~PCW16_KEYBOARD_CLOCK; |
| 595 | state->keyboard_bits_output &= ~PCW16_KEYBOARD_CLOCK; |
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | | static void pcw16_keyboard_set_clock_state(int state) |
| 599 | static void pcw16_keyboard_set_clock_state(pcw16_state *drvstate, int state) |
| 600 | 600 | { |
| 601 | | pcw16_keyboard_bits &= ~PCW16_KEYBOARD_CLOCK; |
| 601 | drvstate->keyboard_bits &= ~PCW16_KEYBOARD_CLOCK; |
| 602 | 602 | |
| 603 | 603 | if (state) |
| 604 | 604 | { |
| 605 | | pcw16_keyboard_bits |= PCW16_KEYBOARD_CLOCK; |
| 605 | drvstate->keyboard_bits |= PCW16_KEYBOARD_CLOCK; |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | | pcw16_keyboard_refresh_outputs(); |
| 608 | pcw16_keyboard_refresh_outputs(drvstate); |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | static void pcw16_keyboard_int(running_machine *machine, int state) |
| 612 | 612 | { |
| 613 | | pcw16_system_status &= ~(1<<1); |
| 613 | pcw16_state *drvstate = machine->driver_data<pcw16_state>(); |
| 614 | drvstate->system_status &= ~(1<<1); |
| 614 | 615 | |
| 615 | 616 | if (state) |
| 616 | 617 | { |
| 617 | | pcw16_system_status |= (1<<1); |
| 618 | drvstate->system_status |= (1<<1); |
| 618 | 619 | } |
| 619 | 620 | |
| 620 | 621 | pcw16_refresh_ints(machine); |
| 621 | 622 | } |
| 622 | 623 | |
| 623 | | static void pcw16_keyboard_reset(void) |
| 624 | static void pcw16_keyboard_reset(pcw16_state *state) |
| 624 | 625 | { |
| 625 | 626 | /* clock set to high */ |
| 626 | | pcw16_keyboard_set_clock_state(1); |
| 627 | pcw16_keyboard_set_clock_state(state, 1); |
| 627 | 628 | } |
| 628 | 629 | |
| 629 | 630 | /* interfaces to a pc-at keyboard */ |
| 630 | 631 | static READ8_HANDLER(pcw16_keyboard_data_shift_r) |
| 631 | 632 | { |
| 632 | | //logerror("keyboard data shift r: %02x\n", pcw16_keyboard_data_shift); |
| 633 | | pcw16_keyboard_state &= ~(PCW16_KEYBOARD_BUSY_STATUS); |
| 633 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 634 | //logerror("keyboard data shift r: %02x\n", state->keyboard_data_shift); |
| 635 | state->keyboard_state &= ~(PCW16_KEYBOARD_BUSY_STATUS); |
| 634 | 636 | |
| 635 | 637 | pcw16_keyboard_int(space->machine, 0); |
| 636 | 638 | /* reset for reception */ |
| 637 | | pcw16_keyboard_reset(); |
| 639 | pcw16_keyboard_reset(state); |
| 638 | 640 | |
| 639 | 641 | /* read byte */ |
| 640 | | return pcw16_keyboard_data_shift; |
| 642 | return state->keyboard_data_shift; |
| 641 | 643 | } |
| 642 | 644 | |
| 643 | 645 | /* if force keyboard clock is low it is safe to send */ |
| 644 | | static int pcw16_keyboard_can_transmit(void) |
| 646 | static int pcw16_keyboard_can_transmit(pcw16_state *state) |
| 645 | 647 | { |
| 646 | 648 | /* clock is not forced low */ |
| 647 | 649 | /* and not busy - i.e. not already sent a char */ |
| 648 | | return ((pcw16_keyboard_bits_output & PCW16_KEYBOARD_CLOCK)!=0); |
| 650 | return ((state->keyboard_bits_output & PCW16_KEYBOARD_CLOCK)!=0); |
| 649 | 651 | } |
| 650 | 652 | |
| 651 | 653 | #ifdef UNUSED_FUNCTION |
| r9675 | r9676 | |
| 658 | 660 | /* signal a code has been received */ |
| 659 | 661 | static void pcw16_keyboard_signal_byte_received(running_machine *machine, int data) |
| 660 | 662 | { |
| 663 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 661 | 664 | /* clear clock */ |
| 662 | | pcw16_keyboard_set_clock_state(0); |
| 665 | pcw16_keyboard_set_clock_state(state, 0); |
| 663 | 666 | |
| 664 | 667 | /* set code in shift register */ |
| 665 | | pcw16_keyboard_data_shift = data; |
| 668 | state->keyboard_data_shift = data; |
| 666 | 669 | /* busy */ |
| 667 | | pcw16_keyboard_state |= PCW16_KEYBOARD_BUSY_STATUS; |
| 670 | state->keyboard_state |= PCW16_KEYBOARD_BUSY_STATUS; |
| 668 | 671 | |
| 669 | 672 | /* initialise start, stop and parity bits */ |
| 670 | | pcw16_keyboard_state &= ~PCW16_KEYBOARD_START_BIT_MASK; |
| 671 | | pcw16_keyboard_state |=PCW16_KEYBOARD_STOP_BIT_MASK; |
| 673 | state->keyboard_state &= ~PCW16_KEYBOARD_START_BIT_MASK; |
| 674 | state->keyboard_state |=PCW16_KEYBOARD_STOP_BIT_MASK; |
| 672 | 675 | |
| 673 | 676 | /* "Keyboard data has odd parity, so the parity bit in the |
| 674 | 677 | status register should only be set when the shift register |
| 675 | 678 | data itself has even parity. */ |
| 676 | 679 | |
| 677 | | pcw16_keyboard_state &= ~PCW16_KEYBOARD_PARITY_MASK; |
| 680 | state->keyboard_state &= ~PCW16_KEYBOARD_PARITY_MASK; |
| 678 | 681 | |
| 679 | 682 | /* if data has even parity, set parity bit */ |
| 680 | | if ((pcw16_keyboard_parity_table[data])==0) |
| 681 | | pcw16_keyboard_state |= PCW16_KEYBOARD_PARITY_MASK; |
| 683 | if ((state->keyboard_parity_table[data])==0) |
| 684 | state->keyboard_state |= PCW16_KEYBOARD_PARITY_MASK; |
| 682 | 685 | |
| 683 | 686 | pcw16_keyboard_int(machine, 1); |
| 684 | 687 | } |
| r9675 | r9676 | |
| 686 | 689 | |
| 687 | 690 | static WRITE8_HANDLER(pcw16_keyboard_data_shift_w) |
| 688 | 691 | { |
| 692 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 689 | 693 | //logerror("Keyboard Data Shift: %02x\n", data); |
| 690 | 694 | /* writing to shift register clears parity */ |
| 691 | 695 | /* writing to shift register clears start bit */ |
| 692 | | pcw16_keyboard_state &= ~( |
| 696 | state->keyboard_state &= ~( |
| 693 | 697 | PCW16_KEYBOARD_PARITY_MASK | |
| 694 | 698 | PCW16_KEYBOARD_START_BIT_MASK); |
| 695 | 699 | |
| 696 | 700 | /* writing to shift register sets stop bit */ |
| 697 | | pcw16_keyboard_state |= PCW16_KEYBOARD_STOP_BIT_MASK; |
| 701 | state->keyboard_state |= PCW16_KEYBOARD_STOP_BIT_MASK; |
| 698 | 702 | |
| 699 | | pcw16_keyboard_data_shift = data; |
| 703 | state->keyboard_data_shift = data; |
| 700 | 704 | |
| 701 | 705 | } |
| 702 | 706 | |
| 703 | 707 | static READ8_HANDLER(pcw16_keyboard_status_r) |
| 704 | 708 | { |
| 709 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 705 | 710 | /* bit 2,3 are bits 8 and 9 of vdu pointer */ |
| 706 | | return (pcw16_keyboard_state & |
| 711 | return (state->keyboard_state & |
| 707 | 712 | (PCW16_KEYBOARD_PARITY_MASK | |
| 708 | 713 | PCW16_KEYBOARD_STOP_BIT_MASK | |
| 709 | 714 | PCW16_KEYBOARD_START_BIT_MASK | |
| r9675 | r9676 | |
| 714 | 719 | |
| 715 | 720 | static WRITE8_HANDLER(pcw16_keyboard_control_w) |
| 716 | 721 | { |
| 722 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 717 | 723 | //logerror("Keyboard control w: %02x\n",data); |
| 718 | 724 | |
| 719 | | pcw16_keyboard_previous_state = pcw16_keyboard_state; |
| 725 | state->keyboard_previous_state = state->keyboard_state; |
| 720 | 726 | |
| 721 | 727 | /* if set, set parity */ |
| 722 | 728 | if (data & 0x080) |
| 723 | 729 | { |
| 724 | | pcw16_keyboard_state |= PCW16_KEYBOARD_PARITY_MASK; |
| 730 | state->keyboard_state |= PCW16_KEYBOARD_PARITY_MASK; |
| 725 | 731 | } |
| 726 | 732 | |
| 727 | 733 | /* clear read/write bits */ |
| 728 | | pcw16_keyboard_state &= |
| 734 | state->keyboard_state &= |
| 729 | 735 | ~(PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK | |
| 730 | 736 | PCW16_KEYBOARD_TRANSMIT_MODE); |
| 731 | 737 | /* set read/write bits from data */ |
| 732 | | pcw16_keyboard_state |= (data & 0x03); |
| 738 | state->keyboard_state |= (data & 0x03); |
| 733 | 739 | |
| 734 | 740 | if (data & PCW16_KEYBOARD_RESET_INTERFACE) |
| 735 | 741 | { |
| 736 | | pcw16_keyboard_reset(); |
| 742 | pcw16_keyboard_reset(state); |
| 737 | 743 | } |
| 738 | 744 | |
| 739 | 745 | if (data & PCW16_KEYBOARD_TRANSMIT_MODE) |
| 740 | 746 | { |
| 741 | 747 | /* force clock changed */ |
| 742 | | if (((pcw16_keyboard_state^pcw16_keyboard_previous_state) & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)!=0) |
| 748 | if (((state->keyboard_state^state->keyboard_previous_state) & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)!=0) |
| 743 | 749 | { |
| 744 | 750 | /* just cleared? */ |
| 745 | | if ((pcw16_keyboard_state & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)==0) |
| 751 | if ((state->keyboard_state & PCW16_KEYBOARD_FORCE_KEYBOARD_CLOCK)==0) |
| 746 | 752 | { |
| 747 | 753 | |
| 748 | 754 | /* write */ |
| 749 | 755 | /* busy */ |
| 750 | | pcw16_keyboard_state |= PCW16_KEYBOARD_BUSY_STATUS; |
| 756 | state->keyboard_state |= PCW16_KEYBOARD_BUSY_STATUS; |
| 751 | 757 | /* keyboard takes data */ |
| 752 | | at_keyboard_write(space->machine,pcw16_keyboard_data_shift); |
| 758 | at_keyboard_write(space->machine,state->keyboard_data_shift); |
| 753 | 759 | /* set clock low - no furthur transmissions */ |
| 754 | | pcw16_keyboard_set_clock_state(0); |
| 760 | pcw16_keyboard_set_clock_state(state, 0); |
| 755 | 761 | /* set int */ |
| 756 | 762 | pcw16_keyboard_int(space->machine, 1); |
| 757 | 763 | } |
| r9675 | r9676 | |
| 760 | 766 | |
| 761 | 767 | } |
| 762 | 768 | |
| 763 | | if (((pcw16_keyboard_state^pcw16_keyboard_previous_state) & PCW16_KEYBOARD_TRANSMIT_MODE)!=0) |
| 769 | if (((state->keyboard_state^state->keyboard_previous_state) & PCW16_KEYBOARD_TRANSMIT_MODE)!=0) |
| 764 | 770 | { |
| 765 | | if ((pcw16_keyboard_state & PCW16_KEYBOARD_TRANSMIT_MODE)==0) |
| 771 | if ((state->keyboard_state & PCW16_KEYBOARD_TRANSMIT_MODE)==0) |
| 766 | 772 | { |
| 767 | | if ((pcw16_system_status & (1<<1))!=0) |
| 773 | if ((state->system_status & (1<<1))!=0) |
| 768 | 774 | { |
| 769 | 775 | pcw16_keyboard_int(space->machine, 0); |
| 770 | 776 | } |
| 771 | 777 | } |
| 772 | 778 | } |
| 773 | 779 | |
| 774 | | pcw16_keyboard_refresh_outputs(); |
| 780 | pcw16_keyboard_refresh_outputs(state); |
| 775 | 781 | } |
| 776 | 782 | |
| 777 | 783 | |
| 778 | 784 | static TIMER_CALLBACK(pcw16_keyboard_timer_callback) |
| 779 | 785 | { |
| 786 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 780 | 787 | at_keyboard_polling(); |
| 781 | | if (pcw16_keyboard_can_transmit()) |
| 788 | if (pcw16_keyboard_can_transmit(state)) |
| 782 | 789 | { |
| 783 | 790 | int data; |
| 784 | 791 | |
| r9675 | r9676 | |
| 796 | 803 | } |
| 797 | 804 | } |
| 798 | 805 | |
| 799 | | static unsigned char rtc_seconds; |
| 800 | | static unsigned char rtc_minutes; |
| 801 | | static unsigned char rtc_hours; |
| 802 | | static unsigned char rtc_days_max; |
| 803 | | static unsigned char rtc_days; |
| 804 | | static unsigned char rtc_months; |
| 805 | | static unsigned char rtc_years; |
| 806 | | static unsigned char rtc_control; |
| 807 | | static unsigned char rtc_256ths_seconds; |
| 808 | 806 | |
| 809 | 807 | static const int rtc_days_in_each_month[]= |
| 810 | 808 | { |
| r9675 | r9676 | |
| 827 | 825 | 29, 28, 28, 28 |
| 828 | 826 | }; |
| 829 | 827 | |
| 830 | | static void rtc_setup_max_days(void) |
| 828 | static void rtc_setup_max_days(pcw16_state *state) |
| 831 | 829 | { |
| 832 | 830 | /* february? */ |
| 833 | | if (rtc_months == 2) |
| 831 | if (state->rtc_months == 2) |
| 834 | 832 | { |
| 835 | 833 | /* low two bits of year select number of days in february */ |
| 836 | | rtc_days_max = rtc_days_in_february[rtc_years & 0x03]; |
| 834 | state->rtc_days_max = rtc_days_in_february[state->rtc_years & 0x03]; |
| 837 | 835 | } |
| 838 | 836 | else |
| 839 | 837 | { |
| 840 | | rtc_days_max = (unsigned char)rtc_days_in_each_month[rtc_months]; |
| 838 | state->rtc_days_max = (unsigned char)rtc_days_in_each_month[state->rtc_months]; |
| 841 | 839 | } |
| 842 | 840 | } |
| 843 | 841 | |
| 844 | 842 | static TIMER_CALLBACK(rtc_timer_callback) |
| 845 | 843 | { |
| 844 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 846 | 845 | int fraction_of_second; |
| 847 | 846 | |
| 848 | 847 | /* halt counter? */ |
| 849 | | if ((rtc_control & 0x01)!=0) |
| 848 | if ((state->rtc_control & 0x01)!=0) |
| 850 | 849 | { |
| 851 | 850 | /* no */ |
| 852 | 851 | |
| 853 | 852 | /* increment 256th's of a second register */ |
| 854 | | fraction_of_second = rtc_256ths_seconds+1; |
| 853 | fraction_of_second = state->rtc_256ths_seconds+1; |
| 855 | 854 | /* add bit 8 = overflow */ |
| 856 | | rtc_seconds+=(fraction_of_second>>8); |
| 855 | state->rtc_seconds+=(fraction_of_second>>8); |
| 857 | 856 | /* ensure counter is in range 0-255 */ |
| 858 | | rtc_256ths_seconds = fraction_of_second & 0x0ff; |
| 857 | state->rtc_256ths_seconds = fraction_of_second & 0x0ff; |
| 859 | 858 | } |
| 860 | 859 | |
| 861 | | if (rtc_seconds>59) |
| 860 | if (state->rtc_seconds>59) |
| 862 | 861 | { |
| 863 | | rtc_seconds = 0; |
| 862 | state->rtc_seconds = 0; |
| 864 | 863 | |
| 865 | | rtc_minutes++; |
| 864 | state->rtc_minutes++; |
| 866 | 865 | |
| 867 | | if (rtc_minutes>59) |
| 866 | if (state->rtc_minutes>59) |
| 868 | 867 | { |
| 869 | | rtc_minutes = 0; |
| 868 | state->rtc_minutes = 0; |
| 870 | 869 | |
| 871 | | rtc_hours++; |
| 870 | state->rtc_hours++; |
| 872 | 871 | |
| 873 | | if (rtc_hours>23) |
| 872 | if (state->rtc_hours>23) |
| 874 | 873 | { |
| 875 | | rtc_hours = 0; |
| 874 | state->rtc_hours = 0; |
| 876 | 875 | |
| 877 | | rtc_days++; |
| 876 | state->rtc_days++; |
| 878 | 877 | |
| 879 | | if (rtc_days>rtc_days_max) |
| 878 | if (state->rtc_days > state->rtc_days_max) |
| 880 | 879 | { |
| 881 | | rtc_days = 1; |
| 880 | state->rtc_days = 1; |
| 882 | 881 | |
| 883 | | rtc_months++; |
| 882 | state->rtc_months++; |
| 884 | 883 | |
| 885 | | if (rtc_months>12) |
| 884 | if (state->rtc_months>12) |
| 886 | 885 | { |
| 887 | | rtc_months = 1; |
| 886 | state->rtc_months = 1; |
| 888 | 887 | |
| 889 | 888 | /* 7 bit year counter */ |
| 890 | | rtc_years = (rtc_years + 1) & 0x07f; |
| 889 | state->rtc_years = (state->rtc_years + 1) & 0x07f; |
| 891 | 890 | |
| 892 | 891 | } |
| 893 | 892 | |
| 894 | | rtc_setup_max_days(); |
| 893 | rtc_setup_max_days(state); |
| 895 | 894 | } |
| 896 | 895 | |
| 897 | 896 | } |
| r9675 | r9676 | |
| 903 | 902 | |
| 904 | 903 | static READ8_HANDLER(rtc_year_invalid_r) |
| 905 | 904 | { |
| 906 | | /* year in lower 7 bits. RTC Invalid status is rtc_control bit 0 |
| 905 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 906 | /* year in lower 7 bits. RTC Invalid status is state->rtc_control bit 0 |
| 907 | 907 | inverted */ |
| 908 | | return (rtc_years & 0x07f) | (((rtc_control & 0x01)<<7)^0x080); |
| 908 | return (state->rtc_years & 0x07f) | (((state->rtc_control & 0x01)<<7)^0x080); |
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | static READ8_HANDLER(rtc_month_r) |
| 912 | 912 | { |
| 913 | | return rtc_months; |
| 913 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 914 | return state->rtc_months; |
| 914 | 915 | } |
| 915 | 916 | |
| 916 | 917 | static READ8_HANDLER(rtc_days_r) |
| 917 | 918 | { |
| 918 | | return rtc_days; |
| 919 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 920 | return state->rtc_days; |
| 919 | 921 | } |
| 920 | 922 | |
| 921 | 923 | static READ8_HANDLER(rtc_hours_r) |
| 922 | 924 | { |
| 923 | | return rtc_hours; |
| 925 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 926 | return state->rtc_hours; |
| 924 | 927 | } |
| 925 | 928 | |
| 926 | 929 | static READ8_HANDLER(rtc_minutes_r) |
| 927 | 930 | { |
| 928 | | return rtc_minutes; |
| 931 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 932 | return state->rtc_minutes; |
| 929 | 933 | } |
| 930 | 934 | |
| 931 | 935 | static READ8_HANDLER(rtc_seconds_r) |
| 932 | 936 | { |
| 933 | | return rtc_seconds; |
| 937 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 938 | return state->rtc_seconds; |
| 934 | 939 | } |
| 935 | 940 | |
| 936 | 941 | static READ8_HANDLER(rtc_256ths_seconds_r) |
| 937 | 942 | { |
| 938 | | return rtc_256ths_seconds; |
| 943 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 944 | return state->rtc_256ths_seconds; |
| 939 | 945 | } |
| 940 | 946 | |
| 941 | 947 | static WRITE8_HANDLER(rtc_control_w) |
| 942 | 948 | { |
| 949 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 943 | 950 | /* write control */ |
| 944 | | rtc_control = data; |
| 951 | state->rtc_control = data; |
| 945 | 952 | } |
| 946 | 953 | |
| 947 | 954 | static WRITE8_HANDLER(rtc_seconds_w) |
| 948 | 955 | { |
| 956 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 949 | 957 | /* TODO: Writing register could cause next to increment! */ |
| 950 | | rtc_seconds = data; |
| 958 | state->rtc_seconds = data; |
| 951 | 959 | } |
| 952 | 960 | |
| 953 | 961 | static WRITE8_HANDLER(rtc_minutes_w) |
| 954 | 962 | { |
| 963 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 955 | 964 | /* TODO: Writing register could cause next to increment! */ |
| 956 | | rtc_minutes = data; |
| 965 | state->rtc_minutes = data; |
| 957 | 966 | } |
| 958 | 967 | |
| 959 | 968 | static WRITE8_HANDLER(rtc_hours_w) |
| 960 | 969 | { |
| 970 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 961 | 971 | /* TODO: Writing register could cause next to increment! */ |
| 962 | | rtc_hours = data; |
| 972 | state->rtc_hours = data; |
| 963 | 973 | } |
| 964 | 974 | |
| 965 | 975 | static WRITE8_HANDLER(rtc_days_w) |
| 966 | 976 | { |
| 977 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 967 | 978 | /* TODO: Writing register could cause next to increment! */ |
| 968 | | rtc_days = data; |
| 979 | state->rtc_days = data; |
| 969 | 980 | } |
| 970 | 981 | |
| 971 | 982 | static WRITE8_HANDLER(rtc_month_w) |
| 972 | 983 | { |
| 984 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 973 | 985 | /* TODO: Writing register could cause next to increment! */ |
| 974 | | rtc_months = data; |
| 986 | state->rtc_months = data; |
| 975 | 987 | |
| 976 | | rtc_setup_max_days(); |
| 988 | rtc_setup_max_days(state); |
| 977 | 989 | } |
| 978 | 990 | |
| 979 | 991 | |
| 980 | 992 | static WRITE8_HANDLER(rtc_year_w) |
| 981 | 993 | { |
| 994 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 982 | 995 | /* TODO: Writing register could cause next to increment! */ |
| 983 | | rtc_hours = data; |
| 996 | state->rtc_hours = data; |
| 984 | 997 | |
| 985 | | rtc_setup_max_days(); |
| 998 | rtc_setup_max_days(state); |
| 986 | 999 | } |
| 987 | 1000 | |
| 988 | | static int previous_fdc_int_state; |
| 989 | 1001 | |
| 990 | 1002 | static void pcw16_trigger_fdc_int(running_machine *machine) |
| 991 | 1003 | { |
| 1004 | pcw16_state *drvstate = machine->driver_data<pcw16_state>(); |
| 992 | 1005 | int state; |
| 993 | 1006 | |
| 994 | | state = pcw16_system_status & (1<<6); |
| 1007 | state = drvstate->system_status & (1<<6); |
| 995 | 1008 | |
| 996 | | switch (pcw16_fdc_int_code) |
| 1009 | switch (drvstate->fdc_int_code) |
| 997 | 1010 | { |
| 998 | 1011 | /* nmi */ |
| 999 | 1012 | case 0: |
| r9675 | r9676 | |
| 1004 | 1017 | is cleared this will not cause another nmi */ |
| 1005 | 1018 | /* I'll emulate it like this to be sure */ |
| 1006 | 1019 | |
| 1007 | | if (state!=previous_fdc_int_state) |
| 1020 | if (state!=drvstate->previous_fdc_int_state) |
| 1008 | 1021 | { |
| 1009 | 1022 | if (state) |
| 1010 | 1023 | { |
| r9675 | r9676 | |
| 1028 | 1041 | break; |
| 1029 | 1042 | } |
| 1030 | 1043 | |
| 1031 | | previous_fdc_int_state = state; |
| 1044 | drvstate->previous_fdc_int_state = state; |
| 1032 | 1045 | } |
| 1033 | 1046 | |
| 1034 | 1047 | static READ8_HANDLER(pcw16_system_status_r) |
| 1035 | 1048 | { |
| 1049 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 1036 | 1050 | // logerror("system status r: \n"); |
| 1037 | 1051 | |
| 1038 | | return pcw16_system_status | (input_port_read(space->machine, "EXTRA") & 0x04); |
| 1052 | return state->system_status | (input_port_read(space->machine, "EXTRA") & 0x04); |
| 1039 | 1053 | } |
| 1040 | 1054 | |
| 1041 | 1055 | static READ8_HANDLER(pcw16_timer_interrupt_counter_r) |
| 1042 | 1056 | { |
| 1057 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 1043 | 1058 | int data; |
| 1044 | 1059 | |
| 1045 | | data = pcw16_interrupt_counter; |
| 1060 | data = state->interrupt_counter; |
| 1046 | 1061 | |
| 1047 | | pcw16_interrupt_counter = 0; |
| 1062 | state->interrupt_counter = 0; |
| 1048 | 1063 | /* clear display int */ |
| 1049 | | pcw16_system_status &= ~(1<<0); |
| 1064 | state->system_status &= ~(1<<0); |
| 1050 | 1065 | |
| 1051 | 1066 | pcw16_refresh_ints(space->machine); |
| 1052 | 1067 | |
| r9675 | r9676 | |
| 1056 | 1071 | |
| 1057 | 1072 | static WRITE8_HANDLER(pcw16_system_control_w) |
| 1058 | 1073 | { |
| 1074 | pcw16_state *state = space->machine->driver_data<pcw16_state>(); |
| 1059 | 1075 | running_device *speaker = space->machine->device("beep"); |
| 1060 | 1076 | //logerror("0x0f8: function: %d\n",data); |
| 1061 | 1077 | |
| r9675 | r9676 | |
| 1077 | 1093 | /* connect IRQ6 input to /NMI */ |
| 1078 | 1094 | case 0x02: |
| 1079 | 1095 | { |
| 1080 | | pcw16_fdc_int_code = 0; |
| 1096 | state->fdc_int_code = 0; |
| 1081 | 1097 | } |
| 1082 | 1098 | break; |
| 1083 | 1099 | |
| 1084 | 1100 | /* connect IRQ6 input to /INT */ |
| 1085 | 1101 | case 0x03: |
| 1086 | 1102 | { |
| 1087 | | pcw16_fdc_int_code = 1; |
| 1103 | state->fdc_int_code = 1; |
| 1088 | 1104 | } |
| 1089 | 1105 | break; |
| 1090 | 1106 | |
| 1091 | 1107 | /* dis-connect IRQ6 input from /NMI and /INT */ |
| 1092 | 1108 | case 0x04: |
| 1093 | 1109 | { |
| 1094 | | pcw16_fdc_int_code = 2; |
| 1110 | state->fdc_int_code = 2; |
| 1095 | 1111 | } |
| 1096 | 1112 | break; |
| 1097 | 1113 | |
| r9675 | r9676 | |
| 1143 | 1159 | /* bit 5 - green/red led (1==green)*/ |
| 1144 | 1160 | /* bit 4 - monitor on/off (1==on) */ |
| 1145 | 1161 | |
| 1146 | | pcw16_4_bit_port = data>>4; |
| 1162 | state->_4_bit_port = data>>4; |
| 1147 | 1163 | |
| 1148 | 1164 | |
| 1149 | 1165 | } |
| r9675 | r9676 | |
| 1190 | 1206 | |
| 1191 | 1207 | static void pcw16_fdc_interrupt(running_machine *machine, int state) |
| 1192 | 1208 | { |
| 1209 | pcw16_state *drvstate = machine->driver_data<pcw16_state>(); |
| 1193 | 1210 | /* IRQ6 */ |
| 1194 | 1211 | /* bit 6 of PCW16 system status indicates floppy ints */ |
| 1195 | | pcw16_system_status &= ~(1<<6); |
| 1212 | drvstate->system_status &= ~(1<<6); |
| 1196 | 1213 | |
| 1197 | 1214 | if (state) |
| 1198 | 1215 | { |
| 1199 | | pcw16_system_status |= (1<<6); |
| 1216 | drvstate->system_status |= (1<<6); |
| 1200 | 1217 | } |
| 1201 | 1218 | |
| 1202 | 1219 | pcw16_trigger_fdc_int(machine); |
| r9675 | r9676 | |
| 1216 | 1233 | }; |
| 1217 | 1234 | |
| 1218 | 1235 | |
| 1219 | | static INS8250_INTERRUPT( pcw16_com_interrupt_1 ) { |
| 1220 | | pcw16_system_status &= ~(1 << 4); |
| 1236 | static INS8250_INTERRUPT( pcw16_com_interrupt_1 ) |
| 1237 | { |
| 1238 | pcw16_state *drvstate = device->machine->driver_data<pcw16_state>(); |
| 1239 | drvstate->system_status &= ~(1 << 4); |
| 1221 | 1240 | |
| 1222 | 1241 | if ( state ) { |
| 1223 | | pcw16_system_status |= (1 << 4); |
| 1242 | drvstate->system_status |= (1 << 4); |
| 1224 | 1243 | } |
| 1225 | 1244 | |
| 1226 | 1245 | pcw16_refresh_ints(device->machine); |
| r9675 | r9676 | |
| 1229 | 1248 | |
| 1230 | 1249 | static INS8250_INTERRUPT( pcw16_com_interrupt_2 ) |
| 1231 | 1250 | { |
| 1232 | | pcw16_system_status &= ~(1 << 3); |
| 1251 | pcw16_state *drvstate = device->machine->driver_data<pcw16_state>(); |
| 1252 | drvstate->system_status &= ~(1 << 3); |
| 1233 | 1253 | |
| 1234 | 1254 | if ( state ) { |
| 1235 | | pcw16_system_status |= (1 << 3); |
| 1255 | drvstate->system_status |= (1 << 3); |
| 1236 | 1256 | } |
| 1237 | 1257 | |
| 1238 | 1258 | pcw16_refresh_ints(device->machine); |
| r9675 | r9676 | |
| 1309 | 1329 | |
| 1310 | 1330 | static void pcw16_reset(running_machine *machine) |
| 1311 | 1331 | { |
| 1332 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 1312 | 1333 | /* initialise defaults */ |
| 1313 | | pcw16_fdc_int_code = 2; |
| 1334 | state->fdc_int_code = 2; |
| 1314 | 1335 | /* clear terminal count */ |
| 1315 | 1336 | pc_fdc_set_tc_state(machine, 0); |
| 1316 | 1337 | /* select first rom page */ |
| 1317 | | pcw16_banks[0] = 0; |
| 1338 | state->banks[0] = 0; |
| 1318 | 1339 | pcw16_update_memory(machine); |
| 1319 | 1340 | |
| 1320 | 1341 | /* temp rtc setup */ |
| 1321 | | rtc_seconds = 0; |
| 1322 | | rtc_minutes = 0; |
| 1323 | | rtc_hours = 0; |
| 1324 | | rtc_days_max = 0; |
| 1325 | | rtc_days = 1; |
| 1326 | | rtc_months = 1; |
| 1327 | | rtc_years = 0; |
| 1328 | | rtc_control = 1; |
| 1329 | | rtc_256ths_seconds = 0; |
| 1342 | state->rtc_seconds = 0; |
| 1343 | state->rtc_minutes = 0; |
| 1344 | state->rtc_hours = 0; |
| 1345 | state->rtc_days_max = 0; |
| 1346 | state->rtc_days = 1; |
| 1347 | state->rtc_months = 1; |
| 1348 | state->rtc_years = 0; |
| 1349 | state->rtc_control = 1; |
| 1350 | state->rtc_256ths_seconds = 0; |
| 1330 | 1351 | |
| 1331 | 1352 | pcw16_keyboard_init(machine); |
| 1332 | 1353 | } |
| r9675 | r9676 | |
| 1334 | 1355 | |
| 1335 | 1356 | static MACHINE_START( pcw16 ) |
| 1336 | 1357 | { |
| 1358 | pcw16_state *state = machine->driver_data<pcw16_state>(); |
| 1337 | 1359 | running_device *speaker = machine->device("beep"); |
| 1338 | | pcw16_system_status = 0; |
| 1339 | | pcw16_interrupt_counter = 0; |
| 1360 | state->system_status = 0; |
| 1361 | state->interrupt_counter = 0; |
| 1340 | 1362 | |
| 1341 | 1363 | /* video ints */ |
| 1342 | 1364 | timer_pulse(machine, ATTOTIME_IN_USEC(5830), NULL, 0,pcw16_timer_callback); |
| r9675 | r9676 | |
| 1394 | 1416 | NULL |
| 1395 | 1417 | }; |
| 1396 | 1418 | |
| 1397 | | static MACHINE_CONFIG_START( pcw16, driver_device ) |
| 1419 | static MACHINE_CONFIG_START( pcw16, pcw16_state ) |
| 1398 | 1420 | /* basic machine hardware */ |
| 1399 | 1421 | MDRV_CPU_ADD("maincpu", Z80, 16000000) |
| 1400 | 1422 | MDRV_CPU_PROGRAM_MAP(pcw16_map) |
src/mess/drivers/pasopia.c
| r9675 | r9676 | |
| 19 | 19 | #include "sound/sn76496.h" |
| 20 | 20 | #include "video/mc6845.h" |
| 21 | 21 | |
| 22 | | static UINT8 vram_sel,mio_sel; |
| 23 | | static UINT8 *p7_pal; |
| 24 | | static UINT8 bank_reg; |
| 25 | | static UINT16 cursor_addr; |
| 26 | | static UINT8 cursor_blink,cursor_raster; |
| 27 | | static UINT8 plane_reg,attr_data,attr_wrap,attr_latch,pal_sel,x_width,gfx_mode; |
| 28 | 22 | |
| 29 | | static UINT8 nmi_mask,nmi_enable_reg,nmi_trap,nmi_reset; |
| 23 | class pasopia_state : public driver_device |
| 24 | { |
| 25 | public: |
| 26 | pasopia_state(running_machine &machine, const driver_device_config_base &config) |
| 27 | : driver_device(machine, config) { } |
| 30 | 28 | |
| 29 | UINT8 vram_sel; |
| 30 | UINT8 mio_sel; |
| 31 | UINT8 *p7_pal; |
| 32 | UINT8 bank_reg; |
| 33 | UINT16 cursor_addr; |
| 34 | UINT8 cursor_blink; |
| 35 | UINT8 cursor_raster; |
| 36 | UINT8 plane_reg; |
| 37 | UINT8 attr_data; |
| 38 | UINT8 attr_wrap; |
| 39 | UINT8 attr_latch; |
| 40 | UINT8 pal_sel; |
| 41 | UINT8 x_width; |
| 42 | UINT8 gfx_mode; |
| 43 | UINT8 nmi_mask; |
| 44 | UINT8 nmi_enable_reg; |
| 45 | UINT8 nmi_trap; |
| 46 | UINT8 nmi_reset; |
| 47 | UINT16 pac2_index[2]; |
| 48 | UINT32 kanji_index; |
| 49 | UINT8 pac2_bank_select; |
| 50 | int addr_latch; |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 31 | 56 | #define VDP_CLOCK XTAL_3_579545MHz/4 |
| 32 | 57 | |
| 33 | 58 | static VIDEO_START( paso7 ) |
| 34 | 59 | { |
| 35 | | p7_pal = auto_alloc_array(machine, UINT8, 0x10); |
| 60 | pasopia_state *state = machine->driver_data<pasopia_state>(); |
| 61 | state->p7_pal = auto_alloc_array(machine, UINT8, 0x10); |
| 36 | 62 | } |
| 37 | 63 | |
| 38 | 64 | #define keyb_press(_val_,_charset_) \ |
| r9675 | r9676 | |
| 153 | 179 | |
| 154 | 180 | static void draw_tv_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int width) |
| 155 | 181 | { |
| 182 | pasopia_state *state = machine->driver_data<pasopia_state>(); |
| 156 | 183 | UINT8 *vram = memory_region(machine, "vram"); |
| 157 | 184 | int x,y/*,xi,yi*/; |
| 158 | 185 | int count; |
| r9675 | r9676 | |
| 170 | 197 | drawgfx_transpen(bitmap,cliprect,machine->gfx[0],tile,color & 7,0,0,x*8,y*8,0); |
| 171 | 198 | |
| 172 | 199 | // draw cursor |
| 173 | | if(cursor_addr*8 == count) |
| 200 | if(state->cursor_addr*8 == count) |
| 174 | 201 | { |
| 175 | 202 | int xc,yc,cursor_on; |
| 176 | 203 | |
| 177 | 204 | cursor_on = 0; |
| 178 | | switch(cursor_raster & 0x60) |
| 205 | switch(state->cursor_raster & 0x60) |
| 179 | 206 | { |
| 180 | 207 | case 0x00: cursor_on = 1; break; //always on |
| 181 | 208 | case 0x20: cursor_on = 0; break; //always off |
| r9675 | r9676 | |
| 185 | 212 | |
| 186 | 213 | if(cursor_on) |
| 187 | 214 | { |
| 188 | | for(yc=0;yc<(8-(cursor_raster & 7));yc++) |
| 215 | for(yc=0;yc<(8-(state->cursor_raster & 7));yc++) |
| 189 | 216 | { |
| 190 | 217 | for(xc=0;xc<8;xc++) |
| 191 | 218 | { |
| r9675 | r9676 | |
| 201 | 228 | |
| 202 | 229 | static void draw_mixed_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int width) |
| 203 | 230 | { |
| 231 | pasopia_state *state = machine->driver_data<pasopia_state>(); |
| 204 | 232 | UINT8 *vram = memory_region(machine, "vram"); |
| 205 | 233 | UINT8 *gfx_data = memory_region(machine,"font"); |
| 206 | 234 | int x,y,xi,yi; |
| r9675 | r9676 | |
| 249 | 277 | } |
| 250 | 278 | |
| 251 | 279 | // draw cursor |
| 252 | | if(cursor_addr*8 == count) |
| 280 | if(state->cursor_addr*8 == count) |
| 253 | 281 | { |
| 254 | 282 | int xc,yc,cursor_on; |
| 255 | 283 | |
| 256 | 284 | cursor_on = 0; |
| 257 | | switch(cursor_raster & 0x60) |
| 285 | switch(state->cursor_raster & 0x60) |
| 258 | 286 | { |
| 259 | 287 | case 0x00: cursor_on = 1; break; //always on |
| 260 | 288 | case 0x20: cursor_on = 0; break; //always off |
| r9675 | r9676 | |
| 264 | 292 | |
| 265 | 293 | if(cursor_on) |
| 266 | 294 | { |
| 267 | | for(yc=0;yc<(8-(cursor_raster & 7));yc++) |
| 295 | for(yc=0;yc<(8-(state->cursor_raster & 7));yc++) |
| 268 | 296 | { |
| 269 | 297 | for(xc=0;xc<8;xc++) |
| 270 | 298 | { |
| r9675 | r9676 | |
| 281 | 309 | |
| 282 | 310 | static VIDEO_UPDATE( paso7 ) |
| 283 | 311 | { |
| 312 | pasopia_state *state = screen->machine->driver_data<pasopia_state>(); |
| 284 | 313 | int width; |
| 285 | 314 | |
| 286 | 315 | bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); |
| 287 | 316 | |
| 288 | 317 | fake_keyboard_data(screen->machine); |
| 289 | 318 | |
| 290 | | width = x_width ? 80 : 40; |
| 319 | width = state->x_width ? 80 : 40; |
| 291 | 320 | |
| 292 | | if(gfx_mode) |
| 321 | if(state->gfx_mode) |
| 293 | 322 | draw_mixed_screen(screen->machine,bitmap,cliprect,width); |
| 294 | 323 | else |
| 295 | 324 | { |
| r9675 | r9676 | |
| 302 | 331 | |
| 303 | 332 | static READ8_HANDLER( vram_r ) |
| 304 | 333 | { |
| 334 | pasopia_state *state = space->machine->driver_data<pasopia_state>(); |
| 305 | 335 | UINT8 *vram = memory_region(space->machine, "vram"); |
| 306 | 336 | UINT8 res; |
| 307 | 337 | |
| 308 | | if(vram_sel == 0) |
| 338 | if(state->vram_sel == 0) |
| 309 | 339 | { |
| 310 | 340 | UINT8 *work_ram = memory_region(space->machine, "maincpu"); |
| 311 | 341 | |
| 312 | 342 | return work_ram[offset+0x8000]; |
| 313 | 343 | } |
| 314 | 344 | |
| 315 | | if(pal_sel && (plane_reg & 0x70) == 0x00) |
| 316 | | return p7_pal[offset & 0xf]; |
| 345 | if(state->pal_sel && (state->plane_reg & 0x70) == 0x00) |
| 346 | return state->p7_pal[offset & 0xf]; |
| 317 | 347 | |
| 318 | 348 | res = 0xff; |
| 319 | 349 | |
| 320 | | if((plane_reg & 0x11) == 0x11) |
| 350 | if((state->plane_reg & 0x11) == 0x11) |
| 321 | 351 | res &= vram[offset | 0x0000]; |
| 322 | | if((plane_reg & 0x22) == 0x22) |
| 352 | if((state->plane_reg & 0x22) == 0x22) |
| 323 | 353 | res &= vram[offset | 0x4000]; |
| 324 | | if((plane_reg & 0x44) == 0x44) |
| 354 | if((state->plane_reg & 0x44) == 0x44) |
| 325 | 355 | { |
| 326 | 356 | res &= vram[offset | 0x8000]; |
| 327 | | attr_latch = vram[offset | 0xc000] & 0x87; |
| 357 | state->attr_latch = vram[offset | 0xc000] & 0x87; |
| 328 | 358 | } |
| 329 | 359 | |
| 330 | 360 | return res; |
| r9675 | r9676 | |
| 332 | 362 | |
| 333 | 363 | static WRITE8_HANDLER( vram_w ) |
| 334 | 364 | { |
| 365 | pasopia_state *state = space->machine->driver_data<pasopia_state>(); |
| 335 | 366 | UINT8 *vram = memory_region(space->machine, "vram"); |
| 336 | 367 | |
| 337 | | if(vram_sel) |
| 368 | if(state->vram_sel) |
| 338 | 369 | { |
| 339 | | if(pal_sel && (plane_reg & 0x70) == 0x00) |
| 370 | if(state->pal_sel && (state->plane_reg & 0x70) == 0x00) |
| 340 | 371 | { |
| 341 | | p7_pal[offset & 0xf] = data & 0xf; |
| 372 | state->p7_pal[offset & 0xf] = data & 0xf; |
| 342 | 373 | return; |
| 343 | 374 | } |
| 344 | 375 | |
| 345 | | if(plane_reg & 0x10) |
| 346 | | vram[(offset & 0x3fff) | 0x0000] = (plane_reg & 1) ? data : 0xff; |
| 347 | | if(plane_reg & 0x20) |
| 348 | | vram[(offset & 0x3fff) | 0x4000] = (plane_reg & 2) ? data : 0xff; |
| 349 | | if(plane_reg & 0x40) |
| 376 | if(state->plane_reg & 0x10) |
| 377 | vram[(offset & 0x3fff) | 0x0000] = (state->plane_reg & 1) ? data : 0xff; |
| 378 | if(state->plane_reg & 0x20) |
| 379 | vram[(offset & 0x3fff) | 0x4000] = (state->plane_reg & 2) ? data : 0xff; |
| 380 | if(state->plane_reg & 0x40) |
| 350 | 381 | { |
| 351 | | vram[(offset & 0x3fff) | 0x8000] = (plane_reg & 4) ? data : 0xff; |
| 352 | | attr_latch = attr_wrap ? attr_latch : attr_data; |
| 353 | | vram[(offset & 0x3fff) | 0xc000] = attr_latch; |
| 382 | vram[(offset & 0x3fff) | 0x8000] = (state->plane_reg & 4) ? data : 0xff; |
| 383 | state->attr_latch = state->attr_wrap ? state->attr_latch : state->attr_data; |
| 384 | vram[(offset & 0x3fff) | 0xc000] = state->attr_latch; |
| 354 | 385 | } |
| 355 | 386 | } |
| 356 | 387 | else |
| r9675 | r9676 | |
| 363 | 394 | |
| 364 | 395 | static WRITE8_HANDLER( pasopia7_memory_ctrl_w ) |
| 365 | 396 | { |
| 397 | pasopia_state *state = space->machine->driver_data<pasopia_state>(); |
| 366 | 398 | UINT8 *work_ram = memory_region(space->machine, "maincpu"); |
| 367 | 399 | UINT8 *basic = memory_region(space->machine, "basic"); |
| 368 | 400 | |
| r9675 | r9676 | |
| 383 | 415 | break; |
| 384 | 416 | } |
| 385 | 417 | |
| 386 | | bank_reg = data & 3; |
| 387 | | vram_sel = data & 4; |
| 388 | | mio_sel = data & 8; |
| 418 | state->bank_reg = data & 3; |
| 419 | state->vram_sel = data & 4; |
| 420 | state->mio_sel = data & 8; |
| 389 | 421 | |
| 390 | 422 | // bank4 is always RAM |
| 391 | 423 | |
| 392 | | // printf("%02x\n",vram_sel); |
| 424 | // printf("%02x\n",state->vram_sel); |
| 393 | 425 | } |
| 394 | 426 | |
| 395 | 427 | #if 0 |
| r9675 | r9676 | |
| 399 | 431 | } |
| 400 | 432 | #endif |
| 401 | 433 | |
| 402 | | static UINT16 pac2_index[2]; |
| 403 | | static UINT32 kanji_index; |
| 404 | | static UINT8 pac2_bank_select; |
| 405 | 434 | |
| 406 | 435 | static WRITE8_HANDLER( pac2_w ) |
| 407 | 436 | { |
| 437 | pasopia_state *state = space->machine->driver_data<pasopia_state>(); |
| 408 | 438 | /* |
| 409 | 439 | select register: |
| 410 | 440 | 4 = ram1; |
| r9675 | r9676 | |
| 414 | 444 | anything else is nop |
| 415 | 445 | */ |
| 416 | 446 | |
| 417 | | if(pac2_bank_select == 3 || pac2_bank_select == 4) |
| 447 | if(state->pac2_bank_select == 3 || state->pac2_bank_select == 4) |
| 418 | 448 | { |
| 419 | 449 | switch(offset) |
| 420 | 450 | { |
| 421 | | case 0: pac2_index[(pac2_bank_select-3) & 1] = (pac2_index[(pac2_bank_select-3) & 1] & 0x7f00) | (data & 0xff); break; |
| 422 | | case 1: pac2_index[(pac2_bank_select-3) & 1] = (pac2_index[(pac2_bank_select-3) & 1] & 0xff) | ((data & 0x7f) << 8); break; |
| 451 | case 0: state->pac2_index[(state->pac2_bank_select-3) & 1] = (state->pac2_index[(state->pac2_bank_select-3) & 1] & 0x7f00) | (data & 0xff); break; |
| 452 | case 1: state->pac2_index[(state->pac2_bank_select-3) & 1] = (state->pac2_index[(state->pac2_bank_select-3) & 1] & 0xff) | ((data & 0x7f) << 8); break; |
| 423 | 453 | case 2: // PAC2 RAM write |
| 424 | 454 | { |
| 425 | 455 | UINT8 *pac2_ram; |
| 426 | 456 | |
| 427 | | pac2_ram = memory_region(space->machine, ((pac2_bank_select-3) & 1) ? "rampac2" : "rampac1"); |
| 457 | pac2_ram = memory_region(space->machine, ((state->pac2_bank_select-3) & 1) ? "rampac2" : "rampac1"); |
| 428 | 458 | |
| 429 | | pac2_ram[pac2_index[(pac2_bank_select-3) & 1]] = data; |
| 459 | pac2_ram[state->pac2_index[(state->pac2_bank_select-3) & 1]] = data; |
| 430 | 460 | } |
| 431 | 461 | } |
| 432 | 462 | } |
| 433 | | else if(pac2_bank_select == 2) // kanji ROM |
| 463 | else if(state->pac2_bank_select == 2) // kanji ROM |
| 434 | 464 | { |
| 435 | 465 | switch(offset) |
| 436 | 466 | { |
| 437 | | case 0: kanji_index = (kanji_index & 0x1ff00) | ((data & 0xff) << 0); break; |
| 438 | | case 1: kanji_index = (kanji_index & 0x100ff) | ((data & 0xff) << 8); break; |
| 439 | | case 2: kanji_index = (kanji_index & 0x0ffff) | ((data & 0x01) << 16); break; |
| 467 | case 0: state->kanji_index = (state->kanji_index & 0x1ff00) | ((data & 0xff) << 0); break; |
| 468 | case 1: state->kanji_index = (state->kanji_index & 0x100ff) | ((data & 0xff) << 8); break; |
| 469 | case 2: state->kanji_index = (state->kanji_index & 0x0ffff) | ((data & 0x01) << 16); break; |
| 440 | 470 | } |
| 441 | 471 | } |
| 442 | 472 | |
| r9675 | r9676 | |
| 447 | 477 | // ... |
| 448 | 478 | } |
| 449 | 479 | else |
| 450 | | pac2_bank_select = data & 7; |
| 480 | state->pac2_bank_select = data & 7; |
| 451 | 481 | } |
| 452 | 482 | } |
| 453 | 483 | |
| 454 | 484 | static READ8_HANDLER( pac2_r ) |
| 455 | 485 | { |
| 486 | pasopia_state *state = space->machine->driver_data<pasopia_state>(); |
| 456 | 487 | if(offset == 2) |
| 457 | 488 | { |
| 458 | | if(pac2_bank_select == 3 || pac2_bank_select == 4) |
| 489 | if(state->pac2_bank_select == 3 || state->pac2_bank_select == 4) |
| 459 | 490 | { |
| 460 | 491 | UINT8 *pac2_ram; |
| 461 | 492 | |
| 462 | | pac2_ram = memory_region(space->machine, ((pac2_bank_select-3) & 1) ? "rampac2" : "rampac1"); |
| 493 | pac2_ram = memory_region(space->machine, ((state->pac2_bank_select-3) & 1) ? "rampac2" : "rampac1"); |
| 463 | 494 | |
| 464 | | return pac2_ram[pac2_index[(pac2_bank_select-3) & 1]]; |
| 495 | return pac2_ram[state->pac2_index[(state->pac2_bank_select-3) & 1]]; |
| 465 | 496 | } |
| 466 | | else if(pac2_bank_select == 2) |
| 497 | else if(state->pac2_bank_select == 2) |
| 467 | 498 | { |
| 468 | 499 | UINT8 *kanji_rom = memory_region(space->machine, "kanji"); |
| 469 | 500 | |
| 470 | | return kanji_rom[kanji_index]; |
| 501 | return kanji_rom[state->kanji_index]; |
| 471 | 502 | } |
| 472 | 503 | else |
| 473 | 504 | { |
| 474 | | printf("%02x\n",pac2_bank_select); |
| 505 | printf("%02x\n",state->pac2_bank_select); |
| 475 | 506 | } |
| 476 | 507 | } |
| 477 | 508 | |
| r9675 | r9676 | |
| 488 | 519 | |
| 489 | 520 | static WRITE8_HANDLER( pasopia7_6845_w ) |
| 490 | 521 | { |
| 491 | | static int addr_latch; |
| 492 | | |
| 522 | pasopia_state *state = space->machine->driver_data<pasopia_state>(); |
| 493 | 523 | if(offset == 0) |
| 494 | 524 | { |
| 495 | | addr_latch = data; |
| 525 | state->addr_latch = data; |
| 496 | 526 | mc6845_address_w(space->machine->device("crtc"), 0,data); |
| 497 | 527 | } |
| 498 | 528 | else |
| 499 | 529 | { |
| 500 | 530 | /* FIXME: this should be inside the MC6845 core! */ |
| 501 | | if(addr_latch == 0x0a) |
| 502 | | cursor_raster = data; |
| 503 | | if(addr_latch == 0x0e) |
| 504 | | cursor_addr = ((data<<8) & 0x3f00) | (cursor_addr & 0xff); |
| 505 | | else if(addr_latch == 0x0f) |
| 506 | | cursor_addr = (cursor_addr & 0x3f00) | (data & 0xff); |
| 531 | if(state->addr_latch == 0x0a) |
| 532 | state->cursor_raster = data; |
| 533 | if(state->addr_latch == 0x0e) |
| 534 | state->cursor_addr = ((data<<8) & 0x3f00) | (state->cursor_addr & 0xff); |
| 535 | else if(state->addr_latch == 0x0f) |
| 536 | state->cursor_addr = (state->cursor_addr & 0x3f00) | (data & 0xff); |
| 507 | 537 | |
| 508 | 538 | mc6845_register_w(space->machine->device("crtc"), 0,data); |
| 509 | 539 | |
| 510 | 540 | /* double pump the pixel clock if we are in 640 x 200 mode */ |
| 511 | | mc6845_set_clock(space->machine->device("crtc"), (x_width) ? VDP_CLOCK*2 : VDP_CLOCK); |
| 541 | mc6845_set_clock(space->machine->device("crtc"), (state->x_width) ? VDP_CLOCK*2 : VDP_CLOCK); |
| 512 | 542 | } |
| 513 | 543 | } |
| 514 | 544 | |
| 515 | 545 | static void pasopia_nmi_trap(running_machine *machine) |
| 516 | 546 | { |
| 517 | | if(nmi_enable_reg) |
| 547 | pasopia_state *state = machine->driver_data<pasopia_state>(); |
| 548 | if(state->nmi_enable_reg) |
| 518 | 549 | { |
| 519 | | nmi_trap |= 2; |
| 550 | state->nmi_trap |= 2; |
| 520 | 551 | |
| 521 | | if(nmi_mask == 0) |
| 552 | if(state->nmi_mask == 0) |
| 522 | 553 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, ASSERT_LINE); |
| 523 | 554 | } |
| 524 | 555 | } |
| 525 | 556 | |
| 526 | 557 | static READ8_HANDLER( pasopia7_io_r ) |
| 527 | 558 | { |
| 559 | pasopia_state *state = space->machine->driver_data<pasopia_state>(); |
| 528 | 560 | UINT16 io_port; |
| 529 | 561 | |
| 530 | | if(mio_sel) |
| 562 | if(state->mio_sel) |
| 531 | 563 | { |
| 532 | 564 | address_space *ram_space = cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 533 | 565 | |
| 534 | | mio_sel = 0; |
| 566 | state->mio_sel = 0; |
| 535 | 567 | //printf("%08x\n",offset); |
| 536 | 568 | //return 0x0d; // hack: this is used for reading the keyboard data, we can fake it a little ... (modify fda4) |
| 537 | 569 | return ram_space->read_byte(offset); |
| r9675 | r9676 | |
| 568 | 600 | |
| 569 | 601 | static WRITE8_HANDLER( pasopia7_io_w ) |
| 570 | 602 | { |
| 603 | pasopia_state *state = space->machine->driver_data<pasopia_state>(); |
| 571 | 604 | UINT16 io_port; |
| 572 | 605 | |
| 573 | | if(mio_sel) |
| 606 | if(state->mio_sel) |
| 574 | 607 | { |
| 575 | 608 | address_space *ram_space = cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 576 | | mio_sel = 0; |
| 609 | state->mio_sel = 0; |
| 577 | 610 | ram_space->write_byte(offset, data); |
| 578 | 611 | return; |
| 579 | 612 | } |
| r9675 | r9676 | |
| 712 | 745 | |
| 713 | 746 | static READ8_DEVICE_HANDLER( crtc_portb_r ) |
| 714 | 747 | { |
| 748 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 715 | 749 | // --x- ---- vsync bit |
| 716 | 750 | // ---x ---- lcd dip-sw |
| 717 | 751 | // ---- x--- disp bit |
| r9675 | r9676 | |
| 719 | 753 | UINT8 vdisp = (device->machine->primary_screen->vpos() < (lcd_bit ? 200 : 28)) ? 0x08 : 0x00; //TODO: check LCD vpos trigger |
| 720 | 754 | UINT8 vsync = vdisp ? 0x00 : 0x20; |
| 721 | 755 | |
| 722 | | return 0x40 | (attr_latch & 0x87) | vsync | vdisp | (lcd_bit << 4); |
| 756 | return 0x40 | (state->attr_latch & 0x87) | vsync | vdisp | (lcd_bit << 4); |
| 723 | 757 | } |
| 724 | 758 | |
| 725 | 759 | static WRITE8_DEVICE_HANDLER( screen_mode_w ) |
| 726 | 760 | { |
| 761 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 727 | 762 | if(data & 0x5f) |
| 728 | 763 | printf("GFX MODE %02x\n",data); |
| 729 | 764 | |
| 730 | | x_width = data & 0x20; |
| 731 | | gfx_mode = data & 0x80; |
| 765 | state->x_width = data & 0x20; |
| 766 | state->gfx_mode = data & 0x80; |
| 732 | 767 | |
| 733 | | // printf("%02x\n",gfx_mode); |
| 768 | // printf("%02x\n",state->gfx_mode); |
| 734 | 769 | } |
| 735 | 770 | |
| 736 | 771 | static WRITE8_DEVICE_HANDLER( plane_reg_w ) |
| 737 | 772 | { |
| 773 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 738 | 774 | //if(data & 0x11) |
| 739 | 775 | //printf("PLANE %02x\n",data); |
| 740 | | plane_reg = data; |
| 776 | state->plane_reg = data; |
| 741 | 777 | } |
| 742 | 778 | |
| 743 | 779 | static WRITE8_DEVICE_HANDLER( video_attr_w ) |
| 744 | 780 | { |
| 781 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 745 | 782 | //printf("VIDEO ATTR %02x | TEXT_PAGE %02x\n",data & 0xf,data & 0x70); |
| 746 | | attr_data = (data & 0x7) | ((data & 0x8)<<4); |
| 783 | state->attr_data = (data & 0x7) | ((data & 0x8)<<4); |
| 747 | 784 | } |
| 748 | 785 | |
| 749 | 786 | //#include "debugger.h" |
| 750 | 787 | |
| 751 | 788 | static WRITE8_DEVICE_HANDLER( video_misc_w ) |
| 752 | 789 | { |
| 790 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 753 | 791 | /* |
| 754 | 792 | --x- ---- blinking |
| 755 | 793 | ---x ---- attribute wrap |
| r9675 | r9676 | |
| 761 | 799 | // printf("VIDEO MISC %02x\n",data); |
| 762 | 800 | // debugger_break(device->machine); |
| 763 | 801 | // } |
| 764 | | cursor_blink = data & 0x20; |
| 765 | | attr_wrap = data & 0x10; |
| 766 | | // pal_sel = data & 0x02; |
| 802 | state->cursor_blink = data & 0x20; |
| 803 | state->attr_wrap = data & 0x10; |
| 804 | // state->pal_sel = data & 0x02; |
| 767 | 805 | } |
| 768 | 806 | |
| 769 | 807 | static WRITE8_DEVICE_HANDLER( nmi_mask_w ) |
| 770 | 808 | { |
| 809 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 771 | 810 | /* |
| 772 | 811 | --x- ---- (related to the data rec) |
| 773 | 812 | ---x ---- data rec out |
| r9675 | r9676 | |
| 778 | 817 | |
| 779 | 818 | if(data & 1) |
| 780 | 819 | { |
| 781 | | nmi_reset &= ~4; |
| 782 | | nmi_trap &= ~2; |
| 820 | state->nmi_reset &= ~4; |
| 821 | state->nmi_trap &= ~2; |
| 783 | 822 | //cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, CLEAR_LINE); //guess |
| 784 | 823 | } |
| 785 | 824 | |
| r9675 | r9676 | |
| 793 | 832 | |
| 794 | 833 | static READ8_DEVICE_HANDLER( nmi_reg_r ) |
| 795 | 834 | { |
| 835 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 796 | 836 | //printf("C\n"); |
| 797 | | return 0xfc | bank_reg;//mame_rand(device->machine); |
| 837 | return 0xfc | state->bank_reg;//mame_rand(device->machine); |
| 798 | 838 | } |
| 799 | 839 | |
| 800 | 840 | static WRITE8_DEVICE_HANDLER( nmi_reg_w ) |
| 801 | 841 | { |
| 842 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 802 | 843 | /* |
| 803 | 844 | x--- ---- NMI mask |
| 804 | 845 | -x-- ---- NMI enable trap on PPI8255 2 r/w |
| 805 | 846 | */ |
| 806 | | nmi_mask = data & 0x80; |
| 807 | | nmi_enable_reg = data & 0x40; |
| 847 | state->nmi_mask = data & 0x80; |
| 848 | state->nmi_enable_reg = data & 0x40; |
| 808 | 849 | } |
| 809 | 850 | |
| 810 | 851 | static READ8_DEVICE_HANDLER( nmi_porta_r ) |
| r9675 | r9676 | |
| 814 | 855 | |
| 815 | 856 | static READ8_DEVICE_HANDLER( nmi_portb_r ) |
| 816 | 857 | { |
| 817 | | return 0xf9 | nmi_trap | nmi_reset; |
| 858 | pasopia_state *state = device->machine->driver_data<pasopia_state>(); |
| 859 | return 0xf9 | state->nmi_trap | state->nmi_reset; |
| 818 | 860 | } |
| 819 | 861 | |
| 820 | 862 | static I8255A_INTERFACE( ppi8255_intf_0 ) |
| r9675 | r9676 | |
| 849 | 891 | |
| 850 | 892 | static MACHINE_RESET( paso7 ) |
| 851 | 893 | { |
| 894 | pasopia_state *state = machine->driver_data<pasopia_state>(); |
| 852 | 895 | UINT8 *bios = memory_region(machine, "maincpu"); |
| 853 | 896 | |
| 854 | 897 | memory_set_bankptr(machine, "bank1", bios + 0x10000); |
| r9675 | r9676 | |
| 856 | 899 | // memory_set_bankptr(machine, "bank3", bios + 0x10000); |
| 857 | 900 | // memory_set_bankptr(machine, "bank4", bios + 0x10000); |
| 858 | 901 | |
| 859 | | nmi_reset |= 4; |
| 902 | state->nmi_reset |= 4; |
| 860 | 903 | } |
| 861 | 904 | |
| 862 | 905 | static PALETTE_INIT( pasopia7 ) |
| r9675 | r9676 | |
| 881 | 924 | palette_set_color_rgb(machine, i+0x020, pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 0)); |
| 882 | 925 | } |
| 883 | 926 | |
| 884 | | static MACHINE_CONFIG_START( paso7, driver_device ) |
| 927 | static MACHINE_CONFIG_START( paso7, pasopia_state ) |
| 885 | 928 | /* basic machine hardware */ |
| 886 | 929 | MDRV_CPU_ADD("maincpu",Z80, XTAL_4MHz) |
| 887 | 930 | MDRV_CPU_PROGRAM_MAP(paso7_mem) |