asm fiddling and better debug info
This commit is contained in:
parent
07d40c05d5
commit
c2aef4f249
|
@ -1,3 +1,3 @@
|
||||||
char_rom = "./src/roms/cozette.rom"
|
char_rom = "./src/roms/cozette.rom"
|
||||||
rom = "./src/roms/george.rom"
|
rom = "./src/roms/george.rom"
|
||||||
|
screen = "Window"
|
||||||
|
|
39
src/cpu.rs
39
src/cpu.rs
|
@ -1,13 +1,11 @@
|
||||||
use crate::instructions::{get_instruction, Instruction};
|
use crate::instructions::get_instruction;
|
||||||
use crate::memory::{MemHandle, MemoryReader, MemoryWriter};
|
use crate::memory::{MemHandle, MemoryReader, MemoryWriter};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::io::{self, Write};
|
|
||||||
use std::process::exit;
|
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Result;
|
use termion::cursor::Goto;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum StatusFlag {
|
pub enum StatusFlag {
|
||||||
|
@ -238,7 +236,7 @@ impl Cpu {
|
||||||
self.receive_control();
|
self.receive_control();
|
||||||
|
|
||||||
if self.stopped & !self.cycle {
|
if self.stopped & !self.cycle {
|
||||||
// self.set_flag(StatusFlag::IrqDisable, true);
|
self.set_flag(StatusFlag::IrqDisable, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.cycle = false;
|
self.cycle = false;
|
||||||
|
@ -264,4 +262,35 @@ impl Cpu {
|
||||||
pub fn stop(&mut self) {
|
pub fn stop(&mut self) {
|
||||||
self.stopped = true;
|
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
|
@ -178,7 +178,7 @@ impl Keyboard {
|
||||||
impl MemoryWriter for Keyboard {
|
impl MemoryWriter for Keyboard {
|
||||||
fn write(&self, address: u16, data: u8) {
|
fn write(&self, address: u16, data: u8) {
|
||||||
if data != 0x00 {
|
if data != 0x00 {
|
||||||
println!("wrote {:02x} to address {:04x}", data, address);
|
// println!("wrote {:02x} to address {:04x}", data, address);
|
||||||
}
|
}
|
||||||
self.memory.write(address, data);
|
self.memory.write(address, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,15 +15,14 @@ use crate::video::Screen;
|
||||||
use cli::get_input;
|
use cli::get_input;
|
||||||
use crossterm::cursor;
|
use crossterm::cursor;
|
||||||
use memory::MemHandle;
|
use memory::MemHandle;
|
||||||
use std::io::{stdout, Read, Result, Write};
|
use std::io::stdout;
|
||||||
use std::thread::{self, sleep};
|
use std::thread::{self, sleep};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use termion::cursor::Goto;
|
use termion::cursor::Goto;
|
||||||
use termion::event::Key;
|
use termion::event::Key;
|
||||||
use termion::input::TermRead;
|
use termion::input::TermRead;
|
||||||
use termion::raw::IntoRawMode;
|
use termion::raw::IntoRawMode;
|
||||||
use termion::screen::IntoAlternateScreen;
|
use termion::{async_stdin, clear};
|
||||||
use termion::{async_stdin, clear, screen};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _stdout = stdout().into_raw_mode();
|
let _stdout = stdout().into_raw_mode();
|
||||||
|
|
|
@ -20,7 +20,7 @@ reset:
|
||||||
ldx #0; initialize data stack pointer
|
ldx #0; initialize data stack pointer
|
||||||
|
|
||||||
initdisplay:
|
initdisplay:
|
||||||
lda #$20
|
lda #0
|
||||||
ldy #0
|
ldy #0
|
||||||
|
|
||||||
cleardisplay:
|
cleardisplay:
|
||||||
|
@ -36,6 +36,13 @@ cleardisplay:
|
||||||
bne cleardisplay
|
bne cleardisplay
|
||||||
cli
|
cli
|
||||||
|
|
||||||
|
print_test:
|
||||||
|
lda #0
|
||||||
|
sta key_row
|
||||||
|
lda #5
|
||||||
|
sta key_col
|
||||||
|
push_coords #5, #5
|
||||||
|
|
||||||
main:
|
main:
|
||||||
; jsr printtext
|
; jsr printtext
|
||||||
; key_zero:
|
; key_zero:
|
||||||
|
@ -45,74 +52,82 @@ main:
|
||||||
; fim:
|
; fim:
|
||||||
; cli
|
; cli
|
||||||
; bra fim
|
; bra fim
|
||||||
jsr keyboard
|
jsr print
|
||||||
|
; jsr print
|
||||||
jmp main
|
jmp main
|
||||||
|
|
||||||
|
|
||||||
keyboard:
|
; keyboard: ; reads keyboard registers and stores the column and row of the first key found
|
||||||
ldy #0
|
; ; TODO: make this routine store up to 8 indices (for 8 key rollover)
|
||||||
.check_row: ; loop through each row
|
; ldy #0
|
||||||
lda kb_row, y
|
; .check_row: ; loop through each row
|
||||||
beq .skip_row ; if row has no key pressed, skip checking which key
|
; lda kb_row, y
|
||||||
; jmp key_down
|
; beq .skip_row ; if row has no key pressed, skip checking which key
|
||||||
sta kb_row_cache, y ; if key pressed, cache it
|
; ; jmp key_down
|
||||||
lda kb_row, y
|
; sta kb_row_cache, y ; if key pressed, cache it
|
||||||
cmp kb_row_cache, y ; has key changed?
|
; lda kb_row, y
|
||||||
beq key_down
|
; cmp kb_row_cache, y ; has key changed?
|
||||||
.skip_row:
|
; beq key_down
|
||||||
iny
|
; .skip_row:
|
||||||
cpy #5
|
; iny
|
||||||
bne .check_row
|
; cpy #5
|
||||||
rts
|
; bne .check_row
|
||||||
|
; rts
|
||||||
|
|
||||||
key_down: ; a is loaded with the row byte
|
; key_down: ; a is loaded with the row byte
|
||||||
phy
|
; phy
|
||||||
sty key_row ; store character row
|
; sty key_row ; store character row
|
||||||
ldy #0
|
; ldy #0
|
||||||
.find_col: ; test each row bit, store column if key pressed
|
; .find_col: ; test each row bit, store column if key pressed
|
||||||
lsr ; test bit 7
|
; lsr ; test bit 7
|
||||||
bcs store_col ; if unset, don't go store character columnb
|
; bcs store_col ; if unset, don't go store character columnb
|
||||||
.skip:
|
; .skip:
|
||||||
iny
|
; iny
|
||||||
cpy #8
|
; cpy #8
|
||||||
bne .find_col ; loop until we've checked each bit
|
; bne .find_col ; loop until we've checked each bit
|
||||||
|
; rts
|
||||||
|
|
||||||
store_col:
|
; store_col:
|
||||||
sty key_col
|
; sty key_col
|
||||||
|
; jsr print
|
||||||
|
; rts
|
||||||
|
|
||||||
keymap_index:
|
|
||||||
push
|
|
||||||
lda key_col
|
|
||||||
stz 1, x
|
|
||||||
sta 0, x
|
|
||||||
push
|
|
||||||
lda #8
|
|
||||||
stz 1, x
|
|
||||||
sta 0, x
|
|
||||||
push
|
|
||||||
lda key_row
|
|
||||||
stz 1, x
|
|
||||||
sta 0, x
|
|
||||||
jsr mult
|
|
||||||
jsr plus
|
|
||||||
lda 0, x
|
|
||||||
tay
|
|
||||||
|
|
||||||
print: ; we've stored the character position, now let's
|
|
||||||
|
|
||||||
|
print: ; x y -- prints the key indexed with key_col and key_row at position x, y
|
||||||
|
|
||||||
|
keymap_index:
|
||||||
|
push
|
||||||
|
lda key_col
|
||||||
|
stz 1, x
|
||||||
|
sta 0, x
|
||||||
|
push
|
||||||
|
lda #8
|
||||||
|
stz 1, x
|
||||||
|
sta 0, x
|
||||||
|
push
|
||||||
|
lda key_row
|
||||||
|
stz 1, x
|
||||||
|
sta 0, x
|
||||||
|
jsr mult
|
||||||
|
jsr plus
|
||||||
|
lda 0, x
|
||||||
|
tay
|
||||||
lda keymap, y
|
lda keymap, y
|
||||||
ldy cursor
|
push
|
||||||
sta $6000, y
|
sta 0, x
|
||||||
inc cursor
|
stz 1, x
|
||||||
ply
|
jsr draw_char
|
||||||
rts
|
rts
|
||||||
|
|
||||||
keymap:
|
keymap:
|
||||||
.byte "?outrew?"
|
.byte "?outrew?"
|
||||||
.byte "?piygsq?"
|
.byte "?piygsq?"
|
||||||
.byte "a??khvd?"
|
.byte "a??khvd?"
|
||||||
.byte "42ljbfz?"
|
.byte "42ljbfz?"
|
||||||
.byte "31?mncx?"
|
.byte "31?mncx?"
|
||||||
.byte "????? m"
|
.byte "????? m"
|
||||||
|
|
||||||
draw:
|
draw:
|
||||||
; push_coords #0, #0
|
; push_coords #0, #0
|
||||||
|
|
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
.macro breakpoint ; $02 isn't a valid instruction, the emulator will see this and halt, dump memory contents
|
.macro breakpoint ; $02 isn't a valid instruction, the emulator will see this and halt, dump memory contents
|
||||||
.byte $02
|
.byte $02
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro pop ; drops a data stack cell
|
.macro pop ; drops a data stack cell
|
||||||
inx
|
inx
|
||||||
inx
|
inx
|
||||||
|
|
|
@ -27,7 +27,7 @@ cleardisplay:
|
||||||
cli
|
cli
|
||||||
|
|
||||||
main:
|
main:
|
||||||
jmp draw
|
jsr draw
|
||||||
jmp main
|
jmp main
|
||||||
|
|
||||||
draw:
|
draw:
|
||||||
|
|
Loading…
Reference in New Issue