Square and Pong programs not doing anything in VM emulator

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

Square and Pong programs not doing anything in VM emulator

fishboy1887
I have compiled both Square and Pong using the supplied Jack compiler, but when I load the directories in the VM emulator, nothing happens when I press the keys.

I can see the key being pressed, in Pong the interface is drawn but pressing a key does nothing. In Square, the square is drawn but pressing a key has no immediate effect and the square moves ~1 minute later. Am I doing something wrong? I am not sure if they are meant to be this slow.
Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

pm100
make sure you have focus on the keyboard panel below the screen, click on it, it should highlight.



Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

fishboy1887
I have made sure to have focus on the keyboard panel. The cube moves around ~1 minute later which I just do not think is right.



~1 minute later:

Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

pm100
I know this is not helpful but, it works fine for me.

On windows 11.

Java version

PS C:\work\nand2tetris\projects\11\Square> java --version
java 17.0.10 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)
PS C:\work\nand2tetris\projects\11\Square>
Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

pm100
does the keyboard test app work ok? projects/12/keyboardtest
Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

fishboy1887
I do not think so. It took 3 minutes for the text to appear on the screen and then pressing the key did nothing.



I think once I have got my space invaders program to compile I will just move onto week 10, since the purpose of project 9 is to become familiar with Jack and I feel like writing the program should be enough to move on since it is probably not worth continuing with it if I cannot test it in the VM emulator.

I have got the space invaders code in my GitHub repo, if you could, would you be able to just comb through it and let me know if you think it looks well or even test it? (if it is not too much trouble)

https://github.com/blacknand/nand2tetris/tree/main/9/SpaceInvaders

Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

pm100
dumb questions. You have turned the speed up to maximum and turned all the animations off haven't you

Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

pm100
This post was updated on .
In reply to this post by fishboy1887
I ran your code through my compiler toolchain, which takes jack code and compiles down to raw binary, including in all the OS stuff. Fond several errors

Invaders,jack:95
should be instanceAlien.setY()

Player.jack:71
should be invader.checkCollision

SpaceINvaderGame:26
should be alienBullet.dispose()

SpaceINvaderGame:61

should be Screen.clearScreen()

Cannot run the output of this because its too big. My compile includes a linker that only pulls in the bits of the OS that are needed, but its still too big (the hack cpu can only deal with 64k of code and the VM compiler is incredibly in efficient in terms of size). It can just squeeze in the Pong game, but this compiles to 68K. I have been looking for an excude to see if I can make the vm to asm phase more space efficient, so here I go.

I tried to run your code in vmemulator but it crashes pretty early on. Alien.getX is call for a non existant alien. (this is 0). I suspect that its to do with the count of number of liens, you calculate in initialiseAliens() but the caclulate again and the size logic is different. SO you are either going out of bounds of the array or not creating an alien instance for each entry in the array. I am in the middle of coding my own emulator with better debugging but its not finished yet so I cannot debug more

 

Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

fishboy1887
Thank you for your help, I will make the changes now and then move onto chapter 10. Good luck with writing your VM emulator too, it sounds very promising!
Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

fishboy1887
In reply to this post by pm100
No I have had animate on Program Flow. I have tried different speeds as well. Perhaps I just need to perform a full re-install of the software.

Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

pm100
turn off animate, it makes a huge performance difference
Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

fishboy1887
Yes that made it a lot faster
Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

pm100
further optimized my vm code compiler so now I can compile your space invaders into hack binary for the cpu emulator. Thank you for making the code available. Now I need to get my debugger finished so I can fix it - the code crashes almost immediately at the moment
Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

fishboy1887
Thanks for all the effort you have put into helping me improve my program. I have moved onto project 10 now, but I if I do make any changes I will keep updating them for you if it is helpful for working on your debugger.
Reply | Threaded
Open this post in threaded view
|

Re: Square and Pong programs not doing anything in VM emulator

dolomiti7
I see that in your repo that not all of the issues mentioned by pm100 are fixed in your .jack files yet (only some .vm files seem to be updated?).

In addition, there are lots of problems with operators precedence. Jack doesn't specify any precedence. Therefore code like
  while (updateX < 512 - 40) {

can fail since it might be evaluated as (updateX < 512) - 40...

I also saw similar issues in other places. You have to explicitly ensure the precedence for all expressions, even multiplication has no precedence over addition.
For example:
let memAddress = 16384 + y * 32 + x / 16;
looks wrong as well. Most likely it will be evaluated as

(((16384 + y) * 32) + x) / 16

depending on the compiler though.
There might be more similar issues in the code, I haven't looked at it further.

For reference: my toolchain currently compiles it into less then 8k hack instructions for speed optimized code and even less than 3k(?!) for size optimized code. However, I assume that this is not a realistic number and the final corrected code will require more.

I look forward to seeing a working version of your program!