CIS 2400 (Fall 2022) HW 06: Wordle Video Game

This assignment gives students hands on experience with writing LC4 OS Traps, dealing with LC4 I/O and writing “real” C code.

Introduction

In this assignment, you will be writing code to implement a verion of Wordle in PennSim. To do this, you will need to implement a few LC4 OS Traps to handle I/O and implement a few functions in C. It is ok if you have never played Wordle before, there should be enough information for you to get it working in the Wordle Overview section below.

Collaboration

For assignments in CS 2400, you will complete each of them on your own or solo. However, you may discuss high-level ideas with other students, but any viewing, sharing, copying, or dictating of code is forbidden. If you are worried about whether something violates academic integrity, please post on Ed or contact the instructor.

Setup

If you haven’t already, you need to follow the VMWare setup. We recommend you try and figure this out ASAP.

Once you have the VM setup, you should boot it up, and download the following tar file. To download them, you should open the terminal (which should be an application on the right hand side of the desktop) and use the provided command:

After downloading the tar file, you should be able to type in the command “ls” in the terminal, or use the file explorer to see the download tar file. Once you confirm that the file is downloaded, run the following command to decompress the files:

For this assignment, it may be very difficult to get this working without a VM setup, but this can vary depending on the machine you are using. If you would like to try, you can download the following files (that are already provided in the VM) to see if it will work. Note that these should be put in the same directory as PennSim.jar and your other files for this assignment.

Wordle Overview

Wordle is a game about guessing a secret 5 letter word, but you have 6 guesses to get it. Each time you make a guess, the game will tell you how close each guess was to the secret word.

One of the best ways to understand the rules is to try playing it. There are various wordle versions available online if you search for them, though the most common one seems to be the one hosted by the New York Times here: https://www.nytimes.com/games/wordle/index.html

One thing that is unique about our game is that you will be prompted to either have a random word chosen for you or to supply your own secret word. The option to choose your own secret word is to provide some help with debugging (or allows you choose a secret word for a friend!).

Below is a screen shot of the functioning game in PennSim:

lc4_wordle

Note:

Instructions

For this assignment you are provided with a number of files in the associated tar file, some of which you need to finish implementing.

Part 1: Operating System Traps

As we discussed in class, access to the input and output devices on PennSim must be performed in privileged mode by the Operating System (OS for short). The facilities provided by the operating system are exposed to the user program via a series of trap routines which the user program can invoke by executing the TRAP instruction and specifying the number of the trap routine. In this assignment we provide you with a file titled os.asm which contains the assembly code used to implement these operating system traps. We have left a couple unimplemented traps in the file marked with the following comment:

;;; YOUR CODE HERE

Your job in Part 1 is to implement these traps. Specifically, these are:

TRAP_PUTS (25 pts): This function outputs a null terminated string to the ASCII display. When the trap is called register R0 should contain the address of the first character in the string. The last character in the string should be zero. (ie the string is null-terminated).

TRAP_DRAW_SQUARE (75 pts): This trap draws a solid square block on the display. On input Register R0 should contain the starting column in the video memory (0-127) and R1 should contain the starting row in video memory (0 - 123). Registers R2 contains the width and height of the block. R3 contains the color that should be drawn into the designated area. Note that the values in R0 and R1 designate the coordinates of the upper left hand corner of the square on the display.

Part 2: C Game Code

Your job in Part 2 is to implement some of the incomplete C functions needed to run the Wordle game. These functions can be found starting just under the main function starting around line 246. Comments are left above each function to let you know what the expected behaviour of each function is. We have also left the following comment in each function to let you know you need to implement it:

// YOUR CODE HERE

These functions include:

More details on the exact behaviour of these functions can be found in Wordle.c.

Extra Credit: (20 pts)

For extra credit, you can try and modify TRAP_DRAW_SQUARE to handle the case when some of the pixels of the square go past the edges of the screen. If the square would go off the screen either across the top/bottom/left/right edge, don’t draw the pixels that would go over the edge. Still draw all other pixels of the square if there are any. We highly suggest you don’t try this until you have gotten the trap to work without checking for boundaries.

Compiling and Testing

To test your code, you will need to run it in PennSim. To do this, you need to compile Wordle.c into LC4 asm. In order to compile the C code into LC4, you will need to use the lcc compiler. To use the compiler, you must make sure that you have copied lcc, lc3pp, rcc and cpp from the directory ~/LC4_Binaries to whatever directory you are working in for this homework in the virtual machine. You can do this using the file explorer or by running cp ~/LC4_Binaries/* . in the terminal from wherever you have your code for this assignment.

Once you have lcc and its accompanying files copied, you can then compile your code by running ./lcc Wordle.c as shown below.

$ ./lcc Wordle.c

This should produce a file called Wordle.asm or a set of helpful error messages.

Once the file has been compiled, you can run WordleScript.txt from within PennSim to assemble and load all of your files. You can then hit the continue button and your program should start to run.

It can be difficult to test some of your code without implementing others, so we recommend that you implement each part in the following order:

After implmenting one component, we HIGHLY suggest you test it before moving on to the next component. Here are some basics for how you can do a quick check to see if the component is likely working.

Advice & Misc Tips

Submission

Please submit your completed Wordle.c and os.asm files to Gradescope