;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Super Mario World Fix-All Patch;;
;;Version 1.0			 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;The Super Mario World Perfection Patch is an xkas patch that:
;	a) fixes several of the little glitches and bugs that were left in SMW upon its 1990 release
;	b) installs hacks that optimize and improve the ROM for better editing
;	c) allows for quick and easy editing of some of the game's most commonly edited offsets

header
lorom

org $049291 : db $4C, $AF, $92 ; REMOVE THIS LINE BEFORE FINAL RELEASE: ACTIVATES ALL PATHS ON OVERWORLD was B1 D1 C1

org $029C94 ; remaps the Spin Jump Star tile
db $6C		;

org $048E3A ;
BRA +		; Fixes an issue when using AMK
NOP #11		;
+			;

org $00DA58 ;Fixes Tides in Stone Sea Sanctuary and Frostblow Freezer
db $80		;
org $00DA6F ;same
db $80		;

org $05B93F : dw $0680  ;Another title screen fix

org $0084E5 : dl $04819F ; Overworld pause fix

org $02CD51 ;Fixes the bottoms of the Flattened Big Switches
db $35,$35,$75,$75		;

org $00A514
db $7F

org $00A51F
db $7E	    ; the previous two bytes fix the overworld's animated colors.

;org $0096C7 ; title music
;db $15	    ; track 15

org $00AF35 ; Disables fadeout when a level is beaten. Doesn't apply to bosses.
db $4C,$91,$B0,$EA 

org $00B091 ; Disables fadeout when a level is beaten. Doesn't apply to bosses.
db $AD,$C6,$13,$F0,$FA,$A5,$13,$29,$03,$4C,$39,$AF

org $05CC16 ; Eliminates Course Clear Scorecard. 
NOP #80 ; 

org $05CC42 ; Hide Timer/Score Tally in Scorecard 
NOP #31 ;

org $009C82	; Disables title screen movement.  Title screen will not loop.
db $EA,$A9,$00

org $01C510 ; Prevents items from being sent to the item box. 
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00

org $00F619 ; Prevents screen from scrolling when Mario loses a life. 
db $12,$14

org $029D4B ; repoints smiley coin to normal coin
db $E8

org $019C0D
db $67,$69,$88,$88	;flopping fish remap

org $02878E ; On/Off switch's bounce YXPPCCCT format.
db $06      ; Palette B, Page 1

org $0291F6 ; On/Off switch's bounce tile.
db $CA

org $05DAE6	; Disables Level 24 (Chocolate Island 2)'s gimmick. Useful for when
db $80		; OW transferring when porting ROMs goes wrong.

org $00CBA3	; Fixes a misplaced tile on the Keyhole's Iris In Effect
db $49

org $00913F	; Fixes S in Mario/Luigi Start!
db $34

org $00CB0C	; HDMA Flicker Fix
db $0C

org $009170	; Also fixes S in Mario/Luigi Start!
db $F4
db $80

org $01C34C	; Prevents Fire Flower from flipping back and forth.
db $00

org $01AA0E	; Prevents various sprites' stun timers from being reset when kicked.
db $03

org $05DA19	; Disables all No Yoshi intros, saving you the three seconds of
db $4C,$D7,$DA	; having to manually do it yourself.

org $028114	;Bob-omb's explosion GFX tile
db $EF		;3C

org $02811E	;Will Change GFX page used by explosion tile
db $18		;38

org $02878A	;Bounce Block Note Block Palette/GFX (YXPPCCCT)
db $02		;03

org $029347	; Fixes a glitch where placing a coin above a ? block or
db $20,$E2,$FF	; turn block will cause the coin to leave behind an invisible
		; solid block if the block below is hit.

org $04F754	; Disables lightning in Valley of Bowser submap. (Flashing)
db $80		; In SMWCP2, this submap is used for World 5.

org $04EB42	; Makes Forest of Illusion submap reveal its event tiles at the same
db $80		; speed as other tilemaps. (World 6 in SMWCP2).

org $0291F2	;Block Bounce Note Block sprite tiles
db $0A		;6B

org $02A2DF	;Hammer Tilemap
db $20,$22,$22,$20,$20,$22,$22,$20
		;08 6D 6D 08 08 6D 6D 08

org $02A2E7	;Hammer YXPPCCCT
db $46,$46,$06,$06,$86,$86,$C6,$C6
		;47 47 07 07 87 87 C7 C7

org $00913F	;x133F, fixes the "S" in "Mario/Luigi Start"
db $34		;30

org $009170	;x1370, fixes the "S" in "Mario/Luigi Start"
db $F4		;F0


org $009D30	;x1F30, title screen "Erase Game" palette darken fix
db $EA,$EA,$EA,$EA,$EA
		;8D 01 07 84 40

org $00A439	;x2639, fixes the Koopa Paratroopa wing glitch
db $80		;F0

org $00AF4C	;x314C, Fade Fix
db $FE,$00,$A9,$01
		;EE 00 A9 07

org $00AF6A	;x316A, Fade Fix
db $C9,$3E,$00,$F0,$05,$C9,$1E,$00,$D0,$04,$38,$E9,$10,$00,$AA,$10,$D3,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA,$EA

org $00CBA3	;x4DA3, fixes a misplaced tile on the keyhole "iris in" effect
db $49		;4B

org $00D26A	;x546A, Piranha Plant Fix #2 (prevents Mario from being hurt while exiting a Piranha Plant's pipe)
db $20,$04,$FA
		;9C F9 13

org $00FA04	;x7C00, Piranha Plant Fix #2 (prevents Mario from being hurt while exiting a Piranha Plant's pipe)
db $9C,$F9,$13,$AD,$97,$14,$D0,$03,$EE,$97,$14,$60

org $018E8D	;x908D, Piranha Plant Fix #1 (restores Classic Piranha Plants)
db $20,$C0,$FF,$EA,$EA,$EA,$EA,$EA,$EA,$EA
   ;$B9 $0B $03 $29 $F1 $09 $0B $99 $0B $03

org $01FFC0	;x101C0, Piranha Plant Fix #1 (restores Classic Piranha Plants)
db $B5,$9E,$C9,$1A,$F0,$0B,$B9,$0B,$03,$29,$F1,$09,$0B,$99,$0B,$03,$60,$B9,$07,$03,$29,$F1,$09,$0B,$99,$07,$03,$60

org $019BC1	;x9DC1, changes the blank tiles used by Jumpin' Piranha Plant from SP2 to SP1
db $69,$69,$C4,$C4,$69,$69
		;83 83 C4 C4 83 83 

org $019C25	;x9E25, changes the blank tiles used by Springboard from SP2 to SP1
db $69,$69
		;83 83

;org $01CFCD	;xD1CD, Morton/Ludwig/Roy HP
;db $05		;03

org $01DEE3	;xE0E3, changes the blank tiles used by Bonus Roulette from SP2 to SP1
db $58,$59,$69,$69,$48,$49,$58,$59,$69,$69,$48,$49,$34,$35,$69,$69,$24,$25,$34,$35,$69,$69,$24,$25,$36,$37,$69,$69,$26,$27,$36,$37,$69,$69,$26,$27
		;58 59 83 83 48 49 58 59 83 83 48 49 34 35 83 83 24 25 34 35 83 83 24 25 36 37 83 83 26 27 36 37 83 83 26 27

;org $01E733	;xE933, changes the tile used by a squished Goomba
;db $38		;C7

org $01FFD7	;x101D7, makes Classic Piranha Plants use the first graphics page
db $0A		;0B

org $01FFCC	;x101CC, makes Upside-Down Piranha Plants use the first graphics page
db $0A		;0B

;org $0288B0	;x10AB0, sprite that comes out of Block 127/128
;db $85		;04

;org $0288C1	;x10AC1, sprite that comes out of Block 127/128 when Yoshi is present
;db $85		;04

;org $0291F7	;x113F7, Turn Block Bounce Sprite
;db $40		;40

org $02AC18	;x12E18, fixes the glitch that occurs when a variable/custom sprite is carried from one level to another
db $80		;30

org $02AD4D	;x12F4D, changes the blank tile used by 10-Point Score from SP2 to SP1
db $69,$69,$69,$69
		;83 83 83 83

org $02CAFA	;x14CFA, makes Chargin' Chuck's arm use the correct palette
db $4B,$0B
		;47 07

org $02FDB8	;x17FB8, Death Swooper tilemap fix
db $C0		;EB

;org $0381A2	;x183A2, Big Boo Boss HP
;db $05		;03

;org $03CE1A	;x1D01A, Lemmy/Wendy HP
;db $05		;03

;org $03CED4	;x1D0D4, how many HP can Lemmy/Wendy lose before other sprites in the room vanish
;db $05		;03

org $03CFAF	;x1D1AF, fixes Wendy's bow
db $08		;06

org $03CFB5	;x1D1B5, fixes Wendy's bow
db $08		;02

org $03D1D7	;x1D3D7, fixes Wendy's bow
db $1F,$1E	;1E 1F

org $03D1DD	;x1D3DD, fixes Wendy's bow
db $1E,$1F	;1F 1E

org $048E2E	;x2102E, allows Overworld music to play properly after a boss is defeated
db $80		;F0

org $0584E1	;x286E1, music played during SMW Koopaling Boss Battles
db $05		;05

;org $07F27B	;x3F47B, makes Goombas die when jumped on
;db $30		;10

;org $07F27C	;x3F47C, makes Winged Goombas "die" when jumped on
;db $30		;10

org $07F47C	;x3F67C, makes Flying Red Coins immune to fireballs
db $38		;28

;;;;;;;;;;;;;;MESSAGE BOX FIX;;;;;;;;;;;;;;

org $05B129

db $EA,$EA,$EA

org $05B296

db $0C


;;;;;;;;;LAYER PRIORITY STUFF;;;;;;;;;;;;;;;


org $0584BE		;\ Enable Priority for Level Mode 07 & 08
db $20,$20		;/

org $0584C1		;\ Enable Priority for Level Mode 0A
db $20			;/

org $0584C3		;\ Enable Priority for Level Mode 0C, 0D & 0E
db $20,$20,$20		;/

org $0584C8		;\ Enable Priority for Level Mode 11
db $20			;/

org $0584D5		;\ Enable Priority for Level Mode 1E & 1F
db $20,$20		;/

;;;;;;;KOOPA REMAP;;;;;;;;;;;;;;;;;;;;;;;;;;;;

org $019B8C	; Shelless koopa tilemap (Fourth byte unused?)
db $E0,$E2,$E2,$CE,$E4,$86,$4E

org $019B93	; Blue shelless koopa tilemap (Fourth byte unused?)
db $E0,$E2,$E2,$CE,$E4,$E0,$E0


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Magikoopa Palette Correction Patch ;;
;; by andy_k_250		      ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The lightest blue color in Magikoopa's	  ;;
;; fade-in/fade-out palette table was		  ;;
;; inverted in the original game for some reason. ;;
;; This patch corrects that problem.		  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

org $03B90C	;x1BB0C
db $00,$28	;92 7E

org $03B91C	;x1BB1C
db $40,$34	;2F 72

org $03B92C	;x1BB2C
db $A3,$40	;CC 65

org $03B93C	;x1BB3C
db $06,$4D	;69 59

org $03B94C	;x1BB4C
db $69,$59	;06 4D

org $03B95C	;x1BB5C
db $CC,$65	;A3 40

org $03B96C	;x1BB6C
db $2F,$72	;40 34

org $03B97C	;x1BB7C
db $92,$7E	;00 28


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Sprite Block Fix - Moves all Sprite Blocks up by 1 pixel
;
;All I've done is add Sprites 4C, 59 and 5A,
;the Exploding Block Sprite and Turn Block Bridges,
;to this patch. This is still Edit1754's work.
;                                           -Milk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

org $018215				;Sprite 4C, Exploding Block w/ Fish/Goomba.Koopa
		dw Fix
org $01822F				;Sprite 59, Turn Block Bridge (H+V)
		dw BlkSprInit
org $018231				;Sprite 5A, Turn Block Bridge (H only)
		dw BlkSprInit
org $0182EF				;Sprite B9, Info Box
		dw BlkSprInit
org $01830D				;Sprite C8, Light Switch Block
		dw BlkSprInit

org $01E2B0
Fix:		JSR $83A4
		JMP BlkSprInit

org $01FFF0
BlkSprInit:	LDA.b $D8,x
		SEC
		SBC.b #$01
		STA.b $D8,x
		LDA.w $14D4,x
		SBC.b #$00
		STA.w $14D4,x
		RTS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Non-Dynamic Podoboo Patch, by imamelia
;;
;; This patch changes the way the Podoboo uses graphics.  Instead of using the
;; tiles normally used by Yoshi, it instead uses graphics from SP3 or SP4 and gets
;; them the same way any other sprite would.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; change the Podoboo's tilemap
org $019C35
db $C8,$C8,$D8,$D8,$C9,$C9,$D9,$D9,$D8,$D8,$C8,$C8,$D9,$D9,$C9,$C9
; 06 06 16 16 07 07 17 17 16 16 06 06 17 17 07 07

; change a JSR to a JMP, bypassing the dynamic GFX routine
org $01E19A
db $4C

; make the sprite use the second GFX page
org $07F431
db $34



;;;;;COUNTER BREAK Y;;;;;;;;;;;;;;;;;

ORG $A0D5
;NOP #8				;Instead of wasting 16 cycles we'll just skip those NOPs

		BRA ORLY	;2 bytes long - 3 cycles
		NOP #6		;We skipped 18 cycles meaning we saved 15 cycles :O		
ORLY:		STZ $0DBA,x	;No Yoshi color (of Player 1 and Player 2)

ORG $0491C9

		BRA YARLY	;\
		NOP		;/Saved 3 cycles
YARLY:		STZ $0DC1	;i have no idea i dont even
		STZ $13C7	;No Yoshi color
		STZ $187A	;No riding Yoshi flag

;;;;;CLASSIC FIREBALL;;;;;;;;;;;;;;;;;

org $02A129
LDA #$02    ; / Make sprite fall down...
STA $14C8,x ; \ ... or disappear in smoke (depends on its settings)
LDA #$05    ; 5 = 100. Changing it will change the amount of score you get (1=10,2=20,3=40,4=80,5=100,6=200,7=400,8=800,9=1000,A=2000,B=4000,C=8000,D=1up)
JSL $02ACEF ; Jump to the score routine handler.
NOP
NOP

;;;;;SPIKE TOP FIX;;;;;;;;;;;;;;;;;;;;

org $02BDA7
NOP #12

;;;;;1 Player Only;;;;;;;;;;;;;;
ORG $009DFA
	INC $0100
	BRA +
	
ORG $009E0B
	+
	LDX #$00	;00 = 1 player, 01 = 2 player
	
ORG $05B872
	db $FF
