Refactors the print flags to use bitwise flags and collect them all under a single byte (now know as the Console Flags)

master
Joey Pollack 1 year ago
parent 41401f7d83
commit e3225cb0ca

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

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

@ -3,8 +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
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:
; http://6502.org/source/integers/fastx10.htm
@ -22,8 +23,9 @@ main LDA #7 ; load 7 into the accumulator
STX strout+1 ; 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
LDA con_flags ; load the current console flag set
ORA #prt_str_flag ; turn on the print string flag
STA con_flags ; store the flags back in memory
; End the program
RTS ; 0x60

@ -13,10 +13,9 @@ 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
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
@ -84,8 +83,8 @@ impl OutputConsole
fn clock(_cpu: &mut R6502, bus: &mut TBus )
{
// Check for a string to print
let mut value = bus.read(PRINT_STR_FLAG);
if value != 0
let mut value = bus.read(CONSOLE_FLAGS_ADDR);
if (value & PRINT_STR_FLAG) != 0
{
let mut msg: Vec<u8> = Vec::new();
@ -98,17 +97,24 @@ impl OutputConsole
}
// Mark the string as empty again
bus.write(PRINT_STR_FLAG, 0);
value &= !(PRINT_STR_FLAG);
bus.write(CONSOLE_FLAGS_ADDR, value);
println!("{}", str::from_utf8(&msg).unwrap());
}
// Check for byte to print
let flag = bus.read(PRINT_BYTE_FLAG);
if flag != 0
let mut flag = bus.read(CONSOLE_FLAGS_ADDR);
if (flag & PRINT_BYTE_FLAG)!= 0
{
// read the byte
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);
}

Loading…
Cancel
Save