Previous 15994 Revisions Next

r5737 Tuesday 15th September, 2009 at 12:29:58 UTC by Dirk Best
[SAMCOUPE] Added mouse support.
[docs]messnew.txt
[src/mess/drivers]samcoupe.c
[src/mess/includes]samcoupe.h
[src/mess/machine]samcoupe.c

src/mess/includes/samcoupe.h
r5736r5737
2929   UINT8 clut[16];         /* color lookup table, 16 entries */
3030   UINT8 line_int;         /* line interrupt */
3131   UINT8 status;           /* status register */
32
33   /* mouse */
34   int mouse_index;
35   emu_timer *mouse_reset;
36   UINT8 mouse_data[9];
37   int mouse_x, mouse_y;
3238};
3339
3440
r5736r5737
4046/*----------- defined in machine/samcoupe.c -----------*/
4147
4248void samcoupe_update_memory(const address_space *space);
49UINT8 samcoupe_mouse_r(running_machine *machine);
4350
4451WRITE8_HANDLER( samcoupe_ext_mem_w );
4552MACHINE_RESET( samcoupe );
src/mess/machine/samcoupe.c
r5736r5737
11/***************************************************************************
22
3 SAM Coupe Driver - Written By Lee Hammerton
3    SAM Coupe Driver - Written By Lee Hammerton, Dirk Best
44
5  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
6  I/O ports)
7
85***************************************************************************/
96
107#include "driver.h"
r5736r5737
129#include "machine/msm6242.h"
1310
1411
12/***************************************************************************
13    CONSTANTS
14***************************************************************************/
15
1516#define LMPR_RAM0    0x20   /* If bit set ram is paged into bank 0, else its rom0 */
1617#define LMPR_ROM1    0x40   /* If bit set rom1 is paged into bank 3, else its ram */
1718#define HMPR_MCNTRL  0x80   /* If set external RAM is enabled */
1819
1920
21/***************************************************************************
22    MEMORY BANKING
23***************************************************************************/
24
2025static void samcoupe_update_bank(const address_space *space, int bank, UINT8 *memory, int is_readonly)
2126{
2227   read8_space_func rh = SMH_NOP;
r5736r5737
147152}
148153
149154
155/***************************************************************************
156    REAL TIME CLOCK
157***************************************************************************/
158
150159static READ8_DEVICE_HANDLER( samcoupe_rtc_r )
151160{
152161   return msm6242_r(device, offset >> 12);
r5736r5737
159168}
160169
161170
171/***************************************************************************
172    MOUSE
173***************************************************************************/
174
175TIMER_CALLBACK( samcoupe_mouse_reset )
176{
177   coupe_asic *asic = machine->driver_data;
178   asic->mouse_index = 0;
179}
180
181UINT8 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
162231MACHINE_RESET( samcoupe )
163232{
164233   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
165234   const address_space *spaceio = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO);
166235   coupe_asic *asic = machine->driver_data;
167236
237   /* initialize asic */
168238   asic->lmpr = 0x0f;      /* ROM0 paged in, ROM1 paged out RAM Banks */
169239   asic->hmpr = 0x01;
170240   asic->vmpr = 0x81;
171241   asic->line_int = 0xff;  /* line interrupts disabled */
172242   asic->status = 0x1f;    /* no interrupts active */
173243
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
174250   if (input_port_read(machine, "config") & 0x01)
175251   {
176252      /* install RTC */
177      const device_config *rtc = devtag_get_device(machine, "rtc");
253      const device_config *rtc = devtag_get_device(machine, "sambus_clock");
178254      memory_install_readwrite8_device_handler(spaceio, rtc, 0xef, 0xef, 0xffff, 0xff00, samcoupe_rtc_r, samcoupe_rtc_w);
179255   }
180256   else
r5736r5737
183259      memory_install_readwrite8_handler(spaceio, 0xef, 0xef, 0xffff, 0xff00, SMH_UNMAP, SMH_UNMAP);
184260   }
185261
262   /* initialize memory */
186263   samcoupe_update_memory(space);
187264}
src/mess/drivers/samcoupe.c
r5736r5737
2222    Todo:
2323    -----
2424
25    - Tape
2625    - Attribute read
2726    - Better timing
2827    - Harddisk interfaces
r5736r5737
221220   if (!BIT(offset, 13)) data &= input_port_read(space->machine, "keyboard_row_df") & 0x1f;
222221   if (!BIT(offset, 14)) data &= input_port_read(space->machine, "keyboard_row_bf") & 0x1f;
223222   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;
225223
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
226233   /* bit 5, lightpen strobe */
227234   data |= 1 << 5;
228235
r5736r5737
445452   PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_LEFT)   PORT_CHAR(UCHAR_MAMEKEY(LEFT))
446453   PORT_BIT(0x10, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_RIGHT)  PORT_CHAR(UCHAR_MAMEKEY(RIGHT))
447454
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
448467   PORT_START("config")
449468   PORT_CONFNAME(0x01, 0x00, "Real Time Clock")
450469   PORT_CONFSETTING(   0x00, DEF_STR(None))
docs/messnew.txt
r5736r5737
88
99System Driver Changes:
1010----------------------
11(none)
11- [SAMCOUPE] Added mouse support.  [Dirk Best]
1212
1313
1414

Previous 15994 Revisions Next


© 1998-2018 The MESS Team