mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-06 15:48:05 -04:00
PCM sound, refactored code940
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@27 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
7573607016
commit
4f265db776
28 changed files with 914 additions and 312 deletions
|
@ -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;
|
||||
|
|
106
Pico/cd/Memory.c
106
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue