Hardware Simulator Keyboard Repeat Bug

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Hardware Simulator Keyboard Repeat Bug

This post was updated on .
I think there's a bug involving the HardwareSimulator and keyboard input.  I discovered this while trying to test my Tetris program all the way down on the HardwareSimulator.  The program would run perfectly fine until I started holding down keys, at which point various screen garbage or halting errors would occur.  I kept thinking that I must have a problem in my CPU/Memory/Computer implementation since everything worked fine in the VMEmulator and CPUEmulator.

To investigate more thoroughly, I created a simplified version of the program in which one block is simply falling down and responds to keyboard input.  I also changed the OS Output.init function to do nothing since this function takes millions of clock cycles to complete and slows down testing.

It doesn't matter whether I call the Keyboard.keyPressed() function or not.  And it doesn't matter whether I hook up the Keyboard out pins to the Memory out pins in the Memory.hdl file.  In one test I placed a right-arrow key into keyboard memory like this:

CHIP Memory {
    IN in[16], load, address[15];
    OUT out[16];


In every case, everything works fine until I start holding down a key in the HardwareSimulator.  After a few seconds of holding down a key, things get corrupted in semi-random ways and the program stops functioning correctly.  To be clear, in the case where my Memory chip is always outputting a right-arrow (132) as the keyboard output, the square happily moves to the right _until_ I start holding down the right-arrow key myself, at which point, after a few seconds, some sort of of corruption occurs.

Anyway, I thought I'd post here to maybe save some other people from going crazy wondering why their interactive programs aren't working in the HardwareSimulator.  Although it's probably too late to save them since they're already crazy to be trying it in the first place :-)

My machine is:

Windows 7 64-bit
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) Client VM (build 25.151-b12, mixed mode, sharing)

I'm running these tests on version 2.6.2 of the tools from here:


I think these posts are related to the problem:



Here are some screenshots of my test program...

A happy square:

The happy square happily moves to the right without me physically pressing a key (because I'm inserting the right-arrow key directly into the keyboard output in Memory.hdl):

But when I physically hold down the right-arrow key for a while, the happy square gets sad:

Reply | Threaded
Open this post in threaded view

Re: Hardware Simulator Keyboard Repeat Bug

I just thought to test this bug on the "Square" program from project 09, and it does indeed happen for me.  Again, it's much faster to test if you change the top lines of Output.vm to the following before translating the vm code to assembly and then assembling to hack:

function Output.init 0
function Output.initold 0

Sad square dance: