so close it hurts...

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

so close it hurts...

agnesi
This post was updated on .
Well, I thought I had completed the entire OS. I was mighty proud of myself. However, my joy was
premature. My OS classes pass all of the individual tests except when I throw the compiled OS into the directory containing Pong it just says "Running..." perpetually at the bottom of the screen.  I believe the problem is somewhere in Screen.vm, when I put all of the other 7 classes into the Pong directory the Pong game executes, with Screen.vm in there it does not.


Would someone be kind enough to look at my code and help?

Joe
Reply | Threaded
Open this post in threaded view
|

Re: so close it hurts...

cadet1620
Administrator
I ran your OS code through my compiler and used it successfully with Pong, albeit drawing is rather slow.

I then ran your code through the supplied compiler and it complained about Screen.jack:
    In Screen.jack (line 61): In subroutine drawPixel: A boolean value is illegal here
Line 61 is
    if (color = true){
I changed this to
    if (color){
and successfully compiled using the supplied compiler.

Using the .vm files generated by the supplied compiler, I could also run Pong.

Were you using your compiler?


In general, it is not a good idea to compare boolean variables. The problem is that the semantics for boolean is that 0 is false and any other value is true. Since there is no provision for type checking in Jack, it is easy to get strange values into boolean variables. If a boolean b's value was 42, then b=true would be false since = is a binary compare.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: so close it hurts...

agnesi
I was using the supplied compiler and , sorry, I actually caught that boolean error earlier and had not updated my code online. Although I had no idea why that was an error until now but that makes perfect sense considering '=' is bitwise.
I think it was the VMEmulator acting up because now it runs fine!! very slowly though but I'm excited to go back and try and make it faster! Thank you so much for your help throughout this process. I'm going to spend some time on optimization and improvements and then start over at the beginning, maybe this time using a different high level language to build the compiler. This book is amazing!

Joe
Reply | Threaded
Open this post in threaded view
|

Re: so close it hurts...

cadet1620
Administrator
I am reminded of something that bit me in the CPU Emulator -- resetting with the << button did not re-zero RAM and I had some code with an uninitialized static variable that hung the second time it was run since it depended on the 0 initialization.

There may be something similar happening with your code and the VM Emulator.

Hint for optimizing Screen: don't use SetPixel to draw horizontal lines.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: so close it hurts...

agnesi
This post was updated on .
Mark,

So I've made some adjustments, using bit masking to draw horizontal lines. It is quite a bit faster but not
quite fast enough I believe. Also, playing pong, when changing directions the paddle sometimes becomes segmented, missing a block until it moves past that part of the screen. I'm not sure what part of my
code is allowing that to happen. Any suggestions as to changes I might want to make to my code.


Joe
Reply | Threaded
Open this post in threaded view
|

Re: so close it hurts...

cadet1620
Administrator
agnesi wrote
ps. Also, does anyone think I should not be posting these solutions online? If so, I can pull them down. I definitely don't want to spoil the fun for others.
Yes, long term we don't want to have solutions or links to them posted in the forum. It's OK to have them temporarily available so that you can get help.

In a case like this it would be better just to email me directly and you can include your source as attachments.

[I'm a bit busy with work at the moment; it might be a few days before I can look at your code.]

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: so close it hurts...

agnesi
No problem. I've had an epiphany and changed my code again and am very happy with the speed now. I'll email you a link to the code but please don't feel under any obligation. You've helped me so much already

Joe