;############## CMonster by Patrick Davidson #define WAIT_RESET $d000 NUM_LEVELS =23 ;############## Hardware initialization main: call Clear_Screen ld hl,saved_flag ld a,(hl) or a ld (hl),0 jr nz,play_game_resumed save_game_not_found: ld de,data_start+1 ld bc,data_end-data_start-1 ldir ld a,3 ld (lives),a ld a,1 ld (level),a ld hl,score ld b,6 loop_zero_score: ld (hl),'0' inc hl djnz loop_zero_score call Show_Title_Screen dec c ret z ld (delay_amount),hl ld (score_inc),a prepare_level: ld a,(level) cp NUM_LEVELS+1 ld hl,win_message jp z,check_highscore call Load_Level play_game: ld hl,initial_data ; initial object positions ld de,bounce_count ld bc,map-bounce_count ldir play_game_resumed: ld hl,WAIT_RESET ld (wait_count),hl call Draw_Map ld a,(lives) or a ld hl,lose_message jp z,check_highscore ld hl,(level) ld h,0 bcall(_DivHLBy10) add a,'0' ld (levelm+1),a ld a,l add a,'0' ld (levelm),a call Decode_Lives ld hl,title_messages call Draw_Strings jr timer_wait_done ;############## Main loop, beginning with timer synchronization main_loop: ld hl,(wait_count) inc hl ld (wait_count),hl ld a,h or l jp z,save_game ld a,(score+4) or 1 ld hl,rand_inc add a,(hl) ld (hl),a #ifdef TI84CE timer_loop: ld a,($F20001) or a jr nz,timer_loop timer_wait_done: ld hl,$F20030 res 0,(hl) ; disable timer set 1,(hl) ; set frequency to 32768Hz res 2,(hl) ; no interrupt inc hl res 1,(hl) ; count down ld a,(delay_amount) ld hl,2 ld ($F20004),hl ld l,a add hl,hl add hl,hl add hl,hl add hl,hl inc h ld ($F20000),hl ; value to count down from xor a ld ($F20003),a ld ($F20006),a ld hl,$F20030 set 0,(hl) ; re-enable timer #else timer_loop: in a,(4) bit 5,a jr z,timer_loop timer_wait_done: xor a out ($31),a ld a,(delay_amount) out ($32),a ; restart timer #endif ld bc,33*4*256+232 ld hl,score call Draw_String #ifdef TI84CE call GET_KEY #else ld a,%11111110 ; mask out most keys (allow arrows) out (1),a #endif call Show_Bonus ld hl,p_x ; move paddle #ifdef TI84CE ld a,(getkeylastdata) cpl #else in a,(1) #endif bit 1,a jr nz,no_left ld a,(hl) sub 3 ld (hl),a cp 140 jr c,no_leftedge ld (hl),0 no_leftedge: ld a,20 add a,(hl) ld b,a ld l,224 ld de,img_fake_paddle call Erase_Sprite ld hl,WAIT_RESET ld (wait_count),hl jr no_right no_left: bit 2,a jr nz,no_right ld a,(hl) add a,3 ld (hl),a cp 140 jr c,no_rightedge ld (hl),140 no_rightedge: ld a,-3 add a,(hl) ld b,a ld l,224 ld de,img_fake_paddle call Erase_Sprite ld hl,WAIT_RESET ld (wait_count),hl no_right: ld bc,(p_x-1) ; redraw paddle ld l,224 ld de,img_player_paddle call Draw_Sprite_16 ld hl,b_type ld bc,$300 loop_balls: ld a,(hl) inc hl or a jr z,no_ball inc c push bc push hl call Handle_Ball pop hl pop bc no_ball: inc hl inc hl inc hl inc hl djnz loop_balls ld a,c or a jr nz,not_dead ld hl,lives dec (hl) call Erase_Paddle jp play_game not_dead: #ifndef TI84CE ld a,%11110101 ; mask out most keys (allow P, STAT, clear) out (1),a #endif ld hl,plimit ld a,(hl) or a jr z,no_pause check_pause: #ifdef TI84CE ld a,(getkeylastdata+3) bit 3,a jr z,no_pause #else in a,(1) bit 3,a jr nz,no_pause #endif ld (hl),2 ld hl,pause_message call Draw_Strings paused: #ifdef TI84CE call GET_KEY cp skClear ret z cp skStat jr nz,paused #else in a,(1) bit 6,a ret z add a,a jr c,paused #endif jp play_game_resumed no_pause: #ifndef TI84CE ld a,%1111101 ; mask out most keys (allows clear and mode) out (1),a #endif ld hl,map ld b,48 #ifdef TI84CE ld a,(getkeylastdata+1) bit 0,a jr nz,save_game bit 6,a ; check for clear ret nz #else in a,(1) bit 0,a jr z,save_game bit 6,a ; check for clear ret z #endif xor a check_map: or (hl) inc hl djnz check_map jp nz,main_loop ld hl,level inc (hl) call Erase_Paddle jp prepare_level save_game: ld hl,saved_flag set 7,(hl) ret Erase_Paddle: ld l,224 ; erase paddle ld a,(p_x) ld b,a ld de,img_player_paddle jp Erase_Sprite Decode_Lives: ld hl,(lives) ld h,0 bcall(_DivHLBy10) add a,'0' ld (livesm+1),a ld a,l add a,'0' ld (livesm),a ret ;############## Images (of sorts) img_player_paddle: SPRITE(40,8) .db $03,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$30 .db $32,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$23 .db $32,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$23 .db $32,$22,$22,$22,$22,$22,$22,$22,$77,$77,$77,$77,$22,$22,$22,$22,$22,$22,$22,$23 .db $32,$22,$22,$22,$22,$22,$22,$22,$77,$77,$77,$77,$22,$22,$22,$22,$22,$22,$22,$23 .db $32,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$23 .db $32,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$23 .db $03,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$33,$30 img_ball: SPRITE(6,5) .db $04,$44,$00 .db $43,$33,$40 .db $43,$33,$40 .db $43,$33,$40 .db $04,$44,$00 bonus_images: SPRITE(16,8) .db $33,$00,$00,$00,$04,$00,$00,$33 .db $33,$00,$00,$00,$00,$40,$00,$33 .db $33,$00,$04,$40,$00,$04,$00,$33 .db $33,$04,$44,$44,$44,$44,$40,$33 .db $33,$04,$44,$44,$44,$44,$40,$33 .db $33,$00,$04,$40,$00,$04,$00,$33 .db $33,$00,$00,$00,$00,$40,$00,$33 .db $33,$00,$00,$00,$04,$00,$00,$33 SPRITE(16,8) .db $33,$00,$00,$00,$00,$00,$00,$33 .db $33,$00,$00,$00,$00,$00,$00,$33 .db $33,$00,$44,$00,$00,$44,$00,$33 .db $33,$04,$44,$40,$04,$44,$40,$33 .db $33,$04,$44,$40,$04,$44,$40,$33 .db $33,$00,$44,$00,$00,$44,$00,$33 .db $33,$00,$00,$00,$00,$00,$00,$33 .db $33,$00,$00,$00,$00,$00,$00,$33 SPRITE(16,8) .db $33,$00,$00,$00,$00,$00,$00,$33 .db $33,$00,$00,$04,$40,$00,$00,$33 .db $33,$00,$00,$04,$40,$00,$00,$33 .db $33,$00,$04,$44,$44,$40,$00,$33 .db $33,$00,$04,$44,$44,$40,$00,$33 .db $33,$00,$00,$04,$40,$00,$00,$33 .db $33,$00,$00,$04,$40,$00,$00,$33 .db $33,$00,$00,$00,$00,$00,$00,$33 SPRITE(16,8) .db $33,$00,$04,$40,$04,$40,$00,$33 .db $33,$00,$40,$04,$40,$04,$00,$33 .db $33,$00,$40,$00,$00,$04,$00,$33 .db $33,$00,$40,$00,$00,$04,$00,$33 .db $33,$00,$40,$00,$00,$04,$00,$33 .db $33,$00,$04,$00,$00,$40,$00,$33 .db $33,$00,$00,$40,$04,$00,$00,$33 .db $33,$00,$00,$04,$40,$00,$00,$33 #ifdef TI84CE img_fake_paddle: .db 3,8 img_fake_bonus =bonus_images img_fake_ball =img_ball #else img_fake_paddle: .db 5,6*8/2 img_fake_bonus: .db 15,8*16/2 img_fake_ball: .db 5,6*5/2 #endif ;############## Data storage title_messages: .db 0,232 title_message: .db "CMONSTER LIVES " livesm: .db "-- LEVEL " levelm: .db "-- SCORE ",0 .db -1 initial_data: .db 0,80,0,0,0,0,0,1,80,210,-2,-2,0,0,0,0 pause_message: .db 0,0,"PAUSED: PRESS STAT TO RESUME",0,-1 ball_directions: .db -2,-1,-2,-2,-1,-4,1,-4,2,-2,2,-1 score_bonus: .db "000025" .end