StarHack - Classic Trek game in Jack/Hack

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

StarHack - Classic Trek game in Jack/Hack

lambda_express
Thought I would share a link to a classic "Trek"-style game I built after finishing the second course.


StarHack

Also includes a few language extensions and compiler optimizations mostly around reducing the number of compiled instructions: register variables, function inlining, a few simple optimizations, more terse function calls.
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

WBahn
Administrator
Looks interesting. I'll try to take a look at it once things settle down a bit for me in a few weeks.
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

lambda_express
This post was updated on .
Interested what people think. After I had written most of the Jack code I realized the equivalent assembly was on order of 200K lines; I felt obliged to make it fit on the target platform.

Today I found a couple of bugs resulting from the rewrite - very embarrassing. Have pushed an update.

On Sat, May 1, 2021 at 9:25 PM WBahn [via Nand2Tetris Questions and
Answers Forum] <ml+s32033n4035971h46@n3.nabble.com> wrote:
>
> Looks interesting. I'll try to take a look at it once things settle down a bit for me in a few weeks.
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/StarHack-Classic-Trek-game-in-Jack-Hack-tp4035970p4035971.html
> To unsubscribe from StarHack - Classic Trek game in Jack/Hack, click here.
> NAML
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

WBahn
Administrator
That you got it from 200 K lines down to the 32 K line ROM capacity is quite an achievement.

Don't be embarrassed by bugs that get introduced. That's almost inevitable. I doubt there's a single program of any significant complexity that is completely bug free.
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

lambda_express
I don't disagree I just have a new apprecation for what it takes to work with limited space - I was concentrating on keeping RAM consumption down and didn't anticipate how fast I would run out of ROM. Just to date myself I played a lot of these Trek games on 8 bit machines and they were considerably more complex that what I did here.

On Sun, May 2, 2021, 10:01 AM WBahn [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:
That you got it from 200 K lines down to the 32 K line ROM capacity is quite an achievement.

Don't be embarrassed by bugs that get introduced. That's almost inevitable. I doubt there's a single program of any significant complexity that is completely bug free.


To unsubscribe from StarHack - Classic Trek game in Jack/Hack, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

WBahn
Administrator
I associate with some folks that take working resource-starved challenges to an extreme. It's amazing what they've been able to do with the bottom-end PIC microcontrollers, such as the PIC16C52, that have 25 bytes of RAM (yep, bytes) and a 384 instruction ROM. One person is really into PC assembly code challenges where your entire program has to fit within some small space, often something like 1024 bytes and occasionally 256 bytes. My first professional design was with the PIC16C62 that had a whopping 128 bytes of RAM and 2K of ROM -- and I caught some grief from them for taking the easy way out.
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

magiwanders
In reply to this post by lambda_express
This is very nice hack computer software, and you also respect the ROM limit! Awesome! Your binaries are also the first third party binaries I tested in my hack computer javascript implementation and they work flawlessly. Check my original post here and let me know what you think of it! Have a great day!
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

lambda_express
Nice, I was hoping to be able to put these into a javascript simulator
but had trouble getting the existing ones to work well.

Your simulator works really well. Very cool. And it's fast. I have to
tune it down to ~4K cycles / frame to make it appear to run at the
same speed as the Java CPU simulator,

Two slight hitches to do with input
  - I'm having a slight problem with my browser (Chrome, MacOS) when I
use the enter key where it will reset the machine - I think it's more
a result of me clicking around the screen and losing input focus.
  -  The game is hardwired to assume input is uppercase only, not a
big deal, honestly I could just change that in the code.

On Tue, May 18, 2021 at 9:40 AM magiwanders [via Nand2Tetris Questions
and Answers Forum] <[hidden email]> wrote:
>
> This is very nice hack computer software, and you also respect the ROM limit! Awesome! Your binaries are also the first binaries I tested in my hack computer javascript implementation that I did not myself compile, and they work flawlessly. Check my original post here and let me know what you think of it! Have a great day!
>
> ________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/StarHack-Classic-Trek-game-in-Jack-Hack-tp4035970p4036017.html
> To unsubscribe from StarHack - Classic Trek game in Jack/Hack, click here.
> NAML
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

magiwanders
Hi lambda! Thank you so much for checking out my simulator!

ENTER resetting the game is a known issue, it has to do with the fact that the last button you press is "START" and it remains selected, so when you press enter it gets pressed again and stops the simulator. A quick workaround is to click elsewhere on the page after clicking "START" with your mouse.

Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

Lozminda
In reply to this post by lambda_express
Just checking out StarHack.

It looks like you've introduced a couple of xtra commands into the Jack syntax, inc and register, inc very handy and can see how that would reduce instructions, but not sure what register is doing ?

It's been a long time since I coded any Jack, so perhaps I've made a mistake in my "analysis". (Started the course 3 years ago but only got to chapter 9, other things took over, drat!)

I wish my code was as efficient, great stuff !

Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

lambda_express
Thanks!

Register is really a shorthand for declaring a local variable off the stack. The word register is probably not the best - I co-opted it from half-remembered C programming. In C register is a hint to try to use an actual CPU register for a variable, but since hack CPU's don't really have a lot of registers I wound up implementing registers as statics. So a more accurate name would be 'static local variable".

The reason for using local statics instead of local vars... you don't have to do any pointer arithmetic to dereference the values, which can save a ton of instructions especially for methods with lots of variables (trying to get to the 5th local variable in the hack CPU is a lot of work!). Using them is a little bit dangerous though - you have to be sure they get initialized before use and also guarantee that they don't get used recursively.





On Mon, May 24, 2021 at 9:38 AM Lozminda [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:
Just checking out StarHack.

It looks like you've introduced a couple of xtra commands into the Jack syntax, inc and register, inc very handy and can see how that would reduce instructions, but not sure what registers doing ?

It's been a long time since I coded any Jack, so perhaps I've made a mistake in my "analysis". (Started the course 3 years ago but only got to chapter 9, other things took over, drat!)

I wish my code was as efficient !




To unsubscribe from StarHack - Classic Trek game in Jack/Hack, click here.
NAML
Reply | Threaded
Open this post in threaded view
|

Re: StarHack - Classic Trek game in Jack/Hack

Lozminda
Sneaky !

It prompted my search as I thought it's use was depreciated (I know a tangent) in C/C++ (I know not the same)

Register keyword stuff