From 41401f7d832f7f6338b0b9a2c391bbb045ecb765 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Wed, 3 Jul 2024 14:39:39 -0400 Subject: [PATCH] Preparing to add the InputConsole --- .gitignore | 8 +++- simple_test_machine/programs/hello.asm | 5 +- simple_test_machine/programs/mult10.asm | 9 ++-- simple_test_machine/programs/mult10_orig.asm | 29 ++++++++++++ simple_test_machine/src/machine.rs | 49 ++++++++++++++++---- simple_test_machine/src/main.rs | 6 +-- todo/todo.todo | 2 +- 7 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 simple_test_machine/programs/mult10_orig.asm diff --git a/.gitignore b/.gitignore index 3646a45..91cb18c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ /target *.pdf -*.bin \ No newline at end of file + +# win2c64 output formats +*.bin +*.rw +*.ptf + +win2c64/ \ No newline at end of file diff --git a/simple_test_machine/programs/hello.asm b/simple_test_machine/programs/hello.asm index f216c02..95d8192 100644 --- a/simple_test_machine/programs/hello.asm +++ b/simple_test_machine/programs/hello.asm @@ -4,9 +4,10 @@ ; http://www.aartbik.com/ ; Adapted for the RE6502 emulator simple test machine +; compile with win2c64 using the -R option -strout .equ $00A0 ; console output address -print_flag .equ $009E ; console output address +strout .equ $1100 ; console output address +print_flag .equ $009E ; str print flag address main .org $0200 ; program load address for the simple test machine ldx #0 diff --git a/simple_test_machine/programs/mult10.asm b/simple_test_machine/programs/mult10.asm index 0ae4a8b..18eefde 100644 --- a/simple_test_machine/programs/mult10.asm +++ b/simple_test_machine/programs/mult10.asm @@ -3,6 +3,9 @@ ; For testing this program was assembled with c64 (using the -R option): ; https://www.aartbik.com/MISC/c64.html +strout .equ $1100 ; console output address +print_flag .equ $009E ; str print flag address + ; FAST MULTIPLY program from: ; http://6502.org/source/integers/fastx10.htm main LDA #7 ; load 7 into the accumulator @@ -14,9 +17,9 @@ main LDA #7 ; load 7 into the accumulator ADC TEMP ;as result, A = x*8 + x*2 ; PRINT RESULT - STA $A0 ; 0x85, 0xA0, ; store A into the console output address - LDX #0 ; 0xA2, 0x00, ; null terminator - STX $A1 ; 0x86, 0xA1, ; store null terminator to output addr + 1 + STA strout ; store A into the console output address + LDX #0 ; 0xA2, 0x00, ; null terminator + STX strout+1 ; store null terminator to output addr + 1 ; Set flag to do the print LDX #1 ; 0xA2, 0x01, diff --git a/simple_test_machine/programs/mult10_orig.asm b/simple_test_machine/programs/mult10_orig.asm new file mode 100644 index 0000000..0ae4a8b --- /dev/null +++ b/simple_test_machine/programs/mult10_orig.asm @@ -0,0 +1,29 @@ + +; Multiply 7 with 10 and print the result +; For testing this program was assembled with c64 (using the -R option): +; https://www.aartbik.com/MISC/c64.html + + ; 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 console output address + 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, ; Print byte flag is at 0x9F + + ; End the program + RTS ; 0x60 + + ; Variables + TEMP .byte 0 diff --git a/simple_test_machine/src/machine.rs b/simple_test_machine/src/machine.rs index d17ff6a..17cef32 100644 --- a/simple_test_machine/src/machine.rs +++ b/simple_test_machine/src/machine.rs @@ -2,6 +2,22 @@ use std::str; +//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +// USED MEMORY ADDRESSES +//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +const PROGRAM_START_ADDR: u16 = 0x0200; // Program code starts on page 2 +const CPU_RESET_START_ADDR: u16 = 0xFFFC; // This is where the cpu looks for the address to start executing code at + +pub const OUTPUT_BUF_ADDR: u16 = 0x1100; // Output buffer -- Put values to be printed at this location! +pub const INPUT_BUF_ADDR: u16 = 0x1200; // Input buffer + +pub const CONSOLE_FLAGS_ADDR: u16 = 0x009A; // Grouping all of the console flags into a single byte + +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. + +pub const READ_KB_FLAG: u16 = 0x009D; // Set this address to 1 to request user input from the keyboard + ///////////////////////////////////////////////////////////////////// // BUS ///////////////////////////////////////////////////////////////////// @@ -49,12 +65,9 @@ impl Bus for TBus } //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -// CONSOLE +// CONSOLE OUTPUT //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -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. struct OutputConsole { @@ -79,7 +92,7 @@ impl OutputConsole let mut idx = 0; while value != 0 { - value = bus.read(OUTPUT_ADDR + idx); + value = bus.read(OUTPUT_BUF_ADDR + idx); msg.push(value); idx += 1; } @@ -94,7 +107,7 @@ impl OutputConsole let flag = bus.read(PRINT_BYTE_FLAG); if flag != 0 { - let byte = bus.read(OUTPUT_ADDR); + let byte = bus.read(OUTPUT_BUF_ADDR); bus.write(PRINT_BYTE_FLAG, 0); println!("{}", byte as u8); } @@ -102,12 +115,28 @@ impl OutputConsole } } +//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +// CONSOLE INPUT +//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| + + +struct InputConsole {} + +impl InputConsole +{ + fn clock(_cpu: &mut R6502, bus: &mut TBus) + { + + } +} + + + ///////////////////////////////////////////////////////////////////// // MACHINE ///////////////////////////////////////////////////////////////////// -const PROGRAM_START_ADDR: u16 = 0x0200; // Program code starts on page 2 -const CPU_RESET_START_ADDR: u16 = 0xFFFC; // This is where the cpu looks for the address to start executing code at + pub struct TestMachine { @@ -150,6 +179,10 @@ impl TestMachine { self.cpu.clock(&mut self.bus); OutputConsole::clock(&mut self.cpu, &mut self.bus); + + // TODO: Check if the input flag is set (need to choose a memory location for it) + // if it's set, prompt for input and copy the input into memory (need an address for that too) + // ACTUALLY: Move that logic into a new module (InputConsole) and just call clock() (like OutputConsole) } } } \ No newline at end of file diff --git a/simple_test_machine/src/main.rs b/simple_test_machine/src/main.rs index 923b3f1..d38626b 100644 --- a/simple_test_machine/src/main.rs +++ b/simple_test_machine/src/main.rs @@ -3,7 +3,7 @@ use std::{ fs, env }; mod machine; -use machine::{OUTPUT_ADDR, PRINT_STR_FLAG, PRINT_BYTE_FLAG, TestMachine}; +use machine::{OUTPUT_BUF_ADDR, PRINT_STR_FLAG, PRINT_BYTE_FLAG, TestMachine}; @@ -35,7 +35,7 @@ fn main() fn hello_world_test() { let print_flag_addr = (PRINT_STR_FLAG & 0x00FF) as u8; - let output_addr = (OUTPUT_ADDR & 0x00FF) as u8; + let output_addr = (OUTPUT_BUF_ADDR & 0x00FF) as u8; let program = [ // Load string into memory at the output address @@ -105,7 +105,7 @@ fn fast_mult_by_10(val: u8) // TEMP .byte 0 let print_flag_addr = (PRINT_BYTE_FLAG & 0x00FF) as u8; - let output_addr = (OUTPUT_ADDR & 0x00FF) as u8; + let output_addr = (OUTPUT_BUF_ADDR & 0x00FF) as u8; let temp_addr: u8 = 0xB0; let program = diff --git a/todo/todo.todo b/todo/todo.todo index ba490c1..7d01d65 100644 --- a/todo/todo.todo +++ b/todo/todo.todo @@ -11,6 +11,7 @@ General: ☐ Debug data lookup for instructions Test Machine: + ☐ Implement basic input ✔ Hello world program @done(24-01-19 17:09) ✔ Load and run a given program binary @done(24-01-22 17:08) @@ -109,5 +110,4 @@ Instructions: ✔ CA DEX @done(24-01-19 13:16) ✔ EA NOP @done(24-01-19 13:16) -