asm fiddling and better debug info

This commit is contained in:
august kline 2024-08-28 21:32:19 -04:00
parent 07d40c05d5
commit c2aef4f249
9 changed files with 421 additions and 106 deletions

View File

@ -1,3 +1,3 @@
char_rom = "./src/roms/cozette.rom"
rom = "./src/roms/george.rom"
screen = "Window"

View File

@ -1,13 +1,11 @@
use crate::instructions::{get_instruction, Instruction};
use crate::instructions::get_instruction;
use crate::memory::{MemHandle, MemoryReader, MemoryWriter};
use std::fmt::Display;
use std::io::{self, Write};
use std::process::exit;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread::sleep;
use std::time::Duration;
use anyhow::Result;
use termion::cursor::Goto;
#[derive(Clone, Copy)]
pub enum StatusFlag {
@ -238,7 +236,7 @@ impl Cpu {
self.receive_control();
if self.stopped & !self.cycle {
// self.set_flag(StatusFlag::IrqDisable, true);
self.set_flag(StatusFlag::IrqDisable, true);
return;
}
self.cycle = false;
@ -264,4 +262,35 @@ impl Cpu {
pub fn stop(&mut self) {
self.stopped = true;
}
pub fn breakpoint(&mut self) {
// 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!("");
// println!(
// "{}{:#04x}: {:#02x}, {:#04x}: {:#02x}",
// Goto(1, 35),
// 0x20,
// self.read(0x20),
// 0x21,
// self.read(0x21)
// );
// println!(
// "{}str_ptr {:#04x}: {:#02x}, {:#04x}: {:#02x}",
// Goto(1, 36),
// 0x30,
// self.read(0x30),
// 0x31,
// self.read(0x31)
// );
// println!(
// "{}cursor - x: {:#02x}, y: {:#02x}",
// Goto(1, 37),
// self.read(0x300),
// self.read(0x301)
// );
self.stop();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -178,7 +178,7 @@ impl Keyboard {
impl MemoryWriter for Keyboard {
fn write(&self, address: u16, data: u8) {
if data != 0x00 {
println!("wrote {:02x} to address {:04x}", data, address);
// println!("wrote {:02x} to address {:04x}", data, address);
}
self.memory.write(address, data);
}

View File

@ -15,15 +15,14 @@ use crate::video::Screen;
use cli::get_input;
use crossterm::cursor;
use memory::MemHandle;
use std::io::{stdout, Read, Result, Write};
use std::io::stdout;
use std::thread::{self, sleep};
use std::time::Duration;
use termion::cursor::Goto;
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use termion::screen::IntoAlternateScreen;
use termion::{async_stdin, clear, screen};
use termion::{async_stdin, clear};
fn main() {
let _stdout = stdout().into_raw_mode();

View File

@ -20,7 +20,7 @@ reset:
ldx #0; initialize data stack pointer
initdisplay:
lda #$20
lda #0
ldy #0
cleardisplay:
@ -36,6 +36,13 @@ cleardisplay:
bne cleardisplay
cli
print_test:
lda #0
sta key_row
lda #5
sta key_col
push_coords #5, #5
main:
; jsr printtext
; key_zero:
@ -45,40 +52,50 @@ main:
; fim:
; cli
; bra fim
jsr keyboard
jsr print
; jsr print
jmp main
keyboard:
ldy #0
.check_row: ; loop through each row
lda kb_row, y
beq .skip_row ; if row has no key pressed, skip checking which key
; jmp key_down
sta kb_row_cache, y ; if key pressed, cache it
lda kb_row, y
cmp kb_row_cache, y ; has key changed?
beq key_down
.skip_row:
iny
cpy #5
bne .check_row
rts
; keyboard: ; reads keyboard registers and stores the column and row of the first key found
; ; TODO: make this routine store up to 8 indices (for 8 key rollover)
; ldy #0
; .check_row: ; loop through each row
; lda kb_row, y
; beq .skip_row ; if row has no key pressed, skip checking which key
; ; jmp key_down
; sta kb_row_cache, y ; if key pressed, cache it
; lda kb_row, y
; cmp kb_row_cache, y ; has key changed?
; beq key_down
; .skip_row:
; iny
; cpy #5
; bne .check_row
; rts
key_down: ; a is loaded with the row byte
phy
sty key_row ; store character row
ldy #0
.find_col: ; test each row bit, store column if key pressed
lsr ; test bit 7
bcs store_col ; if unset, don't go store character columnb
.skip:
iny
cpy #8
bne .find_col ; loop until we've checked each bit
; key_down: ; a is loaded with the row byte
; phy
; sty key_row ; store character row
; ldy #0
; .find_col: ; test each row bit, store column if key pressed
; lsr ; test bit 7
; bcs store_col ; if unset, don't go store character columnb
; .skip:
; iny
; cpy #8
; bne .find_col ; loop until we've checked each bit
; rts
store_col:
sty key_col
; store_col:
; sty key_col
; jsr print
; rts
print: ; x y -- prints the key indexed with key_col and key_row at position x, y
keymap_index:
push
@ -97,13 +114,11 @@ keymap_index:
jsr plus
lda 0, x
tay
print: ; we've stored the character position, now let's
lda keymap, y
ldy cursor
sta $6000, y
inc cursor
ply
push
sta 0, x
stz 1, x
jsr draw_char
rts
keymap:

Binary file not shown.

View File

@ -27,7 +27,7 @@ cleardisplay:
cli
main:
jmp draw
jsr draw
jmp main
draw: