Language…
14 users online:  AmperSam,  Ayami, bucketofwetsocks, Dispace,  Donut, Green, Hayashi Neru, JezJitzu, pnaha, ShadowMistressYuko, signature_steve, Sweetdude, Tomi P, Znes.609 - Guests: 251 - Bots: 284
Users: 64,795 (2,377 active)
Latest user: mathew

Proximity wraparound fix by GreenHammerBro

File Name: Proximity wraparound fix
Submitted: 06-12-2015, 20:06:39 by SantaBro
Authors: SantaBro
Tool: Asar
Requires Free Space: Yes
Bug Fix: Yes
Featured: No
Description: This patch fixes various sprites using the horizontal and vertical proximity check that wraps around the boarder of the screen. It includes:

-Thwomps
-falling spike
-yoshi egg
-Chargin Chuck
-Splittin Chuck
-Bouncin Chuck
-Whistlin Chuck
-Rip van fish
Falling spike onscreen insta-kills the game.

Also, the code can be improved quite a bit. For one, macros. They don't really help the byte count or anything, but when you have tons of similiar code snippets, macro should be the first thing that comes to mind.

Code
macro check(range)
	REP #$21 ;16bit A and CLC in one.
	LDA !ScratchRam+2
	ADC.w #<range>
	CMP.w #<range>*$2
	SEP #$20
	RTL
endmacro

YoshiEgg_sub_range:
	JSL SubHorizPos16bit	;why even JSL?
	%check($20)
Chuck:
	JSL SubHorizPos16bit_2
	%check($30)


Thwompfix_range2 is the only one where it's not exactly 2 times as much and I'm honestly temted to belive that just a typo.

Also, speaking of !ScratchRam, I wouldn't use the term "freeRAM" because people would probably belive that the patch, for some reason, needs 4 bytes of actual freeRAM, this however doesn't. It just uses scratch RAM $00-$03 which is perfectly normal for any ASM code. You don't care what happens to these addresses after your code is done, unlike most freeRAM usages, where it has to remain untouched by any other codes.

Second is the routines. I'm honestly not sure why some sprites require the current position and others the next but whatever.
The fact that you have the same routine twice with only one address difference also really bothers me.
Could be done like this (untested)

Code
SubHorizPos16Bit: ; input: either #$D1 or #$94 in Y
			; output: Y=1 if mario right to the srite, A=absolute distance

	LDA !SprTbl_14E0,x
	XBA
	LDA !SprTbl_E4,x

	REP #$20
	PHA		;preserve spritex
	LDA !Base1,y	;$00,y = either $D1 or $94 (sa-1)
	STA $00		;mariox in $00
	LDY #$00	;didn't check your hijacks, but is this even needed?
	PLA		;restore sprite x
	
	SEC
	SBC $00		; A = spritex - mariox
	BPL .skipinvert	; branch if pos = spritex > mariox = mario left of sprite
	INY		; set Y=1
	EOR #$FFFF	;\ A = -A = mariox - spritex
	INC		;/
.skipinvert
	STA $02		; store distance
	RTS


If you now combine this (untested) routine with the macro above, you could write it like this:

Code
macro check(range, addr)
	LDY #<addr>
	JSR SubHorizPos16bit
	CLC			;since after routine we're still 16bit mode
	LDA $02
	ADC.w #<range>
	CMP.w #<range>*$2
	SEP #$20
	RTL
endmacro

YoshiEgg_sub_range:
	%check($20,$D1)
Chuck:
	%check($30,$94)


SubVertPos can probably be done in a similiar way, except that you don't need to bother with Y as the input address.
Anime statistic on MyAnimeList:
400 animes completed ✓
6000 episodes completed ✓
100 Days completed ✓
... what even am I doing with my life?