{"id":17278348,"url":"https://github.com/lbphacker/tptasm","last_synced_at":"2025-04-14T08:32:18.283Z","repository":{"id":43788113,"uuid":"193108285","full_name":"LBPHacker/tptasm","owner":"LBPHacker","description":"Universal assembler for TPT computers","archived":false,"fork":false,"pushed_at":"2024-09-29T18:55:01.000Z","size":203,"stargazers_count":15,"open_issues_count":5,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-01T02:51:52.294Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","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/LBPHacker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-06-21T14:05:53.000Z","updated_at":"2024-09-29T18:55:05.000Z","dependencies_parsed_at":"2024-04-02T20:41:54.416Z","dependency_job_id":"68fd1b17-437e-4074-8c3a-851d95947f7d","html_url":"https://github.com/LBPHacker/tptasm","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/LBPHacker%2Ftptasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LBPHacker%2Ftptasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LBPHacker%2Ftptasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LBPHacker%2Ftptasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LBPHacker","download_url":"https://codeload.github.com/LBPHacker/tptasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223624146,"owners_count":17175197,"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":[],"created_at":"2024-10-15T09:11:31.210Z","updated_at":"2024-11-08T03:14:58.622Z","avatar_url":"https://github.com/LBPHacker.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TPTASM\n\n## What?\n\nA universal assembler for TPT computers that aims to be as architecture-agnostic\nas possible and to support all computers ever made in TPT. If you're aware of\none that I've missed, open an issue.\n\nComputers currently supported (in alphabetical order):\n\n- [A728D280](https://powdertoy.co.uk/Browse/View.html?ID=2460726) and\n  [A728D28A](https://powdertoy.co.uk/Browse/View.html?ID=2460726) by Sam_Hayzen\n- [B29K1QS60](https://powdertoy.co.uk/Browse/View.html?ID=2435570) by unnick\n- [I8M7D28S](https://powdertoy.co.uk/Browse/View.html?ID=2473628) by Sam_Hayzen\n- [MAPS](https://powdertoy.co.uk/Browse/View.html?ID=975033) by drakide\n- [MICRO21](https://powdertoy.co.uk/Browse/View.html?ID=1599945) by RockerM4NHUN\n- [PTP7](https://powdertoy.co.uk/Browse/View.html?ID=2458644) by unnick\n- [R216K2A](https://powdertoy.co.uk/Browse/View.html?ID=2303519),\n  [R216K4A](https://powdertoy.co.uk/Browse/View.html?ID=2305835) and\n  [R216K8B](https://powdertoy.co.uk/Browse/View.html?ID=2342633) by LBPHacker\n- Generic R3 (unreleased, under development) by LBPHacker\n- Armatoste (unreleased, under development) by DanielUbTb\n\n## Why?\n\nBecause I finally made an assembler with nice enough features that it probably\nmakes sense to not make another one but just support all future (and past)\ncomputers with this one instead.\n\n## How?\n\n[Click here](#tldr) for steps to take if you have no idea what's going on and\njust want to finally program a computer.\n\nYou can run the assembler from TPT or really in any environment that's\ncompatible with Lua 5.1. Running it from TPT has the benefit of actually\nallowing you to program computers.\n\nThe assembler takes both positional and named arguments. A positional string\nargument of the format `key=value` (`^([^=]+)=(.+)$`, to be precise) becomes\na named argument, its name is set to `key` and its value to `value`, both\nstrings. The remaining positional arguments become the final positional\narguments.\n\nAll positional arguments have equivalent named counterparts.\n\n| position | name   | type                     | description                  |\n| -------- | ------ | ------------------------ | ---------------------------- |\n| 1        | source | string                   | path to source to assemble   |\n| 2        | target | integer, string or table | identifier of the target CPU |\n| 3        | log    | string or handle         | path to redirect log to      |\n| 4        | model  | string                   | model number                 |\n| | silent          | any     | don't log anything                            |\n| | anchor          | string  | spawn anchor for specified model              |\n| | anchor\\_dx      | integer | X component of anchor direction vector        |\n| | anchor\\_dy      | integer | Y component of anchor direction vector        |\n| | anchor\\_prop    | string  | name of property for anchor to use            |\n| | anchor\\_id      | integer | CPU identifier to encode in the anchor        |\n| | detect          | any     | list recognisable CPUs with model and ID      |\n| | export\\_labels  | string  | path to export labels to                      |\n| | allow\\_model\\_mismatch | any | throw only warnings instead of errors      |\n\nThere's also a way to pass arguments by simply passing a table as the first\nargument. In this case its integer-keyed pairs will become the positional\narguments (the ones that adhere to Lua's definition of arrays anyway) and\nall other pairs become named arguments. Don't worry, the examples below will\nmake all this clear.\n\n### Notes on arguments\n\n- `target` may be a string, in which case the opcodes are dumped into the file\n  this string refers to, in little endian encoding (refer to the corresponding\n  architecture module for number of bytes in such an opcode; generally it will\n  be the opcode width passed to `opcode.make` multiplied by 4)\n- `target` may be a table, in which case the opcodes are copied into it and\n  no flashing attempts occur (useful when you're using TPTASM outside TPT)\n- if `target` is not specified, the assembler looks for the first CPU that\n  matches the model name passed (or any CPU if it wasn't passed); if the anchor\n  particle of a CPU happens to be directly under your TPT cursor, it's selected\n  as the target\n- `log` may also be an object with a `:write` method (e.g. a file object), in\n  which case output is redirected to that object by means of calling `:write`\n  (`:close` is never called and doesn't have to be present)\n- `silent` and `allow_model_mismatch` are checked for truthiness by Lua's\n  definitions, so they're considered true if they're not `false` or `nil`\n  (likewise, useful when you're using TPTASM outside TPT)\n- `(anchor_dx, anchor_dy)` defaults to the vector `(1, 0)`, as anchors are\n  generally horizontal and are read from the left to the right\n- `anchor_prop` defaults to `\"ctype\"`, as anchors tend to be lines of FILT,\n  which can be easily located visually if they contain ASCII data\n\n### Inside TPT\n\n```lua\ntptasm = loadfile(\"main.lua\") -- load tptasm into memory as a function\n     -- (this assumes you saved it in the same directory TPT is in)\ntptasm(\"/path/to/source.asm\") -- assemble source\ntptasm(\"/path/to/source.asm\", 0xDEAD) -- specify target CPU\ntptasm(\"/path/to/source.asm\", nil, \"log.log\") -- specify file to log output to\ntptasm(\"/path/to/source.asm\", nil, nil, \"R3\") -- specify model name\n```\n\n#### Complete example\n\nAssuming this repository has been cloned to `~/Development/tptasm`, navigate to\n[save id:1599945](https://powdertoy.co.uk/Browse/View.html?ID=1599945) and\nexecute this:\n\n```lua\nloadfile(\"~/Development/tptasm/src/main.lua\")(\"~/Development/tptasm/examples/micro21/demo.asm\")\n```\n\n### Somewhere else\n\n```sh\n# currently quite pointless to do but possible nonetheless\n$ ./main.lua /path/to/source.asm model=R3\n```\n\n```lua\n-- let's say this is not TPT's console\ntptasm = loadfile(\"main.lua\")\nopcodes = {}\ntptasm({ source = \"/path/to/source.asm\", target = opcodes, model = \"R3\" })\nprint(opcodes[0x1337]:dump())\n```\n\n### Exporting labels\n\nThe file referred to by `export_labels` will look something like this\n(see [examples/micro21/demo.asm](examples/micro21/demo.asm)):\n\n```\nstart 0x0\nstart.jump_table 0x6\ndemo_addition 0x2C\ndemo_odds 0x33\ndemo_odds.get_number 0x34\ndemo_odds.get_number.done 0x3A\ndemo_odds.count_odds 0x3B\n...\n```\n\nThat is, it'll have one fully qualified label and the corresponding address\nin hexadecimal per line, separated by one space character.\n\n### TL;DR\n\n1. find the green button on this page which looks like it might let you\n   download something; clicking it gives you a popup with an option somewhere\n   to download a ZIP\n1. download said ZIP and extract it somewhere, then find the src folder inside\n   and rename it to tptasm\n1. open the settings menu in TPT, scroll down and click Open Data Folder;\n   move the tptasm folder from earlier to the one that TPT just opened\n1. have the code you want to assemble saved to a file (say, `code.asm`) and\n   move said file, once again, to the folder TPT just opened\n1. open the save in TPT with the computer you want to program\n1. if there are multiple computers in the save, find the one and only QRTZ\n   particle in the computer you want to program (possibly with the Find mode,\n   `Ctrl+F`) and move your cursor over it (use a `1x1` brush)\n1. open the console (with `~` or the `[C]` button on the right side of the\n   window) and execute the following:\n\n   ```lua\n   loadfile(\"tptasm/main.lua\")(\"code.asm\")\n   ```\n\n1. if `[tptasm] done` is the only thing you see, your code assembled\n   and you're done!\n1. if `[tptasm] done` is not the only thing you see, you may want to save the\n   log to a file for inspection; you can do this by executing this instead:\n\n   ```lua\n   loadfile(\"tptasm/main.lua\")(\"code.asm\", nil, \"log.log\")\n   ```\n\n   ... which will create a file named log.log in the folder TPT opened; open\n   this file in a text editor to see why your code didn't assemble\n1. if the file shows something like \"this is an error, tell LBPHacker\", then\n   tell me!\n\n\n## Then?\n\nThings I still want to do but don't know when I'll have the time:\n\n- [ ] support Harvard architecture computers more, as currently there is no\n      way to address their memory through labels, only preprocessor macros\n      (`%define`, `%eval`, etc.)\n- [ ] clean up and comment code as much as possible\n- [ ] add support for more computers\n- [ ] possibly replace postfix syntax in expression blocks (`{ }` blocks) with\n      infix syntax\n- [ ] possibly add support to recognise expression blocks and implicitly\n      evaluate them at assemble time, thus eliminating the need to wrap them in\n      curly brackets\n- [ ] check if this thing works on Windows at all and fix it if it doesn't\n\nPRs are welcome, especially if they add support for computers. Yes, I do realise\nmy code is a huge mess. Good luck figuring it out.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flbphacker%2Ftptasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flbphacker%2Ftptasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flbphacker%2Ftptasm/lists"}