;############# CMonster by Patrick Davidson - high scores win_message: .db "YOU WIN!",0 lose_message: .db "GAME OVER",0 view_message: .db "ALL-TIME HIGH SCORES",0 no_message: .db "YOU DON'T HAVE A HIGH SCORE",0 yes_message: .db "YOU HAVE A HIGH SCORE! ENTER YOUR NAME:",0 ;############# Show final score and check for high score check_highscore: push hl ld a,(lives) or a jr z,no_lives_bonus ld b,a ld a,'1' ld (score_increment+3),a loop_bonus: push bc ld hl,score+4 ; and increment the score ld de,score_increment+4 ld b,4 call loop_add_nocarry pop bc djnz loop_bonus no_lives_bonus: ld hl,score #ifdef TIME_INDICATOR ld (hl),'0' #endif call Clear_Screen pop hl ld bc,0 call Draw_String ld hl,score ld bc,256*4*(40-6) call Draw_String ld hl,last_score+NAME_LEN ld de,score call CP_SCORE jp c,no_score ;############## Player has a high score, first fill in the bottom entry ld hl,last_score ld b,NAME_LEN loop_space: ld (hl),' ' inc hl djnz loop_space ex de,hl ld hl,score ld bc,SCORELEN ldir ;############## Bubble up the high score ld b,SCORE_COUNT-1 ; Bubble it towards the top ld de,last_score+NAME_LEN ; DE = score of entry to move loop_bubble: ld hl,-(ENTRYLEN) add hl,de ; HL = score of previous item push bc push de call CP_SCORE pop de pop bc jr z,bubble_up jr c,no_bubble_up bubble_up: push bc ld hl,SCORELEN add hl,de ex de,hl ; DE = last byte of new entry ld hl,-(ENTRYLEN) add hl,de ; HL = last byte of previous ld b,0+ENTRYLEN loop_exchange: ld a,(de) ld c,a ld a,(hl) ld (de),a ld (hl),c dec hl dec de djnz loop_exchange pop bc ; DE = last byte of new ld hl,-(SCORELEN) add hl,de ex de,hl ; DE = score of new position djnz loop_bubble no_bubble_up: ;############## Bubbling is done, show the table ld hl,-NAME_LEN add hl,de ; HL -> score entry position push hl push bc ld hl,saved_flag set 0,(hl) ld hl,yes_message ld bc,25 call Draw_String call show_scores_list pop bc pop ix call input_name jr show_highscores ;############## Show high score table if you didn't get a high score no_score: ld hl,no_message ld bc,26*256+25 call Draw_String call show_scores_and_wait ;############## Display high score table (from title screen) show_highscores: call Clear_Screen ld hl,view_message ld bc,40*256 call Draw_String show_scores_and_wait: call show_scores_list ;############## Wait to exit table display wait_key: call GET_KEY ld hl,0 wait_loop_hs: inc hl ld a,h or l ret z call GET_KEY cp skClear ret z cp skEnter jr nz,wait_loop_hs ret ;############## Display list of high scores show_scores_list: ld bc,SCORE_COUNT*256+50 ld hl,high_scores loop_show_highscore: push bc ld b,16 call Draw_String pop bc ld a,15 add a,c ld c,a inc hl djnz loop_show_highscore ret ;############## Compares ASCII numbers ; ; HL ->number to subtract from other ; DE ->number ; B = number of bytes ; ; Returns with flags indicating comparison results. Changes A, B, DE, HL. ; Zero set if equal, carry if HL > DE. CP_SCORE: ld b,6 CP_ASCII: cmpl: ld a,(de) cp (hl) ret nz inc de inc hl djnz cmpl ret ;############## Prompt for name entry input_name: ld a,b add a,a add a,a add a,a add a,a sub b ; A = 15 * row add a,50 ld (Draw_Score_Char+2),a ; store Y coordinate ld b,0 ; B = X coordinate ld hl,0 ld (wait_count),hl enter_name_loop: ld hl,(wait_count) inc hl ld (wait_count),hl ld a,h or l ret z call GET_KEY or a jr z,enter_name_loop cp skDel jr z,backup cp skLeft jr z,backup cp skEnter ret z cp skClear ret z ld c,a ld a,NAME_LEN-1 cp b jr z,enter_name_loop ld hl,chartable-10 #ifdef TI84CE ld de,0 #else ld d,0 #endif ld e,c add hl,de ld a,(hl) ld (ix),a call Draw_Score_Char inc b inc ix jr enter_name_loop backup: xor a cp b jr z,enter_name_loop dec b dec ix ld (ix),32 ld a,32 call Draw_Score_Char jr enter_name_loop Draw_Score_Char: push bc ld c,0 ;Y filled in by self modifying ld d,a ld a,b add a,a add a,a add a,16 ld b,a ld a,d call Draw_Char pop bc ret chartable: .db ":WRMH." .db "..0VQLG!..ZUPKFC" .db ". YTOJEBX.XSNIDA" .db ".12345.."