This commit is contained in:
Samuel Walker 2025-02-16 10:33:06 -07:00
parent 97de875bf2
commit 5934e2e877
Signed by: piwalker
GPG Key ID: 616B1928705EA4C9
3 changed files with 35 additions and 17 deletions

View File

@ -413,8 +413,9 @@ void audio_tick(){
} }
} }
if(ctx.ch4_len_enable) { if(ctx.ch4_len_enable && ctx.ch4_enable) {
ctx.ch4_len++; ctx.ch4_len++;
printf("Ch4 env: %02X\n", ctx.ch4_len);
if(ctx.ch4_len >= 64) { if(ctx.ch4_len >= 64) {
ctx.ch4_len = 0; ctx.ch4_len = 0;
ctx.ch4_enable = false; ctx.ch4_enable = false;
@ -926,6 +927,7 @@ void audio_write(u16 address, u8 value){
ctx.ch4_initial_len = value & 0b111111; ctx.ch4_initial_len = value & 0b111111;
ctx.ch4_len = ctx.ch4_initial_len; ctx.ch4_len = ctx.ch4_initial_len;
ctx.ch4_len_fz = false; ctx.ch4_len_fz = false;
printf("ch4 len: %02X\n", ctx.ch4_len);
} }
if(address == 0xFF21) { if(address == 0xFF21) {
@ -969,6 +971,7 @@ void audio_write(u16 address, u8 value){
} }
} }
ctx.ch4_len_enable = len_en; ctx.ch4_len_enable = len_en;
printf("ch4 trigger: LenEn %d\n", len_en);
if(value & 0x80) { if(value & 0x80) {
enable_noise(); enable_noise();
} }

View File

@ -36,8 +36,16 @@ bool cart_mbc1() {
return BETWEEN(ctx.header->type, 1, 3); return BETWEEN(ctx.header->type, 1, 3);
} }
bool cart_mbc3() {
return BETWEEN(ctx.header->type, 15, 19);
}
bool cart_mbc() {
return cart_mbc1() || cart_mbc3();
}
bool cart_battery() { bool cart_battery() {
return ctx.header->type == 3; return ctx.header->type == 3 || BETWEEN(ctx.header->type, 15, 16) || ctx.header->type == 19;
} }
static const char *ROM_TYPES[] = { static const char *ROM_TYPES[] = {
@ -232,7 +240,7 @@ bool cart_load(char *cart) {
} }
u8 cart_read(u16 address){ u8 cart_read(u16 address){
if(!cart_mbc1() || address < 0x4000) { if(!cart_mbc() || address < 0x4000) {
return ctx.rom_data[address]; return ctx.rom_data[address];
} }
@ -253,7 +261,8 @@ u8 cart_read(u16 address){
} }
void cart_write(u16 address, u8 value){ void cart_write(u16 address, u8 value){
if(!cart_mbc1()) { //printf("Cart Write: %04X\n", address);
if(!cart_mbc()) {
return; return;
} }
@ -266,10 +275,15 @@ void cart_write(u16 address, u8 value){
if(value == 0) { if(value == 0) {
value = 1; value = 1;
} }
if(cart_mbc3()) {
value &= 0b11111; value &= 0b1111111;
ctx.rom_bank_value = value; ctx.rom_bank_value = value;
ctx.rom_bank_x = ctx.rom_data + (0x4000 * ctx.rom_bank_value); ctx.rom_bank_x = ctx.rom_data + (0x4000 * ctx.rom_bank_value);
}else {
value &= 0b11111;
ctx.rom_bank_value = value;
ctx.rom_bank_x = ctx.rom_data + (0x4000 * ctx.rom_bank_value);
}
} }
if((address & 0xE000) == 0x4000) { if((address & 0xE000) == 0x4000) {
@ -284,17 +298,18 @@ void cart_write(u16 address, u8 value){
} }
if((address & 0xE000) == 0x6000) { if((address & 0xE000) == 0x6000) {
//bamking mode select //banking mode select
if(cart_mbc1()){
ctx.banking_mode = value & 1;
ctx.banking_mode = value & 1; ctx.ram_banking = ctx.banking_mode;
ctx.ram_banking = ctx.banking_mode; if (ctx.ram_banking) {
if(cart_need_save) {
if (ctx.ram_banking) { cart_battery_save();
if(cart_need_save) { }
cart_battery_save(); ctx.ram_bank = ctx.ram_banks[ctx.ram_bank_value];
} }
ctx.ram_bank = ctx.ram_banks[ctx.ram_bank_value];
} }
} }

View File

@ -39,7 +39,7 @@ void timer_tick() {
} }
} }
if((prev_div & (1 << 12)) && (!(ctx.div & (1 << 12)))){ if((prev_div & (1 << 13)) && (!(ctx.div & (1 << 13)))){
audio_tick(); audio_tick();
} }