{"id":13419514,"url":"https://github.com/gto76/comp-m2","last_synced_at":"2025-05-09T01:24:18.209Z","repository":{"id":145641398,"uuid":"38218562","full_name":"gto76/comp-m2","owner":"gto76","description":"Comp Mark II – Simple 4-bit virtual computer","archived":false,"fork":false,"pushed_at":"2024-03-09T01:17:50.000Z","size":935,"stargazers_count":169,"open_issues_count":1,"forks_count":13,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-05T02:12:09.966Z","etag":null,"topics":["educational-software","virtual-machine"],"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/gto76.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":"2015-06-28T23:44:42.000Z","updated_at":"2024-12-08T08:11:18.000Z","dependencies_parsed_at":"2024-10-26T21:17:35.155Z","dependency_job_id":"eaacef84-fccb-4517-a600-856537e08e0f","html_url":"https://github.com/gto76/comp-m2","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/gto76%2Fcomp-m2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gto76%2Fcomp-m2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gto76%2Fcomp-m2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gto76%2Fcomp-m2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gto76","download_url":"https://codeload.github.com/gto76/comp-m2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253172492,"owners_count":21865523,"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":["educational-software","virtual-machine"],"created_at":"2024-07-30T22:01:17.081Z","updated_at":"2025-05-09T01:24:18.187Z","avatar_url":"https://github.com/gto76.png","language":"C++","funding_links":[],"categories":["TODO scan for Android support in followings"],"sub_categories":[],"readme":"Comp Mark II\n============\n\n#### Updated version of [**Comp**](https://github.com/gto76/comp-cpp) – Simple 4-bit/1 Hz virtual computer for learning purposes\n\n![screenshot](doc/screenshot.png)\n\n**For quick start see [HOW TO RUN](#how-to-run-on)**\n\nOverview\n--------\n\n* Processor has one 8 bit register.\n* Ram is separated in two address spaces; one for instructions, called CODE, and another for data, called DATA.\n* All instructions are 8 bits long.\n* Execution starts at the first address (0) of the CODE ram.\n* Execution stops when program reaches the last address (15) of the CODE ram.\n* Most of instructions consist of instruction code and address:\n```\ninstruction code - 4 bits\n  |  +-- address - 4 bits\n  v  v\n----***-  -\u003e  READ 14  -\u003e  Copy value stored at address 14 of DATA ram to register.\n```\n* All addresses specified by instructions refer to DATA ram, except for addresses of *Execution Control* instructions (`JUMP`, `IF MAX`, `IF MIN`, ...). They refer to CODE part of ram.\n* Some instructions (`JRI~\u003c\u003e\u0026V`) do not specify address. They operate on register (`SHIFT L/R`, `NOT`, ...) or between register and predefined DATA address (`AND`, `OR`, ...).\n* Whatever gets written to the last address is sent to the printer, or to *stdout* if program is running in a non-interactive mode.\n* When reading from the last address (15), we get a random byte value, or a single word from *stdin*, if program is running in non-interactive mode.\n* In this word every `*` is interpreted as *true* and all other characters as *false*. If word starts with a digit, it is then read as a number and converted appropriately.\n* Program will start in a non-interactive mode when any input is piped in, or any option is given. For instance `echo | ./comp \u003cfile\u003e`\n* Programs can be saved with `s` key and loaded by passing their name as a parameter.\n* If more than one filename is passed, the computers will be chained together (*stdin* \u003e *comp-1* \u003e *comp-2* \u003e ... \u003e *stdout*).\n* If folder is passed, all files in that folder that have suffix `.cm2` will be loaded in an alphabetical order.\n\nInstruction set\n---------------\nMost of the instructions, together with the highlighted word that they use/modify, are pretty self-explainatory. Exception are instructions that start with `-***`, and are a part of `JRI~\u003c\u003e\u0026VX` instruction cluster. They are:  \n * `J` – JUMP_REG,\n * `R` – READ_REG,\n * `I` – INIT,\n * `~` – NOT,\n * `\u003c` – SHIFT_L,\n * `\u003e` – SHIFT_R,\n * `\u0026` – AND,\n * `V` – OR,\n * `X` – XOR.\n\n(Use Shift–Left/Right Arrow to easily shift between them.)  \nDetailed descriptions of all instructions can be found [**HERE**](doc/instruction-set.md).\n\nKeys\n----\n* `Space` – Flip bit\n* `Tab` – Switch address space\n* `Enter` – Start/pause execution\n* `Esc` – Cancel execution\n* `Delete`, `Backspace` – Delete word or move following words up if empty\n* `Insert`, `]` – Insert empty word and move following words down\n* `s` – Save ram to textfile named `punchcard-\u003cnum\u003e.cm2`. To load it, start program with `./comp \u003cfile\u003e`\n* `q` – Save and quit\n\nDetailed descriptions of all keys can be found [**HERE**](doc/keys.md).\n\nOptions\n-------\n* `--non-interactive`, `-n` – Runs program without an interface. Output is sent to *stdout* instead of a printer. This option is not necessary if any other option is present, or if input is piped in.\n* `--char-output`, `-c` – Converts numbers to characters using ASCII standard when printing to *stdout*.\n* `--filter`, `-f` – Convert characters to numbers when reading from *stdin*, and numbers to characters when printing to *stdout*.\n* `--game`, `-g` – Same as *filter*, but reads characters directly from keyboard.\n* `parse` – Converts program to c++ code (other options may be specified).\n* `compile` – Compiles program to executable file, by converting it to c++ code and then running g++ compiler (other options from above may be specified). Only difference between compiled program and one run on the Comp Mark II is in execution speed.\n\n\nHow to run on…\n--------------\n\n### Windows\n\n* Install *Tiny Core Linux* on *VirtualBox* using this [**instructions**](https://github.com/gto76/my-linux-setup/tree/gh-pages/conf-files/tiny-core-linux).\n* Run the *UNIX* commands.\n\n### UNIX\n*Make* and *g++* need to be installed first. On *Ubuntu* and *Debian* you can get them by running `sudo apt-get install build-essential`, on *OS X* they get installed automatically after running *make*.\n```\n$ git clone https://github.com/gto76/comp-m2.git\n$ cd comp-m2\n$ ./run\n```\n\n### Docker\n```\n$ docker run -it --rm mvitaly/comp-m2 \u003coptions\u003e\n```\n\nExamples\n--------\n\n#### Fibonacci Sequence\n```\n$ ./comp --non-interactive examples/fibonacci.cm2\n-------*   1\n-------*   1\n------*-   2\n------**   3\n-----*-*   5\n----*---   8\n...\n```\n\n#### Multiply\n```\n$ echo \"3 4\" | ./comp examples/multiply.cm2\n----**--  12\n```\n\n#### Hello World\n```\n$ ./comp --char-output examples/hello-world.cm2\nHello world\n```\n\n#### To Upper Case\n```\n$ echo \"Hello world\" | ./comp --filter examples/to-upper-case.cm2\nHELLO WORLD\n```\n\n#### Cat and Mouse\nTwo player game\n```\n$ ./comp compile --game examples/cat-and-mouse/\nCompiled as cat-and-mouse\n$ ./cat-and-mouse\n```\n```\n##################\n#                #\n#  C             #\n#                #\n#                #\n#                #\n#                #\n#                #\n#                #\n#                #\n#                #\n#                #\n#                #\n#                #\n#                #\n#             m  #\n#                #\n##################\n```\n\nFurther Development\n-------------------\nCheck out the blueprint of [**Mark III**](https://github.com/gto76/comp-m2/issues/4) model.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgto76%2Fcomp-m2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgto76%2Fcomp-m2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgto76%2Fcomp-m2/lists"}