From 46479aa1bde1ab236fff6e2a52308504bc1cb08e Mon Sep 17 00:00:00 2001 From: Melissa Goad Date: Sun, 22 Jan 2017 00:22:14 -0600 Subject: [PATCH 1/2] Add basic USB support sorta --- src/Makefile.am | 2 +- src/Makefile.mingw | 2 +- src/Makefile.mingw64 | 2 +- src/usb.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ src/usb.h | 32 +++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 src/usb.c create mode 100644 src/usb.h diff --git a/src/Makefile.am b/src/Makefile.am index 10ca53e8d..233d3c6a0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,7 +26,7 @@ olivetti_m24.c opti.c pc.c pci.c pic.c piix.c pit.c ppi.c ps1.c rom.c scat.c ser sound_ad1848.c sound_adlib.c sound_adlibgold.c sound_cms.c sound_emu8k.c sound_gus.c \ sound_mpu401_uart.c sound_opl.c sound_pas16.c sound_ps1.c sound_pssj.c sound_sb.c sound_sb_dsp.c sound_sn76489.c \ sound_speaker.c sound_ssi2001.c sound_wss.c sound_ym7128.c soundopenal.c tandy_eeprom.c tandy_rom.c thread-pthread.c \ -timer.c um8669f.c um8881f.c vid_ati_eeprom.c vid_ati_mach64.c vid_ati18800.c vid_ati28800.c \ +timer.c um8669f.c um8881f.c usb.c vid_ati_eeprom.c vid_ati_mach64.c vid_ati18800.c vid_ati28800.c \ vid_ati68860_ramdac.c vid_cga.c vid_cl_gd.c vid_cl_gd_blit.c vid_cl_ramdac.c vid_ega.c vid_et4000.c vid_et4000w32.c vid_hercules.c vid_herculesplus.c\ vid_icd2061.c vid_ics2595.c vid_incolor.c vid_mda.c vid_nv_riva128.c vid_olivetti_m24.c vid_oti067.c vid_paradise.c vid_pc200.c \ vid_pc1512.c vid_pc1640.c vid_pcjr.c vid_ps1_svga.c vid_s3.c vid_s3_virge.c vid_sdac_ramdac.c \ diff --git a/src/Makefile.mingw b/src/Makefile.mingw index e3e69794a..ec298348f 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -13,7 +13,7 @@ OBJ = 386.o 386_dynarec.o 386_dynarec_ops.o 808x.o acer386sx.o acerm3a.o ali1429 scat.o scsi.o serial.o sis496.o sis85c471.o sio.o sound.o sound_ad1848.o sound_adlib.o sound_adlibgold.o sound_cms.o \ sound_dbopl.o sound_emu8k.o sound_gus.o sound_mpu401_uart.o sound_opl.o sound_pas16.o sound_ps1.o sound_pssj.o sound_resid.o \ sound_sb.o sound_sb_dsp.o sound_sn76489.o sound_speaker.o sound_ssi2001.o sound_wss.o sound_ym7128.o \ - soundopenal.o tandy_eeprom.o tandy_rom.o timer.o um8669f.o vid_ati_eeprom.o vid_ati_mach64.o vid_ati18800.o \ + soundopenal.o tandy_eeprom.o tandy_rom.o timer.o um8669f.o usb.o vid_ati_eeprom.o vid_ati_mach64.o vid_ati18800.o \ vid_ati28800.o vid_ati68860_ramdac.o vid_bt485_ramdac.o vid_cga.o vid_cl_gd.o vid_cl_gd_blit.o vid_cl_ramdac.o vid_colorplus.o vid_ega.o vid_et4000.o \ vid_et4000w32.o vid_hercules.o vid_herculesplus.o vid_icd2061.o vid_ics2595.o vid_incolor.o vid_mda.o vid_nv_riva128.o \ vid_olivetti_m24.o vid_oti067.o vid_paradise.o vid_pc1512.o vid_pc1640.o vid_pc200.o \ diff --git a/src/Makefile.mingw64 b/src/Makefile.mingw64 index a18c8d8f3..389e2296e 100644 --- a/src/Makefile.mingw64 +++ b/src/Makefile.mingw64 @@ -13,7 +13,7 @@ OBJ = 386.o 386_dynarec.o 386_dynarec_ops.o 808x.o acer386sx.o acerm3a.o ali1429 scat.o scsi.o serial.o sis496.o sis85c471.o sio.o sound.o sound_ad1848.o sound_adlib.o sound_adlibgold.o sound_cms.o \ sound_dbopl.o sound_emu8k.o sound_gus.o sound_mpu401_uart.o sound_opl.o sound_pas16.o sound_ps1.o sound_pssj.o sound_resid.o \ sound_sb.o sound_sb_dsp.o sound_sn76489.o sound_speaker.o sound_ssi2001.o sound_wss.o sound_ym7128.o \ - soundopenal.o tandy_eeprom.o tandy_rom.o timer.o um8669f.o vid_ati_eeprom.o vid_ati_mach64.o vid_ati18800.o \ + soundopenal.o tandy_eeprom.o tandy_rom.o timer.o um8669f.o usb.o vid_ati_eeprom.o vid_ati_mach64.o vid_ati18800.o \ vid_ati28800.o vid_ati68860_ramdac.o vid_bt485_ramdac.o vid_cga.o vid_cl_gd.o vid_cl_gd_blit.o vid_cl_ramdac.o vid_colorplus.o vid_ega.o vid_et4000.o \ vid_et4000w32.o vid_hercules.o vid_herculesplus.ovid_icd2061.o vid_ics2595.o vid_incolor.o vid_mda.o vid_nv_riva128.o \ vid_olivetti_m24.o vid_oti067.o vid_paradise.o vid_pc1512.o vid_pc1640.o vid_pc200.o \ diff --git a/src/usb.c b/src/usb.c new file mode 100644 index 000000000..9a1d424c0 --- /dev/null +++ b/src/usb.c @@ -0,0 +1,48 @@ +/* Copyright holders: Melissa Goad + see COPYING for more details +*/ + +#include + +#include "ibm.h" +#include "io.h" +#include "mem.h" + +#include "usb.h" + +uint8_t (*usb_packet_handle[32])(usb_packet_t* packet, void *priv); +void *usb_priv[32]; +static int usb_min_card, usb_max_card; + +void usb_init(int min_card, int max_card) +{ + int c; + + for (c = 0; c < 32; c++) + usb_packet_handle[c] = usb_priv[c] = NULL; + + usb_min_card = min_card; + usb_max_card = max_card; +} + +void usb_add_specific(int card, void (*packet_handle)(usb_packet_t *packet, void *priv), void *priv) +{ + usb_packet_handle[card] = packet_handle; + usb_priv[card] = priv; +} + +void usb_add(void (*packet_handle)(usb_packet_t *packet, void *priv), void *priv) +{ + int c; + + for (c = usb_min_card; c <= usb_max_card; c++) + { + if (!usb_packet_handle[c]) + { + usb_packet_handle[c] = packet_handle; + usb_priv[c] = priv; + // pclog("USB device added to card: %i\n", c); + return; + } + } +} \ No newline at end of file diff --git a/src/usb.h b/src/usb.h new file mode 100644 index 000000000..b61e702f2 --- /dev/null +++ b/src/usb.h @@ -0,0 +1,32 @@ +/* Copyright holders: Melissa Goad + see COPYING for more details +*/ + +typedef struct +{ + uint8_t pid; //low 4 bits are the real pid, top 4 bits are just ~pid + uint8_t dev_addr; + uint8_t dev_endpoint; + uint8_t* data; + int len; + void* device; +} usb_packet_t; + +typedef enum +{ + USB_DEV_TYPE_NONE = 0, + USB_DEV_TYPE_MOUSE, + USB_DEV_TYPE_TABLET, + USB_DEV_TYPE_KEYPAD, + USB_DEV_TYPE_DISK, + USB_DEV_TYPE_CDROM, + USB_DEV_TYPE_HUB, + USB_DEV_TYPE_PRINTER +} usb_device_type_t; + +typedef enum +{ + USB_PID_TOKEN_SETUP = 0x2d, + USB_PID_TOKEN_IN = 0x69, + USB_PID_TOKEN_OUT = 0xe1 +} usb_pid_type_t; \ No newline at end of file From f52213d4e322c19452a2860cf2517bc7b14d79b6 Mon Sep 17 00:00:00 2001 From: Melissa Goad Date: Sun, 22 Jan 2017 00:35:15 -0600 Subject: [PATCH 2/2] Add more PID token types --- src/usb.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/usb.h b/src/usb.h index b61e702f2..69adcf96b 100644 --- a/src/usb.h +++ b/src/usb.h @@ -7,7 +7,9 @@ typedef struct uint8_t pid; //low 4 bits are the real pid, top 4 bits are just ~pid uint8_t dev_addr; uint8_t dev_endpoint; - uint8_t* data; + int crc5; + uint16_t crc16; + uint8_t data[1024]; int len; void* device; } usb_packet_t; @@ -26,7 +28,14 @@ typedef enum typedef enum { + USB_PID_TOKEN_STALL = 0x1e, USB_PID_TOKEN_SETUP = 0x2d, + USB_PID_TOKEN_PRE = 0x3c, + USB_PID_TOKEN_DATA1 = 0x4b, + USB_PID_TOKEN_NAK = 0x5a, USB_PID_TOKEN_IN = 0x69, + USB_PID_TOKEN_SOF = 0xa5, + USB_PID_TOKEN_DATA0 = 0xc3, + USB_PID_TOKEN_ACK = 0xd2, USB_PID_TOKEN_OUT = 0xe1 } usb_pid_type_t; \ No newline at end of file