zxGammon

log.asm

The game as it is played, a record at a time in memory, for whatever reads it from outside (this site catches each and writes the games out as a match file). Download · All the source

; ------------------------------------------------------------------ log; The game as it is played, a record at a time, for whatever reads the; Spectrum's memory from outside: each new record is written at LOGREC,; over the last, and LOGSEQ counts them. A reader catches each as it is; made (the website stops its Spectrum at lnew, where each is complete,; and writes the games out as a match file). Nothing in the game reads; them.;; The records, s the side (0 the player, 1 Gnubby):;   $60, length, score, score, crawford   a game begins: the match's length;       (0 for money), the player's and Gnubby's scores (at most 255), and;       1 in the Crawford game;   $10+s, dice, n, n x (point, die)   a turn: the dice rolled (the larger;       in the high 4 bits), and the steps the checkers took, each from a;       point (0-23 for points 1-24, 24 the bar, from the mover's side) by;       a die; n = 0 if there was no play;   $20+s, cube    side s doubles, the cube now at cube;   $30+s          side s takes;   $40+s          side s passes;   $50+s, lo, hi  side s wins the game, for lo + 256 hi pointsLOGSEQ  equ $fb00           ; the records made, counting from any startLOGREC  equ $fb01           ; the latest record (up to 11 bytes)TSTEPS  equ $fb10           ; the player's steps this turn, as CSTEPS; lgame: a game begins.lgame:  ld a,$60        ld (LOGREC),a        ld a,(MLEN)        ld (LOGREC+1),a        ld hl,(SCH)        call .sc        ld (LOGREC+2),a        ld hl,(SCC)        call .sc        ld (LOGREC+3),a        ld a,(CRAW)        cp 1        ld a,0        jr nz,.c        inc a.c:     ld (LOGREC+4),a        jr lnext; a score, at most 255.sc:    ld a,h        or a        ld a,l        ret z        ld a,255        ret; lnext: the record at LOGREC made, and counted.lnext:  ld hl,LOGSEQ        inc (hl)lnew:   ret; lmove: a turn of side A, with the dice DHI, DLO and the steps at HL (as; CSTEPS: 4 points, $ff after the last, then their 4 dice), or none if HL; is 0.lmove:  or $10        ld (LOGREC),a        ld a,(DHI)        add a,a        add a,a        add a,a        add a,a        ld b,a        ld a,(DLO)        or b        ld (LOGREC+1),a        ld de,LOGREC+3        ld c,0        ld a,h        or l        jr z,.n.s:     ld a,(hl)        cp $ff        jr z,.n        ld (de),a        inc de        push hl        inc hl        inc hl        inc hl        inc hl        ld a,(hl)        pop hl        ld (de),a        inc de        inc hl        inc c        ld a,c        cp 4        jr nz,.s.n:     ld a,c        ld (LOGREC+2),a        jr lnext; ldbl: side A doubles (the cube about to double).ldbl:   or $20        ld (LOGREC),a        ld a,(CUBE)        add a,a        ld (LOGREC+1),a        jr lnext; lone: the one-byte record A (a take or a pass).lone:   ld (LOGREC),a        jr lnext; lwin: WINNER wins POINTS.lwin:   ld a,(WINNER)        dec a        or $50        ld (LOGREC),a        ld a,(POINTS)        ld (LOGREC+1),a        xor a        ld (LOGREC+2),a        jr lnext; lstep: the player's step from CURS by die E, the NDONE-th of the turn.; Keeps DE.lstep:  push de        ld a,(NDONE)        ld l,a        ld h,0        ld bc,TSTEPS        add hl,bc        ld a,(CURS)        ld (hl),a        ld bc,4        add hl,bc        ld (hl),e        ld a,(NDONE)        cp 3        jr nc,.x        or a        sbc hl,bc               ; back to the point, then the next        inc hl        ld (hl),$ff.x:     pop de        ret