Language…
12 users online: DanMario24YT, Dennsen86, derv82, drkrdnk, eltiolavara9, Fozymandias, Maw, Nayfal, prisvag, Red2010, Serena, steelsburg - Guests: 297 - Bots: 249
Users: 64,795 (2,374 active)
Latest user: mathew

Changing the background color on button press

With perhaps ASM or a contraption?

I'd like to make a hack with one level that does one thing: changes the color of the screen (to something bright like red, green, yellow) when a face button is pressed, and reverts the color to blank (black would be suitable) when the button is released.

It would serve as a utility hack for easily measuring and adjusting input lag with a high speed camera.

Fancier options such as flashing the colors red for A, yellow for B, etc would be nice but not required.

I'd like to use the hack for a guide on how to precisely adjust input lag for emulators, as I'm tired of the myth that it cannot be matched to console. Such a utility hack would make it a bit easier for everyone.

Thanks!
Edited the title with a clear description.
This might do the trick (to be inserted with uberASMTool):

Code
main:

	REP #$20
	STZ $0701
	SEP #$20

	PHB : PHK : PLB
	LDX.b #.table_end-.table-4
.loop
	LDA .table,x
	STA $00
	STZ $01
	LDA ($00)
	AND .table+1,x
	BEQ .continue
	REP #$20
	LDA .table+2,x
	STA $0701
	SEP #$20
	BRA .break
.continue
	DEX #4
	BPL .loop
.break

	PLB
	RTL

.table
	db $15,%00001000 : dw $001F	; UP: red
	db $15,%00000100 : dw $7F80	; DOWN: blue
	db $15,%00000010 : dw $03E0	; LEFT: green
	db $15,%00000001 : dw $03E0	; RIGHT: yellow
	db $17,%10000000 : dw $021F	; A: orange
	db $15,%10000000 : dw $4010	; A or B: purple
	db $17,%01000000 : dw $621F	; X: pink
	db $15,%01000000 : dw $7FE0	; X or Y: cyan
	db $15,%00100000 : dw $0177	; SELECT: brown
	db $15,%00010000 : dw $7FFF	; START: white
..end


If you want to change a color, you can use LM's palette editor to get its value (look for "SNES RGB value") and replace the number at the end of the row.

I'm no expert on hardware and video signals and input lag so I have no idea if this will actually help you achieve your goal or not, but it does produce the effect you want.


 
Originally posted by WhiteYoshiEgg
This might do the trick (to be inserted with uberASMTool):


I'm no expert on hardware and video signals and input lag so I have no idea if this will actually help you achieve your goal or not, but it does produce the effect you want.


I made a tiny utility hack with this ASM to aid in measuring input lag: Measure Input Lag.bps The sprites on screen are just to ensure there's a typical processing load on the emulator.

I'd hope to have a detailed post with how to use it properly, with an included readme.

Thank you so much. The only inconsequential note about the ASM is the way the buttons are read; e.g. A or B, X or Y, without differentiation. I understand the 16 data clock cycles used to ID button presses, so I suppose it's a bit more complicated to handle 2 bytes of data at a time? No idea but I wish I knew. The ASM works as intended for its use though, just got me curious.
Glad it's working! (disclaimer again that I don't know if there's any flaws inherent in the color-changing code that interferes with detecting input lag or not, but you're probably a better judge of that.)

Originally posted by PastaNoSauce
The only inconsequential note about the ASM is the way the buttons are read; e.g. A or B, X or Y, without differentiation. I understand the 16 data clock cycles used to ID button presses, so I suppose it's a bit more complicated to handle 2 bytes of data at a time? No idea but I wish I knew. The ASM works as intended for its use though, just got me curious.

I'm using SMW's own RAM addresses to detect button presses (see $15 through $18 in the RAM Map), which are a step away from the way the hardware does it, and which apparently don't distinguish between X/Y and A/B that much. That's about all I know. /shrug


 
Originally posted by WhiteYoshiEgg
I'm using SMW's own RAM addresses to detect button presses (see $15 through $18 in the RAM Map), which are a step away from the way the hardware does it, and which apparently don't distinguish between X/Y and A/B that much. That's about all I know. /shrug


Ok I see the issue, but I don't know how to write it in ASM.

For a B press,

$7E0015 = 10000000 AND $7E0017 = 00000000

For a Y press,

$7E0015 = 01000000 AND $7E0017 = 00000000

Is there a simple way to express this?

Thanks again! This is my first time diving into this and using these tools - but I want to give back to the community in some way.
That's actually true! I fixed that really quick by adding a "bits you don't want to be set in $17" column to the table. It's pretty dirty but seems to work.

Code
.loop
	LDA .table,x
	STA $00
	STZ $01
	LDA ($00)
	AND .table+1,x
	BEQ .continue
	LDA $17
	AND .table+2,x
	BNE .continue
	REP #$20
	LDA .table+3,x
	STA $0701
	SEP #$20
	BRA .break
.continue
	DEX #5
	BPL .loop
.break
	PLB
	RTL

.table
	db $15,%00001000,%00000000 : dw $001F	; UP: red
	db $15,%00000100,%00000000 : dw $7F80	; DOWN: blue
	db $15,%00000010,%00000000 : dw $03E0	; LEFT: green
	db $15,%00000001,%00000000 : dw $03FF	; RIGHT: yellow
	db $17,%10000000,%00000000 : dw $021F	; A: orange
	db $15,%10000000,%10000000 : dw $4010	; B: purple
	db $17,%01000000,%00000000 : dw $621F	; X: pink
	db $15,%01000000,%01000000 : dw $7FE0	; Y: cyan
	db $15,%00100000,%00000000 : dw $0177	; SELECT: brown
	db $15,%00010000,%00000000 : dw $7FFF	; START: white
..end



 
Originally posted by WhiteYoshiEgg
That's actually true! I fixed that really quick by adding a "bits you don't want to be set in $17" column to the table. It's pretty dirty but seems to work.


Great! However when applied the background is green without a button press, and flashes to black on a button press.

I added the code from main in the first ASM code, so the patch looks like this:

Code
main:

	REP #$20
	STZ $0701
	SEP #$20

	PHB : PHK : PLB
	LDX.b #.table_end-.table-4
.loop
	LDA .table,x
	STA $00
	STZ $01
	LDA ($00)
	AND .table+1,x
	BEQ .continue
	LDA $17
	AND .table+2,x
	BNE .continue
	REP #$20
	LDA .table+3,x
	STA $0701
	SEP #$20
	BRA .break
.continue
	DEX #5
	BPL .loop
.break
	PLB
	RTL

.table
	db $15,%00001000,%00000000 : dw $001F	; UP: red
	db $15,%00000100,%00000000 : dw $7F80	; DOWN: blue
	db $15,%00000010,%00000000 : dw $03E0	; LEFT: green
	db $15,%00000001,%00000000 : dw $03FF	; RIGHT: yellow
	db $17,%10000000,%00000000 : dw $021F	; A: orange
	db $15,%10000000,%10000000 : dw $4010	; B: purple
	db $17,%01000000,%00000000 : dw $621F	; X: pink
	db $15,%01000000,%01000000 : dw $7FE0	; Y: cyan
	db $15,%00100000,%00000000 : dw $0177	; SELECT: brown
	db $15,%00010000,%00000000 : dw $7FFF	; START: white
..end


Can you spot what's happened?
Ah right, looks like I didn't copy the start of the code by accident which also had a small change. Here's the entire thing.

Code
main:
	REP #$20
	STZ $0701
	SEP #$20

	PHB : PHK : PLB
	LDX.b #.table_end-.table-5
.loop
	LDA .table,x
	STA $00
	STZ $01
	LDA ($00)
	AND .table+1,x
	BEQ .continue
	LDA $17
	AND .table+2,x
	BNE .continue
	REP #$20
	LDA .table+3,x
	STA $0701
	SEP #$20
	BRA .break
.continue
	DEX #5
	BPL .loop
.break
	PLB
	RTL

.table
	db $15,%00001000,%00000000 : dw $001F	; UP: red
	db $15,%00000100,%00000000 : dw $7F80	; DOWN: blue
	db $15,%00000010,%00000000 : dw $03E0	; LEFT: green
	db $15,%00000001,%00000000 : dw $03FF	; RIGHT: yellow
	db $17,%10000000,%00000000 : dw $021F	; A: orange
	db $15,%10000000,%10000000 : dw $4010	; B: purple
	db $17,%01000000,%00000000 : dw $621F	; X: pink
	db $15,%01000000,%01000000 : dw $7FE0	; Y: cyan
	db $15,%00100000,%00000000 : dw $0177	; SELECT: brown
	db $15,%00010000,%00000000 : dw $7FFF	; START: white
..end



 
Originally posted by WhiteYoshiEgg
Ah right, looks like I didn't copy the start of the code by accident which also had a small change. Here's the entire thing.


Nice!

If you see an obvious way to set the background color when no button is pressed (it's always black), that would a 'so low priority it can be ignored' addition. I attempted to add a table value with all 0's (no buttons pressed) and the desired color, which of course didn't work - which really just comes back to me being grateful for your code capabilities here. #smw{:TUP:}
Replace STZ $0701 with LDA #$xxxx : STA $0701</kbd>.
Unexpected end tag (</kbd>) at 70, expected </code>
Tag (code) was not closed.