mbc 3
This commit is contained in:
parent
97de875bf2
commit
5934e2e877
@ -413,8 +413,9 @@ void audio_tick(){
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx.ch4_len_enable) {
|
||||
if(ctx.ch4_len_enable && ctx.ch4_enable) {
|
||||
ctx.ch4_len++;
|
||||
printf("Ch4 env: %02X\n", ctx.ch4_len);
|
||||
if(ctx.ch4_len >= 64) {
|
||||
ctx.ch4_len = 0;
|
||||
ctx.ch4_enable = false;
|
||||
@ -926,6 +927,7 @@ void audio_write(u16 address, u8 value){
|
||||
ctx.ch4_initial_len = value & 0b111111;
|
||||
ctx.ch4_len = ctx.ch4_initial_len;
|
||||
ctx.ch4_len_fz = false;
|
||||
printf("ch4 len: %02X\n", ctx.ch4_len);
|
||||
}
|
||||
|
||||
if(address == 0xFF21) {
|
||||
@ -969,6 +971,7 @@ void audio_write(u16 address, u8 value){
|
||||
}
|
||||
}
|
||||
ctx.ch4_len_enable = len_en;
|
||||
printf("ch4 trigger: LenEn %d\n", len_en);
|
||||
if(value & 0x80) {
|
||||
enable_noise();
|
||||
}
|
||||
|
27
lib/cart.c
27
lib/cart.c
@ -36,8 +36,16 @@ bool cart_mbc1() {
|
||||
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() {
|
||||
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[] = {
|
||||
@ -232,7 +240,7 @@ bool cart_load(char *cart) {
|
||||
}
|
||||
|
||||
u8 cart_read(u16 address){
|
||||
if(!cart_mbc1() || address < 0x4000) {
|
||||
if(!cart_mbc() || address < 0x4000) {
|
||||
return ctx.rom_data[address];
|
||||
}
|
||||
|
||||
@ -253,7 +261,8 @@ u8 cart_read(u16 address){
|
||||
}
|
||||
|
||||
void cart_write(u16 address, u8 value){
|
||||
if(!cart_mbc1()) {
|
||||
//printf("Cart Write: %04X\n", address);
|
||||
if(!cart_mbc()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -266,11 +275,16 @@ void cart_write(u16 address, u8 value){
|
||||
if(value == 0) {
|
||||
value = 1;
|
||||
}
|
||||
|
||||
if(cart_mbc3()) {
|
||||
value &= 0b1111111;
|
||||
ctx.rom_bank_value = 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) {
|
||||
//ram bank number
|
||||
@ -284,8 +298,8 @@ void cart_write(u16 address, u8 value){
|
||||
}
|
||||
|
||||
if((address & 0xE000) == 0x6000) {
|
||||
//bamking mode select
|
||||
|
||||
//banking mode select
|
||||
if(cart_mbc1()){
|
||||
ctx.banking_mode = value & 1;
|
||||
|
||||
ctx.ram_banking = ctx.banking_mode;
|
||||
@ -297,6 +311,7 @@ void cart_write(u16 address, u8 value){
|
||||
ctx.ram_bank = ctx.ram_banks[ctx.ram_bank_value];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((address & 0xE000) == 0xA000) {
|
||||
if(!ctx.ram_enabled)
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user