2017-09-25 04:31:20 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
2017-05-05 01:49:42 +02:00
|
|
|
#include <stdlib.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <wchar.h>
|
2017-10-17 01:59:09 -04:00
|
|
|
#include "../86box.h"
|
2017-09-02 20:39:57 +02:00
|
|
|
#include "../ibm.h"
|
2017-09-04 01:52:29 -04:00
|
|
|
#include "../io.h"
|
|
|
|
|
#include "../nmi.h"
|
|
|
|
|
#include "../mem.h"
|
2017-09-25 04:31:20 -04:00
|
|
|
#include "../rom.h"
|
2017-09-02 20:39:57 +02:00
|
|
|
#include "../device.h"
|
2017-09-04 01:52:29 -04:00
|
|
|
#include "../nvr.h"
|
2017-10-01 17:30:02 -04:00
|
|
|
#include "../game/gameport.h"
|
2017-09-02 20:39:57 +02:00
|
|
|
#include "../keyboard.h"
|
|
|
|
|
#include "../keyboard_amstrad.h"
|
|
|
|
|
#include "../mouse.h"
|
2017-09-04 01:52:29 -04:00
|
|
|
#include "../lpt.h"
|
|
|
|
|
#include "../floppy/floppy.h"
|
|
|
|
|
#include "../floppy/fdd.h"
|
|
|
|
|
#include "../floppy/fdc.h"
|
2017-10-07 22:18:30 -04:00
|
|
|
#include "machine.h"
|
2016-06-26 00:34:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t amstrad_dead;
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
|
|
|
|
|
static uint8_t amstrad_read(uint16_t port, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
pclog("amstrad_read : %04X\n",port);
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0x379:
|
2017-05-07 04:56:34 +02:00
|
|
|
return 7;
|
2016-06-26 00:34:39 +02:00
|
|
|
case 0x37a:
|
|
|
|
|
if (romset == ROM_PC1512) return 0x20;
|
|
|
|
|
if (romset == ROM_PC200) return 0x80;
|
|
|
|
|
return 0;
|
|
|
|
|
case 0xdead:
|
|
|
|
|
return amstrad_dead;
|
|
|
|
|
}
|
|
|
|
|
return 0xff;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
|
|
|
|
|
static void amstrad_write(uint16_t port, uint8_t val, void *priv)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
switch (port)
|
|
|
|
|
{
|
|
|
|
|
case 0xdead:
|
|
|
|
|
amstrad_dead = val;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
|
2016-12-23 03:16:24 +01:00
|
|
|
static uint8_t mousex, mousey;
|
|
|
|
|
static void amstrad_mouse_write(uint16_t addr, uint8_t val, void *p)
|
|
|
|
|
{
|
|
|
|
|
if (addr == 0x78)
|
|
|
|
|
mousex = 0;
|
|
|
|
|
else
|
|
|
|
|
mousey = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint8_t amstrad_mouse_read(uint16_t addr, void *p)
|
|
|
|
|
{
|
|
|
|
|
if (addr == 0x78)
|
|
|
|
|
return mousex;
|
|
|
|
|
return mousey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct mouse_amstrad_t
|
|
|
|
|
{
|
|
|
|
|
int oldb;
|
|
|
|
|
} mouse_amstrad_t;
|
|
|
|
|
|
2017-05-05 01:49:42 +02:00
|
|
|
static uint8_t mouse_amstrad_poll(int x, int y, int z, int b, void *p)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
|
|
|
|
mouse_amstrad_t *mouse = (mouse_amstrad_t *)p;
|
|
|
|
|
|
|
|
|
|
mousex += x;
|
|
|
|
|
mousey -= y;
|
|
|
|
|
|
|
|
|
|
if ((b & 1) && !(mouse->oldb & 1))
|
|
|
|
|
keyboard_send(0x7e);
|
|
|
|
|
if ((b & 2) && !(mouse->oldb & 2))
|
|
|
|
|
keyboard_send(0x7d);
|
|
|
|
|
if (!(b & 1) && (mouse->oldb & 1))
|
|
|
|
|
keyboard_send(0xfe);
|
|
|
|
|
if (!(b & 2) && (mouse->oldb & 2))
|
|
|
|
|
keyboard_send(0xfd);
|
|
|
|
|
|
|
|
|
|
mouse->oldb = b;
|
2017-05-05 01:49:42 +02:00
|
|
|
|
|
|
|
|
return(0);
|
2016-12-23 03:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
|
|
|
|
|
static void *mouse_amstrad_init(void)
|
2016-12-23 03:16:24 +01:00
|
|
|
{
|
|
|
|
|
mouse_amstrad_t *mouse = (mouse_amstrad_t *)malloc(sizeof(mouse_amstrad_t));
|
|
|
|
|
memset(mouse, 0, sizeof(mouse_amstrad_t));
|
|
|
|
|
|
|
|
|
|
return mouse;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
|
2016-12-23 03:16:24 +01:00
|
|
|
static void mouse_amstrad_close(void *p)
|
|
|
|
|
{
|
|
|
|
|
mouse_amstrad_t *mouse = (mouse_amstrad_t *)p;
|
|
|
|
|
|
|
|
|
|
free(mouse);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
|
2016-12-23 03:16:24 +01:00
|
|
|
mouse_t mouse_amstrad =
|
|
|
|
|
{
|
|
|
|
|
"Amstrad mouse",
|
2017-05-05 01:49:42 +02:00
|
|
|
"amstrad",
|
|
|
|
|
MOUSE_TYPE_AMSTRAD,
|
2016-12-23 03:16:24 +01:00
|
|
|
mouse_amstrad_init,
|
|
|
|
|
mouse_amstrad_close,
|
2017-05-05 01:49:42 +02:00
|
|
|
mouse_amstrad_poll
|
2016-12-23 03:16:24 +01:00
|
|
|
};
|
|
|
|
|
|
2017-06-16 16:00:44 -04:00
|
|
|
|
2017-09-02 20:39:57 +02:00
|
|
|
static void amstrad_init(void)
|
2016-06-26 00:34:39 +02:00
|
|
|
{
|
|
|
|
|
lpt2_remove_ams();
|
|
|
|
|
|
2016-12-23 03:16:24 +01:00
|
|
|
io_sethandler(0x0078, 0x0001, amstrad_mouse_read, NULL, NULL, amstrad_mouse_write, NULL, NULL, NULL);
|
|
|
|
|
io_sethandler(0x007a, 0x0001, amstrad_mouse_read, NULL, NULL, amstrad_mouse_write, NULL, NULL, NULL);
|
2016-06-26 00:34:39 +02:00
|
|
|
io_sethandler(0x0379, 0x0002, amstrad_read, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
|
io_sethandler(0xdead, 0x0001, amstrad_read, NULL, NULL, amstrad_write, NULL, NULL, NULL);
|
|
|
|
|
}
|
2017-09-02 20:39:57 +02:00
|
|
|
|
|
|
|
|
|
2017-10-07 22:18:30 -04:00
|
|
|
void
|
|
|
|
|
machine_amstrad_init(machine_t *model)
|
2017-09-02 20:39:57 +02:00
|
|
|
{
|
2017-10-07 22:18:30 -04:00
|
|
|
machine_common_init(model);
|
|
|
|
|
|
2017-09-02 20:39:57 +02:00
|
|
|
amstrad_init();
|
|
|
|
|
keyboard_amstrad_init();
|
2017-10-03 16:26:55 -04:00
|
|
|
|
|
|
|
|
/* FIXME: make sure this is correct? */
|
|
|
|
|
nvr_at_init(1);
|
|
|
|
|
|
2017-09-02 20:39:57 +02:00
|
|
|
nmi_init();
|
|
|
|
|
fdc_set_dskchg_activelow();
|
|
|
|
|
if (joystick_type != 7)
|
|
|
|
|
device_add(&gameport_device);
|
|
|
|
|
}
|