Post by ZTarget on Apr 16, 2022 3:22:49 GMT
Lets add a full game timer to Kid Chameleon or your KC mod that will keep track of your play time down to the frame and display at the end of a level.
This game timer functions independent of the level timer and in a way is more accurate. This is because the level timer uses a few shortcuts to
get the hud to update like adding an extra subsecond at the beginning of the map and skipping to the next second when you get a clock item.
The game timer is separate but runs anytime the level clock is ticking and wont reset until you start a new game/reset the system.
Lets take a look at the end result
The last line will display the game time so in this picture it reads 12minutes 57seconds and 36subseconds(out of 60 subseconds)
Just a warning I am not a assembly expert so feel free to correct me or post more optimized solutions.
Before we start be sure to make a backup of your project so you can go back to it if there are any problems!!
Step 1
Open up variables.asm scroll down past Clocks_collected and add these 3 new variables.
Timer_SubSeconds = $FFFFFDD0 ;word
Timer_Seconds = $FFFFFDD2 ;word
Timer_Minutes = $FFFFFDD4 ;word
Should look something like this
Note: we can now monitor these variables in certain emulators to see whats there.
Save and close variables.asm
Step 2
Open kid.asm and search to loc_BE82: Here we are going to set up the timer
copy and paste this line and then the chunk to the highlighted locations in the picture (my line numbers may not match yours so go by the code)
bsr.s timer_update ;timermod
bra.s loc_BEE8 ;timermod skip timer on no time
timer_update: ;timermod
addq.w #1,(Timer_SubSeconds).w
cmpi.w #60,(Timer_SubSeconds).w
bne.s timer_exit
clr.w (Timer_SubSeconds).w
addq.w #1,(Timer_Seconds).w
cmpi.w #60,(Timer_Seconds).w
bne.s timer_exit
clr.w (Timer_Seconds).w
addq.w #1,(Timer_Minutes).w
timer_exit:
rts
Step 3
This is optional but I noticed some branch words can be made to branch shorts just below our new code.
would this save a few cycles to make up a little for our new timer?
manually change the .w to .s in these five locations
Step 4
Next we will be changing the scoreboard at the end of the level to display our timer in the place of the continues display, note that this will not mess with your actual continues.
Manually edit the pink highlighted lines like in the picture. (example: in the first line change #$1C to #$28 )
Then copy and paste the code chunk after the (Number_Continues) line. then comment out the (Number_Continues) line with the semicolon ; like in the picture (pink arrow).
Add some of your own comments if you like. I put ";timermod" next to the changes so I could easily search to these locations.
move.w (Timer_Seconds).w,d0 ;timermod
mulu.w #$64,d0
move.w (Timer_SubSeconds).w,d1
add.w d1,d0
move.w (Timer_Minutes).w,d1
mulu.w #$2710,d1
add.l d1,d0
Step 5
clear timer on game start
Search to Title_InputLoop:
add these three lines. now when you hit start on the title screen the timer will be set to zero.
we need this because the demo that plays in the intro will run the timer up.
clr.w (Timer_SubSeconds).w ;timermod clear timer because demo adds time
clr.w (Timer_Seconds).w
clr.w (Timer_Minutes).w
Save kid.asm and build then test it out!
edit:
See Part 2 posted below where we are also going to add the level time to the scoreboard.
I moved the link to this running in vanilla kc to the end of the Part 2 post. If you downloaded the old one delete it and get the new one there.