1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-28 07:49:19 +00:00

Make code more idiomatic (#61)

This commit is contained in:
Matthias Endler 2023-03-20 14:11:44 +01:00 committed by GitHub
parent 113f95afba
commit c3438c14e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 25 deletions

View File

@ -93,7 +93,7 @@ impl CPU {
}
(Instruction::AND, OpInput::UseAddress(addr)) => {
let val = self.memory.get_byte(addr) as i8;
self.and(val as i8);
self.and(val);
}
(Instruction::ASL, OpInput::UseImplied) => {
@ -369,10 +369,10 @@ impl CPU {
self.memory.set_byte(addr, self.registers.accumulator as u8);
}
(Instruction::STX, OpInput::UseAddress(addr)) => {
self.memory.set_byte(addr, self.registers.index_x as u8);
self.memory.set_byte(addr, self.registers.index_x);
}
(Instruction::STY, OpInput::UseAddress(addr)) => {
self.memory.set_byte(addr, self.registers.index_y as u8);
self.memory.set_byte(addr, self.registers.index_y);
}
(Instruction::TAX, OpInput::UseImplied) => {
@ -396,7 +396,7 @@ impl CPU {
// NOT set the zero and negative flags. (Because the target
// is the stack pointer)
let val = self.registers.index_x;
self.registers.stack_pointer = StackPointer(val as u8);
self.registers.stack_pointer = StackPointer(val);
}
(Instruction::TYA, OpInput::UseImplied) => {
let val = self.registers.index_y;
@ -564,7 +564,7 @@ impl CPU {
0x00
};
let bcd2: i8 = if (a_after.wrapping_add(bcd1) as u8 & 0xf0) as u8 > 0x90 {
let bcd2: i8 = if (a_after.wrapping_add(bcd1) as u8 & 0xf0) > 0x90 {
0x60
} else {
0x00
@ -642,7 +642,7 @@ impl CPU {
0x00
};
let bcd2: i8 = if (a_after.wrapping_sub(bcd1) as u8 & 0xf0) as u8 > 0x90 {
let bcd2: i8 = if (a_after.wrapping_sub(bcd1) as u8 & 0xf0) > 0x90 {
0x60
} else {
0x00
@ -761,13 +761,13 @@ impl CPU {
// ...
// The N flag contains most significant bit of the subtraction result.
fn compare(&mut self, r: i8, val: u8) {
if r as u8 >= val as u8 {
if r as u8 >= val {
self.registers.status.insert(Status::PS_CARRY);
} else {
self.registers.status.remove(Status::PS_CARRY);
}
if r as i8 == val as i8 {
if r == val as i8 {
self.registers.status.insert(Status::PS_ZERO);
} else {
self.registers.status.remove(Status::PS_ZERO);

View File

@ -166,8 +166,8 @@ impl AddressingMode {
pub fn process(self, cpu: &CPU, arr: &[u8]) -> OpInput {
debug_assert!(arr.len() == self.extra_bytes() as usize);
let x = cpu.registers.index_x as u8;
let y = cpu.registers.index_y as u8;
let x = cpu.registers.index_x;
let y = cpu.registers.index_y;
let memory = &cpu.memory;

View File

@ -70,21 +70,6 @@ bitflags! {
}
impl Status {
pub fn default() -> Status {
// TODO akeeton: Revisit these defaults.
Status::new(StatusArgs {
negative: false,
overflow: false,
unused: true,
brk: false,
decimal_mode: false,
disable_interrupts: true,
zero: false,
carry: false,
})
}
pub fn new(
StatusArgs {
negative,
@ -140,6 +125,22 @@ impl Status {
}
}
impl Default for Status {
fn default() -> Self {
// TODO akeeton: Revisit these defaults.
Status::new(StatusArgs {
negative: false,
overflow: false,
unused: true,
brk: false,
decimal_mode: false,
disable_interrupts: true,
zero: false,
carry: false,
})
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct StackPointer(pub u8);