;
;  sprites.macros
;  BuGS
;
;  Created by Jeremy Rand on 2020-06-16.
;Copyright © 2020 Jeremy Rand. All rights reserved.
;

        macro
        _spriteHeader
        sei                     ; 2
        tsc                     ; 2
        sta >backupStack        ; 5
        lda >STATE_REGISTER     ; 6 - Direct Page and Stack in Bank 01/
        ora #$0030              ; 3
        sta >STATE_REGISTER     ; 6
        clc                     ; 2
        tya                     ; 2
        tcs                     ; 2
        mend                    ; 30


        macro
        _spriteFooter
        lda >STATE_REGISTER     ; 6
        and #$ffcf              ; 3
        sta >STATE_REGISTER     ; 6
        lda >backupStack        ; 5
        tcs                     ; 2
        cli                     ; 2
        mend                    ; 24
        
        
        macro
        _leftHead
        
; $c - Green
; $4 - Red
; $8 - Off-white
;
; ....|....
; .RRG|G...
; GRRG|GG..
; GGGG|GGG.
; GGGG|GGG.
; GRRG|GG..
; .RRG|G...
; ....|....
        
        lda $a0,s
        and #$00f0
        ora #$4c04
        sta $a0,s
        
        lda $a2,s
;        and #$ff0f     not necessary with pure green
        ora #$00c0
        sta $a2,s
        
        tsc
        adc #$141
        tcs
        
        pea $4cc4
        
        lda $3,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $3,s
        
        lda #$cccc
        sta $a1,s

        lda $a3,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $a3,s
        
        tsc
        adc #$142
        tcs
        
        pea $cccc

        lda $3,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $3,s
        
        lda #$4cc4
        sta $a1,s

        lda $a3,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $a3,s
        
        tsc
        adc #$141
        tcs
        
        lda $0,s
        and #$00f0
        ora #$4c04
        sta $0,s
        
        lda $2,s
;        and #$ff0f     not necessary with pure green
        ora #$00c0
        sta $2,s
        
        mend
        
        macro
        _leftHeadShift

; $c - Green
; $4 - Red
; $8 - Off-white
;
; ....|....
; ..RR|GG..
; .GRR|GGG.
; .GGG|GGGG
; .GGG|GGGG
; .GRR|GGG.
; ..RR|GG..
; ....|....

        lda $a0,s
        and #$00ff
        ora #$4400
        sta $a0,s
        
        lda $a2,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $a2,s
        
        tsc
        adc #$140
        tcs
        
        lda $0,s
        and #$00f0
        ora #$440c
        sta $0,s
        
        lda $2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $2,s
        
        lda $a0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $a0,s
        
        lda #$cccc
        sta $a2,s
        
        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $0,s
        
        lda #$cccc
        sta $2,s
        
        lda $a0,s
        and #$00f0
        ora #$440c
        sta $a0,s
        
        lda $a2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $a2,s
        
        tsc
        adc #$140
        tcs

        lda $0,s
        and #$00ff
        ora #$4400
        sta $0,s
        
        lda $2,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $2,s
        
        mend

        
        macro
        _leftBody
        
; $c - Green
; $4 - Red
; $8 - Off-white
;
; ....|....
; .GGG|G...
; GGGG|GG..
; GGGG|GGG.
; GGGG|GGG.
; GGGG|GG..
; .GGG|G...
; ....|....
        
        lda $a0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $a0,s
        
        lda $a2,s
;        and #$ff0f     not necessary with pure green
        ora #$00c0
        sta $a2,s
        
        tsc
        adc #$141
        tcs
        
        pea $cccc
        
        lda $3,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $3,s
        
        lda #$cccc
        sta $a1,s

        lda $a3,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $a3,s
        
        tsc
        adc #$142
        tcs
        
        pea $cccc

        lda $3,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $3,s
        
        lda #$cccc
        sta $a1,s

        lda $a3,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $a3,s
        
        tsc
        adc #$141
        tcs
        
        lda $0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $0,s
        
        lda $2,s
;        and #$ff0f     not necessary with pure green
        ora #$00c0
        sta $2,s
        
        mend
        
        
        macro
        _leftBodyShift

; $c - Green
; $4 - Red
; $8 - Off-white
;
; ....|....
; ..GG|GG..
; .GGG|GGG.
; .GGG|GGGG
; .GGG|GGGG
; .GGG|GGG.
; ..GG|GG..
; ....|....

        lda $a0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $a0,s
        
        lda $a2,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $a2,s
        
        tsc
        adc #$140
        tcs
        
        lda $0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $0,s
        
        lda $2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $2,s
        
        lda $a0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $a0,s
        
        lda #$cccc
        sta $a2,s
        
        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $0,s
        
        lda #$cccc
        sta $2,s
        
        lda $a0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $a0,s
        
        lda $a2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $a2,s
        
        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $0,s
        
        lda $2,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $2,s
        
        mend

        
        macro
        _rightHead
        
; $c - Green
; $4 - Red
; $8 - Off-white
;
; ....|....
; ...G|GRR.
; ..GG|GRRG
; .GGG|GGGG
; .GGG|GGGG
; ..GG|GRRG
; ...G|GRR.
; ....|....
        
        lda $a0,s
;        and #$f0ff     not necessary with pure green
        ora #$0c00
        sta $a0,s
        
        lda $a2,s
        and #$0f00
        ora #$40c4
        sta $a2,s
        
        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $0,s
        
        lda #$4cc4
        sta $2,s

        lda $a0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $a0,s
        
        lda #$cccc
        sta $a2,s

        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $0,s

        lda #$cccc
        sta $2,s

        lda $a0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $a0,s
        
        lda #$4cc4
        sta $a2,s
        
        tsc
        adc #$140
        tcs
        
        lda $0,s
;        and #$f0ff     not necessary with pure green
        ora #$0c00
        sta $0,s
        
        lda $2,s
        and #$0f00
        ora #$40c4
        sta $2,s
        
        mend
 

        macro
        _rightHeadShift
        
; $c - Green
; $4 - Red
; $8 - Off-white
;
; ....|....
; ..GG|RR..
; .GGG|RRG.
; GGGG|GGG.
; GGGG|GGG.
; .GGG|RRG.
; ..GG|RR..
; ....|....
        
        lda $a0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $a0,s
        
        lda $a2,s
        and #$ff00
        ora #$0044
        sta $a2,s
        
        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $0,s
        
        lda $2,s
        and #$0f00
        ora #$c044
        sta $2,s

        lda #$cccc
        sta $a0,s
        
        lda $a2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $a2,s

        tsc
        adc #$141
        tcs
        
        pea $cccc

        lda $3,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $3,s

        lda $a1,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $a1,s
        
        lda $a3,s
        and #$0f00
        ora #$c044
        sta $a3,s
        
        tsc
        adc #$141
        tcs
        
        lda $0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $0,s
        
        lda $2,s
        and #$ff00
        ora #$0044
        sta $2,s
        
        mend


        macro
        _rightBody
        
; $c - Green
; $4 - Red
; $8 - Off-white
;
; ....|....
; ...G|GGG.
; ..GG|GGGG
; .GGG|GGGG
; .GGG|GGGG
; ..GG|GGGG
; ...G|GGG.
; ....|....
        
        lda $a0,s
;        and #$f0ff     not necessary with pure green
        ora #$0c00
        sta $a0,s
        
        lda $a2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $a2,s
        
        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $0,s
        
        lda #$cccc
        sta $2,s

        lda $a0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $a0,s
        
        lda #$cccc
        sta $a2,s

        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $0,s

        lda #$cccc
        sta $2,s

        lda $a0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $a0,s
        
        lda #$cccc
        sta $a2,s
        
        tsc
        adc #$140
        tcs
        
        lda $0,s
;        and #$f0ff     not necessary with pure green
        ora #$0c00
        sta $0,s
        
        lda $2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $2,s
        
        mend
 
 
        macro
        _rightBodyShift
        
; $c - Green
; $4 - Red
; $8 - Off-white
;
; ....|....
; ..GG|GG..
; .GGG|GGG.
; GGGG|GGG.
; GGGG|GGG.
; .GGG|GGG.
; ..GG|GG..
; ....|....
        
        lda $a0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $a0,s
        
        lda $a2,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $a2,s
        
        tsc
        adc #$140
        tcs

        lda $0,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $0,s
        
        lda $2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $2,s

        lda #$cccc
        sta $a0,s
        
        lda $a2,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $a2,s

        tsc
        adc #$141
        tcs
        
        pea $cccc

        lda $3,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $3,s

        lda $a1,s
;        and #$00f0     not necessary with pure green
        ora #$cc0c
        sta $a1,s
        
        lda $a3,s
;        and #$0f00     not necessary with pure green
        ora #$c0cc
        sta $a3,s
        
        tsc
        adc #$141
        tcs
        
        lda $0,s
;        and #$00ff     not necessary with pure green
        ora #$cc00
        sta $0,s
        
        lda $2,s
;        and #$ff00     not necessary with pure green
        ora #$00cc
        sta $2,s
        
        mend
        
        macro
        _collision &mask,&addr
        tax
        and &mask
        beq _noCollision_&SYSCNT
        sta >collision
        tsc
        clc
        adc &addr
        sta >collisionAddr
_noCollision_&SYSCNT anop
        txa
        mend
