From 5b9312f6431523caacd47f5e14a9168a9bc3c21d Mon Sep 17 00:00:00 2001 From: august Date: Wed, 14 Feb 2024 03:14:49 -0500 Subject: [PATCH] i'm so happy she works :))))) we can display text for realll :))))))))) --- src/cozette.bin | Bin 0 -> 65535 bytes src/cpu.rs | 11 +++++---- src/george | Bin 65536 -> 65536 bytes src/george.asm | 28 +++++++++++++++++------ src/george.config | 5 ++-- src/instructions.rs | 23 ++++++++++++++----- src/main.rs | 2 ++ src/video.rs | 54 +++++++++++++------------------------------- 8 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 src/cozette.bin diff --git a/src/cozette.bin b/src/cozette.bin new file mode 100644 index 0000000000000000000000000000000000000000..df644511eca50237eedb24a9e00e51151cf78511 GIT binary patch literal 65535 zcmeI#y^9>l83ypux$!k-U@K6thJ~#=59^LjjisQ1=C<$^Vi3!EgLbB1F$#>CV1f-g zDDTb<8#ok$19J%d0T+rxfec0nqewVBjH1C@uoyF%a5jSpVqBM)#_jvFrOnbJn<)WmAC*!VF&*4a!Me?n0 zYO%yNKL9ZKwBCK*IS=uK`4Zqg5ipWNN25{G%wEKM+${>5-@biYDX;eTV?%03ekK#8 z3gfZ8-Ym;D?&wJ0^gc7@b7OvI%+X;$%i$o^%A}dxf9emC znV|{#d{KdE%2FMLQ_%M3(;+xuM*~v*5IQP|W`blQ@ z_pHx?S10{`@Q9Ky=sIl^tb_(3-1+YDpSAYEPR{-%hO3|v{FW0loDD|LpYV_ePr*~yVnA&MSv+&Tq}tY@U(Bk@X@2pX7=Uj>rwU6mrH<-4fpo5 zarynX>TWZ|b2@6iKOE)OZjPGFhVZ37s-8XsfL{Pir%$Q~aMSbv5Q0Lj)H?Br*B*mn zRI1AmBVaE+0>1Q>?u1PsJ6K1tVfn;JbiJ;gi%fES}WjGiq4dbV+{KPsnVb@GpC zKnOI=`8V*FF-O_*4|{(&)cWtfh!ODPH!a7=0Xyh0vf$$yx1!<{fSiA(4}19_&pWTsX^d}YF$*9Eq<3(a zN&&zj!fax#v3Z_j7SIKr`9W})1}!p=x9*Ndo)v{ZC2k_1iRJE`9+F-;b(+A6TW zSR}!f2v`S@c__{T=izy$eE^mKYY`xw$AuOJ?*Vl!0Mq(O6K8>w%dYIX z3UKArP3Q&Lo6rcbFC_n)UP=Epypa2CZKmiI+fC3bt00k&O0SZun0u-PC z1t>rP3Q&Lo6rcbFC_n)UP=Epypa2CZKmiI+fC3bt00k&O0SZun0u-PC1t>rP3Q&Lo z6rcbFC_n)UP=Epypa2CZKmiI+fC3bt00k&O0SZun0u-PC1t>rP3Q&Lo6rcbFC_n)U zP=Epypa2CZKmiI+fC3bt00k&O0SZun0u-PC1t>rP3Q&Lo6rcbFC_n)UP=Epypa2CZ zKmiI+fC3bt00k&O0SZun0u-PC1t>rP3Q&Lo6rcbFC_n)UP=Epypa2CZKmiI+fC3bt z00k&O0SZun0u-PC1t>rP3Q&Lo6rcbFC_n)UP=Epypa2CZKmiI+fC3bt00k&O0SZun R0u-PC1t>rP3VgJ{e*yP2?kWHP literal 0 HcmV?d00001 diff --git a/src/cpu.rs b/src/cpu.rs index 116069b..6048e36 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -53,8 +53,8 @@ impl Cpu { } pub fn reset(&mut self) -> Result<(), ExecutionError> { let reset_vector_pointer = self.read_word(0xFFFC)?; - self.pending_cycles = 8; self.pc = reset_vector_pointer; + self.pending_cycles = 8; Ok(()) } pub fn read(&self, address: Word) -> Result { @@ -212,9 +212,12 @@ impl Cpu { let instruction = get_instruction(opcode); match instruction { Instruction::Valid(valid_instruction) => { - //println!("Instruction: {:?}, {:?}", valid_instruction.opcode, opcode); - //println!("a: {a:#04x}, x: {x:#04x}, y: {y:#04x}, pc: {pc:#06x}, sp: {s:#04x}, sr: {p:#010b}, irq: {irq:?}, nmi: {nmi:?}", a = self.a, x = self.x, y = self.y, pc = self.pc, s = self.s, p = self.p, irq = self.irq, nmi = self.nmi); - //println!(""); + println!("a: {a:#04x}, x: {x:#04x}, y: {y:#04x}, pc: {pc:#06x}, sp: {s:#04x}, sr: {p:#010b}, irq: {irq:?}, nmi: {nmi:?}", a = self.a, x = self.x, y = self.y, pc = self.pc, s = self.s, p = self.p, irq = self.irq, nmi = self.nmi); + println!( + "Instruction: {:?}, {:#04x}", + valid_instruction.opcode, opcode + ); + println!(""); self.pc += 1; match valid_instruction.opcode.call(self) { Ok(_) => { diff --git a/src/george b/src/george index 1ca1b4fa6dc31877cb0b0dd244edd0bdf5001c16..2e825e9cbc56b50495df136d0bcf0e5e469280bc 100644 GIT binary patch delta 59 zcmZo@U}&Q3gau4JOdu9>!UE Result { // zp let address = cpu.read(cpu.pc)?; - cpu.pc += 2; + cpu.pc += 1; Ok(AddressingModeValue::Absolute(address as Word)) } @@ -1934,6 +1934,16 @@ fn get_address( Ok(AddressingModeValue::Absolute(address)) } + fn zero_page_indirect( + // (zp) + cpu: &mut Cpu, + ) -> Result { + let byte: Byte = cpu.read(cpu.pc)?; + let address: Word = cpu.read_word(byte as Word)?; + cpu.pc += 1; + Ok(AddressingModeValue::Absolute(address as Word)) + } + fn zero_page_indexed_indirect( // (zp, x) cpu: &mut Cpu, @@ -1985,7 +1995,7 @@ fn get_address( AddressingMode::ZeroPage => zero_page(cpu), AddressingMode::ZeroPageIndexedWithX => zero_page_indexed_with_x(cpu), AddressingMode::ZeroPageIndexedWithY => zero_page_indexed_with_y(cpu), - AddressingMode::ZeroPageIndirect => todo!(), + AddressingMode::ZeroPageIndirect => zero_page_indirect(cpu), AddressingMode::ZeroPageIndexedIndirect => zero_page_indexed_indirect(cpu), AddressingMode::ZeroPageIndirectIndexedWithY => zero_page_indirect_indexed_with_y(cpu), AddressingMode::Accumulator => Ok(accumulator(cpu)), @@ -2625,9 +2635,10 @@ impl Opcode { | AddressingMode::AbsoluteA => { let address = get_address(mode, cpu)?; let byte = cpu.read(address.try_into()?)?; + println!("{byte:#04x}"); cpu.set_flag(StatusFlag::Carry, cpu.y >= byte); cpu.set_flag(StatusFlag::Zero, cpu.y == byte); - cpu.set_flag(StatusFlag::Negative, cpu.is_negative(cpu.y - byte)); + cpu.set_flag(StatusFlag::Negative, cpu.y <= byte); Ok(()) } _ => Err(GeorgeErrorKind::AddrMode( @@ -2698,9 +2709,9 @@ impl Opcode { | AddressingMode::AbsoluteIndexedWithX => { let address = get_address(mode, cpu)?; let byte = cpu.read(address.try_into()?)?; - cpu.set_flag(StatusFlag::Zero, byte + 1 == 0); - cpu.set_flag(StatusFlag::Negative, cpu.is_negative(byte + 1)); - cpu.write(address.try_into()?, byte + 1)?; + cpu.set_flag(StatusFlag::Zero, byte.wrapping_add(1) == 0); + cpu.set_flag(StatusFlag::Negative, cpu.is_negative(byte.wrapping_add(1))); + cpu.write(address.try_into()?, byte.wrapping_add(1))?; Ok(()) } _ => Err(GeorgeErrorKind::AddrMode( diff --git a/src/main.rs b/src/main.rs index bd0d4c9..7b7c35c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,8 @@ fn main() { if let Err(error) = memory.read_from_bin(binary) { println!("{:?}", error); }; + memory.write(0xFFFC, 0x00).unwrap(); + memory.write(0xFFFD, 0x02).unwrap(); let shared_memory = Arc::new(RwLock::new(memory)); let cpu_memory = shared_memory.clone(); diff --git a/src/video.rs b/src/video.rs index e996848..f5c5865 100644 --- a/src/video.rs +++ b/src/video.rs @@ -1,18 +1,15 @@ -use crate::{memory, Mem}; +use crate::Mem; use minifb::{Window, WindowOptions}; use std::{ - char, fs::File, io::Read, - process::exit, - sync::{Arc, RwLock, RwLockReadGuard}, + sync::{Arc, RwLock}, thread::sleep, time::{Duration, Instant}, }; const FG_COLOR: u32 = 0xFFCC00; -//const BG_COLOR: u32 = 0x110500; -const BG_COLOR: u32 = 0x22BB00; +const BG_COLOR: u32 = 0x110500; pub struct Crtc { memory: Arc>, @@ -67,43 +64,24 @@ impl Crtc { return; } }; - for char_col in 0..65 { - let pixel_col = char_col * 8; - for char_row in 0..30 { - let pixel_row = char_row * 13; + for char_row in 0..29 { + for char_col in 0..64 { + let ascii = memory + .read(0x6000 + (char_row as u16 * char_col as u16)) + .unwrap(); for row in 0..13 { - for i in 0..8 { - let address: usize = ((pixel_col * pixel_row + row * 13) + i) * 8; - self.buffer[address] = BG_COLOR; + let byte = self.char_rom[ascii as usize + (row * 0x101)]; + for i in (0..8).rev() { + let buffer_index = ((char_row) * 13 + (row)) * 512 + (char_col * 8 + i); + if (byte << i) & 0x80 == 0x80 { + self.buffer[buffer_index] = FG_COLOR; + } else { + self.buffer[buffer_index] = BG_COLOR; + } } } } } - //for char_col in 0..64 { - // for char_row in 0..29 { - // let ascii = memory.read(0x6000 + char_row * char_col).unwrap(); - // for row in 0..13 { - // for char in 0..=255 { - // if ascii == char { - // let byte = self.char_rom[char as usize + (row * 0xFF)]; - // for i in 0..8 { - // let address: usize = ((char_col as usize * 64 + (8 * i)) - // + (char_row as usize + (13 * row) * 29)) - // * 8 - // + i; - // if (byte >> i) & 0b1 == 1 { - // self.buffer[address] = FG_COLOR; - // } else { - // self.buffer[address] = BG_COLOR; - // } - // } - // } - // } - // } - // } - //} - println!("{:?}", self.buffer); - //exit(0); } fn draw_hires(&mut self) { let memory = match self.memory.try_read() {