Skip to content

Commit 86f9b2a

Browse files
authored
Develop (#1)
* mid right did not have bound check * implementing rule anticanway and copyworld * renamed files and fixed fpgrars display problem * optimizing reset call; changing cell color to more eye friendly * fixing draw_rectangle utest; adding utest for next_cell_edge_detection * added exploding labyrint rule andblacking screen * added change color code * adding UT for living neighboor count * adding color check !=0; excluding exercise solution by renaming to .tjon * fixing missing SUCCESS message of edge test; adding rule_1 UT * added UT for anti conway (rule 2) * added UT for rule 3 * added UT for rule 4 (labyrinth) * added UT checking status bits and printing them
1 parent 470f336 commit 86f9b2a

24 files changed

+1445
-48
lines changed

src/constants_settings.asm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
.eqv MIN_CELL_SIZE 1
2020
.eqv MAX_CELL_SIZE 16
2121

22-
.eqv MAX_RULE 1 # min rule 1
22+
.eqv MAX_RULE 4 # min rule 1
2323

24-
.eqv ALIVE 0x00ff00
24+
#.eqv ALIVE 0xa0a397
2525

2626
ask_rars_version:
2727
.string "are you using fpgrars(any number) or rars(0)\n"
@@ -36,7 +36,7 @@ ask_y_size_display:
3636
.string "width of display rars(64; 128; 256; 512)\n"
3737

3838
ask_rule_to_apply:
39-
.string "which rule do you want tu use min 1 max 1\n"
39+
.string "which rule do you want tu use min 1 max 4\n"
4040

4141
ask_time_till_next_generation:
4242
.string "how much time in ms should the programm wait till next generation is shown max 2³²-1\n"
@@ -47,8 +47,14 @@ ask_start_density:
4747
invalid_input_message:
4848
.string "Somehow you did not gave the valid input try again\n"
4949

50+
ask_colour:
51+
.string "What color do you like?\n"
52+
53+
new_line:
54+
.string "\n"
55+
5056
settings:
51-
.word 8 # here we have our cell size. 1 default for unittest #addresss by 0
57+
.word 1 # here we have our cell size. 1 default for unittest #addresss by 0
5258
.word RARS_DISPLAY_ADDRESS # display address defaulting for rars (unittest) #addresss by 4
5359
.word RARS_KEYBOARD_ADDRESS # keyboard address defaulting for rars (unittest) #addresss by 8
5460

@@ -58,10 +64,12 @@ settings:
5864

5965
.word 1 # rule to use 0 is default/normal Game of Life #addresss by 20
6066

61-
.word 10 # time till next generation will be displayed in ms 0-2³²-1 in unittest i don't want to wait #addresss by 24
67+
.word 0 # time till next generation will be displayed in ms 0-2³²-1 in unittest i don't want to wait #addresss by 24
6268

6369
.word 50 # start density this is random so no UT #addresss by 28
6470

71+
.word 0xa0a397 # color of living cells # adress by 32
72+
6573
state_bits:
6674
.space 32768 # malloc for 512x512Pixel/32Bits of word x 4 addressing
6775
# it is disgusting but i guess the easiest solution for now

src/exercise_solutions/draw_rectangle.asm

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,17 @@ print_living_cell:
107107
# input
108108
# a1 x cell pos
109109
# a2 y cell pos
110-
addi sp, sp, -4
110+
addi sp, sp, -8
111111
sw ra, 0(sp)
112-
113-
li a7, ALIVE # dead cell
112+
sw t0, 4(sp)
113+
114+
la t0, settings
115+
lw a7, 32(t0) # color of living cell
114116
jal ra, draw_cell
115117

116118
lw ra, 0(sp)
117-
addi sp, sp, 4
119+
lw t0, 4(sp)
120+
addi sp, sp, 8
118121
ret
119122

120123
.include "draw_pixel.asm"

src/init_gamefield.asm renamed to src/gamefield.asm

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ init_gamefield:
3333
cell_alive:
3434
mv a1, t2
3535
mv a2, t3
36-
li a7, ALIVE # all living cells are green
37-
jal draw_cell
36+
jal ra, print_living_cell
3837

3938
adding_next_cell:
4039
la a0, return_to_main
4140
mv a1, t2 # incase some below function modified them
4241
mv a2, t3
43-
jal ra, continue_gamefield # input a1, a2
42+
jal ra, next_cell_edge_detection # input a1, a2
4443
mv t2, a1
4544
mv t3, a2
4645
j init_living_cells
@@ -56,7 +55,7 @@ init_gamefield:
5655
ret
5756

5857

59-
continue_gamefield:
58+
next_cell_edge_detection:
6059
# input:
6160
# a0 where to jump if gemfield is finished
6261
# a1 current x pos
@@ -130,10 +129,12 @@ neighboor_status:
130129

131130
la t3, settings
132131
lw s0, 0(t3)
132+
133+
mv t0, a1 # saving the coords of current cell
134+
mv t1, a2
133135

134136
top_left:
135-
mv t0, a1
136-
mv t1, a2
137+
137138
sub a1, t0, s0
138139
sub a2, t1, s0
139140
bltz a2, mid_left
@@ -143,13 +144,15 @@ neighboor_status:
143144
addi a4, a4, 1
144145

145146
top_mid:
146-
add a1, a1, s0
147+
mv a1, t0
148+
sub a2, t1, s0
147149
jal ra, get_pixel
148150
beqz a3, top_right
149151
addi a4, a4, 1
150152

151153
top_right:
152-
add a1, a1, s0
154+
add a1, t0, s0
155+
sub a2, t1, s0
153156
lw t4, 12(t3)
154157
bgeu a1, t4, mid_left
155158
jal ra, get_pixel
@@ -166,13 +169,15 @@ neighboor_status:
166169

167170
mid_right:
168171
add a1, t0, s0
172+
mv a2, t1
173+
lw t4, 12(t3)
174+
bgeu a1, t4, bottom_left
169175
jal ra, get_pixel
170176
beqz a3, bottom_left
171177
addi a4, a4, 1
172178

173179
bottom_left:
174180
sub a1, t0, s0
175-
sub a1, t0, s0
176181
add a2, t1, s0
177182
lw t4, 16(t3)
178183
bgeu a2, t4, finish_counting_neighboor
@@ -182,13 +187,15 @@ neighboor_status:
182187
addi a4, a4, 1
183188

184189
bottom_mid:
185-
add a1, a1, s0
190+
mv a1, t0
191+
add a2, t1, s0
186192
jal ra, get_pixel
187193
beqz a3, bottom_right
188194
addi a4, a4, 1
189195

190196
bottom_right:
191-
add a1, a1, s0
197+
add a1, t0, s0
198+
add a2, t1, s0
192199
lw t4, 12(t3)
193200
bgeu a1, t4, finish_counting_neighboor
194201
jal ra, get_pixel
@@ -259,7 +266,7 @@ print_next_generation:
259266
#current pos
260267
mv a1, t2
261268
mv a2, t3
262-
jal ra, continue_gamefield
269+
jal ra, next_cell_edge_detection
263270
# load coords of next cell
264271
mv t2, a1
265272
mv t3, a2
@@ -275,3 +282,83 @@ print_next_generation:
275282
lw ra, 20(sp)
276283
addi sp, sp, 24
277284
ret
285+
286+
# more efficient way to print black screen (reset)
287+
print_black_display:
288+
addi sp, sp, -12
289+
sw t0, 0(sp)
290+
sw t1, 4(sp)
291+
sw ra, 8(sp)
292+
293+
li t0, 0 # display start coords
294+
li t1, 0
295+
296+
print_trough_blacking_display:
297+
mv a1, t0
298+
mv a2, t1
299+
300+
jal ra, get_pixel
301+
mv a1, t0
302+
mv a2, t1
303+
la ra, continue_blacking_display
304+
bnez a3, print_dead_cell
305+
306+
continue_blacking_display:
307+
la a0, print_black_display_finished # where to go if gamefield is finished
308+
#current pos
309+
mv a1, t0
310+
mv a2, t1
311+
jal ra, next_cell_edge_detection
312+
# load coords of next cell
313+
mv t0, a1
314+
mv t1, a2
315+
j print_trough_blacking_display
316+
317+
318+
print_black_display_finished:
319+
lw t0, 0(sp)
320+
lw t1, 4(sp)
321+
lw ra, 8(sp)
322+
addi sp, sp, 12
323+
ret
324+
325+
print_colour_display:
326+
addi sp, sp, -12
327+
sw t0, 0(sp)
328+
sw t1, 4(sp)
329+
sw ra, 8(sp)
330+
331+
li t0, 0 # display start coords
332+
li t1, 0
333+
334+
print_trough_colour_display:
335+
mv a1, t0
336+
mv a2, t1
337+
338+
jal ra, get_pixel
339+
mv a1, t0
340+
mv a2, t1
341+
la ra, continue_colour_display
342+
bnez a3, print_living_cell
343+
344+
continue_colour_display:
345+
la a0, print_colour_display_finished # where to go if gamefield is finished
346+
#current pos
347+
mv a1, t0
348+
mv a2, t1
349+
jal ra, next_cell_edge_detection
350+
# load coords of next cell
351+
mv t0, a1
352+
mv t1, a2
353+
j print_trough_colour_display
354+
355+
356+
print_colour_display_finished:
357+
lw t0, 0(sp)
358+
lw t1, 4(sp)
359+
lw ra, 8(sp)
360+
addi sp, sp, 12
361+
ret
362+
363+
364+
.include "exercise_solutions/draw_rectangle.asm"

src/main.asm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ j game_loop
2424
#li a0, 10000
2525
#li a7, 32
2626
#ecall
27-
.include "init_user_question.asm"
28-
.include "init_gamefield.asm"
29-
.include "exercise_solutions/draw_rectangle.asm"
27+
.include "user_question.asm"
28+
.include "gamefield.asm"
3029
.include "rules.asm"
3130
.include "user_key_interface.asm"

0 commit comments

Comments
 (0)