### Install and Run TIC-80 App (Release/Debug) Source: https://github.com/nesbox/tic-80/blob/main/build/android/readme.md Installs either the release or debug version of the TIC-80 APK and then starts the application. Ensure the correct APK path is used. ```bash release: adb install -r app/build/outputs/apk/arm8/release/app-arm8-release.apk && adb shell am start -n com.nesbox.tic/com.nesbox.tic.TIC debug: adb install -r app/build/outputs/apk/arm8/debug/app-arm8-debug.apk && adb shell am start -n com.nesbox.tic/com.nesbox.tic.TIC ``` -------------------------------- ### Initialize with BOOT in Fennel Source: https://github.com/nesbox/tic-80/wiki/BOOT Use the BOOT function for initialization in Fennel. The first example shows a basic setup, while the second demonstrates initializing a variable 't' and using it in the main TIC loop. ```fennel ;; script: fennel (global TIC (fn boot [] ;; Put your stuff here ) ) ;;alternate fennel (var t 0) (fn _G.BOOT [] ;; use for init stuff (set t 100)) (fn _G.TIC [] (print t)) ``` -------------------------------- ### Compile and Link S7 FFI Example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Example GCC commands for compiling and linking an S7 FFI (Foreign Function Interface) example on Linux. Includes necessary flags for dynamic linking. ```bash gcc -c s7.c -I. gcc -o ex1 ex1.c s7.o -lm -I. -ldl -Wl,-export-dynamic ``` -------------------------------- ### Old Build: Start in Fullscreen Mode Source: https://github.com/nesbox/tic-80/wiki/Command-Line-Arguments Starts TIC-80 in fullscreen mode for older builds, maximizing the display area. ```bash tic80 -fullscreen ``` -------------------------------- ### s7 REPL example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Example of starting a Read-Eval-Print Loop (REPL) in s7 Scheme, possibly using 'repl.scm'. ```scheme (load "repl.scm") ``` -------------------------------- ### Prototype System Example with openlet Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Demonstrates a prototype-based system where objects can have methods defined dynamically. This example creates two environments, e1 and e2, with 'x' and '*' methods, showcasing inheritance and modification. ```scheme (let* ((e1 (openlet (inlet 'x 3 '* (lambda args (apply * (if (number? (car args)) (values (car args) ((cadr args) 'x) (cddr args)) (values ((car args) 'x) (cdr args)))))))) (e2 (copy e1))) (set! (e2 'x) 4) (\* 2 e1 e2)) ; (\* 2 3 4) => 24 ``` -------------------------------- ### s7 nREPL example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Example of starting a nREPL (New REPL) in s7 Scheme, likely using 'nrepl.scm'. ```scheme (load "nrepl.scm") ``` -------------------------------- ### Install Dependencies with WinGet (Windows) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs Git, CMake, and Ruby+DevKit using the Windows Package Manager. Ensure PowerShell is run with elevated privileges. ```powershell winget install Git.Git Kitware.CMake RubyInstallerTeam.RubyWithDevKit.2.7 ``` -------------------------------- ### Compile and Run Bignum Example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Compilation and linking commands for the bignum example using GCC, including necessary flags and libraries (gmp, mpfr, mpc). Also shows example usage in the s7 REPL. ```bash /* * gcc -DWITH_GMP=1 -c s7.c -I. -O2 -g3 * gcc -DWITH_GMP=1 -o gmpex gmpex.c s7.o -I. -O2 -lm -ldl -lgmp -lmpfr -lmpc * * gmpex * > (add-1 1) * 2 * > (add-1 2/3) * 5/3 * > (add-1 1.4) * 2.4 * > (add-1 1.5+i) * 2.5+1i * > (add-1 (bignum 3)) * 4 * > (add-1 (bignum 3/4)) * 7/4 * > (add-1 (bignum 2.5)) * 3.500E0 * > (add-1 (bignum 1.5+i)) * 2.500E0+1.000E0i */ ``` -------------------------------- ### Define-f*xpr Macro Usage Example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Example demonstrating the usage of 'define-f*xpr' to create a macro 'mac' that adds 1 to its argument. ```scheme > (define-f*xpr (mac a) `(+ ,a 1)) ``` ```scheme > (mac (\* 2 3)) ``` -------------------------------- ### Install Dependencies using WinGet Source: https://github.com/nesbox/tic-80/blob/main/README.md This command installs Git, CMake, Visual Studio 2019 Build Tools, and Ruby+DevKit using the Windows Package Manager (WinGet). This is a convenient way to set up the build environment for 64-bit Windows. ```powershell winget install Git.Git Kitware.CMake Microsoft.VisualStudio.2019.BuildTools RubyInstallerTeam.RubyWithDevKit.2.7 ``` -------------------------------- ### Install Build Dependencies (Fedora 36) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs development tools, libraries, and Ruby gems for building TIC-80 on Fedora 36. Includes specific packages for OpenGL, SDL, and PipeWire. ```bash sudo dnf -y groupinstall "Development Tools" "Development Libraries" sudo dnf -y install ruby rubygem-{tk{,-doc},rake,test-unit} cmake libglvnd-devel libglvnd-gles freeglut-devel clang libXext-devel SDL_sound pipewire-devel pipewire-jack-audio-connection-kit-devel pulseaudio-libs-devel ``` -------------------------------- ### Install Build Dependencies (Fedora 40) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs development tools, libraries, and Ruby gems for building TIC-80 on Fedora 40. Includes packages for Wayland, SDL2, PipeWire, and OpenGL. ```bash sudo dnf -y groupinstall "Development Tools" "Development Libraries" sudo dnf -y install ruby-devel rubygem-rake cmake clang pipewire-devel SDL2-devel SDL2_sound-devel SDL2_gfx-devel wayland-devel libXext-devel pipewire-jack-audio-connection-kit-devel pipewire-jack-audio-connection-kit-devel pulseaudio-libs-devel rubygems-devel libdecor-devel libdrm-devel mesa-libgbm-devel esound-devel freeglut-devel ``` -------------------------------- ### Define-bacro Expansion and Evaluation Examples Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Demonstrates the four ways define-bacro can expand and evaluate in different environments. Use these examples to understand macro behavior in various contexts. ```scheme (let ((x 1) (y 2)) (define-bacro (bac1 a) `(+ ,x y ,a)) ; expand and eval in calling env (let ((x 32) (y 64)) (bac1 3))) ``` ```scheme (let ((x 1) (y 2)) ; this is like define-macro (define-bacro (bac2 a) (with-let (sublet (funclet bac2) :a a) `(+ ,x y ,a))) ; expand in definition env, eval in calling env (let ((x 32) (y 64)) (bac2 3))) ``` ```scheme (let ((x 1) (y 2)) (define-bacro (bac3 a) (let ((e (with-let (sublet (funclet bac3) :a a) `(+ ,x y ,a)))) `(with-let ,(sublet (funclet bac3) :a a) ,e))) ; expand and eval in definition env (let ((x 32) (y 64)) (bac3 3))) ``` ```scheme (let ((x 1) (y 2)) (define-bacro (bac4 a) (let ((e `(+ ,x y ,a))) `(with-let ,(sublet (funclet bac4) :a a) ,e))) ; expand in calling env, eval in definition env (let ((x 32) (y 64)) (bac4 3))) ``` -------------------------------- ### Example Custom Input Function in s7 Scheme Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html An example implementation of a custom input function for s7 Scheme, demonstrating how to handle different read choices. ```c static s7_pointer my_read(s7_scheme *sc, s7_read_t peek, s7_pointer port) { /* this function should handle input according to the peek choice */ return(s7_make_character(sc, '0')); } ``` -------------------------------- ### Install Build Dependencies (openSUSE) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs necessary development packages and libraries for TIC-80 on openSUSE Tumbleweed/Leap 16.0, including CMake, OpenGL, and PipeWire development files. ```bash sudo zypper refresh sudo zypper install --no-confirm --type pattern devel_basis sudo zypper install --no-confirm cmake glu-devel libXext-devel pipewire-devel libcurl-devel ``` -------------------------------- ### Install Dependencies and Build TIC-80 on FreeBSD Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs required system packages and builds TIC-80 from source on FreeBSD. It also includes a step to create a symbolic link for Mesa's swrast_dri.so. ```bash sudo pkg install gcc git cmake ruby libglvnd libglu freeglut mesa-devel mesa-dri alsa-lib git clone --recursive https://github.com/nesbox/TIC-80 && cd TIC-80/build cmake -DBUILD_WITH_ALL=On .. make -j4 ``` ```bash sudo ln -s /usr/local/lib/dri/swrast_dri.so /usr/local/lib/dri-devel/ ``` -------------------------------- ### Install Dependencies and Build TIC-80 on Raspberry Pi (Retropie) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs required packages and builds TIC-80 on Retropie, including adding a backports repository for specific library versions. This process may take a significant amount of time. ```bash # required public keys gpg --keyserver pgpkeys.mit.edu --recv-key 8B48AD6246925553 gpg -a --export 8B48AD6246925553 | sudo apt-key add - gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010 gpg -a --export 7638D0442B90D010 | sudo apt-key add - # upgrade system sudo apt-get update sudo apt-get dist-upgrade # install software sudo apt-get install git build-essential ruby-full libsdl2-dev zlib1g-dev sudo apt-get install -t jessie-backports liblua5.3-dev git clone --recursive https://github.com/nesbox/TIC-80 && cd TIC-80/build cmake -DBUILD_WITH_ALL=On .. ``` ```bash # install software ubuntu 22.04.3 LTS sudo apt-get install git build-essential ruby-full libsdl2-dev zlib1g-dev sudo apt-get install liblua5.3-dev sudo apt-get install libcurl4-openssl-dev git clone --recursive https://github.com/nesbox/TIC-80 && cd TIC-80/build cmake -DBUILD_WITH_ALL=On .. ``` -------------------------------- ### Install CMake and Build Dependencies (Ubuntu 22.04) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs necessary build tools and libraries for TIC-80 on Ubuntu 22.04, including CMake from Kitware's repository, essential development packages, and SDL2 development files. It also sets up the Kitware archive keyring. ```bash # Install the latest CMake from https://apt.kitware.com test -f /usr/share/doc/kitware-archive-keyring/copyright || \ wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null sudo apt-get update test -f /usr/share/doc/kitware-archive-keyring/copyright || \ sudo rm /usr/share/keyrings/kitware-archive-keyring.gpg sudo apt-get install kitware-archive-keyring sudo apt update && sudo apt -y install build-essential cmake git libpipewire-0.3-dev libwayland-dev libsdl2-dev ruby-dev libglvnd-dev libglu1-mesa-dev freeglut3-dev libcurl4-openssl-dev ``` -------------------------------- ### Using the Output Log Port Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Demonstrates how to use the `open-output-log` function to create a log file and write formatted strings to it. ```scheme (let ((p (open-output-log "logit.data"))) (format p "this is a test~%") (format p "line: ~A~%" 2)) ``` -------------------------------- ### Define and Use a Simple Macro Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Demonstrates defining a macro `mac` that uses startup values for `_+` and `_#_let`. Shows how macro expansion results in different values based on the environment. ```scheme (define-macro (mac b) `( _#_let_ ((a 12)) (_#_+ a ,b))) ; #_+ and #_+ are start-up values _mac_ ``` ```scheme > (let ((a 1) (+ *)) (mac a)) _24 ; (+ a a) where a is 12 and + is the start-up +_ ``` -------------------------------- ### Get Time Source: https://github.com/nesbox/tic-80/wiki/Cheatsheet Returns the current time in milliseconds since the system started. ```lua time -> milliseconds ``` -------------------------------- ### Modulo Operator Example Source: https://github.com/nesbox/tic-80/wiki/A-step-by-step-introduction-to-TIC-80,-Part-1---The-Default-Cart Demonstrates the modulo operator (%) in Lua, showing how it returns the remainder of a division. ```lua 150%60=30 ``` -------------------------------- ### Prevent Music Restart in TIC-80 Source: https://github.com/nesbox/tic-80/wiki/music This example demonstrates how to prevent a music track from continuously restarting when called within the TIC() function. It uses a boolean flag to ensure the music starts only once. ```lua musicplaying = false function TIC() -- ensure we only start the music a single time if not musicplaying then music(0) musicplaying = true end end ``` -------------------------------- ### Create and Use a Hash Table Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Demonstrates basic hash table creation and usage with string keys. Hash tables grow as needed, and keys not present return #f. ```scheme (let ((ht (make-hash-table))) (set! (ht "hi") 123) (ht "hi")) ``` -------------------------------- ### Compilation and Execution Example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Provides compilation instructions for Linux and Mac OSX, and demonstrates the execution flow by loading a shared library and calling its functions from s7 Scheme. ```bash /* Put the module in the file ex3a.c and the main program in ex3.c, then * * in Linux: * gcc -c -fPIC ex3a.c * gcc ex3a.o -shared -o ex3a.so * gcc -c s7.c -I. -fPIC -shared * gcc -o ex3 ex3.c s7.o -lm -ldl -I. -Wl,-export-dynamic * # omit -ldl in freeBSD * * in Mac OSX: * gcc -c ex3a.c * gcc ex3a.o -o ex3a.so -dynamic -bundle -undefined suppress -flat_namespace * gcc -c s7.c -I. -dynamic -bundle -undefined suppress -flat_namespace * gcc -o ex3 ex3.c s7.o -lm -ldl -I. * * and run it: * ex3 * > (cload "/home/bil/snd-18/ex3a.so" "init_ex") * _#t_ * > (add-1 2) * _3_ * > (try "a_function" 2.5) * _3.5_ */ ``` -------------------------------- ### Import All Library Bindings with Prefix Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Import all top-level bindings from a library into the current environment, prepending a prefix to each name. This uses `varlet`, `load`, `map`, and `curlet`. ```scheme (varlet (curlet) (with-let (unlet) (let () (load "any-library.scm" (curlet)) (curlet)))) ; these are the bindings introduced by loading the library ``` ```scheme (apply varlet (curlet) (with-let (unlet) (let () (load "any-library.scm" (curlet)) (map (lambda (binding) (cons (symbol "library:" (symbol->string (car binding))) (cdr binding))) (curlet))))) ``` -------------------------------- ### Add Dialogue Example Source: https://github.com/nesbox/tic-80/wiki/How-to-make-Text-box An example of how to call the `addDialogues` function to populate the text box with initial dialogue. ```lua addDialogues( { "Hello World!" } ) ``` -------------------------------- ### let* with named parameters Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Illustrates the usage of let* with named parameters, showing how variables are bound sequentially. ```scheme (let ((c :a)) (f2 c 3 c 4)) ``` -------------------------------- ### BOOT() - Initialization Callback Source: https://context7.com/nesbox/tic-80/llms.txt Called once when the cartridge boots up, before the first TIC() call. This is the preferred place for initializing game state and variables. ```APIDOC ## BOOT() ### Description Called a single time when the cartridge first boots, before the first `TIC()` call. Use it for initialization instead of global-scope code (preferred in Lua and similar scripting languages). ### Method Callback ### Parameters None ### Request Example ```lua -- script: lua local score = 0 local player = {} function BOOT() -- initialize player state once player.x = 120 player.y = 68 player.speed = 2 score = pmem(0) -- load saved high score from persistent memory trace("Booted! High score: " .. score) end function TIC() cls(1) spr(1, player.x, player.y, 0) print("Score: " .. score, 4, 4, 15) if btn(2) then player.x = player.x - player.speed end if btn(3) then player.x = player.x + player.speed end end ``` ``` -------------------------------- ### Install Build Dependencies (Ubuntu 24.04) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs necessary build tools and libraries for TIC-80 on Ubuntu 24.04, including essential development packages, SDL2 development files, and Wayland support. It assumes CMake is already installed or will be handled by apt. ```bash sudo apt update && sudo apt -y install build-essential cmake git libpipewire-0.3-dev libwayland-dev libsdl2-dev ruby-dev libcurl4-openssl-dev libglvnd-dev libglu1-mesa-dev freeglut3-dev ``` -------------------------------- ### s7 lint example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Example demonstrating the use of 'lint' in s7 Scheme, likely for code analysis or style checking. ```scheme (lint "(define (fact n) (if (<= n 1) 1 (* n (fact (- n 1)))))") ``` -------------------------------- ### Initialize with BOOT in Janet Source: https://github.com/nesbox/tic-80/wiki/BOOT Define the BOOT function in Janet for cartridge initialization. This example also shows initializing a variable 't' and setting it in BOOT. ```janet # script: janet (var t 0) (defn BOOT # put your stuff here (set t 10)) ``` -------------------------------- ### Configure and Build Project Source: https://github.com/nesbox/tic-80/blob/main/build/nswitch/README.md Use these CMake commands to configure the build with the Switch toolchain and then build the project. The output executable 'tic80.nro' will be located in the build/bin directory. ```bash cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/cmake/Switch.cmake cmake --build build ``` -------------------------------- ### s7 debug example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Example showing debugging capabilities in s7 Scheme. This might involve setting breakpoints or inspecting variables. ```scheme (debug (lambda (x) (+ x 1))) ``` -------------------------------- ### Dynamic Lambda Construction with Apply Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Demonstrates constructing and executing a lambda function dynamically using 'let*' and 'apply lambda', showcasing code generation and execution. ```scheme (let* ((x 3) (arg '(x)) (body `((+ ,x x 1)))) ((apply lambda arg body) 12)) ; "legolambda"? ``` -------------------------------- ### Get Spritesheet Pixel (Lua) Source: https://github.com/nesbox/tic-80/wiki/Code-examples-and-snippets Gets a pixel from the spritesheet. Assumes a 128x256 image mapped from 512 consecutive 8x8 sprites. ```lua -- get spritesheet pixel function sget(x,y) local addr=0x4000+(x//8+y//8*16)*32 -- get sprite address return peek4(addr*2+x%8+y%8*8) -- get sprite pixel end ``` -------------------------------- ### Implement a Probe with *function*, Bacro, and Openlet Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html This example demonstrates how to implement a probe using *function* for call-time function names, a bacro to access the call-time environment, and an openlet for managing scope. It reports operations involving the probe. ```scheme (define (probe-eval val) (let ((all-let (inlet))) (for-each (lambda (sym) (unless (immutable? sym) ; apply-values etc (let ((func (symbol->value sym (rootlet)))) (when (procedure? func) (varlet all-let sym (apply _bacro_ 'args \`((let-temporarily (((\*s7\'openlets) #f)) (let ((clean-args (map (lambda (arg) (if (eq? arg probe-eval) (probe-eval 'value) arg)) ``` -------------------------------- ### 256 Shades of Gray Example Source: https://github.com/nesbox/tic-80/wiki/SCN Displays 256 shades of gray by manipulating the palette for each scanline. This example requires the 'lua' script and 'mouse' input. ```lua -- title: 256 shades of gray -- author: Marcuss2, fixed by nesbox -- desc: Showoff of grayscale -- script: lua -- input: mouse ADDR = 0x3FC0 palette = 0 function addLight() for i=0, 15 do for j=0, 2 do poke(ADDR+(i*3)+j, palette) end palette = palette + 1 end end function SCN(scnline) if scnline % 8 == 0 then addLight() end end function init() for i=0, 16 do rect(i*15, 0, 15, 240, i) end end init() function TIC() palette = 0 end ``` -------------------------------- ### Initialize Game State and Variables Source: https://github.com/nesbox/tic-80/wiki/Building-a-Menu Sets up initial game variables, including time, game speed, current mode, player and enemy positions, and cursor state. This function is called once at the start. ```lua --title: --author: Bear Thorne --desc: --script: lua --notice the defaults assigned in the init() --function... function init() t=0 gamespeed=10 mode="menu" p={x=8 ,y=1 } e={x=21,y=15} temp=1 cursor=PLAY end --cursor placement constants PLAY={x=12*8-1,y=9*8-1} SETTINGS={x=16*8-1,y=9*8-1} init() function TIC() if mode=="menu" then ------------------------------------- --------menu screen code------------- ------------------------------------- cls() map(30,0,60,17) print("CLINGY",13*8,3*8,2) --press left for game if btnp(2) then cursor=PLAY end --press right for settings if btnp(3) then cursor=SETTINGS end --draw the cursor rectb(cursor.x,cursor.y,18,18,13) --press (A) to select current option if btnp(4) then if cursor==PLAY then mode="game" end if cursor==SETTINGS then mode="settings" end end ------------------------------------- --------settings screen code--------- ------------------------------------- elseif mode=="settings" then cls() map(60,0,90,17) print("SETTINGS",12*8,3*8,6) print("GAME SPEED: ",10*8,9*8+2,6) rect(18*8,9*8,15,8,15) print(temp,18*8+2,9*8+2,6) print("Press A to Accept",9*8,13*8,6) if btnp(0,6,3) and temp<10 then temp=temp+1 end if btnp(1,6,3) and temp>1 then temp=temp-1 end --press (A) to accept if btnp(4) then mode="menu" gamespeed=11-temp end elseif mode=="game" then -------------------------------------- ----------game screen code------------ -------------------------------------- if btnp(0,6,10) and mget(p.x,p.y-1)~= 17 then p.y=p.y-1 end if btnp(1,6,10) and mget(p.x,p.y+1)~= 17 then p.y=p.y+1 end if btnp(2,6,10) and mget(p.x-1,p.y)~= 17 then p.x=p.x-1 end if btnp(3,6,10) and mget(p.x+1,p.y)~= 17 then p.x=p.x+1 end if t%gamespeed==0 then if e.x>p.x and mget(e.x-1,e.y)~=17 then e.x=e.x-1 elseif e.xp.y and mget(e.x,e.y-1)~=17 then e.y=e.y-1 elseif e.y global volume value [0-15] --cli console only output --fullscreen enable fullscreen mode --vsync enable VSYNC --soft use software rendering --fs= path to the file system folder --scale= main window scale --cmd= run commands in the console --keepcmd re-execute commands on every run --version print program version --crt enable CRT monitor effect ``` -------------------------------- ### Truncate List Example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html An example function `truncate-if` that uses `map-with-exit` to stop processing a list early if a condition is met. It returns the elements processed up to the point of truncation. ```scheme (define (truncate-if func lst) (map-with-exit (lambda (escape x) (if (func x) (escape) x)) lst)) ``` -------------------------------- ### Using Apply Define* with Symbol Keywords Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Shows how to use 'apply define*' with a symbol that is converted to a keyword, demonstrating dynamic definition of functions with symbol-based argument names. ```scheme (let ((funny-name (string->symbol "| e t c |"))) ; now use it as a keyword arg to a function (apply define* `((func (,funny-name 32)) (+ ,funny-name 1))) ;; (procedure-source func) is (lambda* ((| e t c | 32)) (+ | e t c | 1)) (apply func (list (symbol->keyword funny-name) 2))) ``` -------------------------------- ### Build Fennel Source: https://github.com/nesbox/tic-80/blob/main/vendor/fennel/README.md Navigate into the cloned Fennel directory and execute the make command to build the library. ```sh cd fennel make ``` -------------------------------- ### OVR() Example: Overlap Demo Source: https://github.com/nesbox/tic-80/wiki/OVR This example demonstrates using OVR() to draw a sprite with a static palette that is not affected by BDR() palette swaps. It requires the BDR() function to be defined. ```lua -- title: Overlap demo -- author: librorumque -- desc: OVR() example -- script: lua PALETTE_ADDR=0x03FC0 CHANGE_COL=8 SCANLINES=144 x=96 y=24 function BDR(line) --[[ Gradient background ]] local color=(0xff*line/SCANLINES) poke(PALETTE_ADDR+3*CHANGE_COL, color) end function OVR() --[[ This sprite uses the same blue as the background, but it's not affected by BDR() palette swap ]] spr(1,x,y,14,3,0,0,2,2) end function TIC() cls(CHANGE_COL) print("OVR() example", 85, 3, 12) print("Press up or down to move the sprite", 22, 10, 12) if btn(0) then y=y-1 end if btn(1) then y=y+1 end end ``` -------------------------------- ### s7 Macro Expansion Example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Demonstrates how a custom macro 'rmac' expands in s7, showing its transformation into a 'begin' block with display calls. ```scheme () (if (null? (cdr args)) `(display ',(car args)) (list 'begin (display ',(car args)) (apply macroexpand (list (cons 'rmac (cdr args)))))))) ``` ```scheme > (macroexpand (rmac a b c)) _(begin (display 'a) (begin (display 'b) (display 'c)))_ ``` ```scheme > (begin (rmac a b c d) (newline)) _abcd_ ``` -------------------------------- ### Install Build Dependencies (Arch Linux) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs essential build tools and libraries for TIC-80 on Arch Linux, including CMake, Ruby, Mesa, and OpenGL development files. ```bash sudo pacman -S cmake ruby mesa libglvnd glu ``` -------------------------------- ### Create New Project in Specific Language Source: https://github.com/nesbox/tic-80/wiki/Supported-Languages Use the `new` command in the TIC-80 console to initialize a project for a chosen scripting language. Type `help new` for language-specific arguments. ```bash new wren ``` -------------------------------- ### Build Bunnymark WASM with Zig Source: https://github.com/nesbox/tic-80/blob/main/demos/bunny/wasmmark/README.md Use this command to build the WASM binary for the Bunnymark demo. Ensure you have Zig 0.14.0-dev.1421 or newer installed. ```bash zig build --release=small ``` -------------------------------- ### Get Help String Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Retrieves a help string for a Scheme object. This might provide more detailed information than `s7_documentation`. ```c const char *s7_help(s7_scheme *sc, s7_pointer obj); ``` -------------------------------- ### Peek Nibble Example Source: https://github.com/nesbox/tic-80/wiki/peek Demonstrates how to set a byte and then read its individual nibbles using peek4. Note that memory is sequenced with least significant nibbles first. ```lua -- set byte address 0x4000 to the value 0xF1 (241) poke(0x4000, 0xF1) -- the low nibble (least significant bits) peek4(0x8000) -- => 1 (0x01) -- the high nibble (most significant bits) peek4(0x8001) -- => 15 (0x0F) ``` -------------------------------- ### Define s7 Function in C (add1 example) Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html A simpler example defining an `add1` function in C that takes an integer and returns the integer incremented by 1. It includes error handling for non-integer arguments. ```c #include #include "s7.h" static s7_pointer add1(s7_scheme *sc, s7_pointer args) { if (s7_is_integer(s7_car(args))) return(s7_make_integer(sc, 1 + s7_integer(s7_car(args)))); return(s7_wrong_type_arg_error(sc, "add1", 1, s7_car(args), "an integer")); } void add1_init(s7_scheme *sc); void add1_init(s7_scheme *sc) { s7_define_function(sc, "add1", add1, 1, 0, false, "(add1 int) adds 1 to int"); } /* gcc -fpic -c add1.c * gcc -shared -Wl,-soname,libadd1.so -o libadd1.so add1.o -lm -lc */ ``` -------------------------------- ### Build Bootup Files Source: https://github.com/nesbox/tic-80/blob/main/build/baremetalpi/README.md Compile the necessary bootup files required for the Raspberry Pi to start TIC-80 in baremetal mode. These files should be copied to the SD card root. ```shell cd ../../vendor/circle-stdlib/libs/circle/boot/ make ``` -------------------------------- ### Fennel Rescale Range Function Example Source: https://github.com/nesbox/tic-80/wiki/Code-examples-and-snippets Demonstrates how to use the `rescale-linear` function to map a value from one range to another. The example shows mapping 9 from the range [0-10] to [100-1000], resulting in 910.0. ```fennel (fn _G.TIC [] (cls) (print (rescale-linear 9 0 10 100 1000))) ``` -------------------------------- ### Install Dependencies and Build TIC-80 on Raspberry Pi OS (64-Bit) Source: https://github.com/nesbox/tic-80/blob/main/README.md Installs necessary development packages and builds TIC-80 from source using CMake. Ensure you have a stable internet connection for package downloads. ```bash sudo apt update && sudo apt -y install cmake libpipewire-0.3-dev libwayland-dev libsdl2-dev ruby-dev libcurl4-openssl-dev git clone --recursive https://github.com/nesbox/TIC-80 && cd TIC-80/build cmake -DBUILD_SDLGPU=On -DBUILD_WITH_ALL=On .. && cmake --build . --parallel 2 ``` -------------------------------- ### Define-Expansion Macro Usage Example Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Demonstrates using 'define-expansion' directly and how it differs from a quoted macro when evaluated in a 'let' context. ```scheme > (define-expansion (ex x) `(+ 1 ,x)) ``` ```scheme > (let ((x ex) (a 3)) (x a)) ; avoid read-time splicing ``` ```scheme > (let ((a 3)) (ex a)) ; spliced in at read-time ``` -------------------------------- ### Skip Startup Animation and Set File System Path Source: https://github.com/nesbox/tic-80/wiki/Command-Line-Arguments Skips the initial startup animation and designates the current directory as the file system storage location. ```bash tic80 --skip --fs . ``` -------------------------------- ### mget Source: https://github.com/nesbox/tic-80/wiki/_Sidebar Gets a tile from the map. ```APIDOC ## mget ### Description Retrieves the tile ID at a specific location in the map. ### Method ``` mget(x: number, y: number, layer: number): number ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **x** (number) - Required - The x-coordinate in the map. - **y** (number) - Required - The y-coordinate in the map. - **layer** (number) - Optional - The layer of the map to query (0-3). Defaults to 0. ### Request Example ``` local tileId = mget(5, 10, 0) print('Tile ID at (5, 10) is: ' .. tileId) ``` ### Response #### Success Response (200) Returns the tile ID at the specified map coordinates. #### Response Example ``` 12 ``` ``` -------------------------------- ### Initialize Level with Floor Tiles (Lua) Source: https://github.com/nesbox/tic-80/wiki/Level-Generation꞉-Random-Point Fills the entire map with floor tiles. Use this to create the base of the level before adding walls. ```lua --map size constants MAXX=29 MAXY=16 MINX=0 MINY=0 --fill the screen with floor tiles function floor() for x=MINX,MAXX do for y=MINY,MAXY do mset(x,y,TILE) end end end ``` -------------------------------- ### fget Source: https://github.com/nesbox/tic-80/wiki/_Sidebar Gets a sprite flag. ```APIDOC ## fget ### Description Retrieves a specific flag value for a given sprite. ### Method ``` fget(spriteId: number, flagIndex: number): boolean ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **spriteId** (number) - Required - The ID of the sprite. - **flagIndex** (number) - Required - The index of the flag to retrieve (0-7). ### Request Example ``` if fget(0, 3) then print('Sprite 0 has flag 3 set.') end ``` ### Response #### Success Response (200) Returns `true` if the flag is set for the sprite, `false` otherwise. #### Response Example ``` true ``` ``` -------------------------------- ### tstamp Source: https://github.com/nesbox/tic-80/wiki/_Sidebar Gets the timestamp of the last save. ```APIDOC ## tstamp ### Description Returns the timestamp (in seconds since epoch) of the last time the cartridge was saved. ### Method ``` tstamp(): number ``` ### Parameters None ### Request Example ``` local lastSaveTime = tstamp() print('Last saved at: ' .. os.date("%Y-%m-%d %H:%M:%S", lastSaveTime)) ``` ### Response #### Success Response (200) Returns the timestamp as a number. #### Response Example ``` 1678886400 ``` ``` -------------------------------- ### Define a Standard Macro Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Use define-macro to create standard macros. This example defines an 'and-let*' macro for sequential binding and execution. ```scheme (define-macro (and-let* vars . body) `(let () (and ,@(map (lambda (v) `(define ,@v)) vars) (begin ,@body)))) ``` -------------------------------- ### time Source: https://github.com/nesbox/tic-80/wiki/_Sidebar Gets the current system time. ```APIDOC ## time ### Description Returns the number of frames elapsed since the system started. ### Method ``` time(): number ``` ### Parameters None ### Request Example ``` local currentTime = time() print('Current frame: ' .. currentTime) ``` ### Response #### Success Response (200) Returns the current frame count as a number. #### Response Example ``` 12345 ``` ``` -------------------------------- ### pix Source: https://github.com/nesbox/tic-80/wiki/_Sidebar Gets the color of a pixel on the screen. ```APIDOC ## pix ### Description Retrieves the color index of a pixel at the specified screen coordinates. ### Method ``` pix(x: number, y: number): number ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **x** (number) - Required - The x-coordinate of the pixel. - **y** (number) - Required - The y-coordinate of the pixel. ### Request Example ``` local pixelColor = pix(50, 75) print('Color at (50, 75): ' .. pixelColor) ``` ### Response #### Success Response (200) Returns the color index of the pixel. #### Response Example ``` 10 ``` ``` -------------------------------- ### View Available Nim Build Tasks Source: https://github.com/nesbox/tic-80/blob/main/templates/nim/README.md Run this command to see all available build options and tasks provided by the Nimble build system for the project. ```bash nimble tasks ``` -------------------------------- ### fset/fget Example - Toggle Sprite Flags Source: https://github.com/nesbox/tic-80/wiki/fset This example demonstrates how to use fset and fget to toggle sprite flags 4 and 6 using keyboard input. It also shows conditional sprite rendering based on flag states. ```lua function TIC() cls(14) if btnp(4) then fset(1,4,not fget(1,4)) end if btnp(5) then fset(1,6,not fget(1,6)) end -- show sprite if flag 4 is true if fget(1,4) then -- scale up if flag 6 is true if fget(1,6) then spr(1,0,0,-1,2) else spr(1,0,0,-1,1) end end end ``` -------------------------------- ### Reader Macro for Startup Values Source: https://github.com/nesbox/tic-80/blob/main/vendor/s7/s7.html Illustrates how reader macros like `#\_` can be conceptually implemented to access startup values. This example shows how changing `#\_*#readers*` could affect macro behavior, though s7 prevents changing `#\_`'s meaning. ```scheme > Conceptually, #\_ could be implemented via *#readers*: > > (set! *#readers* > (cons (cons #\\\_ (lambda (str) >                 (with-let (unlet) > (string->symbol (substring str 1))))) >                *#readers*)) > > but s7 doesn't let you change the meaning of #\\\_; otherwise: > > (set! *#readers* (list (cons #\\\_ (lambda (str) (string->symbol (substring str 1)))))) > > and now #\_ provides no protection: > > \> (let ((+ -)) (#\_+ 1 2)) > _\-1_ ```