Live data from Hacker News

Video Chess disassembled and commented

nanochess.org

31–40 of 72 posts

Re: Video Chess disassembled and commented

#31
post #6

I think I’m pretty good at writing software, and then I see stuff like this, and the impostor syndrome kicks in hard. A fully working chess game in 4K of ROM, using each of the 128 bytes of RAM for several purposes? That’s some genius. Bravo to OP for the disassembly and explanation, too!

I've worked through all the 2600 programming books, including the authors. I've yet to start on anything of my own worth while. At one point I thought maybe I could start reverse engineering some games for some inspiration. Didn't get more than a few hours into it before I decided I'd just rather watch other people do great things with the 2600.

You may want to give Batari Basic a look.

In the early 00's one enthusiast had the idea to make a simple BASIC compiler for the 2600. I was one of the early testers and the first thing I did was make a functional "BREAKOUT", bounce the ball off the bat to eliminate bricks in a wall game.

It took a couple hours and was, I think, the first (and buggy) playable program authored by someone other than the language author. And it was fun!

What the author did was kind of brilliant in that he packaged up several of the common tricks used to make games and presented them along with a simple BASIC.

Variables, for example, were just bytes and or individual bits, essentially addressing bits in a byte like an array.

     J = %01101101
     If J[2] = 0 then X = X +1
Here is a sample program to move a sprite around on the screen:

    x=50
    y=50

   main2

    COLUP0=28
    COLUBK=02

   player0:
     %00011100
     %00011000
     %00011000
     %00100000
     %01011010
     %01111100
     %00100100
     %00010000
     %00011000
     %00111100
     %00011000
    end

     player0x=x
     player0y=y

     drawscreen

     if joy0right then x=x+1
     if joy0left then x=x-1
     if joy0up then y=y-1
     if joy0down then y=y+1

     goto main2
On the VCS, a game is a loop that renders the display and in-between display frames, during VBLANK, one computes the next game state to be displayed, and it all runs at 50 or 60Hz, locked to the display refresh rate.

The BASIC exposes the little bit of hardware to a programmer in a simple way that I found to be a lot of fun because the really hard parts of assembly language are not necessary, but can be written in-line just as easily as defining a sprite is:

    asm
     LDA J
     ASL
     ASL
     .
     .
     .
    end
Any hoo, it was fun and surprisingly productive. I found I could knock out simple concepts in an hour or two.

Re: Video Chess disassembled and commented

#32
post #5

I started developing software as a kid on a Commodore 64, and I thought we were pretty clever if we were able to accomplish interesting things using only 32KB of RAM. But the idea that somebody was able to develop a full chess engine using only 128 Bytes of RAM boggles my mind.

By the way: right now I'm working on a chess training project(1), and I'm thinking that a marketing cofounder could really help. If anybody is interested, my contact info is in my profile. (1) https://chess.braimax.com

Looks neat.

Better call the puzzle training something else than Puzzle Rush though.

Re: Video Chess disassembled and commented

#34
post #18

Earlier quoted context omitted.

That's perpetually true. "You're trying to do machine learning on a desktop PC?" "Hmmm, I wonder if we could use the GPU as a math engine?" But holy cow, that chess game really pushed the limits! (A side note I like to bring up occasionally: my first "computer" was "Atari BASIC" on my 2600. It had 63 bytes of RAM, I think. That didn't last long until my parents brought home a TS1000 with a luxurious 1KB of RAM.)

> But holy how, that chess game really pushed the limits! Having 4 kilobytes of ROM made it relatively easy, I think. If one ignores draws by repeated positions (which I think all small chess programs do), board state can easily be stored in 67 bytes or so (64 for the board proper plus four bits for whether various castlings are allowed, plus a byte indicating the square for en passant opportunity, plus a byte for co…

Each square of the board doesn't even need a byte, only a nibble. There are 6 piece types so that fits in 3 bits, plus one for color. If you pack two of those nibbles per byte then you can do it in 32 bytes plus the castling and en passant bits.

Video Chess uses the lower nibble of 64 bytes for the board, and the upper bits of those for various other purposes.

You actually could condense further than that. Build the storage as an array of pieces rather than squares, so 32 storage locations. Each of those locations needs only 6 bits to indicate that piece's current square. (And even only 5 bits per bishop, although pawns need three more bits each to handle promotion and to which piece type.) Of course, writing an engine for that data structure is much more cumbersome, since it can't look at a square to find what piece is on it, instead it has to iterate over all the pieces to find out what's on a square.

Re: Video Chess disassembled and commented

#35
post #6

I think I’m pretty good at writing software, and then I see stuff like this, and the impostor syndrome kicks in hard. A fully working chess game in 4K of ROM, using each of the 128 bytes of RAM for several purposes? That’s some genius. Bravo to OP for the disassembly and explanation, too!

I've worked through all the 2600 programming books, including the authors. I've yet to start on anything of my own worth while. At one point I thought maybe I could start reverse engineering some games for some inspiration. Didn't get more than a few hours into it before I decided I'd just rather watch other people do great things with the 2600.

Also if you have some acquired 6502 skills consider doing some c64 and appleii or even atari x00 projects. Then maybe go back to 2600. All are very constrained in their own beautiful ways but not as perverse as the 2600 :)

Re: Video Chess disassembled and commented

#36

I think I’m pretty good at writing software, and then I see stuff like this, and the impostor syndrome kicks in hard. A fully working chess game in 4K of ROM, using each of the 128 bytes of RAM for several purposes? That’s some genius. Bravo to OP for the disassembly and explanation, too!

A fully working chess game in 4K of ROM, using each of the 128 bytes of RAM

MicroChess says hold my 924 byte beer: http://www.benlo.com/microchess/index.html

MicroChess is also believed to be the first home computer software that was available for sale to the public.

I have this on my KIM-1, and I find watching it play itself kind of soothing.

Re: Video Chess disassembled and commented

#37
I just finished training a neural network to play a trick taking card game and just the neural network is 4,250 times the size of the ROM for Video Chess and the executable including the UI is even bigger.

True story: One time I was at a party and my parents introduced me to some friends of theirs and they said their son worked on graphics drivers. I said I couldn't handle low-level work like that. My parents glared at me and told me I was being rude. Once I figured out the disconnect I explained that low-level means closer to the CPU and it's much more complicated - not that it's less desirable work.

Re: Video Chess disassembled and commented

#38

I think I’m pretty good at writing software, and then I see stuff like this, and the impostor syndrome kicks in hard. A fully working chess game in 4K of ROM, using each of the 128 bytes of RAM for several purposes? That’s some genius. Bravo to OP for the disassembly and explanation, too!

Keep in mind is these kind of things have a flat memory space between RAM and ROM. It's not like today where disk is some thing way over there that you need to buffer in RAM. All of your code and resources are in ROM which means they're just an address away. Your RAM is scratch space for dynamic values but you can pull everything else from ROM. For instance your bitmaps for pieces/spaces are stored in ROM, the code c…

    Keep in mind is these kind of things have a flat 
    memory space between RAM and ROM
This is true and is very central to how these miracles were pulled off.

While you know this, for the benefit of those reading: you could also use ROM for time/space tradeoff purposes -- for example instead of doing a bunch of trig calculations in real time for character movement purposes you could just have lookup tables in ROM.

    the code called when a scanline is drawn goes and 
    accessed the values in ROM (it's just a memory address) 
    without needing it to ever living in RAM
This went away at some point in console history, and I'm not sure exactly when.

For example the Sega Genesis/Megadrive has a scanline based video chip. No framebuffer, etc. But you've got to copy graphics data from ROM into the 64KB of video RAM before it can be drawn onscreen -- no rendering directly from ROM.

You can do this during the VBLANK interval (the time between frames) but there is not enough time to rewrite all 64KB so you've got to be crafty. Typical procedure was to stream animation data for the main character into VBLANK because you would like your main character to be animated as smoothly as possible. [1]

Contemporary systems like the Neo-Geo did not have that restriction and could render ROM data directly,[2] although it was several times more expensive than the Genesis and had many more address lines physically exposed on the ROM cartridge connector. May have used faster ROM chips too; dunno.

[1] https://rasterscroll.com/mdgraphics/graphical-effects/animat...

[2] https://wiki.neogeodev.org/index.php?title=VRAM

Re: Video Chess disassembled and commented

#39

Earlier quoted context omitted.

By the way: right now I'm working on a chess training project(1), and I'm thinking that a marketing cofounder could really help. If anybody is interested, my contact info is in my profile. (1) https://chess.braimax.com

Looks neat. Better call the puzzle training something else than Puzzle Rush though.

> Looks neat.

Thank you.

> Better call the puzzle training something else than Puzzle Rush though.

Why? I think it's the most recognised name for the sequence of puzzles becoming harder and harder, even if I removed the time limit (as that leads to not learning much :)

Re: Video Chess disassembled and commented

#40
post #5

I started developing software as a kid on a Commodore 64, and I thought we were pretty clever if we were able to accomplish interesting things using only 32KB of RAM. But the idea that somebody was able to develop a full chess engine using only 128 Bytes of RAM boggles my mind.

By the way: right now I'm working on a chess training project(1), and I'm thinking that a marketing cofounder could really help. If anybody is interested, my contact info is in my profile. (1) https://chess.braimax.com

I tried it out, was enjoyable to play a few puzzles. My feedback is a) that the ring sound (when you win a puzzle) was too loud, so I ended up muting the tab, and b) that the logo looks like "BraiMax", and doesn't stylistically fit with the rest of the site theme.
Post reply on HN