Skip to content

vc64webplayer_advanced_scripting

mithrendal edited this page Jul 26, 2021 · 9 revisions

ok now you have integrated vc64web via the webplayer on your html page ...

🤔 sometimes you want to execute something inside the emulator which is triggered from the users interaction on your page

for example an action link 🤓

imagine you like to click a link on your html page and want as a result something to happen inside the c64 virtual machine.

the webplayer offers the exec method for this.

this method takes a function as an argument exec(your_function)

a hello world example

<script>
function write_hello() { 
   action(`'hello world'`);
}
</script>

<a href="javascript:vc64web_player.exec(write_hello);"> 
  type hello inside the c64 
</a>

lets look this more complex example

<script>
async function write_with_type_errors() { 
 await action(`'l'=>600ms=>'o'=>1400ms=>'a'=>800ms=>'f'`);
 let orig_color = wasm_peek(0xD020);
 for(let i=0;i<16;i++)
 {
   wasm_poke( 0xD020, i%2==1 ? orig_color:2);
   await action("100ms");
 } 
 await action(`'"'=>400ms=>'$"'=>500ms=>',8'=>800ms=>loop6{ArrowLeft=>99ms}=>'d'=>loop5{ArrowRight=>99ms}=>Enter`);
 await disk_loading_finished();
 await action(`3000ms=>'r'=>800ms=>'u'=>400ms=>'n'=>Enter`);
};
</script>
<a href="javascript:vc64web_player.exec(write_with_type_errors);"> 
  type like a user with type errors 
</a>

the next chapter is easy ! Like to learn more ?

customizing the icon bar at the bottom of the webplayer

Clone this wiki locally