;Horizontal Screen Wrap
;connects the top and bottom of the screen, meaning that if you fall down a hole, you
;will see mario fall from the top of the screen, and if a sprite falls down, it will also
;appear at the top of the screen. Make sure whatever level you use this on has no vertical
;scrolling enabled, and that mario starts on the lower half of the screen
;This is the same as the patch, but it's in a sprite format so it's easier to add toonly specific levels
;Also fixes a bug noticed by some people where mario would act kinda choppy when big
;insert as a generator
;erm... I don't think it matters which sprite tool you use to assemble it but I used Romi's when I tested it
;so I know it will work with that
;made by: HuFlungDu
;No credit neccesary
;Feel free to PM me if you have any problems

dcb "INIT"
RTL
dcb "MAIN"
JSR Mario	;check for mario
JSR Sprite	;check for sprites
RTL

Sprite:
LDY #$00	;innitiate the accumulator
loop:
LDA $14C8,y	;\check if the sprite is dead
CMP #$02	;|
BEQ endS	;/
LDA $14D4,y	;\Check which (vertical) subscreen the sprite is on
CMP #$01	;|
BNE UpS		;/
LDA $D8,y	;\Check the sprites position on the subscreen
CMP #$A0	;|
BCC UpS		;/
LDA #$00	;\Move to subscreen 0
STA $14D4,y	;/
UpS:
LDA $14D4,y	;\Check which (vertical) subscreen the sprite is on
BNE endS	;|
LDA $D8,y	;\Check the sprites position on the subscreen
CMP #$A0	;|
BCS endS	;/
LDA #$01	;\Move to subscreen 1
STA $14D4,y	;/
endS:
INY			;\increase the Accumulator
CPY #$0C	;|and see if it's checked all sprites
BCC loop	;/ if not, check the next one
RTS			;return

Mario:
LDA $0100	;\make sure the level is going
CMP #$14	;|
BNE endM	;/
LDA $13E0	;\don't do it if mario is dead (this checks his pose)
CMP #$3E	;|
BEQ endM	;/
LDA $D4		;\Check which (vertical) subscreen mario is on
CMP #$01	;|
BNE UpM		;/
LDA $D3		;\Check mario's position on the subscreen
CMP #$A0	;|
BCC UpM		;/
LDA #$00	;\move to subscreen 0
STA $97		;/
UpM:
LDA $D4		;\Check which (vertical) subscreen mario is on
BNE endM	;/
LDA $D3		;\Check mario's position on the subscreen
CMP #$A0	;|
BCS endM	;/
LDA #$01	;\move to screen 0
STA $97		;/
endM:
RTS			;return

