* game.asm - Maintains game state. LANELENGTH equ 14 INITLIVES equ 5 INITLEVEL equ 1 INITLANES equ 1 INITEGGS equ 12 INITROTS equ 1 INITSPEED equ 1 INITLANEY0 equ 3 MAXLIVES equ 9 MAXLEVEL equ 9 MAXLANES equ 10 MAXEGGS equ 12 MAXROTS equ 3 nlives: fcb INITLIVES ; Number of lives remaining. Initially 5. level: fcb INITLEVEL ; Overall difficulty level. Initially 1. nlanes: fcb INITLANES ; Number of lanes. Initially 1. neggs: fcb INITEGGS ; Number of eggs available. Initially 12. nrots: fcb INITROTS ; Rotten eggs available. Initially 1. speed: fcb INITSPEED ; Game speed level. Initially 1. score: fdb 0 ; Score. Initially 0. laney0: fcb INITLANEY0 ; The lane # at screen row Y0. Initially 3. * Chicken screen location and state. INITCHICKX equ LANELENGTH/2 INITCHICKY equ 3 INITCHICKL equ 0 INITCHICKD equ 0 INITCHICKH equ 1 INITCHICKF equ 0 chickx: rmb 1 ; On-screen X coordinate chicky: rmb 1 ; On-screen Y coordinate chickl: rmb 1 ; Which lane is the chicky in? chickd: rmb 1 ; Direction: right (0) or left (1) chickh: rmb 1 ; Head state: forward (0) or back (1) chickf: rmb 1 ; State: normal (0) or flattened (1) * Vehicle data. ncars: rmb 1 ; How many cars are on the board. carx: rmb 256 cary: rmb 256 cartyp: rmb 256 ; Type: car (0) or truck (1) cardir: rmb 256 ; Direction: right (0) or left (1) * Lanes. There may be up to 10 lanes of traffic. * Lane #0 is where the chicken starts, the grassy area initially at the bottom of the screen. * Lane #1 is the first lane of traffic. * Lane #nlanes is the last lane of traffic. * Lane #nlanes+1 is the safe area on the other side. * Each location contains: * 0 - nothing is here * 1 - chicken is here * 2 - an egg is here * 3 - a rotten egg is here * 4 - an explosion is here * n>4 - vehicle #n-5 is here lanes: rmb 240 ; up to 12 lanes, 20 characters each endlanes: equ * * This subroutine starts a new game from scratch. init_game: jsr init_LCD ; Initialize the LCD ldaa #DISP_ONOFF|D_disp ; No cursor or blink jsr send_cmd ; Turn cursor/blink off. ldaa #INITLIVES ; Initialize game state staa nlives ldaa #INITLEVEL staa level ldaa #INITLANES staa nlanes ldaa #INITEGGS staa neggs ldaa #INITROTS staa nrots ldaa #INITSPEED staa speed ldaa #INITLANEY0 staa laney0 clr score * Draw lanes and grass ldaa #0 ; Upper-left corner ldab #0 jsr gotoxy ldx #grass_str ; Draw grass up there jsr lcdstr ldaa #0 ; Start of 2nd row ldab #1 jsr gotoxy ldx #grass_str jsr lcdstr ldaa #0 ; 3rd row ldab #2 jsr gotoxy ldx #lane_str ; Draw a lane there jsr lcdstr ldaa #0 ldab #3 jsr gotoxy ldx #grass_str jsr lcdstr * Initialize scoreboard display ldaa #LANELENGTH ; Go to end of first lane ldab #0 jsr gotoxy ldx #rstr0 ; Print initial row 0 string jsr lcdstr ldaa #LANELENGTH ldab #1 jsr gotoxy ldx #rstr1 jsr lcdstr ldaa #LANELENGTH ldab #2 jsr gotoxy ldx #rstr2 jsr lcdstr ldaa #LANELENGTH ldab #3 jsr gotoxy ldx #rstr3 jsr lcdstr * Initialize chicken state ldaa #INITCHICKX staa chickx ldaa #INITCHICKY staa chicky ldaa #INITCHICKL staa chickl ldaa #INITCHICKD staa chickd ldaa #INITCHICKH staa chickh ldaa #INITCHICKF staa chickf * Create chicken icon ldaa #CHICKEN_CHAR ldy #chikrb jsr store_glyph ldaa chickx ; Put the chicken on-screen ldab chicky jsr gotoxy ldaa #CHICKEN_CHAR jsr lcd_out * Initialize lanes ldx #lanes clrlanes: clr 0,x inx cpx #endlanes bne clrlanes rts ; Return from init_game subroutine * Main game loop subroutine. * Controls are: * 2 - Move chicken up * 8 - Move chicken down * 4 - Move chicken left * 6 - Move chicken right * A - Lay an egg * B - Lay a rotten egg * * - Exit game loop (pause game and return to main menu) debug1: fcc "entering main game loop" fcb EOT game_loop: ldx #debug1 ; Show we got here jsr printmsg * Main Loop. Algorithm: Get an ASCII character from the keypad. If it's a special command key, * then do the requested command. Otherwise, just send the character to the LCD display. Wait * for the key that was pressed to be released, and then repeat the whole process. mloop: JSR get_key ; Get character from keypad into accA. * Switch statement: Do one of several different things, depending on the value in accA. CMPA #'2 BNE not2 JSR chick_moveup BRA end_switch not2: CMPA #'8 BNE not8 JSR chick_movedn BRA end_switch not8: CMPA #'4 BNE not4 JSR chick_movelf BRA end_switch not4: CMPA #'6 BNE not6 JSR chick_movert BRA end_switch not6: cmpa #'A bne nota jsr lay_egg bra end_switch nota: cmpa #'B bne notb jsr lay_rotten bra end_switch notb: CMPA #'* BNE notstar RTS notstar: end_switch: * Wait for the key that was pressed to be released. wait_release: JSR any_key ; Are any keys still pressed? BNE wait_release ; If so, keep waiting. BRA mloop ; Repeat main loop. chick_moveup: ldaa chickf bne return ; If chicken is flattened, do nothing notflat: ldaa chickl ; Which lane are we in? deca cmpa nlanes ; If chickl=nlanes+1, can't go up beq return ldaa chicky ; Check chicken's y position on screen cmpa #2 bhi movehim jsr shift_dn ; Shift display down movehim: jsr pick_chik ; pick chicken up off of road inc chickl ; increment lane number dec chicky ; decrement row index (y loc) jsr put_chik ; put chicken back down on road checkcoll: return: rts chick_movedn: rts chick_movelf: rts chick_movert rts lay_egg: rts lay_rotten: rts shift_dn: rts * Pick up chicken from wherever he is pick_chik: ldaa chickx ldab chicky * jsr redraw_bkgrd rts put_chik: rts * Put the chicken down