From 4f265db77684ec33f9533e7c76734498df03bba4 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 4 Feb 2007 17:15:31 +0000 Subject: [PATCH] PCM sound, refactored code940 git-svn-id: file:///home/notaz/opt/svn/PicoDrive@27 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Pico.c | 6 +- Pico/Pico.h | 3 +- Pico/PicoInt.h | 27 ++- Pico/cd/Area.c | 17 +- Pico/cd/Memory.c | 106 ++++++++- Pico/cd/Pico.c | 51 +++-- Pico/sound/mix.c | 57 +++++ Pico/sound/mix.h | 10 + Pico/sound/mix.s | 350 ++++++++++++++++++++++++++++++ Pico/sound/sn76496.c | 11 +- Pico/sound/sound.c | 119 +++++++--- Pico/sound/sound.h | 5 +- Pico/sound/ym2612.c | 58 ++--- Pico/sound/ym2612.h | 8 +- platform/gp2x/940ctl_ym2612.c | 190 ++++++++-------- platform/gp2x/940ctl_ym2612.h | 2 +- platform/gp2x/Makefile | 8 +- platform/gp2x/asmutils.h | 2 + platform/gp2x/asmutils.s | 11 +- platform/gp2x/code940/940.c | 17 +- platform/gp2x/code940/940init.s | 34 ++- platform/gp2x/code940/940shared.h | 5 +- platform/gp2x/code940/Makefile | 20 +- platform/gp2x/emu.c | 27 +-- platform/gp2x/emu.h | 4 +- platform/gp2x/menu.c | 10 +- platform/linux/940ctl_ym2612.c | 60 +---- platform/linux/Makefile | 4 +- 28 files changed, 912 insertions(+), 310 deletions(-) create mode 100644 Pico/sound/mix.c create mode 100644 Pico/sound/mix.h create mode 100644 Pico/sound/mix.s diff --git a/Pico/Pico.c b/Pico/Pico.c index 1f201f4..004a247 100644 --- a/Pico/Pico.c +++ b/Pico/Pico.c @@ -49,7 +49,8 @@ int PicoInit(void) // to be called once on emu exit void PicoExit(void) { - PicoExitMCD(); + if (PicoMCD&1) + PicoExitMCD(); z80_exit(); // notaz: sram @@ -322,7 +323,8 @@ static __inline void getSamples(int y) if (emustatus&1) emustatus|=2; else emustatus&=~2; if (PicoWriteSound) PicoWriteSound(); // clear sound buffer - memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1)); + sound_clear(); + //memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1)); } else if(emustatus & 3) { emustatus|= 2; diff --git a/Pico/Pico.h b/Pico/Pico.h index 2d0c283..ef2db10 100644 --- a/Pico/Pico.h +++ b/Pico/Pico.h @@ -23,13 +23,14 @@ extern "C" { int mp3_get_bitrate(FILE *f, int size); void mp3_start_play(FILE *f, int pos); int mp3_get_offset(void); // 0-1023 +void mp3_update(int *buffer, int length, int stereo); // Pico.c // PicoOpt bits LSb->MSb: // enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound, // alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites, -// draw_no_32col_border, external_ym2612 +// draw_no_32col_border, external_ym2612, enable_pcm, enable cdda extern int PicoOpt; extern int PicoVer; extern int PicoSkipFrame; // skip rendering frame, but still do sound (if enabled) and emulation stuff diff --git a/Pico/PicoInt.h b/Pico/PicoInt.h index d96a071..c7b72a2 100644 --- a/Pico/PicoInt.h +++ b/Pico/PicoInt.h @@ -164,6 +164,22 @@ struct PicoSRAM #include "cd/LC89510.h" #include "cd/gfx_cd.h" +struct mcd_pcm +{ + unsigned char control; // reg7 + unsigned char enabled; // reg8 + unsigned char cur_ch; + unsigned char bank; + int pad1; + + struct pcm_chan + { + unsigned char regs[8]; + unsigned int addr; // played sample address + int pad; + } ch[8]; +}; + struct mcd_misc { unsigned short hint_vector; @@ -174,7 +190,9 @@ struct mcd_misc unsigned short audio_offset; // for savestates: play pointer offset (0-1023) unsigned char audio_track; // playing audio track # (zero based) char pad1; - int pad[12]; + int timer_int3; + unsigned int timer_stopwatch; + int pad[10]; }; typedef struct @@ -185,8 +203,13 @@ typedef struct unsigned char prg_ram_b[4][0x20000]; }; unsigned char word_ram[0x40000]; // 256K + union { + unsigned char pcm_ram[0x10000]; // 64K + unsigned char pcm_ram_b[0x10][0x1000]; + }; unsigned char bram[0x2000]; // 8K - unsigned char s68k_regs[0x200]; + unsigned char s68k_regs[0x200]; // GA, not CPU regs + struct mcd_pcm pcm; _scd_toc TOC; // not to be saved CDD cdd; CDC cdc; diff --git a/Pico/cd/Area.c b/Pico/cd/Area.c index 2502a7a..a4c2b36 100644 --- a/Pico/cd/Area.c +++ b/Pico/cd/Area.c @@ -1,6 +1,6 @@ // This is part of Pico Library -// (c) Copyright 2006 notaz, All rights reserved. +// (c) Copyright 2007 notaz, All rights reserved. // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. @@ -31,12 +31,14 @@ typedef enum { CHUNK_S68K, CHUNK_PRG_RAM, CHUNK_WORD_RAM, - CHUNK_BRAM, // 15 + CHUNK_PCM_RAM, // 15 + CHUNK_BRAM, CHUNK_GA_REGS, + CHUNK_PCM, CHUNK_CDC, - CHUNK_CDD, + CHUNK_CDD, // 20 CHUNK_SCD, - CHUNK_RC, // 20 + CHUNK_RC, CHUNK_MISC_CD, } chunk_name_e; @@ -96,8 +98,10 @@ int PicoCdSaveState(void *file) CHECKED_WRITE_BUFF(CHUNK_S68K, buff); CHECKED_WRITE_BUFF(CHUNK_PRG_RAM, Pico_mcd->prg_ram); CHECKED_WRITE_BUFF(CHUNK_WORD_RAM, Pico_mcd->word_ram); // in 2M format + CHECKED_WRITE_BUFF(CHUNK_PCM_RAM, Pico_mcd->pcm_ram); CHECKED_WRITE_BUFF(CHUNK_BRAM, Pico_mcd->bram); - CHECKED_WRITE_BUFF(CHUNK_GA_REGS, Pico_mcd->s68k_regs); + CHECKED_WRITE_BUFF(CHUNK_GA_REGS, Pico_mcd->s68k_regs); // GA regs, not CPU regs + CHECKED_WRITE_BUFF(CHUNK_PCM, Pico_mcd->pcm); CHECKED_WRITE_BUFF(CHUNK_CDD, Pico_mcd->cdd); CHECKED_WRITE_BUFF(CHUNK_CDC, Pico_mcd->cdc); CHECKED_WRITE_BUFF(CHUNK_SCD, Pico_mcd->scd); @@ -147,6 +151,7 @@ int PicoCdLoadState(void *file) CHECKED_READ(1, buff); CHECKED_READ(4, &len); if (len < 0 || len > 1024*512) R_ERROR_RETURN("bad length"); + if (buff[0] > CHUNK_FM && !(PicoMCD & 1)) R_ERROR_RETURN("cd chunk in non CD state?"); switch (buff[0]) { @@ -181,8 +186,10 @@ int PicoCdLoadState(void *file) case CHUNK_PRG_RAM: CHECKED_READ_BUFF(Pico_mcd->prg_ram); break; case CHUNK_WORD_RAM: CHECKED_READ_BUFF(Pico_mcd->word_ram); break; + case CHUNK_PCM_RAM: CHECKED_READ_BUFF(Pico_mcd->pcm_ram); break; case CHUNK_BRAM: CHECKED_READ_BUFF(Pico_mcd->bram); break; case CHUNK_GA_REGS: CHECKED_READ_BUFF(Pico_mcd->s68k_regs); break; + case CHUNK_PCM: CHECKED_READ_BUFF(Pico_mcd->pcm); break; case CHUNK_CDD: CHECKED_READ_BUFF(Pico_mcd->cdd); break; case CHUNK_CDC: CHECKED_READ_BUFF(Pico_mcd->cdc); break; case CHUNK_SCD: CHECKED_READ_BUFF(Pico_mcd->scd); break; diff --git a/Pico/cd/Memory.c b/Pico/cd/Memory.c index 05299e6..ff787b0 100644 --- a/Pico/cd/Memory.c +++ b/Pico/cd/Memory.c @@ -17,6 +17,7 @@ #include "../sound/sn76496.h" #include "gfx_cd.h" +#include "pcm.h" typedef unsigned char u8; typedef unsigned short u16; @@ -161,7 +162,8 @@ static u32 s68k_reg_read16(u32 a) goto end; case 0xC: dprintf("s68k stopwatch timer read"); - break; + d = Pico_mcd->m.timer_stopwatch >> 16; + goto end; case 0x30: dprintf("s68k int3 timer read"); break; @@ -212,10 +214,13 @@ static void s68k_reg_write8(u32 a, u32 d) dprintf("s68k set CDC dma addr"); break; case 0xc: + case 0xd: dprintf("s68k set stopwatch timer"); - break; + Pico_mcd->m.timer_stopwatch = 0; + return; case 0x31: - dprintf("s68k set int3 timer"); + dprintf("s68k set int3 timer: %02x", d); + Pico_mcd->m.timer_int3 = d << 16; break; case 0x33: // IRQ mask dprintf("s68k irq mask: %02x", d); @@ -830,6 +835,21 @@ u8 PicoReadS68k8(u32 a) goto end; } + // PCM + if ((a&0xff8000)==0xff0000) { + dprintf("s68k_pcm r8: [%06x] @%06x", a, SekPc); + a &= 0x7fff; + if (a >= 0x2000) + d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff]; + else if (a >= 0x20) { + a &= 0x1e; + d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT; + if (a & 2) d >>= 8; + } + dprintf("ret = %02x", (u8)d); + goto end; + } + // bram if ((a&0xff0000)==0xfe0000) { d = Pico_mcd->bram[(a>>1)&0x1fff]; @@ -849,7 +869,7 @@ u8 PicoReadS68k8(u32 a) u16 PicoReadS68k16(u32 a) { - u16 d=0; + u32 d=0; a&=0xfffffe; @@ -898,12 +918,27 @@ u16 PicoReadS68k16(u32 a) if ((a&0xff0000)==0xfe0000) { dprintf("s68k_bram r16: [%06x] @%06x", a, SekPc); a = (a>>1)&0x1fff; - d = Pico_mcd->bram[a++]; // Gens does little endian here, an so do we.. + d = Pico_mcd->bram[a++]; // Gens does little endian here, and so do we.. d|= Pico_mcd->bram[a++] << 8; dprintf("ret = %04x", d); goto end; } + // PCM + if ((a&0xff8000)==0xff0000) { + dprintf("s68k_pcm r16: [%06x] @%06x", a, SekPc); + a &= 0x7fff; + if (a >= 0x2000) + d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff]; + else if (a >= 0x20) { + a &= 0x1e; + d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT; + if (a & 2) d >>= 8; + } + dprintf("ret = %04x", d); + goto end; + } + dprintf("s68k r16: %06x, %04x @%06x", a&0xffffff, d, SekPcS68k); end: @@ -964,6 +999,29 @@ u32 PicoReadS68k32(u32 a) goto end; } + // PCM + if ((a&0xff8000)==0xff0000) { + dprintf("s68k_pcm r32: [%06x] @%06x", a, SekPc); + a &= 0x7fff; + if (a >= 0x2000) { + a >>= 1; + d = Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][a&0xfff] << 16; + d |= Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a+1)&0xfff]; + } else if (a >= 0x20) { + a &= 0x1e; + if (a & 2) { + a >>= 2; + d = (Pico_mcd->pcm.ch[a].addr >> (PCM_STEP_SHIFT-8)) & 0xff0000; + d |= (Pico_mcd->pcm.ch[(a+1)&7].addr >> PCM_STEP_SHIFT) & 0xff; + } else { + d = Pico_mcd->pcm.ch[a>>2].addr >> PCM_STEP_SHIFT; + d = ((d<<16)&0xff0000) | ((d>>8)&0xff); // PCM chip is LE + } + } + dprintf("ret = %08x", d); + goto end; + } + // bram if ((a&0xff0000)==0xfe0000) { dprintf("s68k_bram r32: [%06x] @%06x", a, SekPc); @@ -1004,9 +1062,6 @@ void PicoWriteS68k8(u32 a,u8 d) return; } - if (a != 0xff0011 && (a&0xff8000) == 0xff0000) // PCM hack - return; - // regs if ((a&0xfffe00) == 0xff8000) { a &= 0x1ff; @@ -1040,6 +1095,16 @@ void PicoWriteS68k8(u32 a,u8 d) return; } + // PCM + if ((a&0xff8000)==0xff0000) { + a &= 0x7fff; + if (a >= 0x2000) + Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff] = d; + else if (a < 0x12) + pcm_write(a>>1, d); + return; + } + // bram if ((a&0xff0000)==0xfe0000) { Pico_mcd->bram[(a>>1)&0x1fff] = d; @@ -1101,6 +1166,16 @@ void PicoWriteS68k16(u32 a,u16 d) return; } + // PCM + if ((a&0xff8000)==0xff0000) { + a &= 0x7fff; + if (a >= 0x2000) + Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a>>1)&0xfff] = d; + else if (a < 0x12) + pcm_write(a>>1, d & 0xff); + return; + } + // bram if ((a&0xff0000)==0xfe0000) { dprintf("s68k_bram w16: [%06x] %04x @%06x", a, d, SekPc); @@ -1171,6 +1246,21 @@ void PicoWriteS68k32(u32 a,u32 d) return; } + // PCM + if ((a&0xff8000)==0xff0000) { + a &= 0x7fff; + if (a >= 0x2000) { + a >>= 1; + Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][a&0xfff] = (d >> 16); + Pico_mcd->pcm_ram_b[Pico_mcd->pcm.bank][(a+1)&0xfff] = d; + } else if (a < 0x12) { + a >>= 1; + pcm_write(a, (d>>16) & 0xff); + pcm_write(a+1, d & 0xff); + } + return; + } + // bram if ((a&0xff0000)==0xfe0000) { dprintf("s68k_bram w32: [%06x] %08x @%06x", a, d, SekPc); diff --git a/Pico/cd/Pico.c b/Pico/cd/Pico.c index 8b4c9e5..d643cb7 100644 --- a/Pico/cd/Pico.c +++ b/Pico/cd/Pico.c @@ -32,11 +32,13 @@ int PicoResetMCD(int hard) { memset(Pico_mcd->prg_ram, 0, sizeof(Pico_mcd->prg_ram)); memset(Pico_mcd->word_ram, 0, sizeof(Pico_mcd->word_ram)); + memset(Pico_mcd->pcm_ram, 0, sizeof(Pico_mcd->pcm_ram)); if (hard) { memset(Pico_mcd->bram, 0, sizeof(Pico_mcd->bram)); memcpy(Pico_mcd->bram + sizeof(Pico_mcd->bram) - 8*0x10, formatted_bram, 8*0x10); } memset(Pico_mcd->s68k_regs, 0, sizeof(Pico_mcd->s68k_regs)); + memset(&Pico_mcd->pcm, 0, sizeof(Pico_mcd->pcm)); *(unsigned int *)(Pico_mcd->bios + 0x70) = 0xffffffff; // reset hint vector (simplest way to implement reg6) Pico_mcd->m.state_flags |= 2; // s68k reset pending @@ -97,6 +99,38 @@ static __inline void check_cd_dma(void) Update_CDC_TRansfer(ddx); // now go and do the actual transfer } +static __inline void update_chips(void) +{ + int counter_timer, int3_set; + int counter75hz_lim = Pico.m.pal ? 2080 : 2096; + + // 75Hz CDC update + if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) { + Pico_mcd->m.counter75hz -= counter75hz_lim; + Check_CD_Command(); + } + + // update timers + counter_timer = Pico.m.pal ? 0x21630 : 0x2121c; // 136752 : 135708; + Pico_mcd->m.timer_stopwatch += counter_timer; + if ((int3_set = Pico_mcd->s68k_regs[0x31])) { + Pico_mcd->m.timer_int3 -= counter_timer; + if (Pico_mcd->m.timer_int3 < 0) { + if (Pico_mcd->s68k_regs[0x33] & (1<<3)) { + dprintf("s68k: timer irq 3"); + SekInterruptS68k(3); + Pico_mcd->m.timer_int3 += int3_set << 16; + } + // is this really what happens if irq3 is masked out? + Pico_mcd->m.timer_int3 &= 0xffffff; + } + } + + // update gfx chip + if (Pico_mcd->rot_comp.Reg_58 & 0x8000) + gfx_cd_update(); +} + // to be called on 224 or line_sample scanlines only static __inline void getSamples(int y) { @@ -108,7 +142,8 @@ static __inline void getSamples(int y) if (emustatus&1) emustatus|=2; else emustatus&=~2; if (PicoWriteSound) PicoWriteSound(); // clear sound buffer - memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1)); + sound_clear(); + //memset(PsndOut, 0, (PicoOpt & 8) ? (PsndLen<<2) : (PsndLen<<1)); } else if(emustatus & 3) { emustatus|= 2; @@ -118,12 +153,10 @@ static __inline void getSamples(int y) } - -// Accurate but slower frame which does hints static int PicoFrameHintsMCD(void) { struct PicoVideo *pv=&Pico.video; - int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample,counter75hz_lim; + int total_z80=0,lines,y,lines_vis = 224,z80CycleAim = 0,line_sample; const int cycles_68k=488,cycles_z80=228,cycles_s68k=795; // both PAL and NTSC compile to same values int skip=PicoSkipFrame || (PicoOpt&0x10); int hint; // Hint counter @@ -133,13 +166,11 @@ static int PicoFrameHintsMCD(void) //cycles_z80 = (int) ((double) OSC_PAL / 15 / 50 / 312 + 0.4); // 228 lines = 312; // Steve Snake says there are 313 lines, but this seems to also work well line_sample = 68; - counter75hz_lim = 2080; if(pv->reg[1]&8) lines_vis = 240; } else { //cycles_68k = (int) ((double) OSC_NTSC / 7 / 60 / 262 + 0.4); // 488 //cycles_z80 = (int) ((double) OSC_NTSC / 15 / 60 / 262 + 0.4); // 228 lines = 262; - counter75hz_lim = 2096; line_sample = 93; } @@ -242,13 +273,7 @@ static int PicoFrameHintsMCD(void) total_z80+=z80_run(z80CycleAim-total_z80); } - if ((Pico_mcd->m.counter75hz+=10) >= counter75hz_lim) { - Pico_mcd->m.counter75hz -= counter75hz_lim; - Check_CD_Command(); - } - - if (Pico_mcd->rot_comp.Reg_58 & 0x8000) - gfx_cd_update(); + update_chips(); } // draw a frame just after vblank in alternative render mode diff --git a/Pico/sound/mix.c b/Pico/sound/mix.c new file mode 100644 index 0000000..8e4a631 --- /dev/null +++ b/Pico/sound/mix.c @@ -0,0 +1,57 @@ +#define MAXOUT (+32767) +#define MINOUT (-32768) + +/* limitter */ +#define Limit(val, max,min) { \ + if ( val > max ) val = max; \ + else if ( val < min ) val = min; \ +} + + + + +void memcpy32(int *dest, int *src, int count) +{ + while (count--) + *dest++ = *src++; +} + + +void memset32(int *dest, int c, int count) +{ + while (count--) + *dest++ = c; +} + + +void mix_32_to_16l_stereo(short *dest, int *src, int count) +{ + int l, r; + + for (; count > 0; count--) + { + l = r = *dest; + l += *src++; + r += *src++; + Limit( l, MAXOUT, MINOUT ); + Limit( r, MAXOUT, MINOUT ); + *dest++ = l; + *dest++ = r; + } +} + + +void mix_32_to_16_mono(short *dest, int *src, int count) +{ + int l; + + for (; count > 0; count--) + { + l = *dest; + l += *src++; + Limit( l, MAXOUT, MINOUT ); + *dest++ = l; + } +} + + diff --git a/Pico/sound/mix.h b/Pico/sound/mix.h new file mode 100644 index 0000000..752cfb6 --- /dev/null +++ b/Pico/sound/mix.h @@ -0,0 +1,10 @@ + +void memcpy32(int *dest, int *src, int count); +void memset32(int *dest, int c, int count); +//void mix_32_to_32(int *dest, int *src, int count); +void mix_16h_to_32(int *dest, short *src, int count); +void mix_16h_to_32_s1(int *dest, short *src, int count); +void mix_16h_to_32_s2(int *dest, short *src, int count); +void mix_32_to_16l_stereo(short *dest, int *src, int count); +void mix_32_to_16_mono(short *dest, int *src, int count); + diff --git a/Pico/sound/mix.s b/Pico/sound/mix.s new file mode 100644 index 0000000..ab0853e --- /dev/null +++ b/Pico/sound/mix.s @@ -0,0 +1,350 @@ +@ vim:filetype=armasm + +.global memcpy32 @ int *dest, int *src, int count + +memcpy32: + stmfd sp!, {r4,lr} + + subs r2, r2, #4 + bmi mcp32_fin + +mcp32_loop: + ldmia r1!, {r3,r4,r12,lr} + subs r2, r2, #4 + stmia r0!, {r3,r4,r12,lr} + bpl mcp32_loop + +mcp32_fin: + tst r2, #3 + ldmeqfd sp!, {r4,pc} + tst r2, #1 + ldrne r3, [r1], #4 + strne r3, [r0], #4 + +mcp32_no_unal1: + tst r2, #2 + ldmneia r1!, {r3,r12} + ldmfd sp!, {r4,lr} + stmneia r0!, {r3,r12} + bx lr + + + +.global memset32 @ int *dest, int c, int count + +memset32: + stmfd sp!, {lr} + + mov r3, r1 + subs r2, r2, #4 + bmi mst32_fin + + mov r12,r1 + mov lr, r1 + +mst32_loop: + subs r2, r2, #4 + stmia r0!, {r1,r3,r12,lr} + bpl mst32_loop + +mst32_fin: + tst r2, #1 + strne r1, [r0], #4 + + tst r2, #2 + stmneia r0!, {r1,r3} + + ldmfd sp!, {lr} + bx lr + + + +@ this assumes src is word aligned +.global mix_16h_to_32 @ int *dest, short *src, int count + +mix_16h_to_32: + stmfd sp!, {r4-r6,lr} +/* + tst r1, #2 + beq m16_32_mo_unalw + ldrsh r4, [r1], #2 + ldr r3, [r0] + sub r2, r2, #1 + add r3, r3, r4, asr #1 + str r3, [r0], #4 +*/ +m16_32_mo_unalw: + subs r2, r2, #4 + bmi m16_32_end + +m16_32_loop: + ldmia r0, {r3-r6} + ldmia r1!,{r12,lr} + subs r2, r2, #4 + add r4, r4, r12,asr #17 @ we use half volume + mov r12,r12,lsl #16 + add r3, r3, r12,asr #17 + add r6, r6, lr, asr #17 + mov lr, lr, lsl #16 + add r5, r5, lr, asr #17 + stmia r0!,{r3-r6} + bpl m16_32_loop + +m16_32_end: + tst r2, #2 + beq m16_32_no_unal2 + ldr r5, [r1], #4 + ldmia r0, {r3,r4} + mov r12,r5, lsl #16 + add r3, r3, r12,asr #17 + add r4, r4, r5, asr #17 + stmia r0!,{r3,r4} + +m16_32_no_unal2: + tst r2, #1 + ldmeqfd sp!, {r4-r6,pc} + ldrsh r4, [r1], #2 + ldr r3, [r0] + add r3, r3, r4, asr #1 + str r3, [r0], #4 + + ldmfd sp!, {r4-r6,lr} + bx lr + + + +.global mix_16h_to_32_s1 @ int *dest, short *src, int count + +mix_16h_to_32_s1: + stmfd sp!, {r4-r6,lr} + + subs r2, r2, #4 + bmi m16_32_s1_end + +m16_32_s1_loop: + ldmia r0, {r3-r6} + ldr r12,[r1], #8 + ldr lr, [r1], #8 + subs r2, r2, #4 + add r4, r4, r12,asr #17 + mov r12,r12,lsl #16 + add r3, r3, r12,asr #17 @ we use half volume + add r6, r6, lr, asr #17 + mov lr, lr, lsl #16 + add r5, r5, lr, asr #17 + stmia r0!,{r3-r6} + bpl m16_32_s1_loop + +m16_32_s1_end: + tst r2, #2 + beq m16_32_s1_no_unal2 + ldr r5, [r1], #8 + ldmia r0, {r3,r4} + mov r12,r5, lsl #16 + add r3, r3, r12,asr #17 + add r4, r4, r5, asr #17 + stmia r0!,{r3,r4} + +m16_32_s1_no_unal2: + tst r2, #1 + ldmeqfd sp!, {r4-r6,pc} + ldrsh r4, [r1], #2 + ldr r3, [r0] + add r3, r3, r4, asr #1 + str r3, [r0], #4 + + ldmfd sp!, {r4-r6,lr} + bx lr + + + +.global mix_16h_to_32_s2 @ int *dest, short *src, int count + +mix_16h_to_32_s2: + stmfd sp!, {r4-r6,lr} + + subs r2, r2, #4 + bmi m16_32_s2_end + +m16_32_s2_loop: + ldmia r0, {r3-r6} + ldr r12,[r1], #16 + ldr lr, [r1], #16 + subs r2, r2, #4 + add r4, r4, r12,asr #17 + mov r12,r12,lsl #16 + add r3, r3, r12,asr #17 @ we use half volume + add r6, r6, lr, asr #17 + mov lr, lr, lsl #16 + add r5, r5, lr, asr #17 + stmia r0!,{r3-r6} + bpl m16_32_s2_loop + +m16_32_s2_end: + tst r2, #2 + beq m16_32_s2_no_unal2 + ldr r5, [r1], #16 + ldmia r0, {r3,r4} + mov r12,r5, lsl #16 + add r3, r3, r12,asr #17 + add r4, r4, r5, asr #17 + stmia r0!,{r3,r4} + +m16_32_s2_no_unal2: + tst r2, #1 + ldmeqfd sp!, {r4-r6,pc} + ldrsh r4, [r1], #2 + ldr r3, [r0] + add r3, r3, r4, asr #1 + str r3, [r0], #4 + + ldmfd sp!, {r4-r6,lr} + bx lr + + + +@ limit +@ reg=int_sample, lr=1, r3=tmp, kills flags +.macro Limit reg + add r3, lr, \reg, asr #16 + bics r3, r3, #1 @ in non-overflow conditions r3 is 0 or 1 + movne \reg, #0x8000 + submi \reg, \reg, #1 +.endm + + +@ limit and shift up by 16 +@ reg=int_sample, lr=1, r3=tmp, kills flags +.macro Limitsh reg +@ movs r4, r3, asr #16 +@ cmnne r4, #1 +@ beq c32_16_no_overflow +@ tst r4, r4 +@ mov r3, #0x8000 +@ subpl r3, r3, #1 + + add r3, lr, \reg, asr #16 + bics r3, r3, #1 @ in non-overflow conditions r3 is 0 or 1 + moveq \reg, \reg, lsl #16 + movne \reg, #0x80000000 + submi \reg, \reg, #0x00010000 +.endm + + +@ mix 32bit audio (with 16bits really used, upper bits indicate overflow) with normal 16 bit audio with left channel only +@ warning: this function assumes dest is word aligned +.global mix_32_to_16l_stereo @ short *dest, int *src, int count + +mix_32_to_16l_stereo: + stmfd sp!, {r4-r8,lr} + + mov lr, #1 + + mov r2, r2, lsl #1 + subs r2, r2, #4 + bmi m32_16l_st_end + +m32_16l_st_loop: + ldmia r0, {r8,r12} + ldmia r1!, {r4-r7} + mov r8, r8, lsl #16 + mov r12,r12,lsl #16 + add r4, r4, r8, asr #16 + add r5, r5, r8, asr #16 + add r6, r6, r12,asr #16 + add r7, r7, r12,asr #16 + Limitsh r4 + Limitsh r5 + Limitsh r6 + Limitsh r7 + subs r2, r2, #4 + orr r4, r5, r4, lsr #16 + orr r5, r7, r6, lsr #16 + stmia r0!, {r4,r5} + bpl m32_16l_st_loop + +m32_16l_st_end: + @ check for remaining bytes to convert + tst r2, #2 + beq m32_16l_st_no_unal2 + ldrsh r6, [r0] + ldmia r1!,{r4,r5} + add r4, r4, r6 + add r5, r5, r6 + Limitsh r4 + Limitsh r5 + orr r4, r5, r4, lsr #16 + str r4, [r0], #4 + +m32_16l_st_no_unal2: + ldmfd sp!, {r4-r8,lr} + bx lr + + +@ mix 32bit audio (with 16bits really used, upper bits indicate overflow) with normal 16 bit audio (for mono sound) +.global mix_32_to_16_mono @ short *dest, int *src, int count + +mix_32_to_16_mono: + stmfd sp!, {r4-r8,lr} + + mov lr, #1 + + @ check if dest is word aligned + tst r0, #2 + beq m32_16_mo_no_unalw + ldrsh r5, [r0], #2 + ldr r4, [r1], #4 + sub r2, r2, #1 + add r4, r4, r5 + Limit r4 + strh r4, [r0], #2 + +m32_16_mo_no_unalw: + subs r2, r2, #4 + bmi m32_16_mo_end + +m32_16_mo_loop: + ldmia r0, {r8,r12} + ldmia r1!, {r4-r7} + add r5, r5, r8, asr #16 + mov r8, r8, lsl #16 + add r4, r4, r8, asr #16 + add r7, r7, r12,asr #16 + mov r12,r12,lsl #16 + add r6, r6, r12,asr #16 + Limitsh r4 + Limitsh r5 + Limitsh r6 + Limitsh r7 + subs r2, r2, #4 + orr r4, r5, r4, lsr #16 + orr r5, r7, r6, lsr #16 + stmia r0!, {r4,r5} + bpl m32_16_mo_loop + +m32_16_mo_end: + @ check for remaining bytes to convert + tst r2, #2 + beq m32_16_mo_no_unal2 + ldr r6, [r0] + ldmia r1!,{r4,r5} + add r5, r5, r6, asr #16 + mov r6, r6, lsl #16 + add r4, r4, r6, asr #16 + Limitsh r4 + Limitsh r5 + orr r4, r5, r4, lsr #16 + str r4, [r0], #4 + +m32_16_mo_no_unal2: + tst r2, #1 + ldmeqfd sp!, {r4-r8,pc} + ldrsh r5, [r0], #2 + ldr r4, [r1], #4 + add r4, r4, r5 + Limit r4 + strh r4, [r0], #2 + + ldmfd sp!, {r4-r8,lr} + bx lr + diff --git a/Pico/sound/sn76496.c b/Pico/sound/sn76496.c index 1afd3be..8474c70 100644 --- a/Pico/sound/sn76496.c +++ b/Pico/sound/sn76496.c @@ -175,7 +175,7 @@ WRITE8_HANDLER( SN76496_4_w ) { SN76496Write(4,data); } */ //static -void SN76496Update(short *buffer,int length,int stereo) +void SN76496Update(short *buffer, int length, int stereo) { int i; struct SN76496 *R = &ono_sn; @@ -258,13 +258,10 @@ void SN76496Update(short *buffer,int length,int stereo) if (out > MAX_OUTPUT * STEP) out = MAX_OUTPUT * STEP; - out /= STEP; // will be optimized to shift - if(stereo) { - // only left channel for stereo (will be copied to right by ym2612 mixing code) + if ((out /= STEP)) // will be optimized to shift; max 0x47ff = 18431 *buffer += out; - buffer+=2; - } else - *buffer++ += out; + if(stereo) buffer+=2; // only left for stereo, to be mixed to right later + else buffer++; length--; } diff --git a/Pico/sound/sound.c b/Pico/sound/sound.c index d5802bd..6ea966b 100644 --- a/Pico/sound/sound.c +++ b/Pico/sound/sound.c @@ -23,7 +23,11 @@ #endif #include "../PicoInt.h" +#include "../cd/pcm.h" +#include "mix.h" +// master int buffer to mix to +static int PsndBuffer[2*44100/50]; //int z80CycleAim = 0; @@ -77,7 +81,7 @@ static void dac_recalculate() dac_cnt -= lines; len++; } - if (i == mid) // midpoint + if (i == mid) // midpoint while(pos+len < PsndLen/2) { dac_cnt -= lines; len++; @@ -124,9 +128,18 @@ void sound_rerate() { unsigned int state[28]; + // not all rates are supported in MCD mode due to mp3 decoder + if (PicoMCD & 1) { + if (PsndRate != 11025 && PsndRate != 22050 && PsndRate != 44100) PsndRate = 22050; + if (!(PicoOpt & 8)) PicoOpt |= 8; + } + + 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); // feed it back it's own registers, just like after loading state 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); memcpy(state, sn76496_regs, 28*4); // remember old state SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PsndRate); @@ -137,56 +150,102 @@ void sound_rerate() // recalculate dac info dac_recalculate(); + + if (PicoMCD & 1) + pcm_set_rate(PsndRate); } // This is called once per raster (aka line), but not necessarily for every line -int sound_timers_and_dac(int raster) +void sound_timers_and_dac(int raster) { - if(raster >= 0 && PsndOut && (PicoOpt&1) && *ym2612_dacen) { - short dout = (short) *ym2612_dacout; - int pos=dac_info[raster], len=pos&0xf; - short *d; - pos>>=4; - - if(PicoOpt&8) { // only left channel for stereo (will be copied to right by ym2612 mixing code) - d=PsndOut+pos*2; - while(len--) { *d = dout; d += 2; } + int pos, len; + int do_dac = PsndOut && (PicoOpt&1) && *ym2612_dacen; +// int do_pcm = PsndOut && (PicoMCD&1) && (PicoOpt&0x400); + + // Our raster lasts 63.61323/64.102564 microseconds (NTSC/PAL) + YM2612PicoTick(1); + + if (!do_dac /*&& !do_pcm*/) return; + + pos=dac_info[raster], len=pos&0xf; + if (!len) return; + + pos>>=4; + + if (do_dac) { + short *d = PsndOut + pos*2; + int dout = *ym2612_dacout; + if(PicoOpt&8) { + // some manual loop unrolling here :) + d[0] = dout; + if (len > 1) { + d[2] = dout; + if (len > 2) { + d[4] = dout; + if (len > 3) + d[6] = dout; + } + } } else { - d=PsndOut+pos; - while(len--) *d++ = dout; + short *d = PsndOut + pos; + d[0] = dout; + if (len > 1) { + d[1] = dout; + if (len > 2) { + d[2] = dout; + if (len > 3) + d[3] = dout; + } + } } } - //dprintf("s: %03i", raster); +#if 0 + if (do_pcm) { + int *d = PsndBuffer; + d += (PicoOpt&8) ? pos*2 : pos; + pcm_update(d, len, 1); + } +#endif +} - // Our raster lasts 63.61323/64.102564 microseconds (NTSC/PAL) - YM2612PicoTick(1); - return 0; +void sound_clear(void) +{ + if (PicoOpt & 8) memset32((int *) PsndOut, 0, PsndLen); + else memset(PsndOut, 0, PsndLen<<1); +// memset(PsndBuffer, 0, (PicoOpt & 8) ? (PsndLen<<3) : (PsndLen<<2)); } int sound_render(int offset, int length) { + int *buf32 = PsndBuffer+offset; int stereo = (PicoOpt & 8) >> 3; + // emulating CD && PCM option enabled && PCM chip on && have enabled channels + int do_pcm = (PicoMCD&1) && (PicoOpt&0x400) && (Pico_mcd->pcm.control & 0x80) && Pico_mcd->pcm.enabled; offset <<= stereo; // PSG - if(PicoOpt & 2) + if (PicoOpt & 2) SN76496Update(PsndOut+offset, length, stereo); // Add in the stereo FM buffer - if(PicoOpt & 1) { - YM2612UpdateOne(PsndOut+offset, length, stereo); - } else { - // YM2612 upmixes to stereo, so we have to do this manually here - int i; - short *s = PsndOut+offset; - for (i = 0; i < length; i++) { - *(s+1) = *s; s+=2; - } - } + if (PicoOpt & 1) + YM2612UpdateOne(buf32, length, stereo, 1); + + if (do_pcm) + pcm_update(buf32, length, stereo); + + // CDDA audio +// if ((PicoMCD & 1) && (PicoOpt & 0x800)) +// mp3_update(PsndBuffer+offset, length, stereo); + + // convert + limit to normal 16bit output + if (stereo) + mix_32_to_16l_stereo(PsndOut+offset, buf32, length); + else mix_32_to_16_mono (PsndOut+offset, buf32, length); return 0; } @@ -259,14 +318,14 @@ void z80_init() mz80init(); // Modify the default context mz80GetContext(&z80); - + // point mz80 stuff z80.z80Base=Pico.zram; z80.z80MemRead=mz80_mem_read; z80.z80MemWrite=mz80_mem_write; z80.z80IoRead=mz80_io_read; z80.z80IoWrite=mz80_io_write; - + mz80SetContext(&z80); #elif defined(_USE_DRZ80) diff --git a/Pico/sound/sound.h b/Pico/sound/sound.h index 8335fb2..ffdfcf5 100644 --- a/Pico/sound/sound.h +++ b/Pico/sound/sound.h @@ -11,8 +11,9 @@ extern "C" { #endif -int sound_timers_and_dac(int raster); -int sound_render(int offset, int length); +void sound_timers_and_dac(int raster); +int sound_render(int offset, int length); +void sound_clear(void); //int YM2612PicoTick(int n); diff --git a/Pico/sound/ym2612.c b/Pico/sound/ym2612.c index 56e5312..60d6c81 100644 --- a/Pico/sound/ym2612.c +++ b/Pico/sound/ym2612.c @@ -1,5 +1,5 @@ /* -** This is a bunch of remains of original fm.c from MAME project. All stuff +** This is a bunch of remains of original fm.c from MAME project. All stuff ** unrelated to ym2612 was removed, multiple chip support was removed, ** some parts of code were slightly rewritten and tied to the emulator. ** @@ -112,6 +112,7 @@ #include #include "ym2612.h" +#include "mix.h" #ifndef EXTERNAL_YM2612 #include @@ -120,7 +121,6 @@ static YM2612 ym2612; #else extern YM2612 *ym2612_940; -extern int *mix_buffer; #define ym2612 (*ym2612_940) #endif @@ -1584,13 +1584,12 @@ INT32 *ym2612_dacout; /* Generate samples for YM2612 */ -void YM2612UpdateOne_(short *buffer, int length, int stereo) +int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty) { int pan; -#ifndef EXTERNAL_YM2612 - int i; - static int *mix_buffer = 0, mix_buffer_length = 0; -#endif + + // if !is_buf_empty, it means it has valid samples to mix with, else it may contain trash + if (is_buf_empty) memset32(buffer, 0, length<>2)); + chan_render(buffer, length, &ym2612.CH[4], stereo|((pan&0x300)>>4)); + chan_render(buffer, length, &ym2612.CH[5], stereo|((pan&0xc00)>>6)|(ym2612.dacen<<2)|2); - /* mix to 32bit temporary buffer */ - chan_render(mix_buffer, length, &ym2612.CH[0], stereo|((pan&0x003)<<4)); // flags: stereo, lastchan, disabled, ?, pan_r, pan_l - chan_render(mix_buffer, length, &ym2612.CH[1], stereo|((pan&0x00c)<<2)); - chan_render(mix_buffer, length, &ym2612.CH[2], stereo|((pan&0x030) )); - chan_render(mix_buffer, length, &ym2612.CH[3], stereo|((pan&0x0c0)>>2)); - chan_render(mix_buffer, length, &ym2612.CH[4], stereo|((pan&0x300)>>4)); - chan_render(mix_buffer, length, &ym2612.CH[5], stereo|((pan&0xc00)>>6)|(ym2612.dacen<<2)|2); - -#ifndef EXTERNAL_YM2612 - /* limit and mix to output buffer */ - if (stereo) { - int *mb = mix_buffer; - for (i = length; i > 0; i--) { - int l, r; - l = r = *buffer; - l += *mb++, r += *mb++; - Limit( l, MAXOUT, MINOUT ); - Limit( r, MAXOUT, MINOUT ); - *buffer++ = l; *buffer++ = r; - } - } else { - for (i = 0; i < length; i++) { - int l = mix_buffer[i]; - l += buffer[i]; - Limit( l, MAXOUT, MINOUT ); - buffer[i] = l; - } - } -#endif + return 1; // buffer updated } diff --git a/Pico/sound/ym2612.h b/Pico/sound/ym2612.h index c575bae..033ba26 100644 --- a/Pico/sound/ym2612.h +++ b/Pico/sound/ym2612.h @@ -142,7 +142,7 @@ typedef struct void YM2612Init_(int baseclock, int rate); void YM2612ResetChip_(void); -void YM2612UpdateOne_(short *buffer, int length, int stereo); +int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty); int YM2612Write_(unsigned int a, unsigned int v); unsigned char YM2612Read_(void); @@ -172,9 +172,9 @@ extern int PicoOpt; if (PicoOpt&0x200) YM2612ResetChip_940(); \ else YM2612ResetChip_(); \ } -#define YM2612UpdateOne(buffer,length,stereo) { \ - if (PicoOpt&0x200) YM2612UpdateOne_940(buffer, length, stereo); \ - else YM2612UpdateOne_(buffer, length, stereo); \ +#define YM2612UpdateOne(buffer,length,stereo,is_buf_empty) { \ + if (PicoOpt&0x200) YM2612UpdateOne_940(buffer, length, stereo, is_buf_empty); \ + else YM2612UpdateOne_(buffer, length, stereo, is_buf_empty); \ } #define YM2612Write(a,v) \ (PicoOpt&0x200) ? YM2612Write_940(a, v) : YM2612Write_(a, v) diff --git a/platform/gp2x/940ctl_ym2612.c b/platform/gp2x/940ctl_ym2612.c index 63d1e48..3502b82 100644 --- a/platform/gp2x/940ctl_ym2612.c +++ b/platform/gp2x/940ctl_ym2612.c @@ -14,6 +14,9 @@ #include "asmutils.h" #include "../../Pico/PicoInt.h" +// tmp +#include "../../Pico/sound/mix.h" + /* we will need some gp2x internals here */ extern volatile unsigned short *gp2x_memregs; /* from minimal library rlyeh */ extern volatile unsigned long *gp2x_memregl; @@ -223,6 +226,7 @@ int YM2612PicoTick_940(int n) return 0; } +static int g_busy = 10; static void wait_busy_940(void) { @@ -239,8 +243,9 @@ static void wait_busy_940(void) } printf("wait iterations: %i\n", i); #else - for (i = 0; shared_ctl->busy && i < 0x10000; i++) + for (i = 0; /*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1] && i < 0x10000; i++) spend_cycles(8*1024); // tested to be best for mp3 dec + //printf("i = 0x%x\n", i); if (i < 0x10000) return; /* 940 crashed */ @@ -248,6 +253,19 @@ static void wait_busy_940(void) for (i = 0; i < 8; i++) printf("%i ", shared_ctl->vstarts[i]); printf(")\n"); + printf("irq pending flags: DUALCPU %04x (see 15?), SRCPND %08lx (see 26), INTPND %08lx\n", + gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2]); + printf("last irq PC: %08x, lastjob: 0x%03x, busy: %x, lastbusy: %x, g_busy: %x\n", shared_ctl->last_irq_pc, + shared_ctl->lastjob, gp2x_memregs[0x3B3E>>1]/*shared_ctl->busy*/, shared_ctl->lastbusy, g_busy); + printf("trying to interrupt..\n"); + gp2x_memregs[0x3B3E>>1] = 0xffff; + for (i = 0; /*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1] && i < 0x10000; i++) + spend_cycles(8*1024); + printf("i = 0x%x\n", i); + printf("irq pending flags: DUALCPU %04x (see 15?), SRCPND %08lx (see 26), INTPND %08lx\n", + gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2]); + printf("last irq PC: %08x, lastjob: 0x%03x, busy: %x\n", shared_ctl->last_irq_pc, shared_ctl->lastjob, gp2x_memregs[0x3B3E>>1]/*shared_ctl->busy*/); + strcpy(menuErrorMsg, "940 crashed."); engineState = PGS_Menu; crashed_940 = 1; @@ -257,10 +275,17 @@ static void wait_busy_940(void) static void add_job_940(int job0, int job1) { +/* if (gp2x_memregs[0x3b46>>1] || shared_ctl->busy) + { + printf("!!add_job_940: irq pending flags: DUALCPU %04x (see 15?), SRCPND %08lx (see 26), INTPND %08lx, busy: %x\n", + gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2], shared_ctl->busy); + } +*/ shared_ctl->jobs[0] = job0; shared_ctl->jobs[1] = job1; - shared_ctl->busy = 1; - gp2x_memregs[0x3B3E>>1] = 0xffff; // cause an IRQ for 940 + //shared_ctl->busy = ++g_busy; // 1; + gp2x_memregs[0x3B3E>>1] = ++g_busy; // set busy flag +// gp2x_memregs[0x3B3E>>1] = 0xffff; // cause interrupt } @@ -268,7 +293,7 @@ void YM2612PicoStateLoad_940(void) { int i, old_A1 = addr_A1; - if (shared_ctl->busy) wait_busy_940(); + if (/*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1]) wait_busy_940(); // feed all the registers and update internal state for(i = 0; i < 0x100; i++) { @@ -310,10 +335,8 @@ void YM2612Init_940(int baseclock, int rate) Reset940(1, 2); Pause940(1); - gp2x_memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940 - gp2x_memregs[0x3B42>>1] = 0xffff; // enable DUALCPU interrupts for 940 - - gp2x_memregl[0x4508>>2] = ~(1<<26); // unmask DUALCPU ints in the undocumented 940's interrupt controller + gp2x_memregs[0x3B40>>1] = 0; // disable DUALCPU interrupts for 920 + gp2x_memregs[0x3B42>>1] = 1; // enable DUALCPU interrupts for 940 if (shared_mem == NULL) { @@ -388,7 +411,13 @@ void YM2612Init_940(int baseclock, int rate) shared_ctl->rate = rate; shared_ctl->jobs[0] = JOB940_INITALL; shared_ctl->jobs[1] = 0; - shared_ctl->busy = 1; + //shared_ctl->busy = 1; + gp2x_memregs[0x3B3E>>1] = 1; // set busy flag + + gp2x_memregs[0x3B46>>1] = 0xffff; // clear pending DUALCPU interrupts for 940 + gp2x_memregl[0x4500>>2] = 0; // clear pending IRQs in SRCPND + gp2x_memregl[0x4510>>2] = 0; // clear pending IRQs in INTPND + gp2x_memregl[0x4508>>2] = ~(1<<26); // unmask DUALCPU ints in the undocumented 940's interrupt controller /* start the 940 */ Reset940(0, 2); @@ -406,7 +435,7 @@ void YM2612ResetChip_940(void) return; } - if (shared_ctl->busy) wait_busy_940(); + if (/*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1]) wait_busy_940(); internal_reset(); @@ -414,104 +443,93 @@ void YM2612ResetChip_940(void) } -static void mix_samples(short *dest_buf, int *ym_buf, short *mp3_buf, int len, int stereo) +//extern int pcm_buffer[2*44100/50]; +/* +static void mix_samples(int *dest_buf, short *mp3_buf, int len, int stereo) { - if (mp3_buf) +// int *pcm = pcm_buffer + offset * 2; + + if (stereo) { - if (stereo) + for (; len > 0; len--) { - for (; len > 0; len--) - { - int l, r, lm, rm; - l = r = *dest_buf; - l += *ym_buf++; r += *ym_buf++; - lm = *mp3_buf++; rm = *mp3_buf++; - l += lm - lm/2; r += rm - rm/2; - Limit( l, MAXOUT, MINOUT ); - Limit( r, MAXOUT, MINOUT ); - *dest_buf++ = l; *dest_buf++ = r; - } - } else { - for (; len > 0; len--) - { - // TODO: normalize - int l = *ym_buf++; - l += *dest_buf; - l += *mp3_buf++; - Limit( l, MAXOUT, MINOUT ); - *dest_buf++ = l; - } + int lm, rm; + lm = *mp3_buf++; rm = *mp3_buf++; + *dest_buf++ += lm - lm/2; *dest_buf++ += rm - rm/2; } - } - else - { - if (stereo) + } else { + for (; len > 0; len--) { - for (; len > 0; len--) - { - int l, r; - l = r = *dest_buf; - l += *ym_buf++, r += *ym_buf++; - Limit( l, MAXOUT, MINOUT ); - Limit( r, MAXOUT, MINOUT ); - *dest_buf++ = l; *dest_buf++ = r; - } - } else { - for (; len > 0; len--) - { - int l = *ym_buf++; - l += *dest_buf; - Limit( l, MAXOUT, MINOUT ); - *dest_buf++ = l; - } + int l = *mp3_buf++; + *dest_buf++ = l - l/2; } } } - +*/ // here we assume that length is different between games, but constant in one game static int mp3_samples_ready = 0, mp3_buffer_offs = 0; static int mp3_play_bufsel = 0; -void YM2612UpdateOne_940(short *buffer, int length, int stereo) +int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty) { - int cdda_on, *ym_buffer = shared_data->mix_buffer, mp3_job = 0; + int length_mp3 = Pico.m.pal ? 44100/50 : 44100/60; // mp3s are locked to 44100Hz stereo + int *ym_buf = shared_data->mix_buffer; +// int *dest_buf = buffer; + int cdda_on, mp3_job = 0; +// int len; + + // emulating CD, enabled in opts, not data track, CDC is reading, playback was started, track not ended + cdda_on = (PicoMCD & 1) && (PicoOpt & 0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) && + (Pico_mcd->scd.Status_CDC & 1) && loaded_mp3; //printf("YM2612UpdateOne_940()\n"); - if (shared_ctl->busy) wait_busy_940(); + if (/*shared_ctl->busy*/gp2x_memregs[0x3B3E>>1]) wait_busy_940(); - //printf("940 (cnt: %i, wc: %i, ve: ", shared_ctl->loopc, shared_ctl->waitc); - //for (i = 0; i < 8; i++) - // printf("%i ", shared_ctl->vstarts[i]); - //printf(")\n"); + // track ended? + cdda_on = cdda_on && shared_ctl->mp3_offs < shared_ctl->mp3_len; - // emulatind MCD, cdda enabled in config, not data track, CDC is reading, playback was started, track not ended - cdda_on = (PicoMCD & 1) && (currentConfig.EmuOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) && - (Pico_mcd->scd.Status_CDC & 1) && loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len; + // mix in ym buffer + if (is_buf_empty) memcpy32(buffer, ym_buf, length< 0; len--) +// { +// *dest_buf++ += *ym_buf++; +// } - /* mix data from previous go */ - if (cdda_on && mp3_samples_ready >= length) + /* mix mp3 data, only stereo */ + if (cdda_on && mp3_samples_ready >= length_mp3) { - if (1152 - mp3_buffer_offs >= length) { - mix_samples(buffer, ym_buffer, shared_data->mp3_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, length, stereo); + int shr = 0; + void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32; + if (PsndRate == 22050) { mix_samples = mix_16h_to_32_s1; shr = 1; } + else if (PsndRate == 11025) { mix_samples = mix_16h_to_32_s2; shr = 2; } - mp3_buffer_offs += length; + if (1152 - mp3_buffer_offs >= length_mp3) { + mix_samples(buffer, shared_data->mp3_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, (length_mp3>>shr)<<1); + + mp3_buffer_offs += length_mp3; } else { // collect from both buffers.. int left = 1152 - mp3_buffer_offs; - mix_samples(buffer, ym_buffer, shared_data->mp3_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, left, stereo); - mp3_play_bufsel ^= 1; - mp3_buffer_offs = length - left; - mix_samples(buffer + left * 2, ym_buffer + left * 2, - shared_data->mp3_buffer[mp3_play_bufsel], mp3_buffer_offs, stereo); + if (mp3_play_bufsel == 0) + { + mix_samples(buffer, shared_data->mp3_buffer[0] + mp3_buffer_offs*2, (length_mp3>>shr)<<1); + mp3_buffer_offs = length_mp3 - left; + mp3_play_bufsel = 1; + } else { + mix_samples(buffer, shared_data->mp3_buffer[1] + mp3_buffer_offs*2, (left>>shr)<<1); + mp3_buffer_offs = length_mp3 - left; + mix_samples(buffer + ((left>>shr)<<1), + shared_data->mp3_buffer[0], (mp3_buffer_offs>>shr)<<1); + mp3_play_bufsel = 0; + } } - mp3_samples_ready -= length; - } else { - mix_samples(buffer, ym_buffer, 0, length, stereo); + mp3_samples_ready -= length_mp3; } - //printf("new writes: %i\n", writebuff_ptr); if (shared_ctl->writebuffsel == 1) { shared_ctl->writebuff0[writebuff_ptr] = 0xffff; } else { @@ -525,7 +543,7 @@ void YM2612UpdateOne_940(short *buffer, int length, int stereo) shared_ctl->stereo = stereo; // make sure we will have enough mp3 samples next frame - if (cdda_on && mp3_samples_ready < length) + if (cdda_on && mp3_samples_ready < length_mp3) { shared_ctl->mp3_buffsel ^= 1; mp3_job = JOB940_MP3DECODE; @@ -536,6 +554,8 @@ void YM2612UpdateOne_940(short *buffer, int length, int stereo) //spend_cycles(512); //printf("SRCPND: %08lx, INTMODE: %08lx, INTMASK: %08lx, INTPEND: %08lx\n", // gp2x_memregl[0x4500>>2], gp2x_memregl[0x4504>>2], gp2x_memregl[0x4508>>2], gp2x_memregl[0x4510>>2]); + + return 1; } @@ -551,11 +571,11 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023 if (loaded_mp3 != f) { - printf("loading mp3... "); fflush(stdout); + // printf("loading mp3... "); fflush(stdout); fseek(f, 0, SEEK_SET); fread(mp3_mem, 1, MP3_SIZE_MAX, f); - if (feof(f)) printf("done.\n"); - else printf("done. mp3 too large, not all data loaded.\n"); + // if (feof(f)) printf("done.\n"); + // else printf("done. mp3 too large, not all data loaded.\n"); shared_ctl->mp3_len = ftell(f); loaded_mp3 = f; } @@ -566,7 +586,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023 byte_offs *= pos; byte_offs >>= 6; } - printf("mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len); + // printf("mp3 pos1024: %i, byte_offs %i/%i\n", pos, byte_offs, shared_ctl->mp3_len); shared_ctl->mp3_offs = byte_offs; diff --git a/platform/gp2x/940ctl_ym2612.h b/platform/gp2x/940ctl_ym2612.h index 7d94c13..bf9b528 100644 --- a/platform/gp2x/940ctl_ym2612.h +++ b/platform/gp2x/940ctl_ym2612.h @@ -1,6 +1,6 @@ void YM2612Init_940(int baseclock, int rate); void YM2612ResetChip_940(void); -void YM2612UpdateOne_940(short *buffer, int length, int stereo); +int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty); int YM2612Write_940(unsigned int a, unsigned int v); unsigned char YM2612Read_940(void); diff --git a/platform/gp2x/Makefile b/platform/gp2x/Makefile index d253dcc..5efe302 100644 --- a/platform/gp2x/Makefile +++ b/platform/gp2x/Makefile @@ -41,7 +41,7 @@ OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory # Pico - CD OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \ ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o \ - ../../Pico/cd/Area.o ../../Pico/cd/Misc.o + ../../Pico/cd/Area.o ../../Pico/cd/Misc.o ../../Pico/cd/pcm.o # asm stuff ifeq "$(asm_render)" "1" DEFINC += -D_ASM_DRAW_C @@ -56,6 +56,7 @@ DEFINC += -D_ASM_YM2612_C OBJS += ../../Pico/sound/ym2612_asm.o endif # Pico - sound +OBJS += ../../Pico/sound/mix_asm.o OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o # zlib OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/inftrees.o ../../zlib/trees.o \ @@ -94,7 +95,7 @@ ifeq "$(up)" "1" @cmd //C copy $@ \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\ endif -up: +up: PicoDrive.gpe @cp -v PicoDrive.gpe /mnt/gp2x/mnt/sd/games/PicoDrive/ # @cmd //C copy PicoDrive.gpe \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\ @@ -124,6 +125,9 @@ testrefr.gpe : test.o gp2x.o asmutils.o ../../Pico/sound/ym2612_asm.o : ../../Pico/sound/ym2612.s @echo $< @$(AS) $(ASOPT) $< -o $@ +../../Pico/sound/mix_asm.o : ../../Pico/sound/mix.s + @echo $< + @$(AS) $(ASOPT) $< -o $@ # build Cyclone ../../cpu/Cyclone/proj/Cyclone.s : diff --git a/platform/gp2x/asmutils.h b/platform/gp2x/asmutils.h index d922690..cade08c 100644 --- a/platform/gp2x/asmutils.h +++ b/platform/gp2x/asmutils.h @@ -10,3 +10,5 @@ void vidCpyM2_40col(void *dest, void *src); void vidCpyM2_32col(void *dest, void *src); void vidCpyM2_32col_nobord(void *dest, void *src); void spend_cycles(int c); // utility +void flushcache(void); + diff --git a/platform/gp2x/asmutils.s b/platform/gp2x/asmutils.s index e1e0945..92226b3 100644 --- a/platform/gp2x/asmutils.s +++ b/platform/gp2x/asmutils.s @@ -3,6 +3,7 @@ @ (c) Copyright 2006, notaz @ All Rights Reserved +@ vim:filetype=armasm @ Convert 0000bbb0 ggg0rrr0 0000bbb0 ggg0rrr0 @ to 00000000 rrr00000 ggg00000 bbb00000 ... @@ -197,7 +198,6 @@ vidCpyM2_32col_nobord: b vidCpyM2_32_loop_out -@ test .global spend_cycles @ c spend_cycles: @@ -208,3 +208,12 @@ spend_cycles: bpl .sc_loop bx lr + + +@ test +.global flushcache + +flushcache: + swi #0x9f0002 + mov pc, lr + diff --git a/platform/gp2x/code940/940.c b/platform/gp2x/code940/940.c index 34b42b9..3f7130a 100644 --- a/platform/gp2x/code940/940.c +++ b/platform/gp2x/code940/940.c @@ -57,17 +57,18 @@ static void mp3_decode(void) } -void Main940(int startvector) +void Main940(int startvector, int pc_at_irq) { ym2612_940 = &shared_data->ym2612; mix_buffer = shared_data->mix_buffer; // debug shared_ctl->vstarts[startvector]++; + shared_ctl->last_irq_pc = pc_at_irq; // asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); - for (;;) +// for (;;) { int job_num = 0; /* @@ -77,13 +78,18 @@ void Main940(int startvector) spend_cycles(8*1024); } */ +/* if (!shared_ctl->busy) { wait_irq(); } + shared_ctl->lastbusy = shared_ctl->busy; +*/ for (job_num = 0; job_num < MAX_940JOBS; job_num++) { + shared_ctl->lastjob = (job_num << 8) | shared_ctl->jobs[job_num]; + switch (shared_ctl->jobs[job_num]) { case JOB940_INITALL: @@ -122,7 +128,7 @@ void Main940(int startvector) YM2612Write_(d >> 8, d); } - YM2612UpdateOne_(0, shared_ctl->length, shared_ctl->stereo); + YM2612UpdateOne_(mix_buffer, shared_ctl->length, shared_ctl->stereo, 1); break; } @@ -138,7 +144,10 @@ void Main940(int startvector) // cache_clean_flush(); shared_ctl->loopc++; - shared_ctl->busy = 0; + +// // shared_ctl->busy = 0; // shared mem is not reliable? + + wait_irq(); } } diff --git a/platform/gp2x/code940/940init.s b/platform/gp2x/code940/940init.s index 904ccba..750e0ae 100644 --- a/platform/gp2x/code940/940init.s +++ b/platform/gp2x/code940/940init.s @@ -1,5 +1,7 @@ .global code940 +.equ mmsp2_regs, (0xc0000000-0x02000000) @ assume we live @ 0x2000000 bank + code940: @ interrupt table: b .b_reset @ reset b .b_undef @ undefined instructions @@ -33,7 +35,7 @@ code940: @ interrupt table: mov r12, #6 mov sp, #0x100000 @ reset stack sub sp, sp, #4 - mov r1, #0xbe000000 @ assume we live @ 0x2000000 bank + mov r1, #mmsp2_regs orr r2, r1, #0x3B00 orr r2, r2, #0x0046 mvn r3, #0 @@ -69,7 +71,7 @@ code940: @ interrupt table: @ set up region 3: 64k 0xbe000000-0xbe010000 (hw control registers) mov r0, #(0x0f<<1)|1 - orr r0, r0, #0xbe000000 + orr r0, r0, #mmsp2_regs mcr p15, 0, r0, c6, c3, 0 mcr p15, 0, r0, c6, c3, 1 @@ -88,7 +90,7 @@ code940: @ interrupt table: mov r0, #(1<<1) mcr p15, 0, r0, c3, c0, 0 - @ set protection, allow accsess only to regions 1 and 2 + @ set protection, allow access only to regions 1 and 2 mov r0, #(3<<8)|(3<<6)|(3<<4)|(3<<2)|(0) @ data: [full, full, full, full, no access] for regions [4 3 2 1 0] mcr p15, 0, r0, c5, c0, 0 mov r0, #(0<<8)|(0<<6)|(0<<4)|(3<<2)|(0) @ instructions: [no access, no, no, full, no] @@ -98,9 +100,9 @@ code940: @ interrupt table: orr r0, r0, #1 @ 0x00000001: enable protection unit orr r0, r0, #4 @ 0x00000004: enable D cache orr r0, r0, #0x1000 @ 0x00001000: enable I cache - bic r0, r0, #0xC0000000 - orr r0, r0, #0x40000000 @ 0x40000000: synchronous, faster? -@ orr r0, r0, #0xC0000000 @ 0xC0000000: async +@ bic r0, r0, #0xC0000000 +@ orr r0, r0, #0x40000000 @ 0x40000000: synchronous, faster? + orr r0, r0, #0xC0000000 @ 0xC0000000: async mcr p15, 0, r0, c1, c0, 0 @ set control reg @ flush (invalidate) the cache (just in case) @@ -109,11 +111,13 @@ code940: @ interrupt table: .Enter: mov r0, r12 + mov r1, lr bl Main940 @ we should never get here -.b_deadloop: - b .b_deadloop +@.b_deadloop: +@ b .b_deadloop + b .b_reserved @@ -171,13 +175,25 @@ cf_inner_loop: .global wait_irq wait_irq: + mov r0, #mmsp2_regs + orr r0, r0, #0x3B00 + orr r1, r0, #0x0042 + mov r3, #0 + strh r3, [r1] @ disable interrupts + orr r2, r0, #0x003E + strh r3, [r2] @ remove busy flag + mov r3, #1 + strh r3, [r1] @ enable interrupts + mrs r0, cpsr bic r0, r0, #0x80 - msr cpsr_c, r0 @ enable interrupts + msr cpsr_c, r0 @ enable interrupts mov r0, #0 mcr p15, 0, r0, c7, c0, 4 @ wait for IRQ @ mcr p15, 0, r0, c15, c8, 2 + nop + nop b .b_reserved .pool diff --git a/platform/gp2x/code940/940shared.h b/platform/gp2x/code940/940shared.h index cc5d0c4..c208e67 100644 --- a/platform/gp2x/code940/940shared.h +++ b/platform/gp2x/code940/940shared.h @@ -24,7 +24,7 @@ typedef struct typedef struct { int jobs[MAX_940JOBS]; /* jobs for second core */ - int busy; /* busy status of the 940 core */ + int busy_; /* unused */ int length; /* number of samples to mix (882 max) */ int stereo; /* mix samples as stereo, doubles sample count automatically */ int baseclock; /* ym2612 settings */ @@ -39,4 +39,7 @@ typedef struct int loopc; /* debug: main loop counter */ int mp3_errors; /* debug: mp3 decoder's error counter */ int mp3_lasterr; /* debug: mp3 decoder's last error */ + int last_irq_pc; /* debug: PC value when IRQ happened */ + int lastjob; /* debug: last job id */ + int lastbusy; /* debug: */ } _940_ctl_t; diff --git a/platform/gp2x/code940/Makefile b/platform/gp2x/code940/Makefile index a8322bb..5858381 100644 --- a/platform/gp2x/code940/Makefile +++ b/platform/gp2x/code940/Makefile @@ -11,7 +11,7 @@ CROSS = arm-linux- DEFINC = -I../.. -I. -D__GP2X__ -DARM # -DBENCHMARK COPT_COMMON = -static -s -O3 -ftracer -fstrength-reduce -Wall -funroll-loops -fomit-frame-pointer -fstrict-aliasing -ffast-math -COPT = $(COPT_COMMON) -mtune=arm920t +COPT = $(COPT_COMMON) -mtune=arm940t GCC = $(CROSS)gcc STRIP = $(CROSS)strip AS = $(CROSS)as @@ -20,10 +20,6 @@ OBJCOPY = $(CROSS)objcopy all: code940.bin -up940: - @cp -v code940.bin /mnt/gp2x/mnt/sd/games/PicoDrive/ - -# @cmd //C copy code940.bin \\\\10.0.1.2\\gp2x\\mnt\\sd\\games\\PicoDrive\\ .c.o: @echo $< @@ -36,7 +32,7 @@ up940: # stuff for 940 core # init, emu_control, emu -OBJS940 += 940init.o 940.o 940ym2612.o memcpy.o +OBJS940 += 940init.o 940.o 940ym2612.o memcpy.o mix.o # the asm code seems to be faster when run on 920, but not on 940 for some reason # OBJS940 += ../../Pico/sound/ym2612_asm.o @@ -51,17 +47,21 @@ code940.bin : code940.gpe code940.gpe : $(OBJS940) ../helix/helix_mp3.a @echo $@ - @$(LD) -static -e code940 -Ttext 0x0 $^ -L$(lgcc_path) -lgcc -o $@ + @$(LD) -static -e code940 -Ttext 0x0 $^ -L$(lgcc_path) -lgcc -o $@ -Map code940.map 940ym2612.o : ../../../Pico/sound/ym2612.c @echo $@ - @$(GCC) $(COPT_COMMON) -mtune=arm940t $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@ + @$(GCC) $(COPT) $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@ + +mix.o : ../../../Pico/sound/mix.s + @echo $@ + @$(GCC) $(COPT) $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@ ../helix/helix_mp3.a: @make -C ../helix/ -up: +up: code940.bin @cp -v code940.bin /mnt/gp2x/mnt/sd/games/PicoDrive/ @@ -69,7 +69,7 @@ up: clean: tidy @$(RM) code940.bin tidy: - @$(RM) code940.gpe $(OBJS940) + @$(RM) code940.gpe $(OBJS940) code940.map OBJSMP3T = mp3test.o ../gp2x.o ../asmutils.o ../usbjoy.o diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index 633a780..e564dfb 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -276,6 +276,7 @@ int emu_ReloadRom(void) // bios_help() ? return 0; } else { + if (PicoMCD & 1) PicoExitMCD(); PicoMCD &= ~1; } @@ -374,7 +375,7 @@ int emu_ReloadRom(void) } } gettimeofday(¬iceMsgTime, 0); -printf("PicoMCD: %x\n", PicoMCD); + // load SRAM for this ROM if(currentConfig.EmuOpt & 1) emu_SaveLoadGame(1, 1); @@ -452,8 +453,8 @@ int emu_ReadConfig(int game) // set default config memset(¤tConfig, 0, sizeof(currentConfig)); currentConfig.lastRomFile[0] = 0; - currentConfig.EmuOpt = 0x1f | 0xc00; // | cd_leds | cd_cdda - currentConfig.PicoOpt = 0x0f | 0x200; // | use_940 + currentConfig.EmuOpt = 0x1f | 0x400; // | cd_leds + currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940 | cd_pcm | cd_cdda currentConfig.PsndRate = 44100; currentConfig.PicoRegion = 0; // auto currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP @@ -599,20 +600,20 @@ static void cd_leds(void) // 8-bit modes unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; - *(unsigned int *)((char *)gp2x_screen + 320*2+306) = - *(unsigned int *)((char *)gp2x_screen + 320*3+306) = - *(unsigned int *)((char *)gp2x_screen + 320*4+306) = col_g; - *(unsigned int *)((char *)gp2x_screen + 320*2+312) = - *(unsigned int *)((char *)gp2x_screen + 320*3+312) = - *(unsigned int *)((char *)gp2x_screen + 320*4+312) = col_r; + *(unsigned int *)((char *)gp2x_screen + 320*2+ 4) = + *(unsigned int *)((char *)gp2x_screen + 320*3+ 4) = + *(unsigned int *)((char *)gp2x_screen + 320*4+ 4) = col_g; + *(unsigned int *)((char *)gp2x_screen + 320*2+12) = + *(unsigned int *)((char *)gp2x_screen + 320*3+12) = + *(unsigned int *)((char *)gp2x_screen + 320*4+12) = col_r; } else { // 16-bit modes - unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+306); + unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+4); unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0; unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0; - *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; - *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; - *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 320/2 - 12/2; } } diff --git a/platform/gp2x/emu.h b/platform/gp2x/emu.h index e5a7f30..674929b 100644 --- a/platform/gp2x/emu.h +++ b/platform/gp2x/emu.h @@ -19,8 +19,8 @@ typedef struct { char lastRomFile[512]; int EmuOpt; // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves, // squidgehack, save_cfg_on_exit, , 16_bit_mode - // craigix_ram, confirm_save, show_cd_leds, enable_cdda - // enable_pcm + // craigix_ram, confirm_save, show_cd_leds + // int PicoOpt; // used for config saving only, see Pico.h int PsndRate; // ditto int PicoRegion; // ditto diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index 16c9ab5..2433742 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -574,7 +574,8 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j gp2x_text_out8(tl_x, (y+=10), "EUR BIOS: %s", b_eu); // 1 gp2x_text_out8(tl_x, (y+=10), "JAP BIOS: %s", b_jp); // 2 gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x400)?"ON":"OFF"); // 3 - gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.EmuOpt &0x800)?"ON":"OFF"); // 4 + gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.PicoOpt&0x800)?"ON":"OFF"); // 4 + gp2x_text_out8(tl_x, (y+=10), "PCM audio %s", (currentConfig.PicoOpt&0x400)?"ON":"OFF"); // 5 gp2x_text_out8(tl_x, (y+=10), "Done"); // draw cursor @@ -590,7 +591,7 @@ static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_j static void cd_menu_loop_options(void) { - int menu_sel = 0, menu_sel_max = 5; + int menu_sel = 0, menu_sel_max = 6; unsigned long inp = 0; char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p; @@ -618,8 +619,9 @@ static void cd_menu_loop_options(void) if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options switch (menu_sel) { case 3: currentConfig.EmuOpt ^=0x400; break; - case 4: currentConfig.EmuOpt ^=0x800; break; - case 5: return; + case 4: currentConfig.PicoOpt^=0x800; break; + case 5: currentConfig.PicoOpt^=0x400; break; + case 6: return; } } if(inp & (GP2X_X|GP2X_A)) return; diff --git a/platform/linux/940ctl_ym2612.c b/platform/linux/940ctl_ym2612.c index 2cfa57b..915ac0a 100644 --- a/platform/linux/940ctl_ym2612.c +++ b/platform/linux/940ctl_ym2612.c @@ -20,8 +20,6 @@ static YM2612 ym2612; YM2612 *ym2612_940 = &ym2612; -int mix_buffer_[44100/50*2]; /* this is where the YM2612 samples will be mixed to */ -int *mix_buffer = mix_buffer_; // static _940_data_t shared_data_; static _940_ctl_t shared_ctl_; @@ -96,58 +94,6 @@ void YM2612ResetChip_940(void) } -static void mix_samples(short *dest_buf, int *ym_buf, short *mp3_buf, int len, int stereo) -{ - if (mp3_buf) - { - if (stereo) - { - for (; len > 0; len--) - { - int l, r; - l = r = *dest_buf; - l += *ym_buf++; r += *ym_buf++; - l += *mp3_buf++; r += *mp3_buf++; - Limit( l, MAXOUT, MINOUT ); - Limit( r, MAXOUT, MINOUT ); - *dest_buf++ = l; *dest_buf++ = r; - } - } else { - for (; len > 0; len--) - { - int l = *ym_buf++; - l += *dest_buf; - l += *mp3_buf++; - Limit( l, MAXOUT, MINOUT ); - *dest_buf++ = l; - } - } - } - else - { - if (stereo) - { - for (; len > 0; len--) - { - int l, r; - l = r = *dest_buf; - l += *ym_buf++, r += *ym_buf++; - Limit( l, MAXOUT, MINOUT ); - Limit( r, MAXOUT, MINOUT ); - *dest_buf++ = l; *dest_buf++ = r; - } - } else { - for (; len > 0; len--) - { - int l = *ym_buf++; - l += *dest_buf; - Limit( l, MAXOUT, MINOUT ); - *dest_buf++ = l; - } - } - } -} - #if 0 static void local_decode(void) { @@ -190,7 +136,7 @@ static void local_decode(void) static FILE *loaded_mp3 = 0; -void YM2612UpdateOne_940(short *buffer, int length, int stereo) +int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty) { #if 0 int cdda_on, *ym_buffer = mix_buffer; @@ -233,9 +179,7 @@ void YM2612UpdateOne_940(short *buffer, int length, int stereo) mp3_samples_ready += 1152; } #else - YM2612UpdateOne_(buffer, length, stereo); // really writes to mix_buffer - - mix_samples(buffer, mix_buffer, 0, length, stereo); + return YM2612UpdateOne_(buffer, length, stereo, is_buf_empty); #endif } diff --git a/platform/linux/Makefile b/platform/linux/Makefile index e8d740e..b5f7133 100644 --- a/platform/linux/Makefile +++ b/platform/linux/Makefile @@ -31,9 +31,9 @@ OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory # Pico - CD OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \ ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o ../../Pico/cd/gfx_cd.o \ - ../../Pico/cd/Area.o ../../Pico/cd/Misc.o + ../../Pico/cd/Area.o ../../Pico/cd/Misc.o ../../Pico/cd/pcm.o # Pico - sound -OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o +OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o ../../Pico/sound/mix.o # zlib OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/inftrees.o ../../zlib/trees.o \ ../../zlib/deflate.o ../../zlib/crc32.o ../../zlib/adler32.o ../../zlib/zutil.o ../../zlib/compress.o -- 2.39.2