Jonny
Well-known member
1. Set up a variable with 3 bytes in Zero Page RAM. For this tutorial I'm calling it "myTime"
This is what will be used for the 3 digits. Counter can be upto 999.
2. Add the following code as part of your doDrawSpriteHud.asm (always make backups)
Code:
;;; TIMER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TXA
PHA
LDA #220 ;; Y POS ;;
STA tempA
LDA #223 ;; X POS ;;
STA tempB
LDX #$03 ;; myTime BYTES ;;
Timer:
DEX
LDA myTime,x
CLC
ADC #$73 ;; ZERO IN TILESET ;;
STA tempC
DrawSprite tempA, tempB, tempC, #$03
LDA tempA
CLC
ADC #$08 ;; OFFSET / SPACE BETWEEN ;;
STA tempA
CPX #$01
BCS Timer
PLA
TAX
3. Add the following code as part of your HandleGameTimer.asm (always make backups)
Code:
;;; GAME TIMER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA gameTimerTicks
CLC
ADC #$04 ;; 'SPEED' / 4 IS ABOUT 1 SEC ;;
STA gameTimerTicks
BCC checkTime
SubtractValue #$03, myTime, #1, #$00
checkTime:
LDA myTime+2 ;; IS 100 PLACE ZERO? ;;
BNE notZero
LDA myTime+1 ;; IS 10 PLACE ZERO? ;;
BNE notZero
LDA myTime ;; IS 1 PLACE ZERO? ;;
BNE notZero
WarpToScreen warpToMap, warpToScreen, #$01
notZero:
4. Add the following code as part of your PostScreenLoad.asm (always make backups)
Code:
LDA #09
STA myTime+1
LDA #09
STA myTime
Please let me know if you see improvements. I have tested this with metrovania module and also with a pickup which increases the time. When the time gets over 999 it rolls over so an addition could be something to normalise the timer to its max but for this tutorial I wanted to keep it simple. Hope this is helpful.
Last edited: