diff --git a/src/constants_settings.asm b/src/constants_settings.asm index b5f1725..f2d6208 100644 --- a/src/constants_settings.asm +++ b/src/constants_settings.asm @@ -3,6 +3,7 @@ .data .space 1048576 # Addressing for 512x512 Display addresses -> bug at 0x1040... +# it is disgusting but i guess the easiest solution for now .eqv FPG_DISPLAY_ADDRESS 0xFF000000 .eqv FPG_DISPLAY_WIDTH 320 .eqv FPG_DISPLAY_HEIGHT 240 @@ -61,5 +62,8 @@ settings: .word 50 # start density this is random so no UT #addresss by 28 +state_bits: +.space 32768 # malloc for 512x512Pixel/32Bits of word x 4 addressing +# it is disgusting but i guess the easiest solution for now .text diff --git a/src/exercise_solutions/draw_rectangle.asm b/src/exercise_solutions/draw_rectangle.asm index 436db87..4363ffe 100644 --- a/src/exercise_solutions/draw_rectangle.asm +++ b/src/exercise_solutions/draw_rectangle.asm @@ -89,5 +89,33 @@ draw_cell: addi sp, sp, 8 ret +print_dead_cell: +# input +# a1 x cell pos +# a2 y cell pos + addi sp, sp, -4 + sw ra, 0(sp) + + li a7, 0 # dead cell + jal ra, draw_cell + + lw ra, 0(sp) + addi sp, sp, 4 + ret + +print_living_cell: +# input +# a1 x cell pos +# a2 y cell pos + addi sp, sp, -4 + sw ra, 0(sp) + + li a7, ALIVE # dead cell + jal ra, draw_cell + + lw ra, 0(sp) + addi sp, sp, 4 + ret + .include "draw_pixel.asm" diff --git a/src/init_gamefield.asm b/src/init_gamefield.asm index 0d05a66..d47cdf1 100644 --- a/src/init_gamefield.asm +++ b/src/init_gamefield.asm @@ -8,7 +8,7 @@ ecall init_gamefield: - # sw ra, sp + addi sp, sp, -20 sw t0, 0(sp) sw t1, 4(sp) @@ -23,8 +23,6 @@ init_gamefield: li t3, 0 init_living_cells: - - # coords of cell mv a1, t2 mv a2, t3 @@ -209,3 +207,71 @@ neighboor_status: ret +# cropped from rules.asm next_generation +# -> looks even more weird from used registers +print_next_generation: + # saving all needed register those of rules as well + addi sp, sp, -24 + sw t2, 0(sp) + sw t3, 4(sp) + sw s0, 8(sp) + sw s1, 12(sp) + sw s2, 16(sp) + sw ra, 20(sp) + + la s0, state_bits # base adress for state bits + li s2, 31 # bits in one word +1 bit your bit; i changed the register at a later point + lw s1, 0(s0) # first value + + li t2, 0 + li t3, 0 + + print_through_gamefield: + # current cell: + mv a1, t2 + mv a2, t3 + + get_status_bit: + srl a4, s1, s2 # getting cell status + andi a4, a4, 1 # only single bit is needed + + beqz a4, continue_print_gamefiled + + # i already have my cell coords:: + jal ra, get_pixel + la ra, continue_print_gamefiled + + bnez a3, print_dead_cell + j print_living_cell + + + continue_print_gamefiled: + addi s2, s2, -1 + bgez s2, same_status_word_print + + li s2, 31 # resetting bit count + addi s0, s0, 4 # going to next word adress + lw s1, 0(s0) # and loading the next word status bits + + same_status_word_print: + # going to next cell + la a0, print_next_gemeration_finished # where to go if gamefield is finished + #current pos + mv a1, t2 + mv a2, t3 + jal ra, continue_gamefield + # load coords of next cell + mv t2, a1 + mv t3, a2 + j print_through_gamefield + + + print_next_gemeration_finished: + lw t2, 0(sp) + lw t3, 4(sp) + lw s0, 8(sp) + lw s1, 12(sp) + lw s2, 16(sp) + lw ra, 20(sp) + addi sp, sp, 24 + ret diff --git a/src/main.asm b/src/main.asm index c5e936e..c271a9d 100644 --- a/src/main.asm +++ b/src/main.asm @@ -2,6 +2,7 @@ .include "constants_settings.asm" # init + jal ra, init_user_questioning jal ra, init_gamefield diff --git a/src/rules.asm b/src/rules.asm index 2640c99..f9c2fba 100644 --- a/src/rules.asm +++ b/src/rules.asm @@ -1,7 +1,6 @@ next_generation: - # saving all needed register those of rules as well addi sp, sp, -32 sw t0, 0(sp) @@ -12,21 +11,14 @@ next_generation: sw s1, 20(sp) sw s2, 24(sp) sw ra, 28(sp) - - la t0, settings - lw t1, 20(t0) # rule - li s0, 1 # first rule - beq s0, t1, rule_1 + la s0, state_bits # base adress for state bits + li s2, 31 # bits in one word +1 bit your bit; i changed the register at a later point + li s1, 0 # first value - - rule_1: - - lw t1, 28(t0) #density - lw s0, 12(t0) # widht size - lw s1, 16(t0) # height size - lw s2, 0(t0) # cell size - + la t0, settings + lw t1, 20(t0) + li t0, 1 # min rule == 1 li t2, 0 li t3, 0 @@ -35,19 +27,39 @@ next_generation: # current cell: mv a1, t2 mv a2, t3 - jal neighboor_status - mv a0, a4 # print status ehre to safe? - li a7, 1 - ecall + jal neighboor_status # return with a4 count living neighboors + # current cell; incase i have done something stupid in neighboor_status + mv a1, t2 + mv a2, t3 + # now the magic begins + bne t0, t1, check_rule_2 + jal ra, rule_1 # returning status bit -->1 -> change status (dead -> alive; alive ->dead) + j set_status_bit + + check_rule_2: + + # well shouldn't be possible + ## switch rule call a4 -> next status of current cell is a4 as well + + + set_status_bit: + sll a4, a4, s2 + add s1, s1, a4 + addi s2, s2, -1 + bgez s2, same_status_word + + sw s1, 0(s0) # saving the status bits + li s2, 31 # resetting bit count + li s1, 0 # resetting saving word + addi s0, s0, 4 # going to next word adress + + same_status_word: # going to next cell la a0, finished_rule # where to go if gamefield is finished #current pos mv a1, t2 mv a2, t3 - mv a3, s2 # cell size - mv a4, s0 # max widht - mv a5, s1 # max height jal ra, continue_gamefield # load coords of next cell mv t2, a1 @@ -56,6 +68,10 @@ next_generation: finished_rule: + sw s1, 0(s0) # saving the status bits; incase of cells not divideable to 32 + # now the fun begins:: print the next generation + jal ra, print_next_generation + lw t0, 0(sp) lw t1, 4(sp) lw t2, 8(sp) @@ -66,3 +82,58 @@ next_generation: lw ra, 28(sp) addi sp, sp, 32 ret + + +rule_1: +# a1 x pos of cell +# a2 y pos of cell +# input a4 with number of living neighboors +# return a4 if status bit is set -> change cell status dead/alive + + addi sp, sp, -8 + sw t0, 0(sp) + sw ra, 4(sp) + + li t0, 2 + bne a4, t0, rule_1_3 + # well this means no chances + # can not relieve dead cells + # alive cells can not be dead + jal ra, nochange_bit # ra is not set to finish yet + j back_rule_1 + + rule_1_3: + jal ra, get_pixel # return color code in a3 -> status of cell + # i need the status for the other rules so i am calling it now + + # after that ra need to be the finished rule so... + la ra, back_rule_1 + + li t0, 3 + bne a4, t0, dead_rule_1 + + # now i need the current status of the cell + bnez a3, nochange_bit + # this means the cell rebirth + j change_bit + + dead_rule_1: # not all can survive...now die or stay dead + + bnez a3, change_bit # cell dies + # well at this point the cell is dead and stays dead + j nochange_bit + + back_rule_1: + lw t0, 0(sp) + lw ra, 4(sp) + addi sp, sp, 8 + ret + + +change_bit: +li a4, 1 +ret + +nochange_bit: +li a4, 0 +ret