initial MMC5 bring-up
This commit is contained in:
parent
280cbb3e39
commit
2da96a7e76
9 changed files with 707 additions and 11 deletions
|
|
@ -21,6 +21,8 @@
|
|||
#include <string.h>
|
||||
#include "apu.h"
|
||||
|
||||
struct _nla_table nla_table;
|
||||
|
||||
void apu_tick(struct NESAPU* a, BYTE *hwtick) {
|
||||
/* sottraggo il numero di cicli eseguiti */
|
||||
a->apu.cycles--;
|
||||
|
|
@ -177,8 +179,8 @@ void apu_tick(struct NESAPU* a, BYTE *hwtick) {
|
|||
* eseguo un ticket per ogni canale
|
||||
* valorizzandone l'output.
|
||||
*/
|
||||
square_tick(a->S1, 0, a->apu)
|
||||
square_tick(a->S2, 0, a->apu)
|
||||
square_tick(a->S1, 0, a->apu.clocked)
|
||||
square_tick(a->S2, 0, a->apu.clocked)
|
||||
triangle_tick()
|
||||
noise_tick()
|
||||
dmc_tick()
|
||||
|
|
|
|||
|
|
@ -137,12 +137,12 @@ enum apu_mode { APU_60HZ, APU_48HZ };
|
|||
#define dmc_output()\
|
||||
a->DMC.output = a->DMC.counter & 0x7F
|
||||
/* tick */
|
||||
#define square_tick(square, swap, type)\
|
||||
#define square_tick(square, swap, type_clocked)\
|
||||
if (!(--square.frequency)) {\
|
||||
square_output(square, swap)\
|
||||
square.frequency = (square.timer + 1) << 1;\
|
||||
square.sequencer = (square.sequencer + 1) & 0x07;\
|
||||
type.clocked = TRUE;\
|
||||
type_clocked = TRUE;\
|
||||
}
|
||||
#define triangle_tick()\
|
||||
if (!(--a->TR.frequency)) {\
|
||||
|
|
@ -302,7 +302,7 @@ enum apu_mode { APU_60HZ, APU_48HZ };
|
|||
#define square_reg2(square)\
|
||||
/* timer (low 8 bits) */\
|
||||
square.timer = (square.timer & 0x0700) | value
|
||||
#define square_reg3(square)\
|
||||
#define square_reg3(square,length_clocked)\
|
||||
/* length counter */\
|
||||
/*\
|
||||
* se non disabilitato, una scrittura in\
|
||||
|
|
@ -312,7 +312,7 @@ enum apu_mode { APU_60HZ, APU_48HZ };
|
|||
* momento del clock di un length counter e\
|
||||
* con il length diverso da zero.\
|
||||
*/\
|
||||
if (square.length.enabled && !(a->apu.length_clocked && square.length.value)) {\
|
||||
if (square.length.enabled && !(length_clocked && square.length.value)) {\
|
||||
square.length.value = length_table[value >> 3];\
|
||||
}\
|
||||
/* envelope */\
|
||||
|
|
@ -510,9 +510,11 @@ typedef struct _apuDMC {
|
|||
#endif
|
||||
|
||||
EXTERNC struct _nla_table {
|
||||
SWORD pulse[32];
|
||||
SWORD tnd[203];
|
||||
} nla_table;
|
||||
SWORD pulse[32];
|
||||
SWORD tnd[203];
|
||||
};
|
||||
|
||||
extern struct _nla_table nla_table;
|
||||
|
||||
EXTERNC struct NESAPU {
|
||||
_apu apu;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ INLINE static void apu_wr_reg(struct NESAPU* a, WORD address, BYTE value) {
|
|||
return;
|
||||
}
|
||||
if (address == 0x4003) {
|
||||
square_reg3(a->S1);
|
||||
square_reg3(a->S1,a->apu.length_clocked);
|
||||
sweep_silence(a->S1)
|
||||
return;
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ INLINE static void apu_wr_reg(struct NESAPU* a, WORD address, BYTE value) {
|
|||
return;
|
||||
}
|
||||
if (address == 0x4007) {
|
||||
square_reg3(a->S2);
|
||||
square_reg3(a->S2,a->apu.length_clocked);
|
||||
sweep_silence(a->S2)
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
107
src/engine/platform/sound/nes/mmc5.c
Normal file
107
src/engine/platform/sound/nes/mmc5.c
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "apu.h"
|
||||
#include "mmc5.h"
|
||||
|
||||
enum { MODE0, MODE1, MODE2, MODE3 };
|
||||
enum { CHR_S, CHR_B };
|
||||
enum { SPLIT_LEFT, SPLIT_RIGHT = 0x40 };
|
||||
|
||||
const BYTE filler_attrib[4] = {0x00, 0x55, 0xAA, 0xFF};
|
||||
BYTE prg_ram_mode;
|
||||
|
||||
void map_init_MMC5(struct _mmc5* mmc5) {
|
||||
memset(mmc5,0,sizeof(struct _mmc5));
|
||||
|
||||
mmc5->S3.frequency = 1;
|
||||
mmc5->S4.frequency = 1;
|
||||
mmc5->S3.length.enabled = 0;
|
||||
mmc5->S3.length.value = 0;
|
||||
mmc5->S4.length.enabled = 0;
|
||||
mmc5->S4.length.value = 0;
|
||||
}
|
||||
void extcl_cpu_wr_mem_MMC5(struct _mmc5* mmc5, WORD address, BYTE value) {
|
||||
if (address < 0x5000) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (address) {
|
||||
case 0x5000:
|
||||
square_reg0(mmc5->S3);
|
||||
return;
|
||||
case 0x5001:
|
||||
/* lo sweep non e' utilizzato */
|
||||
return;
|
||||
case 0x5002:
|
||||
square_reg2(mmc5->S3);
|
||||
return;
|
||||
case 0x5003:
|
||||
square_reg3(mmc5->S3,0);
|
||||
return;
|
||||
case 0x5004:
|
||||
square_reg0(mmc5->S4);
|
||||
return;
|
||||
case 0x5005:
|
||||
/* lo sweep non e' utilizzato */
|
||||
return;
|
||||
case 0x5006:
|
||||
square_reg2(mmc5->S4);
|
||||
return;
|
||||
case 0x5007:
|
||||
square_reg3(mmc5->S4,0);
|
||||
return;
|
||||
case 0x5010:
|
||||
mmc5->pcm.enabled = ~value & 0x01;
|
||||
mmc5->pcm.output = 0;
|
||||
if (mmc5->pcm.enabled) {
|
||||
mmc5->pcm.output = mmc5->pcm.amp;
|
||||
}
|
||||
mmc5->clocked = TRUE;
|
||||
return;
|
||||
case 0x5011:
|
||||
mmc5->pcm.amp = value;
|
||||
mmc5->pcm.output = 0;
|
||||
if (mmc5->pcm.enabled) {
|
||||
mmc5->pcm.output = mmc5->pcm.amp;
|
||||
}
|
||||
mmc5->clocked = TRUE;
|
||||
return;
|
||||
case 0x5015:
|
||||
if (!(mmc5->S3.length.enabled = value & 0x01)) {
|
||||
mmc5->S3.length.value = 0;
|
||||
}
|
||||
if (!(mmc5->S4.length.enabled = value & 0x02)) {
|
||||
mmc5->S4.length.value = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
void extcl_length_clock_MMC5(struct _mmc5* mmc5) {
|
||||
length_run(mmc5->S3)
|
||||
length_run(mmc5->S4)
|
||||
}
|
||||
void extcl_envelope_clock_MMC5(struct _mmc5* mmc5) {
|
||||
envelope_run(mmc5->S3)
|
||||
envelope_run(mmc5->S4)
|
||||
}
|
||||
void extcl_apu_tick_MMC5(struct _mmc5* mmc5) {
|
||||
square_tick(mmc5->S3, 0, mmc5->clocked)
|
||||
square_tick(mmc5->S4, 0, mmc5->clocked)
|
||||
}
|
||||
80
src/engine/platform/sound/nes/mmc5.h
Normal file
80
src/engine/platform/sound/nes/mmc5.h
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef MAPPER_MMC5_H_
|
||||
#define MAPPER_MMC5_H_
|
||||
|
||||
#include "apu.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
#define EXTERNC extern "C"
|
||||
#else
|
||||
#define EXTERNC
|
||||
#endif
|
||||
|
||||
EXTERNC struct _mmc5 {
|
||||
BYTE prg_mode;
|
||||
BYTE chr_mode;
|
||||
BYTE ext_mode;
|
||||
BYTE nmt_mode[4];
|
||||
BYTE prg_ram_write[2];
|
||||
BYTE prg_bank[4];
|
||||
uint32_t prg_ram_bank[4][2];
|
||||
BYTE chr_last;
|
||||
WORD chr_high;
|
||||
WORD chr_s[8];
|
||||
WORD chr_b[4];
|
||||
BYTE ext_ram[0x400];
|
||||
BYTE fill_table[0x400];
|
||||
BYTE fill_tile;
|
||||
BYTE fill_attr;
|
||||
BYTE split;
|
||||
BYTE split_st_tile;
|
||||
BYTE split_side;
|
||||
BYTE split_scrl;
|
||||
BYTE split_in_reg;
|
||||
BYTE split_x;
|
||||
BYTE split_y;
|
||||
WORD split_tile;
|
||||
uint32_t split_bank;
|
||||
BYTE factor[2];
|
||||
WORD product;
|
||||
_apuSquare S3, S4;
|
||||
struct _mmc5_pcm {
|
||||
BYTE enabled;
|
||||
BYTE output;
|
||||
BYTE amp;
|
||||
} pcm;
|
||||
BYTE filler[50];
|
||||
|
||||
/* ------------------------------------------------------- */
|
||||
/* questi valori non e' necessario salvarli nei savestates */
|
||||
/* ------------------------------------------------------- */
|
||||
/* */ BYTE clocked; /* */
|
||||
/* ------------------------------------------------------- */
|
||||
};
|
||||
|
||||
EXTERNC void map_init_MMC5(struct _mmc5* mmc5);
|
||||
EXTERNC void extcl_cpu_wr_mem_MMC5(struct _mmc5* mmc5, WORD address, BYTE value);
|
||||
EXTERNC void extcl_length_clock_MMC5(struct _mmc5* mmc5);
|
||||
EXTERNC void extcl_envelope_clock_MMC5(struct _mmc5* mmc5);
|
||||
EXTERNC void extcl_apu_tick_MMC5(struct _mmc5* mmc5);
|
||||
|
||||
#undef EXTERNC
|
||||
|
||||
#endif /* MAPPER_MMC5_H_ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue