-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameWithoutPlayerMoving.s
177 lines (153 loc) · 5.71 KB
/
GameWithoutPlayerMoving.s
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# x3 basket direction 1/0
# x4 register for rinport
# x5 offset for rinport memory address
# x6 mask check register for rinport values
# x7 check left most bit value
# x8 delay
# x9 mask check for basket
# x10 ground value
# x11 base basket value
# x13 ball value
# x14 highscore value
# x15 current score value
# x17 ball dropped true false 1/0
# x18 ball memory address row
# x19 base memory address row
# x20 score needed to go to level 2 difficulty
# x21 mask check for disible by 2 for difficulty
# x22 check for level for speed
# x23 constant length of basket
setupconstants:
#Register sets up at start
addi x10, x0, -1 # gnd
addi x15, x0, 0 # current score
sw x15, 4(x0) # store current score = 0
sw x10, 16(x0) # store ground
#sw x14, 8(x0) # store high score
lui x5, 0x00010 # offset for rinport
lui x7, 0x80000 # mask check for left most bit
#addi x3, x0, 1 # basket moving register 0=left
#addi x16, x0, 1 # check basket direction constant
addi x19, x0, 24 #basket base memory row
addi x11, x0, 0xff # base basket dynamic moves around
addi x20, x0, 8 # stop shifting bits off when score 6
addi x23, x0, 0xff # starting basket length, used to shsift bits off too
#start game
pollForRInport2Eq1: # read rInport, mask bit (2), repeat until rInport(2) = 1
lw x4, 0xc(x5)
andi x6, x4, 4
beq x6, x0, pollForRInport2Eq1
pollForRInport2Eq0: # read rInport, mask bit (2), repeat until rInport(2) = 0
lw x4, 0xc(x5)
andi x6, x4, 4
bne x6, x0, pollForRInport2Eq0
seedBasket:
sw x11, 0(x19)
seedBall:
addi x18, x0, 56 # ball starting starting row
lui x13, 0x10 # ball
sw x13, 0(x18)
mainLoop: # program-based decrementing delay loop [ref 1]
#check which one t branch to
lui x8, 0x00601 # load defualt
andi x22, x15, 8 #mask check to see if min basket length reached
bne x22, x0, loadDelay2
beq x0,x0, decrDelayCountUntil0
loadDelay2:
jal x1, delay2
beq x0, x0, decrDelayCountUntil0
# loadDelay3:
# jal x1, delay3
#lui x8, 0x00601 # delayCount 0x00601000. Approx 1 second delay for 12.5MHz clk
#addi x8, x0, 1 # test: (uncomment if testing) initial count value
decrDelayCountUntil0:
addi x8, x8, -1
bne x8, x0, decrDelayCountUntil0
checkBasketDirection:
beq x3, x0, basketMovingLeft #check basket moving register = 0
bne x3, x0, basketMovingRight # check basket moving register != 0 i.e = 1
basketMovingLeft:
addi x3, x0, 0 # add 0 to basket direction register
and x9, x11, x7 # and with left most bit
bne x9, x0, basketMovingRight #if and comes back with 1 you are in left most bit so go right
slli x11, x11,1
sw x11, 24(x0)
beq x0,x0, ballDroppedCheck
basketMovingRight:
addi x3, x0, 1
andi x9, x11, 1
bne x9, x0, basketMovingLeft
srli x11, x11,1
sw x11, 24(x0)
ballDroppedCheck:
bne x17, x0, dropBall # ball has been dropped skip player moving stuff
pollRInport10_chkPlayerMove: # inport(1)/(0) player left/right move control. Use AND mask to isolate bit.
lw x4, 0xc(x5)
mskRInport1_If1ShiftPlayerLeft_ifPosnNotBit31:
andi x6, x4, 2
# #addi x12, x0, 2 # test: (uncomment if testing), force inport(0) asserted flag
beq x6, x0, mskRInport0_If1ShiftPlayerRight_ifPosnNotBit0
and x6, x13, x7 # mask player bit 31. Can't move further left
bne x6, x0, chkIfDropBallBit
slli x13, x13, 1 # shift player left 1 bit
sw x13, 56(x0)
beq x0, x0, chkIfDropBallBit# unconditional branch
mskRInport0_If1ShiftPlayerRight_ifPosnNotBit0:
andi x6, x4, 1
# #addi x12, x0, 1 # test: (uncomment if testing), force inport(1) asserted flag
beq x6, x0, chkIfDropBallBit
andi x6, x13, 1 # mask player bit 0. Can't move further right
bne x6, x0, chkIfDropBallBit
srli x13, x13, 1 # shift player right 1 bit
sw x13, 56(x0)
chkIfDropBallBit: #check rinport to see if ball is dropped
andi x6, x4, 4
beq x6, x0, mainLoop
dropBall:
addi x17, x0, 1 # ball has began dropping
sw x0, 0(x18) # clear row where ball is now
addi x18, x18, -8 # minus 8 to move ball down 2 rows
beq x18, x19, scoreKeeper # when ball and base same row move to scorekeeper
sw x13, 0(x18) # store ball in new memory row
beq x0, x0, mainLoop # testing to go back to start
scoreKeeper:
and x6, x11, x13 # check if ball lands on base
bne x6, x0, addScore # player scores so go to addScore
# ball missed so game over
or x11, x11, x13 # or ball and base so it appears on one line in led array
sw x11, 0(x19) # store on led array
#add delay code here
addi x17, x0, 0 # deassert ball has been dropped reg
bgt x15, x14, updateHighScore # if current score is greater than highscore, update highscore
beq x0, x0, setupconstants
addScore:
addi x17, x0, 0 # deassert ball has been dropped reg
addi x15, x15, 1 #add one to curent score
sw x15, 4(x0) # store current score
jal x1, waitPlayerDeassertBallDrop
andi x21, x15, 1 # change to 2 later , 1 easier for testing
beq x21, x0, makeBasketSmaller
#beq x15, x2, makeBasketSmaller
beq x0, x0, seedBall
#jal x1, updateHighScore #checks if update is needed to highscore
#wait for player to deassert drop ball to continue game
waitPlayerDeassertBallDrop: # read rInport, mask bit (2), repeat until rInport(2) = 0
lw x4, 0xc(x5)
andi x6, x4, 4
#addi x5, x0, 0 # test: (uncomment if testing) deasserts rInport(2)
bne x6, x0, waitPlayerDeassertBallDrop
ret
updateHighScore:
addi x14, x15, 0 #add new highscore to highscore register
sw x14, 8(x0) # store high score
beq x0, x0, setupconstants #game is over reset game
makeBasketSmaller:
bge x15,x20, seedBasket
addi x11, x23, 0
srli x11, x11, 1
addi x23, x11, 0
beq x0, x0, seedBasket
#player deasserts drop ball bit -> seed ball and begin main again
delay2:
lui x8, 0x002EE
ret