diff options
| author | lameguy64 <lameguy64@gmail.com> | 2019-05-23 22:24:56 +0800 |
|---|---|---|
| committer | lameguy64 <lameguy64@gmail.com> | 2019-05-23 22:24:56 +0800 |
| commit | 3ffebff2aad2ca438cf76db51fb3459c5639cd67 (patch) | |
| tree | a234fc6158d3c09904c4c1fb2feee09afb479a4c /libpsn00b | |
| parent | e70cd149f41ea71f9ca9ee86c03d1e59005dad2a (diff) | |
| download | psn00bsdk-3ffebff2aad2ca438cf76db51fb3459c5639cd67.tar.gz | |
Added BIOS Controller, BIOS CD, 2 new examples and custom exit handler in the works
Diffstat (limited to 'libpsn00b')
| -rw-r--r-- | libpsn00b/include/psxapi.h | 16 | ||||
| -rw-r--r-- | libpsn00b/include/psxpad.h | 1 | ||||
| -rw-r--r-- | libpsn00b/libc/readme.txt | 4 | ||||
| -rw-r--r-- | libpsn00b/libc/start.s | 16 | ||||
| -rw-r--r-- | libpsn00b/psxapi/fs/_InitCd.s | 37 | ||||
| -rw-r--r-- | libpsn00b/psxapi/makefile | 2 | ||||
| -rw-r--r-- | libpsn00b/psxapi/pad/initpad.s | 10 | ||||
| -rw-r--r-- | libpsn00b/psxapi/pad/startpad.s | 10 | ||||
| -rw-r--r-- | libpsn00b/psxapi/pad/stoppad.s | 10 | ||||
| -rw-r--r-- | libpsn00b/psxapi/sys/initcard.s | 10 | ||||
| -rw-r--r-- | libpsn00b/psxapi/sys/initpad.s | 11 | ||||
| -rw-r--r-- | libpsn00b/psxapi/sys/returnfromexception.s | 10 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/readme.txt | 15 | ||||
| -rw-r--r-- | libpsn00b/psxgpu/resetgraph.s | 81 |
14 files changed, 181 insertions, 52 deletions
diff --git a/libpsn00b/include/psxapi.h b/libpsn00b/include/psxapi.h index 54b87ee..9cfb6cb 100644 --- a/libpsn00b/include/psxapi.h +++ b/libpsn00b/include/psxapi.h @@ -84,14 +84,20 @@ extern int chdir(const char *path); int AddDev(DCB *dcb); int DelDev(const char *name); -extern void ListDev(); +extern void ListDev(void); -extern void EnterCriticalSection(); -extern void ExitCriticalSection(); +extern void EnterCriticalSection(void); +extern void ExitCriticalSection(void); -extern void _96_init(); -extern void _96_remove(); +extern void _InitCd(void); +extern void _96_init(void); +extern void _96_remove(void); extern void ChangeClearPAD(int mode); +// BIOS pad functions +void _InitPad(char *buff1, int len1, char *buff2, int len2); +void _StartPad(void); +void _StopPad(void); + #endif diff --git a/libpsn00b/include/psxpad.h b/libpsn00b/include/psxpad.h index 09d17b1..5478596 100644 --- a/libpsn00b/include/psxpad.h +++ b/libpsn00b/include/psxpad.h @@ -104,5 +104,4 @@ typedef struct { unsigned short gun_y; // Gun Y position in scanlines } GCONTYPE; - #endif
\ No newline at end of file diff --git a/libpsn00b/libc/readme.txt b/libpsn00b/libc/readme.txt index d7abf0a..064a353 100644 --- a/libpsn00b/libc/readme.txt +++ b/libpsn00b/libc/readme.txt @@ -45,4 +45,6 @@ Todo list: Changelog: - None thus far... + 05-23-2019 by Lameguy64: + + * Made stack usage a lot less wastefull in _start entrypoint. diff --git a/libpsn00b/libc/start.s b/libpsn00b/libc/start.s index c9b529b..d08a2c7 100644 --- a/libpsn00b/libc/start.s +++ b/libpsn00b/libc/start.s @@ -1,5 +1,5 @@ # Start function! -# This is essentially the entrypoint of the PS-EXE +# This is essentially the entry point of the PS-EXE .set noreorder @@ -8,11 +8,10 @@ .global _start .type _start, @function _start: - - addiu $sp, -32 - sw $ra, 28($sp) + addiu $sp, -4 + sw $ra, 0($sp) - la $gp, _gp # Very important to set! + la $gp, _gp # Very important! la $a0, .bss # What are the CORRECT symbols for BSS start and end? la $a1, _end @@ -30,10 +29,11 @@ _start: move $a1, $0 jal main - nop + addiu $sp, -8 + addiu $sp, 8 - lw $ra, 28($sp) - addiu $sp, 32 + lw $ra, 0($sp) # Return + addiu $sp, 4 jr $ra nop
\ No newline at end of file diff --git a/libpsn00b/psxapi/fs/_InitCd.s b/libpsn00b/psxapi/fs/_InitCd.s new file mode 100644 index 0000000..decf2bd --- /dev/null +++ b/libpsn00b/psxapi/fs/_InitCd.s @@ -0,0 +1,37 @@ +.section .text +.set noreorder + +.include "hwregs_a.h" + +.global _InitCd +.type _InitCd, @function +_InitCd: + addiu $sp, -8 + sw $ra, 0($sp) + + lui $a0, IOBASE # Load IOBASE value + + lw $v0, DPCR($a0) # Get current DMA settings + nop + sw $v0, 4($sp) # Save to stack + + jal _96_init # Init CD subsystem + nop + + lui $a0, IOBASE # Load IOBASE again + + lw $v0, 4($sp) # Get old DMA control settings + lw $v1, DPCR($a0) # Get DMA settings by _96_init() + + lui $a1, 0xffff # Mask out settings for CD DMA + ori $a1, 0x0f00 + and $v0, $a1 + + or $v0, $v1 # Merge and set new DMA settings + sw $v0, DPCR($a0) + + lw $ra, 0($sp) + addiu $sp, 8 + jr $ra + nop +
\ No newline at end of file diff --git a/libpsn00b/psxapi/makefile b/libpsn00b/psxapi/makefile index 30c1522..e97451c 100644 --- a/libpsn00b/psxapi/makefile +++ b/libpsn00b/psxapi/makefile @@ -6,7 +6,7 @@ PREFIX = mipsel-unknown-elf- TARGET = ../libpsxapi.a -SOURCES = stdio fs sys +SOURCES = stdio fs sys pad AFILES = $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.s)) OFILES = $(addprefix build/,$(AFILES:.s=.o)) diff --git a/libpsn00b/psxapi/pad/initpad.s b/libpsn00b/psxapi/pad/initpad.s new file mode 100644 index 0000000..d983d75 --- /dev/null +++ b/libpsn00b/psxapi/pad/initpad.s @@ -0,0 +1,10 @@ +.set noreorder +.section .text + +.global _InitPad +.type _InitPad, @function +_InitPad: + addiu $t2, $0 , 0xb0 + jr $t2 + addiu $t1, $0 , 0x12 +
\ No newline at end of file diff --git a/libpsn00b/psxapi/pad/startpad.s b/libpsn00b/psxapi/pad/startpad.s new file mode 100644 index 0000000..c8e7da8 --- /dev/null +++ b/libpsn00b/psxapi/pad/startpad.s @@ -0,0 +1,10 @@ +.set noreorder +.section .text + +.global _StartPad +.type _StartPad, @function +_StartPad: + addiu $t2, $0 , 0xb0 + jr $t2 + addiu $t1, $0 , 0x13 +
\ No newline at end of file diff --git a/libpsn00b/psxapi/pad/stoppad.s b/libpsn00b/psxapi/pad/stoppad.s new file mode 100644 index 0000000..4465e5a --- /dev/null +++ b/libpsn00b/psxapi/pad/stoppad.s @@ -0,0 +1,10 @@ +.set noreorder +.section .text + +.global _StopPad +.type _StopPad, @function +_StopPad: + addiu $t2, $0 , 0xb0 + jr $t2 + addiu $t1, $0 , 0x14 +
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/initcard.s b/libpsn00b/psxapi/sys/initcard.s deleted file mode 100644 index e589592..0000000 --- a/libpsn00b/psxapi/sys/initcard.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global InitCard -.type InitCard, @function -InitCard: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x4a -
\ No newline at end of file diff --git a/libpsn00b/psxapi/sys/initpad.s b/libpsn00b/psxapi/sys/initpad.s deleted file mode 100644 index b0f1b6f..0000000 --- a/libpsn00b/psxapi/sys/initpad.s +++ /dev/null @@ -1,11 +0,0 @@ -.set noreorder -.section .text - -.include "hwregs_a.h" - -.global InitPad -.type InitPad, @function -InitPad: - addiu $t2, $0, 0xb0 - jr $t2 - addiu $t1, $0, 0x12 diff --git a/libpsn00b/psxapi/sys/returnfromexception.s b/libpsn00b/psxapi/sys/returnfromexception.s new file mode 100644 index 0000000..ec67b64 --- /dev/null +++ b/libpsn00b/psxapi/sys/returnfromexception.s @@ -0,0 +1,10 @@ +.set noreorder +.section .text + +.global ReturnFromException +.type ReturnFromException, @function +ReturnFromException: + addiu $t2, $0, 0xb0 + jr $t2 + addiu $t1, $0, 0x17 +
\ No newline at end of file diff --git a/libpsn00b/psxgpu/readme.txt b/libpsn00b/psxgpu/readme.txt index 55fcb68..0d44e72 100644 --- a/libpsn00b/psxgpu/readme.txt +++ b/libpsn00b/psxgpu/readme.txt @@ -27,7 +27,7 @@ Todo list: getting number of vsyncs elapsed and waiting until a specified number of vsyncs have passed. - * VSync interrupt handler should be hooked using BIOS function + * (old) VSync interrupt handler should be hooked using BIOS function SetCustomExitFromException() like the official GPU library instead of hooking an event handler, but said hook never seems to work. Perhaps something in the kernel area needs to be patched/set or some event/IRQ @@ -47,4 +47,15 @@ Todo list: Changelog: - None thus far... + 05-23-2019 by Lameguy64: + + * Got custom exit handler set using SetCustomExitFromException() (BIOS + function B(19h)) working. Currently used to acknowledge VSync IRQ but + actual VSync handling is still done with events and needs to be + transferred to the custom exit handler. At least it lets BIOS + controller functions to work now. See doc/dev notes.txt for details + on how this handler behaves. + + * Made stack usage a lot less wasteful in ResetGraph() (you only need + to allocate N words on stack based on N arguments of the function + being called. diff --git a/libpsn00b/psxgpu/resetgraph.s b/libpsn00b/psxgpu/resetgraph.s index bc30d3b..189b1ad 100644 --- a/libpsn00b/psxgpu/resetgraph.s +++ b/libpsn00b/psxgpu/resetgraph.s @@ -9,9 +9,9 @@ .global ResetGraph # Resets the GPU and installs a .type ResetGraph, @function # VSync event handler ResetGraph: - addiu $sp, -0x20 # C style stack allocation (required if - sw $ra, 28($sp) # you call BIOS functions from asm) - sw $a0, 24($sp) + addiu $sp, -8 # C style stack allocation (required if + sw $ra, 0($sp) # you call BIOS functions from asm) + sw $a0, 4($sp) la $v0, _hooks_installed # Skip installing hooks if this function lbu $v0, 0($v0) # has already been called before once @@ -20,8 +20,8 @@ ResetGraph: nop # Temporary, may help improve compatibility? - jal SetDefaultExitFromException - nop + #jal SetDefaultExitFromException + #nop jal ChangeClearPAD # Remove pad handler left by the BIOS move $a0, $0 @@ -52,13 +52,16 @@ ResetGraph: jal OpenEvent # Open a VSync event handler # (PSXSDK style vsync handler) - nop + addiu $sp, -16 + addiu $sp, 16 la $v1, _vsync_event_desc # Save event descriptor sw $v0, 0($v1) - jal EnableEvent # Enable the opened event move $a0, $v0 + jal EnableEvent # Enable the opened event + addiu $sp, -4 + addiu $sp, 4 la $v0, _hooks_installed # Set installed flag li $v1, 0x1 @@ -70,6 +73,11 @@ ResetGraph: la $v0, _vsync_callback_func # Clear callback function sw $0 , 0($v0) + la $a0, _custom_exit + jal SetCustomExitFromException + addiu $sp, -4 + addiu $sp, 4 + jal ExitCriticalSection # Re-enable interrupts nop @@ -87,7 +95,7 @@ ResetGraph: sw $v0, 0($v1) .not_pal: - lw $a0, 24($sp) # Get argument value + lw $a0, 4($sp) # Get argument value lui $a3, 0x1f80 # Set base I/O again (likely destroyed # by previous calls) @@ -118,10 +126,10 @@ ResetGraph: .init_done: - lw $ra, 28($sp) - lw $a0, 24($sp) # Return + lw $ra, 0($sp) + lw $a0, 4($sp) # Return jr $ra - addiu $sp, 0x20 + addiu $sp, 8 .global _vsync_func # VSync event handler, executed on @@ -142,8 +150,9 @@ _vsync_func: andi $v0, $v1, 0x1 beqz $v0, .exit nop - xori $v1, $v1, 0x1 # Acknowledge the IRQ - sw $v1, ISTAT($at) + + #xori $v1, $v1, 0x1 # Acknowledge the IRQ + #sw $v1, ISTAT($at) # Commented out as it breaks BIOS pads la $v1, _vsync_counter # Increment VSync counter lw $v0, 0($v1) @@ -171,6 +180,32 @@ _vsync_func: nop +.global _vsync_func_2 +.type _vsync_func_2, @function +_vsync_func_2: + + lui $at, 0x1f80 # Check if there's a VSync IRQ + lw $v0, IMASK($at) + nop + andi $v0, $v0, 0x1 + beqz $v0, .exit_2 + nop + + lw $v1, ISTAT($at) + nop + andi $v0, $v1, 0x1 + beqz $v0, .exit_2 + nop + + xori $v1, $v1, 0x1 # Acknowledge the IRQ + sw $v1, ISTAT($at) + +.exit_2: + + j ReturnFromException + nop + + .global VSync # VSync function .type VSync, @function VSync: @@ -211,6 +246,26 @@ VSync: library_credits: .string "psxgpu programs by Lameguy64" + +.type _custom_exit, @object +_custom_exit: + .word _vsync_func_2 # pc + .word _vsync_stack # sp + .word 0 # fp + .word 0 # s0 + .word 0 # s1 + .word 0 # s2 + .word 0 # s3 + .word 0 # s4 + .word 0 # s5 + .word 0 # s6 + .word 0 # s7 + .word _gp # gp + + .fill 60 +_vsync_stack: + .fill 4 + .type _vsync_counter, @object _vsync_counter: .word 0 |
