### JSON Preconfiguration Example Source: https://github.com/vc64web/virtualc64web/wiki/json_preconfig This example demonstrates how to use JSON for preconfiguring vc64web settings, including opening ROMs, setting display properties, and specifying a ROM URL. Note the JSON structure for configuration. ```json {"openROMS":true,"wide":true,"border":false,"url":"http://csdb.dk/getinternalfile.php/205484/elite-code-mechanics.prg"} ``` -------------------------------- ### Install and Activate Emscripten SDK Source: https://github.com/vc64web/virtualc64web/wiki/Emscripten Steps to clone the Emscripten SDK repository, install the latest SDK tools, activate a specific SDK version, and set up environment variables for the current terminal session. ```bash # Get the emsdk repo git clone https://github.com/emscripten-core/emsdk.git # Enter that directory cd emsdk # Fetch the latest version of the emsdk (not needed the first time you clone) git pull # Download and install the latest SDK tools. ./emsdk install latest # Make the "latest" SDK "active" for the current user. (writes ~/.emscripten file) ./emsdk activate latest # Activate PATH and other environment variables in the current terminal source ./emsdk_env.sh ``` -------------------------------- ### Preconfigure ROMs and Action Buttons Source: https://github.com/vc64web/virtualc64web/wiki/preconfig An example demonstrating how to preconfigure ROMs to open and define an action button with a specific script. ```json {"openROMS":true,"buttons":[{"position":"bottom:0vh;left:0vw","title":"[w]eapon","key":"w","script":"action('Space')"}]} ``` -------------------------------- ### Autorun Script Preconfiguration Example Source: https://github.com/vc64web/virtualc64web/wiki/json_preconfig This example shows how to configure an autorun script using JSON. It includes setting 'openROMS' and defining a button with a 'run' script that executes a Wasm function and an action. The script is URL-encoded. ```json {"openROMS":true,"buttons":[{"run":true,"script":"await%20wasm_ready_after_reset();action(`'helloworld'`)"}]} ``` -------------------------------- ### Example Script with Loop and Delay Source: https://github.com/vc64web/virtualc64web/wiki/action_sequence_script An example demonstrating a 3-second delay followed by a loop that simulates keyboard 'F' press and joystick fire for 5 times. This illustrates combining delays and loops for action sequences. ```actionscript 3000ms=>loop5{'F'=>j1fire1=>100ms=>j1fire0=>150ms} ``` -------------------------------- ### Build and Run VirtualC64 Source: https://github.com/vc64web/virtualc64web/wiki/build_and_run Follow these commands to build the project and start the local web server. Ensure emsdk is sourced and the repository is cloned. ```bash mkdir b emcmake cmake -S . -B b cd b make run ``` -------------------------------- ### Joystick Port 2 Preconfiguration Example Source: https://github.com/vc64web/virtualc64web/wiki/simple_preconfig This URL demonstrates preconfiguring OpenROMS and enabling joystick port 2 before loading a program. ```url https://vc64web.github.io/#openROMS=true#port2=true#http://csdb.dk/getinternalfile.php/207233/joytester.prg ``` -------------------------------- ### Joystick Port 1 Preconfiguration Example Source: https://github.com/vc64web/virtualc64web/wiki/simple_preconfig This URL shows how to preconfigure OpenROMS and enable joystick port 1 before loading a program. ```url https://vc64web.github.io/#openROMS=true#port1=true#http://csdb.dk/getinternalfile.php/207233/joytester.prg ``` -------------------------------- ### Dual SID Preconfiguration Example Source: https://github.com/vc64web/virtualc64web/wiki/simple_preconfig This URL demonstrates preconfiguring dual SID with OpenROMS, a specific second SID address, and hiding the navbar before loading a program. ```url https://vc64web.github.io/#openROMS=true#2ndSID=d420#navbar=hidden#http://csdb.dk/getinternalfile.php/206403/to_norah.prg ``` -------------------------------- ### TypeScript Class and Button Example Source: https://github.com/vc64web/virtualc64web/blob/master/js/cm/mode/javascript/typescript.html A TypeScript example demonstrating a class definition and creating a button to trigger a greeting. This code can be used to illustrate basic TypeScript syntax. ```typescript class Greeter { greeting: string; constructor (message: string) { this.greeting = message; } greet() { return "Hello, " + this.greeting; } } var greeter = new Greeter("world"); var button = document.createElement('button') button.innerText = "Say Hello" button.onclick = function() { alert(greeter.greet()) } document.body.appendChild(button) ``` -------------------------------- ### URL with OpenROMS and Encoded Script Source: https://github.com/vc64web/virtualc64web/wiki/preconfig A URL example demonstrating how to open ROMs and include a button with a URL-encoded JavaScript script. ```url https://vc64web.github.io/#{"openROMS":true,"buttons":[{"run":true,"script":"alert('hello%20world!')"}]} ``` -------------------------------- ### Enable OpenROMS in vc64web Source: https://github.com/vc64web/virtualc64web/wiki/simple_preconfig Use `openROMS=true` to automatically boot into OpenROMS when no ROMs are installed. This setting should be placed after the emulator address. ```url openROMS=true ``` -------------------------------- ### URL with Base64 Encoded Script Source: https://github.com/vc64web/virtualc64web/wiki/preconfig This URL example shows how to use the 'script_base64' property for larger scripts, providing the base64 encoded version of the JavaScript code. ```url https://vc64web.github.io/#{"openROMS":true,"buttons":[{"run":true,"script_base64":"YWxlcnQoJ2hlbGxvIHdvcmxkIScp"}]} ``` -------------------------------- ### Basic JSON for Buttons Source: https://github.com/vc64web/virtualc64web/wiki/preconfig An example of a JSON object used to define buttons, where the 'buttons' property is an empty array. ```json { "buttons": [] } ``` -------------------------------- ### JSON-LD Data Example Source: https://github.com/vc64web/virtualc64web/blob/master/js/cm/mode/javascript/json-ld.html This is an example of JSON-LD data structure. It defines a context for schema.org terms and provides data for the Empire State Building. ```json { "@context": { "name": "http://schema.org/name", "description": "http://schema.org/description", "image": { "@id": "http://schema.org/image", "@type": "@id" }, "geo": "http://schema.org/geo", "latitude": { "@id": "http://schema.org/latitude", "@type": "xsd:float" }, "longitude": { "@id": "http://schema.org/longitude", "@type": "xsd:float" }, "xsd": "http://www.w3.org/2001/XMLSchema#" }, "name": "The Empire State Building", "description": "The Empire State Building is a 102-story landmark in New York City.", "image": "http://www.civil.usherbrooke.ca/cours/gci215a/empire-state-building.jpg", "geo": { "latitude": "40.75", "longitude": "73.98" } } ``` -------------------------------- ### JSON Key Transformation Example Source: https://github.com/vc64web/virtualc64web/wiki/json_preconfig Illustrates the transformation of a non-standard JSON key like '2ndSID' into a valid JSON key by prefixing it with an underscore. This is necessary for keys that conflict with JSON syntax. ```json {"_2ndSID":"d420"} ``` -------------------------------- ### Custom Target for Running the Application Source: https://github.com/vc64web/virtualc64web/blob/master/CMakeLists.txt Defines a custom target 'run' to copy build artifacts and start a local web server. The server command differs based on the 'thread_type'. ```cmake if("${thread_type}" STREQUAL "worker") #run worker version on local webserver add_custom_target(run COMMAND ${CMAKE_COMMAND} -E copy vc64.html ../index.html COMMAND ${CMAKE_COMMAND} -E copy vc64.js .. COMMAND ${CMAKE_COMMAND} -E copy vc64.ww.js .. COMMAND ${CMAKE_COMMAND} -E copy vc64.wasm .. COMMAND ${CMAKE_COMMAND} -E copy sw.js .. # COMMAND ${CMAKE_COMMAND} -E chdir .. python3 -m http.server 8080 COMMAND ${CMAKE_COMMAND} -E chdir .. python3 ./https.py DEPENDS vc64 ) else() add_custom_target(run COMMAND ${CMAKE_COMMAND} -E copy vc64.html ../index.html COMMAND ${CMAKE_COMMAND} -E copy vc64.js .. COMMAND ${CMAKE_COMMAND} -E copy vc64.wasm .. COMMAND ${CMAKE_COMMAND} -E copy sw.js .. COMMAND ${CMAKE_COMMAND} -E chdir .. python3 -m http.server 8080 DEPENDS vc64 ) endif() ``` -------------------------------- ### Force Light Mode in vc64web Source: https://github.com/vc64web/virtualc64web/wiki/simple_preconfig Use `dark=false` to force vc64web to start in light mode, overriding user preferences. This is useful for embedding on light-themed web pages. ```url dark=false ``` -------------------------------- ### Preconfigure Hidden Action Button with ActionScript Source: https://github.com/vc64web/virtualc64web/wiki/preconfig An example of preconfiguring a hidden action button that remaps key 'a' to 'b' using ActionScript and displays 'HELLO'. ```json {"openROMS":true,"buttons":[{"key":"a","lang":"actionscript","script":"'HELLO'"}]} ``` -------------------------------- ### Basic Player Integration with onclick Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer Embed the emulator into an image element by adding an onclick attribute. The emulator loads when the image is clicked. This example links joystick port 2 to cursor keys and spacebar. ```html ``` -------------------------------- ### Initialize CodeMirror Editor for JavaScript Source: https://github.com/vc64web/virtualc64web/blob/master/js/cm/mode/javascript/index.html Initializes a CodeMirror editor instance from a textarea element. This example demonstrates common options for JavaScript editing, including line numbers, bracket matching, and comment toggling. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, continueComments: "Enter", extraKeys: {"Ctrl-Q": "toggleComment"} }); ``` -------------------------------- ### Embed C64 PRG into HTML Body Source: https://github.com/vc64web/virtualc64web/blob/master/run.html Example of how to embed a C64 PRG file directly into the HTML body. This snippet includes basic CSS for styling the player container and player icons. ```css body { background-color: darkgray; color: white; } #player_container { background-color: darkgray; } #vc64web { border:none; } .player_icon_btn { background-color: transparent; color: white; cursor: pointer; user-select: none; } .btn_play { color: #2575ff; cursor: pointer; } @media (orientation: landscape) { #container { width: 60vw; } } @media (orientation: portrait) { #container { width: 99vw; } } /* uncomment to disable the players icon control bar at the bottom */ /* #player_container div { display: none !important; } */ ``` -------------------------------- ### Get Sprite Y Position Source: https://github.com/vc64web/virtualc64web/wiki/javascript Retrieves the current y-position of a specified sprite. ```javascript function sprite_ypos(0..7) //returns the current x-position of the selected sprite... ``` -------------------------------- ### Preloading D64 with Custom Configuration Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_d64 This HTML snippet demonstrates how to configure the vc64webplayer to load a specific D64 file on startup. It sets various dialog options to false and specifies the URLs for system ROMs and the D64 file. The 'my_demo.d64' file will be loaded when the image is clicked. ```html
``` -------------------------------- ### Get Sprite X Position Source: https://github.com/vc64web/virtualc64web/wiki/javascript Retrieves the current x-position of a specified sprite. ```javascript function sprite_xpos(0..7) //returns the current x-position of the selected sprite... ``` -------------------------------- ### Execute Simple Text Output in C64 Emulator Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_advanced_scripting Use the `exec` method to call a JavaScript function that outputs 'hello world' to the C64 emulator when a link is clicked. This is useful for triggering basic emulator responses from user interface elements. ```html type hello inside the c64 ``` -------------------------------- ### Publish VirtualC64 Build Source: https://github.com/vc64web/virtualc64web/wiki/build_and_run This command copies all necessary files for browser execution into a specified PUBLISH_FOLDER, preparing the project for deployment. ```bash make publish ``` -------------------------------- ### Pass Same-Site File to vc64web Player Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer Assign the created file descriptor to the `vc64web_player.samesite_file` property before calling the load function. This prepares the player to load the specified program. ```javascript vc64web_player.samesite_file=my_file; ``` -------------------------------- ### Configure Datasette Sources and Includes Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/Peripherals/Datasette/CMakeLists.txt Adds include directories and sources for the vc64Core target, including Datasette implementation files. ```cmake target_include_directories(vc64Core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_sources(vc64Core PRIVATE Datasette.cpp DatasetteBase.cpp ) ``` -------------------------------- ### Define Binary File for vc64web Player Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer Specify a C64 program using a `Uint8Array` for the `vc64web_player.samesite_file` property. This is an alternative when you have the program as binary data but cannot upload it as a file. ```javascript vc64web_player.samesite_file={ bin: Uint8Array.from(something), name:'samesite_wolfling.prg' }; ``` -------------------------------- ### Copying Files and Directories with CMake Source: https://github.com/vc64web/virtualc64web/blob/master/CMakeLists.txt This snippet demonstrates using CMake's COMMAND -E copy and copy_directory for deploying project assets. It's used to set up the UAT (User Acceptance Testing) folder with necessary HTML, JS, WASM, CSS, images, ROMs, and sounds. ```cmake COMMAND ${CMAKE_COMMAND} -E rm -f ${UAT_FOLDER}/*.json COMMAND ${CMAKE_COMMAND} -E rm -f ${UAT_FOLDER}/index.html COMMAND ${CMAKE_COMMAND} -E rm -f ${UAT_FOLDER}/run.html COMMAND ${CMAKE_COMMAND} -E copy vc64.html ${UAT_FOLDER}/index.html COMMAND ${CMAKE_COMMAND} -E copy vc64.js ${UAT_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy vc64.wasm ${UAT_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy_directory ../js ${UAT_FOLDER}/js COMMAND ${CMAKE_COMMAND} -E copy_directory ../css ${UAT_FOLDER}/css COMMAND ${CMAKE_COMMAND} -E copy_directory ../img ${UAT_FOLDER}/img COMMAND ${CMAKE_COMMAND} -E copy_directory ../roms ${UAT_FOLDER}/roms COMMAND ${CMAKE_COMMAND} -E copy_directory ../sounds ${UAT_FOLDER}/sounds COMMAND ${CMAKE_COMMAND} -E copy ../run.html ${UAT_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy sw.js ${UAT_FOLDER} ``` -------------------------------- ### Add Subdirectory and Link Libraries Source: https://github.com/vc64web/virtualc64web/blob/master/CMakeLists.txt Includes the 'Emulator' subdirectory and links its output to the main vc64 executable. ```cmake add_subdirectory("Emulator" "vc64Core") target_link_libraries(vc64 vc64Core) ``` -------------------------------- ### Define Same-Site File for vc64web Player Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer Create a file descriptor object to specify a C64 program URL and its name for loading into the vc64web player. This method is useful when CORS is not enabled. ```javascript let my_file={ url:'https://my-c64-website.de/wolfling14.prg', name:'samesite_wolfling.prg' }; ``` -------------------------------- ### Configuring Auto-run Script in vc64webplayer Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_d64 This JavaScript snippet shows how to add an action button to the vc64webplayer configuration. The button's script executes the `load_from_inserted_disk` function after the emulator is ready, automatically loading and running a specified program from the disk. ```javascript any_prg_from_that_disk='myprogram'; // the name of the program on the disk you like to start config.buttons= [{ run: true, script: `await wasm_ready_after_reset();(${load_from_inserted_disk.toString()})('${any_prg_from_that_disk}');` }]; ``` -------------------------------- ### Configure Player with ROM URLs Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_roms Configure the vc64web player to use the specified ROM file URLs and the disk image. This sets up the emulator with custom system files. ```javascript vc64web_player.samesite_file={ floppy_rom_url:floppy_url, basic_rom_url:basic_url, kernal_rom_url:kernal_url, charset_rom_url:charset_url, url:file_url,name:'my_demo.d64' }; ``` -------------------------------- ### Touchscreen Player Integration with JSON config Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer Integrate the player for touch devices by adding ontouchstart and modifying the onclick attribute to use JSON for configuration. This handles touch events and passes configuration via JSON. ```html ``` -------------------------------- ### Complex Game Loop with Sprite Movement and Shooting Source: https://github.com/vc64web/virtualc64web/wiki/javascript An example of a complex game loop that moves a sprite and simulates shooting. It continuously logs sprite positions and executes predefined movement and aiming strategies. ```javascript var x=sprite_xpos(1); var y=sprite_ypos(1); while(not_stopped(this_id)) { console.log('------'+x + ' '+sprite_xpos(1)); await my_move_strategy1(1); await my_aim_and_shoot(1); console.log('------'+x + ' '+sprite_xpos(1)); } async function my_move_strategy1(port) { await action("j"+port+"right1=>850ms"); await action("j"+port+"right0=>800ms"); await action("j"+port+"left1=>450ms"); await action("j"+port+"left0=>800ms"); } async function my_aim_and_shoot(port) { await action("j"+port+"fire1=>j"+port+"left1"); await action("300ms"); await action("j"+port+"left0=>j"+port+"fire0"); } alert('finished the script'); ``` -------------------------------- ### Project and C++ Standard Configuration Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/CMakeLists.txt Sets the minimum CMake version, project name, enables testing, and specifies C++20 as the standard. ```cmake cmake_minimum_required(VERSION 3.16 FATAL_ERROR) # Set the project name project(vc64Core) # Enable testing enable_testing() # Specify the C++ standard set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_EXTENSIONS False) ``` -------------------------------- ### Run Background Script for Progress Bar Source: https://github.com/vc64web/virtualc64web/wiki/preconfig Executes a background script that shows a progress bar upon startup, waits for 3 seconds, and then hides it. ```javascript {"run":true, "script":"$('#alert_wait').show();await action('3000ms');$('#alert_wait').hide();"} ``` -------------------------------- ### Adding Emulator Library Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/CMakeLists.txt Adds the main emulator library 'vc64Core' using specified source files. ```cmake # Add the emulator library add_library(vc64Core VirtualC64.cpp config.cpp) ``` -------------------------------- ### Execute Complex Emulator Actions with Type Errors Simulation Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_advanced_scripting This snippet demonstrates a more advanced use of the `exec` method to simulate user input with simulated typing errors, screen color changes, and disk loading sequences. It utilizes `action` for timed key presses and `disk_loading_finished` to wait for emulator operations. ```html type like a user with type errors ``` -------------------------------- ### Enable Touch Joystick in vc64web Source: https://github.com/vc64web/virtualc64web/wiki/simple_preconfig Set `touch=true` before `port2=true` to enable a touch joystick input for port 2, overriding the default keyboard input. ```url touch=true ``` -------------------------------- ### Initialize CodeMirror with TypeScript Mode Source: https://github.com/vc64web/virtualc64web/blob/master/js/cm/mode/javascript/typescript.html Demonstrates how to initialize a CodeMirror editor from a textarea element, enabling line numbers, bracket matching, and setting the mode to TypeScript. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, mode: "text/typescript" }); ``` -------------------------------- ### Configure Second SID Address in vc64web Source: https://github.com/vc64web/virtualc64web/wiki/simple_preconfig Specify the memory address for a second SID chip using `2ndSID=d420`. Replace `d420` with the desired address. ```url 2ndSID=d420 ``` -------------------------------- ### Define ROM and Disk Image URLs Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_roms Define the URLs for the system ROM files and the disk image to be preloaded. These variables are used in subsequent steps to configure the player. ```html ``` -------------------------------- ### Configure Player with Base64 ROMs Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_roms Configure the vc64web player using Base64 encoded ROM strings. This allows embedding ROM data directly within the HTML, useful for self-contained deployments. ```javascript vc64web_player.samesite_file={ floppy_rom_base64:floppy_base64_encoded, ... }; ``` -------------------------------- ### Include Directories for vc64Core Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/Media/Cartridges/CMakeLists.txt Specifies the include directories for the vc64Core target, using the current source directory. ```cmake target_include_directories(vc64Core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### Include Directories Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/CMakeLists.txt Adds the current source directory to the include paths for the vc64Core library. ```cmake # Add include paths target_include_directories(vc64Core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### General Compile Options Source: https://github.com/vc64web/virtualc64web/blob/master/CMakeLists.txt Sets various compile options for the vc64 target, including warnings, optimization, and Emscripten-specific flags. ```cmake target_compile_options(vc64 PRIVATE -Wall -Werror -Wno-unused-parameter -O3 -mnontrapping-fptoint -fwasm-exceptions -sWASM_LEGACY_EXCEPTIONS=0 -s USE_SDL=2 -Wfatal-errors #-g ) ``` -------------------------------- ### Define Base64 Encoded File for vc64web Player Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer Provide a C64 program as a base64 encoded string to the `vc64web_player.samesite_file` property. This method is useful for embedding program data directly within your HTML or JavaScript. ```javascript vc64web_player.samesite_file={ base64: 'AQgLCB4AnjIwNjEAAACgAHipAI2RA...3z2Z3t2srQ71hMQg3M8g==', name:'samesite_wolfling.prg' }; ``` -------------------------------- ### Configure Player Behavior Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_roms Set player configuration options to disable dialogs for missing ROMs or inserted disks, and to hide the navbar. This provides a streamlined, automated loading experience. ```javascript let config={ dialog_on_missing_roms:false, dialog_on_disk:false, navbar:false }; ``` -------------------------------- ### Initialize Popovers and Tooltips Source: https://github.com/vc64web/virtualc64web/blob/master/shell.html Initializes Bootstrap popovers and tooltips on elements with specific data attributes after the DOM is ready. ```javascript $(function () { $('[data-toggle="popover"]').popover(); //$('data-toggle="tooltip"').tooltip(); $("body").tooltip({selector: '[data-toggle="tooltip"]'}); }); ``` -------------------------------- ### Copy Project Files to Publish Folder Source: https://github.com/vc64web/virtualc64web/blob/master/CMakeLists.txt Copies essential project files and directories to the specified publish folder. This includes HTML, JavaScript, WebAssembly, CSS, images, ROMs, and sounds. ```cmake COMMAND ${CMAKE_COMMAND} -E copy vc64.html ${PUBLISH_FOLDER}/index.html COMMAND ${CMAKE_COMMAND} -E copy vc64.js ${PUBLISH_FOLDER} #the following line is only needed for the worker build #COMMAND ${CMAKE_COMMAND} -E copy vc64.ww.js ${PUBLISH_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy vc64.wasm ${PUBLISH_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy_directory ../js ${PUBLISH_FOLDER}/js COMMAND ${CMAKE_COMMAND} -E copy_directory ../css ${PUBLISH_FOLDER}/css COMMAND ${CMAKE_COMMAND} -E copy_directory ../img ${PUBLISH_FOLDER}/img COMMAND ${CMAKE_COMMAND} -E copy_directory ../roms ${PUBLISH_FOLDER}/roms COMMAND ${CMAKE_COMMAND} -E copy_directory ../sounds ${PUBLISH_FOLDER}/sounds COMMAND ${CMAKE_COMMAND} -E copy ../run.html ${PUBLISH_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy sw.js ${PUBLISH_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy ../manifest.json ${PUBLISH_FOLDER} ``` -------------------------------- ### Simulate Run/Stop Restore Key Press Source: https://github.com/vc64web/virtualc64web/wiki/javascript Executes a simulated run/stop restore key press in the correct order. ```javascript //simulates in the correct order a runstop restore key press wasm_runstop_restore(); ``` -------------------------------- ### Wait for C64 Ready After Reset Source: https://github.com/vc64web/virtualc64web/wiki/javascript Asynchronously waits until the C64 emulator is ready to accept input after a reset. ```javascript //wait until the c64 shows its ready cursor after reset await wasm_ready_after_reset(); ``` -------------------------------- ### JavaScript Function to Load and Run PRG from Disk Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer_d64 This JavaScript function, `load_from_inserted_disk`, is designed to be executed within the vc64webplayer's scripting environment. It takes a program name or '$' (for directory listing) as input and automates the process of loading and running it from the currently inserted disk. ```javascript async function load_from_inserted_disk(prg_or_dir) { if(prg_or_dir != null) { if(prg_or_dir=="$") { await action(`'load"$",8'=>Enter`); await disk_loading_finished(); await action(`'list'=>Enter`); } else { await action(`'load"${prg_or_dir}*",8,1'=>Enter`); await disk_loading_finished(); await action(`'run'=>Enter`); } } } ``` -------------------------------- ### Control Wide Screen and Border in vc64web Source: https://github.com/vc64web/virtualc64web/wiki/simple_preconfig Adjust the display with `wide={true|false}` for a cinematic widescreen effect and `border={true|false}` or `border=0.3` to control the presence and thickness of borders. These settings are not saved to local preferences. ```url wide=true ``` ```url wide=false ``` ```url border=true ``` ```url border=false ``` ```url border=0.3 ``` -------------------------------- ### Initialize JSON-LD CodeMirror Editor Source: https://github.com/vc64web/virtualc64web/blob/master/js/cm/mode/javascript/json-ld.html Initialize a CodeMirror editor for JSON-LD content. Ensure the target element has the ID 'code'. This configuration enables bracket matching, auto-closing brackets, and line wrapping. ```javascript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { matchBrackets: true, autoCloseBrackets: true, mode: "application/ld+json", lineWrapping: true }); ``` -------------------------------- ### Load Same-Site C64 Program via HTML Click Event Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer An HTML image element's click event handler that configures and loads a C64 program using the same-site file injection method. It sets player configurations and the program's URL. ```html Enter"); ``` -------------------------------- ### Compile Definitions and Options for MSVC Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/CMakeLists.txt Sets compile definitions and specific warning/preprocessor options for the MSVC compiler. ```cmake # Specify compile options target_compile_definitions(vc64Core PUBLIC _USE_MATH_DEFINES) if(MSVC) target_compile_options(vc64Core PUBLIC /W4 /WX /Zc:preprocessor) target_compile_options(vc64Core PUBLIC /wd4100 /wd4201 /wd4324 /wd4458 /wd4996) ``` -------------------------------- ### Clean VirtualC64 Build Source: https://github.com/vc64web/virtualc64web/wiki/build_and_run Use this command to clean the build directory, removing all generated build artifacts. ```bash make clean ``` -------------------------------- ### Configure Action Button with JavaScript Source: https://github.com/vc64web/virtualc64web/wiki/preconfig Defines an action button positioned at the bottom left corner. The script is written in JavaScript, which is the default language. ```json {"position":"bottom:0vh;left:0vw", "title":"[w]eapon", "key":"w", "script":"action('Space')"} ``` -------------------------------- ### Clean and Prepare UAT Folder Source: https://github.com/vc64web/virtualc64web/blob/master/CMakeLists.txt Removes existing files and directories within the UAT folder before preparing it for new content. This ensures a clean state for user acceptance testing. ```cmake COMMAND ${CMAKE_COMMAND} -E rm -rf ${UAT_FOLDER}/sounds COMMAND ${CMAKE_COMMAND} -E rm -rf ${UAT_FOLDER}/roms COMMAND ${CMAKE_COMMAND} -E rm -rf ${UAT_FOLDER}/css COMMAND ${CMAKE_COMMAND} -E rm -rf ${UAT_FOLDER}/js COMMAND ${CMAKE_COMMAND} -E rm -rf ${UAT_FOLDER}/img COMMAND ${CMAKE_COMMAND} -E rm -f ${UAT_FOLDER}/vc64.* COMMAND ${CMAKE_COMMAND} -E rm -f ${UAT_FOLDER}/*.js ``` -------------------------------- ### Include vc64web Player Script Source: https://github.com/vc64web/virtualc64web/wiki/vc64webplayer Add this script tag to the end of your HTML's section to include the vc64web player functionality. ```html ``` -------------------------------- ### Simple Loop Execution Source: https://github.com/vc64web/virtualc64web/wiki/action_sequence_script Repeats a sequence of actions a specified number of times. The format is 'loop{}'. ```actionscript loop5{j1fire1=>100ms=>j1fire0=>150ms} ``` -------------------------------- ### Adding Subdirectories Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/CMakeLists.txt Includes other subdirectories, each likely containing their own CMakeLists.txt for modular builds. ```cmake # Add sub directories add_subdirectory(Base) add_subdirectory(Components) add_subdirectory(FileSystems) add_subdirectory(Media) add_subdirectory(Misc) add_subdirectory(Peripherals) add_subdirectory(Utilities) ``` -------------------------------- ### Build Type and Optimization Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/CMakeLists.txt Sets the build type to Release if not specified and configures optimization levels. ```cmake # Set the optimization level (if not specified on the command line) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() ``` -------------------------------- ### JavaScript Action Sequence Script Call Source: https://github.com/vc64web/virtualc64web/wiki/action_sequence_script Demonstrates how to embed Action Sequence Script within JavaScript using the 'action' function. Useful for triggering C64 emulation actions from JavaScript. ```javascript action('j1fire1=>100ms=>j1fire0'); ``` -------------------------------- ### Compiler Options for Non-MSVC Source: https://github.com/vc64web/virtualc64web/blob/master/Emulator/Components/SID/resid/CMakeLists.txt Enables all warnings (-w) for non-MSVC builds. ```cmake target_compile_options(resid PUBLIC -w) ``` -------------------------------- ### Monitor Download Dependencies Source: https://github.com/vc64web/virtualc64web/blob/master/shell.html Tracks the number of remaining dependencies and updates the status message accordingly. Ensures totalDependencies is at least the maximum number of left dependencies. ```javascript monitorRunDependencies: function(left) { this.totalDependencies = Math.max(this.totalDependencies, left); Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.'); } ``` -------------------------------- ### Custom Target for Publishing to GitHub Pages Source: https://github.com/vc64web/virtualc64web/blob/master/CMakeLists.txt Defines a custom target 'publish' to clean and copy build artifacts to a specified deployment folder for GitHub Pages. ```cmake set(PUBLISH_FOLDER "../../vc64web.github.io") add_custom_target(publish COMMAND ${CMAKE_COMMAND} -E rm -rf ${PUBLISH_FOLDER}/roms COMMAND ${CMAKE_COMMAND} -E rm -rf ${PUBLISH_FOLDER}/sounds COMMAND ${CMAKE_COMMAND} -E rm -rf ${PUBLISH_FOLDER}/css COMMAND ${CMAKE_COMMAND} -E rm -rf ${PUBLISH_FOLDER}/js COMMAND ${CMAKE_COMMAND} -E rm -rf ${PUBLISH_FOLDER}/img COMMAND ${CMAKE_COMMAND} -E rm -f ${PUBLISH_FOLDER}/vc64.* COMMAND ${CMAKE_COMMAND} -E rm -f ${PUBLISH_FOLDER}/*.js COMMAND ${CMAKE_COMMAND} -E rm -f ${PUBLISH_FOLDER}/*.json COMMAND ${CMAKE_COMMAND} -E rm -f ${PUBLISH_FOLDER}/index.html COMMAND ${CMAKE_COMMAND} -E rm -f ${PUBLISH_FOLDER}/run.html ) ``` -------------------------------- ### Complex C64 RSS Reader Configuration Source: https://github.com/vc64web/virtualc64web/wiki/preconfig A detailed URL configuration for a C64 RSS reader, including two buttons: one for navigation ('weiter') and another to refresh content using base64 encoded scripts. ```url https://vc64web.github.io/#{"openROMS":true,"buttons":[{"position":"bottom:0vh;right:0vw","title":"weiter","script":"action('Space')"},{"run":true,"script_base64":"ZnVuY3Rpb24gcmVhZF9zY3JlZW5fY2hhcnMobGluZSwgeCwgbGVuKQp7CiAgbGV0IHJlc3VsdCA9ICcnOwogIGZvcig7eDxsZW47eCsrKQogICAgcmVzdWx0ICs9U3RyaW5nLmZyb21DaGFyQ29kZShHQU1NQ09ERU1BUElOR19TVEFSRVQuQ0hBUkFDRVRfQ09ERV9PTEQoNjQpKyB3YXNtX3BlZWsoMHg0MDArNDAqbGluZSt4KSk7CiAgcmV0dXJuIHJlc3VsdDsKfQpmdW5jdGlvbiB3cml0ZV9zY3JlZW5fY2hhcnMobGluZSwgeCwgc3RyKQp7CiAgZm9yKGxldCBpPTA7aTxzdHIubGVuZ3RoO2krKykKICB7CiAgICBsZXQgY29kZSA9IHN0ci5jaGFyQ29kZUF0KGkpOwogICAgd2FzbV9wb2tlKDB4NDAwKzQwKmxpbmUreCtpLCBjb2RlPT0zMj8gY29kZTogY29kZS02NCk7CiAgfQp9CmFzeW5jIGZ1bmN0aW9uIGNsZWFyX3NjcmVlbl9hbmltYXRpb24oKQp7CiAgZm9yKGxldCB6ID0gMDsgeiA8IDI0OyB6KyspCiAgewogICAgYXdhaXQgYWN0aW9uKCI1MG1zIik7IAogICAgd3JpdGVfc2NyZWVuX2NoYXJzKHosMCwiICIucmVwZWF0KDQwKSk7ICAKICB9Cn0KYXN5bmMgZnVuY3Rpb24gbG9hZF9yc3MocmVzcG9uc2UpewogIHRyeXsKICAgIGxldCBmaWxlX2J1ZmZlciA9IG5ldyBVaW50OEFycmF5KGF3YWl0IHJlc3BvbnNlLmFycmF5QnVmZmVyKCkpOwogICAgbGV0IGZpbGVfdXJsX3BhdGggPSByZXNwb25zZS51cmwuc3BsaXQoJy8nKTsKICAgIGxldCBmaWxlX25hbWUgPSBmaWxlX3VybF9wYXRoW2ZpbGVfdXJsX3BhdGgubGVuZ3RoLTFdOwogICAgbGV0IGZpbGVfdHlwZSA9IHdhc21fbG9hZGZpbGUoZmlsZV9uYW1lLCBmaWxlX2J1ZmZlciwgZmlsZV9idWZmZXIuYnl0ZUxlbmd0aCk7ICAgIAogIH0gY2F0Y2goZSkgeyBhbGVydChlKTsgfSAgCn0KYXdhaXQgd2FzbV9yZWFkeV9hZnRlcl9yZXNldCgpOwp3aGlsZShub3Rfc3RvcHBlZCh0aGlzX2lkKSkKewogIGF3YWl0IGNsZWFyX3NjcmVlbl9hbmltYXRpb24oKTsKICB3cml0ZV9zY3JlZW5fY2hhcnMoMTAsNSwiTEFERSBORVVFTiBSU1MgQ09OVEVOVCIpOwogIGF3YWl0IGFjdGlvbigiMjAwMG1zIik7CiAgYXdhaXQgZmV0Y2goYGh0dHBzOi8vcmV0cm9zdHVmZi5jYWZlb2Jza3VyLmRlL3JzczJwcmcucGhwP3Q9JHtuZXcgRGF0ZSgpLmdldFRpbWUoKX0mZG93bmxvYWQ9ZjY0cnNzX2M2NC5wcmdgKS50aGVuKGxvYWRfcnNzKTsgIAogIGF3YWl0IGFjdGlvbigiJ3J1bic9PkVudGVyIik7IAogIHdoaWxlKG5vdF9zdG9wcGVkKHRoaXNfaWQpKXsKICAgICAgIGlmKHJlYWRfc2NyZWVuX2NoYXJzKDIzLDAsNik9PSJSRUFEWW4iKQogICAgICAgICBicmVhazsgICAKICAgIGF3YWl0IGFjdGlvbigiNjBtcyIpOwogIH0KfQ== ``` -------------------------------- ### Cleaning and Copying Worker Files with CMake Source: https://github.com/vc64web/virtualc64web/blob/master/CMakeLists.txt This snippet shows how to clean and then copy specific files and directories to a worker folder using CMake commands. It includes removing old files and copying new ones for the web worker deployment. ```cmake COMMAND ${CMAKE_COMMAND} -E rm -rf ${WORKER_FOLDER}/sounds COMMAND ${CMAKE_COMMAND} -E rm -rf ${WORKER_FOLDER}/roms COMMAND ${CMAKE_COMMAND} -E rm -rf ${WORKER_FOLDER}/css COMMAND ${CMAKE_COMMAND} -E rm -rf ${WORKER_FOLDER}/js COMMAND ${CMAKE_COMMAND} -E rm -rf ${WORKER_FOLDER}/img COMMAND ${CMAKE_COMMAND} -E rm -f ${WORKER_FOLDER}/vc64.* COMMAND ${CMAKE_COMMAND} -E rm -f ${WORKER_FOLDER}/*.js # COMMAND ${CMAKE_COMMAND} -E rm -f ${WORKER_FOLDER}/*.json COMMAND ${CMAKE_COMMAND} -E rm -f ${WORKER_FOLDER}/index.html COMMAND ${CMAKE_COMMAND} -E rm -f ${WORKER_FOLDER}/vc64.html COMMAND ${CMAKE_COMMAND} -E rm -f ${WORKER_FOLDER}/run.html COMMAND ${CMAKE_COMMAND} -E copy vc64.html ${WORKER_FOLDER}/index.html COMMAND ${CMAKE_COMMAND} -E copy vc64.js ${WORKER_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy vc64.ww.js ${WORKER_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy vc64.wasm ${WORKER_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy_directory ../js ${WORKER_FOLDER}/js COMMAND ${CMAKE_COMMAND} -E copy_directory ../css ${WORKER_FOLDER}/css COMMAND ${CMAKE_COMMAND} -E copy_directory ../img ${WORKER_FOLDER}/img COMMAND ${CMAKE_COMMAND} -E copy_directory ../roms ${WORKER_FOLDER}/roms COMMAND ${CMAKE_COMMAND} -E copy_directory ../sounds ${WORKER_FOLDER}/sounds COMMAND ${CMAKE_COMMAND} -E copy ../run.html ${WORKER_FOLDER} COMMAND ${CMAKE_COMMAND} -E copy sw.js ${WORKER_FOLDER} ```