{"id":15659063,"url":"https://github.com/siraben/r216-forth","last_synced_at":"2025-04-19T13:48:49.141Z","repository":{"id":111748496,"uuid":"173112066","full_name":"siraben/r216-forth","owner":"siraben","description":"A Forth implementation for the R216K8B Powder Toy computer.","archived":false,"fork":false,"pushed_at":"2024-05-24T14:20:09.000Z","size":1828,"stargazers_count":27,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T08:22:59.789Z","etag":null,"topics":["assembly","fantasy-computer","forth","powder-toy"],"latest_commit_sha":null,"homepage":"","language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/siraben.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-28T12:54:55.000Z","updated_at":"2024-12-30T17:13:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"91675d28-4ec2-4929-ad0a-d0260832a85b","html_url":"https://github.com/siraben/r216-forth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siraben%2Fr216-forth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siraben%2Fr216-forth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siraben%2Fr216-forth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/siraben%2Fr216-forth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/siraben","download_url":"https://codeload.github.com/siraben/r216-forth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249707069,"owners_count":21313761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembly","fantasy-computer","forth","powder-toy"],"created_at":"2024-10-03T13:14:48.188Z","updated_at":"2025-04-19T13:48:49.084Z","avatar_url":"https://github.com/siraben.png","language":"Assembly","readme":"# A Forth for the R216 computer\n\n![Screenshot](screenshot.png)\n\n## What?\nThis project aims to implement the Forth programming language on the\n[R216 computer by LBPHacker](https://trigraph.net/powdertoy/R216/manual.md).  The\ncomputer is implemented completely in the video game [Powder\nToy](https://powdertoy.co.uk/), so this Forth will be one of the few\nsystems out there that target a fictional computer.  Since Forth is\nextremely easy to port, it only takes a couple of primitive routines\nto get started writing the whole thing again.\n\nThis is the first system I know of in Powder Toy that allows\ninteractive programming within Powder Toy itself (i.e. without needing\nan assembler), and the first non-assembly language to be ported to a\nPowder Toy computer.\n\nThe default program `forth.asm` reads up to 128 characters of input,\nthen starts the interpreter up, which performs the standard Forth loops\nuntil a `NUL` byte is read.  The interpreter echos back what it's\nreading for debugging purposes, according to the following table.\n\n| Color  | Meaning                 |\n| :-:    | :-:                     |\n| Green  | Interpreted             |\n| Red    | Compiled                |\n| Yellow | Interpreted (immediate) |\n| Blue   | Compiled number         |\n| Cyan   | Interpreted number      |\n\nHere are some example programs that you can type at the REPL.\n```forth\n.\" hello, world!\"\n\\ =\u003e hello, world ok\n\n: stars 0 do star loop ;\n10 stars\n\\ =\u003e ********** ok\n\n: factorial dup 0= if drop 1 else dup 1- recurse * then ;\n5 factorial .\n\\ =\u003e 120 ok\n```\n\nHere is a list of words defined in the system.\n```\ns0 sp@ depth .s decimal hex latest base xor and find allot here c@ c!\n@ !  , +!  -!  \u003er r\u003e /mod nip mod div space create immed ?immed hide [\n] : ; constant value to .  d.  u.  ?dup \u003c \u003e = 0\u003c\u003e 0= \u003c\u003e dup 2dup drop\n2drop swap over rot + - * um* 1- 1+ 2- 2+ number max min word /mod\norigin page emit \u003edfa \u003ecfa execute recurse puts lit tell s\" .\"  halt\n(') ' if else then begin until again while j i repeat do loop +loop\nstar\n```\n\n## Features\n- The first Forth system for a TPT computer; 75 words and counting\n  - An extensible, lightweight, interactive, introspective language.\n- Harnesses the 16-bit power of the R216 computer, with features such\n  as\n  - 16-bit multiplication (16 * 16 -\u003e 16 bit or 16 * 16 -\u003e 32 bit)\n  - Terminal output/input (can be generalized to other peripherals)\n- Adapts to memory layout, can be flashed on the 4K or 8K variant of\n  the R216\n\n### Quirks\n- Only the first three characters and length are checked when\n  traversing the dictionary (this was actually the case in older Forth\n  systems such as the one used in _Starting Forth_)\n- **Runs slowly**: increase the frame rate by running `tpt.setfpscap(2)`\n  unless you're prepared to wait minutes for simple programs\n\n## Why?\nFictional computers are great.  One can learn a lot from both\nimplementing and playing around with them.  But when was the last time\nyou saw a Forth REPL in fictional computer?  What about a Forth REPL\nin a fictional computer implemented in a powder simulation game?\nWell, now you have!  From the relative success of my [previous\nproject](https://github.com/siraben/zkeme80), a Forth-based operating\nsystem for TI-84+ calculators, I thought it would be fun to write\nanother one.  From initially knowing nothing about the architecture,\nWithin two days I got a REPL working with compile/interpret states,\nand now it's just a matter of porting all the other Forth words we\nknow and love.\n\n## Building and running R216 Forth\nEnsure you have a recent version of Powder Toy (tested on version\n94.1).\n\nClone [the assembler](https://github.com/LBPHacker/R216) and this\nrepository using Git.  Open the file `r216-forth.cps` in Powder Toy, you'll\nsee a computer, screen and keyboard.  Open the Lua console by pressing\n~ and type the following:\n\n```lua\nr2asm = loadfile(\"\u003cpath to repo\u003e/r2asm.lua\")\n```\n\nWhere `\u003cpath to assembler repo\u003e` is the absolute path to the cloned assembler.\nThen, type in\n\n```lua\na = \"\u003cpath to this repo\u003e/forth.asm\"\n```\n\nTo define a variable `a` to shorten lines (Powder Toy truncates long\ncommands).  Finally, you can assemble `forth.asm` by running:\n\n```lua\nr2asm(a, 0xDEAD, \"\u003cpath to logfile\u003e\")\n```\n\nWhere `\u003cpath to logfile\u003e` is the path to a log file which you can open\nto see if the assembling worked.  Close the console by pressing ~, and\nclick on the sign to begin using R216 Forth!\n\n## Future plans\n- [x] Add ability to read numbers\n  - [x] Relies on multiplication routine\n- [x] Add string words `.\"`, `s\"`\n- [x] Add exceptions, `catch`, `throw`\n- [ ] Add `?do`, fix `leave`\n  - [ ] Requires rewriting implementation of `do`, `loop` and `+loop`\n  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiraben%2Fr216-forth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsiraben%2Fr216-forth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiraben%2Fr216-forth/lists"}