Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. # Luc Sheltons Basic MIPS Player
  2.  
  3. .data # Data that is used within the MIPS file
  4.  
  5.  
  6. copyright: .asciiz "Developed by Luc Shelton\n"
  7.  
  8. file: .asciiz "menu-main-theme-gm-.luc"
  9. msgOne: .asciiz "Name of the file: "
  10.  
  11. .align 0
  12. buffer:
  13. .space 102400
  14.  
  15. .text # Rest of the code
  16. main:
  17.  
  18.  
  19. # Register Reference
  20. # t8 - The max iterator, make sure to change this when the file has been loaded in
  21. # t9 - The iterator, this amount will increase once the play loop has been made
  22.  
  23. # v0 - Type of syscall that is being made
  24.  
  25. # Load the instruments at the top here
  26.  
  27. openFile:
  28.  
  29. # Printing out the filename with "Name of the file: " prior to it
  30. la $a0, copyright
  31. jal printString
  32.  
  33. la $a0, msgOne # Print "Name of the file: "
  34. jal printString
  35.  
  36. la $a0, file # Print "crawling.luc"
  37. jal printString
  38.  
  39. # OPEN THE FILE AND STORE THE ASCIIZ AS FILE NAME
  40.  
  41. # Open (for reading a file that does not exist
  42. li $v0, 13 # system call for open file
  43. la $a0, file # output file name
  44. li $a1, 0 # Open for writing (flags are 0: read, 1: write)
  45. li $a2, 0 # mode is ignored
  46. syscall # open a file (file descriptor returned in $v0)
  47. move $s6, $v0 # save the file descriptor - copying $v0 to $s6
  48.  
  49. # LOAD THE FILE INTO MEMORY!
  50.  
  51. li $v0, 14 # Assigning the syscall to read the file into memory
  52. move $a0, $s6 # File descriptor - Getting the file name
  53. la $a1, buffer # Puts the file into buffer
  54. li $a2, 104200 # Hardcoding the buffer size
  55. syscall
  56.  
  57. # Close the file
  58. li $v0, 16 # system call for close file
  59. move $a0, $s6 # file descriptor to close
  60. syscall # close file
  61.  
  62.  
  63. la $k0,buffer # Load the buffer into memory.
  64.  
  65.  
  66. # Decide how the player is going to get set up
  67.  
  68. jal loadnotecount
  69. addi $k0,$k0,1
  70.  
  71. li $t8, 15 # Iterator max
  72. li $t9, 0 # The iterator
  73.  
  74. loadchannels: # This loop is made to load all the instruments into the channels
  75. li $v0, 38 # Loading up syscall 38, changes channels instruments
  76. addi $a0, $t9, 0 # Define channel
  77. lb $a1, 0($k0) # Load the instrument from $k0 at the given pointers location
  78. syscall
  79.  
  80. addi $k0, $k0, 1 # Move the pointer along in the memory address
  81. addi $t9, $t9, 1 # Increase the channel instrument iterator
  82.  
  83. bne $t8,$t9, loadchannels # If the iterator is not equal to 15 carrying on looping through the load chanels
  84.  
  85. li $t8, 0
  86. li $t9, 0
  87.  
  88. addi $k0,$k0,1 # Increase the pointer again
  89.  
  90. # BYTE ORDER
  91. # 1: CHANNEL
  92.  
  93. #IGNORE
  94. # 2: DURATION BYTE 1
  95. # 3: DURATION BYTE 2
  96. # 4: DURATION BYTE 3
  97. # 5: DURATION BYTE 4
  98.  
  99. # 3: PITCH
  100. # 4: VOLUME
  101. # 5: SLEEPTIME
  102.  
  103. # 11: VOLUME
  104.  
  105. li $t2, 0 # Iterator
  106.  
  107. play:
  108. li $v0, 37
  109. lb $a2, 0($k0) # CHANNEL # as thats the first thing that's written to binary
  110. beq $a2, -1, exit
  111. addi $k0, $k0, 1 # Move the pointer along one.
  112. jal loadduration
  113. addi $k0, $k0, 1
  114.  
  115. lb $a0, 0($k0) # PITCH / KEY
  116. addi $k0, $k0, 1
  117.  
  118. lb $a3, 0($k0) # VOLUME / VELOCITY
  119. addi $k0, $k0, 1
  120.  
  121. syscall
  122.  
  123. # Go to SLEEEEP until the next note D:
  124. li $v0, 32
  125. #addi $k0, $k0, 1
  126. jal loadsleep
  127. addi $k0, $k0, 1 # Push the pointer forward for the next time around
  128. syscall
  129.  
  130. # Increase the counter
  131. addi $t2, $t2, 1
  132.  
  133. bne $t2,$t0, play
  134.  
  135.  
  136. # Enter player code
  137. #addiu $t9, $t9, 1 # Adds one onto the iterator
  138.  
  139. #syscall
  140. #jr $ra # Go back to return address
  141.  
  142.  
  143. #bne $t8, $t9, play
  144.  
  145. jal exit
  146.  
  147. loadduration:
  148. #addi $s1, $0, 0
  149. #lb $s1, 0($k0)
  150. #mul $s1, $s1, $s2
  151.  
  152. lbu $s1, 0($k0) # Load the first byte of the duration
  153. addi $k0, $k0, 1
  154. lbu $s2, 0($k0) # Load the second byte of the duration
  155. addi $k0, $k0, 1
  156. lbu $s3, 0($k0) # Load the third byte of the duration
  157. addi $k0, $k0, 1
  158. lbu $s4, 0($k0) # Load the fourth and last byte of the duration
  159.  
  160. mul $s1, $s1, $s2 # Multiply the second and the first byte together
  161. mul $s1, $s1, $s3 # Multiply the result of the two with the third byte
  162.  
  163. # Add the last byte onto the total
  164. add $s1, $s1, $s4
  165.  
  166. move $a1, $s1 # Now that all the multiplication is done, lets move it back!
  167. jr $ra
  168.  
  169. loadsleep:
  170. #li $s1, 0
  171. #lb $s1, 0($k0)
  172. #mul $s1, $s1, $s3
  173.  
  174. lbu $s1, 0($k0) # Load the first byte of the duration
  175. addi $k0, $k0, 1
  176. lbu $s2, 0($k0) # Load the second byte of the duration
  177. addi $k0, $k0, 1
  178. lbu $s3, 0($k0) # Load the third byte of the duration
  179. addi $k0, $k0, 1
  180. lbu $s4, 0($k0) # Load the fourth and last byte of the duration
  181.  
  182. mul $s1, $s1, $s2 # Multiply the second and the first byte together
  183. mul $s1, $s1, $s3 # Multiply the result of the two with the third byte
  184.  
  185. # Add the last byte onto the total
  186. add $s1, $s1, $s4
  187.  
  188. move $a0, $s1 # Now that all the multiplication is done, lets move it back!
  189. jr $ra
  190.  
  191. # End the duration loading
  192.  
  193. loadnotecount:
  194. lbu $s1, 0($k0) # Load the first byte of the duration
  195. addi $k0, $k0, 1
  196. lbu $s2, 0($k0) # Load the second byte of the duration
  197. addi $k0, $k0, 1
  198. lbu $s3, 0($k0) # Load the third byte of the duration
  199. addi $k0, $k0, 1
  200. lbu $s4, 0($k0) # Load the fourth and last byte of the duration
  201.  
  202. mul $s1, $s1, $s2 # Multiply the second and the first byte together
  203. mul $s1, $s1, $s3 # Multiply the result of the two with the third byte
  204.  
  205. # Add the last byte onto the total
  206. add $s1, $s1, $s4
  207.  
  208. move $t0, $s1 # Now that all the multiplication is done, lets move it back!
  209. jr $ra
  210.  
  211. printString:
  212. li $v0, 4 # Assigning the "Print String" Syscall
  213. syscall
  214. jr $ra # Hop back to where it was called
  215.  
  216. exit: # Leave the program and set the default values back
  217. addi $v0,$0, 10 # Syscall 10 - terminate and leave the program
  218. syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement