so basically i have to make a maze on mips and i think im almost done, the problem i have is after processing the display, when i jump to the game_loop where every movement is being processed by reading an charachter for example "Z" = up, the program shuts down completely ( dropped of bottom)
.data
mazeFilename: .asciiz "C:\\Users\\noahm\\OneDrive\\Bureau\\computer architecture\\Mips opdracht\\Mips opdracht 2\\input_1.txt"
buffer: .space 4096
newline: .asciiz "\n"
wallColor: .word 0x004286F4 # Kleur gebruikt voor muren (blauw)
passageColor: .word 0x00000000 # Kleur gebruikt voor doorgangen (zwart)
playerColor: .word 0x00FFFF00 # Kleur gebruikt voor speler (geel)
exitColor: .word 0x0000FF00 # Kleur gebruikt voor uitgang (groen)
breedte: .word 32
hoogte: .word 16
.text
main:
j read_maze
loop_game:
li $t1,0
li $t2, 0
li $t3, 0
# lees gebruiker input
li $v0, 12 # System call voor 1 single character
syscall
move $s1, $v0 # input charachter opslaan
# Move up
beq $s1, 122, move_up
# Move down
beq $s1,115, move_down
# Move left
beq $s1, 113, move_left
# Move right
beq $s1, 100, move_right
# Exit the game
beq $s1, 120, exit_game
# If no valid input, continue the loop
j loop_game
move_up:
addi $a2, $a0, -1
addi $a3, $a1, 0
jal positie_speler
j beweging
move_down:
addi $a2, $a0, 1
addi $a3, $a1, 0
jal positie_speler
j beweging
move_left:
addi $a2, $a0, 0
addi $a3, $a1, -1
jal positie_speler
j beweging
move_right:
addi $a2, $a0, 0
addi $a3, $a1, 1
jal positie_speler
j beweging
beweging:
li $v0, 32
la $a0, 60
syscall # Wacht voor 60s
exit_game:
li $v0, 10 # System call for exit
syscall
read_maze:
# Open het bestand
li $v0, 13 # Syscall voor openen bestand
la $a0, mazeFilename # Adres van de bestandsnaam
li $a1, 0 # 0 voor lezen, 1 voor schrijven
li $a2, 0 # 0 voor standaardmodus
syscall
move $s0, $v0 # Bewaar bestandsdescriptornummer
# Lees de inhoud van het bestand in het buffer
li $v0, 14 # Syscall voor lezen bestand
move $a0, $s0 # Bestandsdescriptornummer
la $a1, buffer # Adres van het buffer
li $a2, 4096 # Maximale grootte om te lezen
syscall
# Sluit het bestand
li $v0, 16 # Syscall voor sluiten bestand
move $a0, $s0 # Bestandsdescriptornummer
syscall
# Verwerk de inhoud van het doolhof
la $t0, buffer # Adres van het buffer
verwerkDoolhof:
lb $t1, 0($t0) # Laad het eerste teken van het buffer in $t0
li $t2, 0 # rijnummer
li $t3, 0 # kolomnummer
verwerkRegel:
# Check for newline character
beq $t1, 10, isNewline # ASCII value of newline character
# Process the current character and apply the color
beq $t1, 119, isWall # Compare with ASCII value of 'w'
beq $t1, 112, isPassage # Compare with ASCII value of 'p'
beq $t1, 115, isPlayer # Compare with ASCII value of 's'
beq $t1, 117, isExit # Compare with ASCII value of 'u'
# Your existing code for processing characters and applying colors
isNewline:
addi $t2, $t2, 1 # Increment row number
li $t3, 0 # reset column number
# Move to the next character in the buffer
addi $t0, $t0, 1
# Load the next character from the buffer
lb $t1, 0($t0)
lw $t7, hoogte # laad hoogte in
beq $t2, $t7 , loop_game # als de hoogte wordt bereikt eindig
# Continue processing the next row
j verwerkRegel
isWall:
lw $t5, wallColor # laad blauw
jal GeheugenAdress
jal color_pixel
j eindeTeken
isPassage:
lw $t5, passageColor # laad zwart
jal GeheugenAdress
jal color_pixel
j eindeTeken
isPlayer:
lw $t5, playerColor # laad geel
move $a0, $t2 # startpositie rijnummer
move $a1, $t3 # startpositie kolomnummer
jal GeheugenAdress
jal color_pixel
j eindeTeken
isExit:
lw $t5, exitColor # laad groen
jal GeheugenAdress
jal color_pixel
j eindeTeken
eindeTeken:
addi $t0, $t0, 1 # Ga naar het volgende teken in het buffer
addi $t3, $t3, 1 # ga naar volgende kolom
lb $t1, 0($t0) # Laad het volgende teken van het buffer in $t0
j verwerkRegel # Ga terug naar verwerkRegel
GeheugenAdress: #bereken geheugenadress
subu $sp, $sp, 8 # Reserveer ruimte op de stack
sw $t2, 0($sp) # Sla het rijnummer op de stack op
sw $t3, 4($sp) # Sla het kolomnummer op de stack op
# use row major, Formule: Ba + (r * K + c) * EL
lw $t6, breedte # Breedte van het scherm (in pixels)
mul $t2, $t6, $t2 # r * K
add $t2, $t2, $t3 # r * K + c
sll $t2, $t2, 2 # Elke pixel is 32 bits, dus vermenigvuldig met 4 om het geheugenadres te krijgen ( * EL)
la $t3, 0($gp) # $gp bevat het basisadres
add $t2, $t2, $t3 # Ba + (r * K + c) * EL
jr $ra
color_pixel: # kleur de pixel op de gegeven geheugenplaats
sw $t5, 0($t2) # sla kleur op ( gegeven pixel)
lw $t2, 0($sp) # Laad het rijnummer van de stack
lw $t3, 4($sp) # Laad het kolomnummer van de stack
addu $sp, $sp, 8 # Maak de stackruimte vrij
jr $ra
i genuinly dont know what is going wrong, im just jumping to another funtion and it doesnt work