; set this if you're using this as a UberASM GM14 code !gm14_uberasm = 0 ; what tile to convert stuff to !tile_to_use = $012F ; power of 2, tile is (attempted to be) placed every this many frames !delay = $02 ; whether to only replace solid tiles ; (if you turn this off, you should turn down the speed too) !onlySolid = 1 if !gm14_uberasm main: else org $008F5B autoclean JSL everyframe NOP #2 freecode everyframe: endif ;JSL $01ACF9 ;LDA $148D ;CMP #$80 ; for testing - ~1/sec is 04 ; though if we only do something on ground tiles then it may be fine as $80 ;BCS .return LDA $9D ORA $13D4 BNE .return LDA $14 AND.b #!delay-1 BNE .return ; only do shit while mario is moving ; (a futile attempt to make this a bit more fair) LDA $7B BEQ .return REP #$20 STZ $1933 ; random offset from mario X - magnitude 64-128, sign any SEP #$20 JSL $01ACF9 LDA $148D REP #$21 ; CLC too BMI .neg AND #$003F ADC #$0040 BRA + .neg AND #$003F ADC #$0040 EOR #$FFFF ;\ negate INC ;/ + ADC $94 ; player X BCS .return_sep ; if we overflowed, don't even try to write the tile AND #$FFF0 STA $9A LDA $148E ; use the high part of last RNG call REP #$21 ; CLC too BMI .neg_y AND #$007F ;ADC #$0040 BRA + .neg_y AND #$007F ;ADC #$0040 EOR #$FFFF ;\ negate INC ;/ + ADC $96 ; player Y BCS .return_sep AND #$FFF0 STA $98 if !onlySolid LDA $9A STA $00 LDA $98 STA $02 SEP #$20 JSL FindMap16TileNum XBA CMP #$01 BNE .return REP #$20 endif LDA.w #!tile_to_use JSL ChangeMap16 .return_sep SEP #$20 .return ; restore old code and return if not(!gm14_uberasm) LDX $0DB3 LDA $0F48,x endif RTL ;;;;;;;;;;;;;; ;; routines ;; ;;;;;;;;;;;;;; ChangeMap16: !Base2 = 0 !BankB = 0 !SA1 = 0 !EXLEVEL = 0 ; PIXI's ChangeMap16 routine, by Akaginite ; Slightly modified by Tattletale PHX PHP REP #$10 TAX SEP #$20 PHB PHY PHX LDY $98 STY $0E LDY $9A STY $0C SEP #$30 LDA $5B LDX $1933|!Base2 BEQ .layer1 LSR A .layer1 STA $0A LSR A BCC .horz LDA $9B LDY $99 STY $9B STA $99 .horz if !EXLEVEL BCS .verticalCheck REP #$20 LDA $98 CMP $13D7|!Base2 SEP #$20 BRA .check endif .verticalCheck LDA $99 CMP #$02 .check BCC .noEnd REP #$10 PLX PLY PLB PLP PLX RTL .noEnd LDA $9B STA $0B ASL A ADC $0B TAY REP #$20 LDA $98 AND.w #$FFF0 STA $08 AND.w #$00F0 ASL #2 ; 0000 00YY YY00 0000 XBA ; YY00 0000 0000 00YY STA $06 TXA SEP #$20 ASL A TAX LDA $0D LSR A LDA $0F AND #$01 ; 0000 000y ROL A ; 0000 00yx ASL #2 ; 0000 yx00 ORA #$20 ; 0010 yx00 CPX #$00 BEQ .noAdd ORA #$10 ; 001l yx00 .noAdd TSB $06 ; $06 : 001l yxYY LDA $9A ; X LowByte AND #$F0 ; XXXX 0000 LSR #3 ; 000X XXX0 TSB $07 ; $07 : YY0X XXX0 LSR A TSB $08 LDA $1925|!Base2 ASL A REP #$31 ADC $00BEA8|!BankB,x TAX TYA if !SA1 ADC.l $00,x TAX LDA $08 ADC.l $00,x else ADC $00,x TAX LDA $08 ADC $00,x endif TAX PLA ASL A TAY LSR A SEP #$20 if !SA1 STA $400000,x XBA STA $410000,x else STA $7E0000,x XBA STA $7F0000,x endif LSR $0A LDA $1933|!Base2 REP #$20 BCS .vert BNE .horzL2 .horzL1 LDA $1A ;\ SBC #$007F ; |$08 : Layer1X - 0x80 STA $08 ;/ LDA $1C ; $0A : Layer1Y BRA + .horzL2 LDA $1E ;\ $08 : Layer2X STA $08 ;/ LDA $20 ;\ $0A : Layer2Y - 0x80 SBC #$007F ;/ BRA + .vert BNE .vertL2 LDA $1A ;\ $08 : Layer1X STA $08 ;/ LDA $1C ;\ $0A : Layer1Y - 0x80 SBC #$0080 ;/ BRA + .vertL2 LDA $1E ;\ SBC #$0080 ; |$08 : Layer2X - 0x80 STA $08 ;/ LDA $20 ; $0A : Layer2Y + STA $0A PHK - PEA.w (-)+9 PEA $804C JML $00C0FB|!BankB PLY PLB PLP PLX RTL ; Map16 tile number finder, from imamelia's shared subroutines !F = |$800000 FindMap16TileNum: PHX LDA $02 AND #$F0 STA $06 LDA $00 LSR #4 ORA $06 PHA LDA $5B AND #$01 BNE .L0 PLA LDX $01 CLC ADC $00BA60!F,x STA $05 LDA $00BA9C!F,x ADC $03 STA $06 BRA .L1 .L0 PLA LDX $03 CLC ADC $00BA80!F,x STA $05 LDA $00BABC!F,x ADC $01 STA $06 .L1 LDA #$7E STA $07 PLX LDA [$05] XBA INC $07 LDA [$05] XBA RTL