### 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.x