-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.asm
executable file
·95 lines (82 loc) · 1.48 KB
/
game.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
; Simon type game
org 0x00
pat_len skip 1 ; Pattern length
rng skip 1 ; Random number generator
count skip 1 ; Counter
delay_count skip 1
tmp skip 1
tmp1 skip 1
; Start
done org 0x0f
halt
start st #0xfd, pat_len ; Initial length
main_loop jsr show_rtn, show_pat ; Show pattern
jsr read_rtn, read_pat ; Read pattern from user
jcc done ; We fail
dec pat_len ; Increase length
jmp main_loop
; Show pattern
show_pat st #1, rng
st pat_len, count
show_loop st rng, tmp
rol tmp
rol tmp
rol tmp
andto #3, tmp
st #1, tmp1
jeq tmp, tdone
tloop lsl tmp1
dec tmp
jne tmp, tloop
tdone out tmp1
jsr delay_rtn, delay
out #0
jsr rng_rtn, rng_step
incjne count, show_loop
show_rtn jmp 0
; Delay
delay st #0xFA, delay_count
delay_loop incjne delay_count, delay_loop
delay_rtn jmp 0
; Random number generator: rng = rng*49 + 47 = rng * 32 + rng * 16 + rng + 47
rng_step st rng, tmp
lsl tmp
lsl tmp
lsl tmp
lsl tmp
addto tmp, rng
lsl tmp
addto tmp, rng
addto #47, rng
rng_rtn jmp 0
; Read pattern
read_pat st #1, rng
st pat_len, count
read_loop
inwait tmp
jeq tmp, read_loop
out tmp
st #0xff, tmp1
cvt_loop inc tmp1
lsr tmp
jcc cvt_loop
st rng, tmp
rol tmp
rol tmp
rol tmp
andto #3, tmp
rsbto tmp1, tmp
jne tmp, fail
out #0
jsr rng_rtn, rng_step
unpress in tmp
jne tmp, unpress
incjne count, read_loop
stc
read_rtn jmp 0
fail out #15
jsr delay_rtn, delay
jsr delay_rtn, delay
out #0
clc
jmp read_rtn