6502 Assembly, Raku

That’s interesting. What kinds of things do you build? I was thinking of trying to make an Atari 2600 game to learn more about it but haven’t had time yet.

[This discussion was split off from another topic.]

I’m not building much new code, I’m more into source code archaeology. I’m currently working on an old C64 game cartridge. I started with a opaque binary blob and with the help of a few tools I was eventually able to reconstruct a working source tree that actually assembles.

Primarily I used the following tools:

  • Radare2 for disassembly.
  • xxd to get side-by-side comparisons of hex dumps.
  • 64tass assembler which is the assembler I’m targeting.
  • md5sum to confirm my builds match the original exactly.

I had to write a bunch of little scripts right from the very beginning. My first challenge was to take radare2 output and make it match tass64’s expectations.

Then I found a bug in how Radare computes two’s complement relative jumps. So, I had to write a script to handle that and insert my branch instruction labels. It mostly worked, with some manual cleanup in the end.

I went with a mix of Perl 5 and Raku for scripting different things depending upon the complexity. Both languages are excellent for utility script creation. Vim Macros were also a huge help.

Because I’m sure someone will ask: I didn’t use Python because, while it excels at API-to-API work it sucks at command-line level stuff in my view. Perl and it’s much more elegant sibling Raku are better suited for quick hack-y scripts that do one thing well.

I found this 6502 instruction set reference to be invaluable. I started with Programming Games for the Atari 2600 on Udemy.

I actually feel like I didn’t set my initial bar low enough. The C64 is actually a pretty complex beast. I may put my current project to the side and try an Atari 2600 game instead. I will still use 64tass however, because I find it so flexible.

1 Like

I went to Larry Wall’s talk in San Francisco when he presented Raku a few years ago, and it looked interesting, but I haven’t tried more than a few examples with it. In one part of the presentation I think he showed an example of writing some Python in the middle of a Perl 6 file, which I thought was pretty cool.

I just checked out the docs and might look at it more closely for scripting. It can’t get much simpler that that:

mkdir "data";
spurt "data/file.txt", "hello world";
say dir;
say slurp "data/file.txt";
1 Like

In one part of the presentation I think he [Larry Wall] showed an example of writing some Python in the middle of a Perl 6 file, which I thought was pretty cool.

First off, I’m jealous. I’ve never been to a live Perl conference.

Yes, there are a whole host of Inline modules available for Raku. Some are more mature than others. I haven’t personally mixed scripts like that, but I suspect I will be doing so at some point.

I just checked out the docs and might look at it more closely for scripting. It can’t get much simpler that that:

mkdir "data";
spurt "data/file.txt", "hello world";
say dir;
say slurp "data/file.txt";

And… you just hit exactly why I like Raku so much. It’s an extremely flexible and it tries hard to get out of its own way for common tasks like the one you just described.

Pro Tip: You can absolutely install Raku and zef (the module package manager) from cpan if you have to. It works just like perlbrew:

$ cpanm App::Rakubrew

The other reason Raku is awesome is because asynchronicity is built into the interpreter all the way down to the underlying VM. While Python has gotten much better at this, Raku makes this really straightforward.

The community is cool too. I’m pretty active on the /r/rakulang sub-Reddit.

What do you think about the future of Perl?

I’m not of the opinion that Perl will “die” in my lifetime. It’s certainly not popular right now. But, I think that’s due in large part to the push towards containerizing way too many things. Python dominates in the container space. But, containers aren’t the “everything pattern” that some people seem to think.

It seems to me that lots of people in the Linux space know Docker but don’t know the classic Unix tool chain unfortunately. Because they didn’t learn a modicum of C followed by some sed and awk, Perl feels alien to them. If you have that experience then Perl 5 feels like a natural (if slightly quirky) extension of those tools.

Obviously, “I got burned by badly written Perl [in the 90’s] and have hated it ever since” is another matter. But, maybe I’m a little harsh, but for the most part I equate “I hate Perl [but have never touched it]” with loudly announcing “I have very thin sysadmin skills.”

What do you think of that take on things? Am I being overly harsh? If you build anything cool with Raku let me know. I’d be curious to see it!

1 Like

Thanks, I got it installed with cpan and rakubrew.

I’m not sure. I think Perl 5 will be around for a long time even if it isn’t the first language that most new programmers will reach for. I don’t know much about Raku but I’m going to send the link to some people and see what they think. I hope it takes off.

I learned a little Perl 5 many years ago but don’t remember much. I actually like the syntax, especially the obfuscated code art. :slight_smile:

I found this PDF on Raku one liners and think it could be useful.

The grammars feature looks interesting.

The Larry Wall talk was just one evening, not a whole conference, unfortunately. I looked for a video and couldn’t find one, but there is a write up here:

If you know of any good Raku talks (or other Raku resources) that are available online, feel free to post links here.

There’s a conference called YAPC(Yet Another Perl Conference). It used to be serveral hundered people every time/year. I’ve attended a few times. I believe Perl hackers are one of the smartest cluster of people because there are a lot of tricks you can play. Maybe not extremely good for building big projects but from artist point of view not many languages in practical use have the features.

There are a lot of good speakers in the community either. I remember a Perl hacker Daimian Conway. Every time I listened to his talk I almost laughed to death. Attending YAPC is not only for technology purpose but also for entertaining.

1 Like

It looks like some of his talks are on YouTube:

I found this book while searching around and it looks interesting:

Yes, I own it. I’ve read it. I confess I still don’t fully understand how Grammars work. I’m 99% sure it’s just a matter of needing to sit down and experiment until everything clicks in my head. Programming is like that: the books guide you but you’ve got to hone the skill yourself. It’s sort of like Karate in that regard, you can’t really learn it from a book.

Oh, I almost forgot: I discovered an interesting subreddit and thought of you. Check out the Reverse Engineering Games subreddit. I’m sure they can help you with your Atari 2600 efforts if you get stuck.

1 Like

Thanks, I’ll check out the reverse engineering link.

I don’t know much about the book, but I skimmed through the first part of this excerpt and it looked interesting.

I stumbled across this and you were the first person I thought of: Creating a Compiler with Raku. I think it was referenced by the Raku Advent Calendar somewhere.

1 Like

Thanks, I’ll check it out. I’d like to figure out how to create an esolang someday, so maybe that will help.

I read about 100 pages of that Parsing with Perl 6 Regexes and Grammars book, and it’s good. I hope that other languages borrow some of those ideas.