splitting and pub using

This commit is contained in:
Alex Janka 2023-02-13 12:42:38 +11:00
parent 04fcb000a1
commit 8a04f5e507
4 changed files with 82 additions and 77 deletions

View file

@ -7,7 +7,7 @@ use clap::{ArgGroup, Parser};
use gilrs::Gilrs; use gilrs::Gilrs;
use minifb::{Window, WindowOptions}; use minifb::{Window, WindowOptions};
use processor::{ use processor::{
memory::{rom::Rom, Memory}, memory::{Memory, Rom},
Cpu, Cpu,
}; };
use std::{ use std::{

View file

@ -1,90 +1,18 @@
use self::rom::Rom; use self::mmio::{Joypad, JoypadBank};
pub use self::rom::Rom;
use crate::{ use crate::{
processor::{clear_bit, get_bit, SplitRegister}, processor::{get_bit, SplitRegister},
verbose_println, verbose_println,
}; };
use gilrs::{Button, ConnectedGamepadsIterator}; use gilrs::{Button, ConnectedGamepadsIterator};
use minifb::Key; use minifb::Key;
use std::io::{stdout, Write}; use std::io::{stdout, Write};
mod mmio;
pub(crate) mod rom; pub(crate) mod rom;
pub(crate) type Address = u16; pub(crate) type Address = u16;
#[derive(Debug, Clone, Copy, PartialEq)]
enum JoypadBank {
Action,
Direction,
}
#[derive(Debug, Clone, Copy, PartialEq)]
struct Joypad {
bank_sel: JoypadBank,
down: bool,
up: bool,
left: bool,
right: bool,
start: bool,
select: bool,
b: bool,
a: bool,
}
impl Joypad {
fn as_register(&self) -> u8 {
let mut reg = 0xFF;
match self.bank_sel {
JoypadBank::Action => {
reg = clear_bit(reg, 5);
if self.start {
reg = clear_bit(reg, 3);
}
if self.select {
reg = clear_bit(reg, 2);
}
if self.b {
reg = clear_bit(reg, 1);
}
if self.a {
reg = clear_bit(reg, 0);
}
}
JoypadBank::Direction => {
reg = clear_bit(reg, 4);
if self.down {
reg = clear_bit(reg, 3);
}
if self.up {
reg = clear_bit(reg, 2);
}
if self.left {
reg = clear_bit(reg, 1);
}
if self.right {
reg = clear_bit(reg, 0);
}
}
}
reg
}
}
impl Default for Joypad {
fn default() -> Self {
Self {
bank_sel: JoypadBank::Action,
down: false,
up: false,
left: false,
right: false,
start: false,
select: false,
b: false,
a: false,
}
}
}
#[allow(dead_code)] #[allow(dead_code)]
pub struct Memory { pub struct Memory {
bootrom: Vec<u8>, bootrom: Vec<u8>,

View file

@ -0,0 +1,75 @@
use crate::util::clear_bit;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum JoypadBank {
Action,
Direction,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Joypad {
pub bank_sel: JoypadBank,
pub down: bool,
pub up: bool,
pub left: bool,
pub right: bool,
pub start: bool,
pub select: bool,
pub b: bool,
pub a: bool,
}
impl Joypad {
pub fn as_register(&self) -> u8 {
let mut reg = 0xFF;
match self.bank_sel {
JoypadBank::Action => {
reg = clear_bit(reg, 5);
if self.start {
reg = clear_bit(reg, 3);
}
if self.select {
reg = clear_bit(reg, 2);
}
if self.b {
reg = clear_bit(reg, 1);
}
if self.a {
reg = clear_bit(reg, 0);
}
}
JoypadBank::Direction => {
reg = clear_bit(reg, 4);
if self.down {
reg = clear_bit(reg, 3);
}
if self.up {
reg = clear_bit(reg, 2);
}
if self.left {
reg = clear_bit(reg, 1);
}
if self.right {
reg = clear_bit(reg, 0);
}
}
}
reg
}
}
impl Default for Joypad {
fn default() -> Self {
Self {
bank_sel: JoypadBank::Action,
down: false,
up: false,
left: false,
right: false,
start: false,
select: false,
b: false,
a: false,
}
}
}

View file

@ -0,0 +1,2 @@
mod joypad;
pub use joypad::{Joypad, JoypadBank};