🡄 Previous

Next 🡆

Contents > Applications

General-purpose Computer

The General-purpose Computer executes a machine code binary via emulation or simulation. To run it from the command-line, enter the following.

java -cp target/tetromino-computer.jar tetrominocomputer.gpc.app.GeneralPurposeComputer -c [ processor and memory class name ] -b [ binary filename ] -l [ cycle left filename ] -r [ cycle right filename ]

The arguments are optional. They default to:

java -cp target/tetromino-computer.jar tetrominocomputer.gpc.app.GeneralPurposeComputer -c tetrominocomputer.gpc.app.MCProcessorAndMemory -b example.bin -l CYCLE_LEFT.mc -r CYCLE_RIGHT.mc

The General-purpose Computer provides two implementations of an abstract processor and memory type in the tetrominocomputer.gpc.app package: EmulatedProcessorAndMemory and MCProcessorAndMemory. Both load the binary file from code/bin to set the starting memory state.

EmulatedProcessorAndMemory contains variables in place of registers and memory, and Java code that directly manipulates those variables to reproduce the effect of every machine code instruction type. It was created for testing purposes. It enabled the development of example.asm before MCProcessorAndMemory was available.

MCProcessorAndMemory is the simulator detailed in a prior section. It runs the MC programs in code/mc, and it simulates the TS programs by applying the lookup tables in code/luts that were derived from them. It does not use the JavaScript files.

MCProcessorAndMemory accepts the left and right cycle MC program filenames because their contents depend on the binary file size. EmulatedProcessorAndMemory ignores those arguments.

The video below demonstrates the performance of MCProcessorAndMemory on a Dell XPS 8930 desktop featuring an i7-8700K CPU, 64 GiB of RAM, and Windows 10 Pro—a five year old machine at the time of this writing. It runs at approximately 5.75 frames/sec with Java 8u351. For unknown reasons, it runs slower on more recent versions of Java, at approximately 5.25 frames/sec. The game pauses momentarily while clearing lines because shifting rows requires copying a large amount of data, and the processor cannot do anything else until that finishes.

EmulatedProcessorAndMemory runs at approximately 400 frames/sec, nearly 70× faster. But the General-purpose Computer caps the maximum frame rate at 10 frames/sec.

Here is the game's key mapping:

ActionKey
Start gameEnter
Shift left
Shift right
Soft drop
Rotate counterclockwiseZ
Rotate clockwiseX

🡄 Previous

Next 🡆