X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fsound%2Fsound.c;h=ac37c614c769b8adec3dac8639067a86d0dee8de;hb=f02439758ee681130093e689d4d8a4b377ca462f;hp=c0b32523eefffed3969a79d5ce03a3a4396e9c2a;hpb=0af33fe0ef24a3e3b65217ad0d7aa2db03d16fc1;p=picodrive.git diff --git a/Pico/sound/sound.c b/Pico/sound/sound.c index c0b3252..ac37c61 100644 --- a/Pico/sound/sound.c +++ b/Pico/sound/sound.c @@ -8,14 +8,9 @@ #include -#include "sound.h" #include "ym2612.h" #include "sn76496.h" -#ifndef __GNUC__ -#pragma warning (disable:4244) -#endif - #if defined(_USE_MZ80) #include "../../cpu/mz80/mz80.h" #elif defined(_USE_DRZ80) @@ -29,11 +24,8 @@ // master int buffer to mix to static int PsndBuffer[2*44100/50]; -//int z80CycleAim = 0; - // dac -short *dac_out; -unsigned short dac_info[312]; // pppppppp ppppllll, p - pos in buff, l - length to write for this sample +static unsigned short dac_info[312]; // pppppppp ppppllll, p - pos in buff, l - length to write for this sample // for Pico int PsndRate=0; @@ -51,7 +43,7 @@ void YM2612TimerHandler(int c,int cnt); extern int *sn76496_regs; -static void dac_recalculate() +static void dac_recalculate(void) { int i, dac_cnt, pos, len, lines = Pico.m.pal ? 312 : 262, mid = Pico.m.pal ? 68 : 93; @@ -107,7 +99,7 @@ static void dac_recalculate() } -void sound_reset() +PICO_INTERNAL void sound_reset(void) { void *ym2612_regs; @@ -125,7 +117,7 @@ void sound_reset() // to be called after changing sound rate or chips void sound_rerate(int preserve_state) { - unsigned int state[28]; + void *state = NULL; int target_fps = Pico.m.pal ? 50 : 60; // not all rates are supported in MCD mode due to mp3 decoder limitations @@ -135,12 +127,16 @@ void sound_rerate(int preserve_state) } if (preserve_state) { + state = malloc(0x200); + if (state == NULL) return; + memcpy(state, YM2612GetRegs(), 0x200); if ((PicoMCD & 1) && Pico_mcd->m.audio_track) Pico_mcd->m.audio_offset = mp3_get_offset(); } YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PsndRate); if (preserve_state) { // feed it back it's own registers, just like after loading state + memcpy(YM2612GetRegs(), state, 0x200); YM2612PicoStateLoad(); if ((PicoMCD & 1) && Pico_mcd->m.audio_track) mp3_start_play(Pico_mcd->TOC.Tracks[Pico_mcd->m.audio_track].F, Pico_mcd->m.audio_offset); @@ -150,6 +146,9 @@ void sound_rerate(int preserve_state) SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PsndRate); if (preserve_state) memcpy(sn76496_regs, state, 28*4); // restore old state + if (state) + free(state); + // calculate PsndLen PsndLen=PsndRate / target_fps; PsndLen_exc_add=((PsndRate - PsndLen*target_fps)<<16) / target_fps; @@ -169,7 +168,7 @@ void sound_rerate(int preserve_state) // This is called once per raster (aka line), but not necessarily for every line -void sound_timers_and_dac(int raster) +PICO_INTERNAL void sound_timers_and_dac(int raster) { int pos, len; int do_dac = PsndOut && (PicoOpt&1) && *ym2612_dacen; @@ -217,7 +216,7 @@ void sound_timers_and_dac(int raster) } -void sound_clear(void) +PICO_INTERNAL void sound_clear(void) { int len = PsndLen; if (PsndLen_exc_add) len++; @@ -226,7 +225,7 @@ void sound_clear(void) } -int sound_render(int offset, int length) +PICO_INTERNAL int sound_render(int offset, int length) { int buf32_updated = 0; int *buf32 = PsndBuffer+offset; @@ -318,11 +317,13 @@ static unsigned int DrZ80_rebaseSP(unsigned short a) static unsigned char DrZ80_in(unsigned short p) { + elprintf(EL_ANOMALY, "Z80 port %04x read", p); return 0xff; } static void DrZ80_out(unsigned short p,unsigned char d) { + elprintf(EL_ANOMALY, "Z80 port %04x write %02x", p, d); } static void DrZ80_irq_callback() @@ -333,7 +334,7 @@ static void DrZ80_irq_callback() #endif // z80 functionality wrappers -void z80_init() +PICO_INTERNAL void z80_init(void) { #if defined(_USE_MZ80) struct mz80context z80; @@ -367,7 +368,7 @@ void z80_init() #endif } -void z80_reset() +PICO_INTERNAL void z80_reset(void) { #if defined(_USE_MZ80) mz80reset(); @@ -384,14 +385,14 @@ void z80_reset() Pico.m.z80_fakeval = 0; // for faking when Z80 is disabled } -void z80_resetCycles() +PICO_INTERNAL void z80_resetCycles(void) { #if defined(_USE_MZ80) mz80GetElapsedTicks(1); #endif } -void z80_int() +PICO_INTERNAL void z80_int(void) { #if defined(_USE_MZ80) mz80int(0); @@ -402,7 +403,7 @@ void z80_int() } // returns number of cycles actually executed -int z80_run(int cycles) +PICO_INTERNAL int z80_run(int cycles) { #if defined(_USE_MZ80) int ticks_pre = mz80GetElapsedTicks(0); @@ -415,7 +416,7 @@ int z80_run(int cycles) #endif } -void z80_pack(unsigned char *data) +PICO_INTERNAL void z80_pack(unsigned char *data) { #if defined(_USE_MZ80) struct mz80context mz80; @@ -430,7 +431,7 @@ void z80_pack(unsigned char *data) #endif } -void z80_unpack(unsigned char *data) +PICO_INTERNAL void z80_unpack(unsigned char *data) { #if defined(_USE_MZ80) if(*(int *)data == 0x00005A6D) { // "mZ" save? @@ -456,7 +457,7 @@ void z80_unpack(unsigned char *data) #endif } -void z80_exit() +PICO_INTERNAL void z80_exit(void) { #if defined(_USE_MZ80) mz80shutdown(); @@ -464,7 +465,7 @@ void z80_exit() } #if defined(__DEBUG_PRINT) || defined(__GP2X__) -void z80_debug(char *dstr) +PICO_INTERNAL void z80_debug(char *dstr) { #if defined(_USE_DRZ80) sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", drZ80.Z80PC-drZ80.Z80PC_BASE, drZ80.Z80SP-drZ80.Z80SP_BASE);