Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactor #17

Merged
merged 8 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ The directory should look like this:
```text
CatsAndDogs
├── bmem.mem
├── catsAndDogs.json
├── CatsAndDogs.json
├── dmem.mem
├── imem.mem
└── smem.mem
```

Our default configuration JSON file is [`catsAndDogs.json`](src/test/TestProjects/CatsAndDogs/catsAndDogs.json). You should download it and modify it, if necessary, for your own project.
Our default configuration JSON file is [`CatsAndDogs.json`](src/test/ExampleProjects/CatsAndDogs/CatsAndDogs.json). You should download it and modify it, if necessary, for your own project.

You shouldn't need to change many fields, if any, since it uses the same memory mappings as the ones in the project specification. If your memory files are named differently from `{b,d,i,s}mem.mem`, then change your memory file names, or change the names in the JSON file.

Expand All @@ -130,7 +130,7 @@ The `"type"` fields contain the special types `Keyboard`, `Accelerometer`, etc.,
}
```

`catsAndDogs.json` has the special types `InstructionMemory`, `DataMemory`, `BitmapMemory`, `ScreenMemory`, `Keyboard`, and `Accelerometer`.
`CatsAndDogs.json` has the special types `InstructionMemory`, `DataMemory`, `BitmapMemory`, `ScreenMemory`, `Keyboard`, and `Accelerometer`.

LED and Sound are not considered special types because they do not serve any special purpose (e.g., I/O) in the emulator. That is, the emulator does not show 12 LED's on the screen or play sound (unsupported, as of now). Thus, LED and Sound are mapped with type `DataMemory` at the appropriate memory addresses so that you can at least inspect the values at those memory addresses in the Other Memory tab in the emulator.

Expand All @@ -151,7 +151,7 @@ For sound, specifically, the original Windows-only [MIPS Emulator](https://githu

### Additional memory mappings

If you have additional memory mappings in your project, you can create those mappings in the JSON with type `DataMemory` to view the values in the emulator, similar to the Sound mapping shown above. For example, see [rubiks.json](src/test/TestProjects/Rubik's/rubiks.json), which has 7 additional mappings. For example,
If you have additional memory mappings in your project, you can create those mappings in the JSON with type `DataMemory` to view the values in the emulator, similar to the Sound mapping shown above. For example, see [rubiks.json](src/test/ExampleProjects/Rubik's/rubiks.json), which has 7 additional mappings. For example,

```json
{
Expand All @@ -175,7 +175,7 @@ This should be all you need. For advanced mapping options, see [Advanced configu

## Issues

**Please** report issues with MIPS emulator (e.g., bug report, feature request, usage question) at [Issues](https://github.com/madiali/mips-emulator/issues).
Please report issues with MIPS emulator (e.g., bug report, feature request, usage question) at [Issues](https://github.com/madiali/mips-emulator/issues).

## Developer information

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/comp541/GUI/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ResourceBundle;

/**
Expand Down Expand Up @@ -58,6 +60,8 @@ public class MainController implements Initializable {
// Misc
@FXML private Label statusLabel;

public static final Path EXAMPLE_PROJECT_DIR = Paths.get("src/test/ExampleProjects");

/** Constructor with no params is necessary for loader.getController() in AppLauncher. */
public MainController() {}

Expand Down Expand Up @@ -242,12 +246,16 @@ public void renderAllDisplays() {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
System.out.println(
"Load a project configuration JSON file. Examples: https://github.com/madiali/mips-emulator/tree/main/src/test/TestProjects");
"Load a project configuration JSON file. Examples: https://github.com/madiali/mips-emulator/tree/main/" + EXAMPLE_PROJECT_DIR.toString().replace("\\", "/"));
try {
handleOpen();
} catch (IOException ioe) {
throw new IllegalArgumentException(
"Your JSON file doesn't exist or something else went wrong during initialization");
} catch (NullPointerException npe) {
System.out.println("No JSON file selected. Please load a required project configuration JSON file next time you run, " +
"and examples are at the link above.\nExiting...");
System.exit(1);
}
}
}
85 changes: 85 additions & 0 deletions src/test/ExampleProjects/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# README

Please watch the demo video shown at the top of the [README](https://github.com/madiali/mips-emulator), if you haven't already.

The two directories here are example projects containing the 5 required files for MIPS Emulator:

1. Configuration JSON file
2. `{b,d,i,s}mem.mem`

You can run MIPS Emulator and load either JSON file in these directories to run the projects.

[CatsAndDogs.json](CatsAndDogs/CatsAndDogs.json) is our default JSON file that specifies the memory types `InstructionMemory`, `DataMemory`, `BitmapMemory`, `ScreenMemory`, `Keyboard`, and `Accelerometer`. It also contains LED and Sound, specified with type `DataMemory` so that their values can be viewed in the Other Memory tab in the emulator. All are specified with the default memory addresses given by the project specification, so you probably won't need to change that.

[rubiks.json](Rubik's/rubiks.json) contains 7 additional memory mappings, also specified with type `DataMemory`.

To test MIPS Emulator, controls for these projects are provided.

## CatsAndDogs

Use the accelerometer y slider to move the umbrella.

Cat and dog sprite positions are not randomized when run in the emulator because Madison handled RNG in Verilog. The emulator cannot simulate Verilog code, of course.

## Rubik's

[Project demo](https://youtu.be/CWI60TmpJHM)

These controls follow [Rubik's cube notation](https://youtu.be/24eHm4ri8WM).

## Face moves

| Key | Action |
| :---: | :----: |
| u | U |
| d | D |
| l | L |
| r | R |
| f | F |
| b | B |

## Slice moves

| Key | Action |
| :---: | :----: |
| m | M |
| e | E |
| s | S |

## Rotations

| Input | Action |
| :---------------------------------------------------: | :----: |
| x | x |
| y | y |
| z | z |
| accelerometer x (when outside the range $[114,398]$ ) | x |
| accelerometer y (when outside the range $[82,430]$ ) | y |

## Move configuration

| Key | Action |
| :---: | :-------------------------------------------: |
| 1 | Make future moves clockwise (e.g., U) |
| 2 | Make future moves 180 degrees (e.g., U2) |
| ' | Make future moves counterclockwise (e.g., U') |
| w | Make future moves wide (e.g., u) |

w can be composed with any direction 1, 2, or '. Therefore, u, u2, and u' can all be performed.

## Miscellaneous

| Key | Action |
| :---: | :--------------------: |
| g | Solve the cube |
| n | Next scramble |
| p | Previous scramble |
| c | Create random scramble |
| t | Toggle `is_legit` |
| v | Toggle `timer_mode` |

I handled RNG in Verilog, so I'm pretty sure creating a random scramble doesn't work in the emulator and would just set the scramble to the next one.

`is_legit` is a boolean for whether the program will pause and play music when the cube is solved. For example, when g is pressed, `is_legit` will always be false.

`timer_mode` is shown in the demo.
Loading