Controller with ASM code

General Programming help in C, C++ or ASM, Compiling / Debugging, and R3000A Central Processing Unit (CPU) information
Post Reply
User avatar
scorpion2k81
Curious PSXDEV User
Curious PSXDEV User
Posts: 23
Joined: Feb 24, 2022
I am a: Programmer
PlayStation Model: SCPH-5502
Location: Italy

Controller with ASM code

Post by scorpion2k81 » December 1st, 2022, 10:58 am

Hello,
How can I read controller buttons via asm code?
I would like to use it with asmpsx.

User avatar
Shadow
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2638
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

Post by Shadow » December 1st, 2022, 12:03 pm

Here's some snippets to help you out. You'll need to understand MIPS in order to get it to work correctly ;)

Code: Select all

var_pad_pointer		equ		$80100020


; branch if triangle is being held
check_triangle
	li		t0,var_pad_pointer
	lhu		t0,$0(t6)
	nop		
	beq		t0,$10,myfunction
	nop


; InitPads - initialise the joypads (trashes fp)
InitPads
	addiu   	sp, sp, -$C
	sw      	ra, $0(sp)
	sw      	s0, $4(sp)
	sw		fp, $8(sp)
	nop
	addiu		sp,sp,-$20		; stack
	
	jal		NBStartPAD
	nop
	
	li		t1, $15
	li		a0, $20000001
	li		t2, $b0
	
	li		a1,var_pad_pointer
	li		a2,$00000000
	sw		a2,$0(a1)
	;li		a2,$0000FFFF	; to test, write a nonzero value to the pad read loc
	;sw		a2,$0(a1)
	
	jal NBPAD_init
	nop
	
	;la		a1, pad_buf
	;jalr		t2
	;nop
	
	addiu   	sp,sp,$20		; stack
	
	lw		ra,$0(sp)
	lw      	s0,$4(sp)
	lw		fp,$8(sp)

	addiu   	sp,sp,$C
	jr      	ra
	nop


; kernel/BIOS functions
NBStartPAD:
	ori     	t2, zero, $B0
	jr      	t2			; StartPAD
	ori     	t1, zero, $13


NBPAD_init:
	ori     	t2, zero, $B0
	jr      	t2			; PAD_init
	ori     	t1, zero, $15
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
scorpion2k81
Curious PSXDEV User
Curious PSXDEV User
Posts: 23
Joined: Feb 24, 2022
I am a: Programmer
PlayStation Model: SCPH-5502
Location: Italy

Post by scorpion2k81 » December 1st, 2022, 10:42 pm

Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest