Skip to content

Commit

Permalink
Implement video vector callback and add example rom
Browse files Browse the repository at this point in the history
  • Loading branch information
belen-albeza committed Jul 18, 2024
1 parent 188fc69 commit 255ec9b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions coco-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h1>👻-8</h1>
<option value="put_pixel.rom">Pixel (single)</option>
<option value="pixel_fill.rom">Pixel (fill)</option>
<option value="sprite.rom">Sprite</option>
<option value="sprite_move.rom">Moving Sprite</option>
</select>

<div>
Expand Down
2 changes: 1 addition & 1 deletion coco-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Binary file added coco-ui/roms/sprite_move.rom
Binary file not shown.
3 changes: 1 addition & 2 deletions coco-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ impl Vm {
}

pub fn on_video(&mut self, cpu: &mut Cpu) -> DeviceOutput {
// TODO: call video vector
cpu.run(0x200, self);
cpu.run(self.video.vector(), self);
self.output()
}

Expand Down
17 changes: 16 additions & 1 deletion coco-vm/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +31,7 @@ pub struct VideoDevice {
pub layers: [VideoBuffer; 2],
is_dirty: bool,
buffer: VideoBuffer,
vector: u16,
}

impl VideoDevice {
Expand All @@ -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();
Expand Down Expand Up @@ -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::<VideoPorts>();
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;

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 255ec9b

Please sign in to comment.