Weave

by dtothefourth

Game: SMW

Description: A horrible weaving HDMA effect

main:
   LDA $0100
   CMP #$14
   BEQ +
   RTL
   +

   LDA $1696
   CMP #$AB
   BEQ +

   REP #$20             ; | 
   LDA #$0D02           ; | Use Mode 02 on register 210D
   STA $4330            ; | 4330 = Mode, 4331 = Register
   LDA #$B600           ; | Address of HDMA table
   STA $4332            ; | 4332 = Low-Byte of table, 4333 = High-Byte of table
   SEP #$20             ; | 
   LDA.b #$7F           ; | Address of HDMA table, get bank byte
   STA $4334            ; | 4334 = Bank-Byte of table

   LDA #$40
   STA $7FB501

   LDA #$AB
   STA $1696

   LDA #$08             ; | 
   TSB $0D9F      ; | Enable HDMA channel 3

   +

   LDA $9D
   ORA $13D4
   BEQ +
   RTL
   +



   REP #$10
   LDY #$0000             ; | Y will be the loop counter.
   LDX #$0000             ; | X the index for writing the table to the RAM
   LDA $13              ; | Speed of waves
   LSR #2               ; | Slowing down A
   STA $05              ;/  Save for later use.
   STZ $06

   LDA $13
   AND #$01
   BNE ++
   LDA $7FB501
   DEC
   CMP #$C0
   BNE +
   LDA #$40
   +
   STA $7FB501
   ++

   LDA $7FB501
   BPL +
   EOR #$FF
   INC
   +
   STA $01
   STZ $02
   STA $03
   STZ $04

   PHB : PHK : PLB      ;\  Preserve bank
Loop:                  ; | Jump back if not finished writing table
   LDA #$02             ; | Set scanline height
   STA $7FB600,x        ; | for each wave

   REP #$20

   LDA $01
   CLC                  
   ADC $1E              
   STA $7FB600+1,x        
         
   TYA
   CLC
   ADC $05
   AND #$0003
   BNE +
   LDA $03
   STA $01
   BRA ++
   +
   CMP #$0001
   BNE +
   LDA #$0000
   STA $01
   BRA ++ 
   +
   CMP #$0002
   BNE +
   LDA $03
   EOR #$FFFF
   INC
   STA $01
   BRA ++ 
   +
   LDA #$0000
   STA $01
   ++ 
   SEP #$20
   CPY #$0070             ; | Compare if we have written enough HDMA entries.
   BCS End             ; | If bigger, end HDMA
   INX                  ; | Increase X, so that in the next loop, it writes the new table data...
   INX                  ; | ... at the end of the old one instead of overwritting it.
   INX                  ; | 
   INY                  ; | Increase loop counter
   BRA Loop            ;/  Repeat loop

End:                   ;\  Jump here when at the end of HDMA
   SEP #$10
   PLB                  ; | Pull back data bank.
   LDA #$00             ; | End HDMA by writting 00...
   STA $7FB600+3,x        ; | ...at the end of the table.
   RTL                  ;/  
back to listings