privatekey

by asmagicianmaks

Game: SMW

Description:

if !sa1
	!SprSize = $16
	!SpriteID	= $E0
	!SpriteHijack	= $6003
else
	!SprSize = $0C
	!SpriteID	= $D5
	!SpriteHijack	= $0FBE+($69*2)	;$1090
endif
macro define_sprite_table(name, addr, addr_sa1)
	if !sa1 == 0
		!<name> = <addr>
	else
		!<name> = <addr_sa1>
	endif
endmacro
%define_sprite_table("7FAB10",$7FAB10,$6040)
%define_sprite_table("7FAB1C",$7FAB1C,$6056)
%define_sprite_table("7FAB28",$7FAB28,$6057)
%define_sprite_table("7FAB34",$7FAB34,$606D)
%define_sprite_table("7FAB9E",$7FAB9E,$6083)
%define_sprite_table("7FAB40",$7FAB40,$6099)
%define_sprite_table("7FAB4C",$7FAB4C,$60AF)
%define_sprite_table("7FAB58",$7FAB58,$60C5)
%define_sprite_table("7FAB64",$7FAB64,$60DB)
%define_sprite_table("9E", $9E, $3200)
%define_sprite_table("AA", $AA, $9E)
%define_sprite_table("B6", $B6, $B6)
%define_sprite_table("C2", $C2, $D8)
%define_sprite_table("D8", $D8, $3216)
%define_sprite_table("E4", $E4, $322C)
%define_sprite_table("14C8", $14C8, $3242)
%define_sprite_table("14D4", $14D4, $3258)
%define_sprite_table("14E0", $14E0, $326E)
%define_sprite_table("14EC", $14EC, $74C8)
%define_sprite_table("14F8", $14F8, $74DE)
%define_sprite_table("1504", $1504, $74F4)
%define_sprite_table("1510", $1510, $750A)
%define_sprite_table("151C", $151C, $3284)
%define_sprite_table("1528", $1528, $329A)
%define_sprite_table("1534", $1534, $32B0)
%define_sprite_table("1540", $1540, $32C6)
%define_sprite_table("154C", $154C, $32DC)
%define_sprite_table("1558", $1558, $32F2)
%define_sprite_table("1564", $1564, $3308)
%define_sprite_table("1570", $1570, $331E)
%define_sprite_table("157C", $157C, $3334)
%define_sprite_table("1588", $1588, $334A)
%define_sprite_table("1594", $1594, $3360)
%define_sprite_table("15A0", $15A0, $3376)
%define_sprite_table("15AC", $15AC, $338C)
%define_sprite_table("15B8", $15B8, $7520)
%define_sprite_table("15C4", $15C4, $7536)
%define_sprite_table("15D0", $15D0, $754C)
%define_sprite_table("15DC", $15DC, $7562)
%define_sprite_table("15EA", $15EA, $33A2)
%define_sprite_table("15F6", $15F6, $33B8)
%define_sprite_table("1602", $1602, $33CE)
%define_sprite_table("160E", $160E, $33E4)
%define_sprite_table("161A", $161A, $7578)
%define_sprite_table("1626", $1626, $758E)
%define_sprite_table("1632", $1632, $75A4)
%define_sprite_table("163E", $163E, $33FA)
%define_sprite_table("164A", $164A, $75BA)
%define_sprite_table("1656", $1656, $75D0)
%define_sprite_table("1662", $1662, $75EA)
%define_sprite_table("166E", $166E, $7600)
%define_sprite_table("167A", $167A, $7616)
%define_sprite_table("1686", $1686, $762C)
%define_sprite_table("186C", $186C, $7642)
%define_sprite_table("187B", $187B, $3410)
%define_sprite_table("190F", $190F, $7658)
%define_sprite_table("1FD6", $1FD6, $766E)
%define_sprite_table("1FE2", $1FE2, $7FD6)
%define_sprite_table("1938", $1938, $418A00)

CarlModule:
	LDY $0100|!addr
	CPY #$12
	BNE +
	LDA #$00
	STA !carl_initialized
+
	CPY #$14
	BNE ++
	LDA !carl_initialized
	BNE ++
	LDY.b #!SprSize-1
-
	LDA.w !14C8,y
	CMP.b #$08
	BEQ +
	DEY
	BPL -
++
	RTL
+
	LDX.b #$00
-
	LDA !14C8,x
	BEQ +
	INX
CPX.b #!SprSize
	BNE -
	RTL
+
	LDA #$01
	STA !carl_initialized
	REP #$20
	LDA.w #((SpriteCode&$FF)<<8)+$5C
	STA !SpriteHijack
	LDA.w #SpriteCode>>8
	STA !SpriteHijack+2
	SEP #$20
	LDA #!SpriteID
	STA !9E,x
	JSL $07F722|!bank
	LDA #$00	;Prevent bugs from being in state 8 for 1 frame before real init takes place
	STA !1656,x
	LDA #$80
	STA !1662,x
	LDA #$70
	STA !166E,x
	AND #$0F
	STA !15F6,x
	LDA #$A7
	STA !167A,x
	LDA #$A9
	STA !1686,x
	LDA #$42
	STA !190F,x
	LDA #$00
	STA !7FAB9E,x
	LDA #$08
	STA !14C8,x
	LDA #$01
	STA !7FAB28,x
LDA #$00
STA !7FAB34,x
	LDA.w !E4,y
	STA !E4,x
	LDA !14E0,y
	STA !14E0,x
	LDA.w !D8,y
	SEC
	SBC #$40
	STA !D8,x
	LDA !14D4,y
	SBC #$00
	STA !14D4,x
	LDA #$80
	STA $2100
	REP #$10
	LDA #$80
	STA $2115
	LDX.w #$6C20
	STX $2116
	LDX #$1801
	STX $4320
	LDX.w #PhantoGFX
	STX $4322
	LDA.b #PhantoGFX>>16
	STA $4324
	LDY #$0040
	STY $4325
	LDA #$04
	STA $420B
	LDX.w #$6D20
	STX $2116
	LDX.w #PhantoGFX+$40
	STX $4322
	STY $4325
	STA $420B
	SEP #$10
	LDA $0DAE|!addr
	STA $2100
	RTL

PhantoGFX:
db $00,$07,$07,$1B,$1F,$27,$3F,$47,$3F,$47,$5F,$AF,$43,$BF,$61,$9F
db $00,$00,$02,$00,$06,$00,$06,$00,$06,$00,$0E,$00,$02,$00,$00,$00
db $00,$C0,$C0,$70,$F0,$38,$F8,$1C,$F8,$1C,$F4,$1E,$84,$7E,$0C,$FE
db $00,$00,$80,$00,$C0,$00,$E0,$00,$E0,$00,$E0,$00,$80,$00,$00,$00
db $7D,$8F,$6F,$9F,$63,$9F,$30,$5F,$30,$4F,$18,$2F,$0F,$17,$00,$0F
db $0C,$00,$0E,$00,$02,$00,$10,$00,$00,$00,$08,$00,$06,$00,$00,$00
db $7C,$9E,$EC,$1E,$8C,$7E,$18,$FC,$18,$FC,$30,$D8,$E0,$30,$00,$E0
db $60,$00,$E0,$00,$80,$00,$00,$00,$00,$00,$20,$00,$C0,$00,$00,$00


SpriteCode:
	LDA !7FAB28,x
	CMP #$08
	BEQ .main
	CMP #$01
	BEQ .init
	;PHK
	;PEA.w .end-1
	;PEA.w $80CA-1
	;JML $018133|!bank
.init
	PHB
	PHK
	PLB
	LDA #$08
	STA !7FAB28,x
	LDA !7FAB9E,x
	TAY
	LDA.w Sprite1656Vals,y
	STA !1656,x
	LDA.w Sprite1662Vals,y
	STA !1662,x
	LDA.w Sprite166EVals,y
	STA !166E,x
	AND #$0F
	STA !15F6,x
	LDA.w Sprite167AVals,y
	STA !167A,x
	LDA.w Sprite1686Vals,y
	STA !1686,x
	LDA.w Sprite190FVals,y
	STA !190F,x
	LDA.w InitPtr,y
	STA $00
	LDA.w InitPtr+1,y
	BRA +
.main
	PHB
	PHK
	PLB
	LDA !7FAB9E,x
	TAY
	LDA.w MainPtr,y
	STA $00
	LDA.w MainPtr+1,y
+
	STA $01
	PEA.w (+)-1
	JMP (!dp)
+
	PLB
.end
	JML $018762|!bank

;Tweaker Bytes
Sprite1656Vals:
db $00
Sprite1662Vals:
db $00
Sprite166EVals:
db $F8
Sprite167AVals:
db $05
Sprite1686Vals:
db $99
Sprite190FVals:
db $04

;Sprite Pointers:
InitPtr:
dw Phanto_Init
MainPtr:
dw Phanto_Main

;Shared Subroutines
SubHorzPos:
	LDY #$00
	LDA $94
	SEC
	SBC !E4,x
	STA $0E
	LDA $95
	SBC !14E0,x
	STA $0F
	BPL +
	INY
+
	RTS

SubVertPos:
	LDY #$00
	LDA $96
	SEC
	SBC !D8,x
	STA $0F
	LDA $97
	SBC !14D4,x
	BPL +
	INY
+
	RTS

GetDrawInfo:
	STZ !186C,x
	LDA !14E0,x
	XBA
	LDA !E4,x
	REP #$20
	SEC : SBC $1A
	STA $00
	CLC
	ADC.w #$0040
	CMP.w #$0180
	SEP #$20
	LDA $01
	BEQ .on_screen_x
	LDA #$01
.on_screen_x
	STA !15A0,x
	; in sa-1, this isn't #$000
	; this actually doesn't matter
	; because we change A and B to different stuff
	TDC
	ROL A
	STA !15C4,x
	BNE .invalid

	LDA !14D4,x
	XBA
	LDA !190F,x
	AND #$20
	BEQ .check_once
.check_twice
	LDA !D8,x
	REP #$21
	ADC.w #$0020
	SEC : SBC $1C
	SEP #$20
	LDA !14D4,x
	XBA
	BEQ .check_once
	LDA #$02
.check_once
	STA !186C,x
	LDA !D8,x
	REP #$21
	ADC.w #$0010
	SEC : SBC $1C
	SEP #$21
	SBC #$10
	STA $01
	XBA
	BEQ .on_screen_y
	INC !186C,x
.on_screen_y
	LDY !15EA,x
	RTS

.invalid
	PLA				; destroy the JSL
	PLA
	RTS




;;Phanto by mikeyk,yoshicookiezeus
Phanto:

!Tilemap = $C2			; The sprite tile used by Phanto.

; The horizontal acceleration of the sprite.
.X_Accel:
	db $02,$FE

; The vertical acceleration of the sprite.
.Y_Accel:
	db $02,$FE

; The maximum horizontal speed of the sprite.
.Max_X_Speed:
	db $28,$D8

; The maximum vertical speed of the sprite.
.Max_Y_Speed:
	db $18,$E8

.Init
	RTS
.Main
	JSR .Graphics
	LDA !14C8,x				;\ if sprite state not normal
	CMP #$08				; |
	BNE .Return				;/ return
	LDA $9D					;\ if sprites locked,
	BNE .Return				;/ return
	JSR .SubHasKey			;\ if Mario has a key,
	CPY #$01				; |
	BEQ .Chase				;/ go to main movement routine

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Secondary movement routine
;
; This routine is executed if Mario isn't holding a key, and will slow Phanto down
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


	JSL $01A7DC|!bank		; interact with Mario
	LDA $14					;\ only change speeds every second frame
	AND #$01				; |
	BNE .ApplySpeed			;/

	LDA !B6,x				;\ if x speed zero,
	BEQ .XSpeedZero			;/ branch
	BPL .XSpeedPositive		; if positive, branch
	INC A
	INC A
.XSpeedPositive:
	DEC A
	STA !B6,x

.XSpeedZero:
	LDA !AA,x				;\ if y speed zero,
	BEQ .YSpeedZero			;/ branch
	BPL .YSpeedPositive		; if positive, branch
	INC A
	INC A
.YSpeedPositive:
	DEC A
	STA !AA,x
.YSpeedZero:
	BRA .ApplySpeed

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Main movement routine
;
; If Mario is holding a key, this routine moves Phanto towards him, and accelerates it
; if the speed cap hasn't been hit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.Chase:
	JSL $01A7DC|!bank		; interact with Mario

	LDA $14					;\ only change speeds every fourth frame
	AND #$03				; |
	BNE .ApplySpeed			;/

	JSR SubHorzPos			;\ if max horizontal speed in the appropriate
	LDA !B6,x				; | direction achieved,
	CMP .Max_X_Speed,y		; |
	BEQ .MaxXSpeedReached	;/ don't change horizontal speed
	CLC						;\ else,
	ADC .X_Accel,y			; | accelerate in appropriate direction
	STA !B6,x				;/
.MaxXSpeedReached:
	JSR SubVertPos			;\ if max vertical speed in the appropriate
	LDA !AA,x				; | direction achieved,
	CMP .Max_Y_Speed,y		; |
	BEQ .ApplySpeed			;/ don't change vertical speed
	CLC						;\ else,
	ADC .Y_Accel,y			; | accelerate in appropriate direction
	STA !AA,x				;/
.ApplySpeed:
	JSL $018022|!bank		; apply x speed
	JSL $01801A|!bank		; apply y speed
.Return:
	RTS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SUB_HAS_KEY
;
; If Mario is holding a key, the Y register is set to 1 after this routine has been run
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.SubHasKey:
LDY #$00
LDA $15
AND #$40
BEQ +
INY
+
RTS
	PHX						; push Phanto sprite number
	LDY #$00				; clear Y register
	LDA $1470|!addr			;\ if carriying flag not set,
	BEQ ..Return			;/ no need to check for key
	LDX.b #!SprSize-1		; setup loop variable
-	LDA !9E,x				;\ if sprite currently being checked isn't key,
	CMP #$A2				; | (key = sprite # 80)
	BNE ..NextX				;/ no need to check anything else for that sprite
	LDA !14C8,x				;\ if sprite is key, check if it is being carried
	CMP #$0B				; |
	BNE ..NextX				;/ if it isn't, no more checks
	BRA ..HasKey			; if it is, get out of loop

..NextX
	DEX						; increase number of sprite to check
	BPL -					; if still sprites left to check, repeat loop
	BRA ..Return			; if not, return

..HasKey
	INY						; increase Y register to show that key is being carried
..Return
	PLX						; get Phanto sprite number back
	RTS						; and return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GENERIC GRAPHICS ROUTINE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.Graphics:
	JSR GetDrawInfo

	LDA $00					; set x position of the tile
	STA $0300|!addr,y
	LDA $01					; set y position of the tile
	STA $0301|!addr,y
	LDA.b #!Tilemap
	STA $0302|!addr,y

	LDA !15F6,x				; get sprite palette info
	ORA $64					; add in the priority bits from the level settings
	STA $0303|!addr,y		; set properties

	LDY #$02				; the tiles drawn were 16x16
	LDA #$00				; one tile was drawn
	JSL $01B7B3|!bank		; finish OAM write
	RTS
back to listings