;; send up to two 8byte values to mechacon and read up to two back
;; $s0 carries the command value to send to the mechacon
;; $s1 is how many bytes to send (8 or 16 probably)
.align 128
mecha_input:
dc64 0, 0
mecha_output:
dc64 0, 0
.align 32
Mechacon_auth:
addi $sp, $sp, -48
sd $ra, 0($sp)
sd $s0, 8($sp)
sd $s1, 16($sp)
sd $s2, 24($sp)
sd $s3, 32($sp)
sd $s4, 40($sp)
jal CDVD_wait
nop
li $s0, CDVD_STATP
li $s2, mecha_input
Mechacon_send_loop:
lbu $s3, ($s2)
addi $s1, $s1, -1
sb $s3, ($s0)
bne $s1, $zero, Mechacon_send_loop
addi $s2, $s2, 1
li $s0, CDVD_SCMD
lbu $s1, 8($sp) ; read the command out of stack
jal CDVD_wait
sb $s1, ($s0) ; send command and wait
li $s0, CDVD_RESULT
li $s2, mecha_output
ori $s4, $zero, 0x10
Mechacon_get_loop:
lbu $s1, ($s0)
addi $s4, $s4, -1
sb $s1, ($s2)
bne $s4, $zero, Mechacon_get_loop
addi $s2, $s2, 1
ld $ra, 0($sp)
ld $s0, 8($sp)
ld $s1, 16($sp)
ld $s2, 24($sp)
ld $s3, 32($sp)
ld $s4, 40($sp)
jr $ra
addi $sp, $sp, 48
Because the "Mechacon" is in the CDVD area, it is communicated with using the same SCMD process as reading the RTC, so I can easily copy and adapt that routine and add a couple of little buffers to hold the input and output.