game.asm
The game: its memory map, what Gnubby says, its pictures; includes the rest, the engine among it. Download · All the source
; zxGammon: backgammon for the 48K ZX Spectrum, you against Gnubby, a; little gnu with a neural-net Z80 engine for a brain. Money games, or matches to; 1, 3, 5 or 7 points, with the doubling cube (and the Crawford rule).;; Loaded at $5e00 and started there: the game, its art and tables, then; from $8000 (clear of the memory the screen slows) the engine, the; net2-style evaluator of NET2_DESIGN.md (z80/n2*.asm), its tables first.; The engine works in the top 8 pages (WORK) and the WORK2NEED bytes; below them (WORK2), with the stack below that; the game's RAM, with the; engine's little-used parts, is at $5b00 (the printer buffer and BASIC's; area, free once the game runs: cleared at the start, not loaded). Interrupts stay off throughout: the; keyboard is read directly, and the engine reads its weights off the; stack pointer.G equ $5b00 ; the game's RAM, to G+$300NB equ 16 ; the dense layer's blocks (n2net.asm) org $5e00 jp start include "n2ram.asm" include "play.asm" include "screen.asm" include "input.asm" include "log.asm"; ------------------------------------------------------------------ RAM; From G: the game's, and parts of the engine's work area (WORK3 to 5).GB equ G ; the game: the player's checkers, then at +32 ; Gnubby's, each from their own sideTB0 equ G+$40 ; the player's turn's startANIM equ G+$80 ; Gnubby's play, a step at a timeCSTEPS equ G+$c0 ; its steps (points, then dice); G+$c8 to G+$db: the log (log.asm)CBUF equ G+$dc ; a checker or a point's number being drawn (32, ; within a page)CSH equ G+$fcSAID equ G+$100 ; what Gnubby last saidTXT equ G+$170 ; what he is to sayWORK5 equ G+$1e0 ; (the engine's PART, 32 bytes)NUMBUF equ G+$200 ; (at a page)GV equ G+$210DIE1 equ GV+0 ; the dice, as rolledDIE2 equ GV+1U1 equ GV+2 ; each playedU2 equ GV+3NDONE equ GV+4 ; checkers moved this turnNMAX equ GV+5 ; as many as the roll must moveMUSTHI equ GV+6 ; only one die can be played, and the larger canCUBE equ GV+7OWNER equ GV+8 ; 0 the middle, 1 the player, 2 GnubbyMLEN equ GV+9 ; the match's length, 0 for moneySCH equ GV+10 ; the scores (2 each)SCC equ GV+12CRAW equ GV+14 ; 1 in the Crawford game, 2 after itTURN equ GV+15 ; 0 the player, 1 GnubbyCURS equ GV+16 ; the point the player moves from (25: none)MOOD equ GV+17 ; Gnubby: 0 calm, 1 happy, 2 sad, 3 thinkingSEED equ GV+18 ; (2)SHOWN equ GV+20 ; the dice shown: 1 the player's, 2 Gnubby's, ; 3 one eachMXA equ GV+21NNEED equ GV+22WINNER equ GV+23GAMMON equ GV+24POINTS equ GV+25TATTR equ GV+26PCOL equ GV+27FATTR equ GV+28TMPI equ GV+29TOPPT equ GV+30TSTEP equ GV+31 ; (2)SN equ GV+33SATT equ GV+34SDIR equ GV+35SMAX equ GV+36UZERO equ GV+37TXP equ GV+38 ; (2)CNT equ GV+40PLAYED equ GV+41 ; Gnubby has just played (what he said, in TXT)OWNED equ GV+46 ; the doubler owns the cubeTAKEQ equ GV+47 ; a take, not a doubleUP equ GV+52 ; the board is on the screen (see setup)SAIDNEW equ GV+53 ; what Gnubby says is still to be shownNCK equ GV+54 ; a point's cells with checkers (2 each)LSHOWN equ GV+55 ; what was drawn last: whose dice,LTRAY equ GV+56 ; the checkers off (2),LCUBE equ GV+58 ; the cube (3),LSCORE equ GV+61 ; the score (4)DIG3 equ GV+65 ; small digits to draw (3)SROW equ GV+68SLINE equ GV+69PIPOFF equ GV+70 ; the pip counts hidden (the I key)DOTS equ GV+71 ; the dots shown while Gnubby thinks (0-3); The keys the game will take now, for whatever shows them (as the website; does, under its emulator's screen): KWAIT is 1 while it waits for a key; (0 while it works or thinks), and KSET which keys, as one of K_ANY..KWAIT equ GV+72KSET equ GV+73K_ANY equ 0 ; any key, to go onK_TITLE equ 1 ; M (money), 1, 3, 5, 7 (a match)K_ROLL equ 2 ; R (roll), I (pips)K_ROLLD equ 3 ; R, D (double), IK_MOVE equ 4 ; Q, A (the cursor up and down), SPACE (move), ; 1, 2 (by that die), D (swap), U (undo), ; H (hint), IK_DONE equ 5 ; ENTER (done), U (undo)K_TAKE equ 6 ; Y (take), N (pass)K_AGAIN equ 7 ; Y, N (another game)TXT2 equ G+$25a ; (40)WORK3 equ G+$282 ; (the engine's TOPC, 82 bytes)WORK4 equ G+$2d4 ; (H1 and H2, 32 bytes), to G+$2f4; ----------------------------------------------------------------- dataSTART: db 0,0,0,0,0,5,0,3,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0 db 0,0,0,0,0,5,0,3,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0; small digits, 3 dots by 5, a row a byteSDIG: db 7,5,5,5,7 db 2,6,2,2,7 db 7,1,7,4,7 db 7,1,3,1,7 db 5,5,7,1,1 db 7,4,7,1,7 db 7,4,7,5,7 db 7,1,2,2,2 db 7,5,7,5,7 db 7,5,7,1,7 db 7,5,7,4,4 ; P db 7,2,2,2,7 ; IS_TITLE: db "ZXGAMMON",0S_WITH: db "WITH GNUBBY #",0S_MENU: db "M MONEY GAME||1 1 POINT MATCH||3 3 POINT MATCH||5 5 POINT MATCH||7 7 POINT MATCH",0S_FOOT: db "FOR THE ZX SPECTRUM 48K",0S_HELLO: db "HI! I'M GNUBBY. LET'S PLAY!|PRESS A KEY TO SEE WHO STARTS.",0S_YOUROLL: db "YOU ROLL ",0S_IROLL: db ", I ROLL ",0S_TIE: db ".|A TIE! AGAIN...",0S_YOUSTART: db ".|YOU START! (PRESS A KEY)",0S_ISTART: db ".|I START! (PRESS A KEY)",0S_ROLL: db "YOUR TURN! R: ROLL THE DICE",0S_ROLLDBL: db "YOUR TURN! R: ROLL D: DOUBLE",0S_MOVE: db "Q/A: UP/DOWN SPACE: MOVE|D:SWAP U:UNDO H:HINT I:PIPS",0S_DONE: db "ALL DONE? ENTER: YES|U: UNDO",0S_NOMOVE: db "OH NO, YOU CAN'T MOVE!|PRESS A KEY.",0S_HINT: db "HMM, LET ME SEE",0S_THINK: db "HMM, LET ME THINK",0S_ICANT: db "OOPS, I CAN'T MOVE!",0S_IPLAY: db "I PLAY ",0S_BAR: db "BAR",0S_OFF: db "OFF",0S_DBLYOU: db "YOU DOUBLE? HMM",0S_CUBEQ: db "SHALL I DOUBLE? HMM",0S_ITAKE: db "I TAKE! THE CUBE IS MINE.|PRESS A KEY.",0S_IPASS: db "I PASS. YOU WIN THIS ONE!|PRESS A KEY.",0S_IDOUBLE: db "I DOUBLE TO ",0S_TAKEQ: db "!|TAKE (Y) OR PASS (N)?",0S_YOUTAKE: db "BRAVE! GOOD LUCK!",0S_YOUWIN: db "YOU WIN ",0S_IWIN: db "I WIN ",0S_POINT: db " POINT",0S_GAMMON: db " - GAMMON!",0S_BACKG: db " - BACKGAMMON!",0S_YAY: db "|YAY! WELL PLAYED!",0S_HEHE: db "|HEHE!",0S_NL: db "|",0S_MATCHYOU: db "YOU WIN THE MATCH! #",0S_MATCHME: db "I WIN THE MATCH. GOOD GAME!",0S_AGAIN: db " AGAIN? (Y/N)",0S_TO: db "TO ",0S_CRAW: db "CRAW",0FONT: incbin "font" ; characters 32 to 95CHK: incbin "checker" ; a checker, 2 cells by 2; then the disc that ; counts are cut out of (see chkimg)TRI: incbin "triangle" ; a point, 2 bytes a line from its baseDICE: incbin "dice" ; 32 a face: its four cellsCUBEG: incbin "cube" ; the cube face on, 32 a value: 1 (as 64), 2, 4, ... 128; Gnubby's faces (128 a mood, 16 cells).MASC: incbin "mascot"; The engine above $8000, clear of the memory the screen contends for:; its code, then its tables (from a page); its work area at the top of; memory, the stack below it.GAMEEND:ENGINE: include "n2gen.asm" include "encode.asm" include "n2net.asm" include "n2choose.asm" include "n2cube.asm" include "n2data.asm"; gnubg's match equity table, for the cube and the outcomes' weights in a; match (see mwc): here, clear of the tables' page alignment.MET16: incbin "met16"ENGINEEND:WORK equ $f800 ; 8 pages, to the topWORK2 equ WORK-WORK2NEEDSTACK equ WORK2 ; the stack, down from here (STACKROOM bytesSTACKROOM equ 128 ; above ENGINEEND)