{"id":15357709,"url":"https://github.com/nauja/moro8","last_synced_at":"2025-03-27T19:48:45.244Z","repository":{"id":46139951,"uuid":"445605697","full_name":"Nauja/moro8","owner":"Nauja","description":"Fantasy 8-bit CPU in ANSI C","archived":false,"fork":false,"pushed_at":"2022-12-23T19:11:08.000Z","size":295,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T22:29:02.570Z","etag":null,"topics":["6502","6502-assembly","6502-processor","ansi-c","c","cpu","emulator","library","simulator"],"latest_commit_sha":null,"homepage":"","language":"C","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/Nauja.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}},"created_at":"2022-01-07T17:46:14.000Z","updated_at":"2024-03-09T21:04:01.000Z","dependencies_parsed_at":"2023-01-30T19:30:24.040Z","dependency_job_id":null,"html_url":"https://github.com/Nauja/moro8","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nauja%2Fmoro8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nauja%2Fmoro8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nauja%2Fmoro8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nauja%2Fmoro8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nauja","download_url":"https://codeload.github.com/Nauja/moro8/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245916256,"owners_count":20693389,"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":["6502","6502-assembly","6502-processor","ansi-c","c","cpu","emulator","library","simulator"],"created_at":"2024-10-01T12:38:15.491Z","updated_at":"2025-03-27T19:48:45.222Z","avatar_url":"https://github.com/Nauja.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# moro8\r\n\r\n[![CI](https://github.com/Nauja/moro8/actions/workflows/CI.yml/badge.svg)](https://github.com/Nauja/moro8/actions/workflows/CI.yml)\r\n[![CI Docs](https://github.com/Nauja/moro8/actions/workflows/CI_docs.yml/badge.svg)](https://github.com/Nauja/moro8/actions/workflows/CI_docs.yml)\r\n[![Documentation Status](https://readthedocs.org/projects/moro8/badge/?version=latest)](https://moro8.readthedocs.io/en/latest/?badge=latest)\r\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Nauja/moro8/master/LICENSE)\r\n\r\nmoro8 is a 8-bit fantasy CPU written in ANSI C with extensibility and portability in mind.\r\n\r\n## Purpose\r\n\r\nThe ultimate goal of writing moro8 was to:\r\n\r\n  * Learn more about 8-bit microcontrollers\r\n  * Write small programs and games in assembler for fun (see [moro8asm](https://github.com/Nauja/moro8asm))\r\n  * Make it run programs loaded from an SD card on an Arduino with 6KB of SRAM\r\n  * Compile it to WASM so it can run on the Web (see [moro8.js](https://github.com/Nauja/moro8.js))\r\n\r\nIt is extensible because:\r\n\r\n  * You can register handlers at runtime for handling additional opcodes providing new features\r\n  * You can completely change how the memory is accessed and even implement some pagination\r\n\r\nIt is portable because:\r\n\r\n  * Written in ANSI C with barely any dependencies on the system\r\n\r\n## Usage\r\n\r\nThis is how you can load a program to ROM and run it:\r\n\r\n```c\r\n#include \"moro8.h\"\r\n\r\n// Initialize the cpu\r\nstruct moro8_cpu cpu;\r\nmoro8_init(\u0026cpu);\r\n\r\n// Initialize the memory\r\nstruct moro8_array_memory memory;\r\nmoro8_array_memory_init(\u0026memory);\r\n\r\n// Link cpu to memory\r\nmoro8_set_memory_bus(\u0026cpu, \u0026memory.bus);\r\n\r\n// Load this small program to ROM and run\r\nmoro8_uword prog[] = {\r\n    0xA9, 0x02, // LDA #$02\r\n    0x69, 0x03  // ADC #$03\r\n};\r\nmoro8_load(\u0026cpu, prog, 4);\r\nmoro8_run(\u0026cpu);\r\n\r\n// Print result in accumulator register\r\nprintf(\"Result of 2 + 3 is %d\", moro8_get_ac(\u0026cpu));\r\n```\r\n\r\nYou can notice that we have two distinct objects, the cpu itself, and the memory.\r\nBut why is that so ?\r\n\r\nWell, while the cpu has a maximum memory of 64KB that could have easily been hard coded, I chose to design the library\r\nso that the memory stays separated from the cpu and can easily be implemented in different ways. This is to allow for different\r\nstrategies such as some pagination system when running on a microcontroller with less than 64KB which is the case when\r\nrunning on Arduino.\r\n\r\nCheck the [documentation](https://moro8.readthedocs.io/en/latest/) to find more examples and learn about the API.\r\n\r\n## Build Manually\r\n\r\nCopy the files [moro8.c](https://github.com/Nauja/moro8/blob/main/moro8.c) and [moro8.h](https://github.com/Nauja/moro8/blob/main/moro8.h) into an existing project.\r\n\r\nComment or uncomment the defines at the top of `moro8.h` depending on your configuration:\r\n\r\n```c\r\n/* Define to 1 if you have the \u003cstdio.h\u003e header file. */\r\n#ifndef HAVE_STDIO_H\r\n#define HAVE_STDIO_H 1\r\n#endif\r\n\r\n/* Define to 1 if you have the \u003cstdlib.h\u003e header file. */\r\n#ifndef HAVE_STDLIB_H\r\n#define HAVE_STDLIB_H 1\r\n#endif\r\n\r\n/* Define to 1 if you have the \u003cstring.h\u003e header file. */\r\n#ifndef HAVE_STRING_H\r\n#define HAVE_STRING_H 1\r\n#endif\r\n\r\n...\r\n```\r\n\r\nYou should now be able to compile this library correctly.\r\n\r\n## Build with CMake\r\n\r\nTested with CMake \u003e= 3.13.4:\r\n\r\n```\r\ngit clone https://github.com/Nauja/moro8.git\r\ncd moro8\r\ngit submodule init\r\ngit submodule update\r\nmkdir build\r\ncd build\r\ncmake ..\r\n```\r\n\r\nCMake will correctly configure the defines at the top of [moro8.h](https://github.com/Nauja/moro8/blob/main/moro8.h) for your system.\r\n\r\nYou can then build this library manually as described above, or by using:\r\n\r\n```\r\nmake\r\n```\r\n\r\nThis will generate `moro8.a` if building as a static library and `libmoro8.so` in the `build` directory.\r\n\r\nYou can change the build process with a list of different options that you can pass to CMake. Turn them on with `On` and off with `Off`:\r\n  * `-DMORO8_STATIC=On`: Enable building as static library. (on by default)\r\n  * `-DMORO8_UNIT_TESTING=On`: Enable building the tests. (on by default)\r\n  * `-DMORO8_DOXYGEN=On`: Enable building the docs. (off by default)\r\n  * `-DMORO8_MINIMALIST=On`: Strip some extra functions. (off by default)\r\n  * `-DMORO8_EXTENDED_OPCODES=On`: Enable extended opcodes specific to moro8. (on by default)\r\n  * `-DMORO8_WITH_PARSER=On`: Enable moro8_print and moro8_parse functions. (on by default)\r\n  * `-DMORO8_WITH_HANDLERS=On`: Enable support for custom opcode handlers. (on by default)\r\n  * `-DMORO8_WITH_CLI=On`: Enable building the command-line interface. (on by default)\r\n\r\n## Build with Visual Studio\r\n\r\nGenerate the Visual Studio solution with:\r\n\r\n```\r\nmkdir build\r\ncd build\r\ncmake .. -G \"Visual Studio 16 2019\"\r\n```\r\n\r\nYou can now open `build/moro8.sln` and compile the library.\r\n\r\n## License\r\n\r\nLicensed under the [MIT](https://github.com/Nauja/moro8/blob/main/LICENSE) License.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnauja%2Fmoro8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnauja%2Fmoro8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnauja%2Fmoro8/lists"}