diff --git a/src/Makefile.mingw b/src/Makefile.mingw index cb53dabfc..e002d4d55 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -8,7 +8,7 @@ # # Modified Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.37 2017/08/23 +# Version: @(#)Makefile.mingw 1.0.38 2017/08/24 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -197,7 +197,8 @@ DEVOBJ = bugger.o lpt.o $(SERIAL) \ mouse.o mouse_serial.o mouse_ps2.o mouse_bus.o \ fdd.o fdc.o fdi2raw.o \ hdd.o hdd_image.o \ - esdi_at.o mfm_at.o mfm_xebec.o hdd_esdi.o ide.o xtide.o piix.o \ + hdd_mfm_at.o hdd_mfm_xebec.o hdd_esdi_at.o hdd_esdi_mca.o \ + hdd_ide_at.o hdd_ide_xt.o piix.o \ disc.o \ disc_86f.o disc_fdi.o disc_imd.o disc_img.o \ disc_random.o disc_td0.o \ @@ -341,7 +342,7 @@ amstrad.o: ibm.h CPU/cpu.h io.h device.h model.h keyboard.h lpt.h mouse.h bugger.o: ibm.h io.h bugger.h -cdrom.o: 86box.h cdrom.h ibm.h ide.h piix.h scsi.h timer.h \ +cdrom.o: 86box.h cdrom.h ibm.h hdd_ide_at.h piix.h scsi.h timer.h \ WIN/plat_iodev.h cdrom_dosbox.o: cdrom_dosbox.h @@ -355,7 +356,7 @@ cdrom_null.o: ibm.h cdrom.h cdrom_ioctl.h compaq.o: ibm.h CPU/cpu.h mem.h device.h model.h config.o: cdrom.h config.h device.h disc.h fdc.h fdd.h ibm.h \ - CPU/cpu.h gameport.h ide.h hdd.h model.h mouse.h \ + CPU/cpu.h gameport.h hdd_ide_at.h hdd.h model.h mouse.h \ NETWORK/network.h nvr.h scsi.h WIN/plat_joystick.h \ WIN/plat_midi.h SOUND/snd_dbopl.h SOUND/snd_mpu401.h \ SOUND/snd_opl.h SOUND/sound.h VIDEO/video.h WIN/win.h \ @@ -370,8 +371,8 @@ disc_86f.o: LZF/lzf.h config.h dma.h disc.h disc_86f.h disc_random.h \ fdc.h fdd.h ibm.h disc_fdi.o: ibm.h disc.h disc_img.h disc_fdi.h fdc.h fdd.h fdi2raw.h \ - ibm.h disc.h disc_imd.h fdc.h fdd.h ibm.h config.h disc.h \ - disc_img.h fdc.h fdd.h + disc.h disc_imd.h fdc.h fdd.h config.h disc.h disc_img.h \ + fdc.h fdd.h disc_random.o: disc_random.h @@ -379,17 +380,14 @@ disc_td0.o: ibm.h disc.h disc_td0.h fdc.h fdd.h dma.o: ibm.h CPU/x86.h mem.h io.h dma.h -esdi_at.o: ibm.h device.h hdd_image.h io.h mem.h pic.h rom.h timer.h \ - esdi_at.h - fdc.o: ibm.h disc.h dma.h fdc.h fdd.h io.h pic.h timer.h -fdc37c665.o: ibm.h disc.h fdc.h fdd.h ide.h io.h lpt.h serial.h \ - fdc37c665.h ibm.h disc.h fdc.h fdd.h io.h ide.h \ +fdc37c665.o: ibm.h disc.h fdc.h fdd.h hdd_ide_at.h io.h lpt.h serial.h \ + fdc37c665.h disc.h fdc.h fdd.h io.h hdd_ide_at.h \ lpt.h serial.h fdc37c669.h -fdc37c932fr.o: ibm.h disc.h fdc.h fdd.h ide.h io.h lpt.h serial.h \ - fdc37c932fr.h +fdc37c932fr.o: ibm.h disc.h fdc.h fdd.h hdd_ide_at.h io.h lpt.h \ + serial.h fdc37c932fr.h fdd.o: ibm.h disc.h fdc.h fdd.h @@ -399,13 +397,26 @@ gameport.o: ibm.h CPU/cpu.h device.h io.h timer.h gameport.h \ joystick_ch_flightstick_pro.h joystick_standard.h \ joystick_sw_pad.h joystick_tm_fcs.h plat_joystick.h -hdd.o: ibm.h CPU/cpu.h device.h hdd.h model.h esdi_at.h \ - hdd_esdi.h mfm_at.h mfm_xebec.h xtide.h +hdd.o: ibm.h CPU/cpu.h device.h hdd.h model.h hdd_esdi_at.h \ + hdd_esdi_mca.h hdd_mfm_at.h hdd_mfm_xebec.h hdd_ide_xt.h -hdd_image.o: ibm.h ide.h hdd_image.h +hdd_image.o: ibm.h hdd_ide_at.h hdd_image.h -hdd_esdi.o: ibm.h device.h dma.h hdd_image.h io.h mca.h mem.h \ - pic.h rom.h timer.h hdd_esdi.h +hdd_esdi_at.o: ibm.h device.h hdd_image.h io.h mem.h pic.h rom.h timer.h \ + hdd_esdi_at.h + +hdd_esdi_mca.o: ibm.h device.h dma.h hdd_image.h io.h mca.h mem.h \ + pic.h rom.h timer.h hdd_esdi_mca.h + +hdd_ide_at.o: 86box.h cdrom.h hdd_image.h ibm.h io.h pic.h timer.h \ + cdrom.h scsi.h hdd_ide_at.h + +hdd_ide_xt.o: ibm.h io.h mem.h rom.h device.h hdd_ide_at.h hdd_ide_xt.h + +hdd_mfm_at.o: ibm.h device.h hdd_image.h io.h pic.h timer.h hdd_mfm_at.h + +hdd_mfm_xebec.o: ibm.h device.h dma.h hdd_image.h io.h mem.h pic.h rom.h \ + timer.h hdd_mfm_xebec.h headland.o: ibm.h CPU/cpu.h io.h mem.h device.h model.h @@ -421,8 +432,6 @@ i430vx.o: ibm.h CPU/cpu.h io.h mem.h pci.h device.h model.h i440fx.o: ibm.h CPU/cpu.h io.h mem.h pci.h device.h model.h -ide.o: 86box.h cdrom.h hdd_image.h ibm.h io.h pic.h timer.h cdrom.h scsi.h ide.h - intel.o: ibm.h CPU/cpu.h io.h mem.h pit.h timer.h intel.h intel_flash.o: ibm.h CPU/cpu.h device.h mem.h model.h rom.h @@ -474,21 +483,16 @@ mem.o: ibm.h CPU/cpu.h CPU/x86_ops.h CPU/x86.h config.h \ memregs.o: ibm.h io.h memregs.h -mfm_at.o: ibm.h device.h hdd_image.h io.h pic.h timer.h mfm_at.h - -mfm_xebec.o: ibm.h device.h dma.h hdd_image.h io.h mem.h pic.h rom.h timer.h mfm_xebec.h - model.o: ibm.h io.h mem.h rom.h device.h model.h CPU/cpu.h \ - mouse.h cdrom.h disc.h dma.h fdc.h \ - fdc37c665.h fdc37c669.h fdc37c932fr.h \ - gameport.h ide.h intel.h intel_flash.h \ + mouse.h cdrom.h disc.h dma.h fdc.h fdc37c665.h fdc37c669.h \ + fdc37c932fr.h gameport.h hdd_ide_at.h intel.h intel_flash.h \ keyboard_amstrad.h keyboard_at.h keyboard_olim24.h \ keyboard_pcjr.h keyboard_xt.h lpt.h mem.h memregs.h \ nmi.h nvr.h pc87306.h pci.h pic.h piix.h pit.h ps2_mca.h \ serial.h sis85c471.h sio.h SOUND/snd_ps1.h SOUND/snd_pssj.h \ SOUND/snd_sn76489.h tandy_eeprom.h tandy_rom.h \ VIDEO/vid_pcjr.h VIDEO/vid_tandy.h w83877f.h wd76c10.h \ - xtide.h bugger.h + hdd_ide_xt.h bugger.h mouse.o: ibm.h CPU/cpu.h device.h model.h mouse.h keyboard_olim24.h @@ -513,21 +517,22 @@ pc.o: 86box.h ibm.h mem.h CPU/cpu.h CPU/x86_ops.h CPU/codegen.h \ dma.h nvr.h pic.h pit.h timer.h device.h model.h disc.h \ disc_86f.h disc_fdi.h disc_imd.h disc_img.h disc_td0.h \ disc_random.h config.h fdc.h fdd.h gameport.h plat_joystick.h \ - plat_midi.h hdd.h ide.h cdrom.h cdrom_ioctl.h cdrom_image.h \ - cdrom_null.h scsi.h keyboard.h plat_keyboard.h keyboard_at.h \ - mouse.h plat_mouse.h NETWORK/network.h serial.h \ + plat_midi.h hdd.h hdd_ide_at.h cdrom.h cdrom_ioctl.h \ + cdrom_image.h cdrom_null.h scsi.h keyboard.h plat_keyboard.h \ + keyboard_at.h mouse.h plat_mouse.h NETWORK/network.h serial.h \ SOUND/sound.h SOUND/snd_cms.h SOUND/snd_dbopl.h \ SOUND/snd_mpu401.h SOUND/snd_opl.h SOUND/snd_gus.h \ SOUND/snd_sb.h SOUND/snd_speaker.h SOUND/snd_ssi2001.h \ VIDEO/video.h VIDEO/vid_voodoo.h WIN/plat_ui.h -pc87306.o: ibm.h disc.h fdc.h fdd.h ide.h io.h lpt.h serial.h pc87306.h +pc87306.o: ibm.h disc.h fdc.h fdd.h hdd_ide_at.h io.h lpt.h serial.h \ + pc87306.h pci.o: ibm.h io.h mem.h pic.h pci.h pic.o: ibm.h io.h pic.h pit.h -piix.o: ibm.h dma.h ide.h io.h mem.h pci.h piix.h +piix.o: ibm.h dma.h hdd_ide_at.h io.h mem.h pci.h piix.h pit.o: ibm.h CPU/cpu.h dma.h io.h pic.h pit.h device.h timer.h \ model.h SOUND/snd_speaker.h video/video.h @@ -561,21 +566,21 @@ scsi_buslogic.o: ibm.h io.h mem.h rom.h dma.h pic.h pci.h timer.h \ device.h scsi.h scsi_device.h scsi_disk.h cdrom.h \ scsi_buslogic.h -scsi_disk.o: 86box.h cdrom.h hdd_image.h ibm.h ide.h piix.h scsi.h \ +scsi_disk.o: 86box.h cdrom.h hdd_image.h ibm.h hdd_ide_at.h piix.h scsi.h \ scsi_disk.h timer.h WIN/plat_iodev.h serial.o: ibm.h io.h pic.h timer.h serial.h plat_serial.h serial_old.o: ibm.h io.h mouse.h pic.h serial.h timer.h -sio.o: ibm.h cdrom.h disc.h dma.h fdc.h keyboard_at.h ide.h \ - io.h mem.h pci.h sio.h +sio.o: ibm.h cdrom.h disc.h dma.h fdc.h keyboard_at.h io.h mem.h \ + hdd_ide_at.h pci.h sio.h sis496.o: ibm.h CPU/cpu.h io.h mem.h pci.h device.h model.h sis50x.o: ibm.h device.h io.h mem.h pci.h sis50x.h -sis85c471.o: ibm.h ide.h disc.h fdc.h fdd.h io.h lpt.h serial.h sis85c471.h +sis85c471.o: ibm.h hdd_ide_at.h disc.h fdc.h fdd.h io.h lpt.h serial.h sis85c471.h superio_detect.o: ibm.h io.h disc.h fdd.h fdc.h superio_detect.h @@ -591,8 +596,6 @@ w83877f.o: ibm.h disc.h fdc.h fdd.h io.h lpt.h serial.h w83877f.h wd76c10.o: ibm.h disc.h fdc.h io.h mem.h serial.h wd76c10.h -xtide.o: ibm.h io.h mem.h rom.h device.h ide.h xtide.h - 386.o: ibm.h CPU/cpu.h CPU/x86.h CPU/x87.h mem.h disc.h fdc.h pic.h timer.h CPU/386_common.h 386_dynarec.o: ibm.h CPU/cpu.h CPU/x86.h CPU/x86_ops.h CPU/x87.h mem.h CPU/codegen.h disc.h fdc.h pic.h timer.h CPU/386_common.h \ @@ -772,7 +775,7 @@ video.o: ibm.h CPU/cpu.h io.h mem.h rom.h config.h device.h timer.h WIN/plat_th VIDEO/vid_pc200.h VIDEO/vid_pcjr.h VIDEO/vid_ps1_svga.h VIDEO/vid_s3.h VIDEO/vid_s3_virge.h VIDEO/vid_tandy.h \ VIDEO/vid_tandysl.h VIDEO/vid_tgui9440.h VIDEO/vid_tvga.h VIDEO/vid_vga.h VIDEO/vid_wy700.h -win.o: 86box.h device.h disc.h fdd.h hdd.h ibm.h CPU/cpu.h mem.h rom.h nvr.h config.h model.h ide.h cdrom.h cdrom_null.h \ +win.o: 86box.h device.h disc.h fdd.h hdd.h ibm.h CPU/cpu.h mem.h rom.h nvr.h config.h model.h hdd_ide_at.h cdrom.h cdrom_null.h \ cdrom_ioctl.h cdrom_image.h scsi.h scsi_disk.h VIDEO/video.h VIDEO/vid_ega.h mouse.h SOUND/sound.h SOUND/snd_dbopl.h \ WIN/plat_keyboard.h WIN/plat_iodev.h WIN/plat_mouse.h WIN/plat_midi.h WIN/plat_thread.h WIN/plat_ticks.h WIN/plat_ui.h \ WIN/resource.h WIN/win.h WIN/win_cgapal.h WIN/win_ddraw.h WIN/win_d3d.h WIN/win_language.h @@ -799,7 +802,7 @@ win_joystickconfig.o: ibm.h config.h device.h gameport.h WIN/plat_joystick.h WIN win_keyboard.o: device.h WIN/plat_keyboard.h WIN/resource.h WIN/win.h -win_language.o: ibm.h device.h ide.h WIN/plat_ui.h WIN/resource.h WIN/win.h WIN/win_language.h io.h mem.h rom.h device.h ide.h xtide.h +win_language.o: ibm.h device.h WIN/plat_ui.h WIN/resource.h WIN/win.h WIN/win_language.h win_midi.o: ibm.h config.h SOUND/midi.h WIN/plat_midi.h WIN/resource.h @@ -809,7 +812,7 @@ win_opendir.o: ibm.h WIN/plat_dir.h WIN/resource.h win_serial.o: WIN/plat_thread.h WIN/plat_serial.h WIN/resource.h -win_settings.o: ibm.h mem.h CPU/cpu.h nvr.h device.h model.h cdrom.h disc.h fdd.h hdd.h ide.h scsi.h NETWORK/network.h SOUND/midi.h \ +win_settings.o: ibm.h mem.h CPU/cpu.h nvr.h device.h model.h cdrom.h disc.h fdd.h hdd.h hdd_ide_at.h scsi.h NETWORK/network.h SOUND/midi.h \ SOUND/sound.h SOUND/snd_dbopl.h SOUND/snd_mpu401.h VIDEO/video.h VIDEO/vid_voodoo.h gameport.h mouse.h WIN/plat_midi.h \ WIN/resource.h WIN/win.h WIN/win_language.h diff --git a/src/WIN/86Box.rc b/src/WIN/86Box.rc index 24fe7a2f8..c7d57db46 100644 --- a/src/WIN/86Box.rc +++ b/src/WIN/86Box.rc @@ -8,11 +8,11 @@ * * Windows resource script. * - * Version: @(#)86Box.rc 1.0.5 2017/08/08 + * Version: @(#)86Box.rc 1.0.6 2017/08/24 * * Authors: Miran Grca, * Fred N. van Kempen, - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #include #define IN_RESOURCE_H @@ -833,10 +833,10 @@ BEGIN IDS_4111 "This image exists and will be overwritten.\nAre you sure you want to use it?" IDS_4112 "Please enter a valid file name" IDS_4113 "Remember to partition and format the new drive" - IDS_4114 "MFM or ESDI CD-ROM drives never existed" + IDS_4114 "MFM/RLL or ESDI CD-ROM drives never existed" IDS_4115 "Removable disk %i (SCSI): %ws" - IDS_4352 "MFM" + IDS_4352 "MFM/RLL" IDS_4353 "XT IDE" IDS_4354 "ESDI" IDS_4355 "IDE (PIO-only)" @@ -844,7 +844,7 @@ BEGIN IDS_4357 "SCSI" IDS_4358 "SCSI (removable)" - IDS_4608 "MFM (%01i:%01i)" + IDS_4608 "MFM/RLL (%01i:%01i)" IDS_4609 "XT IDE (%01i:%01i)" IDS_4610 "ESDI (%01i:%01i)" IDS_4611 "IDE (PIO-only) (%01i:%01i)" diff --git a/src/WIN/resource.h b/src/WIN/resource.h index bd4bf3ea3..3b131f54b 100644 --- a/src/WIN/resource.h +++ b/src/WIN/resource.h @@ -9,14 +9,15 @@ * Windows resource defines. * * NOTE: FIXME: Strings 2176 and 2193 are same. + * NOTE: FIXME: string 2095 not in use. * - * Version: @(#)resource.h 1.0.4 2017/06/16 + * Version: @(#)resource.h 1.0.5 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempem, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #ifndef WIN_RESOURCE_H # define WIN_RESOURCE_H @@ -245,7 +246,7 @@ #define IDS_2092 2092 // "Bus" #define IDS_2093 2093 // "DMA" #define IDS_2094 2094 // "KB" -#define IDS_2095 2095 // "MFM, RLL, or ESDI CD-ROM.." +#define IDS_2095 2095 #define IDS_2096 2096 // "Slave" #define IDS_2097 2097 // "SCSI (ID %s, LUN %s)" #define IDS_2098 2098 // "Adapter Type" @@ -317,7 +318,7 @@ #define IDS_2164 2164 // "Invalid number of sectors.." #define IDS_2165 2165 // "MFM" #define IDS_2166 2166 // "XT IDE" -#define IDS_2167 2167 // "RLL" +#define IDS_2167 2167 // "ESDI" #define IDS_2168 2168 // "IDE (PIO-only)" #define IDS_2169 2169 // "%01i:%01i" #define IDS_2170 2170 // "%01i:%01i" diff --git a/src/WIN/win.c b/src/WIN/win.c index cf95c4eec..8c8fef00f 100644 --- a/src/WIN/win.c +++ b/src/WIN/win.c @@ -8,7 +8,7 @@ * * The Emulator's Windows core. * - * Version: @(#)win.c 1.0.4 2017/08/23 + * Version: @(#)win.c 1.0.6 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, @@ -33,7 +33,7 @@ #include "../nvr.h" #include "../config.h" #include "../model.h" -#include "../ide.h" +#include "../hdd_ide_at.h" #include "../cdrom.h" #include "../cdrom_null.h" #include "../cdrom_ioctl.h" @@ -1056,7 +1056,7 @@ void update_status_bar_panes(HWND hwnds) int edge = 0; int c_mfm = 0; - int c_rll = 0; + int c_esdi = 0; int c_xtide = 0; int c_ide_pio = 0; int c_ide_dma = 0; @@ -1067,7 +1067,7 @@ void update_status_bar_panes(HWND hwnds) sb_ready = 0; c_mfm = count_hard_disks(HDD_BUS_MFM); - c_rll = count_hard_disks(HDD_BUS_RLL); + c_esdi = count_hard_disks(HDD_BUS_ESDI); c_xtide = count_hard_disks(HDD_BUS_XTIDE); c_ide_pio = count_hard_disks(HDD_BUS_IDE_PIO_ONLY); c_ide_dma = count_hard_disks(HDD_BUS_IDE_PIO_AND_DMA); @@ -1148,7 +1148,7 @@ void update_status_bar_panes(HWND hwnds) { sb_parts++; } - if (c_rll && !memcmp(hdd_controller_name, "esdi", 4)) + if (c_esdi && !memcmp(hdd_controller_name, "esdi", 4)) { sb_parts++; } @@ -1240,11 +1240,11 @@ void update_status_bar_panes(HWND hwnds) sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_MFM; sb_parts++; } - if (c_rll && !memcmp(hdd_controller_name, "esdi", 4)) + if (c_esdi && !memcmp(hdd_controller_name, "esdi", 4)) { edge += SB_ICON_WIDTH; iStatusWidths[sb_parts] = edge; - sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_RLL; + sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_ESDI; sb_parts++; } if (c_xtide && !memcmp(hdd_controller_name, "xtide", 5)) diff --git a/src/WIN/win_language.c b/src/WIN/win_language.c index 4b83261ce..4c0d761b3 100644 --- a/src/WIN/win_language.c +++ b/src/WIN/win_language.c @@ -8,12 +8,12 @@ * * Windows localization core. * - * Version: @(#)win_language.c 1.0.0 2017/05/30 + * Version: @(#)win_language.c 1.0.1 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #include #define UNICODE @@ -27,7 +27,6 @@ #include "../ibm.h" #include "../device.h" -#include "../ide.h" #include "plat_ui.h" #include "win.h" #include "win_language.h" diff --git a/src/WIN/win_settings.c b/src/WIN/win_settings.c index f6332b0a8..8713a19e9 100644 --- a/src/WIN/win_settings.c +++ b/src/WIN/win_settings.c @@ -8,10 +8,10 @@ * * Windows 86Box Settings dialog handler. * - * Version: @(#)win_settings.c 1.0.7 2017/08/23 + * Version: @(#)win_settings.c 1.0.8 2017/08/24 * * Author: Miran Grca, - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #define UNICODE #define BITMAP WINDOWS_BITMAP @@ -31,7 +31,7 @@ #include "../disc.h" #include "../fdd.h" #include "../hdd.h" -#include "../ide.h" +#include "../hdd_ide_at.h" #include "../scsi.h" #include "../NETWORK/network.h" #include "../SOUND/sound.h" @@ -1980,7 +1980,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) EnableWindow(h, TRUE); SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdc.xtide_channel : temp_hdc[hdlv_current_sel].xtide_channel, 0); break; - case HDD_BUS_RLL: /* RLL */ + case HDD_BUS_ESDI: /* ESDI */ h = GetDlgItem(hdlg, IDT_1722); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); @@ -1988,7 +1988,7 @@ static void recalc_location_controls(HWND hdlg, int is_add_dlg) h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdc.rll_channel : temp_hdc[hdlv_current_sel].rll_channel, 0); + SendMessage(h, CB_SETCURSEL, is_add_dlg ? new_hdc.esdi_channel : temp_hdc[hdlv_current_sel].esdi_channel, 0); break; case HDD_BUS_IDE_PIO_ONLY: /* IDE (PIO-only) */ case HDD_BUS_IDE_PIO_AND_DMA: /* IDE (PIO and DMA) */ @@ -2050,7 +2050,7 @@ static void recalc_next_free_id(HWND hdlg) int i; int c_mfm = 0; - int c_rll = 0; + int c_esdi = 0; int c_xtide = 0; int c_ide_pio = 0; int c_ide_dma = 0; @@ -2065,9 +2065,9 @@ static void recalc_next_free_id(HWND hdlg) { c_mfm++; } - else if (temp_hdc[i].bus == HDD_BUS_RLL) + else if (temp_hdc[i].bus == HDD_BUS_ESDI) { - c_rll++; + c_esdi++; } else if (temp_hdc[i].bus == HDD_BUS_XTIDE) { @@ -2104,7 +2104,7 @@ static void recalc_next_free_id(HWND hdlg) enable_add = enable_add || (next_free_id >= 0); /* pclog("Enable add: %i\n", enable_add); */ - enable_add = enable_add && ((c_mfm < MFM_NUM) || (c_rll < RLL_NUM) || (c_xtide < XTIDE_NUM) || (c_ide_pio < IDE_NUM) || (c_ide_dma < IDE_NUM) || (c_scsi < SCSI_NUM)); + enable_add = enable_add && ((c_mfm < MFM_NUM) || (c_esdi < ESDI_NUM) || (c_xtide < XTIDE_NUM) || (c_ide_pio < IDE_NUM) || (c_ide_dma < IDE_NUM) || (c_scsi < SCSI_NUM)); /* pclog("Enable add: %i\n", enable_add); */ h = GetDlgItem(hdlg, IDC_BUTTON_HDD_ADD_NEW); @@ -2131,7 +2131,7 @@ static void recalc_next_free_id(HWND hdlg) h = GetDlgItem(hdlg, IDC_BUTTON_HDD_REMOVE); - if ((c_mfm == 0) && (c_rll == 0) && (c_xtide == 0) && (c_ide_pio == 0) && (c_ide_dma == 0) && (c_scsi == 0)) + if ((c_mfm == 0) && (c_esdi == 0) && (c_xtide == 0) && (c_ide_pio == 0) && (c_ide_dma == 0) && (c_scsi == 0)) { EnableWindow(h, FALSE); } @@ -2162,8 +2162,8 @@ static void win_settings_hard_disks_update_item(HWND hwndList, int i, int column case HDD_BUS_XTIDE: wsprintf(szText, win_language_get_string_from_id(IDS_4609), temp_hdc[i].xtide_channel >> 1, temp_hdc[i].xtide_channel & 1); break; - case HDD_BUS_RLL: - wsprintf(szText, win_language_get_string_from_id(IDS_4610), temp_hdc[i].rll_channel >> 1, temp_hdc[i].rll_channel & 1); + case HDD_BUS_ESDI: + wsprintf(szText, win_language_get_string_from_id(IDS_4610), temp_hdc[i].esdi_channel >> 1, temp_hdc[i].esdi_channel & 1); break; case HDD_BUS_IDE_PIO_ONLY: wsprintf(szText, win_language_get_string_from_id(IDS_4611), temp_hdc[i].ide_channel >> 1, temp_hdc[i].ide_channel & 1); @@ -2246,8 +2246,8 @@ static BOOL win_settings_hard_disks_recalc_list(HWND hwndList) case HDD_BUS_XTIDE: wsprintf(szText, win_language_get_string_from_id(IDS_4609), temp_hdc[i].xtide_channel >> 1, temp_hdc[i].xtide_channel & 1); break; - case HDD_BUS_RLL: - wsprintf(szText, win_language_get_string_from_id(IDS_4610), temp_hdc[i].rll_channel >> 1, temp_hdc[i].rll_channel & 1); + case HDD_BUS_ESDI: + wsprintf(szText, win_language_get_string_from_id(IDS_4610), temp_hdc[i].esdi_channel >> 1, temp_hdc[i].esdi_channel & 1); break; case HDD_BUS_IDE_PIO_ONLY: wsprintf(szText, win_language_get_string_from_id(IDS_4611), temp_hdc[i].ide_channel >> 1, temp_hdc[i].ide_channel & 1); @@ -2650,9 +2650,9 @@ static BOOL CALLBACK win_settings_hard_disks_add_proc(HWND hdlg, UINT message, W h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); hdc_ptr->mfm_channel = SendMessage(h, CB_GETCURSEL, 0, 0); break; - case HDD_BUS_RLL: + case HDD_BUS_ESDI: h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); - hdc_ptr->rll_channel = SendMessage(h, CB_GETCURSEL, 0, 0); + hdc_ptr->esdi_channel = SendMessage(h, CB_GETCURSEL, 0, 0); break; case HDD_BUS_XTIDE: h = GetDlgItem(hdlg, IDC_COMBO_HD_CHANNEL); @@ -3093,7 +3093,7 @@ hdd_add_file_open_error: max_hpc = 15; max_tracks = 1023; break; - case HDD_BUS_RLL: + case HDD_BUS_ESDI: case HDD_BUS_XTIDE: max_spt = 63; max_hpc = 16; @@ -3315,9 +3315,9 @@ hd_bus_skip: { temp_hdc[hdlv_current_sel].mfm_channel = SendMessage(h, CB_GETCURSEL, 0, 0); } - else if (temp_hdc[hdlv_current_sel].bus == HDD_BUS_RLL) + else if (temp_hdc[hdlv_current_sel].bus == HDD_BUS_ESDI) { - temp_hdc[hdlv_current_sel].rll_channel = SendMessage(h, CB_GETCURSEL, 0, 0); + temp_hdc[hdlv_current_sel].esdi_channel = SendMessage(h, CB_GETCURSEL, 0, 0); } else if (temp_hdc[hdlv_current_sel].bus == HDD_BUS_XTIDE) { diff --git a/src/cdrom.c b/src/cdrom.c index 88c62ef67..bb28a7e41 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -9,24 +9,23 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * Version: @(#)cdrom.c 1.0.2 2017/08/23 + * Version: @(#)cdrom.c 1.0.3 2017/08/24 * * Author: Miran Grca, - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #include #include #include #include #include - #include "86box.h" #include "cdrom.h" #include "ibm.h" -#include "ide.h" #include "piix.h" #include "scsi.h" #include "timer.h" +#include "hdd_ide_at.h" #include "WIN/plat_iodev.h" /* Bits of 'status' */ diff --git a/src/config.c b/src/config.c index c52afec38..7b212edc2 100644 --- a/src/config.c +++ b/src/config.c @@ -8,15 +8,15 @@ * * Configuration file handler. * - * Version: @(#)config.c 1.0.1 2017/08/23 + * Version: @(#)config.c 1.0.2 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * Fred N. van Kempen, * Overdoze, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. - * Copyright 2017-2017 Fred N. van Kempen. + * Copyright 2016,2017 Miran Grca. + * Copyright 2017 Fred N. van Kempen. * * NOTE: Forcing config files to be in Unicode encoding breaks it on * Windows XP, and possibly also Vista. Use -DANSI_CFG for use @@ -37,8 +37,8 @@ #include "ibm.h" #include "CPU/cpu.h" #include "gameport.h" -#include "ide.h" #include "hdd.h" +#include "hdd_ide_at.h" #include "model.h" #include "mouse.h" #include "NETWORK/network.h" @@ -1172,18 +1172,12 @@ static int config_string_to_bus(char *str, int cdrom) return HDD_BUS_MFM; } - if (!strcmp(str, "rll")) + /* FIXME: delete 'rll' in a year or so.. --FvK */ + if (!strcmp(str, "esdi") || !strcmp(str, "rll")) { if (cdrom) goto no_mfm_cdrom; - return HDD_BUS_RLL; - } - - if (!strcmp(str, "esdi")) - { - if (cdrom) goto no_mfm_cdrom; - - return HDD_BUS_RLL; + return HDD_BUS_ESDI; } if (!strcmp(str, "ide_pio_only")) @@ -1362,7 +1356,7 @@ static void loadconfig_hard_disks(void) max_hpc = 15; max_tracks = 1023; break; - case HDD_BUS_RLL: + case HDD_BUS_ESDI: case HDD_BUS_XTIDE: max_spt = 63; max_hpc = 16; @@ -1417,11 +1411,11 @@ static void loadconfig_hard_disks(void) config_delete_var(cat, temps); } - /* RLL (ESDI) */ - sprintf(temps, "hdd_%02i_rll_channel", c + 1); - if (hdc[c].bus == HDD_BUS_RLL) + /* ESDI */ + sprintf(temps, "hdd_%02i_esdi_channel", c + 1); + if (hdc[c].bus == HDD_BUS_ESDI) { - hdc[c].rll_channel = !!config_get_int(cat, temps, c & 1); + hdc[c].esdi_channel = !!config_get_int(cat, temps, c & 1); } else { @@ -2296,8 +2290,8 @@ static char *config_bus_to_string(int bus, int cdrom) case HDD_BUS_XTIDE: return "xtide"; break; - case HDD_BUS_RLL: - return "rll"; + case HDD_BUS_ESDI: + return "esdi"; break; case HDD_BUS_IDE_PIO_ONLY: return cdrom ? "atapi_pio_only" : "ide_pio_only"; @@ -2361,14 +2355,14 @@ static void saveconfig_hard_disks(void) config_set_int(cat, temps, hdc[c].xtide_channel); } - sprintf(temps, "hdd_%02i_rll_channel", c + 1); - if (!hard_disk_is_valid(c) || (hdc[c].bus != HDD_BUS_RLL)) + sprintf(temps, "hdd_%02i_esdi_channel", c + 1); + if (!hard_disk_is_valid(c) || (hdc[c].bus != HDD_BUS_ESDI)) { config_delete_var(cat, temps); } else { - config_set_int(cat, temps, hdc[c].rll_channel); + config_set_int(cat, temps, hdc[c].esdi_channel); } sprintf(temps, "hdd_%02i_ide_channel", c + 1); diff --git a/src/device.c b/src/device.c index 93412ec2e..3d60d33b4 100644 --- a/src/device.c +++ b/src/device.c @@ -9,12 +9,12 @@ * Implementation of the generic device interface to handle * all devices attached to the emulator. * - * Version: @(#)device.c 1.0.1 2017/06/03 + * Version: @(#)device.c 1.0.2 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2016 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #include "ibm.h" #include "CPU/cpu.h" @@ -24,30 +24,34 @@ #include "SOUND/sound.h" -static void *device_priv[256]; -static device_t *devices[256]; +#define DEVICE_MAX 256 /* max # of devices */ + + +static void *device_priv[DEVICE_MAX]; +static device_t *devices[DEVICE_MAX]; static device_t *current_device; void device_init(void) { - memset(devices, 0, sizeof(devices)); + memset(devices, 0x00, sizeof(devices)); } + void device_add(device_t *d) { - int c = 0; - void *priv = NULL; + int c = 0; + void *priv = NULL; - while (devices[c] != NULL && c < 256) + while (devices[c] != NULL && c < 256) c++; - if (c >= 256) + if (c >= DEVICE_MAX) fatal("device_add : too many devices\n"); - current_device = d; + current_device = d; - if (d->init != NULL) + if (d->init != NULL) { priv = d->init(); if (priv == NULL) @@ -58,11 +62,12 @@ void device_add(device_t *d) device_priv[c] = priv; } -void device_close_all() + +void device_close_all(void) { int c; - - for (c = 0; c < 256; c++) + + for (c=0; cconfig; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) return config_get_int(current_device->name, s, config->default_int); @@ -165,11 +176,12 @@ int device_get_config_int(char *s) return 0; } + int device_get_config_int_ex(char *s, int default_int) { device_config_t *config = current_device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) return config_get_int(current_device->name, s, default_int); @@ -179,11 +191,12 @@ int device_get_config_int_ex(char *s, int default_int) return default_int; } + int device_get_config_hex16(char *s) { device_config_t *config = current_device->config; - - while (config->type != -1) + + while (config && config->type != -1) { if (!strcmp(s, config->name)) return config_get_hex16(current_device->name, s, config->default_int); @@ -193,11 +206,12 @@ int device_get_config_hex16(char *s) return 0; } + int device_get_config_hex20(char *s) { device_config_t *config = current_device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) return config_get_hex20(current_device->name, s, config->default_int); @@ -207,11 +221,12 @@ int device_get_config_hex20(char *s) return 0; } + int device_get_config_mac(char *s, int default_int) { device_config_t *config = current_device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) return config_get_mac(current_device->name, s, default_int); @@ -221,11 +236,12 @@ int device_get_config_mac(char *s, int default_int) return default_int; } + void device_set_config_int(char *s, int val) { device_config_t *config = current_device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) { @@ -235,14 +251,14 @@ void device_set_config_int(char *s, int val) config++; } - return; } + void device_set_config_hex16(char *s, int val) { device_config_t *config = current_device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) { @@ -252,14 +268,14 @@ void device_set_config_hex16(char *s, int val) config++; } - return; } + void device_set_config_hex20(char *s, int val) { device_config_t *config = current_device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) { @@ -269,14 +285,14 @@ void device_set_config_hex20(char *s, int val) config++; } - return; } + void device_set_config_mac(char *s, int val) { device_config_t *config = current_device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) { @@ -286,14 +302,14 @@ void device_set_config_mac(char *s, int val) config++; } - return; } + char *device_get_config_string(char *s) { device_config_t *config = current_device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) return config_get_string(current_device->name, s, config->default_string); @@ -303,6 +319,7 @@ char *device_get_config_string(char *s) return NULL; } + int model_get_config_int(char *s) { device_t *device = model_getdevice(model); @@ -313,7 +330,7 @@ int model_get_config_int(char *s) config = device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) return config_get_int(device->name, s, config->default_int); @@ -323,6 +340,7 @@ int model_get_config_int(char *s) return 0; } + char *model_get_config_string(char *s) { device_t *device = model_getdevice(model); @@ -333,7 +351,7 @@ char *model_get_config_string(char *s) config = device->config; - while (config->type != -1) + while (config && config->type != -1) { if (!strcmp(s, config->name)) return config_get_string(device->name, s, config->default_string); diff --git a/src/fdc37c665.c b/src/fdc37c665.c index c85a9df96..1fd4396d9 100644 --- a/src/fdc37c665.c +++ b/src/fdc37c665.c @@ -8,7 +8,7 @@ * * Implementation of the SMC FDC37C665 Super I/O Chip. * - * Version: @(#)fdc37c665.c 1.0.1 2017/08/23 + * Version: @(#)fdc37c665.c 1.0.2 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, @@ -16,14 +16,13 @@ * Copyright 2016-2017 Miran Grca. */ #include "ibm.h" - #include "disc.h" #include "fdc.h" #include "fdd.h" -#include "ide.h" #include "io.h" #include "lpt.h" #include "serial.h" +#include "hdd_ide_at.h" #include "fdc37c665.h" static uint8_t fdc37c665_lock[2]; diff --git a/src/fdc37c669.c b/src/fdc37c669.c index 33d19b8ba..343efc484 100644 --- a/src/fdc37c669.c +++ b/src/fdc37c669.c @@ -8,21 +8,19 @@ * * Implementation of the SMC FDC37C669 Super I/O Chip. * - * Version: @(#)fdc37c669.c 1.0.0 2017/05/30 + * Version: @(#)fdc37c669.c 1.0.1 2017/08/24 * * Author: Miran Grca, - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ - #include "ibm.h" - #include "disc.h" #include "fdc.h" #include "fdd.h" #include "io.h" -#include "ide.h" #include "lpt.h" #include "serial.h" +#include "hdd_ide_at.h" #include "fdc37c669.h" static int fdc37c669_locked; diff --git a/src/fdc37c932fr.c b/src/fdc37c932fr.c index 6b9f8aa05..8c382856c 100644 --- a/src/fdc37c932fr.c +++ b/src/fdc37c932fr.c @@ -8,21 +8,19 @@ * * Implementation of the SMC FDC37C932FR Super I/O Chip. * - * Version: @(#)fdc37c932fr.c 1.0.0 2017/05/30 + * Version: @(#)fdc37c932fr.c 1.0.1 2017/08/24 * * Author: Miran Grca, - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ - #include "ibm.h" - #include "disc.h" #include "fdc.h" #include "fdd.h" -#include "ide.h" #include "io.h" #include "lpt.h" #include "serial.h" +#include "hdd_ide_at.h" #include "fdc37c932fr.h" static int fdc37c932fr_locked; diff --git a/src/hdd.c b/src/hdd.c index 169410050..f1848fdc2 100644 --- a/src/hdd.c +++ b/src/hdd.c @@ -4,11 +4,11 @@ #include "hdd.h" #include "model.h" -#include "esdi_at.h" -#include "hdd_esdi.h" -#include "mfm_at.h" -#include "mfm_xebec.h" -#include "xtide.h" +#include "hdd_esdi_at.h" +#include "hdd_esdi_mca.h" +#include "hdd_mfm_at.h" +#include "hdd_mfm_xebec.h" +#include "hdd_ide_xt.h" char hdd_controller_name[16]; diff --git a/src/hdd_esdi.c b/src/hdd_esdi.c deleted file mode 100644 index eb9335836..000000000 --- a/src/hdd_esdi.c +++ /dev/null @@ -1,883 +0,0 @@ -#include -#include "ibm.h" - -#include "device.h" -#include "dma.h" -#include "hdd_image.h" -#include "io.h" -#include "mca.h" -#include "mem.h" -#include "pic.h" -#include "rom.h" -#include "timer.h" - -#include "hdd_esdi.h" - -#define ESDI_TIME (2000 * TIMER_USEC) - -#define CMD_ADAPTER 0 - -typedef struct esdi_drive_t -{ - int spt, hpc; - int tracks; - int sectors; - int present; - int hdc_num; -} esdi_drive_t; - -typedef struct esdi_t -{ - rom_t bios_rom; - - uint8_t basic_ctrl; - uint8_t status; - uint8_t irq_status; - - int irq_in_progress; - int cmd_req_in_progress; - - int cmd_pos; - uint16_t cmd_data[4]; - int cmd_dev; - - int status_pos, status_len; - uint16_t status_data[256]; - - int data_pos; - uint16_t data[256]; - - uint16_t sector_buffer[256][256]; - - int sector_pos; - int sector_count; - - int command; - int cmd_state; - - int in_reset; - int callback; - - uint32_t rba; - - struct - { - int req_in_progress; - } cmds[3]; - - esdi_drive_t drives[2]; - - uint8_t pos_regs[8]; -} esdi_t; - -#define STATUS_DMA_ENA (1 << 7) -#define STATUS_IRQ_PENDING (1 << 6) -#define STATUS_CMD_IN_PROGRESS (1 << 5) -#define STATUS_BUSY (1 << 4) -#define STATUS_STATUS_OUT_FULL (1 << 3) -#define STATUS_CMD_IR_FULL (1 << 2) -#define STATUS_TRANSFER_REQ (1 << 1) -#define STATUS_IRQ (1 << 0) - -#define CTRL_RESET (1 << 7) -#define CTRL_DMA_ENA (1 << 1) -#define CTRL_IRQ_ENA (1 << 0) - -#define IRQ_HOST_ADAPTER (7 << 5) -#define IRQ_DEVICE_0 (0 << 5) -#define IRQ_CMD_COMPLETE_SUCCESS 0x1 -#define IRQ_RESET_COMPLETE 0xa -#define IRQ_DATA_TRANSFER_READY 0xb -#define IRQ_CMD_COMPLETE_FAILURE 0xc - -#define ATTN_DEVICE_SEL (7 << 5) -#define ATTN_HOST_ADAPTER (7 << 5) -#define ATTN_DEVICE_0 (0 << 5) -#define ATTN_DEVICE_1 (1 << 5) -#define ATTN_REQ_MASK 0xf -#define ATTN_CMD_REQ 1 -#define ATTN_EOI 2 -#define ATTN_RESET 4 - -#define CMD_SIZE_4 (1 << 14) - -#define CMD_DEVICE_SEL (7 << 5) -#define CMD_MASK 0x1f -#define CMD_READ 0x01 -#define CMD_WRITE 0x02 -#define CMD_READ_VERIFY 0x03 -#define CMD_WRITE_VERIFY 0x04 -#define CMD_SEEK 0x05 -#define CMD_GET_DEV_CONFIG 0x09 -#define CMD_GET_POS_INFO 0x0a - -#define STATUS_LEN(x) ((x) << 8) -#define STATUS_DEVICE_HOST_ADAPTER (7 << 5) - -static __inline void esdi_set_irq(esdi_t *esdi) -{ - if (esdi->basic_ctrl & CTRL_IRQ_ENA) - picint(1 << 14); -} -static __inline void esdi_clear_irq() -{ - picintc(1 << 14); -} - -static uint8_t esdi_read(uint16_t port, void *p) -{ - esdi_t *esdi = (esdi_t *)p; - uint8_t temp = 0xff; - - switch (port) - { - case 0x3512: /*Basic status register*/ - temp = esdi->status; - break; - case 0x3513: /*IRQ status*/ - esdi->status &= ~STATUS_IRQ; - temp = esdi->irq_status; - break; - - default: - fatal("esdi_read port=%04x\n", port); - } - - return temp; -} - -static void esdi_write(uint16_t port, uint8_t val, void *p) -{ - esdi_t *esdi = (esdi_t *)p; - - switch (port) - { - case 0x3512: /*Basic control register*/ - if ((esdi->basic_ctrl & CTRL_RESET) && !(val & CTRL_RESET)) - { - esdi->in_reset = 1; - esdi->callback = ESDI_TIME * 50; - esdi->status = STATUS_BUSY; - } - esdi->basic_ctrl = val; - if (!(esdi->basic_ctrl & CTRL_IRQ_ENA)) - picintc(1 << 14); - break; - case 0x3513: /*Attention register*/ - switch (val & ATTN_DEVICE_SEL) - { - case ATTN_HOST_ADAPTER: - switch (val & ATTN_REQ_MASK) - { - case ATTN_CMD_REQ: - if (esdi->cmd_req_in_progress) - fatal("Try to start command on in_progress adapter\n"); - esdi->cmd_req_in_progress = 1; - esdi->cmd_dev = ATTN_HOST_ADAPTER; - esdi->status |= STATUS_BUSY; - esdi->cmd_pos = 0; - break; - - case ATTN_EOI: - esdi->irq_in_progress = 0; - esdi->status &= ~STATUS_IRQ; - esdi_clear_irq(); - break; - - case ATTN_RESET: - esdi->in_reset = 1; - esdi->callback = ESDI_TIME * 50; - esdi->status = STATUS_BUSY; - break; - - default: - fatal("Bad attention request %02x\n", val); - } - break; - - case ATTN_DEVICE_0: - switch (val & ATTN_REQ_MASK) - { - case ATTN_CMD_REQ: - if (esdi->cmd_req_in_progress) - fatal("Try to start command on in_progress device0\n"); - esdi->cmd_req_in_progress = 1; - esdi->cmd_dev = ATTN_DEVICE_0; - esdi->status |= STATUS_BUSY; - esdi->cmd_pos = 0; - break; - - case ATTN_EOI: - esdi->irq_in_progress = 0; - esdi->status &= ~STATUS_IRQ; - esdi_clear_irq(); - break; - - default: - fatal("Bad attention request %02x\n", val); - } - break; - - case ATTN_DEVICE_1: - switch (val & ATTN_REQ_MASK) - { - case ATTN_CMD_REQ: - if (esdi->cmd_req_in_progress) - fatal("Try to start command on in_progress device0\n"); - esdi->cmd_req_in_progress = 1; - esdi->cmd_dev = ATTN_DEVICE_1; - esdi->status |= STATUS_BUSY; - esdi->cmd_pos = 0; - break; - - case ATTN_EOI: - esdi->irq_in_progress = 0; - esdi->status &= ~STATUS_IRQ; - esdi_clear_irq(); - break; - - default: - fatal("Bad attention request %02x\n", val); - } - break; - - default: - fatal("Attention to unknown device %02x\n", val); - } - break; - - default: - fatal("esdi_write port=%04x val=%02x\n", port, val); - } -} - -static uint16_t esdi_readw(uint16_t port, void *p) -{ - esdi_t *esdi = (esdi_t *)p; - uint16_t temp = 0xffff; - - switch (port) - { - case 0x3510: /*Status Interface Register*/ - if (esdi->status_pos >= esdi->status_len) - return 0; - temp = esdi->status_data[esdi->status_pos++]; - if (esdi->status_pos >= esdi->status_len) - { - esdi->status &= ~STATUS_STATUS_OUT_FULL; - esdi->status_pos = esdi->status_len = 0; - } - break; - - default: - fatal("esdi_readw port=%04x\n", port); - } - - return temp; -} - -static void esdi_writew(uint16_t port, uint16_t val, void *p) -{ - esdi_t *esdi = (esdi_t *)p; - - switch (port) - { - case 0x3510: /*Command Interface Register*/ - if (esdi->cmd_pos >= 4) - fatal("CIR pos 4\n"); - esdi->cmd_data[esdi->cmd_pos++] = val; - if ( ((esdi->cmd_data[0] & CMD_SIZE_4) && esdi->cmd_pos == 4) || - (!(esdi->cmd_data[0] & CMD_SIZE_4) && esdi->cmd_pos == 2)) - { - - esdi->cmd_pos = 0; - esdi->cmd_req_in_progress = 0; - esdi->cmd_state = 0; - - if ((esdi->cmd_data[0] & CMD_DEVICE_SEL) != esdi->cmd_dev) - fatal("Command device mismatch with attn\n"); - esdi->command = esdi->cmd_data[0] & CMD_MASK; - esdi->callback = ESDI_TIME; - esdi->status = STATUS_BUSY; - esdi->data_pos = 0; - } - break; - - default: - fatal("esdi_writew port=%04x val=%04x\n", port, val); - } -} - -static void cmd_unsupported(esdi_t *esdi) -{ - esdi->status_len = 9; - esdi->status_data[0] = esdi->command | STATUS_LEN(9) | esdi->cmd_dev; - esdi->status_data[1] = 0x0f03; /*Attention error, command not supported*/ - esdi->status_data[2] = 0x0002; /*Interface fault*/ - esdi->status_data[3] = 0; - esdi->status_data[4] = 0; - esdi->status_data[5] = 0; - esdi->status_data[6] = 0; - esdi->status_data[7] = 0; - esdi->status_data[8] = 0; - - esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; - esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_FAILURE; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); -} - -static void device_not_present(esdi_t *esdi) -{ - esdi->status_len = 9; - esdi->status_data[0] = esdi->command | STATUS_LEN(9) | esdi->cmd_dev; - esdi->status_data[1] = 0x0c11; /*Command failed, internal hardware error*/ - esdi->status_data[2] = 0x000b; /*Selection error*/ - esdi->status_data[3] = 0; - esdi->status_data[4] = 0; - esdi->status_data[5] = 0; - esdi->status_data[6] = 0; - esdi->status_data[7] = 0; - esdi->status_data[8] = 0; - - esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; - esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_FAILURE; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); -} - -#define ESDI_ADAPTER_ONLY() do \ - { \ - if (esdi->cmd_dev != ATTN_HOST_ADAPTER) \ - { \ - cmd_unsupported(esdi); \ - return; \ - } \ - } while (0) - -#define ESDI_DRIVE_ONLY() do \ - { \ - if (esdi->cmd_dev != ATTN_DEVICE_0 && esdi->cmd_dev != ATTN_DEVICE_1) \ - { \ - cmd_unsupported(esdi); \ - return; \ - } \ - if (esdi->cmd_dev == ATTN_DEVICE_0) \ - drive = &esdi->drives[0]; \ - else \ - drive = &esdi->drives[1]; \ - } while (0) - -static void esdi_callback(void *p) -{ - esdi_t *esdi = (esdi_t *)p; - esdi_drive_t *drive; - - esdi->callback = 0; - - if (esdi->in_reset) - { - esdi->in_reset = 0; - esdi->status = STATUS_IRQ; - esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_RESET_COMPLETE; - - return; - } - switch (esdi->command) - { - case CMD_READ: - ESDI_DRIVE_ONLY(); - - if (!drive->present) - { - device_not_present(esdi); - return; - } - - switch (esdi->cmd_state) - { - case 0: - esdi->rba = (esdi->cmd_data[2] | (esdi->cmd_data[3] << 16)) & 0x0fffffff; - - esdi->sector_pos = 0; - esdi->sector_count = esdi->cmd_data[1]; - - esdi->status = STATUS_IRQ | STATUS_CMD_IN_PROGRESS | STATUS_TRANSFER_REQ; - esdi->irq_status = esdi->cmd_dev | IRQ_DATA_TRANSFER_READY; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - - esdi->cmd_state = 1; - esdi->callback = ESDI_TIME; - esdi->data_pos = 0; - break; - - case 1: - if (!(esdi->basic_ctrl & CTRL_DMA_ENA)) - { - esdi->callback = ESDI_TIME; - return; - } - while (esdi->sector_pos < esdi->sector_count) - { - if (!esdi->data_pos) - { - if (esdi->rba >= drive->sectors) - fatal("Read past end of drive\n"); - hdd_image_read(drive->hdc_num, esdi->rba, 1, (uint8_t *) esdi->data); - update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 1); - } - while (esdi->data_pos < 256) - { - int val = dma_channel_write(5, esdi->data[esdi->data_pos]); - - if (val == DMA_NODATA) - { - esdi->callback = ESDI_TIME; - return; - } - - esdi->data_pos++; - } - - esdi->data_pos = 0; - esdi->sector_pos++; - esdi->rba++; - } - - esdi->status = STATUS_CMD_IN_PROGRESS; - esdi->cmd_state = 2; - esdi->callback = ESDI_TIME; - break; - - case 2: - esdi->status = STATUS_IRQ; - esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - } - break; - - case CMD_WRITE: - case CMD_WRITE_VERIFY: - ESDI_DRIVE_ONLY(); - - if (!drive->present) - { - device_not_present(esdi); - return; - } - - switch (esdi->cmd_state) - { - case 0: - esdi->rba = (esdi->cmd_data[2] | (esdi->cmd_data[3] << 16)) & 0x0fffffff; - - esdi->sector_pos = 0; - esdi->sector_count = esdi->cmd_data[1]; - - esdi->status = STATUS_IRQ | STATUS_CMD_IN_PROGRESS | STATUS_TRANSFER_REQ; - esdi->irq_status = esdi->cmd_dev | IRQ_DATA_TRANSFER_READY; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - - esdi->cmd_state = 1; - esdi->callback = ESDI_TIME; - esdi->data_pos = 0; - break; - - case 1: - if (!(esdi->basic_ctrl & CTRL_DMA_ENA)) - { - esdi->callback = ESDI_TIME; - return; - } - while (esdi->sector_pos < esdi->sector_count) - { - while (esdi->data_pos < 256) - { - int val = dma_channel_read(5); - - if (val == DMA_NODATA) - { - esdi->callback = ESDI_TIME; - return; - } - - esdi->data[esdi->data_pos++] = val & 0xffff; - } - - if (esdi->rba >= drive->sectors) - fatal("Write past end of drive\n"); - hdd_image_write(drive->hdc_num, esdi->rba, 1, (uint8_t *) esdi->data); - esdi->rba++; - esdi->sector_pos++; - update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 1); - - esdi->data_pos = 0; - } - update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 0); - - esdi->status = STATUS_CMD_IN_PROGRESS; - esdi->cmd_state = 2; - esdi->callback = ESDI_TIME; - break; - - case 2: - esdi->status = STATUS_IRQ; - esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - } - break; - - case CMD_READ_VERIFY: - ESDI_DRIVE_ONLY(); - - if (!drive->present) - { - device_not_present(esdi); - return; - } - - esdi->status = STATUS_IRQ; - esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - - case CMD_SEEK: - ESDI_DRIVE_ONLY(); - - if (!drive->present) - { - device_not_present(esdi); - return; - } - - esdi->status = STATUS_IRQ; - esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - - case CMD_GET_DEV_CONFIG: - ESDI_DRIVE_ONLY(); - - if (!drive->present) - { - device_not_present(esdi); - return; - } - - if (esdi->status_pos) - fatal("Status send in progress\n"); - if ((esdi->status & STATUS_IRQ) || esdi->irq_in_progress) - fatal("IRQ in progress %02x %i\n", esdi->status, esdi->irq_in_progress); - - esdi->status_len = 6; - esdi->status_data[0] = CMD_GET_POS_INFO | STATUS_LEN(6) | STATUS_DEVICE_HOST_ADAPTER; - esdi->status_data[1] = 0x10; /*Zero defect*/ - esdi->status_data[2] = drive->sectors & 0xffff; - esdi->status_data[3] = drive->sectors >> 16; - esdi->status_data[4] = drive->tracks; - esdi->status_data[5] = drive->hpc | (drive->spt << 16); - -/* pclog("CMD_GET_DEV_CONFIG %i %04x %04x %04x %04x %04x %04x\n", drive->sectors, - esdi->status_data[0], esdi->status_data[1], - esdi->status_data[2], esdi->status_data[3], - esdi->status_data[4], esdi->status_data[5]);*/ - - esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; - esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - - case CMD_GET_POS_INFO: - ESDI_ADAPTER_ONLY(); - if (esdi->status_pos) - fatal("Status send in progress\n"); - if ((esdi->status & STATUS_IRQ) || esdi->irq_in_progress) - fatal("IRQ in progress %02x %i\n", esdi->status, esdi->irq_in_progress); - - esdi->status_len = 5; - esdi->status_data[0] = CMD_GET_POS_INFO | STATUS_LEN(5) | STATUS_DEVICE_HOST_ADAPTER; - esdi->status_data[1] = 0xffdd; /*MCA ID*/ - esdi->status_data[2] = esdi->pos_regs[3] | (esdi->pos_regs[2] << 8); - esdi->status_data[3] = 0xff; - esdi->status_data[4] = 0xff; - - esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; - esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - - case 0x11: - ESDI_ADAPTER_ONLY(); - switch (esdi->cmd_state) - { - case 0: - esdi->sector_pos = 0; - esdi->sector_count = esdi->cmd_data[1]; - if (esdi->sector_count > 256) - fatal("Read sector buffer count %04x\n", esdi->cmd_data[1]); - - esdi->status = STATUS_IRQ | STATUS_CMD_IN_PROGRESS | STATUS_TRANSFER_REQ; - esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_DATA_TRANSFER_READY; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - - esdi->cmd_state = 1; - esdi->callback = ESDI_TIME; - esdi->data_pos = 0; - break; - - case 1: - if (!(esdi->basic_ctrl & CTRL_DMA_ENA)) - { - esdi->callback = ESDI_TIME; - return; - } - while (esdi->sector_pos < esdi->sector_count) - { - if (!esdi->data_pos) - memcpy(esdi->data, esdi->sector_buffer[esdi->sector_pos++], 512); - while (esdi->data_pos < 256) - { - int val = dma_channel_write(5, esdi->data[esdi->data_pos]); - - if (val == DMA_NODATA) - { - esdi->callback = ESDI_TIME; - return; - } - - esdi->data_pos++; - } - - esdi->data_pos = 0; - } - - esdi->status = STATUS_CMD_IN_PROGRESS; - esdi->cmd_state = 2; - esdi->callback = ESDI_TIME; - break; - - case 2: - esdi->status = STATUS_IRQ; - esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - } - break; - - case 0x10: - ESDI_ADAPTER_ONLY(); - switch (esdi->cmd_state) - { - case 0: - esdi->sector_pos = 0; - esdi->sector_count = esdi->cmd_data[1]; - if (esdi->sector_count > 256) - fatal("Write sector buffer count %04x\n", esdi->cmd_data[1]); - - esdi->status = STATUS_IRQ | STATUS_CMD_IN_PROGRESS | STATUS_TRANSFER_REQ; - esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_DATA_TRANSFER_READY; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - - esdi->cmd_state = 1; - esdi->callback = ESDI_TIME; - esdi->data_pos = 0; - break; - - case 1: - if (!(esdi->basic_ctrl & CTRL_DMA_ENA)) - { - esdi->callback = ESDI_TIME; - return; - } - while (esdi->sector_pos < esdi->sector_count) - { - while (esdi->data_pos < 256) - { - int val = dma_channel_read(5); - - if (val == DMA_NODATA) - { - esdi->callback = ESDI_TIME; - return; - } - - esdi->data[esdi->data_pos++] = val & 0xffff;; - } - - memcpy(esdi->sector_buffer[esdi->sector_pos++], esdi->data, 512); - esdi->data_pos = 0; - } - - esdi->status = STATUS_CMD_IN_PROGRESS; - esdi->cmd_state = 2; - esdi->callback = ESDI_TIME; - break; - - case 2: - esdi->status = STATUS_IRQ; - esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - } - break; - - case 0x12: - ESDI_ADAPTER_ONLY(); - if (esdi->status_pos) - fatal("Status send in progress\n"); - if ((esdi->status & STATUS_IRQ) || esdi->irq_in_progress) - fatal("IRQ in progress %02x %i\n", esdi->status, esdi->irq_in_progress); - - esdi->status_len = 2; - esdi->status_data[0] = 0x12 | STATUS_LEN(5) | STATUS_DEVICE_HOST_ADAPTER; - esdi->status_data[1] = 0; - - esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; - esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_CMD_COMPLETE_SUCCESS; - esdi->irq_in_progress = 1; - esdi_set_irq(esdi); - break; - - default: - fatal("Bad command %02x %i\n", esdi->command, esdi->cmd_dev); - - } -} - -static uint8_t esdi_mca_read(int port, void *p) -{ - esdi_t *esdi = (esdi_t *)p; - - return esdi->pos_regs[port & 7]; -} - -static void esdi_mca_write(int port, uint8_t val, void *p) -{ - esdi_t *esdi = (esdi_t *)p; - - if (port < 0x102) - return; - - esdi->pos_regs[port & 7] = val; - - io_removehandler(0x3510, 0x0008, esdi_read, esdi_readw, NULL, esdi_write, esdi_writew, NULL, esdi); - mem_mapping_disable(&esdi->bios_rom.mapping); - if (esdi->pos_regs[2] & 1) - { - io_sethandler(0x3510, 0x0008, esdi_read, esdi_readw, NULL, esdi_write, esdi_writew, NULL, esdi); - if (!(esdi->pos_regs[3] & 8)) - { - mem_mapping_enable(&esdi->bios_rom.mapping); - mem_mapping_set_addr(&esdi->bios_rom.mapping, ((esdi->pos_regs[3] & 7) * 0x4000) + 0xc0000, 0x4000); - } - } -} - -static void loadhd(esdi_t *esdi, int hdc_num, int d, const wchar_t *fn) -{ - esdi_drive_t *drive = &esdi->drives[d]; - int ret = 0; - - ret = hdd_image_load(hdc_num); - - if (!ret) - { - drive->present = 0; - return; - } - - drive->spt = hdc[hdc_num].spt; - drive->hpc = hdc[hdc_num].hpc; - drive->tracks = hdc[hdc_num].tracks; - drive->sectors = hdc[hdc_num].spt * hdc[hdc_num].hpc * hdc[hdc_num].tracks; - drive->hdc_num = hdc_num; - drive->present = 1; -} - -static void *esdi_init() -{ - int i = 0; - int c = 0; - - esdi_t *esdi = malloc(sizeof(esdi_t)); - memset(esdi, 0, sizeof(esdi_t)); - - rom_init_interleaved(&esdi->bios_rom, L"roms/hdd/esdi/90x8970.bin", L"roms/hdd/esdi/90x8969.bin", 0xc8000, 0x4000, 0x3fff, 0, MEM_MAPPING_EXTERNAL); - mem_mapping_disable(&esdi->bios_rom.mapping); - - esdi->drives[0].present = esdi->drives[1].present = 0; - - for (i = 0; i < HDC_NUM; i++) - { - if ((hdc[i].bus == HDD_BUS_RLL) && (hdc[i].rll_channel < RLL_NUM)) - { - loadhd(esdi, i, hdc[i].rll_channel, hdc[i].fn); - c++; - if (c >= RLL_NUM) break; - } - } - - timer_add(esdi_callback, &esdi->callback, &esdi->callback, esdi); - - mca_add(esdi_mca_read, esdi_mca_write, esdi); - - esdi->pos_regs[0] = 0xff; - esdi->pos_regs[1] = 0xdd; - - esdi->in_reset = 1; - esdi->callback = ESDI_TIME * 50; - esdi->status = STATUS_BUSY; - - return esdi; -} - -static void esdi_close(void *p) -{ - esdi_t *esdi = (esdi_t *)p; - esdi_drive_t *drive; - - int d; - - esdi->drives[0].present = esdi->drives[1].present = 0; - - for (d = 0; d < 2; d++) - { - drive = &esdi->drives[d]; - - hdd_image_close(drive->hdc_num); - } - - free(esdi); -} - -static int esdi_available() -{ - return rom_present(L"roms/hdd/esdi/90x8969.bin") && rom_present(L"roms/hdd/esdi/90x8970.bin"); -} - -device_t hdd_esdi_device = -{ - "IBM ESDI Fixed Disk Adapter (MCA)", - DEVICE_MCA, - esdi_init, - esdi_close, - esdi_available, - NULL, - NULL, - NULL, - NULL -}; diff --git a/src/esdi_at.c b/src/hdd_esdi_at.c similarity index 99% rename from src/esdi_at.c rename to src/hdd_esdi_at.c index 0429b350b..3fe083a68 100644 --- a/src/esdi_at.c +++ b/src/hdd_esdi_at.c @@ -18,7 +18,7 @@ #include "rom.h" #include "timer.h" -#include "esdi_at.h" +#include "hdd_esdi_at.h" #define IDE_TIME (TIMER_USEC*10) @@ -501,7 +501,7 @@ void esdi_callback(void *p) esdi->pos = 0; esdi->status = STAT_DRQ | STAT_READY | STAT_DSC; esdi_irq_raise(esdi); - update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 1); + update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); } break; @@ -538,7 +538,7 @@ void esdi_callback(void *p) } else esdi->status = STAT_READY | STAT_DSC; - update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 1); + update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); } break; @@ -565,7 +565,7 @@ void esdi_callback(void *p) esdi_irq_raise(esdi); break; } - update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 1); + update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); esdi_next_sector(esdi); esdi->secount = (esdi->secount - 1) & 0xff; if (esdi->secount) @@ -604,7 +604,7 @@ void esdi_callback(void *p) } esdi->status = STAT_READY | STAT_DSC; esdi_irq_raise(esdi); - update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 1); + update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); } break; @@ -744,7 +744,7 @@ void esdi_callback(void *p) break; } - update_status_bar_icon(SB_HDD | HDD_BUS_RLL, 0); + update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 0); } static void esdi_rom_write(uint32_t addr, uint8_t val, void *p) @@ -789,11 +789,11 @@ void *wd1007vse1_init() for (i = 0; i < HDC_NUM; i++) { - if ((hdc[i].bus == HDD_BUS_RLL) && (hdc[i].rll_channel < RLL_NUM)) + if ((hdc[i].bus == HDD_BUS_ESDI) && (hdc[i].esdi_channel < ESDI_NUM)) { - loadhd(esdi, i, hdc[i].rll_channel, hdc[i].fn); + loadhd(esdi, i, hdc[i].esdi_channel, hdc[i].fn); c++; - if (c >= RLL_NUM) break; + if (c >= ESDI_NUM) break; } } diff --git a/src/esdi_at.h b/src/hdd_esdi_at.h similarity index 100% rename from src/esdi_at.h rename to src/hdd_esdi_at.h diff --git a/src/hdd_esdi_mca.c b/src/hdd_esdi_mca.c new file mode 100644 index 000000000..38c11c83d --- /dev/null +++ b/src/hdd_esdi_mca.c @@ -0,0 +1,1057 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Driver for IBM PS/2 ESDI disk controller (MCA) + * + * AdapterID: 0xDDFF + * AdapterName: "ESDI Fixed Disk Controller" + * NumBytes 2 + * I/O base: 0x3510 - 0x3517 + * IRQ: 14 + * + * Primary Board pos[0]=XXxx xx0X 0x3510 + * Secondary Board pos[0]=XXxx xx1X 0x3518 + * + * DMA 5 pos[0]=XX01 01XX + * DMA 6 pos[0]=XX01 10XX + * DMA 7 pos[0]=XX01 11XX + * DMA 0 pos[0]=XX00 00XX + * DMA 1 pos[0]=XX00 01XX + * DMA 3 pos[0]=XX00 11XX + * DMA 4 pos[0]=XX01 00XX + * + * MCA Fairness ON pos[0]=X1XX XXXX + * MCA Fairness OFF pos[0]=X0XX XXXX + * + * ROM C000 pos[1]=XXXX 0000 + * ROM C400 pos[1]=XXXX 0001 + * ROM C800 pos[1]=XXXX 0010 + * ROM CC00 pos[1]=XXXX 0011 + * ROM D000 pos[1]=XXXX 0100 + * ROM D400 pos[1]=XXXX 0101 + * ROM D800 pos[1]=XXXX 0110 + * ROM DC00 pos[1]=XXXX 0111 + * ROM Disabled pos[1]=XXXX 1XXX + * + * DMA Burst 8 pos[1]=XX01 XXXX + * DMA Burst 16 pos[1]=XX10 XXXX + * DMA Burst 24 pos[1]=XX11 XXXX + * DMA Disabled pos[1]=XX00 XXXX + * + * Although this is an MCA device, meaning that the system + * software will take care of device configuration, the ESDI + * controller is a somewhat weird one.. it's I/O base address + * and IRQ channel are locked to 0x3510 and IRQ14, possibly + * to enforce compatibility with the IBM MFM disk controller + * that was also in use on these systems. All other settings, + * however, are auto-configured by the system software as + * shown above. + * + * Version: @(#)hdd_esdi_mca.c 1.0.1 2017/08/24 + * + * Authors: Sarah Walker, + * Miran Grca, + * Copyright 2008-2017 Sarah Walker. + * Copyright 2017 Fred N. van Kempen. + */ +#include +#include "ibm.h" +#include "device.h" +#include "dma.h" +#include "hdd_image.h" +#include "io.h" +#include "mca.h" +#include "mem.h" +#include "pic.h" +#include "rom.h" +#include "timer.h" +#include "hdd_esdi_mca.h" + + +/* These are hardwired. */ +#define ESDI_IOADDR 0x3510 +#define ESDI_IRQCHAN 14 + + +#define ESDI_TIME (2000 * TIMER_USEC) +#define CMD_ADAPTER 0 + + +typedef struct esdi_drive { + int spt, hpc; + int tracks; + int sectors; + int present; + int hdc_num; +} esdi_drive_t; + +typedef struct esdi { + uint16_t base; + int8_t irq; + int8_t dma; + + uint32_t bios; + rom_t bios_rom; + + uint8_t basic_ctrl; + uint8_t status; + uint8_t irq_status; + int irq_in_progress; + int cmd_req_in_progress; + int cmd_pos; + uint16_t cmd_data[4]; + int cmd_dev; + + int status_pos, + status_len; + + uint16_t status_data[256]; + + int data_pos; + uint16_t data[256]; + + uint16_t sector_buffer[256][256]; + + int sector_pos; + int sector_count; + + int command; + int cmd_state; + + int in_reset; + int callback; + + uint32_t rba; + + struct { + int req_in_progress; + } cmds[3]; + + esdi_drive_t drives[2]; + + uint8_t pos_regs[8]; +} esdi_t; + +#define STATUS_DMA_ENA (1 << 7) +#define STATUS_IRQ_PENDING (1 << 6) +#define STATUS_CMD_IN_PROGRESS (1 << 5) +#define STATUS_BUSY (1 << 4) +#define STATUS_STATUS_OUT_FULL (1 << 3) +#define STATUS_CMD_IR_FULL (1 << 2) +#define STATUS_TRANSFER_REQ (1 << 1) +#define STATUS_IRQ (1 << 0) + +#define CTRL_RESET (1 << 7) +#define CTRL_DMA_ENA (1 << 1) +#define CTRL_IRQ_ENA (1 << 0) + +#define IRQ_HOST_ADAPTER (7 << 5) +#define IRQ_DEVICE_0 (0 << 5) +#define IRQ_CMD_COMPLETE_SUCCESS 0x1 +#define IRQ_RESET_COMPLETE 0xa +#define IRQ_DATA_TRANSFER_READY 0xb +#define IRQ_CMD_COMPLETE_FAILURE 0xc + +#define ATTN_DEVICE_SEL (7 << 5) +#define ATTN_HOST_ADAPTER (7 << 5) +#define ATTN_DEVICE_0 (0 << 5) +#define ATTN_DEVICE_1 (1 << 5) +#define ATTN_REQ_MASK 0x0f +#define ATTN_CMD_REQ 1 +#define ATTN_EOI 2 +#define ATTN_RESET 4 + +#define CMD_SIZE_4 (1 << 14) + +#define CMD_DEVICE_SEL (7 << 5) +#define CMD_MASK 0x1f +#define CMD_READ 0x01 +#define CMD_WRITE 0x02 +#define CMD_READ_VERIFY 0x03 +#define CMD_WRITE_VERIFY 0x04 +#define CMD_SEEK 0x05 +#define CMD_GET_DEV_CONFIG 0x09 +#define CMD_GET_POS_INFO 0x0a + +#define STATUS_LEN(x) ((x) << 8) +#define STATUS_DEVICE_HOST_ADAPTER (7 << 5) + + +static __inline void +esdi_set_irq(esdi_t *esdi) +{ + if (esdi->basic_ctrl & CTRL_IRQ_ENA) + picint(1 << esdi->irq); +} + + +static __inline void +esdi_clear_irq(esdi_t *esdi) +{ + picintc(1 << esdi->irq); +} + + + +static void +cmd_unsupported(esdi_t *esdi) +{ + esdi->status_len = 9; + esdi->status_data[0] = esdi->command | STATUS_LEN(9) | esdi->cmd_dev; + esdi->status_data[1] = 0x0f03; /*Attention error, command not supported*/ + esdi->status_data[2] = 0x0002; /*Interface fault*/ + esdi->status_data[3] = 0; + esdi->status_data[4] = 0; + esdi->status_data[5] = 0; + esdi->status_data[6] = 0; + esdi->status_data[7] = 0; + esdi->status_data[8] = 0; + + esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; + esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_FAILURE; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); +} + + +static void +device_not_present(esdi_t *esdi) +{ + esdi->status_len = 9; + esdi->status_data[0] = esdi->command | STATUS_LEN(9) | esdi->cmd_dev; + esdi->status_data[1] = 0x0c11; /*Command failed, internal hardware error*/ + esdi->status_data[2] = 0x000b; /*Selection error*/ + esdi->status_data[3] = 0; + esdi->status_data[4] = 0; + esdi->status_data[5] = 0; + esdi->status_data[6] = 0; + esdi->status_data[7] = 0; + esdi->status_data[8] = 0; + + esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; + esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_FAILURE; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); +} + +#define ESDI_ADAPTER_ONLY() do \ + { \ + if (esdi->cmd_dev != ATTN_HOST_ADAPTER) \ + { \ + cmd_unsupported(esdi); \ + return; \ + } \ + } while (0) + +#define ESDI_DRIVE_ONLY() do \ + { \ + if (esdi->cmd_dev != ATTN_DEVICE_0 && esdi->cmd_dev != ATTN_DEVICE_1) \ + { \ + cmd_unsupported(esdi); \ + return; \ + } \ + if (esdi->cmd_dev == ATTN_DEVICE_0) \ + drive = &esdi->drives[0]; \ + else \ + drive = &esdi->drives[1]; \ + } while (0) + + +static void +esdi_callback(void *p) +{ + esdi_t *esdi = (esdi_t *)p; + esdi_drive_t *drive; + int val; + + esdi->callback = 0; + + /* If we are returning from a RESET, handle this first. */ + if (esdi->in_reset) { + esdi->in_reset = 0; + esdi->status = STATUS_IRQ; + esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_RESET_COMPLETE; + + return; + } + + switch (esdi->command) { + case CMD_READ: + ESDI_DRIVE_ONLY(); + + if (! drive->present) { + device_not_present(esdi); + return; + } + + switch (esdi->cmd_state) { + case 0: + esdi->rba = (esdi->cmd_data[2] | (esdi->cmd_data[3] << 16)) & 0x0fffffff; + + esdi->sector_pos = 0; + esdi->sector_count = esdi->cmd_data[1]; + + esdi->status = STATUS_IRQ | STATUS_CMD_IN_PROGRESS | STATUS_TRANSFER_REQ; + esdi->irq_status = esdi->cmd_dev | IRQ_DATA_TRANSFER_READY; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + + esdi->cmd_state = 1; + esdi->callback = ESDI_TIME; + esdi->data_pos = 0; + break; + + case 1: + if (!(esdi->basic_ctrl & CTRL_DMA_ENA)) { + esdi->callback = ESDI_TIME; + return; + } + + while (esdi->sector_pos < esdi->sector_count) { + if (! esdi->data_pos) { + if (esdi->rba >= drive->sectors) + fatal("Read past end of drive\n"); + hdd_image_read(drive->hdc_num, esdi->rba, 1, (uint8_t *) esdi->data); + update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); + } + + while (esdi->data_pos < 256) { + val = dma_channel_write(esdi->dma, esdi->data[esdi->data_pos]); + + if (val == DMA_NODATA) { + esdi->callback = ESDI_TIME; + return; + } + + esdi->data_pos++; + } + + esdi->data_pos = 0; + esdi->sector_pos++; + esdi->rba++; + } + + esdi->status = STATUS_CMD_IN_PROGRESS; + esdi->cmd_state = 2; + esdi->callback = ESDI_TIME; + break; + + case 2: + esdi->status = STATUS_IRQ; + esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + } + break; + + case CMD_WRITE: + case CMD_WRITE_VERIFY: + ESDI_DRIVE_ONLY(); + if (! drive->present) { + device_not_present(esdi); + return; + } + + switch (esdi->cmd_state) { + case 0: + esdi->rba = (esdi->cmd_data[2] | (esdi->cmd_data[3] << 16)) & 0x0fffffff; + + esdi->sector_pos = 0; + esdi->sector_count = esdi->cmd_data[1]; + + esdi->status = STATUS_IRQ | STATUS_CMD_IN_PROGRESS | STATUS_TRANSFER_REQ; + esdi->irq_status = esdi->cmd_dev | IRQ_DATA_TRANSFER_READY; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + + esdi->cmd_state = 1; + esdi->callback = ESDI_TIME; + esdi->data_pos = 0; + break; + + case 1: + if (! (esdi->basic_ctrl & CTRL_DMA_ENA)) { + esdi->callback = ESDI_TIME; + return; + } + + while (esdi->sector_pos < esdi->sector_count) { + while (esdi->data_pos < 256) { + val = dma_channel_read(esdi->dma); + + if (val == DMA_NODATA) { + esdi->callback = ESDI_TIME; + return; + } + + esdi->data[esdi->data_pos++] = val & 0xffff; + } + + if (esdi->rba >= drive->sectors) + fatal("Write past end of drive\n"); + hdd_image_write(drive->hdc_num, esdi->rba, 1, (uint8_t *) esdi->data); + esdi->rba++; + esdi->sector_pos++; + update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 1); + + esdi->data_pos = 0; + } + update_status_bar_icon(SB_HDD | HDD_BUS_ESDI, 0); + + esdi->status = STATUS_CMD_IN_PROGRESS; + esdi->cmd_state = 2; + esdi->callback = ESDI_TIME; + break; + + case 2: + esdi->status = STATUS_IRQ; + esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + } + break; + + case CMD_READ_VERIFY: + ESDI_DRIVE_ONLY(); + + if (! drive->present) { + device_not_present(esdi); + return; + } + + esdi->status = STATUS_IRQ; + esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + + case CMD_SEEK: + ESDI_DRIVE_ONLY(); + + if (! drive->present) { + device_not_present(esdi); + return; + } + + esdi->status = STATUS_IRQ; + esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + + case CMD_GET_DEV_CONFIG: + ESDI_DRIVE_ONLY(); + + if (! drive->present) { + device_not_present(esdi); + return; + } + + if (esdi->status_pos) + fatal("Status send in progress\n"); + if ((esdi->status & STATUS_IRQ) || esdi->irq_in_progress) + fatal("IRQ in progress %02x %i\n", esdi->status, esdi->irq_in_progress); + + esdi->status_len = 6; + esdi->status_data[0] = CMD_GET_POS_INFO | STATUS_LEN(6) | STATUS_DEVICE_HOST_ADAPTER; + esdi->status_data[1] = 0x10; /*Zero defect*/ + esdi->status_data[2] = drive->sectors & 0xffff; + esdi->status_data[3] = drive->sectors >> 16; + esdi->status_data[4] = drive->tracks; + esdi->status_data[5] = drive->hpc | (drive->spt << 16); + +#if 0 + pclog("CMD_GET_DEV_CONFIG %i %04x %04x %04x %04x %04x %04x\n", + drive->sectors, + esdi->status_data[0], esdi->status_data[1], + esdi->status_data[2], esdi->status_data[3], + esdi->status_data[4], esdi->status_data[5]); +#endif + esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; + esdi->irq_status = esdi->cmd_dev | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + + case CMD_GET_POS_INFO: + ESDI_ADAPTER_ONLY(); + if (esdi->status_pos) + fatal("Status send in progress\n"); + if ((esdi->status & STATUS_IRQ) || esdi->irq_in_progress) + fatal("IRQ in progress %02x %i\n", esdi->status, esdi->irq_in_progress); + + esdi->status_len = 5; + esdi->status_data[0] = CMD_GET_POS_INFO | STATUS_LEN(5) | STATUS_DEVICE_HOST_ADAPTER; + esdi->status_data[1] = 0xffdd; /*MCA ID*/ + esdi->status_data[2] = esdi->pos_regs[3] | + (esdi->pos_regs[2] << 8); + esdi->status_data[3] = 0xffff; + esdi->status_data[4] = 0xffff; + + esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; + esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + + case 0x10: + ESDI_ADAPTER_ONLY(); + switch (esdi->cmd_state) { + case 0: + esdi->sector_pos = 0; + esdi->sector_count = esdi->cmd_data[1]; + if (esdi->sector_count > 256) + fatal("Write sector buffer count %04x\n", esdi->cmd_data[1]); + + esdi->status = STATUS_IRQ | STATUS_CMD_IN_PROGRESS | STATUS_TRANSFER_REQ; + esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_DATA_TRANSFER_READY; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + + esdi->cmd_state = 1; + esdi->callback = ESDI_TIME; + esdi->data_pos = 0; + break; + + case 1: + if (! (esdi->basic_ctrl & CTRL_DMA_ENA)) { + esdi->callback = ESDI_TIME; + return; + } + while (esdi->sector_pos < esdi->sector_count) { + while (esdi->data_pos < 256) { + val = dma_channel_read(esdi->dma); + + if (val == DMA_NODATA) { + esdi->callback = ESDI_TIME; + return; + } + + esdi->data[esdi->data_pos++] = val & 0xffff;; + } + + memcpy(esdi->sector_buffer[esdi->sector_pos++], esdi->data, 512); + esdi->data_pos = 0; + } + + esdi->status = STATUS_CMD_IN_PROGRESS; + esdi->cmd_state = 2; + esdi->callback = ESDI_TIME; + break; + + case 2: + esdi->status = STATUS_IRQ; + esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + } + break; + + case 0x11: + ESDI_ADAPTER_ONLY(); + switch (esdi->cmd_state) { + case 0: + esdi->sector_pos = 0; + esdi->sector_count = esdi->cmd_data[1]; + if (esdi->sector_count > 256) + fatal("Read sector buffer count %04x\n", esdi->cmd_data[1]); + + esdi->status = STATUS_IRQ | STATUS_CMD_IN_PROGRESS | STATUS_TRANSFER_REQ; + esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_DATA_TRANSFER_READY; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + + esdi->cmd_state = 1; + esdi->callback = ESDI_TIME; + esdi->data_pos = 0; + break; + + case 1: + if (! (esdi->basic_ctrl & CTRL_DMA_ENA)) { + esdi->callback = ESDI_TIME; + return; + } + + while (esdi->sector_pos < esdi->sector_count) { + if (! esdi->data_pos) + memcpy(esdi->data, esdi->sector_buffer[esdi->sector_pos++], 512); + while (esdi->data_pos < 256) { + val = dma_channel_write(esdi->dma, esdi->data[esdi->data_pos]); + + if (val == DMA_NODATA) { + esdi->callback = ESDI_TIME; + return; + } + + esdi->data_pos++; + } + + esdi->data_pos = 0; + } + + esdi->status = STATUS_CMD_IN_PROGRESS; + esdi->cmd_state = 2; + esdi->callback = ESDI_TIME; + break; + + case 2: + esdi->status = STATUS_IRQ; + esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + } + break; + + case 0x12: + ESDI_ADAPTER_ONLY(); + if (esdi->status_pos) + fatal("Status send in progress\n"); + if ((esdi->status & STATUS_IRQ) || esdi->irq_in_progress) + fatal("IRQ in progress %02x %i\n", esdi->status, esdi->irq_in_progress); + + esdi->status_len = 2; + esdi->status_data[0] = 0x12 | STATUS_LEN(5) | STATUS_DEVICE_HOST_ADAPTER; + esdi->status_data[1] = 0; + + esdi->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; + esdi->irq_status = IRQ_HOST_ADAPTER | IRQ_CMD_COMPLETE_SUCCESS; + esdi->irq_in_progress = 1; + esdi_set_irq(esdi); + break; + + default: + fatal("BAD COMMAND %02x %i\n", esdi->command, esdi->cmd_dev); + } +} + + +static uint8_t +esdi_read(uint16_t port, void *priv) +{ + esdi_t *esdi = (esdi_t *)priv; + uint8_t temp = 0xff; + + switch (port-esdi->base) { + case 2: /*Basic status register*/ + temp = esdi->status; + break; + + case 3: /*IRQ status*/ + esdi->status &= ~STATUS_IRQ; + temp = esdi->irq_status; + break; + + default: + fatal("esdi_read port=%04x\n", port); + } + + return(temp); +} + + +static void +esdi_write(uint16_t port, uint8_t val, void *priv) +{ + esdi_t *esdi = (esdi_t *)priv; + +#if 0 + pclog("ESDI: wr(%04x, %02x)\n", port-esdi->base, val); +#endif + switch (port-esdi->base) { + case 2: /*Basic control register*/ + if ((esdi->basic_ctrl & CTRL_RESET) && !(val & CTRL_RESET)) { + esdi->in_reset = 1; + esdi->callback = ESDI_TIME * 50; + esdi->status = STATUS_BUSY; + } + esdi->basic_ctrl = val; + + if (! (esdi->basic_ctrl & CTRL_IRQ_ENA)) + picintc(1 << esdi->irq); + break; + + case 3: /*Attention register*/ + switch (val & ATTN_DEVICE_SEL) { + case ATTN_HOST_ADAPTER: + switch (val & ATTN_REQ_MASK) { + case ATTN_CMD_REQ: + if (esdi->cmd_req_in_progress) + fatal("Try to start command on in_progress adapter\n"); + esdi->cmd_req_in_progress = 1; + esdi->cmd_dev = ATTN_HOST_ADAPTER; + esdi->status |= STATUS_BUSY; + esdi->cmd_pos = 0; + break; + + case ATTN_EOI: + esdi->irq_in_progress = 0; + esdi->status &= ~STATUS_IRQ; + esdi_clear_irq(esdi); + break; + + case ATTN_RESET: + esdi->in_reset = 1; + esdi->callback = ESDI_TIME * 50; + esdi->status = STATUS_BUSY; + break; + + default: + fatal("Bad attention request %02x\n", val); + } + break; + + case ATTN_DEVICE_0: + switch (val & ATTN_REQ_MASK) { + case ATTN_CMD_REQ: + if (esdi->cmd_req_in_progress) + fatal("Try to start command on in_progress device0\n"); + esdi->cmd_req_in_progress = 1; + esdi->cmd_dev = ATTN_DEVICE_0; + esdi->status |= STATUS_BUSY; + esdi->cmd_pos = 0; + break; + + case ATTN_EOI: + esdi->irq_in_progress = 0; + esdi->status &= ~STATUS_IRQ; + esdi_clear_irq(esdi); + break; + + default: + fatal("Bad attention request %02x\n", val); + } + break; + + case ATTN_DEVICE_1: + switch (val & ATTN_REQ_MASK) { + case ATTN_CMD_REQ: + if (esdi->cmd_req_in_progress) + fatal("Try to start command on in_progress device0\n"); + esdi->cmd_req_in_progress = 1; + esdi->cmd_dev = ATTN_DEVICE_1; + esdi->status |= STATUS_BUSY; + esdi->cmd_pos = 0; + break; + + case ATTN_EOI: + esdi->irq_in_progress = 0; + esdi->status &= ~STATUS_IRQ; + esdi_clear_irq(esdi); + break; + + default: + fatal("Bad attention request %02x\n", val); + } + break; + + default: + fatal("Attention to unknown device %02x\n", val); + } + break; + + default: + fatal("esdi_write port=%04x val=%02x\n", port, val); + } +} + + +static uint16_t +esdi_readw(uint16_t port, void *priv) +{ + esdi_t *esdi = (esdi_t *)priv; + uint16_t temp = 0xffff; + + switch (port-esdi->base) { + case 0: /*Status Interface Register*/ + if (esdi->status_pos >= esdi->status_len) + return(0); + temp = esdi->status_data[esdi->status_pos++]; + if (esdi->status_pos >= esdi->status_len) { + esdi->status &= ~STATUS_STATUS_OUT_FULL; + esdi->status_pos = esdi->status_len = 0; + } + break; + + default: + fatal("esdi_readw port=%04x\n", port); + } + + return(temp); +} + + +static void +esdi_writew(uint16_t port, uint16_t val, void *priv) +{ + esdi_t *esdi = (esdi_t *)priv; + +#if 0 + pclog("ESDI: wrw(%04x, %04x)\n", port-esdi->base, val); +#endif + switch (port-esdi->base) { + case 0: /*Command Interface Register*/ + if (esdi->cmd_pos >= 4) + fatal("CIR pos 4\n"); + esdi->cmd_data[esdi->cmd_pos++] = val; + if (((esdi->cmd_data[0] & CMD_SIZE_4) && esdi->cmd_pos == 4) || + (!(esdi->cmd_data[0] & CMD_SIZE_4) && esdi->cmd_pos == 2)) { + esdi->cmd_pos = 0; + esdi->cmd_req_in_progress = 0; + esdi->cmd_state = 0; + + if ((esdi->cmd_data[0] & CMD_DEVICE_SEL) != esdi->cmd_dev) + fatal("Command device mismatch with attn\n"); + esdi->command = esdi->cmd_data[0] & CMD_MASK; + esdi->callback = ESDI_TIME; + esdi->status = STATUS_BUSY; + esdi->data_pos = 0; + } + break; + + default: + fatal("esdi_writew port=%04x val=%04x\n", port, val); + } +} + + +static uint8_t +esdi_mca_read(int port, void *priv) +{ + esdi_t *esdi = (esdi_t *)priv; + +#if 0 + pclog("ESDI: mcard(%04x)\n", port); +#endif + return(esdi->pos_regs[port & 7]); +} + + +static void +esdi_mca_write(int port, uint8_t val, void *priv) +{ + esdi_t *esdi = (esdi_t *)priv; + +#if 0 + pclog("ESDI: mcawr(%04x, %02x) pos[2]=%02x pos[3]=%02x\n", + port, val, esdi->pos_regs[2], esdi->pos_regs[3]); +#endif + if (port < 0x102) + return; + + /* Save the new value. */ + esdi->pos_regs[port & 7] = val; + + io_removehandler(esdi->base, 8, + esdi_read, esdi_readw, NULL, + esdi_write, esdi_writew, NULL, esdi); + + /* Disable the BIOS mapping. */ + mem_mapping_disable(&esdi->bios_rom.mapping); + + if (esdi->pos_regs[2] & 0x01) { + /* OK, register (new) I/O handler. */ + io_sethandler(esdi->base, 8, + esdi_read, esdi_readw, NULL, + esdi_write, esdi_writew, NULL, esdi); + + /* Extract the new DMA channel. */ + switch(esdi->pos_regs[2] & 0x3c) { + case 0x14: /* DMA 5 [0]=XX01 01XX */ + esdi->dma = 5; + break; + + case 0x18: /* DMA 6 [0]=XX01 10XX */ + esdi->dma = 6; + break; + + case 0x1c: /* DMA 7 [0]=XX01 11XX */ + esdi->dma = 7; + break; + + case 0x00: /* DMA 0 [0]=XX00 00XX */ + esdi->dma = 0; + break; + + case 0x01: /* DMA 1 [0]=XX00 01XX */ + esdi->dma = 1; + break; + + case 0x04: /* DMA 3 [0]=XX00 11XX */ + esdi->dma = 3; + break; + + case 0x10: /* DMA 4 [0]=XX01 00XX */ + esdi->dma = 4; + break; + } + + /* Extract the new BIOS address. */ + if (! (esdi->pos_regs[3] & 0x08)) switch(esdi->pos_regs[3] & 0x0f) { + case 0: /* ROM C000 [1]=XXXX 0000 */ + esdi->bios = 0xC0000; + break; + + case 1: /* ROM C400 [1]=XXXX 0001 */ + esdi->bios = 0xC4000; + break; + + case 2: /* ROM C800 [1]=XXXX 0010 */ + esdi->bios = 0xC8000; + break; + + case 3: /* ROM CC00 [1]=XXXX 0011 */ + esdi->bios = 0xCC000; + break; + + case 4: /* ROM D000 [1]=XXXX 0100 */ + esdi->bios = 0xD0000; + break; + + case 5: /* ROM D400 [1]=XXXX 0101 */ + esdi->bios = 0xD4000; + break; + + case 6: /* ROM D800 [1]=XXXX 0110 */ + esdi->bios = 0xD8000; + break; + + case 7: /* ROM DC00 [1]=XXXX 0111 */ + esdi->bios = 0xC0000; + break; + + } else { + /* BIOS ROM disabled. */ + esdi->bios = 0x000000; + } + + /* Enable or disable the BIOS ROM. */ + if (esdi->bios != 0x000000) { + mem_mapping_enable(&esdi->bios_rom.mapping); + mem_mapping_set_addr(&esdi->bios_rom.mapping, + esdi->bios, 0x4000); + } else { + mem_mapping_disable(&esdi->bios_rom.mapping); + } + + /* Say hello. */ + pclog("ESDI: I/O=%04x, IRQ=%d, DMA=%d, BIOS @ %06X\n", + esdi->base, esdi->irq, esdi->dma, esdi->bios); + } +} + + +static void * +esdi_init(void) +{ + esdi_drive_t *drive; + esdi_t *esdi; + int c, i; + + esdi = malloc(sizeof(esdi_t)); + if (esdi == NULL) return(NULL); + memset(esdi, 0x00, sizeof(esdi_t)); + + /* These are hardwired. */ + esdi->base = ESDI_IOADDR; + esdi->irq = ESDI_IRQCHAN; + + rom_init_interleaved(&esdi->bios_rom, + L"roms/hdd/esdi/90x8970.bin", + L"roms/hdd/esdi/90x8969.bin", + 0xc8000, 0x4000, 0x3fff, 0, MEM_MAPPING_EXTERNAL); + mem_mapping_disable(&esdi->bios_rom.mapping); + + esdi->drives[0].present = esdi->drives[1].present = 0; + + for (c=0,i=0; idrives[hdc[i].esdi_channel]; + + /* Try to load an image for the drive. */ + if (! hdd_image_load(i)) { + /* Nope. */ + drive->present = 0; + continue; + } + + /* OK, so fill in geometry info. */ + drive->spt = hdc[i].spt; + drive->hpc = hdc[i].hpc; + drive->tracks = hdc[i].tracks; + drive->sectors = hdc[i].spt*hdc[i].hpc*hdc[i].tracks; + drive->hdc_num = i; + + /* Mark drive as present. */ + drive->present = 1; + } + + if (++c >= ESDI_NUM) break; + } + + /* Set the MCA ID for this controller, 0xFFDD. */ + esdi->pos_regs[0] = 0xff; + esdi->pos_regs[1] = 0xdd; + + /* Enable the device. */ + mca_add(esdi_mca_read, esdi_mca_write, esdi); + + /* Mark for a reset. */ + esdi->in_reset = 1; + esdi->callback = ESDI_TIME * 50; + esdi->status = STATUS_BUSY; + + /* Set the reply timer. */ + timer_add(esdi_callback, &esdi->callback, &esdi->callback, esdi); + + return(esdi); +} + + +static void +esdi_close(void *p) +{ + esdi_t *esdi = (esdi_t *)p; + esdi_drive_t *drive; + int d; + + esdi->drives[0].present = esdi->drives[1].present = 0; + + for (d=0; d<2; d++) { + drive = &esdi->drives[d]; + + hdd_image_close(drive->hdc_num); + } + + free(esdi); +} + + +static int esdi_available(void) +{ + return(rom_present(L"roms/hdd/esdi/90x8969.bin") && + rom_present(L"roms/hdd/esdi/90x8970.bin")); +} + + +device_t hdd_esdi_device = +{ + "IBM ESDI Fixed Disk Adapter (MCA)", + DEVICE_MCA, + esdi_init, + esdi_close, + esdi_available, + NULL, + NULL, + NULL, + NULL +}; diff --git a/src/hdd_esdi.h b/src/hdd_esdi_mca.h similarity index 100% rename from src/hdd_esdi.h rename to src/hdd_esdi_mca.h diff --git a/src/ide.c b/src/hdd_ide_at.c similarity index 99% rename from src/ide.c rename to src/hdd_ide_at.c index 72eb186d7..4d7104b15 100644 --- a/src/ide.c +++ b/src/hdd_ide_at.c @@ -9,14 +9,13 @@ * Implementation of the IDE emulation for hard disks and ATAPI * CD-ROM devices. * - * Version: @(#)ide.c 1.0.4 2017/06/20 + * Version: @(#)hdd_ide_at.c 1.0.5 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * TheCollector1995, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. - * Copyright 2016-2017 TheCollector1995. + * Copyright 2016,2017 Miran Grca. */ #include #include @@ -32,7 +31,7 @@ #include "timer.h" #include "cdrom.h" #include "scsi.h" -#include "ide.h" +#include "hdd_ide_at.h" /* Bits of 'atastat' */ #define ERR_STAT 0x01 diff --git a/src/ide.h b/src/hdd_ide_at.h similarity index 97% rename from src/ide.h rename to src/hdd_ide_at.h index ad3295ee8..b41ce3dfa 100644 --- a/src/ide.h +++ b/src/hdd_ide_at.h @@ -9,14 +9,13 @@ * Implementation of the IDE emulation for hard disks and ATAPI * CD-ROM devices. * - * Version: @(#)ide.h 1.0.1 2017/08/23 + * Version: @(#)hdd_ide_at.h 1.0.2 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * TheCollector1995, * Copyright 2008-2017 Sarah Walker. * Copyright 2016,2017 Miran Grca. - * Copyright 2016,2017 TheCollector1995. */ #ifndef EMU_IDE_H # define EMU_IDE_H diff --git a/src/xtide.c b/src/hdd_ide_xt.c similarity index 98% rename from src/xtide.c rename to src/hdd_ide_xt.c index a9d805e96..ed7d77a1a 100644 --- a/src/xtide.c +++ b/src/hdd_ide_xt.c @@ -8,7 +8,7 @@ * * XT IDE controller emulation. * - * Version: @(#)xtide.c 1.0.1 2017/06/03 + * Version: @(#)xtide.c 1.0.3 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, @@ -21,8 +21,8 @@ #include "mem.h" #include "rom.h" #include "device.h" -#include "ide.h" -#include "xtide.h" +#include "hdd_ide_at.h" +#include "hdd_ide_xt.h" #define XTIDE_ROM_PATH L"roms/hdd/xtide/ide_xt.bin" diff --git a/src/xtide.h b/src/hdd_ide_xt.h similarity index 100% rename from src/xtide.h rename to src/hdd_ide_xt.h diff --git a/src/hdd_image.c b/src/hdd_image.c index bf0b45b11..6cbd0e525 100644 --- a/src/hdd_image.c +++ b/src/hdd_image.c @@ -8,7 +8,7 @@ #include #include "ibm.h" -#include "ide.h" +#include "hdd_ide_at.h" #include "hdd_image.h" typedef struct diff --git a/src/mfm_at.c b/src/hdd_mfm_at.c similarity index 99% rename from src/mfm_at.c rename to src/hdd_mfm_at.c index c6531bbfd..69016126c 100644 --- a/src/mfm_at.c +++ b/src/hdd_mfm_at.c @@ -6,7 +6,7 @@ #include "io.h" #include "pic.h" #include "timer.h" -#include "mfm_at.h" +#include "hdd_mfm_at.h" #define IDE_TIME (TIMER_USEC*10) diff --git a/src/mfm_at.h b/src/hdd_mfm_at.h similarity index 100% rename from src/mfm_at.h rename to src/hdd_mfm_at.h diff --git a/src/mfm_xebec.c b/src/hdd_mfm_xebec.c similarity index 99% rename from src/mfm_xebec.c rename to src/hdd_mfm_xebec.c index f581d92d9..44de960da 100644 --- a/src/mfm_xebec.c +++ b/src/hdd_mfm_xebec.c @@ -10,7 +10,7 @@ #include "pic.h" #include "rom.h" #include "timer.h" -#include "mfm_xebec.h" +#include "hdd_mfm_xebec.h" #define XEBEC_TIME (2000 * TIMER_USEC) diff --git a/src/mfm_xebec.h b/src/hdd_mfm_xebec.h similarity index 100% rename from src/mfm_xebec.h rename to src/hdd_mfm_xebec.h diff --git a/src/ibm.h b/src/ibm.h index af30ad43e..ff84c0d38 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -8,12 +8,12 @@ * * General include file. * - * Version: @(#)ibm.h 1.0.1 2017/06/03 + * Version: @(#)ibm.h 1.0.2 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #include #include @@ -593,7 +593,7 @@ enum HDD_BUS_DISABLED = 0, HDD_BUS_MFM, HDD_BUS_XTIDE, - HDD_BUS_RLL, + HDD_BUS_ESDI, HDD_BUS_IDE_PIO_ONLY, HDD_BUS_IDE_PIO_AND_DMA, HDD_BUS_SCSI, @@ -603,7 +603,7 @@ enum #define HDC_NUM 30 #define MFM_NUM 2 -#define RLL_NUM 2 +#define ESDI_NUM 2 #define XTIDE_NUM 2 #define IDE_NUM 8 #define SCSI_NUM 16 /* Theoretically the controller can have at least 64 devices, or even 128 in case of a wide bus, but @@ -618,9 +618,9 @@ typedef struct { int wp; uint32_t base; uint64_t at_spt,at_hpc; /*[Translation] Sectors per track, heads per cylinder*/ - unsigned int bus; /* 0 = none, 1 = MFM/RLL, 2 = IDE, 3 = SCSI */ + unsigned int bus; unsigned int mfm_channel; - unsigned int rll_channel; + unsigned int esdi_channel; unsigned int xtide_channel; unsigned int ide_channel; unsigned int scsi_id; diff --git a/src/model.c b/src/model.c index a72cef74d..83a0adee9 100644 --- a/src/model.c +++ b/src/model.c @@ -8,16 +8,15 @@ * * Handling of the emulated machines. * - * Version: @(#)model.c 1.0.6 2017/08/23 + * Version: @(#)model.c 1.0.7 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #include #include - #include "ibm.h" #include "CPU/cpu.h" #include "io.h" @@ -36,7 +35,7 @@ #include "fdc37c932fr.h" #include "gameport.h" #include "i82335.h" -#include "ide.h" +#include "hdd_ide_at.h" #include "intel.h" #include "intel_flash.h" #include "keyboard_amstrad.h" @@ -71,7 +70,7 @@ #include "VIDEO/vid_tandy.h" #include "w83877f.h" #include "wd76c10.h" -#include "xtide.h" +#include "hdd_ide_xt.h" #include "bugger.h" diff --git a/src/mouse_bus.c b/src/mouse_bus.c index 526c3dc02..7b70ca712 100644 --- a/src/mouse_bus.c +++ b/src/mouse_bus.c @@ -32,11 +32,11 @@ * Based on an early driver for MINIX 1.5. * Based on the 86Box PS/2 mouse driver as a framework. * - * Version: @(#)mouse_bus.c 1.0.7 2017/07/27 + * Version: @(#)mouse_bus.c 1.0.8 2017/08/03 * - * Author: Fred N. van Kempen, - * TheCollector1995, - * Copyright 1989-2017 Fred N. van Kempen, TheCollector1995. + * Authors: Fred N. van Kempen, + * TheCollector1995 + * Copyright 1989-2017 Fred N. van Kempen. */ #include #include @@ -47,6 +47,395 @@ #include "mouse.h" +#define BUSMOUSE_PORT 0x023c +#define BUSMOUSE_PORTLEN 4 +#define BUSMOUSE_IRQ 5 + + +#define ENABLE_3BTN 1 /* enable 3-button mode */ + + +/* Our mouse device. */ +typedef struct mouse_bus { + int8_t type; + uint8_t flags; /* device flags */ + uint16_t port; /* I/O port range start */ + uint16_t portlen; /* length of I/O port range */ + int8_t irq; /* IRQ channel to use */ + + uint8_t r_magic; /* MAGIC register */ + uint8_t r_ctrl; /* CONTROL register (WR) */ + uint8_t r_intr; /* INTSTAT register (RO) */ + uint8_t r_conf; /* CONFIG register */ + + int8_t x, y; /* current mouse status */ + uint8_t but; + + uint8_t (*read)(struct mouse_bus *, uint16_t); + void (*write)(struct mouse_bus *, uint16_t, uint8_t); +} mouse_bus_t; +#define MOUSE_ENABLED 0x80 /* device is enabled for use */ +#define MOUSE_FROZEN 0x01 /* do not update counters */ + + +/* Definitions for Logitech. */ +#define LTMOUSE_DATA 0 /* DATA register */ +#define LTMOUSE_MAGIC 1 /* signature magic register */ +# define MAGIC_BYTE1 0xa5 /* most drivers use this */ +# define MAGIC_BYTE2 0x5a /* some drivers use this */ +#define LTMOUSE_CTRL 2 /* CTRL register */ +# define CTRL_FREEZE 0x80 /* do not sample when set */ +# define CTRL_RD_Y_HI 0x60 /* plus FREEZE */ +# define CTRL_RD_Y_LO 0x40 /* plus FREEZE */ +# define CTRL_RD_X_HI 0x20 /* plus FREEZE */ +# define CTRL_RD_X_LO 0x00 /* plus FREEZE */ +# define CTRL_RD_MASK 0x60 +# define CTRL_IDIS 0x10 +# define CTRL_IENB 0x00 +#define LTMOUSE_CONFIG 3 /* CONFIG register */ + +/* Definitions for Microsoft. */ +#define MSMOUSE_CTRL 0 /* CTRL register */ +# define MSCTRL_RESET 0x80 +# define MSCTRL_MODE 0x07 +# define MSCTRL_RD_Y 0x02 +# define MSCTRL_RD_X 0x01 +# define MSCTRL_RD_BUT 0x00 +#define MSMOUSE_DATA 1 /* DATA register */ +# define MSDATA_BASE 0x10 +# define MSDATA_IRQ 0x01 +#define MSMOUSE_MAGIC 2 /* MAGIC register */ +# define MAGIC_MSBYTE1 0xde /* indicates MS InPort */ +# define MAGIC_MSBYTE2 0xad +#define MSMOUSE_CONFIG 3 /* CONFIG register */ + + +/* Handle a WRITE to a LOGITECH register. */ +static void +lt_write(mouse_bus_t *ms, uint16_t port, uint8_t val) +{ + uint8_t b = (ms->r_ctrl ^ val); + +#if 0 + pclog("BUSMOUSE: lt_write(%d,%02x)\n", port, val); +#endif + + switch (port) { + case LTMOUSE_DATA: /* [00] data register */ + break; + + case LTMOUSE_MAGIC: /* [01] magic data register */ + if (val == MAGIC_BYTE1 || val == MAGIC_BYTE2) { + ms->r_magic = val; + } + break; + + case LTMOUSE_CTRL: /* [02] control register */ + if (b & CTRL_FREEZE) { + if (val & CTRL_FREEZE) { + /* Hold the sampling while we do something. */ + ms->flags |= MOUSE_FROZEN; + } else { + /* Reset current state. */ + ms->x = ms->y = 0; + if (ms->but) + /* One more POLL for button-release. */ + ms->but = 0x80; + ms->flags &= ~MOUSE_FROZEN; + } + } + + if (b & CTRL_IDIS) { + /* Disable or enable interrupts. */ + /* (we don't do anything for that here..) */ + } + + /* Save new register value. */ + ms->r_ctrl = val; + break; + + case LTMOUSE_CONFIG: /* [03] config register */ + ms->r_conf = val; + break; + + default: + break; + } +} + + +/* Handle a READ from a LOGITECH register. */ +static uint8_t +lt_read(mouse_bus_t *ms, uint16_t port) +{ + uint8_t r = 0xff; + + switch (port) { + case LTMOUSE_DATA: /* [00] data register */ + if (! (ms->r_ctrl & CTRL_FREEZE)) { + r = 0x00; + } else switch(ms->r_ctrl & CTRL_RD_MASK) { + case CTRL_RD_X_LO: /* X, low bits */ + /* + * Some drivers expect the buttons to + * be in this byte. Others want it in + * the Y-LO byte. --FvK + */ + r = 0x07; + if (ms->but & 0x01) /*LEFT*/ + r &= ~0x04; + if (ms->but & 0x02) /*RIGHT*/ + r &= ~0x01; +#if ENABLE_3BTN + if (ms->but & 0x04) /*MIDDLE*/ + r &= ~0x02; +#endif + r <<= 5; + r |= (ms->x & 0x0f); + break; + + case CTRL_RD_X_HI: /* X, high bits */ + r = (ms->x >> 4) & 0x0f; + break; + + case CTRL_RD_Y_LO: /* Y, low bits */ + r = (ms->y & 0x0f); + break; + + case CTRL_RD_Y_HI: /* Y, high bits */ + /* + * Some drivers expect the buttons to + * be in this byte. Others want it in + * the X-LO byte. --FvK + */ + r = 0x07; + if (ms->but & 0x01) /*LEFT*/ + r &= ~0x04; + if (ms->but & 0x02) /*RIGHT*/ + r &= ~0x01; +#if ENABLE_3BTN + if (ms->but & 0x04) /*MIDDLE*/ + r &= ~0x02; +#endif + r <<= 5; + r |= (ms->y >> 4) & 0x0f; + break; + } + break; + + case LTMOUSE_MAGIC: /* [01] magic data register */ + /* + * Logitech drivers start out by blasting their magic + * value (0xA5) into this register, and then read it + * back to see if that worked. If it did (and we do + * support this) the controller is assumed to be a + * Logitech-protocol one, and not InPort. + */ + r = ms->r_magic; + break; + + case LTMOUSE_CTRL: /* [02] control register */ + /* + * This is the weird stuff mentioned in the file header + * above. Microsoft's "mouse.exe" does some whacky stuff + * to extract the configured IRQ channel from the board. + * + * First, it reads the current value, and then re-reads + * it another 10,000 (yes, really) times. It keeps track + * of whether or not the data has changed, most likely + * to de-bounce reading of a DIP switch for example. This + * first value is assumed to be the 2's complement of the + * actual IRQ value. + * Next, it does this a second time, but now with the + * IDIS bit clear (so, interrupts enabled), which is + * our cue to return the regular (not complemented) value + * to them. + * + * Since we have to fake the initial value and the settling + * of the data a bit later on, we first return a bunch of + * invalid ("random") data, and then the real value. + * + * Yes, this is weird. --FvK + */ + if (ms->r_intr++ < 250) + /* Still settling, return invalid data. */ + r = (ms->r_ctrl&CTRL_IDIS)?0xff:0x00; + else { + /* OK, all good, return correct data. */ + r = (ms->r_ctrl&CTRL_IDIS)?-ms->irq:ms->irq; + ms->r_intr = 0; + } + break; + + case LTMOUSE_CONFIG: /* [03] config register */ + r = ms->r_conf; + break; + + default: + break; + } + +#if 0 + pclog("BUSMOUSE: lt_read(%d): %02x\n", port, r); +#endif + + return(r); +} + + +/* Initialize the Logitech Bus Mouse interface. */ +static void +lt_init(mouse_bus_t *ms) +{ + pclog("Logitech Bus Mouse, I/O=%04x, IRQ=%d\n", ms->port, ms->irq); + + /* Initialize registers. */ + ms->r_magic = 0x00; + ms->r_conf = 0x91; /* 8255 controller config */ + ms->r_ctrl = (CTRL_IDIS); + + /* Initialize I/O handlers. */ + ms->read = lt_read; + ms->write = lt_write; + + /* All done. */ + ms->flags = 0x00; +} + + +/* Handle a WRITE operation to one of our registers. */ +static void +busmouse_write(uint16_t port, uint8_t val, void *priv) +{ + mouse_bus_t *ms = (mouse_bus_t *)priv; + + ms->write(ms, port-ms->port, val); +} + + +/* Handle a READ operation from one of our registers. */ +static uint8_t +busmouse_read(uint16_t port, void *priv) +{ + mouse_bus_t *ms = (mouse_bus_t *)priv; + uint8_t r; + + r = ms->read(ms, port-ms->port); + + return(r); +} + + +/* The emulator calls us with an update on the host mouse device. */ +static uint8_t +busmouse_poll(int x, int y, int z, int b, void *priv) +{ + mouse_bus_t *ms = (mouse_bus_t *)priv; + + /* Return early if nothing to do. */ + if (!x && !y && !z && (ms->but == b)) return(1); + + /* If we are not interested, return. */ + if (!(ms->flags & MOUSE_ENABLED) || (ms->flags & MOUSE_FROZEN)) return(0); + +#if 0 + pclog("BUSMOUSE: poll(%d,%d,%d, %02x)\n", x, y, z, b); +#endif + + /* Add the delta to our state. */ + x += ms->x; + if (x > 127) + x = 127; + if (x < -128) + x = -128; + ms->x = (int8_t)x; + + y += ms->y; + if (y > 127) + y = 127; + if (y < -128) + y = -128; + ms->y = (int8_t)y; + + ms->but = b; + + /* All set, generate an interrupt. */ + if (! (ms->r_ctrl & CTRL_IDIS)) + picint(1 << ms->irq); + + return(0); +} + + +/* Release all resources held by the device. */ +static void +busmouse_close(void *priv) +{ + mouse_bus_t *ms = (mouse_bus_t *)priv; + + /* Release our I/O range. */ + io_removehandler(ms->port, ms->portlen, + busmouse_read, NULL, NULL, busmouse_write, NULL, NULL, ms); + + free(ms); +} + + +/* Initialize the device for use by the user. */ +static void * +busmouse_init(int type) +{ + mouse_bus_t *ms; + + ms = (mouse_bus_t *)malloc(sizeof(mouse_bus_t)); + memset(ms, 0x00, sizeof(mouse_bus_t)); + ms->type = type; + ms->port = BUSMOUSE_PORT; + ms->portlen = BUSMOUSE_PORTLEN; +#if BUSMOUSE_IRQ + ms->irq = BUSMOUSE_IRQ; +#else + ms->irq = -1; +#endif + + switch(ms->type) { + case MOUSE_TYPE_LOGIBUS: + lt_init(ms); + break; + + case MOUSE_TYPE_INPORT: +// ms_init(ms); + break; + } + ms->flags |= MOUSE_ENABLED; + + /* Request an I/O range. */ + io_sethandler(ms->port, ms->portlen, + busmouse_read, NULL, NULL, busmouse_write, NULL, NULL, ms); + + /* Return our private data to the I/O layer. */ + return(ms); +} + + +static void * +logibus_init(void) +{ + return(busmouse_init(MOUSE_TYPE_LOGIBUS)); +} + + +static void * +inport_init(void) +{ + return(busmouse_init(MOUSE_TYPE_LOGIBUS)); +} + + + +#if 0 +@@@@ + #define BUS_MOUSE_IRQ 5 #define IRQ_MASK ((1<<5) >> BUS_MOUSE_IRQ) @@ -394,44 +783,6 @@ static uint8_t busmouse_poll(int x, int y, int z, int b, void *priv) return(0); } -/* Release all resources held by the device. */ -static void busmouse_close(void *priv) -{ - mouse_bus_t *busmouse = (mouse_bus_t *)priv; - - /* Release our I/O range. */ - io_removehandler(0x023C, 0x0004, busmouse_read, NULL, NULL, busmouse_write, NULL, NULL, busmouse); - - free(busmouse); -} - -/* Initialize the device for use by the user. */ -static void *busmouse_init(void) -{ - mouse_bus_t *busmouse; - - busmouse = (mouse_bus_t *)malloc(sizeof(mouse_bus_t)); - memset(busmouse, 0x00, sizeof(mouse_bus_t)); - - busmouse->is_inport = 0; - busmouse->irq = BUS_MOUSE_IRQ; - - /* Initialize registers. */ - busmouse->control_val = 0x1f; /* The control port value */ - busmouse->config_val = 0x0e; /* The config port value */ - - /* Common. */ - busmouse->command_val = 0; - busmouse->toggle_counter = 0; - busmouse->interrupts = 0; - - /* Request an I/O range. */ - io_sethandler(0x023C, 0x0004, busmouse_read, NULL, NULL, busmouse_write, NULL, NULL, busmouse); - timer_add(busmouse_timer_handler, &busmouse->timer_index, TIMER_ALWAYS_ENABLED, busmouse); - - /* Return our private data to the I/O layer. */ - return(busmouse); -} /* Initialize the device for use by the user. */ static void *inport_init(void) @@ -460,21 +811,21 @@ static void *inport_init(void) /* Return our private data to the I/O layer. */ return(inport); } +#endif -mouse_t mouse_bus_logitech = -{ + +mouse_t mouse_bus_logitech = { "Logitech Bus Mouse", - "msbus", + "logibus", MOUSE_TYPE_LOGIBUS, - busmouse_init, + logibus_init, busmouse_close, busmouse_poll }; -mouse_t mouse_bus_msinport = -{ - "InPort Mouse", - "inport", +mouse_t mouse_bus_msinport = { + "Microsoft Bus Mouse (InPort)", + "msbus", MOUSE_TYPE_INPORT, inport_init, busmouse_close, diff --git a/src/mouse_serial.c b/src/mouse_serial.c index 422de2045..40b80f44a 100644 --- a/src/mouse_serial.c +++ b/src/mouse_serial.c @@ -10,7 +10,7 @@ * * Based on the 86Box Serial Mouse driver as a framework. * - * Version: @(#)mouse_serial.c 1.0.7 2017/07/27 + * Version: @(#)mouse_serial.c 1.0.8 2017/08/03 * * Author: Fred N. van Kempen, */ diff --git a/src/pc.c b/src/pc.c index 35c33598d..2cf524243 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,17 +8,16 @@ * * Emulation core dispatcher. * - * Version: @(#)pc.c 1.0.6 2017/06/17 + * Version: @(#)pc.c 1.0.7 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ #include #include #include - #include "86box.h" #include "ibm.h" #include "mem.h" @@ -45,7 +44,7 @@ #include "fdd.h" #include "gameport.h" #include "hdd.h" -#include "ide.h" +#include "hdd_ide_at.h" #include "cdrom.h" #include "cdrom_ioctl.h" #include "cdrom_image.h" diff --git a/src/pc87306.c b/src/pc87306.c index b67aa5071..253cd8308 100644 --- a/src/pc87306.c +++ b/src/pc87306.c @@ -9,21 +9,19 @@ * Emulation of the National Semiconductors PC87306 Super I/O * chip. * - * Version: @(#)pc87306.c 1.0.0 2017/05/30 + * Version: @(#)pc87306.c 1.0.1 2017/08/24 * * Author: Miran Grca, - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ - #include "ibm.h" - #include "disc.h" #include "fdc.h" #include "fdd.h" -#include "ide.h" #include "io.h" #include "lpt.h" #include "serial.h" +#include "hdd_ide_at.h" #include "pc87306.h" static int pc87306_curreg; diff --git a/src/piix.c b/src/piix.c index 002d7de3b..abeaa155b 100644 --- a/src/piix.c +++ b/src/piix.c @@ -8,12 +8,12 @@ * * Emulation core dispatcher. * - * Version: @(#)piix.c 1.0.1 2017/08/23 + * Version: @(#)piix.c 1.0.2 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ /*PRD format : @@ -25,10 +25,10 @@ #include "ibm.h" #include "dma.h" -#include "ide.h" #include "io.h" #include "mem.h" #include "pci.h" +#include "hdd_ide_at.h" #include "piix.h" diff --git a/src/scsi_aha154x.c b/src/scsi_aha154x.c index 2028bf255..7844707db 100644 --- a/src/scsi_aha154x.c +++ b/src/scsi_aha154x.c @@ -12,7 +12,7 @@ * * NOTE: THIS IS CURRENTLY A MESS, but will be cleaned up as I go. * - * Version: @(#)scsi_aha154x.c 1.0.11 2017/08/23 + * Version: @(#)scsi_aha154x.c 1.0.12 2017/08/24 * * Authors: Fred N. van Kempen, * Original Buslogic version by SA1988 and Miran Grca. @@ -654,6 +654,10 @@ aha_reset(aha_t *dev) static void aha_reset_ctrl(aha_t *dev, uint8_t Reset) { + /* Say hello! */ + pclog("Adaptec %s (IO=0x%04X, IRQ=%d, DMA=%d)\n", + dev->name, dev->Base, dev->Irq, dev->DmaChannel); + aha_reset(dev); if (Reset) { dev->Status |= STAT_STST; @@ -1730,13 +1734,19 @@ aha_mca_write(int port, uint8_t val, void *priv) if (dev->pos_regs[2] & 1) { addr = aha_mca_get_port(dev->pos_regs[3]); + dev->Base = addr; io_sethandler(addr, 4, aha_read, aha_readw, NULL, aha_write, aha_writew, NULL, dev); } - dev->Irq = (dev->pos_regs[4] & 0x7) + 8; - dev->DmaChannel = dev->pos_regs[5] & 0xf; + dev->Irq = (dev->pos_regs[4] & 0x07) + 8; + dev->DmaChannel = dev->pos_regs[5] & 0x0f; + + /* Initialize the device if fully configured. */ + if (dev->Base != 0 && dev->Irq != 0 && dev->DmaChannel != 0) { + aha_reset_ctrl(dev, CTRL_HRST); + } } @@ -1936,7 +1946,13 @@ aha_init(int type) memset(dev, 0x00, sizeof(aha_t)); dev->type = type; - /* Set up the (initial) I/O address, IRQ and DMA info. */ + /* + * Set up the (initial) I/O address, IRQ and DMA info. + * + * Note that on MCA, configuration is handled by the BIOS, + * and so any info we get here will be overwritten by the + * MCA-assigned values later on! + */ dev->Base = device_get_config_hex16("base"); dev->Irq = device_get_config_int("irq"); dev->DmaChannel = device_get_config_int("dma"); @@ -1992,6 +2008,8 @@ aha_init(int type) break; case AHA_1640: + strcpy(dev->name, "AHA-1640"); + /* Enable MCA. */ dev->pos_regs[0] = 0x1F; dev->pos_regs[1] = 0x0F; @@ -2014,15 +2032,11 @@ aha_init(int type) io_sethandler(dev->Base, 4, aha_read, aha_readw, NULL, aha_write, aha_writew, NULL, dev); + + /* Initialize the device. */ + aha_reset_ctrl(dev, CTRL_HRST); } - /* Say hello! */ - pclog("Adaptec %s (IO=0x%04X, IRQ=%d, DMA=%d)\n", - dev->name, dev->Base, dev->Irq, dev->DmaChannel); - - /* Reset the device. */ - aha_reset_ctrl(dev, CTRL_HRST); - return(dev); } diff --git a/src/scsi_disk.c b/src/scsi_disk.c index 8a19c7cbb..5e75ab49e 100644 --- a/src/scsi_disk.c +++ b/src/scsi_disk.c @@ -6,7 +6,7 @@ * * Emulation of SCSI fixed and removable disks. * - * Version: @(#)scsi_disk.c 1.0.5 2017/08/23 + * Version: @(#)scsi_disk.c 1.0.6 2017/08/24 * * Author: Miran Grca, * Copyright 2017 Miran Grca. @@ -20,7 +20,7 @@ #include "cdrom.h" #include "ibm.h" #include "hdd_image.h" -#include "ide.h" +#include "hdd_ide_at.h" #include "piix.h" #include "scsi.h" #include "scsi_disk.h" diff --git a/src/sio.c b/src/sio.c index dd51810b2..1329be8fc 100644 --- a/src/sio.c +++ b/src/sio.c @@ -6,7 +6,7 @@ * * Emulation of Intel System I/O PCI chip. * - * Version: @(#)sio.c 1.0.2 2017/08/23 + * Version: @(#)sio.c 1.0.3 2017/08/24 * * Authors: Sarah Walker, * Miran Grca, @@ -20,7 +20,7 @@ #include "dma.h" #include "fdc.h" #include "keyboard_at.h" -#include "ide.h" +#include "hdd_ide_at.h" #include "io.h" #include "mem.h" #include "pci.h" diff --git a/src/sis85c471.c b/src/sis85c471.c index 8b337a30c..513ab2ea3 100644 --- a/src/sis85c471.c +++ b/src/sis85c471.c @@ -9,19 +9,19 @@ * SiS sis85c471 Super I/O Chip * Used by Batman's Revenge * - * Version: @(#)sis85c471.c 1.0.1 2017/08/23 + * Version: @(#)sis85c471.c 1.0.2 2017/08/24 * * Author: Miran Grca, * Copyright 2017 Miran Grca. */ #include "ibm.h" -#include "ide.h" +#include "io.h" +#include "lpt.h" #include "disc.h" #include "fdc.h" #include "fdd.h" -#include "io.h" -#include "lpt.h" #include "serial.h" +#include "hdd_ide_at.h" #include "sis85c471.h"