Simple test machine can now load an arbitrary program binary

master
Joey Pollack 2 years ago
parent 6efdfecf54
commit 05fcb7b7f7

1
.gitignore vendored

@ -1,2 +1,3 @@
/target
*.pdf
*.bin

@ -5,6 +5,8 @@
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
@ -57,7 +59,7 @@
"kind": "bin"
}
},
"args": [],
"args": ["simple_test_machine\\programs\\mult10.bin"],
"cwd": "${workspaceFolder}"
},
]

@ -0,0 +1,37 @@
# Load string into memory at the output address
0xA2, b'H', # LDX H
0x86, output_addr, # STX
0xA2, b'e', # LDX e
0x86, output_addr + 1, # STX
0xA2, b'l', # LDX l
0x86, output_addr + 2, # STX
0xA2, b'l', # LDX l
0x86, output_addr + 3, # STX
0xA2, b'o', # LDX o
0x86, output_addr + 4, # STX
0xA2, b' ', # LDX ' '
0x86, output_addr + 5, # STX
0xA2, b'w', # LDX w
0x86, output_addr + 6, # STX
0xA2, b'o', # LDX o
0x86, output_addr + 7, # STX
0xA2, b'r', # LDX r
0x86, output_addr + 8, # STX
0xA2, b'l', # LDX l
0x86, output_addr + 9, # STX
0xA2, b'd', # LDX d
0x86, output_addr + 10, # STX
0xA2, b'!', # LDX !
0x86, output_addr + 11, # STX
0xA2, 0x00, # LDX 0
0x86, output_addr + 12, # STX
# Set flag to do the print
0xA2, 0x01, # LDX 1
0x86, print_flag_addr, # STX
# End the program
0x60 # RTS

@ -0,0 +1,26 @@
; Multiply 7 with 10 and print the result
; FAST MULTIPLY program from:
; http://6502.org/source/integers/fastx10.htm
main LDA #7 ; load 7 into the accumulator
ASL ;multiply by 2
STA TEMP ;temp store in TEMP
ASL ;again multiply by 2 (*4)
ASL ;again multiply by 2 (*8)
CLC
ADC TEMP ;as result, A = x*8 + x*2
; PRINT RESULT
STA $A0 ; 0x85, 0xA0, ; store A into the output addr
LDX #0 ; 0xA2, 0x00, ; null terminator
STX $A1 ; 0x86, 0xA1, ; store null terminator to output addr + 1
; Set flag to do the print
LDX #1 ; 0xA2, 0x01,
STX $9F ; 0x86, 0x9F,
; End the program
RTS ; 0x60
TEMP .byte 0

@ -52,11 +52,10 @@ impl Bus for TBus
// CONSOLE
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub const OUTPUT_ADDR: u16 = 0x00A0;
pub const PRINT_BYTE_FLAG: u16 = 0x009E;
pub const PRINT_STR_FLAG: u16 = 0x009F;
pub const OUTPUT_ADDR: u16 = 0x00A0; // Put values to be printed at this location!
pub const PRINT_BYTE_FLAG: u16 = 0x009F; // Then set one of these flags to trigger the print
pub const PRINT_STR_FLAG: u16 = 0x009E; // and indicate what type is being printed.
// TODO: Handle input
struct OutputConsole
{

@ -1,13 +1,35 @@
use machine::{OUTPUT_ADDR, PRINT_STR_FLAG, PRINT_BYTE_FLAG, TestMachine};
use std::{ fs, env };
mod machine;
use machine::{OUTPUT_ADDR, PRINT_STR_FLAG, PRINT_BYTE_FLAG, TestMachine};
fn main()
{
let args: Vec<String> = env::args().collect();
if args.len() < 2
{
println!("No program provided, running internal test programs...");
hello_world_test();
println!();
fast_mult_by_10();
fast_mult_by_10(7);
return;
}
let program = fs::read(&args[1]).expect(&format!("Failed read program file: {}", &args[1]));
let mut vm = TestMachine::new();
vm.load_program(&program);
vm.reset();
vm.run_program();
println!("Program stopped");
}
fn hello_world_test()
@ -66,7 +88,7 @@ fn hello_world_test()
}
fn fast_mult_by_10()
fn fast_mult_by_10(val: u8)
{
// Program from:
// http://6502.org/source/integers/fastx10.htm
@ -88,7 +110,7 @@ fn fast_mult_by_10()
let program =
[
0xA9, 0x07, // LDA 7 - The value we want to multiply
0xA9, val, // LDA val - The value we want to multiply
// START OF MULT10 FUNCTION
0x0A, // ASL ;multiply by 2

@ -7,6 +7,7 @@ General:
Test Machine:
✔ Hello world program @done(24-01-19 17:09)
✔ Load and run a given program binary @done(24-01-22 17:08)
CPU:
Signals:

Loading…
Cancel
Save