aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/libpsxcd/cdgetsector.s
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-11-22 09:11:12 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-11-22 09:11:12 +0800
commitea46d05aed0343c20d8fdfaa0e67d54d51e8e2a0 (patch)
tree43e2a53f4e5f7f55b075cfc9d6dc7a652a7b0837 /libpsn00b/libpsxcd/cdgetsector.s
parentd80d92e13330d527ddb94420b19f9e21bf0e74eb (diff)
downloadpsn00bsdk-ea46d05aed0343c20d8fdfaa0e67d54d51e8e2a0.tar.gz
Added long awaited CD-ROM library and loads of fixes, see changelog for details
Diffstat (limited to 'libpsn00b/libpsxcd/cdgetsector.s')
-rw-r--r--libpsn00b/libpsxcd/cdgetsector.s53
1 files changed, 53 insertions, 0 deletions
diff --git a/libpsn00b/libpsxcd/cdgetsector.s b/libpsn00b/libpsxcd/cdgetsector.s
new file mode 100644
index 0000000..70039bf
--- /dev/null
+++ b/libpsn00b/libpsxcd/cdgetsector.s
@@ -0,0 +1,53 @@
+.set noreorder
+
+.include "hwregs_a.h"
+
+.section .text
+
+.global CdGetSector
+.type CdGetSector, @function
+CdGetSector:
+
+ lui $a2, IOBASE
+
+.Lwait_fifo:
+ lbu $v0, CD_REG0($a2)
+ nop
+ andi $v0, 0x40
+ beqz $v0, .Lwait_fifo
+ nop
+
+ lui $v0, 0x1
+ srl $a1, 2
+ or $v0, $a1
+ sw $a0, D3_MADR($a2) # Set DMA base address and transfer length
+ sw $v0, D3_BCR($a2)
+
+ lui $v0, 0x1100 # Start DMA transfer
+ sw $v0, D3_CHCR($a2)
+ nop
+ nop
+.Ldma_wait:
+ lw $v0, D3_CHCR($a2)
+ nop
+ srl $v0, 24
+ andi $v0, 0x1
+ bnez $v0, .Ldma_wait
+ nop
+
+# Not stable
+# sb $0 , CD_REG0($a2)
+#.Lflush_fifo: # Read out any remaining bytes in the buffer
+# lbu $v1, CD_REG0($a2)
+# li $v0, 0x40
+# and $v1, $v0
+# beqz $v1, .Lend_flush
+# nop
+# lbu $v0, CD_REG2($a2)
+# b .Lflush_fifo
+# nop
+#.Lend_flush:
+
+ jr $ra
+ li $v0, 1
+