Skip to content

Commit

Permalink
Bochs USB
Browse files Browse the repository at this point in the history
  • Loading branch information
Cacodemon345 committed Mar 22, 2024
1 parent d2c5420 commit f69c243
Show file tree
Hide file tree
Showing 13 changed files with 3,870 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if(INSTRUMENT)
endif()

target_link_libraries(86Box cpu chipset mch dev mem fdd game cdrom zip mo hdd
net print scsi sio snd vid voodoo plat ui)
net print scsi sio snd usb vid voodoo plat ui)

if(WIN32 AND ARCH STREQUAL "i386")
if(MINGW)
Expand Down Expand Up @@ -145,6 +145,7 @@ endif()

add_subdirectory(cdrom)
add_subdirectory(chipset)
add_subdirectory(usb)

add_subdirectory(cpu)
if(NEW_DYNAREC)
Expand Down
5 changes: 4 additions & 1 deletion src/chipset/intel_piix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,7 @@ piix_speed_changed(void *priv)
static void *
piix_init(const device_t *info)
{
usb_params_t params;
piix_t *dev = (piix_t *) malloc(sizeof(piix_t));
memset(dev, 0, sizeof(piix_t));

Expand All @@ -1551,6 +1552,8 @@ piix_init(const device_t *info)
pci_add_card(PCI_ADD_SOUTHBRIDGE, piix_read, piix_write, dev, &dev->pci_slot);
piix_log("PIIX%i: Added to slot: %02X\n", dev->type, dev->pci_slot);
piix_log("PIIX%i: Added to slot: %02X\n", dev->type, dev->pci_slot);
params.pci_dev = &dev->pci_slot;
params.pci_conf = &dev->regs[2][0];

dev->bm[0] = device_add_inst(&sff8038i_device, 1);
dev->bm[1] = device_add_inst(&sff8038i_device, 2);
Expand All @@ -1569,7 +1572,7 @@ piix_init(const device_t *info)
sff_set_irq_mode(dev->bm[1], IRQ_MODE_MIRQ_0);

if (dev->type >= 3)
dev->usb = device_add(&usb_device);
dev->usb = device_add_parameters(&usb_device, &params);

if (dev->type > 3) {
dev->nvr = device_add(&piix4_nvr_device);
Expand Down
8 changes: 6 additions & 2 deletions src/chipset/via_pipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,7 @@ pipc_reset(void *priv)
static void *
pipc_init(const device_t *info)
{
usb_params_t usb_params;
pipc_t *dev = (pipc_t *) malloc(sizeof(pipc_t));
memset(dev, 0, sizeof(pipc_t));

Expand All @@ -1635,6 +1636,9 @@ pipc_init(const device_t *info)
dev->local = info->local;
pci_add_card(PCI_ADD_SOUTHBRIDGE, pipc_read, pipc_write, dev, &dev->pci_slot);

usb_params.pci_dev = &dev->pci_slot;
usb_params.pci_conf = &dev->usb_regs[0][0];

dev->bm[0] = device_add_inst(&sff8038i_device, 1);
sff_set_irq_mode(dev->bm[0], IRQ_MODE_LEGACY);
sff_set_irq_pin(dev->bm[0], PCI_INTA);
Expand All @@ -1658,9 +1662,9 @@ pipc_init(const device_t *info)
acpi_set_trap_update(dev->acpi, pipc_trap_update_586, dev);
}

dev->usb[0] = device_add_inst(&usb_device, 1);
dev->usb[0] = device_add_inst_parameters(&usb_device, 1, &usb_params);
if (dev->local >= VIA_PIPC_686A) {
dev->usb[1] = device_add_inst(&usb_device, 2);
dev->usb[1] = device_add_inst_parameters(&usb_device, 2, &usb_params);

dev->ac97 = device_add(&ac97_via_device);

Expand Down
2 changes: 1 addition & 1 deletion src/device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_library(dev OBJECT bugger.c cassette.c cartridge.c hasp.c hwm.c hwm_lm75.c h
keyboard_at.c
mouse.c mouse_bus.c mouse_serial.c mouse_ps2.c nec_mate_unk.c phoenix_486_jumper.c
serial_passthrough.c
novell_cardkey.c)
novell_cardkey.c mouse_wacom_tablet.c)

if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(86Box atomic)
Expand Down
26 changes: 20 additions & 6 deletions src/device/mouse_wacom_tablet.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,13 @@ wacom_write(UNUSED(struct serial_s *serial), void *priv, uint8_t data)
}
}

static int
wacom_poll(void *priv)
static mouse_wacom_t* instance;


static void
wacom_poll(void)
{
mouse_wacom_t *wacom = (mouse_wacom_t *) priv;
mouse_wacom_t *wacom = (mouse_wacom_t *) instance;
int delta_x;
int delta_y;
int b = mouse_get_buttons_ex();
Expand Down Expand Up @@ -456,7 +459,6 @@ wacom_poll(void *priv)
if (wacom->b != b)
wacom->oldb = wacom->b;
wacom->b = b;
return 0;
}

static int
Expand Down Expand Up @@ -570,6 +572,8 @@ wacom_report_timer(void *priv)
int y_diff = abs(relative_mode ? wacom->rel_y : (wacom->abs_y - wacom->last_abs_y));
int increment = wacom->suppressed_increment ? wacom->suppressed_increment : wacom->increment;

pclog("x_diff = %d, y_diff = %d\n", x_diff, y_diff);

timer_on_auto(&wacom->report_timer, wacom->transmit_period);
if ((((double) (tsc - wacom->reset_tsc)) / cpuclock * 1000.0) <= 10)
return;
Expand Down Expand Up @@ -665,6 +669,15 @@ wacom_init(const device_t *info)
}
else wacom_reset(dev);

serial_set_ri(dev->serial, 1);
serial_set_dcd(dev->serial, 1);
serial_set_cts(dev->serial, 1);
serial_set_dsr(dev->serial, 1);

mouse_set_poll_ex(wacom_poll);

instance = dev;

return dev;
}

Expand All @@ -687,6 +700,7 @@ wacom_close(void *priv)
if (dev && dev->serial && dev->serial->sd)
memset(dev->serial->sd, 0, sizeof(serial_device_t));

instance = NULL;
free(dev);
}

Expand Down Expand Up @@ -720,7 +734,7 @@ const device_t mouse_wacom_device = {
.init = wacom_init,
.close = wacom_close,
.reset = NULL,
{ .poll = wacom_poll },
{ .poll = NULL },
.speed_changed = wacom_speed_changed,
.force_redraw = NULL,
.config = wacom_config
Expand All @@ -734,7 +748,7 @@ const device_t mouse_wacom_artpad_device = {
.init = wacom_init,
.close = wacom_close,
.reset = NULL,
{ .poll = wacom_poll },
{ .poll = NULL },
.speed_changed = wacom_speed_changed,
.force_redraw = NULL,
.config = wacom_config
Expand Down
9 changes: 8 additions & 1 deletion src/include/86box/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
extern "C" {
#endif

typedef struct usb_params_t {
uint8_t* pci_dev;
uint8_t* pci_conf;
} usb_params_t;

typedef struct usb_t {
uint8_t uhci_io[32];
uint8_t ohci_mmio[4096];
Expand All @@ -30,10 +35,12 @@ typedef struct usb_t {
int ohci_enable;
uint32_t ohci_mem_base;
mem_mapping_t ohci_mmio_mapping;

void* usb_uhci_priv;
} usb_t;

/* Global variables. */
extern const device_t usb_device;
extern const device_t usb_device, usb_uhci_device;

/* Functions. */
extern void uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, int enable);
Expand Down
2 changes: 1 addition & 1 deletion src/machine/m_at_socket8.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ machine_at_p65up5_common_init(const machine_t *model, const device_t *northbridg

pci_init(PCI_CONFIG_TYPE_1);
pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0);
pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0);
pci_register_slot(0x01, PCI_CARD_SOUTHBRIDGE, 0, 0, 0, 0xf9);
pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3);
pci_register_slot(0x0A, PCI_CARD_NORMAL, 3, 4, 1, 2);
pci_register_slot(0x0B, PCI_CARD_NORMAL, 2, 3, 4, 1);
Expand Down
20 changes: 17 additions & 3 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,14 @@ uhci_reg_writew(uint16_t addr, uint16_t val, void *priv)
}
}

extern void uhci_update_io_mapping_new(void *priv, uint8_t base_l, uint8_t base_h, int enable);

void
uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, int enable)
{
uhci_update_io_mapping_new(dev->usb_uhci_priv, base_l, base_h, enable);

return;
if (dev->uhci_enable && (dev->uhci_io_base != 0x0000))
io_removehandler(dev->uhci_io_base, 0x20, uhci_reg_read, NULL, NULL, uhci_reg_write, uhci_reg_writew, NULL, dev);

Expand Down Expand Up @@ -368,11 +373,18 @@ ohci_update_mem_mapping(usb_t *dev, uint8_t base1, uint8_t base2, uint8_t base3,
mem_mapping_set_addr(&dev->ohci_mmio_mapping, dev->ohci_mem_base, 0x1000);
}

extern void *
usb_uhci_init_ext(UNUSED(const device_t *info), void* params);
extern void
usb_uhci_reset(void *priv);

static void
usb_reset(void *priv)
{
usb_t *dev = (usb_t *) priv;

usb_uhci_reset(dev->usb_uhci_priv);

memset(dev->uhci_io, 0x00, 128);
dev->uhci_io[0x0c] = 0x40;
dev->uhci_io[0x10] = dev->uhci_io[0x12] = 0x80;
Expand All @@ -394,11 +406,12 @@ usb_close(void *priv)
{
usb_t *dev = (usb_t *) priv;

free(dev->usb_uhci_priv);
free(dev);
}

static void *
usb_init(UNUSED(const device_t *info))
usb_init_ext(UNUSED(const device_t *info), void* params)
{
usb_t *dev;

Expand All @@ -420,6 +433,7 @@ usb_init(UNUSED(const device_t *info))
ohci_mmio_read, NULL, NULL,
ohci_mmio_write, NULL, NULL,
NULL, MEM_MAPPING_EXTERNAL, dev);
dev->usb_uhci_priv = usb_uhci_init_ext(info, params);
usb_reset(dev);

return dev;
Expand All @@ -428,9 +442,9 @@ usb_init(UNUSED(const device_t *info))
const device_t usb_device = {
.name = "Universal Serial Bus",
.internal_name = "usb",
.flags = DEVICE_PCI,
.flags = DEVICE_PCI | DEVICE_EXTPARAMS,
.local = 0,
.init = usb_init,
{ .init_ext = usb_init_ext, },
.close = usb_close,
.reset = usb_reset,
{ .available = NULL },
Expand Down
1 change: 1 addition & 0 deletions src/usb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_library(usb usb_hid.c usb_uhci_bochs.c usb_common.c)
Loading

0 comments on commit f69c243

Please sign in to comment.