Skip to content

Commit

Permalink
Replace the old animation rom for a pacman-themed one (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
belen-albeza authored Jul 19, 2024
1 parent 0eea85a commit dd6740b
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 61 deletions.
2 changes: 1 addition & 1 deletion coco-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1>👻-8</h1>
<option value="put_pixel">Pixel (single)</option>
<option value="pixel_fill">Pixel (fill)</option>
<option value="sprite">Sprite</option>
<option value="sprite_move">Moving Sprite</option>
<option value="pacman">Animation</option>
</select>
</label>
<div>
Expand Down
Binary file added coco-ui/roms/pacman.rom
Binary file not shown.
85 changes: 85 additions & 0 deletions coco-ui/roms/pacman.tal
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
( sprite animation )
|10 @Screen &vector $2 &x $1 &y $1 &pixel $1 &pad $3 &address $2 &sprite $1

%MOD { DUP2 DIV MUL SUB } ( a b -- a%b )

|0000
@x $1
@t $1
@pacman-spr $2

|0100 ( -> )
;on-frame .Screen/vector DEO2

( init vars )
;pacman00 .pacman-spr STZ2
#00 .t STZ
#00 .x STZ

( draw bg )
#21 .Screen/pixel DEO
BRK

@on-frame ( -> )
( clear foreground )
#00 .Screen/x DEO
#00 .Screen/y DEO
#30 .Screen/pixel DEO

( move party )
.x LDZ INC #c0 MOD DUP

.x STZ .Screen/x DEO

( handle animation time )
.t LDZ INC DUP .t STZ #0f EQU ,&update-frame JCN ,&draw-pacman JMP
&update-frame
#00 .t STZ
.pacman-spr LDZ2 ;pacman00 EQU2 ,&change-to-01 JCN ,&change-to-00 JMP
&change-to-01
;pacman01 .pacman-spr STZ2 ,&draw-pacman JMP
&change-to-00
;pacman00 .pacman-spr STZ2

( draw pacman )
&draw-pacman
#44 .Screen/y DEO
.pacman-spr LDZ2 .Screen/address DEO2
#10 .Screen/sprite DEO

( draw ghost )
&draw-ghost
;coco .Screen/address DEO2
.x LDZ #0f ADD #c0 MOD .Screen/x DEO
#10 .Screen/sprite DEO
BRK

@coco
0077 7700
0777 7770
6717 7176
7f77 77f7
7711 1177
7772 8777
7777 7777
7607 7067

@pacman00
00aa aa00
0aa1 8aa0
9aaa a000
9aa0 0000
99a0 0000
99aa a000
0999 aaa0
0099 9900

@pacman01
00aa aa00
0aaa aaa0
9aaa 18aa
9aaa aaaa
99aa aaaa
99aa aaaa
0999 aaa0
0099 9900
Binary file removed coco-ui/roms/sprite_move.rom
Binary file not shown.
38 changes: 0 additions & 38 deletions coco-ui/roms/sprite_move.tal

This file was deleted.

5 changes: 4 additions & 1 deletion coco-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ pub fn run_rom(rom: &[u8]) -> Result<Output> {
render(&mut vm.borrow_mut(), &ctx, &mut canvas_buffer);

*g.borrow_mut() = Some(Closure::new(move || {
vm.borrow_mut().on_video(&mut cpu.borrow_mut());
let on_video_output = vm.borrow_mut().on_video(&mut cpu.borrow_mut());
if on_video_output.sys_stdout.len() > 0 {
web_sys::console::log_1(&JsValue::from(on_video_output.sys_stdout));
}
render(&mut vm.borrow_mut(), &ctx, &mut canvas_buffer);
request_animation_frame(f.borrow().as_ref().unwrap())
}));
Expand Down
49 changes: 28 additions & 21 deletions coco-ui/vendor/coco_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ function takeObject(idx) {
return ret;
}

const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );

if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };

let cachedUint8Memory0 = null;

function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
Expand Down Expand Up @@ -96,15 +114,6 @@ function debugString(val) {

let WASM_VECTOR_LEN = 0;

let cachedUint8Memory0 = null;

function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}

const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );

const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
Expand Down Expand Up @@ -168,15 +177,6 @@ function getInt32Memory0() {
return cachedInt32Memory0;
}

const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );

if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}

const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(state => {
Expand Down Expand Up @@ -207,7 +207,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
CLOSURE_DTORS.register(real, state, state);
return real;
}
function __wbg_adapter_14(arg0, arg1) {
function __wbg_adapter_16(arg0, arg1) {
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hbe6b0b61f022bb4f(arg0, arg1);
}

Expand Down Expand Up @@ -366,6 +366,10 @@ function __wbg_get_imports() {
const ret = false;
return ret;
};
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbg_instanceof_Window_f401953a2cf86220 = function(arg0) {
let result;
try {
Expand Down Expand Up @@ -405,6 +409,9 @@ function __wbg_get_imports() {
const ret = new ImageData(getClampedArrayU8FromWasm0(arg0, arg1), arg2 >>> 0, arg3 >>> 0);
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_log_5bb5f88f245d7762 = function(arg0) {
console.log(getObject(arg0));
};
imports.wbg.__wbg_instanceof_HtmlCanvasElement_46bdbf323b0b18d1 = function(arg0) {
let result;
try {
Expand Down Expand Up @@ -461,8 +468,8 @@ function __wbg_get_imports() {
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};
imports.wbg.__wbindgen_closure_wrapper25 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 3, __wbg_adapter_14);
imports.wbg.__wbindgen_closure_wrapper27 = function(arg0, arg1, arg2) {
const ret = makeMutClosure(arg0, arg1, 3, __wbg_adapter_16);
return addHeapObject(ret);
};

Expand Down
Binary file modified coco-ui/vendor/coco_ui_bg.wasm
Binary file not shown.

0 comments on commit dd6740b

Please sign in to comment.