Language…
12 users online: Ahrion, Anas, AntonioDosGames, chester_fields, GrenCarret, jhonz22, luigi doll, marathonx, matthew27567, Phyll, Somebody for sure, Steven - Guests: 141 - Bots: 190
Users: 58,131 (2,461 active)
Latest user: TuNieViel

Water Physics

I was trying to replicate the water+ground movement inside a block. I'd almost assume there's a flag I could set if I didn't want the bubbles/splashes/swim. So I started working on this:

Code
main:
	LDA #!Magnitude
	STA $01
	LDA $7B
	STA $02
	STA $00
	JSL decrease_magnitude
	STA $7B
	RTL

; $00/LDA = in, $01 = Mag dec, $02 = min mag, $03 = scratch
decrease_magnitude:
	BPL Posi ; -->
	JSR abs
	CMP $01
	BMI Zero_mag2 ; -->
	LDA $00
	CLC
	ADC $01
	BRA Ret ; -->
Posi:
	JSR abs
	CMP $01
	BMI Zero_mag ; -->
	CLC
	SBC $01
Ret:
	RTL
Zero_mag2:
	LDA $02
	EOR #$FF
	INC
	RTL
Zero_mag:
	LDA $02
	RTL

abs:
	LSR 7
	STA $03
	EOR $00
	SBC $03
	RTS


It's super broken and I'm being blind as to why. I'm reduced to nigh immovable going left but double speed going right >__>
Anyone notice the problem?

EDIT: Think I noticed it. SMW RAM for $7B is not a 2's compliment x-speed.... everything else looks solid though right?
FIXED: Obviously I was tired with that edit. Water doesn't work the way I thought it did and abs was broken...

Code
main:
	LDA $7B
	STA $00
	JSL decrease_magnitude
	STA $7B
	RTL

!water_speed = $08
!Lwater_speed = $F8
; $00/LDA = in
decrease_magnitude:
	JSR abs
	CMP #!water_speed
	BMI ignore ; -->
	LDA $00
	BMI left ; -->
right:
	LDA #!water_speed
	DEC
	RTS
left:
	LDA #!Lwater_speed
	INC
	RTS ; -->
ignore:
	LDA $00
	RTS

; LDA = in
abs:
	BPL posi
	EOR #$FF
	clc
	adc #1
posi:
	RTS