Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Luc Sheltons Basic MIPS Player
- .data # Data that is used within the MIPS file
- copyright: .asciiz "Developed by Luc Shelton\n"
- file: .asciiz "menu-main-theme-gm-.luc"
- msgOne: .asciiz "Name of the file: "
- .align 0
- buffer:
- .space 102400
- .text # Rest of the code
- main:
- # Register Reference
- # t8 - The max iterator, make sure to change this when the file has been loaded in
- # t9 - The iterator, this amount will increase once the play loop has been made
- # v0 - Type of syscall that is being made
- # Load the instruments at the top here
- openFile:
- # Printing out the filename with "Name of the file: " prior to it
- la $a0, copyright
- jal printString
- la $a0, msgOne # Print "Name of the file: "
- jal printString
- la $a0, file # Print "crawling.luc"
- jal printString
- # OPEN THE FILE AND STORE THE ASCIIZ AS FILE NAME
- # Open (for reading a file that does not exist
- li $v0, 13 # system call for open file
- la $a0, file # output file name
- li $a1, 0 # Open for writing (flags are 0: read, 1: write)
- li $a2, 0 # mode is ignored
- syscall # open a file (file descriptor returned in $v0)
- move $s6, $v0 # save the file descriptor - copying $v0 to $s6
- # LOAD THE FILE INTO MEMORY!
- li $v0, 14 # Assigning the syscall to read the file into memory
- move $a0, $s6 # File descriptor - Getting the file name
- la $a1, buffer # Puts the file into buffer
- li $a2, 104200 # Hardcoding the buffer size
- syscall
- # Close the file
- li $v0, 16 # system call for close file
- move $a0, $s6 # file descriptor to close
- syscall # close file
- la $k0,buffer # Load the buffer into memory.
- # Decide how the player is going to get set up
- jal loadnotecount
- addi $k0,$k0,1
- li $t8, 15 # Iterator max
- li $t9, 0 # The iterator
- loadchannels: # This loop is made to load all the instruments into the channels
- li $v0, 38 # Loading up syscall 38, changes channels instruments
- addi $a0, $t9, 0 # Define channel
- lb $a1, 0($k0) # Load the instrument from $k0 at the given pointers location
- syscall
- addi $k0, $k0, 1 # Move the pointer along in the memory address
- addi $t9, $t9, 1 # Increase the channel instrument iterator
- bne $t8,$t9, loadchannels # If the iterator is not equal to 15 carrying on looping through the load chanels
- li $t8, 0
- li $t9, 0
- addi $k0,$k0,1 # Increase the pointer again
- # BYTE ORDER
- # 1: CHANNEL
- #IGNORE
- # 2: DURATION BYTE 1
- # 3: DURATION BYTE 2
- # 4: DURATION BYTE 3
- # 5: DURATION BYTE 4
- # 3: PITCH
- # 4: VOLUME
- # 5: SLEEPTIME
- # 11: VOLUME
- li $t2, 0 # Iterator
- play:
- li $v0, 37
- lb $a2, 0($k0) # CHANNEL # as thats the first thing that's written to binary
- beq $a2, -1, exit
- addi $k0, $k0, 1 # Move the pointer along one.
- jal loadduration
- addi $k0, $k0, 1
- lb $a0, 0($k0) # PITCH / KEY
- addi $k0, $k0, 1
- lb $a3, 0($k0) # VOLUME / VELOCITY
- addi $k0, $k0, 1
- syscall
- # Go to SLEEEEP until the next note D:
- li $v0, 32
- #addi $k0, $k0, 1
- jal loadsleep
- addi $k0, $k0, 1 # Push the pointer forward for the next time around
- syscall
- # Increase the counter
- addi $t2, $t2, 1
- bne $t2,$t0, play
- # Enter player code
- #addiu $t9, $t9, 1 # Adds one onto the iterator
- #syscall
- #jr $ra # Go back to return address
- #bne $t8, $t9, play
- jal exit
- loadduration:
- #addi $s1, $0, 0
- #lb $s1, 0($k0)
- #mul $s1, $s1, $s2
- lbu $s1, 0($k0) # Load the first byte of the duration
- addi $k0, $k0, 1
- lbu $s2, 0($k0) # Load the second byte of the duration
- addi $k0, $k0, 1
- lbu $s3, 0($k0) # Load the third byte of the duration
- addi $k0, $k0, 1
- lbu $s4, 0($k0) # Load the fourth and last byte of the duration
- mul $s1, $s1, $s2 # Multiply the second and the first byte together
- mul $s1, $s1, $s3 # Multiply the result of the two with the third byte
- # Add the last byte onto the total
- add $s1, $s1, $s4
- move $a1, $s1 # Now that all the multiplication is done, lets move it back!
- jr $ra
- loadsleep:
- #li $s1, 0
- #lb $s1, 0($k0)
- #mul $s1, $s1, $s3
- lbu $s1, 0($k0) # Load the first byte of the duration
- addi $k0, $k0, 1
- lbu $s2, 0($k0) # Load the second byte of the duration
- addi $k0, $k0, 1
- lbu $s3, 0($k0) # Load the third byte of the duration
- addi $k0, $k0, 1
- lbu $s4, 0($k0) # Load the fourth and last byte of the duration
- mul $s1, $s1, $s2 # Multiply the second and the first byte together
- mul $s1, $s1, $s3 # Multiply the result of the two with the third byte
- # Add the last byte onto the total
- add $s1, $s1, $s4
- move $a0, $s1 # Now that all the multiplication is done, lets move it back!
- jr $ra
- # End the duration loading
- loadnotecount:
- lbu $s1, 0($k0) # Load the first byte of the duration
- addi $k0, $k0, 1
- lbu $s2, 0($k0) # Load the second byte of the duration
- addi $k0, $k0, 1
- lbu $s3, 0($k0) # Load the third byte of the duration
- addi $k0, $k0, 1
- lbu $s4, 0($k0) # Load the fourth and last byte of the duration
- mul $s1, $s1, $s2 # Multiply the second and the first byte together
- mul $s1, $s1, $s3 # Multiply the result of the two with the third byte
- # Add the last byte onto the total
- add $s1, $s1, $s4
- move $t0, $s1 # Now that all the multiplication is done, lets move it back!
- jr $ra
- printString:
- li $v0, 4 # Assigning the "Print String" Syscall
- syscall
- jr $ra # Hop back to where it was called
- exit: # Leave the program and set the default values back
- addi $v0,$0, 10 # Syscall 10 - terminate and leave the program
- syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement