;############## Calcuzap by Patrick Davidson ;############## Read in the save game and erase it, sets carry if not found Read_Files: ld hl,data_save ; clear data ld (hl),0 ld de,data_save+1 ld bc,data_end-data_start ldir ld hl,save_name bcall(_Mov9ToOP1) ; copy (HL) to OP1 bcall(_ChkFindSym) jr c,read_scores #ifdef TI84CE bcall(_ChkInRam) #else ld a,b or a #endif jr z,its_not_archived_so_dont_unarchive_it bcall(_Arc_Unarc) ld hl,save_name bcall(_Mov9ToOP1) ; copy (HL) to OP1 bcall(_ChkFindSym) its_not_archived_so_dont_unarchive_it: ld hl,save_size ld b,10 compare_identifier: ld a,(de) cp (hl) jr nz,erase_save_file inc hl inc de djnz compare_identifier ld (data_save),a ex de,hl ld de,data_save+1 ld bc,data_end-data_start ldir erase_save_file: bcall(_ChkFindSym) bcall(_DelVarArc) read_scores: ld de,score_save ld a,SCORE_COUNT build_default_loop: ld hl,default_high_score ld bc,ENTRYLEN ldir dec a jr nz,build_default_loop ld b,SCORE_COUNT-1 ld de,score_save+TABLE_SIZE-ENTRYLEN-SCORELEN-1 default_inc_loop: push bc ld hl,ENTRYLEN add hl,de ; HL -> next score ld bc,6 ldir ; copy next score over this one ex de,hl call Add_6_Digits_BCD ; double it (moves pointer back) ld de,-ENTRYLEN add hl,de ex de,hl pop bc djnz default_inc_loop ld hl,score_name bcall(_Mov9ToOP1) ; copy (HL) to OP1 bcall(_ChkFindSym) ret c #ifdef TI84CE bcall(_ChkInRam) #else ld a,b or a #endif jr z,scores_not_archived_so_dont_unarchive_it bcall(_Arc_Unarc) ld hl,score_name bcall(_Mov9ToOP1) ; copy (HL) to OP1 bcall(_ChkFindSym) scores_not_archived_so_dont_unarchive_it: ex de,hl inc hl inc hl ld a,SCORE_COUNT ld de,score_save read_scores_from_file_loop: ld bc,ENTRYLEN-1 ldir inc de dec a jr nz,read_scores_from_file_loop ret save_name: .db AppVarObj,"CZapSave",0 save_size: .dw 8+data_end-data_start save_identifier: .db "CZAP",5,26,82,21 score_name: .db AppVarObj,"CZapHigh",0 default_high_score: .db "PATRICK ANDREW DAVIDSON 000001",0 #ifndef TI84CE Add_6_Digits_BCD: ld b,6 loop_add_nocarry: xor a loop_add: dec hl dec de ld a,(de) adc a,(hl) sub '0' ; '0' was added twice because both ASCII cp '0'+10 jr c,loop_add_nocarry_end sub 10 ccf ld (hl),a djnz loop_add ret loop_add_nocarry_end: ld (hl),a djnz loop_add_nocarry ret #endif ;############## Write out the save game file Write_Files: ld a,(data_save) add a,a jr nc,not_saving_game ld hl,save_name bcall(_Mov9ToOP1) ; copy (HL) to OP1 ld hl,8+data_end-data_start bcall(_CreateAppVar) ld hl,save_identifier inc de inc de ld bc,8 ldir ld hl,data_save+1 ld bc,data_end-data_start ldir ret not_saving_game: ld a,(data_save) rra ret nc ld hl,score_name bcall(_Mov9ToOP1) ; copy (HL) to OP1 bcall(_ChkFindSym) jr c,it_doesnt_exist_so_dont_delete_it bcall(_DelVarArc) it_doesnt_exist_so_dont_delete_it: ld hl,TABLE_SIZE-SCORE_COUNT bcall(_CreateAppVar) ld a,SCORE_COUNT ld hl,score_save inc de inc de write_score_file_loop: ld bc,ENTRYLEN-1 ldir inc hl dec a jr nz,write_score_file_loop ret