Skip to content
Snippets Groups Projects
Verified Commit 823fa0a2 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: add new constants for ADDR values

Also made some initial timer validation.
parent f15167e6
No related branches found
No related tags found
1 merge request!41Support for address based testing
// Timer registers
pub const DIV_ADDR: u16 = 0xff04;
pub const TIMA_ADDR: u16 = 0xff05;
pub const TMA_ADDR: u16 = 0xff06;
pub const TAC_ADDR: u16 = 0xff07;
......@@ -2,6 +2,7 @@
pub mod apu;
pub mod cheats;
pub mod consts;
pub mod cpu;
pub mod data;
pub mod devices;
......
......@@ -65,11 +65,13 @@ pub fn run_image_test(
#[cfg(test)]
mod tests {
use crate::consts::{DIV_ADDR, TAC_ADDR, TIMA_ADDR, TMA_ADDR};
use super::{run_serial_test, run_step_test, TestOptions};
#[test]
fn test_boot_state() {
let result = run_step_test(
let mut result = run_step_test(
"res/roms/test/blargg/cpu/cpu_instrs.gb",
0x0100,
TestOptions::default(),
......@@ -81,6 +83,11 @@ mod tests {
assert_eq!(result.cpu_i().de(), 0x00d8);
assert_eq!(result.cpu_i().hl(), 0x014d);
assert_eq!(result.cpu_i().ime(), false);
assert_eq!(result.mmu().read(DIV_ADDR), 0xab);
assert_eq!(result.mmu().read(TIMA_ADDR), 0x00);
assert_eq!(result.mmu().read(TMA_ADDR), 0x00);
assert_eq!(result.mmu().read(TAC_ADDR), 0xf8);
}
#[test]
......
use crate::warnln;
use crate::{
consts::{DIV_ADDR, TAC_ADDR, TIMA_ADDR, TMA_ADDR},
warnln,
};
pub struct Timer {
div: u8,
......@@ -70,13 +73,13 @@ impl Timer {
pub fn read(&mut self, addr: u16) -> u8 {
match addr {
// 0xFF04 — DIV: Divider register
0xff04 => self.div,
DIV_ADDR => self.div,
// 0xFF05 — TIMA: Timer counter
0xff05 => self.tima,
TIMA_ADDR => self.tima,
// 0xFF06 — TMA: Timer modulo
0xff06 => self.tma,
TMA_ADDR => self.tma,
// 0xFF07 — TAC: Timer control
0xff07 => self.tac,
TAC_ADDR => self.tac | 0xf8,
_ => {
warnln!("Reding from unknown Timer location 0x{:04x}", addr);
0xff
......@@ -87,13 +90,13 @@ impl Timer {
pub fn write(&mut self, addr: u16, value: u8) {
match addr {
// 0xFF04 — DIV: Divider register
0xff04 => self.div = 0,
DIV_ADDR => self.div = 0,
// 0xFF05 — TIMA: Timer counter
0xff05 => self.tima = value,
TIMA_ADDR => self.tima = value,
// 0xFF06 — TMA: Timer modulo
0xff06 => self.tma = value,
TMA_ADDR => self.tma = value,
// 0xFF07 — TAC: Timer control
0xff07 => {
TAC_ADDR => {
self.tac = value;
match value & 0x03 {
0x00 => self.tima_ratio = 1024,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment