Monster patch to clean up a lot of cruft in the code, and reduce the RAM footptiny of a running XT machine from about 680MB down to about 80MB. Yes, 600MB of unused 0x00's.

This commit is contained in:
waltje
2018-03-17 23:13:46 -05:00
parent a86d717ae1
commit 1c60e22813
217 changed files with 9300 additions and 9128 deletions

View File

@@ -8,7 +8,7 @@
*
* Common code to handle all sorts of disk controllers.
*
* Version: @(#)hdc.c 1.0.1 2018/02/14
* Version: @(#)hdc.c 1.0.2 2018/03/15
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -49,7 +49,7 @@ int hdc_current;
static void *
null_init(device_t *info)
null_init(const device_t *info)
{
return(NULL);
}
@@ -61,7 +61,7 @@ null_close(void *priv)
}
static device_t null_device = {
static const device_t null_device = {
"Null HDC", 0, 0,
null_init, null_close, NULL,
NULL, NULL, NULL, NULL, NULL
@@ -69,7 +69,7 @@ static device_t null_device = {
static void *
inthdc_init(device_t *info)
inthdc_init(const device_t *info)
{
return(NULL);
}
@@ -81,18 +81,18 @@ inthdc_close(void *priv)
}
static device_t inthdc_device = {
static const device_t inthdc_device = {
"Internal Controller", 0, 0,
inthdc_init, inthdc_close, NULL,
NULL, NULL, NULL, NULL, NULL
};
static struct {
char *name;
char *internal_name;
device_t *device;
int is_mfm;
static const struct {
const char *name;
const char *internal_name;
const device_t *device;
int is_mfm;
} controllers[] = {
{ "None", "none",
&null_device, 0 },
@@ -158,7 +158,7 @@ hdc_init(char *name)
pclog("HDC: initializing..\n");
for (c=0; controllers[c].device; c++) {
if (! strcmp(name, controllers[c].internal_name)) {
if (! strcmp(name, (char *)controllers[c].internal_name)) {
hdc_current = c;
break;
}
@@ -182,18 +182,18 @@ hdc_reset(void)
char *
hdc_get_name(int hdc)
{
return(controllers[hdc].name);
return((char *)controllers[hdc].name);
}
char *
hdc_get_internal_name(int hdc)
{
return(controllers[hdc].internal_name);
return((char *)controllers[hdc].internal_name);
}
device_t *
const device_t *
hdc_get_device(int hdc)
{
return(controllers[hdc].device);

View File

@@ -8,7 +8,7 @@
*
* Definitions for the common disk controller handler.
*
* Version: @(#)hdc.h 1.0.1 2018/02/14
* Version: @(#)hdc.h 1.0.2 2018/03/15
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -46,29 +46,29 @@
* least 7 devices, with each device being
* able to support 8 units, but hey... */
extern char *hdc_name;
extern int hdc_current;
extern char *hdc_name;
extern int hdc_current;
extern device_t mfm_xt_xebec_device; /* mfm_xt_xebec */
extern device_t mfm_xt_dtc5150x_device; /* mfm_xt_dtc */
extern device_t mfm_at_wd1003_device; /* mfm_at_wd1003 */
extern const device_t mfm_xt_xebec_device; /* mfm_xt_xebec */
extern const device_t mfm_xt_dtc5150x_device; /* mfm_xt_dtc */
extern const device_t mfm_at_wd1003_device; /* mfm_at_wd1003 */
extern device_t esdi_at_wd1007vse1_device; /* esdi_at */
extern device_t esdi_ps2_device; /* esdi_mca */
extern const device_t esdi_at_wd1007vse1_device; /* esdi_at */
extern const device_t esdi_ps2_device; /* esdi_mca */
extern device_t ide_isa_device; /* isa_ide */
extern device_t ide_isa_2ch_device; /* isa_ide_2ch */
extern device_t ide_isa_2ch_opt_device; /* isa_ide_2ch_opt */
extern device_t ide_vlb_device; /* vlb_ide */
extern device_t ide_vlb_2ch_device; /* vlb_ide_2ch */
extern device_t ide_pci_device; /* pci_ide */
extern device_t ide_pci_2ch_device; /* pci_ide_2ch */
extern const device_t ide_isa_device; /* isa_ide */
extern const device_t ide_isa_2ch_device; /* isa_ide_2ch */
extern const device_t ide_isa_2ch_opt_device; /* isa_ide_2ch_opt */
extern const device_t ide_vlb_device; /* vlb_ide */
extern const device_t ide_vlb_2ch_device; /* vlb_ide_2ch */
extern const device_t ide_pci_device; /* pci_ide */
extern const device_t ide_pci_2ch_device; /* pci_ide_2ch */
extern device_t xtide_device; /* xtide_xt */
extern device_t xtide_at_device; /* xtide_at */
extern device_t xtide_acculogic_device; /* xtide_ps2 */
extern device_t xtide_at_ps2_device; /* xtide_at_ps2 */
extern const device_t xtide_device; /* xtide_xt */
extern const device_t xtide_at_device; /* xtide_at */
extern const device_t xtide_acculogic_device; /* xtide_ps2 */
extern const device_t xtide_at_ps2_device; /* xtide_at_ps2 */
extern void hdc_init(char *name);
@@ -76,7 +76,7 @@ extern void hdc_reset(void);
extern char *hdc_get_name(int hdc);
extern char *hdc_get_internal_name(int hdc);
extern device_t *hdc_get_device(int hdc);
extern const device_t *hdc_get_device(int hdc);
extern int hdc_get_flags(int hdc);
extern int hdc_available(int hdc);
extern int hdc_current_is_mfm(void);

View File

@@ -8,7 +8,7 @@
*
* Driver for the ESDI controller (WD1007-vse1) for PC/AT.
*
* Version: @(#)hdc_esdi_at.c 1.0.2 2018/02/26
* Version: @(#)hdc_esdi_at.c 1.0.3 2018/03/15
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -788,7 +788,7 @@ loadhd(esdi_t *esdi, int hdd_num, int d, const wchar_t *fn)
static void *
wd1007vse1_init(device_t *info)
wd1007vse1_init(const device_t *info)
{
int c, d;
@@ -853,7 +853,7 @@ wd1007vse1_available(void)
}
device_t esdi_at_wd1007vse1_device = {
const device_t esdi_at_wd1007vse1_device = {
"Western Digital WD1007V-SE1 (ESDI)",
DEVICE_ISA | DEVICE_AT,
0,

View File

@@ -52,7 +52,7 @@
* however, are auto-configured by the system software as
* shown above.
*
* Version: @(#)hdc_esdi_mca.c 1.0.1 2018/02/14
* Version: @(#)hdc_esdi_mca.c 1.0.2 2018/03/15
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Sarah Walker, <tommowalker@tommowalker.co.uk>
@@ -1059,7 +1059,7 @@ esdi_mca_write(int port, uint8_t val, void *priv)
static void *
esdi_init(device_t *info)
esdi_init(const device_t *info)
{
drive_t *drive;
esdi_t *dev;
@@ -1153,7 +1153,7 @@ esdi_available(void)
}
device_t esdi_ps2_device = {
const device_t esdi_ps2_device = {
"IBM ESDI Fixed Disk Adapter (MCA)",
DEVICE_MCA, 0,
esdi_init, esdi_close, NULL,

View File

@@ -9,7 +9,7 @@
* Implementation of the IDE emulation for hard disks and ATAPI
* CD-ROM devices.
*
* Version: @(#)hdc_ide.c 1.0.7 2018/03/12
* Version: @(#)hdc_ide.c 1.0.9 2018/03/16
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Sarah Walker, <tommowalker@tommowalker.co.uk>
@@ -38,11 +38,12 @@
#define __USE_LARGEFILE64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <inttypes.h>
#include <wchar.h>
#define HAVE_STDARG_H
#include "../emu.h"
@@ -757,6 +758,25 @@ void ide_ter_disable_cond();
void ide_qua_disable_cond();
void ide_destroy_buffers(void)
{
int d;
for (d = 0; d < (IDE_NUM+XTIDE_NUM); d++)
{
if (ide_drives[d].buffer) {
free(ide_drives[d].buffer);
ide_drives[d].buffer = NULL;
}
if (ide_drives[d].sector_buffer) {
free(ide_drives[d].sector_buffer);
ide_drives[d].sector_buffer = NULL;
}
}
}
void ide_reset(void)
{
int c, d;
@@ -782,8 +802,18 @@ void ide_reset(void)
ide_drives[d].atastat = READY_STAT | DSC_STAT;
ide_drives[d].service = 0;
ide_drives[d].board = d >> 1;
if (ide_drives[d].buffer) {
free(ide_drives[d].buffer);
ide_drives[d].buffer = NULL;
}
if (ide_drives[d].sector_buffer) {
free(ide_drives[d].sector_buffer);
ide_drives[d].sector_buffer = NULL;
}
}
idecallback[0]=idecallback[1]=0LL;
idecallback[2]=idecallback[3]=0LL;
idecallback[4]=0LL;
@@ -796,12 +826,14 @@ void ide_reset(void)
{
ide_log("Found IDE hard disk on channel %i\n", hdd[d].ide_channel);
loadhd(&ide_drives[hdd[d].ide_channel], d, hdd[d].fn);
ide_drives[hdd[d].ide_channel].sector_buffer = (uint8_t *) malloc(256*512);
if (++c >= (IDE_NUM+XTIDE_NUM)) break;
}
if ((hdd[d].bus==HDD_BUS_XTIDE) && (hdd[d].xtide_channel < XTIDE_NUM))
{
ide_log("Found XT IDE hard disk on channel %i\n", hdd[d].xtide_channel);
loadhd(&ide_drives[hdd[d].xtide_channel | 8], d, hdd[d].fn);
ide_drives[hdd[d].xtide_channel | 8].sector_buffer = (uint8_t *) malloc(256*512);
if (++c >= (IDE_NUM+XTIDE_NUM)) break;
}
}
@@ -809,14 +841,13 @@ void ide_reset(void)
for (d = 0; d < IDE_NUM; d++)
{
if (ide_drive_is_zip(&ide_drives[d]) && (ide_drives[d].type != IDE_HDD))
{
if (ide_drive_is_zip(&ide_drives[d]) && (ide_drives[d].type == IDE_NONE))
ide_drives[d].type = IDE_ZIP;
}
else if (ide_drive_is_cdrom(&ide_drives[d]) && (ide_drives[d].type != IDE_HDD))
{
else if (ide_drive_is_cdrom(&ide_drives[d]) && (ide_drives[d].type == IDE_NONE))
ide_drives[d].type = IDE_CDROM;
}
if (ide_drives[d].type != IDE_NONE)
ide_drives[d].buffer = (uint16_t *) malloc(65536 * sizeof(uint16_t));
ide_set_signature(&ide_drives[d]);
@@ -2758,7 +2789,7 @@ void secondary_ide_check(void)
* keeping a zillion of duplicate functions around.
*/
static void *
ide_sainit(device_t *info)
ide_sainit(const device_t *info)
{
switch(info->local) {
case 0: /* ISA, single-channel */
@@ -2788,7 +2819,7 @@ ide_sainit(device_t *info)
break;
}
return(info);
return((void *)info);
}
@@ -2800,7 +2831,7 @@ ide_saclose(void *priv)
}
device_t ide_isa_device = {
const device_t ide_isa_device = {
"ISA PC/AT IDE Controller",
DEVICE_ISA | DEVICE_AT,
0,
@@ -2809,7 +2840,7 @@ device_t ide_isa_device = {
NULL
};
device_t ide_isa_2ch_device = {
const device_t ide_isa_2ch_device = {
"ISA PC/AT IDE Controller (Dual-Channel)",
DEVICE_ISA | DEVICE_AT,
2,
@@ -2818,7 +2849,7 @@ device_t ide_isa_2ch_device = {
NULL
};
device_t ide_isa_2ch_opt_device = {
const device_t ide_isa_2ch_opt_device = {
"ISA PC/AT IDE Controller (Single/Dual)",
DEVICE_ISA | DEVICE_AT,
3,
@@ -2827,7 +2858,7 @@ device_t ide_isa_2ch_opt_device = {
NULL
};
device_t ide_vlb_device = {
const device_t ide_vlb_device = {
"VLB IDE Controller",
DEVICE_VLB | DEVICE_AT,
4,
@@ -2836,7 +2867,7 @@ device_t ide_vlb_device = {
NULL
};
device_t ide_vlb_2ch_device = {
const device_t ide_vlb_2ch_device = {
"VLB IDE Controller (Dual-Channel)",
DEVICE_VLB | DEVICE_AT,
6,
@@ -2845,7 +2876,7 @@ device_t ide_vlb_2ch_device = {
NULL
};
device_t ide_pci_device = {
const device_t ide_pci_device = {
"PCI IDE Controller",
DEVICE_PCI | DEVICE_AT,
8,
@@ -2854,7 +2885,7 @@ device_t ide_pci_device = {
NULL
};
device_t ide_pci_2ch_device = {
const device_t ide_pci_2ch_device = {
"PCI IDE Controller (Dual-Channel)",
DEVICE_PCI | DEVICE_AT,
10,

View File

@@ -8,7 +8,7 @@
*
* Definitions for the IDE module.
*
* Version: @(#)hdd_ide.h 1.0.1 2018/02/14
* Version: @(#)hdc_ide.h 1.0.2 2018/03/15
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -56,7 +56,7 @@ typedef struct {
int packetstatus;
uint8_t asc;
int reset;
uint16_t buffer[65536];
uint16_t *buffer;
int irqstat;
int service;
int lba;
@@ -69,7 +69,7 @@ typedef struct {
int hdd_num;
uint8_t specify_success;
int mdma_mode;
uint8_t sector_buffer[256*512];
uint8_t *sector_buffer;
int do_initial_read;
int sector_pos;
} IDE;
@@ -124,6 +124,7 @@ extern void ide_set_callback(uint8_t channel, int64_t callback);
extern void secondary_ide_check(void);
extern void ide_padstr8(uint8_t *buf, int buf_size, const char *src);
extern void ide_destroy_buffers(void);
extern int (*ide_bus_master_read)(int channel, uint8_t *data, int transfer_length);
extern int (*ide_bus_master_write)(int channel, uint8_t *data, int transfer_length);

View File

@@ -12,7 +12,7 @@
* based design. Most cards were WD1003-WA2 or -WAH, where the
* -WA2 cards had a floppy controller as well (to save space.)
*
* Version: @(#)hdc_mfm_at.c 1.0.1 2018/02/14
* Version: @(#)hdc_mfm_at.c 1.0.2 2018/03/15
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Sarah Walker, <tommowalker@tommowalker.co.uk>
@@ -725,7 +725,7 @@ loadhd(mfm_t *mfm, int c, int d, const wchar_t *fn)
static void *
mfm_init(device_t *info)
mfm_init(const device_t *info)
{
mfm_t *mfm;
int c, d;
@@ -782,7 +782,7 @@ mfm_close(void *priv)
}
device_t mfm_at_wd1003_device = {
const device_t mfm_at_wd1003_device = {
"WD1003 AT MFM/RLL Controller",
DEVICE_ISA | DEVICE_AT,
0,

View File

@@ -41,7 +41,7 @@
* Since all controllers (including the ones made by DTC) use
* (mostly) the same API, we keep them all in this module.
*
* Version: @(#)hdc_mfm_xt.c 1.0.1 2018/02/14
* Version: @(#)hdc_mfm_xt.c 1.0.2 2018/03/15
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Sarah Walker, <tommowalker@tommowalker.co.uk>
@@ -826,7 +826,7 @@ mfm_set_switches(mfm_t *mfm)
static void *
xebec_init(device_t *info)
xebec_init(const device_t *info)
{
int i, c = 0;
@@ -881,7 +881,7 @@ xebec_available(void)
}
device_t mfm_xt_xebec_device = {
const device_t mfm_xt_xebec_device = {
"IBM PC Fixed Disk Adapter",
DEVICE_ISA,
0,
@@ -892,7 +892,7 @@ device_t mfm_xt_xebec_device = {
static void *
dtc5150x_init(device_t *info)
dtc5150x_init(const device_t *info)
{
int i, c = 0;
@@ -936,7 +936,7 @@ dtc5150x_available(void)
}
device_t mfm_xt_dtc5150x_device = {
const device_t mfm_xt_dtc5150x_device = {
"DTC 5150X",
DEVICE_ISA,
0,

View File

@@ -21,7 +21,7 @@
* already on their way out, the newer IDE standard based on the
* PC/AT controller and 16b design became the IDE we now know.
*
* Version: @(#)hdc_xtide.c 1.0.2 2018/02/22
* Version: @(#)hdc_xtide.c 1.0.3 2018/03/15
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com>
@@ -143,7 +143,7 @@ xtide_read(uint16_t port, void *priv)
static void *
xtide_init(device_t *info)
xtide_init(const device_t *info)
{
xtide_t *xtide = malloc(sizeof(xtide_t));
@@ -170,7 +170,7 @@ xtide_available(void)
static void *
xtide_at_init(device_t *info)
xtide_at_init(const device_t *info)
{
xtide_t *xtide = malloc(sizeof(xtide_t));
@@ -193,7 +193,7 @@ xtide_at_available(void)
static void *
xtide_acculogic_init(device_t *info)
xtide_acculogic_init(const device_t *info)
{
xtide_t *xtide = malloc(sizeof(xtide_t));
@@ -220,7 +220,7 @@ xtide_acculogic_available(void)
static void *
xtide_at_ps2_init(device_t *info)
xtide_at_ps2_init(const device_t *info)
{
xtide_t *xtide = malloc(sizeof(xtide_t));
@@ -251,7 +251,7 @@ xtide_close(void *priv)
}
device_t xtide_device = {
const device_t xtide_device = {
"XTIDE",
DEVICE_ISA,
0,
@@ -260,7 +260,7 @@ device_t xtide_device = {
NULL
};
device_t xtide_at_device = {
const device_t xtide_at_device = {
"XTIDE (AT)",
DEVICE_ISA | DEVICE_AT,
0,
@@ -269,7 +269,7 @@ device_t xtide_at_device = {
NULL
};
device_t xtide_acculogic_device = {
const device_t xtide_acculogic_device = {
"XTIDE (Acculogic)",
DEVICE_ISA,
0,
@@ -278,7 +278,7 @@ device_t xtide_acculogic_device = {
NULL
};
device_t xtide_at_ps2_device = {
const device_t xtide_at_ps2_device = {
"XTIDE (AT) (1.1.5)",
DEVICE_ISA | DEVICE_PS2,
0,