-
Notifications
You must be signed in to change notification settings - Fork 2
/
clock.asm
77 lines (67 loc) · 1.6 KB
/
clock.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
If the game has started, show the clock for the current player
*/
ShowClock:
jne currentmenu:#MENU_GAME:!return+
bfc playclockrunning:!return+
lda subseconds
cmp #$01
bne !return+
!showclock:
FillMemory(ColorAddress(HoursPos), $08, WHITE)
lda #':'
sta ScreenAddress(Colon1Pos)
sta ScreenAddress(Colon2Pos)
jeq currentplayer:#WHITES_TURN:!showwhiteclock+
!showblackclock:
ldx #BLACK_CLOCK_POS // Set the position to show the black clock
jmp !doshow+
!showwhiteclock:
ldx #WHITE_CLOCK_POS // Set the position to show the white clock
!doshow:
ldy #$00
!showloop:
stb timers, x:num1
stb timerpositions, y:printvector
iny
stb timerpositions, y:printvector + $01
jsr PrintByte // Print the 2 byte BCD digit for this position
inx
iny
cpy #$06 // hours, minutes and seconds
bne !showloop-
!return:
rts
/*
Update the clock for the current player
*/
UpdateClock:
jne currentmenu:#MENU_GAME:!return+
bfc playclockrunning:!return+
!updateclock:
dec subseconds
bne !return+
stb #$3c:subseconds
jeq currentplayer:#WHITES_TURN:!updatewhiteclock+
!updateblackclock:
ldx #BLACK_CLOCK_POS // Black player is up
jmp !doupdate+
!updatewhiteclock:
ldx #WHITE_CLOCK_POS // White player is up
!doupdate:
sed // All of our numbers are in BCD.
!updatetimers:
clc
lda timers, x
adc #$01
sta timers, x
cmp #$60 // Have we hit 60 seconds/minutes/hours?
bne !return+
lda #$00 // Yup. Reset seconds and increment minutes/hours
sta timers, x
inx
cpx #$02
bne !updatetimers-
cld
!return:
rts