src/mess/machine/samcoupe.c
| r5736 | r5737 | |
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | | SAM Coupe Driver - Written By Lee Hammerton |
| 3 | SAM Coupe Driver - Written By Lee Hammerton, Dirk Best |
| 4 | 4 | |
| 5 | | Functions to emulate general aspects of the machine (RAM, ROM, interrupts, |
| 6 | | I/O ports) |
| 7 | | |
| 8 | 5 | ***************************************************************************/ |
| 9 | 6 | |
| 10 | 7 | #include "driver.h" |
| r5736 | r5737 | |
| 12 | 9 | #include "machine/msm6242.h" |
| 13 | 10 | |
| 14 | 11 | |
| 12 | /*************************************************************************** |
| 13 | CONSTANTS |
| 14 | ***************************************************************************/ |
| 15 | |
| 15 | 16 | #define LMPR_RAM0 0x20 /* If bit set ram is paged into bank 0, else its rom0 */ |
| 16 | 17 | #define LMPR_ROM1 0x40 /* If bit set rom1 is paged into bank 3, else its ram */ |
| 17 | 18 | #define HMPR_MCNTRL 0x80 /* If set external RAM is enabled */ |
| 18 | 19 | |
| 19 | 20 | |
| 21 | /*************************************************************************** |
| 22 | MEMORY BANKING |
| 23 | ***************************************************************************/ |
| 24 | |
| 20 | 25 | static void samcoupe_update_bank(const address_space *space, int bank, UINT8 *memory, int is_readonly) |
| 21 | 26 | { |
| 22 | 27 | read8_space_func rh = SMH_NOP; |
| r5736 | r5737 | |
| 147 | 152 | } |
| 148 | 153 | |
| 149 | 154 | |
| 155 | /*************************************************************************** |
| 156 | REAL TIME CLOCK |
| 157 | ***************************************************************************/ |
| 158 | |
| 150 | 159 | static READ8_DEVICE_HANDLER( samcoupe_rtc_r ) |
| 151 | 160 | { |
| 152 | 161 | return msm6242_r(device, offset >> 12); |
| r5736 | r5737 | |
| 159 | 168 | } |
| 160 | 169 | |
| 161 | 170 | |
| 171 | /*************************************************************************** |
| 172 | MOUSE |
| 173 | ***************************************************************************/ |
| 174 | |
| 175 | TIMER_CALLBACK( samcoupe_mouse_reset ) |
| 176 | { |
| 177 | coupe_asic *asic = machine->driver_data; |
| 178 | asic->mouse_index = 0; |
| 179 | } |
| 180 | |
| 181 | UINT8 samcoupe_mouse_r(running_machine *machine) |
| 182 | { |
| 183 | coupe_asic *asic = machine->driver_data; |
| 184 | UINT8 result; |
| 185 | |
| 186 | /* on a read, reset the timer */ |
| 187 | timer_adjust_oneshot(asic->mouse_reset, ATTOTIME_IN_USEC(50), 0); |
| 188 | |
| 189 | /* update when we are about to read the first real values */ |
| 190 | if (asic->mouse_index == 2) |
| 191 | { |
| 192 | /* update values */ |
| 193 | int mouse_x = input_port_read(machine, "mouse_x"); |
| 194 | int mouse_y = input_port_read(machine, "mouse_y"); |
| 195 | |
| 196 | int mouse_dx = asic->mouse_x - mouse_x; |
| 197 | int mouse_dy = asic->mouse_y - mouse_y; |
| 198 | |
| 199 | asic->mouse_x = mouse_x; |
| 200 | asic->mouse_y = mouse_y; |
| 201 | |
| 202 | /* button state */ |
| 203 | asic->mouse_data[2] = input_port_read(machine, "mouse_buttons"); |
| 204 | |
| 205 | /* y-axis */ |
| 206 | asic->mouse_data[3] = (mouse_dy & 0xf00) >> 8; |
| 207 | asic->mouse_data[4] = (mouse_dy & 0x0f0) >> 4; |
| 208 | asic->mouse_data[5] = (mouse_dy & 0x00f) >> 0; |
| 209 | |
| 210 | /* x-axis */ |
| 211 | asic->mouse_data[6] = (mouse_dx & 0xf00) >> 8; |
| 212 | asic->mouse_data[7] = (mouse_dx & 0x0f0) >> 4; |
| 213 | asic->mouse_data[8] = (mouse_dx & 0x00f) >> 0; |
| 214 | } |
| 215 | |
| 216 | /* get current value */ |
| 217 | result = asic->mouse_data[asic->mouse_index++]; |
| 218 | |
| 219 | /* reset if we are at the end */ |
| 220 | if (asic->mouse_index == sizeof(asic->mouse_data)) |
| 221 | asic->mouse_index = 1; |
| 222 | |
| 223 | return result; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | /*************************************************************************** |
| 228 | RESET |
| 229 | ***************************************************************************/ |
| 230 | |
| 162 | 231 | MACHINE_RESET( samcoupe ) |
| 163 | 232 | { |
| 164 | 233 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 165 | 234 | const address_space *spaceio = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO); |
| 166 | 235 | coupe_asic *asic = machine->driver_data; |
| 167 | 236 | |
| 237 | /* initialize asic */ |
| 168 | 238 | asic->lmpr = 0x0f; /* ROM0 paged in, ROM1 paged out RAM Banks */ |
| 169 | 239 | asic->hmpr = 0x01; |
| 170 | 240 | asic->vmpr = 0x81; |
| 171 | 241 | asic->line_int = 0xff; /* line interrupts disabled */ |
| 172 | 242 | asic->status = 0x1f; /* no interrupts active */ |
| 173 | 243 | |
| 244 | /* initialize mouse */ |
| 245 | asic->mouse_reset = timer_alloc(space->machine, samcoupe_mouse_reset, 0); |
| 246 | asic->mouse_index = 0; |
| 247 | asic->mouse_data[0] = 0xff; |
| 248 | asic->mouse_data[1] = 0xff; |
| 249 | |
| 174 | 250 | if (input_port_read(machine, "config") & 0x01) |
| 175 | 251 | { |
| 176 | 252 | /* install RTC */ |
| 177 | | const device_config *rtc = devtag_get_device(machine, "rtc"); |
| 253 | const device_config *rtc = devtag_get_device(machine, "sambus_clock"); |
| 178 | 254 | memory_install_readwrite8_device_handler(spaceio, rtc, 0xef, 0xef, 0xffff, 0xff00, samcoupe_rtc_r, samcoupe_rtc_w); |
| 179 | 255 | } |
| 180 | 256 | else |
| r5736 | r5737 | |
| 183 | 259 | memory_install_readwrite8_handler(spaceio, 0xef, 0xef, 0xffff, 0xff00, SMH_UNMAP, SMH_UNMAP); |
| 184 | 260 | } |
| 185 | 261 | |
| 262 | /* initialize memory */ |
| 186 | 263 | samcoupe_update_memory(space); |
| 187 | 264 | } |
src/mess/drivers/samcoupe.c
| r5736 | r5737 | |
| 22 | 22 | Todo: |
| 23 | 23 | ----- |
| 24 | 24 | |
| 25 | | - Tape |
| 26 | 25 | - Attribute read |
| 27 | 26 | - Better timing |
| 28 | 27 | - Harddisk interfaces |
| r5736 | r5737 | |
| 221 | 220 | if (!BIT(offset, 13)) data &= input_port_read(space->machine, "keyboard_row_df") & 0x1f; |
| 222 | 221 | if (!BIT(offset, 14)) data &= input_port_read(space->machine, "keyboard_row_bf") & 0x1f; |
| 223 | 222 | if (!BIT(offset, 15)) data &= input_port_read(space->machine, "keyboard_row_7f") & 0x1f; |
| 224 | | if (offset == 0xff00) data &= input_port_read(space->machine, "keyboard_row_ff") & 0x1f; |
| 225 | 223 | |
| 224 | if (offset == 0xff00) |
| 225 | { |
| 226 | data &= input_port_read(space->machine, "keyboard_row_ff") & 0x1f; |
| 227 | |
| 228 | /* if no key has been pressed, return the mouse state */ |
| 229 | if (data == 0x1f) |
| 230 | data = samcoupe_mouse_r(space->machine); |
| 231 | } |
| 232 | |
| 226 | 233 | /* bit 5, lightpen strobe */ |
| 227 | 234 | data |= 1 << 5; |
| 228 | 235 | |
| r5736 | r5737 | |
| 445 | 452 | PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT)) |
| 446 | 453 | PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT)) |
| 447 | 454 | |
| 455 | PORT_START("mouse_buttons") |
| 456 | PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_CODE(MOUSECODE_BUTTON1) PORT_NAME("Mouse Button 1") |
| 457 | PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON3) PORT_CODE(MOUSECODE_BUTTON3) PORT_NAME("Mouse Button 3") |
| 458 | PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_BUTTON2) PORT_CODE(MOUSECODE_BUTTON2) PORT_NAME("Mouse Button 2") |
| 459 | PORT_BIT(0xf8, IP_ACTIVE_LOW, IPT_UNUSED) |
| 460 | |
| 461 | PORT_START("mouse_x") |
| 462 | PORT_BIT(0xfff, 0x000, IPT_MOUSE_X) PORT_SENSITIVITY(50) PORT_KEYDELTA(0) PORT_REVERSE |
| 463 | |
| 464 | PORT_START("mouse_y") |
| 465 | PORT_BIT(0xfff, 0x000, IPT_MOUSE_Y) PORT_SENSITIVITY(50) PORT_KEYDELTA(0) |
| 466 | |
| 448 | 467 | PORT_START("config") |
| 449 | 468 | PORT_CONFNAME(0x01, 0x00, "Real Time Clock") |
| 450 | 469 | PORT_CONFSETTING( 0x00, DEF_STR(None)) |