-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbm_snake.tas
111 lines (90 loc) · 2.39 KB
/
bm_snake.tas
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# This file doesn't adhere to the standard EABI !
.set VGA_ROWS, 32
.set VGA_COLS, 64
.set SIZEOF_SNAKE, 4
_start:
o <- ((1 << 13) - 1)
n <- @+snakes + p
e <- @+snakes_after + p
init:
[o] <- p + 2 ; o <- o - 1 ; p <- @+rand + p
j <- b >>> 27 # 5 bits
k <- b >>> 21 ; k <- k & 0x3f # 6 bits
j -> [n + 2]
k -> [n + 3]
n <- n + @SIZEOF_SNAKE
j <- n < e
p <- @+init & j + p
g <- -1 # constant
l <- 0 # loop counter (generation number)
L_loop:
l -> [0x100] # show generation number on LED output
l <- l + 1
n <- @+snakes + p
L_snake:
# j:k = row:col
j <- [n + 2]
k <- [n + 3]
# direction and character choice are not independent variables
[o] <- p + 2 ; o <- o - 1 ; p <- @+rand + p
f <- b # save away random value for later
d <- f >>> 30 # a direction 0 - 3 ; clockwise, 0 = up
# start get_incrs
# direction map
# 0 -> -1 0
# 1 -> 0 1
# 2 -> 1 0
# 3 -> 0 -1
h <- d & 1 + g # 1 -> 0, 0 -> -1
i <- d & 2 + g # 2 -> 1, 0 -> -1
b <- i & h
c <- -i
c <- c &~ h
# end get_incrs
j <- j + b
k <- k + c
# start clamp
# Check for out-of-bounds and bounce off the wall
b <- j >= @VGA_ROWS ; j <- b << 1 + j
b <- j >= a + 1 ; j <- b << 1 + j
c <- k >= @VGA_COLS ; k <- c << 1 + k
c <- k >= a + 1 ; k <- c << 1 + k
# end clamp
j -> [n + 2] # store new row, col
k -> [n + 3]
i <- [n + 1]
c <- f >>> i
h <- i == 0 # special case when shift-value is zero : no randomness
c <- c &~ h
h <- [n + 0]
c <- c + h
d <- j * @VGA_COLS + k # d is offset into display
e <- 0x100
e <- e << 8 # e is video base
c -> [e + d] # e is d characters past start of text region
n <- n + @SIZEOF_SNAKE
e <- @+snakes_after + p
j <- n < e
p <- @+L_snake & j + p
j <- 250
j <- j * 75
slow_down:
e <- j > 0
j <- j - 1
p <- @+slow_down & e + p
p <- p + @+L_loop # infinite loop
snakes:
# base type, shift distance for rand(), row, col
.word 'A', 28, 0, 0;
.word '0', 29, 0, 0;
.word '-', 31, 0, 0;
.word ':', 31, 0, 0;
.word '*', 31, 0, 0;
.word '(', 31, 0, 0;
.word ' ', 0, 0, 0; # eraser snakes
.word ' ', 0, 0, 0;
.word ' ', 0, 0, 0;
.word ' ', 0, 0, 0;
.word ' ', 0, 0, 0;
.word ' ', 0, 0, 0;
snakes_after: .word 0