{"id":51544916,"url":"https://github.com/millertechnologyperu/swift-embedded-nintendo-64","last_synced_at":"2026-07-09T17:01:39.226Z","repository":{"id":367683024,"uuid":"1281823402","full_name":"MillerTechnologyPeru/swift-embedded-nintendo-64","owner":"MillerTechnologyPeru","description":"Embedded Swift for Nintendo 64","archived":false,"fork":false,"pushed_at":"2026-06-27T04:14:57.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-27T06:14:00.331Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MillerTechnologyPeru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-27T01:06:23.000Z","updated_at":"2026-06-27T04:15:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/MillerTechnologyPeru/swift-embedded-nintendo-64","commit_stats":null,"previous_names":["millertechnologyperu/swift-embedded-nintendo-64"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/MillerTechnologyPeru/swift-embedded-nintendo-64","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MillerTechnologyPeru%2Fswift-embedded-nintendo-64","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MillerTechnologyPeru%2Fswift-embedded-nintendo-64/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MillerTechnologyPeru%2Fswift-embedded-nintendo-64/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MillerTechnologyPeru%2Fswift-embedded-nintendo-64/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MillerTechnologyPeru","download_url":"https://codeload.github.com/MillerTechnologyPeru/swift-embedded-nintendo-64/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MillerTechnologyPeru%2Fswift-embedded-nintendo-64/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35306717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-09T02:00:07.329Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2026-07-09T17:01:38.109Z","updated_at":"2026-07-09T17:01:39.212Z","avatar_url":"https://github.com/MillerTechnologyPeru.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swift-embedded-nintendo-64\n\nEmbedded Swift running on the Nintendo 64, targeting the VR4300 CPU (MIPS III).\n\nEach example builds a working N64 ROM. The Swift code is compiled on the host\nwith a MIPS-enabled `swiftc`, lowered to a MIPS ELF object via `llc`, then\nlinked against C code compiled by the appropriate N64 GCC toolchain.\n\n## Examples\n\n### [nusys/](nusys/) — Calling Swift from C (NuSYS SDK)\n3D rotating cube using the proprietary NuSYS / crashsdk toolchain. The graphics\npipeline (`gfx.swift`), scene stages (`stage0.swift`, `stage1.swift`), and\nentry point (`lib.swift`) are all Swift. C handles static data and matrix math\nthat must call N64 SDK float functions.\n\nUses `@c @implementation` (Swift 6.3) to implement functions declared in C headers.\n\n\u003cimg width=\"771\" height=\"632\" alt=\"Screenshot 2026-06-29 at 8 13 38 AM\" src=\"https://github.com/user-attachments/assets/41544965-1622-4b85-8c34-dbf48723e6b0\" /\u003e\n\n### [libdragon/](libdragon/) — Swift + libdragon\nAnimated color grid using the open-source [libdragon](https://github.com/DragonMinded/libdragon)\nSDK and its `n64.mk` build system — a completely different toolchain from the\nNuSYS example. Swift drives libdragon's `rdpq` fill API; C owns libdragon init\nand the frame loop.\n\n\u003cimg width=\"767\" height=\"628\" alt=\"Screenshot 2026-06-29 at 8 12 53 AM\" src=\"https://github.com/user-attachments/assets/b4d7aa60-f640-4029-8d5a-4bed68901197\" /\u003e\n\n## Cross-toolchain gotchas\n\nTwo hard constraints apply to all examples:\n\n**1. No floats across the Swift↔C boundary.**\nLLVM (swiftc) and N64 GCC disagree on the o32 float-argument ABI: LLVM passes\ntrailing floats after a pointer in FP registers (`$f13`/`$f14`); GCC expects\nthem in GPRs (`$a1`/`$a2`). Pass IEEE-754 bit patterns as `UInt32`/`u32` instead\nand reinterpret with a union on the C side.\n\n**2. ≤4 register arguments per Swift↔C bridge call (libdragon only).**\nlibdragon uses `-mabi=o64` (8-byte stack slots); the Swift object is o32\n(4-byte stack slots). Arguments beyond the first four spill to the stack and\nare read at the wrong offset. Pack multiple values into a single `uint32_t`\nto stay within four registers.\n\n### Conditional moves (movn/movz) — fixed by llc flags\n\nBy default, LLVM lowers Swift `if`/ternary/`min`/`max` on integers to `select`\nIR, which the MIPS backend emits as `movn`/`movz` — MIPS IV instructions the\nVR4300 does not have. Executing them raises a Reserved Instruction exception.\n\nThe fix is two llc `-mattr` flags that disable the MIPS IV conditional-move\nsubset inherited by MIPS32:\n\n```\n-mattr=+mips3,+noabicalls,+gp64,+fpxx,+nooddspreg,-mips4_32,-mips4_32r2\n```\n\nBoth `compile-swift.sh` scripts already include these flags. With them, Swift\nconditionals compile to branches and there are no restrictions on using\n`if`/`else`, ternaries, `min`, `max`, or `abs` in Swift code.\n\n## Building\n\nEach example has its own `build.sh`. Requirements:\n\n- A MIPS-enabled Embedded Swift toolchain (`swiftc` + `llc`) — the standard\n  release toolchains do not include MIPS; you need a custom build or one that\n  ships MIPS embedded Swift modules.\n- Docker — for the N64 GCC toolchain and SDK (pulled automatically on first run).\n\n```bash\ncd nusys     \u0026\u0026 ./build.sh   # → build/calling-swift-from-c.z64\ncd libdragon \u0026\u0026 ./build.sh   # → libdragon-swift.z64\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmillertechnologyperu%2Fswift-embedded-nintendo-64","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmillertechnologyperu%2Fswift-embedded-nintendo-64","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmillertechnologyperu%2Fswift-embedded-nintendo-64/lists"}