From 255ec9be606024a9df8d444cd90e68bafe509bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Thu, 18 Jul 2024 17:13:44 +0200 Subject: [PATCH] Implement video vector callback and add example rom --- coco-ui/index.html | 1 + coco-ui/index.js | 2 +- coco-ui/roms/sprite_move.rom | Bin 0 -> 89 bytes coco-vm/src/lib.rs | 3 +-- coco-vm/src/video.rs | 17 ++++++++++++++++- 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 coco-ui/roms/sprite_move.rom diff --git a/coco-ui/index.html b/coco-ui/index.html index 625c6ec..175e9e3 100644 --- a/coco-ui/index.html +++ b/coco-ui/index.html @@ -20,6 +20,7 @@

👻-8

+
diff --git a/coco-ui/index.js b/coco-ui/index.js index 82b0e8a..3cb7830 100644 --- a/coco-ui/index.js +++ b/coco-ui/index.js @@ -51,7 +51,7 @@ async function main() { const _ = await initWasm("./vendor/coco_ui_bg.wasm"); const romSelector = document.querySelector("#coco-rom-selector"); - const defaultRom = "sprite.rom"; + const defaultRom = "sprite_move.rom"; setupRomSelector(romSelector, defaultRom); setupControls(); diff --git a/coco-ui/roms/sprite_move.rom b/coco-ui/roms/sprite_move.rom new file mode 100644 index 0000000000000000000000000000000000000000..a9bc92639e014e64e4b6a880babb9a0869bb450b GIT binary patch literal 89 zcmZ3$DAXWezJSrPLBhO2u|Y(fp+QKj0Z51g31RUD1E3IN!vQsEDM^r+3rI|$K}wu~ ip}d@dy}Z02UA(ZYzP$W DeviceOutput { - // TODO: call video vector - cpu.run(0x200, self); + cpu.run(self.video.vector(), self); self.output() } diff --git a/coco-vm/src/video.rs b/coco-vm/src/video.rs index 6fc4a95..3c7242b 100644 --- a/coco-vm/src/video.rs +++ b/coco-vm/src/video.rs @@ -11,7 +11,6 @@ impl Ports for VideoPorts { } impl VideoPorts { - #[allow(dead_code)] const VECTOR: u8 = 0x00; const X: u8 = 0x02; const Y: u8 = 0x03; @@ -32,6 +31,7 @@ pub struct VideoDevice { pub layers: [VideoBuffer; 2], is_dirty: bool, buffer: VideoBuffer, + vector: u16, } impl VideoDevice { @@ -40,9 +40,14 @@ impl VideoDevice { layers: [[0x00; VIDEO_BUFFER_LEN]; 2], is_dirty: true, buffer: [0x00; VIDEO_BUFFER_LEN], + vector: 0, } } + pub fn vector(&self) -> u16 { + self.vector + } + pub fn pixels(&mut self) -> &VideoBuffer { if std::mem::take(&mut self.is_dirty) { self.refresh_buffer(); @@ -76,6 +81,15 @@ impl VideoDevice { u16::from_be_bytes([hi, lo]) } + #[inline] + fn deo_vector(&mut self, cpu: &mut Cpu) { + let ports = cpu.device_page::(); + let hi = ports[VideoPorts::VECTOR as usize]; + let lo = ports[VideoPorts::VECTOR as usize + 1]; + + self.vector = u16::from_be_bytes([hi, lo]); + } + fn deo_pixel(&mut self, cpu: &mut Cpu) { self.is_dirty = true; @@ -162,6 +176,7 @@ impl VideoDevice { impl Device for VideoDevice { fn deo(&mut self, cpu: &mut Cpu, target: u8) { match target { + VideoPorts::VECTOR => self.deo_vector(cpu), VideoPorts::X => {} VideoPorts::Y => {} VideoPorts::PIXEL => self.deo_pixel(cpu),