24 ms·
People always say that terse code is hard to read and understand. I'd say I just learned a lot from a quick skim of the concise source here. If it had been stru
by tlack 10y ago
People always say that terse code is hard to read and understand. I'd say I just learned a lot from a quick skim of the concise source here. If it had been structured with tons of white space and split over dozens of files/folders/modules, I'd have no chance of understanding it at a glance.
- qwertyuiop924 10y agoTerse code is easy to read. Gratuitously compact code isn't The rule of thumb is that if it's short but in no way obfuscated, it's terse. If it's short, and impossible to read because of it, it's gratuitously compact.
- posterboy 10y agoIt is in multiple files, but still very terse, eg. using single letter variables. /* CPU state */ u8 ram[0x800]; u8 A, X, Y, S; u16 PC; Flags P; bool nmi, irq; I like it.
- andreaorru 10y agoI'm the author. The reason for the single letters is that those are the actual names of the 6502 registers. Glad you like it overall. :)
- pawadu 10y agoIt's really nice that you keep it so close to the actual hardware (not just the variable names, but also the way the logic works in for example PPU). I also love the way you use C++ templates to simplify things!
- posterboy 10y agoaccumulator xchange ... y, something stacky perhaps? program counter flagPort non maskable interrupt, interrupt request I'm sure you knew that though, it's common micro processor nomenclature.
- Two9A 10y agoSpecifically on 6502-derived processors, you have the following registers: Accumulator, X and Y indexes, Stack Pointer, Program Counter, Flags. Of these, only the Program Counter is double-width. Additionally, the zeroth "page" of memory (the lowest 256 bytes) are accessible with a dedicated addressing mode which saves space and time in the program, and can be used as a form of cache.
- serge2k 10y agothe variables are named for the registers they represent, it's not single letter variables for the sake of compactness.
- posterboy 10y agoOK, that was an unfair pick, other variables have longer strings. I just picked the example, because I thought it was cute how short the CPU status is, and because I couldn't remember what nmi ment, at first. Trying to talk about it brought it back to mind, so that worked for me, but I blamed the project in vain, because the decision was made elsewhere. Those electronic engineers!! Let's argue about better names for x and y. is anyone even reading this? I'm prolly not gonna come back to this either.
- Graziano_M 10y agoAbsolutely agree. I'm writing an NES emulator myself and just glancing at this code has given me a few line-saving ideas.