Compare commits

..

No commits in common. 'e3225cb0caf95dde817b379661ce436a87ed8cf3' and 'ecc7b9b73f3ea2bc5bd6f34a12412301029b3eb5' have entirely different histories.

6
.gitignore vendored

@ -1,9 +1,3 @@
/target /target
*.pdf *.pdf
# win2c64 output formats
*.bin *.bin
*.rw
*.ptf
win2c64/

@ -60,7 +60,7 @@
"kind": "bin" "kind": "bin"
} }
}, },
"args": ["simple_test_machine\\programs\\hello.rw"], "args": ["simple_test_machine\\programs\\hello.bin"],
"cwd": "${workspaceFolder}" "cwd": "${workspaceFolder}"
}, },
] ]

@ -4,11 +4,9 @@
; http://www.aartbik.com/ ; http://www.aartbik.com/
; Adapted for the RE6502 emulator simple test machine ; Adapted for the RE6502 emulator simple test machine
; compile with win2c64 using the -R option
strout .equ $1100 ; console output address strout .equ $00A0 ; console output address
con_flags .equ $009A ; console flags address print_flag .equ $009E ; console output address
prt_str_flag .equ $0002
main .org $0200 ; program load address for the simple test machine main .org $0200 ; program load address for the simple test machine
ldx #0 ldx #0
@ -23,12 +21,11 @@ loop lda text,x
sta strout,x sta strout,x
; Set flag to do the print ; Set flag to do the print
lda con_flags ldx #1 ; 0xA2, 0x01,
ora #prt_str_flag stx print_flag ; 0x86, 0x9E, ; Print string flag is at 0x9E
sta con_flags ; 0x86, 0x9A, ; Print string flag is at 0x9A
; End the program ; End the program
rts ; 0x60 rts ; 0x60
; Variables ; Variables
text .byte "HELLO WORLD" text .byte "HELLO WORLD"

@ -3,10 +3,6 @@
; For testing this program was assembled with c64 (using the -R option): ; For testing this program was assembled with c64 (using the -R option):
; https://www.aartbik.com/MISC/c64.html ; https://www.aartbik.com/MISC/c64.html
strout .equ $1100 ; console output address
con_flags .equ $009A ; console flags address
prt_str_flag .equ $0001 ; print string flag
; FAST MULTIPLY program from: ; FAST MULTIPLY program from:
; http://6502.org/source/integers/fastx10.htm ; http://6502.org/source/integers/fastx10.htm
main LDA #7 ; load 7 into the accumulator main LDA #7 ; load 7 into the accumulator
@ -18,14 +14,13 @@ main LDA #7 ; load 7 into the accumulator
ADC TEMP ;as result, A = x*8 + x*2 ADC TEMP ;as result, A = x*8 + x*2
; PRINT RESULT ; PRINT RESULT
STA strout ; store A into the console output address STA $A0 ; 0x85, 0xA0, ; store A into the console output address
LDX #0 ; 0xA2, 0x00, ; null terminator LDX #0 ; 0xA2, 0x00, ; null terminator
STX strout+1 ; store null terminator to output addr + 1 STX $A1 ; 0x86, 0xA1, ; store null terminator to output addr + 1
; Set flag to do the print ; Set flag to do the print
LDA con_flags ; load the current console flag set LDX #1 ; 0xA2, 0x01,
ORA #prt_str_flag ; turn on the print string flag STX $9F ; 0x86, 0x9F, ; Print byte flag is at 0x9F
STA con_flags ; store the flags back in memory
; End the program ; End the program
RTS ; 0x60 RTS ; 0x60

@ -1,29 +0,0 @@
; 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

@ -2,21 +2,6 @@
use std::str; 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: u8 = 0x01; // Then set one of these flags to trigger the print
pub const PRINT_STR_FLAG: u8 = 0x02; // and indicate what type is being printed.
pub const READ_KB_FLAG: u8 = 0x04; // Set this address to 1 to request user input from the keyboard
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// BUS // BUS
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
@ -64,9 +49,12 @@ impl Bus for TBus
} }
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// CONSOLE OUTPUT // CONSOLE
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 struct OutputConsole
{ {
@ -83,66 +71,43 @@ impl OutputConsole
fn clock(_cpu: &mut R6502, bus: &mut TBus ) fn clock(_cpu: &mut R6502, bus: &mut TBus )
{ {
// Check for a string to print // Check for a string to print
let mut value = bus.read(CONSOLE_FLAGS_ADDR); let mut value = bus.read(PRINT_STR_FLAG);
if (value & PRINT_STR_FLAG) != 0 if value != 0
{ {
let mut msg: Vec<u8> = Vec::new(); let mut msg: Vec<u8> = Vec::new();
let mut idx = 0; let mut idx = 0;
while value != 0 while value != 0
{ {
value = bus.read(OUTPUT_BUF_ADDR + idx); value = bus.read(OUTPUT_ADDR + idx);
msg.push(value); msg.push(value);
idx += 1; idx += 1;
} }
// Mark the string as empty again // Mark the string as empty again
value &= !(PRINT_STR_FLAG); bus.write(PRINT_STR_FLAG, 0);
bus.write(CONSOLE_FLAGS_ADDR, value);
println!("{}", str::from_utf8(&msg).unwrap()); println!("{}", str::from_utf8(&msg).unwrap());
} }
// Check for byte to print // Check for byte to print
let mut flag = bus.read(CONSOLE_FLAGS_ADDR); let flag = bus.read(PRINT_BYTE_FLAG);
if (flag & PRINT_BYTE_FLAG)!= 0 if flag != 0
{ {
// read the byte let byte = bus.read(OUTPUT_ADDR);
let byte = bus.read(OUTPUT_BUF_ADDR); bus.write(PRINT_BYTE_FLAG, 0);
// reset the flag
flag &= !(PRINT_BYTE_FLAG);
bus.write(CONSOLE_FLAGS_ADDR, flag);
// print the byte
println!("{}", byte as u8); println!("{}", byte as u8);
} }
} }
} }
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// CONSOLE INPUT
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
struct InputConsole {}
impl InputConsole
{
fn clock(_cpu: &mut R6502, bus: &mut TBus)
{
}
}
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// MACHINE // 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 pub struct TestMachine
{ {
@ -185,10 +150,6 @@ impl TestMachine
{ {
self.cpu.clock(&mut self.bus); self.cpu.clock(&mut self.bus);
OutputConsole::clock(&mut self.cpu, &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)
} }
} }
} }

@ -3,7 +3,7 @@
use std::{ fs, env }; use std::{ fs, env };
mod machine; mod machine;
use machine::{OUTPUT_BUF_ADDR, PRINT_STR_FLAG, PRINT_BYTE_FLAG, TestMachine}; use machine::{OUTPUT_ADDR, PRINT_STR_FLAG, PRINT_BYTE_FLAG, TestMachine};
@ -35,7 +35,7 @@ fn main()
fn hello_world_test() fn hello_world_test()
{ {
let print_flag_addr = (PRINT_STR_FLAG & 0x00FF) as u8; let print_flag_addr = (PRINT_STR_FLAG & 0x00FF) as u8;
let output_addr = (OUTPUT_BUF_ADDR & 0x00FF) as u8; let output_addr = (OUTPUT_ADDR & 0x00FF) as u8;
let program = let program =
[ [
// Load string into memory at the output address // Load string into memory at the output address
@ -105,7 +105,7 @@ fn fast_mult_by_10(val: u8)
// TEMP .byte 0 // TEMP .byte 0
let print_flag_addr = (PRINT_BYTE_FLAG & 0x00FF) as u8; let print_flag_addr = (PRINT_BYTE_FLAG & 0x00FF) as u8;
let output_addr = (OUTPUT_BUF_ADDR & 0x00FF) as u8; let output_addr = (OUTPUT_ADDR & 0x00FF) as u8;
let temp_addr: u8 = 0xB0; let temp_addr: u8 = 0xB0;
let program = let program =

@ -11,7 +11,6 @@ General:
☐ Debug data lookup for instructions ☐ Debug data lookup for instructions
Test Machine: Test Machine:
☐ Implement basic input
✔ Hello world program @done(24-01-19 17:09) ✔ Hello world program @done(24-01-19 17:09)
✔ Load and run a given program binary @done(24-01-22 17:08) ✔ Load and run a given program binary @done(24-01-22 17:08)
@ -111,3 +110,4 @@ Instructions:
✔ EA NOP @done(24-01-19 13:16) ✔ EA NOP @done(24-01-19 13:16)

Loading…
Cancel
Save