Advertisement
Guest User

Untitled

a guest
Apr 1st, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.45 KB | None | 0 0
  1. .data
  2. # --- Global simulated time variable (in milliseconds) ---
  3. sim_time: .word 0
  4.  
  5. # --- User input for pet name ---
  6. prompt_name: .asciiz "Enter pet name: "
  7. pet_name: .space 32
  8. newline: .asciiz "\n"
  9.  
  10. # --- Pet Stats (initially 4 stars each, max 5) ---
  11. happiness: .word 4
  12. sleepiness: .word 4
  13. hunger: .word 4
  14.  
  15. # --- Timers for stat decay (in milliseconds) ---
  16. happiness_timer: .word 0
  17. sleepiness_timer: .word 0
  18. hunger_timer: .word 0
  19.  
  20. # --- Pet state and interaction flags ---
  21. # 0 = default, 1 = sad, 2 = dead, 3 = happy, 4 = sleeping
  22. pet_state: .word 0
  23. is_playing: .word 0
  24. is_sleeping: .word 0
  25. is_eating: .word 0
  26.  
  27. # --- Timer constants ---
  28. HUNGER_DECAY: .word 45000 # hunger loses a star every 45 sec
  29. SLEEPINESS_DECAY: .word 90000 # sleepiness loses a star every 90 sec
  30. HAPPINESS_DECAY: .word 75000 # happiness loses a star every 75 sec
  31.  
  32. # --- Interaction durations ---
  33. SLEEP_DURATION: .word 20000 # sleep lasts 20 sec
  34. EAT_DURATION: .word 7000 # feed lasts 7 sec
  35.  
  36. # --- Pet Icons (from Fikro.txt, with proper escape sequences) ---
  37. sretna_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / O O \\\n | __ |\n ----- \\/ -----\n ----- \\_/\\_/ -----\n | |\n \\ /\n \\_______________/\n"
  38. tuzna_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / _ _ \\\n | __ |\n ----- \\/ -----\n ----- _/\\_ -----\n | |\n \\ /\n \\_______________/\n"
  39. spava_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / V V \\\n | __ |\n ----- \\/ -----\n ----- \\_/\\_/ -----\n | |\n \\ /\n \\_______________/\n"
  40. vesela_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / /\\ /\\ \\\n | __ |\n ----- \\/ -----\n ----- \\_/\\_/ -----\n | |\n \\ /\n \\_______________/\n"
  41. rahmetli_art: .asciiz "\n / \\ / \\\n / ^ \\_____/ ^ \\\n / \\\n / X X \\\n | __ |\n ----- \\/ -----\n ----- \\_/\\_/ -----\n | |\n \\ /\n \\_______________/\n"
  42.  
  43. # --- Accessories (from deepseek.asm) ---
  44. bowl_art: .asciiz " (____)\n / \\\n / \\\n---------\n"
  45. ball_art: .asciiz " O\n /|\\\n / \\\n"
  46.  
  47. # --- UI Elements ---
  48. menu_prompt: .asciiz "\nChoose an action:\n1. Play\n2. Sleep\n3. Feed\n4. Exit\n"
  49. invalid_choice: .asciiz "Invalid choice!\n"
  50. playing_msg: .asciiz "Playing with the pet!\n"
  51. sleeping_msg: .asciiz "Pet is sleeping...\n"
  52. feeding_msg: .asciiz "Feeding the pet!\n"
  53. pet_dead_msg: .asciiz "Your pet has died! Game over.\n"
  54.  
  55. # --- Stat Labels for Inline Display ---
  56. happiness_label: .asciiz "HAPPINESS: "
  57. sleepiness_label: .asciiz "SLEEPINESS: "
  58. hunger_label: .asciiz "HUNGER: "
  59. star: .asciiz "*"
  60. space: .asciiz " "
  61.  
  62. .text
  63. .globl main
  64.  
  65. main:
  66. # Prompt for pet name and read it
  67. li $v0, 4
  68. la $a0, prompt_name
  69. syscall
  70.  
  71. li $v0, 8
  72. la $a0, pet_name
  73. li $a1, 32
  74. syscall
  75.  
  76. # Initialize simulated timer
  77. jal get_time
  78. move $t0, $v0 # $t0 holds previous time
  79.  
  80. main_loop:
  81. # Call a short delay to prevent busy-wait overload
  82. jal delay
  83.  
  84. # Get simulated current time
  85. jal get_time
  86. sub $t5, $v0, $t0 # elapsed time in ms
  87. move $t0, $v0 # update reference time
  88.  
  89. # Update each stat's timer
  90. lw $t6, happiness_timer
  91. add $t6, $t6, $t5
  92. sw $t6, happiness_timer
  93.  
  94. lw $t6, sleepiness_timer
  95. add $t6, $t6, $t5
  96. sw $t6, sleepiness_timer
  97.  
  98. lw $t6, hunger_timer
  99. add $t6, $t6, $t5
  100. sw $t6, hunger_timer
  101.  
  102. # Check for happiness decay
  103. lw $t6, happiness_timer
  104. lw $t7, HAPPINESS_DECAY
  105. blt $t6, $t7, check_sleepiness_decay
  106. lw $t1, happiness
  107. blez $t1, check_sleepiness_decay
  108. sub $t1, $t1, 1
  109. sw $t1, happiness
  110. sw $zero, happiness_timer
  111.  
  112. check_sleepiness_decay:
  113. lw $t6, sleepiness_timer
  114. lw $t7, SLEEPINESS_DECAY
  115. blt $t6, $t7, check_hunger_decay
  116. lw $t2, sleepiness
  117. blez $t2, check_hunger_decay
  118. sub $t2, $t2, 1
  119. sw $t2, sleepiness
  120. sw $zero, sleepiness_timer
  121.  
  122. check_hunger_decay:
  123. lw $t6, hunger_timer
  124. lw $t7, HUNGER_DECAY
  125. blt $t6, $t7, update_pet_state
  126. lw $t3, hunger
  127. blez $t3, update_pet_state
  128. sub $t3, $t3, 1
  129. sw $t3, hunger
  130. sw $zero, hunger_timer
  131.  
  132. update_pet_state:
  133. # If all stats sum to 0, pet is dead (state 2)
  134. lw $t1, happiness
  135. lw $t2, sleepiness
  136. lw $t3, hunger
  137. add $t4, $t1, $t2
  138. add $t4, $t4, $t3
  139. beqz $t4, set_dead_state
  140.  
  141. # If sleeping flag is active, set state to 4 (sleeping)
  142. lw $t5, is_sleeping
  143. bnez $t5, set_sleeping_state
  144.  
  145. # If playing flag is active, set state to 3 (happy)
  146. lw $t5, is_playing
  147. bnez $t5, set_happy_state
  148.  
  149. # Otherwise, if any stat is less than 3, set to sad (1)
  150. li $t7, 3
  151. lw $t1, happiness
  152. blt $t1, $t7, set_sad_state
  153. lw $t2, sleepiness
  154. blt $t2, $t7, set_sad_state
  155. lw $t3, hunger
  156. blt $t3, $t7, set_sad_state
  157.  
  158. # Default state otherwise
  159. li $t4, 0
  160. j store_state
  161.  
  162. set_sad_state:
  163. li $t4, 1
  164. j store_state
  165.  
  166. set_dead_state:
  167. li $t4, 2
  168. j store_state
  169.  
  170. set_sleeping_state:
  171. li $t4, 4
  172. j store_state
  173.  
  174. set_happy_state:
  175. li $t4, 3
  176.  
  177. store_state:
  178. sw $t4, pet_state
  179.  
  180. # Display current UI
  181. jal display_ui
  182.  
  183. # If pet is dead, go to pet_dead routine
  184. lw $t4, pet_state
  185. li $t7, 2
  186. beq $t4, $t7, pet_dead
  187.  
  188. # Check if sleep duration elapsed to clear sleeping flag
  189. lw $t5, is_sleeping
  190. bnez $t5, check_sleep_duration
  191. j show_menu
  192.  
  193. check_sleep_duration:
  194. lw $t6, sleepiness_timer
  195. lw $t7, SLEEP_DURATION
  196. blt $t6, $t7, show_menu
  197. # Sleep finished: clear sleeping flag, refill sleepiness, reset timer
  198. sw $zero, is_sleeping
  199. li $t1, 5
  200. sw $t1, sleepiness
  201. sw $zero, sleepiness_timer
  202. j show_menu
  203.  
  204. show_menu:
  205. # Display menu prompt and get user choice
  206. li $v0, 4
  207. la $a0, menu_prompt
  208. syscall
  209.  
  210. li $v0, 5
  211. syscall
  212. move $t8, $v0
  213.  
  214. beq $t8, 1, play_action
  215. beq $t8, 2, sleep_action
  216. beq $t8, 3, feed_action
  217. beq $t8, 4, exit_program
  218.  
  219. # Invalid choice message
  220. li $v0, 4
  221. la $a0, invalid_choice
  222. syscall
  223. j main_loop
  224.  
  225. # --- Action Routines ---
  226. play_action:
  227. # Only act if pet is alive
  228. lw $t1, happiness
  229. lw $t2, sleepiness
  230. lw $t3, hunger
  231. add $t4, $t1, $t2
  232. add $t4, $t4, $t3
  233. beqz $t4, main_loop
  234.  
  235. # Increase happiness by one star (max 5)
  236. li $t5, 5
  237. lw $t1, happiness
  238. bge $t1, $t5, play_continue
  239. addi $t1, $t1, 1
  240. sw $t1, happiness
  241.  
  242. play_continue:
  243. # Set playing flag (to show ball accessory) and reset happiness timer
  244. li $t1, 1
  245. sw $t1, is_playing
  246. sw $zero, happiness_timer
  247.  
  248. li $v0, 4
  249. la $a0, playing_msg
  250. syscall
  251.  
  252. j main_loop
  253.  
  254. sleep_action:
  255. # Only act if pet is alive
  256. lw $t1, happiness
  257. lw $t2, sleepiness
  258. lw $t3, hunger
  259. add $t4, $t1, $t2
  260. add $t4, $t4, $t3
  261. beqz $t4, main_loop
  262.  
  263. # Set sleeping flag and reset sleepiness timer; refill sleepiness to 5
  264. li $t1, 1
  265. sw $t1, is_sleeping
  266. sw $zero, sleepiness_timer
  267. li $t1, 5
  268. sw $t1, sleepiness
  269.  
  270. li $v0, 4
  271. la $a0, sleeping_msg
  272. syscall
  273.  
  274. j main_loop
  275.  
  276. feed_action:
  277. # Only act if pet is alive
  278. lw $t1, happiness
  279. lw $t2, sleepiness
  280. lw $t3, hunger
  281. add $t4, $t1, $t2
  282. add $t4, $t4, $t3
  283. beqz $t4, main_loop
  284.  
  285. # Set eating flag and reset hunger timer; refill hunger to 5
  286. li $t1, 1
  287. sw $t1, is_eating
  288. sw $zero, hunger_timer
  289. li $t1, 5
  290. sw $t1, hunger
  291.  
  292. li $v0, 4
  293. la $a0, feeding_msg
  294. syscall
  295.  
  296. j main_loop
  297.  
  298. pet_dead:
  299. li $v0, 4
  300. la $a0, pet_dead_msg
  301. syscall
  302. li $v0, 4
  303. la $a0, rahmetli_art
  304. syscall
  305. j exit_program
  306.  
  307. # --- Display UI Routine ---
  308. # Clears the screen (by printing newlines), prints the pet's name,
  309. # then prints the pet icon (based on pet_state), any accessory,
  310. # and finally prints the three stat labels with their stars inline.
  311. display_ui:
  312. # Clear screen (simulate by printing several newlines)
  313. li $v0, 4
  314. la $a0, newline
  315. syscall
  316. syscall
  317. syscall
  318.  
  319. # Print pet name
  320. li $v0, 4
  321. la $a0, pet_name
  322. syscall
  323.  
  324. # Extra newline for spacing
  325. li $v0, 4
  326. la $a0, newline
  327. syscall
  328.  
  329. # Print pet icon based on pet_state
  330. lw $t4, pet_state
  331. li $t7, 0
  332. beq $t4, $t7, print_default
  333. li $t7, 1
  334. beq $t4, $t7, print_sad
  335. li $t7, 2
  336. beq $t4, $t7, print_dead
  337. li $t7, 3
  338. beq $t4, $t7, print_happy
  339. li $t7, 4
  340. beq $t4, $t7, print_sleeping
  341.  
  342. print_default:
  343. li $v0, 4
  344. la $a0, sretna_art
  345. syscall
  346. j print_accessories
  347.  
  348. print_sad:
  349. li $v0, 4
  350. la $a0, tuzna_art
  351. syscall
  352. j print_accessories
  353.  
  354. print_dead:
  355. li $v0, 4
  356. la $a0, rahmetli_art
  357. syscall
  358. j print_accessories
  359.  
  360. print_happy:
  361. li $v0, 4
  362. la $a0, vesela_art
  363. syscall
  364. j print_accessories
  365.  
  366. print_sleeping:
  367. li $v0, 4
  368. la $a0, spava_art
  369. syscall
  370.  
  371. print_accessories:
  372. # If feeding, show bowl; if playing, show ball
  373. lw $t5, is_eating
  374. bnez $t5, print_bowl
  375. lw $t5, is_playing
  376. bnez $t5, print_ball
  377. j print_stats
  378.  
  379. print_bowl:
  380. li $v0, 4
  381. la $a0, bowl_art
  382. syscall
  383. j print_stats
  384.  
  385. print_ball:
  386. li $v0, 4
  387. la $a0, ball_art
  388. syscall
  389.  
  390. print_stats:
  391. # Print stats inline on one line:
  392. # HAPPINESS: **** SLEEPINESS: **** HUNGER: ****
  393. li $v0, 4
  394. la $a0, happiness_label
  395. syscall
  396.  
  397. lw $t1, happiness
  398. jal print_stars
  399.  
  400. li $v0, 4
  401. la $a0, space
  402. syscall
  403.  
  404. li $v0, 4
  405. la $a0, sleepiness_label
  406. syscall
  407.  
  408. lw $t1, sleepiness
  409. jal print_stars
  410.  
  411. li $v0, 4
  412. la $a0, space
  413. syscall
  414.  
  415. li $v0, 4
  416. la $a0, hunger_label
  417. syscall
  418.  
  419. lw $t1, hunger
  420. jal print_stars
  421.  
  422. # Newline at end of stats line
  423. li $v0, 4
  424. la $a0, newline
  425. syscall
  426.  
  427. jr $ra
  428.  
  429. # --- Print Stars Routine ---
  430. # Expects $t1 to contain the number of stars to print.
  431. print_stars:
  432. blez $t1, print_stars_end
  433. print_stars_loop:
  434. li $v0, 4
  435. la $a0, star
  436. syscall
  437. addi $t1, $t1, -1
  438. bgtz $t1, print_stars_loop
  439. print_stars_end:
  440. jr $ra
  441.  
  442. # --- get_time Subroutine ---
  443. # Simulates a system time call by incrementing the global sim_time.
  444. # Returns the updated simulated time (in ms) in $v0.
  445. get_time:
  446. la $t9, sim_time
  447. lw $v0, 0($t9)
  448. addi $v0, $v0, 100 # simulate 100 ms per call
  449. sw $v0, 0($t9)
  450. jr $ra
  451.  
  452. # --- delay Subroutine ---
  453. # A short busy-wait loop (adjust the count as needed)
  454. delay:
  455. li $t9, 1000 # lower iteration count for a shorter delay
  456. delay_loop:
  457. addi $t9, $t9, -1
  458. bgtz $t9, delay_loop
  459. jr $ra
  460.  
  461. exit_program:
  462. li $v0, 10
  463. syscall
  464.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement