We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS

Useful Code Snippets: Difference between revisions

From SnesLab
Jump to: navigation, search
(Add get acts as from map16, add find OAM slot, add erase current save file)
Line 77: Line 77:
LDA #$0080 ; deoompress ExGFX80.bin ..
LDA #$0080 ; deoompress ExGFX80.bin ..
JSL $0FF900
JSL $0FF900
</pre>
==== Get acts like from map16 number ====
by [[User:Vitor Vilela|Vitor Vilela]]
Works with SA-1.
<pre>
; $00 = map16 tile
get_act_like:
LDA $06F624
STA $02
LDA $06F625
STA $03
LDA $06F626
STA $04
REP #$30
LDA $00
AND #$3FFF
ASL
TAY
LDA [$02],y
STA $00
SEP #$30
RTS
</pre>
==== Find free OAM slot ====
by [[User:Vitor Vilela|Vitor Vilela]]
SA-1 hybrid.
<pre>
; Routine for finding a free OAM slot
; NMSTL compatible. Tested against Level ASM, Overworld ASM.
find_oam:
LDY #$FC
- LDA $02FD|!addr,y
CMP #$F0
BNE +
CPY #$3C
BEQ +
DEY
DEY
DEY
DEY
BRA -
+ RTS
</pre>
==== Erase current save file ====
by [[User:Sixtare|Sixtare]]
<pre>
Erase:
REP #$10
LDA $010A
CMP #$01
BEQ .01
BCS .02
.00
LDX #$008F
JMP .delete
.01
LDX #$011E
JMP .delete
.02
LDX #$01AD
.delete
LDY #$008F
LDA #$00
- STA $700000,x
STA $7001AD,x
DEX
DEY
BPL -
SEP #$10
RTS
</pre>
</pre>



Revision as of 01:33, 26 July 2019

Useful code snippets for the 65c816 ASM and general SNES hardware.

65c816 S-CPU

General

Wait for H-Blank

-
BIT $4212
BVS -
-
BIT $4212
BVC -

Inverse the accumulator (8-bit)

EOR #$FF
INC

Inverse the accumulator (16-bit)

EOR #$FFFF
INC

SMW Hacking

Custom block template

by Alcaro Works with SA-1.

db $42 ; or db $37
JMP MarioBelow : JMP MarioAbove : JMP MarioSide
JMP SpriteV : JMP SpriteH : JMP MarioCape : JMP MarioFireball
JMP TopCorner : JMP BodyInside : JMP HeadInside
; JMP WallFeet : JMP WallBody ; if using db $37

MarioBelow:
MarioAbove:
MarioSide:

TopCorner:
BodyInside:
HeadInside:

WallFeet:
WallBody:

SpriteV:
SpriteH:

MarioCape:
MarioFireball:
RTL

Decompress GFX File

by Vitor Vilela Works with SA-1.

; Decompress input GFX file
; Must be called from SNES CPU.
; SA-1 is automatically invoked on SA-1 Pack ROMs.

STZ $00
REP #$20
LDA #$7EAD	; destination buffer = $7EAD00
STA $01
LDA #$0080	; deoompress ExGFX80.bin ..
JSL $0FF900

Get acts like from map16 number

by Vitor Vilela Works with SA-1.

; $00 = map16 tile
get_act_like:
	LDA $06F624
	STA $02
	LDA $06F625
	STA $03
	LDA $06F626
	STA $04
	
	REP #$30
	LDA $00
	AND #$3FFF
	ASL
	TAY
	LDA [$02],y
	STA $00
	SEP #$30
	RTS

Find free OAM slot

by Vitor Vilela SA-1 hybrid.

; Routine for finding a free OAM slot
; NMSTL compatible. Tested against Level ASM, Overworld ASM.

find_oam:
	LDY #$FC
-	LDA $02FD|!addr,y
	CMP #$F0
	BNE +
	CPY #$3C
	BEQ +
	DEY
	DEY
	DEY
	DEY
	BRA -
+	RTS

Erase current save file

by Sixtare

Erase:
REP #$10
	LDA $010A
	CMP #$01
	BEQ .01
	BCS .02
.00
LDX #$008F
JMP .delete

.01
LDX #$011E
JMP .delete

.02
LDX #$01AD
	.delete
	LDY #$008F
	LDA #$00
-	STA $700000,x
	STA $7001AD,x
	DEX
	DEY
	BPL -
	SEP #$10
RTS

65c816 SA-1 CPU

Some snippets present on S-CPU section works with SA-1 CPU as well.

General

Unsigned 16 bit x 16 bit = 32 bit multiplication

by Akaginite

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 16bit * 16bit Multiplication SA-1 version
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Parameters
; $00-$01 : Multiplicand
; $02-$03 : Multiplier
; Return values
; $04-$07 : Product
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MathMul16_16:	STZ $2250
		REP #$20
		LDA $00
		STA $2251
		ASL A
		LDA $02
		STA $2253
		BCS +
		LDA.w #$0000
+		BIT $02
		BPL +
		CLC
		ADC $00
+		CLC
		ADC $2308
		STA $06
		LDA $2306
		STA $04
		SEP #$20
		RTS