agat-snake

The tables inside SNAKE.bin

Read out of the binary; every address is where the byte lives at run time. Regenerated by convert.py.

Glyphs ($26A5, 128 x 8 bytes)

One table serves as both the character generator and the sprite sheet: PUTCH ($237E) draws glyph N and codes $00-$0F happen to be the snake. $20-$7F are KOI-7 N2 text, so glyph $30 is 0 and the score routine indexes straight into the digits.

code what it is
$00 body, vertical
$01 body, horizontal
$02 bend
$03 bend
$04 bend
$05 bend
$06 tail, heading up
$07 tail, heading right
$08 tail, heading down
$09 tail, heading left
$0A head, heading up
$0B head, heading right
$0C head, heading down
$0D head, heading left
$0E wall
$0F blank – what erases a cell

Movement

Direction is a bit: 1 = up, 2 = down, 4 = left, 8 = right.

direction dx, dy head tail forbidden turn key
up +0, -1 $0A $06 down $19
down +0, +1 $0C $08 up $1A
left -1, +0 $0D $09 right $08
right +1, +0 $0B $07 left $15

The body glyph comes from (new direction << 4) | old:

turn glyph
up then up $00
down then down $00
left then left $01
right then right $01
down then right $03
left then up $03
right then up $02
down then left $02
up then left $05
right then down $05
left then down $04
up then right $04

Keys ($2B43)

A one-byte code, then the handler address; $80 ends the table. The dispatch is a JMP whose operand the lookup writes ($259E).

key code handler
up arrow $19 K.MOVE
down arrow $1A K.MOVE
left arrow $08 K.MOVE
right arrow $15 K.MOVE
РЕД (esc) $1B K.SOUND
УПР+C (ctrl-C) $03 WAITKEY
; $3B K.FASTER
+ $2B K.FASTER
- $2D K.SLOWER
R $52 REBOOT

Prizes

PRIZETAB ($2B62) is 17 (points, glyph) pairs – nine animals, some of them twice. $2B88 indexes it and steps down by one every time you press a direction key, wrapping at $10; $2B86/$2B87 are the cell the search for a free square starts from, and one of the two moves every frame. So both what appears and where is driven by the player’s own timing – there is no random generator anywhere in the file. The sprites are nine 8x8 glyphs of their own at $2EDA; the names are the help screen’s, in the order it lists them.

glyph points name  
0 11 ТУЗЕМЕЦ native
1 2 ЛЯГУШКА (АНФАС) frog (front view)
2 12 КЕНГУРУ kangaroo
3 1 МУХА ЦЕ-ЦЕ tsetse fly
4 6 ТУЗЕМНЫЙ ПЕСИК native dog
5 3 МЫШКА mouse
6 4 ЯЙЦО С ЦЫПЛЕНКОМ egg with a chick
7 5 КРОЛИК rabbit
8 13 БАРАН (СЗАДИ) ram (from behind)

Melodies ($2AA5)

PLAY ($23CC) walks pairs of (cycles, half-period): it toggles the speaker cycles times with DELAY in between, so the second number sets the pitch and $00 ends the tune.

tune address notes (cycles, half-period)
game start $2AA5 a sweep down, 13 steps 44/13 42/14 40/15 38/16 36/17 34/18 32/19 30/20 28/21 26/22 24/23 22/24 20/25
prize eaten $2AC7 three chirps, low-lower-high 7/25 5/30 10/20
collision $2ACE three buzzes with long gaps, then a lower one 100/25 1/0 100/25 1/0 100/25 1/0 100/35
sound on/off $2ADD four blips, each lower 20/10 15/12 10/14 5/16
reset $2AE6 a twelve-note phrase 20/47 20/35 20/29 20/31 20/35 20/29 20/35 20/31 20/35 20/44 20/39 20/47

Where things live

address  
$2000-$26A4 code
$26A5-$2AA4 glyph table, 128 x 8
$2AA5-$2AFE five melodies
$2AFF-$2B42 the movement tables above
$2B43-$2B61 key dispatch
$2B62-$2B85 prize table
$2B86-$2B89 prize seeds, prize counter, frame delay ($CD)
$2B8A-$2C3B title text
$2C3C-$2D21 the blurb
$2D22-$2DE4 the controls screen
$2DE5-$2ED9 the prize list
$2EDA-$2F21 nine prize sprites
$3C00-$3FFF the board, one byte a cell (run time only)
$4000-$5FFF video page a screen is composed on
$6000-$7FFF video page you see