Joypad Code Executed At Startup?

Topics relating to the 68000 CPU in general, not a specific platform.
Post Reply
Posts: 23
Joined: Thu Apr 22, 2021 9:30 pm

Joypad Code Executed At Startup?

Post by puppydrum64 » Mon May 24, 2021 2:14 am

I was fiddling with the Joystick test rom for Neo Geo and ran into this problem, but I seem to recall something similar happening to me on Commodore 64 and Gameboy Advance so I'm not sure which board this belongs in but anyway...

The Joypad routine doesn't check the buttons on Neo Geo (I believe it had 4 but I don't quite recall) and I wanted to see if I could add that functionality in. I decided to use something simple- have the background color change when you press A. Weird thing is, when the game boots, the background has already changed before pressing any buttons! If I comment out the part where the background changes when pressing A, the background appears as normal. To keep things brief, I will only include the original palette setup code and the input handler. I haven't done anything with Commodore 64 or GBA in a while but I seem to remember having the same problem on those systems as well (I've never had this happen on the NES and I think it's because its controller works differently)

Code: Select all

	;        -RGB			;Color Num:
	move.w #$000F,$401FFE	;0 - Background color
	move.w #$0FF0,$400022	;1
	move.w #$00FF,$400024	;2
	move.w #$0F00,$400026	;3
	move.w #$0FF0,$40003E	;15 - Font
	btst #0,d3
	bne JoyNotUp		;Jump if UP not pressed
	subq.w #1,d1		;Move Y Up the screen
	btst #1,d3
	bne JoyNotDown		;Jump if DOWN not pressed
	addq.w #1,d1		;Move Y DOWN the screen

	btst #2,d3
	bne JoyNotLeft		;Jump if LEFT not pressed
	subq.w #1,d0		;Move X Left

	btst #3,d3
	bne JoyNotRight		;Jump if RIGHT not pressed
	addq.w #1,d0		;Move X Right
	btst #4,d3			;Jump if A not pressed
	bne JoyNotA
	;        -RGB			;Color Num:
	move.w #$0006,$401FFE	;0 - Background color
	move.w #$0FF0,$400022	;1
	move.w #$00FF,$400024	;2
	move.w #$0F00,$400026	;3
	move.w #$0FF0,$40003E	;15 - Font
	btst #5,d3			;Jump if B not pressed
	bne JoyNotB

	btst #6,d3			;Jump if C not pressed
	bne JoyNotC
	btst #7,d3			;Jump if D not pressed
	bne JoyNotD
	move.w d1,(PlayerY)
	move.w d0,(PlayerX)
;X Boundary Check - if we go <0 we will end up back at &FF
	cmp.w #40,d0
	bcs PlayerPosXOk		
	jmp PlayerReset		;Player out of bounds - Reset!

Post Reply

Return to “General 68000 Assembly”