diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index 3d572d035..b2743528b 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -9,7 +9,7 @@ * Implementation of the IDE emulation for hard disks and ATAPI * CD-ROM devices. * - * Version: @(#)hdc_ide.c 1.0.33 2018/03/15 + * Version: @(#)hdc_ide.c 1.0.34 2018/03/15 * * Authors: Sarah Walker, * Miran Grca, @@ -20,10 +20,11 @@ #define __USE_LARGEFILE64 #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE +#include #include #include +#include #include -#include #include #include #define HAVE_STDARG_H @@ -793,6 +794,24 @@ 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; @@ -818,8 +837,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; @@ -832,12 +861,16 @@ 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 = NULL; /* Important, makes sure malloc does not reuse an existing pointer from elsewhere. */ + 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 = NULL; /* Important, makes sure malloc does not reuse an existing pointer from elsewhere. */ + ide_drives[hdd[d].xtide_channel | 8].sector_buffer = (uint8_t *) malloc(256*512); if (++c >= (IDE_NUM+XTIDE_NUM)) break; } } @@ -845,13 +878,14 @@ 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 = NULL; /* Important, makes sure malloc does not reuse an existing pointer from elsewhere. */ + ide_drives[d].buffer = (uint16_t *) malloc(65536); } ide_set_signature(&ide_drives[d]); diff --git a/src/disk/hdc_ide.h b/src/disk/hdc_ide.h index ce3cd8436..74e938b2e 100644 --- a/src/disk/hdc_ide.h +++ b/src/disk/hdc_ide.h @@ -9,7 +9,7 @@ * Implementation of the IDE emulation for hard disks and ATAPI * CD-ROM devices. * - * Version: @(#)hdd_ide.h 1.0.6 2018/02/14 + * Version: @(#)hdd_ide.h 1.0.7 2018/03/15 * * Authors: Sarah Walker, * Miran Grca, @@ -36,7 +36,7 @@ typedef struct { int packetstatus; uint8_t asc; int reset; - uint16_t buffer[65536]; + uint16_t *buffer; int irqstat; int service; int lba; @@ -49,7 +49,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; @@ -104,6 +104,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); diff --git a/src/pc.c b/src/pc.c index 8ec023651..3aec78258 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Main emulator module where most things are controlled. * - * Version: @(#)pc.c 1.0.63 2018/03/13 + * Version: @(#)pc.c 1.0.64 2018/03/15 * * Authors: Sarah Walker, * Miran Grca, @@ -968,6 +968,8 @@ pc_close(thread_t *ptr) sound_cd_thread_end(); mem_destroy_pages(); + + ide_destroy_buffers(); }