AWE32 onboard RAM size now configurable.

Also fixed a memory leak in the EMU8000.
This commit is contained in:
TomW 2015-08-27 20:39:38 +01:00
commit 115e829480
3 changed files with 81 additions and 10 deletions

View file

@ -45,9 +45,11 @@ static inline int16_t EMU8K_READ(emu8k_t *emu8k, uint32_t addr)
addr &= 0xffffff;
if (addr < 0x80000)
return emu8k->rom[addr];
if (addr < 0x200000 || addr >= 0x400000)
if (addr < 0x200000 || addr >= emu8k->ram_end_addr)
return 0;
return emu8k->ram[addr & 0x1fffff];
if (!emu8k->ram)
return 0;
return emu8k->ram[addr - 0x200000];
}
static inline int16_t EMU8K_READ_INTERP(emu8k_t *emu8k, uint32_t addr)
@ -60,8 +62,8 @@ static inline int16_t EMU8K_READ_INTERP(emu8k_t *emu8k, uint32_t addr)
static inline void EMU8K_WRITE(emu8k_t *emu8k, uint32_t addr, uint16_t val)
{
addr &= 0xffffff;
if (addr >= 0x200000 && addr < 0x400000)
emu8k->ram[addr & 0x1fffff] = val;
if (emu8k->ram && addr >= 0x200000 && addr < emu8k->ram_end_addr)
emu8k->ram[addr - 0x200000] = val;
}
static int ff = 0;
static int voice_count = 0;
@ -641,7 +643,7 @@ void emu8k_poll_getsamp(emu8k_t *emu8k, int16_t *l, int16_t *r)
*r = emu8k->out_r;
}
void emu8k_init(emu8k_t *emu8k)
void emu8k_init(emu8k_t *emu8k, int onboard_ram)
{
FILE *f;
int c;
@ -650,8 +652,13 @@ void emu8k_init(emu8k_t *emu8k)
f = romfopen("roms/awe32.raw", "rb");
if (!f)
fatal("ROMS/AWE32.RAW not found\n");
emu8k->ram = malloc(4096 * 1024);
if (onboard_ram)
{
emu8k->ram = malloc(onboard_ram * 1024);
emu8k->ram_end_addr = 0x200000 + ((onboard_ram * 1024) / 2);
}
emu8k->rom = malloc(1024 * 1024);
fread(emu8k->rom, 1024 * 1024, 1, f);
@ -715,3 +722,8 @@ void emu8k_init(emu8k_t *emu8k)
emu8k->hwcf3 = 0x04;
}
void emu8k_close(emu8k_t *emu8k)
{
free(emu8k->rom);
free(emu8k->ram);
}

View file

@ -72,6 +72,8 @@ typedef struct emu8k_t
int16_t *ram, *rom;
uint32_t ram_end_addr;
int cur_reg, cur_voice;
int timer_count;
@ -79,5 +81,7 @@ typedef struct emu8k_t
int16_t out_l, out_r;
} emu8k_t;
void emu8k_init(emu8k_t *emu8k);
void emu8k_init(emu8k_t *emu8k, int onboard_ram);
void emu8k_close(emu8k_t *emu8k);
void emu8k_poll_getsamp(emu8k_t *dsp, int16_t *l, int16_t *r);

View file

@ -412,6 +412,7 @@ int sb_awe32_available()
void *sb_awe32_init()
{
sb_t *sb = malloc(sizeof(sb_t));
int onboard_ram = device_get_config_int("onboard_ram");
memset(sb, 0, sizeof(sb_t));
opl3_init(&sb->opl);
@ -424,7 +425,7 @@ void *sb_awe32_init()
io_sethandler(0x0224, 0x0002, sb_16_mixer_read, NULL, NULL, sb_16_mixer_write, NULL, NULL, sb);
sound_add_handler(sb_emu8k_poll, sb_get_buffer, sb);
mpu401_uart_init(&sb->mpu, 0x330);
emu8k_init(&sb->emu8k);
emu8k_init(&sb->emu8k, onboard_ram);
sb->mixer.regs[0x30] = 31 << 3;
sb->mixer.regs[0x31] = 31 << 3;
@ -450,6 +451,15 @@ void sb_close(void *p)
free(sb);
}
void sb_awe32_close(void *p)
{
sb_t *sb = (sb_t *)p;
emu8k_close(&sb->emu8k);
free(sb);
}
void sb_speed_changed(void *p)
{
sb_t *sb = (sb_t *)p;
@ -629,6 +639,51 @@ static device_config_t sb_16_config[] =
}
};
static device_config_t sb_awe32_config[] =
{
{
.name = "midi",
.description = "MIDI out device",
.type = CONFIG_MIDI,
.default_int = 0
},
{
.name = "onboard_ram",
.description = "Onboard RAM",
.type = CONFIG_SELECTION,
.selection =
{
{
.description = "None",
.value = 0
},
{
.description = "512 KB",
.value = 512
},
{
.description = "2 MB",
.value = 2048
},
{
.description = "8 MB",
.value = 8192
},
{
.description = "28 MB",
.value = 28*1024
},
{
.description = ""
}
},
.default_int = 512
},
{
.type = -1
}
};
device_t sb_1_device =
{
"Sound Blaster v1.0",
@ -711,5 +766,5 @@ device_t sb_awe32_device =
sb_speed_changed,
NULL,
sb_add_status_info,
sb_16_config
sb_awe32_config
};