https://github.com/rozukke/lc3-vm-mcpp
LC3 virtual machine written in C++ that implements mcpp related TRAPs
https://github.com/rozukke/lc3-vm-mcpp
Last synced: 25 days ago
JSON representation
LC3 virtual machine written in C++ that implements mcpp related TRAPs
- Host: GitHub
- URL: https://github.com/rozukke/lc3-vm-mcpp
- Owner: rozukke
- License: mit
- Created: 2024-05-01T03:59:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-06T04:32:52.000Z (6 months ago)
- Last Synced: 2025-05-05T23:16:32.963Z (5 months ago)
- Language: C++
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LC3 Virtual Machine for mcpp
[](https://cplusplus.com/) [](https://github.com/justinmeiners) [](https://github.com/rozukke) [](https://github.com/rozukke/lc3-vm-mcpp/blob/main/LICENSE)This is a C++ based virtual machine for the LC3 assembly language, adapted to work with [mcpp](https://github.com/rozukke/mcpp) the Royal Melbourne Institute of Technology (RMIT) to supplement the COSC2084 (Programming Studio 2) course. The original project by [Justin Meiners](https://github.com/justinmeiners) can be found [here](https://github.com/justinmeiners/lc3-vm). Thank you to [Michael Dann](https://github.com/mchldann/) for the original adaptation and trap implementations.
## Additions
This VM supports a few additional TRAPs based on mcpp functionality, including:
- `CHAT` to post to Minecraft chat
- `GETP` to get player position
- `SETP` to set player position
- `GETB` to get block type
- `SETB` to set block type
- `GETH` to get max height at an x,z coordinate
As well as:
- `REG` to print out registers to console. By default, it will print as `unsigned`, but the VM supports flags to print as:
- `-d` signed
- `-x` hexadecimal
- `-b` binary## Usage
`lc3 [-FLAG] ` where `file.obj` is a [compiled](https://github.com/rozukke/laser-mcpp) binary. `-FLAG` is a single letter flag based on the above Additions section.## Installation
Designed to install on UNIX-based systems. Run `make` in the root directory and then `sudo make install` to make the command globally available.## TRAP formats
| TRAP | **mcpp** function | Description |
| ---- | -------------------- | --------------------------------------- |
| CHAT | postToChat(R0) | Outputs a null terminating string starting at the address contained in R0 to the Minecraft chat. |
| GETP | getPlayerPosition() -> R0, R1, R2 | Gets the position of the player. The x, y and z coordinates are output in registers R0, R1 and R2 respectively. |
| SETP | setPlayerPosition(R0, R1, R2) | This function moves the player to the tile (x, y, z) = (R0, R1, R2). |
| GETB | getBlock(R0, R1, R2) -> R3 | This function retrieves the block's ID at tile (x, y, z) = (R0, R1, R2) and returns it to R3. |
| SETB | setBlock(R0, R1, R2, R3) | This function changes the ID of the block at tile (x, y, z) = (R0, R1, R2) to the value stored in R3. |
| GETH | getHeight(R0, R2) -> R1 | This function calculates the y-position of the highest non-air block at (x, z) = (R0, R2) and returns the value to R1. |
| REG | **Non-mcpp** | Debugging function to print registers to console. See above for alternative print modes. |## Examples
Two `.asm` examples are provided, printing a "Hello World" message in the console and in Minecraft. Run the `.obj` files to test the code out.