Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- # --- Global simulated time variable (in milliseconds) ---
- sim_time: .word 0
- # --- User input for pet name ---
- prompt_name: .asciiz "Enter pet name: "
- pet_name: .space 32
- newline: .asciiz "\n"
- # --- Pet Stats (initially 4 stars each, max 5) ---
- happiness: .word 4
- sleepiness: .word 4
- hunger: .word 4
- # --- Timers for stat decay (in milliseconds) ---
- happiness_timer: .word 0
- sleepiness_timer: .word 0
- hunger_timer: .word 0
- # --- Pet state and interaction flags ---
- # 0 = default, 1 = sad, 2 = dead, 3 = happy, 4 = sleeping
- pet_state: .word 0
- is_playing: .word 0
- is_sleeping: .word 0
- is_eating: .word 0
- # --- Timer constants ---
- HUNGER_DECAY: .word 45000 # hunger loses a star every 45 sec
- SLEEPINESS_DECAY: .word 90000 # sleepiness loses a star every 90 sec
- HAPPINESS_DECAY: .word 75000 # happiness loses a star every 75 sec
- # --- Interaction durations ---
- SLEEP_DURATION: .word 20000 # sleep lasts 20 sec
- EAT_DURATION: .word 7000 # feed lasts 7 sec
- # --- Pet Icons (from Fikro.txt, with proper escape sequences) ---
- sretna_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / O O \\\n | __ |\n ----- \\/ -----\n ----- \\_/\\_/ -----\n | |\n \\ /\n \\_______________/\n"
- tuzna_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / _ _ \\\n | __ |\n ----- \\/ -----\n ----- _/\\_ -----\n | |\n \\ /\n \\_______________/\n"
- spava_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / V V \\\n | __ |\n ----- \\/ -----\n ----- \\_/\\_/ -----\n | |\n \\ /\n \\_______________/\n"
- vesela_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / /\\ /\\ \\\n | __ |\n ----- \\/ -----\n ----- \\_/\\_/ -----\n | |\n \\ /\n \\_______________/\n"
- rahmetli_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / X X \\\n | __ |\n ----- \\/ -----\n ----- \\_/\\_/ -----\n | |\n \\ /\n \\_______________/\n"
- # --- Accessories (from deepseek.asm) ---
- bowl_art: .asciiz " (____)\n / \\\n / \\\n---------\n"
- ball_art: .asciiz " O\n /|\\\n / \\\n"
- # --- UI Elements ---
- menu_prompt: .asciiz "\nChoose an action:\n1. Play\n2. Sleep\n3. Feed\n4. Exit\n"
- invalid_choice: .asciiz "Invalid choice!\n"
- playing_msg: .asciiz "Playing with the pet!\n"
- sleeping_msg: .asciiz "Pet is sleeping...\n"
- feeding_msg: .asciiz "Feeding the pet!\n"
- pet_dead_msg: .asciiz "Your pet has died! Game over.\n"
- # --- Stat Labels for Inline Display ---
- happiness_label: .asciiz "HAPPINESS: "
- sleepiness_label: .asciiz "SLEEPINESS: "
- hunger_label: .asciiz "HUNGER: "
- star: .asciiz "*"
- space: .asciiz " "
- .text
- .globl main
- main:
- # Prompt for pet name and read it
- li $v0, 4
- la $a0, prompt_name
- syscall
- li $v0, 8
- la $a0, pet_name
- li $a1, 32
- syscall
- # Initialize simulated timer
- jal get_time
- move $t0, $v0 # $t0 holds previous time
- main_loop:
- # Call a short delay to prevent busy-wait overload
- jal delay
- # Get simulated current time
- jal get_time
- sub $t5, $v0, $t0 # elapsed time in ms
- move $t0, $v0 # update reference time
- # Update each stat's timer
- lw $t6, happiness_timer
- add $t6, $t6, $t5
- sw $t6, happiness_timer
- lw $t6, sleepiness_timer
- add $t6, $t6, $t5
- sw $t6, sleepiness_timer
- lw $t6, hunger_timer
- add $t6, $t6, $t5
- sw $t6, hunger_timer
- # Check for happiness decay
- lw $t6, happiness_timer
- lw $t7, HAPPINESS_DECAY
- blt $t6, $t7, check_sleepiness_decay
- lw $t1, happiness
- blez $t1, check_sleepiness_decay
- sub $t1, $t1, 1
- sw $t1, happiness
- sw $zero, happiness_timer
- check_sleepiness_decay:
- lw $t6, sleepiness_timer
- lw $t7, SLEEPINESS_DECAY
- blt $t6, $t7, check_hunger_decay
- lw $t2, sleepiness
- blez $t2, check_hunger_decay
- sub $t2, $t2, 1
- sw $t2, sleepiness
- sw $zero, sleepiness_timer
- check_hunger_decay:
- lw $t6, hunger_timer
- lw $t7, HUNGER_DECAY
- blt $t6, $t7, update_pet_state
- lw $t3, hunger
- blez $t3, update_pet_state
- sub $t3, $t3, 1
- sw $t3, hunger
- sw $zero, hunger_timer
- update_pet_state:
- # If all stats sum to 0, pet is dead (state 2)
- lw $t1, happiness
- lw $t2, sleepiness
- lw $t3, hunger
- add $t4, $t1, $t2
- add $t4, $t4, $t3
- beqz $t4, set_dead_state
- # If sleeping flag is active, set state to 4 (sleeping)
- lw $t5, is_sleeping
- bnez $t5, set_sleeping_state
- # If playing flag is active, set state to 3 (happy)
- lw $t5, is_playing
- bnez $t5, set_happy_state
- # Otherwise, if any stat is less than 3, set to sad (1)
- li $t7, 3
- lw $t1, happiness
- blt $t1, $t7, set_sad_state
- lw $t2, sleepiness
- blt $t2, $t7, set_sad_state
- lw $t3, hunger
- blt $t3, $t7, set_sad_state
- # Default state otherwise
- li $t4, 0
- j store_state
- set_sad_state:
- li $t4, 1
- j store_state
- set_dead_state:
- li $t4, 2
- j store_state
- set_sleeping_state:
- li $t4, 4
- j store_state
- set_happy_state:
- li $t4, 3
- store_state:
- sw $t4, pet_state
- # Display current UI
- jal display_ui
- # If pet is dead, go to pet_dead routine
- lw $t4, pet_state
- li $t7, 2
- beq $t4, $t7, pet_dead
- # Check if sleep duration elapsed to clear sleeping flag
- lw $t5, is_sleeping
- bnez $t5, check_sleep_duration
- j show_menu
- check_sleep_duration:
- lw $t6, sleepiness_timer
- lw $t7, SLEEP_DURATION
- blt $t6, $t7, show_menu
- # Sleep finished: clear sleeping flag, refill sleepiness, reset timer
- sw $zero, is_sleeping
- li $t1, 5
- sw $t1, sleepiness
- sw $zero, sleepiness_timer
- j show_menu
- show_menu:
- # Display menu prompt and get user choice
- li $v0, 4
- la $a0, menu_prompt
- syscall
- li $v0, 5
- syscall
- move $t8, $v0
- beq $t8, 1, play_action
- beq $t8, 2, sleep_action
- beq $t8, 3, feed_action
- beq $t8, 4, exit_program
- # Invalid choice message
- li $v0, 4
- la $a0, invalid_choice
- syscall
- j main_loop
- # --- Action Routines ---
- play_action:
- # Only act if pet is alive
- lw $t1, happiness
- lw $t2, sleepiness
- lw $t3, hunger
- add $t4, $t1, $t2
- add $t4, $t4, $t3
- beqz $t4, main_loop
- # Increase happiness by one star (max 5)
- li $t5, 5
- lw $t1, happiness
- bge $t1, $t5, play_continue
- addi $t1, $t1, 1
- sw $t1, happiness
- play_continue:
- # Set playing flag (to show ball accessory) and reset happiness timer
- li $t1, 1
- sw $t1, is_playing
- sw $zero, happiness_timer
- li $v0, 4
- la $a0, playing_msg
- syscall
- j main_loop
- sleep_action:
- # Only act if pet is alive
- lw $t1, happiness
- lw $t2, sleepiness
- lw $t3, hunger
- add $t4, $t1, $t2
- add $t4, $t4, $t3
- beqz $t4, main_loop
- # Set sleeping flag and reset sleepiness timer; refill sleepiness to 5
- li $t1, 1
- sw $t1, is_sleeping
- sw $zero, sleepiness_timer
- li $t1, 5
- sw $t1, sleepiness
- li $v0, 4
- la $a0, sleeping_msg
- syscall
- j main_loop
- feed_action:
- # Only act if pet is alive
- lw $t1, happiness
- lw $t2, sleepiness
- lw $t3, hunger
- add $t4, $t1, $t2
- add $t4, $t4, $t3
- beqz $t4, main_loop
- # Set eating flag and reset hunger timer; refill hunger to 5
- li $t1, 1
- sw $t1, is_eating
- sw $zero, hunger_timer
- li $t1, 5
- sw $t1, hunger
- li $v0, 4
- la $a0, feeding_msg
- syscall
- j main_loop
- pet_dead:
- li $v0, 4
- la $a0, pet_dead_msg
- syscall
- li $v0, 4
- la $a0, rahmetli_art
- syscall
- j exit_program
- # --- Display UI Routine ---
- # Clears the screen (by printing newlines), prints the pet's name,
- # then prints the pet icon (based on pet_state), any accessory,
- # and finally prints the three stat labels with their stars inline.
- display_ui:
- # Clear screen (simulate by printing several newlines)
- li $v0, 4
- la $a0, newline
- syscall
- syscall
- syscall
- # Print pet name
- li $v0, 4
- la $a0, pet_name
- syscall
- # Extra newline for spacing
- li $v0, 4
- la $a0, newline
- syscall
- # Print pet icon based on pet_state
- lw $t4, pet_state
- li $t7, 0
- beq $t4, $t7, print_default
- li $t7, 1
- beq $t4, $t7, print_sad
- li $t7, 2
- beq $t4, $t7, print_dead
- li $t7, 3
- beq $t4, $t7, print_happy
- li $t7, 4
- beq $t4, $t7, print_sleeping
- print_default:
- li $v0, 4
- la $a0, sretna_art
- syscall
- j print_accessories
- print_sad:
- li $v0, 4
- la $a0, tuzna_art
- syscall
- j print_accessories
- print_dead:
- li $v0, 4
- la $a0, rahmetli_art
- syscall
- j print_accessories
- print_happy:
- li $v0, 4
- la $a0, vesela_art
- syscall
- j print_accessories
- print_sleeping:
- li $v0, 4
- la $a0, spava_art
- syscall
- print_accessories:
- # If feeding, show bowl; if playing, show ball
- lw $t5, is_eating
- bnez $t5, print_bowl
- lw $t5, is_playing
- bnez $t5, print_ball
- j print_stats
- print_bowl:
- li $v0, 4
- la $a0, bowl_art
- syscall
- j print_stats
- print_ball:
- li $v0, 4
- la $a0, ball_art
- syscall
- print_stats:
- # Print stats inline on one line:
- # HAPPINESS: **** SLEEPINESS: **** HUNGER: ****
- li $v0, 4
- la $a0, happiness_label
- syscall
- lw $t1, happiness
- jal print_stars
- li $v0, 4
- la $a0, space
- syscall
- li $v0, 4
- la $a0, sleepiness_label
- syscall
- lw $t1, sleepiness
- jal print_stars
- li $v0, 4
- la $a0, space
- syscall
- li $v0, 4
- la $a0, hunger_label
- syscall
- lw $t1, hunger
- jal print_stars
- # Newline at end of stats line
- li $v0, 4
- la $a0, newline
- syscall
- jr $ra
- # --- Print Stars Routine ---
- # Expects $t1 to contain the number of stars to print.
- print_stars:
- blez $t1, print_stars_end
- print_stars_loop:
- li $v0, 4
- la $a0, star
- syscall
- addi $t1, $t1, -1
- bgtz $t1, print_stars_loop
- print_stars_end:
- jr $ra
- # --- get_time Subroutine ---
- # Simulates a system time call by incrementing the global sim_time.
- # Returns the updated simulated time (in ms) in $v0.
- get_time:
- la $t9, sim_time
- lw $v0, 0($t9)
- addi $v0, $v0, 100 # simulate 100 ms per call
- sw $v0, 0($t9)
- jr $ra
- # --- delay Subroutine ---
- # A short busy-wait loop (adjust the count as needed)
- delay:
- li $t9, 1000 # lower iteration count for a shorter delay
- delay_loop:
- addi $t9, $t9, -1
- bgtz $t9, delay_loop
- jr $ra
- exit_program:
- li $v0, 10
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement