IO initial states are correct
This commit is contained in:
15
include/serial.h
Normal file
15
include/serial.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <common.h>
|
||||
|
||||
typedef struct {
|
||||
u8 serial_data;
|
||||
u8 serial_control;
|
||||
} serial_context;
|
||||
|
||||
serial_context *serial_get_context();
|
||||
|
||||
void serial_init();
|
||||
|
||||
void serial_write(u16 address, u8 value);
|
||||
u8 serial_read(u16 address);
|
33
lib/audio.c
33
lib/audio.c
@ -85,33 +85,34 @@ void audio_init(){
|
||||
memset(ctx.left_audio_buffer, 0, sizeof(float) * FRAMES_PER_BUFFER);
|
||||
memset(ctx.right_audio_buffer, 0, sizeof(float) * FRAMES_PER_BUFFER);
|
||||
|
||||
ctx.audio_enabled = false;
|
||||
ctx.ch1_left = false;
|
||||
ctx.ch1_right = false;
|
||||
ctx.ch2_left = false;
|
||||
ctx.ch2_right = false;
|
||||
ctx.ch3_left = false;
|
||||
ctx.audio_enabled = true;
|
||||
ctx.ch1_left = true;
|
||||
ctx.ch1_right = true;
|
||||
ctx.ch2_left = true;
|
||||
ctx.ch2_right = true;
|
||||
ctx.ch3_left = true;
|
||||
ctx.ch3_right = false;
|
||||
ctx.ch4_left = false;
|
||||
ctx.ch4_left = true;
|
||||
ctx.ch4_right = false;
|
||||
|
||||
ctx.volume_left = 0x1;
|
||||
ctx.volume_right = 0x1;
|
||||
ctx.volume_left = 0x7;
|
||||
ctx.volume_right = 0x7;
|
||||
|
||||
ctx.sq1_duty = 0x0;
|
||||
ctx.sq1_volume = 0x0;
|
||||
ctx.sq1_duty = 0x2;
|
||||
ctx.sq1_volume = 0xF;
|
||||
ctx.sq1_sample = 0x0;
|
||||
ctx.sq1_period_reset = 0x0;
|
||||
ctx.sq1_period_timer = 0x0;
|
||||
ctx.sq1_enable = false;
|
||||
ctx.sq1_enable = true;
|
||||
ctx.sq1_len_enable = false;
|
||||
ctx.sq1_sweep_pace = 0x0;
|
||||
ctx.sq1_sweep_direction = false;
|
||||
ctx.sq1_initial_len = 0x0;
|
||||
ctx.sq1_initial_len = 0x3F;
|
||||
ctx.sq1_len = 0x0;
|
||||
ctx.sq1_initial_volume = 0x0;
|
||||
ctx.sq1_initial_volume = 0xF;
|
||||
ctx.sq1_env_direction = false;
|
||||
ctx.sq1_env_pace = 0x0;
|
||||
ctx.sq1_env_pace = 0x3;
|
||||
ctx.sq1_env_pace_buffer = 0x3;
|
||||
ctx.sq1_env_timer = 0x0;
|
||||
ctx.sq1_sweep_step = 0x0;
|
||||
|
||||
@ -122,7 +123,7 @@ void audio_init(){
|
||||
ctx.sq2_period_timer = 0x0;
|
||||
ctx.sq2_enable = false;
|
||||
ctx.sq2_len_enable = false;
|
||||
ctx.sq2_initial_len = 0x0;
|
||||
ctx.sq2_initial_len = 0x3F;
|
||||
ctx.sq2_len = 0x0;
|
||||
ctx.sq2_initial_volume = 0x0;
|
||||
ctx.sq2_env_direction = false;
|
||||
|
@ -28,7 +28,7 @@ void cpu_init() {
|
||||
ctx.regs.sp = 0xFFFE;
|
||||
ctx.regs.pc = 0x100;
|
||||
ctx.ie_register = 0;
|
||||
ctx.int_flags = 0;
|
||||
ctx.int_flags = 0xE1;
|
||||
ctx.int_master_enabled = false;
|
||||
ctx.enabling_ime = false;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <audio.h>
|
||||
#include <cart.h>
|
||||
#include <debug.h>
|
||||
#include <serial.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@ -69,6 +70,7 @@ void emu_reset() {
|
||||
cpu_init();
|
||||
audio_init();
|
||||
cart_init();
|
||||
serial_init();
|
||||
}
|
||||
|
||||
void emu_start() {
|
||||
|
21
lib/io.c
21
lib/io.c
@ -5,19 +5,14 @@
|
||||
#include <lcd.h>
|
||||
#include <gamepad.h>
|
||||
#include <audio.h>
|
||||
|
||||
static char serial_data[2];
|
||||
#include <serial.h>
|
||||
|
||||
u8 io_read(u16 address){
|
||||
if(address == 0xFF00) {
|
||||
return gamepad_get_output();
|
||||
}
|
||||
if(address == 0xFF01) {
|
||||
return serial_data[0];
|
||||
}
|
||||
|
||||
if(address == 0xFF02) {
|
||||
return serial_data[1];
|
||||
if(address == 0xFF01 || address == 0xFF02) {
|
||||
return serial_read(address);
|
||||
}
|
||||
|
||||
if(BETWEEN(address, 0xFF04, 0xFF07)){
|
||||
@ -46,14 +41,8 @@ void io_write(u16 address, u8 value){
|
||||
gamepad_set_sel(value);
|
||||
return;
|
||||
}
|
||||
if(address == 0xFF01) {
|
||||
serial_data[0] = value;
|
||||
//printf("%c", value);
|
||||
return;
|
||||
}
|
||||
|
||||
if(address == 0xFF02) {
|
||||
serial_data[1] = value;
|
||||
if(address == 0xFF01 || address == 0xFF02) {
|
||||
serial_write(address, value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ void lcd_init() {
|
||||
ctx.obj_palette[1] = 0xFF;
|
||||
ctx.win_x = 0;
|
||||
ctx.win_y = 0;
|
||||
ctx.lcds = 0x80;
|
||||
|
||||
for(int i = 0; i < 4; i++) {
|
||||
ctx.bg_colors[i] = colors_default[i];
|
||||
|
34
lib/serial.c
Normal file
34
lib/serial.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <serial.h>
|
||||
|
||||
static serial_context ctx;
|
||||
|
||||
serial_context *serial_get_context() {
|
||||
return &ctx;
|
||||
};
|
||||
|
||||
void serial_init() {
|
||||
ctx.serial_control = 0x7E;
|
||||
ctx.serial_data = 0;
|
||||
}
|
||||
|
||||
void serial_write(u16 address, u8 value) {
|
||||
if(address == 0xFF01) {
|
||||
ctx.serial_data = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if(address == 0xFF02) {
|
||||
ctx.serial_control = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
u8 serial_read(u16 address) {
|
||||
if(address == 0xFF01) {
|
||||
return ctx.serial_data;
|
||||
}
|
||||
|
||||
if(address == 0xFF02) {
|
||||
return ctx.serial_control;
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ void inc_tima() {
|
||||
|
||||
void timer_init() {
|
||||
ctx.div = 0XAC00;
|
||||
ctx.tac = 0xF8;
|
||||
}
|
||||
|
||||
void timer_tick() {
|
||||
|
Reference in New Issue
Block a user