writes bins better now

This commit is contained in:
2025-07-07 16:28:13 -04:00
parent 9c672741ed
commit 8c08555003
29 changed files with 1381 additions and 108 deletions
+32 -7
View File
@@ -4,14 +4,39 @@ use beneater::parts::ben_eater_pc::BenEaterPC;
use beneater::parts::cpu_display::CpuDisplay;
use macroquad::prelude::*;
use macroquad::telemetry::frame;
use core::mos6502cpu::cpu::Mos6502Cpu;
use core::periph::at28c256::At28C256;
use core::periph::hm62256::Hm62256;
use core::constants::constants_system::*;
/// BenEater computer represents the 'Ben Eater' 6502 breadboard computer.
/// This was built along watching the video series where Ben builds a
/// 6502 on a breadboard and explains each step.
///
pub struct BenEater {
cpu: Mos6502Cpu,
ram: At28C256,
rom: Hm62256
}
impl BenEater {
pub fn new(rom: &[u8; SIZE_32KB]) -> BenEater {
}
}
#[macroquad::main("Ben Eaters PC")]
async fn main() {
println!("Taxation is Theft");
let mut backplane = Backplane::new();
backplane.load_rom("resources/beneater/roms/ror.bin");
let rom_to_run = fs::read("resources/beneater/roms/ror.bin");
let mut pc = BenEater::new(&rom_to_run);
let mut dm = DisplayMatrix::new(200.0, 50.0);
let mut backplane = Backplane::new();
// backplane.load_rom("resources/beneater/roms/ror.bin");
// let mut dm = DisplayMatrix::new(200.0, 50.0);
// dm.push_letter('T');
let mut frame_number: u32 = 0x00;
@@ -20,18 +45,18 @@ async fn main() {
clear_background(BLUE);
draw_text("Ben Eater", 20.0, 20.0, 30.0, BLACK);
dm.render(20.0, 40.0);
// dm.render(20.0, 40.0);
// CpuDisplay::render(&computer.cpu, 20.0, 120.0);
frame_number += 1;
if frame_number.is_multiple_of(60) {
dm.push_letter('X');
computer.tick_system();
// dm.push_letter('X');
// computer.tick_system();
}
if frame_number.is_multiple_of(60 * 6) {
dm.clear_display()
// dm.clear_display()
}
next_frame().await
+37 -7
View File
@@ -1,16 +1,46 @@
#![feature(slice_as_array)]
use core::constants::constants_system::SIZE_32KB;
use core::constants::constants_isa_op::*;
use std::fs;
use std::path::Path;
fn le_swap(to_swap: &[u8; SIZE_32KB]) -> [u8; 32768] {
let mut work: [u8; SIZE_32KB] = [0x00; SIZE_32KB];
for i in (0..SIZE_32KB).step_by(2) {
work[i] = to_swap[i+1];
work[i + 1] = to_swap[i];
}
work
}
fn main() {
// make the rom data in memory.
// Fill with 0x6a -> ROR, A
let vec = vec![0x6a; SIZE_32KB];
let slice: Box<[u8]> = vec.into_boxed_slice();
let mut array: Box<[u8; SIZE_32KB]> = slice.try_into().expect("Unable to make rom in ram");
// Fill with 0xea -> NOP
let mut vec: [u8; SIZE_32KB] = [ISA_OP_NOP; SIZE_32KB];
array[0] = 0xa9; // LDA #$ab
array[1] = 0xab; // 1010 1011
vec[0] = ISA_OP_LDA_I; // LDA #$ab
vec[1] = 0b1010_1011; // 1010 1011
vec[2] = 0x02; // --
vec[3] = 0x03; // --
vec[0x4000] = ISA_OP_LDA_I;
vec[0x4001] = 0b0101_0100;
vec[0x4002] = ISA_OP_JMP_ABS;
vec[0x4003] = 0x00;
vec[0x4004] = 0x40;
vec[0x4005] = ISA_OP_NOP;
vec[0x7ffc] = 0x12; // Reset Vector
vec[0x7ffd] = 0x34;
vec[0x7ffe] = 0x43; // Interrupt Vector
vec[0x7fff] = 0x21;
vec = le_swap(&vec);
// write the rom to disk
fs::write("outputfile.bin", array.as_slice());
fs::write("outputfile.bin", &vec[..]).expect("TODO: panic message");
}
+6 -6
View File
@@ -8,7 +8,7 @@ fn main() {
let mut backplane = Backplane::new();
backplane.load_rom();
//backplane.load_rom();
println!("Backplane is live.");
let mut new_program = [0x00u8; SIZE_32KB];
@@ -21,9 +21,9 @@ fn main() {
);
// println!("{:?}", new_program);
backplane.rom.program(&new_program);
backplane.cpu.pc = 0x6000;
backplane.memory[0x6000] = ISA_OP_LDA_I;
backplane.memory[0x6001] = 0xab;
backplane.tick();
// backplane.rom.program(&new_program);
// backplane.cpu.pc = 0x6000;
// backplane.memory[0x6000] = ISA_OP_LDA_I;
// backplane.memory[0x6001] = 0xab;
// backplane.tick();
}
-1
View File
@@ -1,3 +1,2 @@
pub mod parts;
pub mod backplane;
mod backplane;
+5 -4
View File
@@ -1,9 +1,10 @@
use crate::parts::mos6522_peripheral::Mos6522Peripheral;
use crate::parts::via6522::VIA6522;
use core::constants::constants_system::*;
use core::mos6502cpu::Mos6502Cpu;
use core::mos6502cpu::cpu::Mos6502Cpu;
use core::periph::at28c256::At28C256;
use core::periph::rom_chip::RomChip;
use core::constants::constants_via6522::*;
/// Backplane
///
@@ -60,7 +61,7 @@ impl Backplane {
// if we are reading
if rw {
println!("CPU HAS SET READ FLAG FOR ADDRESS {address:04x} with data 0x{data:02x}");
println!("CPU HAS SET READ FLAG FOR ADDRESS {:04x} with data 0x{:02x}", self.address_bus, self.data_bus);
match self.address_bus {
0x0000..=0x3fff => {
// read from ram
@@ -75,13 +76,13 @@ impl Backplane {
}
}
} else {
println!("CPU HAS SET WRITE FLAG FOR ADDRESS 0x{address:04x} with data 0x{data:02x}");
println!("CPU HAS SET WRITE FLAG FOR ADDRESS 0x{:04x} with data 0x{:02x}", self.address_bus, self.data_bus);
match self.address_bus {
0x6000..=0x600f => {
self.via.write((self.address_bus - 0x6000) as u8, self.data_bus);
},
0x0000..=0x3fff => {
self.memory[self.address_bus] = self.data_bus;
self.memory[self.address_bus as usize] = self.data_bus;
}
_ => {
println!("ATTEMPT TO WRITE OUTSIDE OF MEMORY");
+1 -1
View File
@@ -1,6 +1,6 @@
use crate::parts::clock::Clock;
use core::constants::constants_system::*;
use core::mos6502cpu::Mos6502Cpu;
use core::mos6502cpu::cpu::Mos6502Cpu;
use std::fs;
use std::fs::File;
use std::io::{BufReader, Read};
+2 -2
View File
@@ -1,4 +1,4 @@
use core::mos6502cpu::Mos6502Cpu;
use core::mos6502cpu::cpu::Mos6502Cpu;
use macroquad::color::{BLACK, Color};
use macroquad::prelude::*;
use macroquad::text::draw_text;
@@ -7,7 +7,7 @@ pub struct CpuDisplay {}
impl CpuDisplay {
pub fn render(cpu: &Mos6502Cpu, x_offset: f32, y_offset: f32) {
// get the data to display...
let (pc, a, x, y, address_bus, data_bus, microsteps_remaining) = cpu.dump_data();
let (pc, a, x, y, address_bus, data_bus, microsteps_remaining, reset_vector, interrupt_vector) = cpu.dump_data();
// ...build the interface
Self::draw_square(x_offset, y_offset, x_offset + 300.0, y_offset + 85.0, BLACK);