Skip to content

Commit 51d6339

Browse files
committed
Almost working text buffer
1 parent b6ad893 commit 51d6339

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

examples/screen.asm

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@org 0x0000
2+
@define BUF_START 0xF800
3+
4+
_start:
5+
mv A, 0
6+
.loop:
7+
lda [BUF_START]
8+
add16 H, L, 0x00, A
9+
st A
10+
inc A
11+
jnz A, [.loop]
12+
halt

src/emulator.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,11 @@ impl State {
628628
)
629629
} else if cw.contains(ControlWord::LA) {
630630
match self.addr {
631-
0x0000..=0xFFBF => self.mem[self.addr as usize],
632-
0xFFC0..=0xFFFC => match self.peripherals.get(&((self.addr - 0xFFC0) as u8)) {
631+
0x0000..=0xF7FF => self.mem[self.addr as usize],
632+
0xF800..=0xFFCF => {
633+
self.text_buffer.get(self.addr - 0xF800)
634+
}
635+
0xFFD0..=0xFFFC => match self.peripherals.get(&((self.addr - 0xFFC0) as u8)) {
633636
Some(periph) => unsafe {
634637
if let Ok(stateful_read) =
635638
periph.lib.library.get::<StatefulReadFn>(b"stateful_read")
@@ -670,10 +673,13 @@ impl State {
670673

671674
if cw.contains(ControlWord::SA) {
672675
match self.addr {
673-
0x0000..=0xFFBF => {
676+
0x0000..=0xF7FF => {
674677
self.mem[self.addr as usize] = bus;
675678
}
676-
0xFFC0..=0xFFFC => match self.peripherals.get(&((self.addr - 0xFFC0) as u8)) {
679+
0xF800..=0xFFCF => {
680+
self.text_buffer.set(self.addr - 0xF800, bus);
681+
}
682+
0xFFD0..=0xFFFC => match self.peripherals.get(&((self.addr - 0xFFC0) as u8)) {
677683
Some(periph) => unsafe {
678684
if let Ok(stateful_write) =
679685
periph.lib.library.get::<StatefulWriteFn>(b"stateful_write")

src/emulator/display.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,22 @@ impl TextBuffer {
2525

2626
TextBuffer {data, handle}
2727
}
28+
29+
pub fn get(&self, addr: u16) -> u8 {
30+
self.data[addr as usize]
31+
}
32+
33+
pub fn set(&mut self, addr: u16, data: u8) {
34+
self.data[addr as usize] = data;
35+
println!("{}", self.data[addr as usize]);
36+
}
2837
}
2938

3039
async fn run_handle(buffer: BufferPtr) {
3140
let mut opts = WindowOptions::default();
3241
opts.scale = Scale::FitScreen;
33-
opts.scale_mode = ScaleMode::Center;
42+
opts.scale_mode = ScaleMode::AspectRatioStretch;
43+
opts.resize = true;
3444

3545
let mut window = minifb::Window::new("f8ful", WIDTH, HEIGHT, opts).expect("should be able to create window");
3646
let mut fb = [0x00000000; WIDTH*HEIGHT];
@@ -48,14 +58,16 @@ async fn run_handle(buffer: BufferPtr) {
4858
(*buffer.0)[char_idx]
4959
};
5060

51-
let font_addr = (character as usize) << 4 + font_y;
52-
let lit = FONT[font_addr] & !(1 << font_x) > 0;
61+
let font_addr = ((character as usize) << 4) + font_y;
62+
let lit = FONT[font_addr] & (1 << (7 - font_x)) > 0;
63+
5364

5465
// This part isn't part of the actual CPU,
5566
// the real value will be transmitted via wire instead of stored.
5667
fb[x + y*WIDTH] = if lit {0x00FFFFFF} else {0x00000000};
57-
window.update_with_buffer(&fb, WIDTH, HEIGHT).expect("should be able to update window");
5868
}
5969
}
70+
71+
window.update_with_buffer(&fb, WIDTH, HEIGHT).expect("should be able to update window");
6072
}
6173
}

0 commit comments

Comments
 (0)