Skip to content

rozukke/lc3-vm-mcpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LC3 Virtual Machine for mcpp

made-with-cpp creator-justinmeiners adapted-by-rozukke GitHub license

This is a C++ based virtual machine for the LC3 assembly language, adapted to work with mcpp the Royal Melbourne Institute of Technology (RMIT) to supplement the COSC2084 (Programming Studio 2) course. The original project by Justin Meiners can be found here. Thank you to Michael Dann 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] <file.obj> where file.obj is a compiled 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.

About

LC3 virtual machine written in C++ that implements mcpp related TRAPs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •