[HN Gopher] Show HN: Programming language for making NES games
       ___________________________________________________________________
        
       Show HN: Programming language for making NES games
        
       Author : pubby
       Score  : 190 points
       Date   : 2023-03-07 13:52 UTC (9 hours ago)
        
 (HTM) web link (pubby.games)
 (TXT) w3m dump (pubby.games)
        
       | foldor wrote:
       | Really cool stuff! Is there an syntax highlighter available on
       | any IDE's like VSCode available? I'm having a hard time following
       | the documentation without it as it's hard for me to know what is
       | a keyword and what is a variable for example. Single letter types
       | can be hard for me to follow, but I can definitely appreciate
       | their style.
       | 
       | Nice work.
        
       | mungoman2 wrote:
       | I have long dreamed of a language for 8-bit computers/consoles
       | with a compiler that helps scheduling routines.
       | 
       | For example, let's say I have a short snippet of code that needs
       | to run every H blanking period. I should just declare something
       | like
       | 
       | @every_hblank Blabla_code()
       | 
       | Or scheduling some code for X pixels into a line.
       | 
       | Actual scheduling can be done however the compiler wants to,
       | using interrupts or inserting dummy instructions for delays.
       | 
       | I guess in the end it's a constraint problem to solve where all
       | these snippets fit in.
       | 
       | I imagine this makes it easier to write games/special effects as
       | you remove the tricky cycle counting. Easier, but maybe less
       | fun...
        
       | hunta2097 wrote:
       | I got a Windows Defender alert when downloading the Windows
       | binary:
       | 
       | Detected: Trojan:Script/Wacatac.H!ml
       | 
       | Status: Removed
       | 
       | Details: This program is dangerous and executes commands from an
       | attacker.
        
         | easrng wrote:
         | I've never seen a Wacatac detection that wasn't a false
         | positive, but who knows.
        
       | leroy-is-here wrote:
       | I didn't take a deep dive, but I'm interested in how you keep the
       | binary size small. Is it simply that LLVM, etc., all have too
       | much function overhead and don't take advantage of routines over
       | subroutines (function calls)? Or is your back-end just
       | specialized enough to take advantage of architecture-specific
       | features the larger compiler suites don't have the time to care
       | about?
       | 
       | Anyway, this looks dope. Truthfully, we could use more hyper-
       | specific languages like this in all sorts of areas.
        
         | pubby wrote:
         | LLVM and GCC are great at optimizing until the last leg of the
         | race where they convert IR to assembly code. Their back-ends
         | were designed for modern systems, not the ancient 6502, and so
         | getting them to work involves kludges and clever hacks. I
         | recall there being a video on how LLVM approaches this - search
         | LLVM MOS on youtube.
         | 
         | I plan on writing an article on how my own code generator
         | works. If you check my HN profile in a week or two you'll
         | probably see it submitted.
        
           | leroy-is-here wrote:
           | Good work. I'm looking forward to the article.
        
       | benj111 wrote:
       | Why spaces and not tabs for indents?
       | 
       | I know this conversation has probably been had many times before.
       | But if I prefer a 2 space tab, and you prefer a 4 space tab, we
       | both get them how we want them with tabs.
       | 
       | With spaces, I have to put up with your stupidly wide indents,
       | and try not to scratch my eyes out from the pain.
        
         | mwcremer wrote:
         | set your tab stops to 1 space. problem solved.
        
         | entelechy0 wrote:
         | [dead]
        
         | MoSattler wrote:
         | While I share the preference for using 2 spaces, it seems
         | unnecessary to focus solely on criticizing the formatting
         | choices when someone has generously shared a wonderful project
         | they created during their free time, available for all to enjoy
         | at no cost.
        
         | pubby wrote:
         | For languages with significant whitespace, mixing tabs and
         | spaces can be very error prone. It can look like two lines of
         | code have the same indentation, but if the compiler's tab width
         | doesn't match yours it would not parse correctly. See Haskell
         | for an example of what not to do.
        
         | resizeitplz wrote:
         | A question as old as time (or as old as the existence of code
         | editors). 4k results on Hacker News alone - and surely
         | thousands, if not millions more, across the internet. There is
         | no right answer, just differing preference.
         | 
         | https://www.google.com/search?q=spaces+vs+tabs+site%3Anews.y...
        
         | incrudible wrote:
         | Getting over these pet peeves is one of the best skills you can
         | acquire as a programmer.
        
           | postalrat wrote:
           | Time to turn off linters. Seriously your linting rules suck.
        
             | incrudible wrote:
             | If you're unironically linting whitespace you need to get
             | your priorities straight.
        
           | stcroixx wrote:
           | Agreed. The next challenge is getting over the annoyance
           | every time someone wants to debate this AGAIN.
        
       | AdmiralAsshat wrote:
       | Does this language have support for being able to save the game's
       | state into a simulated battery a la Legend of Zelda/Metroid?
        
         | pubby wrote:
         | There's no built-in support for that, but you can still do it.
         | Nowadays flash memory is used rather than battery stuff, but
         | the idea remains the same.
        
       | lastdong wrote:
       | Congrats on the release! Website and code look super clean, and
       | looks like super useful for anyone getting into NES game
       | development.
       | 
       | - What languages did you use as inspiration?
       | 
       | - Is it possible to write a game to a physical cartridge and play
       | it on a real snes?
       | 
       | Thanks for sharing your amazing work!
        
       | Taikonerd wrote:
       | This is a really interesting approach. One thing that surprised
       | me from the code snippet:                   fn play_sound()
       | {$4015}(%100)             {$4008}($FF)
       | 
       | Are these hard-coded memory addresses meaningful to NES devs? I'm
       | surprised that they don't have more readable aliases, like
       | $SOUND_ROM_BASE_ADDR or whatever.
        
         | wk_end wrote:
         | I can't speak for the NES, but I've done lots of Game Boy asm
         | coding, and personally - although others feel differently - I
         | prefer using the register addresses rather than trying to
         | memorize a bunch of unofficial names. Usually context/the sort
         | of abundant comments asm necessitates indicates well enough
         | what the read/write is doing, and if I want to look up the
         | register to get a better idea of it, well...the names are
         | unofficial, there isn't clear consensus about what these
         | registers should be called, so it's easier to lookup the
         | address in docs, too. Eventually the common ones you memorize,
         | anyway; there's only a handful on these systems.
        
           | karmakaze wrote:
           | Same. I started on an Atari 8-bit and had most of the i/o
           | memory map memorized in both hex and decimal as well as the
           | ROM i/o routine address/parameters.
        
         | nubinetwork wrote:
         | Yes.
         | 
         | https://www.nesdev.org/wiki/APU#Registers
         | https://github.com/cc65/cc65/blob/master/asminc/nes.inc#L44
        
           | kristiandupont wrote:
           | Still seems to me like something there should be "standard
           | library" symbols for? Or is there some cultural reason for
           | this?
        
             | Drakim wrote:
             | Some people prefer localhost, others like 127.0.0.1
        
             | nubinetwork wrote:
             | You would think so, but between NIH, old unmaintainable
             | code (like nesasm/magickit), or not knowing other code
             | exists, a lot of times you'll see people reinventing the
             | wheel.
        
             | pubby wrote:
             | There's standardized names for the graphics registers. The
             | convention for the sound registers is to use the address
             | itself, as there are lots of sound registers and each does
             | multiple things.
        
             | postalrat wrote:
             | Would you rather have a many different set of constants for
             | the same addresses or just the addresses themselves?
             | 
             | Or do you think all NES developers can agree on the same
             | names?
        
       | pubby wrote:
       | This is a long-running personal project I've had to write an
       | optimizing compiler from scratch. Everything was done by me,
       | including the lexer/parser, SSA-based IR, high-performance data
       | structures, and code generator.
       | 
       | Originally I wasn't targeting the NES. It started as a scripting
       | language, then it morphed into a C++ replacement, and then
       | finally I turned it into what it is today. The large scope of the
       | project and colorful history means it's still a little rough
       | around the edges, but it's now working well enough to post.
        
         | nunobrito wrote:
         | It is looking fantastic. Great work!
        
         | tibbon wrote:
         | Not to increase your scope, but have you considered making it
         | work across other 6502 systems?
        
           | pubby wrote:
           | That was the original plan, but I veered off to focus on
           | doing one system really well. I figured if some company
           | wanted to sponsor a port, I could do it, but otherwise I'd
           | direct people to other compilers like LLVM-MOS. I do think
           | it's possible to port, but it's not trivial. Some areas -
           | like the linker - are very specifically designed for the NES.
        
             | agiacalone wrote:
             | This is a really neat project. It reminds me a lot of
             | Inform, in the sense that a full "modern" language was
             | designed around creating an older-style of game.
        
             | TedDoesntTalk wrote:
             | > if some company wanted to sponsor a port
             | 
             | I don't think any company in 2023 is going to sponsor port
             | of a 6502 compiler, unfortunately.
        
               | detrites wrote:
               | You may be mistaken. Retro hw/sw and gaming is a booming
               | business at the moment. Plenty of crowdfunded projects
               | that have been overfunded and then delivered, and even
               | consumer goods being shipped worldwide in major
               | department stores.
        
           | cpeterso wrote:
           | There is an experimental LLVM backend for 6502!
           | 
           | https://llvm.org/devmtg/2022-05/slides/2022EuroLLVM-LLVM-
           | MOS...
        
         | [deleted]
        
         | pkaye wrote:
         | You should make a link to the examples directory prominent on
         | the webpage so others get an quick idea of the language
         | features.
        
         | agentultra wrote:
         | This is very cool. I had wanted to do a project like this once.
         | Nice work!
        
       | bmitc wrote:
       | As someone trying to undertake some personal projects like this,
       | I have a question. How do you keep motivated enough to work on
       | this for so long and dedicatedly? As a solo developer, how did
       | you manage things like getting stuck on technical issues that
       | were either bugs out of your control or something you didn't have
       | the knowledge to know how to fix?
        
         | pubby wrote:
         | Motivation was sporadic. I'd have a few weeks of intense focus,
         | followed by months of inactivity. The nice thing about
         | compilers it that 90% of their code is interesting, so there
         | was always something fun worth coming back to. Besides, I put
         | other projects on hold so I wouldn't get distracted.
         | 
         | I don't always know the best way to do something, but so long
         | as I know _some_ way to do it, I can make progress. Tough bugs
         | are just a matter of perseverance. And hey, if it 's still not
         | working, just drop the feature. In a personal project, you can
         | do that and nobody can stop you.
         | 
         | One more thing: don't talk about your projects until they're
         | 95% done. Seeking early validation is a poison pill.
        
           | bmitc wrote:
           | Thanks for the response! My projects aren't that far along,
           | but this echoes a lot of my experience and helps me remember
           | these are common feelings.
           | 
           | > I don't always know the best way to do something, but so
           | long as I know some way to do it, I can make progress.
           | 
           | This helps a lot. Thanks! One of my issues is being able to
           | be ok with feature gaps or bugs. I can solve them if they
           | were created by me, but there are some that need outside help
           | as they are likely bugs in external software or even drivers.
           | But maybe it makes sense to press on and revisit later.
           | 
           | > One more thing: don't talk about your projects until
           | they're 95% done. Seeking early validation is a poison pill.
           | 
           | Is this because you draw attention to an unfinished project,
           | get distracted by feature requests or praise, or something
           | else?
        
             | pubby wrote:
             | Yeah, external bugs suck, but usually there's workarounds.
             | 
             | > Is this because you draw attention to an unfinished
             | project, get distracted by feature requests or praise, or
             | something else?
             | 
             | If you get a bad reaction, you'll be demotivated. If you
             | get a good reaction, you'll feel satisfied and not have the
             | drive to keep working. Either that, or you'll devote more
             | and more time to posting on social media, getting less work
             | done in the process.
        
               | detrites wrote:
               | > If you get a bad reaction, you'll be demotivated. If
               | you get a good reaction, you'll feel satisfied and not
               | have the drive to keep working.
               | 
               | This is so important, and not only for sw dev but
               | anything.
               | 
               | Anyone who is struggling with completing personal
               | projects, try starting the next one with the explicit
               | goal to not speak about it - with anyone - until it's
               | either complete, or very near. It may be hard to do at
               | first but ultimately worth it.
        
           | proper_elb wrote:
           | If you don't mind: What would you working on it look like, on
           | a typical work-day look like, hour wise? Raise up at 5am and
           | hack away for 2h, or come back from day job and straight into
           | the fun thing, or wait a bit and than hack away... What
           | worked for you?
           | 
           | Lately, I seem to manage 1-3 days of coding on my hobby
           | project after work, provided I have some features where I can
           | see meaningful success within 90 minutes of coding (+ the
           | same time for debugging or researching new libraries, if
           | needed)
        
             | pubby wrote:
             | I think it helps that I'm not working as a software
             | developer right now, so I have more energy for coding
             | projects. (I'd like to write software professionally, but
             | no company responds to my applications.)
             | 
             | Regarding time, I have thinking periods and coding periods.
             | On thinking periods I'll take a 30-60 minute walks and
             | figure things out in my head. On coding periods, I'll spend
             | 1-2 hours in the text editor per day, sometimes more, at
             | whatever time suits me. It's pretty laid back and I don't
             | beat myself up if I stop.
        
               | proper_elb wrote:
               | Sorry for the assumption and thank you for your answer!
               | Regarding time, I work similar. In work-life, it gets a
               | bit more muddy (basically the time talking walks expands
               | and turns into time spent in meeting, talks, support
               | etc.)
               | 
               | I would encourage you to ask here on HN and maybe also
               | over at reddit (i.e.
               | https://old.reddit.com/r/cscareerquestions) for feedback
               | on landing a software dev job. Getting the foot in the
               | door can be tough, after that it get easier. I wish you
               | best of success in landing a job! :)
               | 
               | Edit: It might be a good idea to mention your current job
               | search in your most visible comments here in this thread.
               | Also, you could mention it on your website! ;)
        
           | and0 wrote:
           | I strongly agree on the last point about early validation,
           | albeit with two exceptions: when you're marketing a product
           | you want to sell and want to generate hype, or your product
           | requires early feedback. I've kept things hidden to keep
           | myself motivated only to find I was left with the horribly
           | unmotivating task of _shudders_ marketing. Also, my friends
           | who I thought would love it had fundamental changes they 'd
           | want to find it useful.
        
         | MysteryChessBox wrote:
         | Honestly keeping yourself motivated through the end is a
         | monumental task and I can only do it on smaller games (which
         | coincidentally fit the NES hence why I actually have a finished
         | game on it). It's all too easy to just quit when all the fun
         | stuff gets programmed, leaving only the boring parts left. If
         | there's a magic trick for bigger project motivation I'd like to
         | know, too.
        
         | cloogshicer wrote:
         | Think of something you really enjoy doing. As a random example
         | I'll pick "playing video games".
         | 
         | Now, imagine you've been playing the same game for a couple
         | days in a row. And you're getting kinda sick of it. Not that
         | it's bad, it's got its good moments. You've just had enough of
         | it, for now. Would you continue playing it?
         | 
         | The answer is (hopefully): Of course not! You'd move on to
         | something else you enjoy more. If the game was truly engaging,
         | you'll come back to it anyways, maybe a few days/weeks/months
         | later, when it captures your interest again.
         | 
         | Since a few years this is my attitude towards side projects.
         | The flipside is that you have to accept the fact that 99% of
         | the things you start will never get finished. But that's ok, as
         | long as you enjoy the work itself. Of course that doesn't mean
         | there aren't difficult moments. But there has to be a genuine,
         | intrinsic motivation, which is independent of shipping
         | something.
         | 
         | Keeping a journal/todo-list for every project (I use an
         | infinite bulleted list like Dynalist) really helps, since you
         | can just come back to a project anytime by looking at the end
         | of the list.
        
       | warpspin wrote:
       | Pretty cool project. While I never did NES games, I did assembler
       | on the C64 for a while. The language alone minus the NES parts
       | would already have been super useful back then at least for the
       | high level parts of the programs I wrote.
        
       | jonny_eh wrote:
       | > Handling banks is normally a tedious affair for programmers,
       | but NESFab handles it for you. The compiler smartly allocates
       | code and data into banks, with the gritty details abstracted
       | away.
       | 
       | Killer feature, but is there a cost to bank switching? Could
       | abstracting it result in a lot of performance cost?
        
         | pubby wrote:
         | There is a cost: subroutine calls get wrapped in something
         | called a trampoline, and some data is duplicated across
         | multiple banks. You would do both of these things in assembly
         | language too, and could even do it more optimally, but it's an
         | NP-hard problem and takes a lot of thinking.
        
       | nubinetwork wrote:
       | Its nice that people are still writing code for the NES, but I
       | have to ask what makes this better than using ca65... assembly
       | isn't hard to learn.
        
         | pubby wrote:
         | I like 6502 assembly a whole lot, but there's definitely
         | limitations to it at scale. Multi-byte arithmetic is a chore,
         | bank switching is a pointless time sink, and managing local
         | variables makes me want to pull my hair out. Those were the
         | deciders in making this.
        
           | karmakaze wrote:
           | Use an assembler with macros. I spent so much time 'in the
           | zone' of Atari Macro Assembler[0] editor MEDIT, that when
           | someone interrupted me I'd simply respond "I'm in medit" as
           | if in meditation.
           | 
           | [0] https://atariwiki.org/wiki/attach/Atari%20Macro%20Assembl
           | er/...
        
       | a_e_k wrote:
       | Nice work! Pubby, it looks like the markdown for the
       | documentation goes off the rails in 12.3.
        
       | dom96 wrote:
       | Really cool but shouldn't this actually be a library rather than
       | a programming language?
        
         | detaro wrote:
         | Given the authors top comment here the answer to that is a very
         | clear "no".
        
       | algem wrote:
       | this is really cool, thanks for sharing.
        
       ___________________________________________________________________
       (page generated 2023-03-07 23:00 UTC)