From 6ab214a2b07444b27ae039b0b29a6919579b7f58 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 2 Feb 2017 02:55:08 +0100 Subject: [PATCH] Commented out the NEC PowerMate V, because it doesn't work; Applied all mainline PCem commits; CD-ROM sound thread is now disabled if all CD-ROM drives are either disabled or have audio disabled; Fixed the displayed incorrect zero cylinders, head, and sectors per cylinder when loading an already existing HDI image; Fixed the CD-ROM audio menu item not checking/unchecking correctly. --- src/ibm.h | 2 +- src/ide.c | 8 +++++ src/io.c | 7 ++++ src/model.c | 14 +++++--- src/pc.c | 2 ++ src/sound.c | 83 +++++++++++++++++++++++++++++++++++++++++++---- src/soundopenal.c | 6 +++- src/win-hdconf.c | 2 +- src/win.c | 3 +- 9 files changed, 113 insertions(+), 14 deletions(-) diff --git a/src/ibm.h b/src/ibm.h index 726192285..558f7a92e 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -496,7 +496,7 @@ float VGACONST1,VGACONST2; float RTCCONST; int gated,speakval,speakon; -#define SOUNDBUFLEN (48000/10) +#define SOUNDBUFLEN (48000/40) /*Sound Blaster*/ diff --git a/src/ide.c b/src/ide.c index 83ff385e4..eb98e78d2 100644 --- a/src/ide.c +++ b/src/ide.c @@ -1283,6 +1283,14 @@ ide_bad_command: ide->atastat = ide_other->atastat = BUSY_STAT; // ide_log("IDE Reset %i\n", ide_board); } + if (val & 4) + { + /*Drive held in reset*/ + timer_process(); + idecallback[ide_board] = 0; + timer_update_outstanding(); + ide->atastat = ide_other->atastat = BUSY_STAT; + } ide->fdisk = ide_other->fdisk = val; ide_irq_update(ide); return; diff --git a/src/io.c b/src/io.c index 6361e6afa..9431268fd 100644 --- a/src/io.c +++ b/src/io.c @@ -130,6 +130,9 @@ uint8_t inb(uint16_t port) /* if (!port_inb[port][0] && !port_inb[port][1]) pclog("Bad INB %04X %04X:%04X\n", port, CS, cpu_state.pc); */ + /* if (port_inb[port][0] || port_inb[port][1]) + pclog("Good INB %04X %04X:%04X\n", port, CS, cpu_state.pc); */ + return temp; } @@ -144,6 +147,10 @@ void outb(uint16_t port, uint8_t val) /* if (!port_outb[port][0] && !port_outb[port][1]) pclog("Bad OUTB %04X %02X %04X:%08X\n", port, val, CS, cpu_state.pc); */ + + /* if (port_outb[port][0] || port_outb[port][1]) + pclog("Good OUTB %04X %02X %04X:%08X\n", port, val, CS, cpu_state.pc); */ + return; } diff --git a/src/model.c b/src/model.c index c50523b3d..174fe63e0 100644 --- a/src/model.c +++ b/src/model.c @@ -101,7 +101,9 @@ void at_r418_init(); void at_586mc1_init(); void at_plato_init(); void at_mb500n_init(); -// void at_powermate_v_init(); +#if 0 +void at_powermate_v_init(); +#endif void at_p54tp4xe_init(); void at_acerm3a_init(); void at_acerv35n_init(); @@ -166,7 +168,9 @@ MODEL models[] = {"Intel Premiere/PCI II",ROM_PLATO, { "Intel", cpus_PentiumS5,"IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL}, 0, MODEL_AT|MODEL_PS2, 1, 128, 1, at_plato_init, NULL}, {"Intel Advanced/EV", ROM_ENDEAVOR, { "Intel", cpus_PentiumS5,"IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL}, 0, MODEL_AT|MODEL_PS2, 1, 128, 1, at_endeavor_init, NULL}, {"PC Partner MB500N", ROM_MB500N, { "Intel", cpus_PentiumS5,"IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL}, 0, MODEL_AT|MODEL_PS2, 1, 128, 1, at_mb500n_init, NULL}, -/* {"NEC PowerMate V", ROM_POWERMATE_V, { "Intel", cpus_PentiumS5,"IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL}, 0, MODEL_AT|MODEL_PS2, 1, 128, 1, at_powermate_v_init, NULL}, */ +#if 0 + {"NEC PowerMate V", ROM_POWERMATE_V, { "Intel", cpus_PentiumS5,"IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL}, 0, MODEL_AT|MODEL_PS2, 1, 128, 1, at_powermate_v_init, NULL}, +#endif {"Intel Advanced/ATX", ROM_THOR, { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT|MODEL_PS2, 1, 256, 1, at_endeavor_init, NULL}, {"MR Intel Advanced/ATX", ROM_MRTHOR, { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, MODEL_AT|MODEL_PS2, 1, 256, 1, at_endeavor_init, NULL}, {"ASUS P/I-P54TP4XE", ROM_P54TP4XE, { "Intel", cpus_PentiumS5, "IDT", cpus_WinChip, "AMD", cpus_K5, "", NULL}, 0, MODEL_AT|MODEL_PS2, 1, 512, 1, at_p54tp4xe_init, NULL}, @@ -527,7 +531,8 @@ void at_mb500n_init() device_add(&intel_flash_bxt_device); } -/* void at_powermate_v_init() +#if 0 +void at_powermate_v_init() { at_init(); powermate_memregs_init(); @@ -537,7 +542,8 @@ void at_mb500n_init() fdc37c665_init(); acerm3a_io_init(); device_add(&intel_flash_bxt_device); -} */ +} +#endif void at_p54tp4xe_init() { diff --git a/src/pc.c b/src/pc.c index 68f3a2ac0..408133744 100644 --- a/src/pc.c +++ b/src/pc.c @@ -501,6 +501,8 @@ void resetpchard() } } } + + sound_cd_thread_reset(); } char romsets[17][40]={"IBM PC","IBM XT","Generic Turbo XT","Euro PC","Tandy 1000","Amstrad PC1512","Sinclair PC200","Amstrad PC1640","IBM AT","AMI 286 clone","Dell System 200","Misc 286","IBM AT 386","Misc 386","386 clone","486 clone","486 clone 2"}; diff --git a/src/sound.c b/src/sound.c index e290a0fdc..87adb2580 100644 --- a/src/sound.c +++ b/src/sound.c @@ -98,6 +98,7 @@ static float cd_out_buffer[CD_BUFLEN * 2]; static thread_t *sound_cd_thread_h; static event_t *sound_cd_event; static unsigned int cd_vol_l, cd_vol_r; +static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN; void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r) { @@ -114,18 +115,34 @@ static void sound_cd_thread(void *param) int c, has_audio; thread_wait_event(sound_cd_event, -1); + if (!soundon) + { + return; + } for (c = 0; c < CD_BUFLEN*2; c += 2) { cd_out_buffer[c] = 0.0; cd_out_buffer[c+1] = 0.0; } + has_audio = 0; + for (i = 0; i < CDROM_NUM; i++) + { + if (cdrom_drives[i].enabled && cdrom_drives[i].sound_on) + { + has_audio++; + } + } + if (!has_audio) + { + return; + } for (i = 0; i < CDROM_NUM; i++) { has_audio = 0; if (cdrom_drives[i].handler->audio_callback) { cdrom_drives[i].handler->audio_callback(i, cd_buffer[i], CD_BUFLEN*2); - has_audio = cdrom_drives[i].sound_on; + has_audio = (cdrom_drives[i].enabled && cdrom_drives[i].sound_on); } if (soundon && has_audio) { @@ -189,16 +206,34 @@ static void sound_cd_thread(void *param) static int32_t *outbuffer; static float *outbuffer_ex; +static int cd_thread_enable = 0; + void sound_init() { + int i = 0; + int available_cdrom_drives = 0; + initalmain(0,NULL); inital(); outbuffer = malloc(SOUNDBUFLEN * 2 * sizeof(int32_t)); outbuffer_ex = malloc(SOUNDBUFLEN * 2 * sizeof(float)); - - sound_cd_event = thread_create_event(); - sound_cd_thread_h = thread_create(sound_cd_thread, NULL); + + for (i = 0; i < CDROM_NUM; i++) + { + if (cdrom_drives[i].enabled && cdrom_drives[i].sound_on) + { + available_cdrom_drives++; + } + } + + if (available_cdrom_drives) + { + sound_cd_event = thread_create_event(); + sound_cd_thread_h = thread_create(sound_cd_thread, NULL); + } + + cd_thread_enable = available_cdrom_drives ? 1 : 0; } void sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p) @@ -244,7 +279,15 @@ void sound_poll(void *priv) if (soundon) givealbuffer(outbuffer_ex); - thread_set_event(sound_cd_event); + if (cd_thread_enable) + { + cd_buf_update--; + if (!cd_buf_update) + { + cd_buf_update = (48000 / SOUNDBUFLEN) / (CD_FREQ / CD_BUFLEN); + thread_set_event(sound_cd_event); + } + } sound_pos_global = 0; } @@ -258,6 +301,7 @@ void sound_speed_changed() void sound_reset() { int i = 0; + int available_cdrom_drives = 0; timer_add(sound_poll, &sound_poll_time, TIMER_ALWAYS_ENABLED, NULL); @@ -267,10 +311,37 @@ void sound_reset() for (i = 0; i < CDROM_NUM; i++) { - pclog("Resetting audio for CD-ROM %i...\n", i); if (cdrom_drives[i].handler->audio_stop) { cdrom_drives[i].handler->audio_stop(i); } } } + +void sound_cd_thread_reset() +{ + int i = 0; + int available_cdrom_drives = 0; + + for (i = 0; i < CDROM_NUM; i++) + { + if (cdrom_drives[i].enabled && cdrom_drives[i].sound_on) + { + available_cdrom_drives++; + } + } + + if (available_cdrom_drives && !cd_thread_enable) + { + thread_destroy_event(sound_cd_event); + thread_kill(sound_cd_thread_h); + sound_cd_thread_h = NULL; + } + else if (!available_cdrom_drives && cd_thread_enable) + { + sound_cd_event = thread_create_event(); + sound_cd_thread_h = thread_create(sound_cd_thread, NULL); + } + + cd_thread_enable = available_cdrom_drives ? 1 : 0; +} diff --git a/src/soundopenal.c b/src/soundopenal.c index 29173b75b..aeb9d728d 100644 --- a/src/soundopenal.c +++ b/src/soundopenal.c @@ -87,6 +87,8 @@ void inital() int c; float buf[BUFLEN*2]; + float cd_buf[CD_BUFLEN*2]; + // printf("1\n"); check(); @@ -114,13 +116,15 @@ void inital() alSourcei (source[1], AL_SOURCE_RELATIVE, AL_TRUE ); check(); - memset(buf,0,BUFLEN*4); + memset(buf,0,BUFLEN*2*sizeof(float)); + memset(cd_buf,0,BUFLEN*2*sizeof(float)); // printf("5\n"); for (c = 0; c < 4; c++) { alBufferData(buffers[c], AL_FORMAT_STEREO_FLOAT32, buf, BUFLEN*2*sizeof(float), FREQ); alBufferData(buffers_cd[c], AL_FORMAT_STEREO_FLOAT32, buf, CD_BUFLEN*2*sizeof(float), CD_FREQ); + alBufferData(buffers_cd[c], AL_FORMAT_STEREO_FLOAT32, cd_buf, CD_BUFLEN*2*sizeof(float), CD_FREQ); } alSourceQueueBuffers(source[0], 4, buffers); diff --git a/src/win-hdconf.c b/src/win-hdconf.c index 8ab21591e..d42bd8e80 100644 --- a/src/win-hdconf.c +++ b/src/win-hdconf.c @@ -440,7 +440,7 @@ static void hdconf_file(HWND hdlg, int drive_num) if (image_is_hdi(openfilestring)) { - fseeko64(f, 0x10, SEEK_END); + fseeko64(f, 0x10, SEEK_SET); fread(§or_size, 1, 4, f); if (sector_size != 512) { diff --git a/src/win.c b/src/win.c index 79b46de76..84c8781bc 100644 --- a/src/win.c +++ b/src/win.c @@ -1655,8 +1655,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM cdrom_id = convert_cdrom_id(LOWORD(wParam) - IDM_CDROM_1_SOUND_ON); Sleep(100); cdrom_drives[cdrom_id].sound_on ^= 1; - CheckMenuItem(hmenu, IDM_CDROM_1_SOUND_ON + (cdrom_id * 1000), cdrom_drives[cdrom_id].enabled ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(hmenu, IDM_CDROM_1_SOUND_ON + (cdrom_id * 1000), cdrom_drives[cdrom_id].sound_on ? MF_CHECKED : MF_UNCHECKED); saveconfig(); + sound_cd_thread_reset(); break; case IDM_CDROM_1_SCSI: