;==================================================================
; [s1boss.s] - Copyfight (C) kr Software '04.
;
;   This file contains all code for the the STAGE 1 boss fight +
;   a lot of other stuff, ahaha!
;
;   *GROWL*
;
;    This file -also- contains several routines for universal usage.
;    The routines in question are marked with `UNIVERSAL ROUTINE'.
;==================================================================

; bank #18
.BANK $12 SLOT 0
.ORG $0000
.SECTION "stage1BossPlusPlus"


STAGE1BOSS

    lda #$01
    sta areWeAtFirstBoss
    sta lostLife_forceNoFLIP

    dec SPRBUF1+SX12
    dec SPRBUF1+SX12
    lda #$8c                    ; eliminate the blatant crap laser-buggy!
    sta SPRBUF1+SFRAME21

    jsl sym_MUS_SONG_BOWSER

    lda #%11111100              ; disable space enemy sprites
    sta SPRBUF2+3               ; except for ship (#12) +#13 and #14.
    lda #$ff
    sta SPRBUF2+4

    lda #$30
    sta SPRBUF1+SPRIORITY12
    stz SPRBUF1+SPRIORITY13
    stz SPRBUF1+SPRIORITY14
    stz SPRBUF1+SPRIORITY15
    stz SPRBUF1+SPRIORITY16
    stz SPRBUF1+SPRIORITY17
    stz SPRBUF1+SPRIORITY18
    stz SPRBUF1+SPRIORITY19
    stz SPRBUF1+SPRIORITY20
    stz SPRBUF1+SPRIORITY21

    lda #$00                    ; hide some sprite garbage
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16

    lda #$08                    ; change to the third ship sprite as the first
    sta SPRBUF1+SFRAME12        ; one is not to used before after Twinbee appears.

    lda #$0f
    sta $2100


    ; force the ship back to its original position.
    ; e.g: when `stage 1' first began.

S1B_w2
    wai                         ; wait for vblank
    jsl bH13_ENGINE_ALL_doThe50p
    jsl bH13_ENMBLINK_doIt
    jsl bH13_ENMBLINK_delay
    jsr S1B_starScroll

    ; check whether or not we should quit this loop (S1B_w2)
    lda SPRBUF1+SX12
    cmp #$40
    bne S1B_w2_callLocalDealer
    lda SPRBUF1+SY12
    cmp #$80
    beq S1B_w3_prologue


    ; our ship of heroine haven't reached the desired location yet :/
S1B_w2_callLocalDealer

    lda SPRBUF1+SX12
    cmp #$40
    beq S1B_w2_mvY
    bmi S1B_w2_Xpp

    dec SPRBUF1+SX12
    jmp S1B_w2_mvY
S1B_w2_Xpp
    inc SPRBUF1+SX12

S1B_w2_mvY
    lda SPRBUF1+SY12
    cmp #$80
    beq S1B_w2
    bmi S1B_w2_Ypp

    dec SPRBUF1+SY12
    jmp S1B_w2
S1B_w2_Ypp
    inc SPRBUF1+SY12
    jmp S1B_w2


    ; a little delay ...

S1B_w3_prologue
    lda #$80                   ; used to be $40, but more was needed due to 50-
    sta a_byte                 ; sprite still on screen when changing sprset :[
S1B_w3_prologue_wait
    wai
    jsl bH13_ENGINE_ALL_doThe50p
    jsl bH13_ENMBLINK_doIt
    jsl bH13_ENMBLINK_delay
    jsr S1B_starScroll
    dec a_byte
    lda a_byte
    cmp #$00
    bne S1B_w3_prologue_wait    ; loop until a_byte equ $00

    ; load the spriteset with Twinbee in it :)
    LOAD_BLOCK2VRAM SPR_TILES5,$6000,$2000
    wai
    jsl bH13_ENGINE_ALL_doThe50p
    jsl bH13_ENMBLINK_doIt
    jsl bH13_ENMBLINK_delay
    wai
    jsl bH13_ENGINE_ALL_doThe50p
    jsl bH13_ENMBLINK_doIt
    jsl bH13_ENMBLINK_delay

S1B_w3
    lda #$03
    sta a_byte                  ; total repeat counter
    stz a_byte2                 ; press start to skip text var
    ldx #$0040
    stx a_word

S1B_w3_setup
    lda #$FF
    sta dummybyte

S1B_w3_loop
    wai
    jsl bH13_ENGINE_ALL_doThe50p
    jsl bH13_ENMBLINK_doIt
    jsl bH13_ENMBLINK_delay
    jsr S1B_FS_sillyRandomising ; force some silly randomising
    jsr S1B_starScrollSKIP

    lda joy1+1                  ; check if 'start'-button is pressed
    and #$10
    beq S1B_w3_loopContinues
    jmp S1B_SKIP_SEQUENCE       ; if pressed then skip the sequence

S1B_w3_loopContinues
    dec dummybyte
    lda dummybyte
    cmp #$00                    ; reached zero yet?
    beq S1B_w3_areWeDoneYet
    jmp S1B_w3_loop

S1B_w3_areWeDoneYet
    dec a_byte
    lda a_byte
    cmp #$00
    bne S1B_w3_setup
    jmp S1B_w4


S1B_starScrollSKIP
    ldx MAPX                    ; scroll bg#1 map
    inx
    inx
    inx
    stx MAPX
    jsr S1B_FS_sillyRandomising

    ldx a_word
    dex
    stx a_word
    cpx #$0000
    beq S1B_starScrollSKIPresetW
    jmp S1B_starScrollSKIPwriteInfo
S1B_starScrollSKIPresetW
    ldx #$0040
    stx a_word
    inc a_byte2
    lda a_byte2
    cmp #$04
    bne S1B_starScrollSKIPwriteInfo
    stz a_byte2


S1B_starScrollSKIPwriteInfo

    lda a_byte2                 ; display info about how to skip the sequence
    cmp #$00
    beq S1B_starScrollSKIP_msg1
    cmp #$01
    beq S1B_starScrollSKIP_msg2
    cmp #$02
    beq S1B_starScrollSKIP_msg3
S1B_starScrollSKIP_msg4
    jsl bH0_PRINTS_START_TO_SKIP5
    jmp S1B_starScrollSKIPrts
S1B_starScrollSKIP_msg3
    jsl bH0_PRINTS_START_TO_SKIP3
    jmp S1B_starScrollSKIPrts
S1B_starScrollSKIP_msg2
    jsl bH0_PRINTS_START_TO_SKIP2
    jmp S1B_starScrollSKIPrts
S1B_starScrollSKIP_msg1    
    jsl bH0_PRINTS_START_TO_SKIP1
S1B_starScrollSKIPrts
    rts


S1B_SKIP_SEQUENCE
;   FADE_OUT
    jsl bH13_FADE_OUT_SCROLLBG1
    jsl bH13_DEINIT_doThe50p
    jsl bH13_ENMBLINK_setup
    jsl sym_MUS_NO_SONG
    jmp S1B_w9_versusScreen


;   SPECIAL GUEST STAR: Twinbee!!! *yay*

S1B_w4
    jsl bH0_PRINTS_START_TO_SKIP4

    lda SPRBUF1+SY12
    sta freeForAll3             ; copy of ship.y (for later use)

    lda #%11000000
    sta SPRBUF2+3


    ; Twinbee setup -- my re-coloured Twinbee looks not only effectively sharper
    ; than, but also better than Twinbee himself (from the game Pop 'n Twinbee).
    lda #$40
    sta SPRBUF1+SX13
    sta SPRBUF1+SX14
    stz SPRBUF1+SY13
    lda #$20
    sta SPRBUF1+SY14

    lda #$40
    sta SPRBUF1+SFRAME13
    lda #$0c
    sta SPRBUF1+SFRAME14


S1B_twinbeeFall_part1           ; fall towards ship
    wai
    jsr S1B_starScroll

    inc SPRBUF1+SY13
    inc SPRBUF1+SY14

    lda SPRBUF1+SY14
    cmp #$6b
    bne S1B_twinbeeFall_part1

    dec SPRBUF1+SY13
    dec SPRBUF1+SY14
    lda #$04
    sta SPRBUF1+SFRAME12

    jsl sym_SFX_GUN_FIRE

S1B_twinbeeFall_part2           ; now both Twinbee and ship
    wai
    wai
    jsr S1B_starScroll

    jsl sym_SFX_EXPLOSION

    inc SPRBUF1+SY12
    inc SPRBUF1+SY13
    inc SPRBUF1+SY14

    lda SPRBUF1+SY14
    cmp #$74
    bne S1B_twinbeeFall_part2

    inc SPRBUF1+SY13
    inc SPRBUF1+SY13
    inc SPRBUF1+SY14
    inc SPRBUF1+SY14
    lda #$00
    sta SPRBUF1+SFRAME12

    jsl sym_SFX_GUN_FIRE

    stz a_byte                  ; inc skip thingy
    lda #$04
    sta dummybyte               ; number of times to loop

S1B_twinbeeFall_part3           ; now both Twinbee and ship..slower
    wai
    wai
    jsr S1B_starScroll

    lda a_byte
    cmp #$01
    bne S1B_twinbeeFall_part3_skipINC
    inc SPRBUF1+SY12
    inc SPRBUF1+SY13
    inc SPRBUF1+SY14
    stz a_byte
S1B_twinbeeFall_part3_skipINC
    inc a_byte
    dec dummybyte
    lda dummybyte
    cmp #$00
    bne S1B_twinbeeFall_part3



S1B_w5                          ; move ship up a little and let Twinbee flee :)
    lda #%11001100
    sta SPRBUF2+3

    lda #$44                    ; Twinbee second frame
    sta SPRBUF1+SFRAME14

    jsl sym_SFX_DEEP_THUMP

    lda #$05
    sta freeForAll4             ; number of times to dec SY12
    lda #$40
    sta a_byte2                 ; a copy of twinbee.x

S1B_w5_loop
    wai
    jsr S1B_starScroll
    jsl S1B_virreteShipShip
    jsr S1B_FS_sillyRandomising

    lda freeForAll4
    cmp #$00
    bne S1B_w5_decShip
    lda freeForAll3
    sta SPRBUF1+SY12
    jmp S1B_w5_leaveShipAlone

S1B_w5_decShip
    lda freeForAll4
    cmp #$00
    beq S1B_w5_leaveShipAlone
    dec freeForAll4
    dec SPRBUF1+SY12

S1B_w5_leaveShipAlone

    inc a_byte2
    inc a_byte2
    inc SPRBUF1+SX14
    inc SPRBUF1+SX14
    dec SPRBUF1+SY14

    lda a_byte2
    cmp #$E2
    beq S1B_w6
    jmp S1B_w5_loop



S1B_w6

    jsl sym_MUS_SONG_METLM      ; play some techno, DJ!
    lda #$ff
    sta a_byte

S1B_w6_delayLoop
    wai
    jsr S1B_starScroll
    jsl S1B_virreteShipShip
    dec a_byte
    lda a_byte
    cmp #$00
    beq S1B_w69_LOAD_SEQ_S1AMCHAT ; was: S1B_w7
    jmp S1B_w6_delayLoop


;------------------------------------

;.ENDASM
    ; ANGELA AND MANKO-CHAN DISCUSSION SCENE

S1B_w69_LOAD_SEQ_S1AMCHAT

    ; the two following instructions is to make sure that Twinbee doesn't get
    ; visible during the mosaic fadeout.
    stz SPRBUF1+SY13
    stz SPRBUF1+SY14

;   FADE_OUT_MOSAIC
    jsl bH13_FADE_OUT_MOSAIC_SCROLLBG1

    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100

    lda #$03
    sta $212c                   ; disable all, but bg#1 and bg#2

    LOAD_PAL SEQ_S1B_DISCUSS_PAL
    wai
    LOAD_BLOCK2VRAM INTRO_BG_GRL_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_DISCUSS_PIC,$2000,$6000
    wai
    wai
    LOAD_BLOCK2VRAM S1AM_S1B_SEQ_FONT,$5000,$0800
    wai
    wai


    jsl bH0_SPLSC_CLR

    ldx #$0000                  ; reset bg#1 tilemap position
    stx MAPX
    stx MAPY

    stz a_byte                  ; "A" button animation var

    FADE_IN_MOSAIC

    ldx #$6f
    jsl bH12_WAIT_FOR_THE_HOLY_WAI

;----
    jsl bH0_PRINTS_SB1_DAIJOUBU_KA
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_ERR_YES
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_YOKATTA
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_STATUS_IS_WHAT
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_RATHER_CRAP
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO

    jmp _BURZUM


S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    ldx #$1a
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsr S1B_FS_sillyRandomising
    rts

;----

_BURZUM
    wai
    wai
    wai
    wai
    wai
    wai

    inc a_byte
    lda a_byte
    cmp #$04
    bne _BURZUM_PROCEED
    stz a_byte

_BURZUM_PROCEED
    jsl bH0_PRINTZ_angelManko_AbuttAnim

    lda joy1                    ; check if button A (red pill) has been pressed
    and #$80
    beq _BURZUM_NOT_A
    jmp S1B_w69_S1AMCHAT_PAGE2
_BURZUM_NOT_A
    jmp _BURZUM
;.ASM


S1B_w69_S1AMCHAT_PAGE2
    GOTOXY 24,30
    jsl bH0_PRINTZ_singleEraser
    stz a_byte                  ; "A" button animation var

    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_SPLSC_CLR

    jsl bH0_PRINTS_SB1_JUST_ABOUT
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_BUT_THE_PHAZER
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_BASIC_CONTROL
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_DESTROYED
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_FREAK_ACCIDENT
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO

_BURZUM_ZWEI
    wai
    wai
    wai
    wai
    wai
    wai

    inc a_byte
    lda a_byte
    cmp #$04
    bne _BURZUM_ZWEI_PROCEED
    stz a_byte

_BURZUM_ZWEI_PROCEED
    jsl bH0_PRINTZ_angelManko_AbuttAnim

    lda joy1
    and #$80
    beq _BURZUM_ZWEI_NOT_A
    jmp S1B_w69_S1AMCHAT_PAGE3
_BURZUM_ZWEI_NOT_A
    jmp _BURZUM_ZWEI



S1B_w69_S1AMCHAT_PAGE3
    GOTOXY 24,30
    jsl bH0_PRINTZ_singleEraser
    stz a_byte                  ; "A" button animation var

    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_SPLSC_CLR

    jsl bH0_PRINTS_SB1_BUT_AS_LONG
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_LIFE_HOPE
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_YAY_PLUS_HEART
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_CRAPPY_MUSIC_1
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_CRAPPY_MUSIC_2
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO

_BURZUM_DREI
    wai
    wai
    wai
    wai
    wai
    wai

    inc a_byte
    lda a_byte
    cmp #$04
    bne _BURZUM_DREI_PROCEED
    stz a_byte

_BURZUM_DREI_PROCEED
    jsl bH0_PRINTZ_angelManko_AbuttAnim

    lda joy1
    and #$80
    beq _BURZUM_DREI_NOT_A
    jmp S1B_w7_alpha ;beta catherine zeta
_BURZUM_DREI_NOT_A
    jmp _BURZUM_DREI


S1B_w7_alpha
    FADE_OUT_MOSAIC

    jsl bH12_INIT_VIDEO_03
    lda #$80
    sta $2100

    lda #$ff
    sta $212c                   ; enable all planes + obj

    LOAD_PAL BG_PAL
    wai
    LOAD_BLOCK2VRAM BG_MAPDAT,$0000,$2000
    wai
    wai
    wai
    LOAD_BLOCK2VRAM BG_MAPGFX,$1000,$0800
    wai
    wai
    wai
    LOAD_BLOCK2VRAM FONT2_TILES,$2000,$1800
    wai
    wai

    jsl bH0_SPLSC_CLR
    jsl CUT_PLYFLD
    jsl bH13_BLACK_SIDES_MKAY
    jsl WRITE_STATUSBAR_LV1
    jsl ADD_BLACK_SIDES_MKAY
    jsl WRITE_FOOBAR_LV1
    jsl UPDATE_SCORE
    jsl WRITE_LIVES_REMAINING
    jsl WRITE_HP_REMAINING

;   FADE_IN
    jsl bH13_FADE_IN_SCROLLBG1virreVirre

    ldy #$9f                    ; delay the sequence, but scroll bg#1
S1B_w7_alpha_wai
    wai
    jsl S1B_virreteShipShip
    ldx MAPX
    inx
    inx
    inx
    stx MAPX
    dey
    cpy #$0000
    bne S1B_w7_alpha_wai

;-----------------------------------------



S1B_w7                          ; initialise the ebil frat Smiley (tm)

    lda #$30
    sta SPRBUF1+SPRIORITY13     ; priority smiley sprites
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    stz SPRBUF1+SPRIORITY17     ; projectile sprites
    stz SPRBUF1+SPRIORITY18
    stz SPRBUF1+SPRIORITY19
    stz SPRBUF1+SPRIORITY20
    stz SPRBUF1+SPRIORITY21

    lda #$90                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$B0
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16

    lda #$70                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$90
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16

    lda #$48                    ; assign evil smiley gfx
    sta SPRBUF1+SFRAME13
    lda #$4c
    sta SPRBUF1+SFRAME14
    lda #$80
    sta SPRBUF1+SFRAME15
    lda #$84
    sta SPRBUF1+SFRAME16

    jsr S1B_MAKE_LAST_SPRPAL_WHITE
    jsr S1B_MAKE_SMILEY_PAL_WHITE

    stz SPRBUF2+3
    lda #%11111100
    sta SPRBUF2+4


    ; make that Evil Smiley "blink its way onto the screen"

    lda #$50
    sta a_byte2                 ; loop counter
    stz a_byte                  ; blink counter
S1B_w8
    wai
    jsl S1B_virreteShipShip
    ldx MAPX
    inx
    inx
    inx
    stx MAPX
    dec a_byte2
    lda a_byte2
    cmp #$00
    beq S1B_w8_ende
    lda a_byte
    cmp #$00
    beq S1B_w8_no

    jsr S1B_MAKE_SMILEY_PAL_WHITE
    jmp S1B_w8_cont
S1B_w8_no
    jsr S1B_MAKE_SMILEY_PAL_NORM
S1B_w8_cont
    inc a_byte
    lda a_byte
    cmp #$03
    beq S1B_w8_resetAByte
    jmp S1B_w8
S1B_w8_resetAByte
    stz a_byte
    jmp S1B_w8

S1B_w8_ende
    jsr S1B_MAKE_SMILEY_PAL_NORM
    

    ldy #$7f                    ; delay the sequence, but scroll bg#1
S1B_w8_alpha_wai
    wai
    jsr S1B_starScroll
    jsl S1B_virreteShipShip
    dey
    cpy #$0000
    bne S1B_w8_alpha_wai


    ; Make Evil Smiley go bling-bling

    stz SPRBUF1+SPRIORITY13     ; decrease upperleft Smiley sprite priority
    jsl sym_SFX_DING_A_LING_HIGH

    stz a_byte                  ; bling bling
    ldy #$3f                    ; delay the sequence, but scroll bg#1
S1B_w8_beta_wai
    inc a_byte
    lda a_byte
    cmp #$04
    bne S1B_w8_beta_continue
    stz a_byte
S1B_w8_beta_continue
    wai
    jsr S1B_starScroll
    jsl S1B_virreteShipShip

    GOTOXY 16,20
    lda a_byte
    cmp #$03
    beq S1B_w8_beta_01
    cmp #$02
    beq S1B_w8_beta_02
    cmp #$01
    beq S1B_w8_beta_01

    jsl bH0_PRINTZ_blingBling_a01
    jmp S1B_w8_beta_animUpdated
S1B_w8_beta_01
    jsl bH0_PRINTZ_singleEraser
    jmp S1B_w8_beta_animUpdated
S1B_w8_beta_02
    jsl bH0_PRINTZ_blingBling_a02
S1B_w8_beta_animUpdated
    dey
    cpy #$0000
    bne S1B_w8_beta_wai


    lda #$30
    sta SPRBUF1+SPRIORITY13
    GOTOXY 16,20                ; not needed, but I add these two lines anyway
    jsl bH0_PRINTZ_singleEraser ; just to make it all idiot-proof. :-)


    lda #$45
    sta a_byte
S1B_w8end_delay
    wai
    jsr S1B_starScroll
    jsl S1B_virreteShipShip
    dec a_byte
    lda a_byte
    cmp #$00
    beq S1B_w9
    jmp S1B_w8end_delay

;--------------------------------

S1B_w9
    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100

    lda #$01
    sta $212c                   ; disable all, but bg#1

    jsl sym_MUS_NO_SONG

    LOAD_PAL SEQ_S1B_FUUUCK_PAL
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_FUUUCK_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_FUUUCK_PIC,$2000,$6000
    wai
    wai

    ldx #$0000                  ; reset bg#1 tilemap position
    stx MAPX
    stx MAPY

    FADE_IN_MOSAIC

    ldx #$6f
    jsl bH12_WAIT_FOR_THE_HOLY_WAI


    lda #$40
    sta a_byte                  ; number of times to run the blink screen loop


S1B_w9_blinkScreenLoop

    lda #$80
    sta $2100
    wai
    wai
    lda #$0f
    sta $2100
    wai
    wai

    dec a_byte
    lda a_byte
    cmp #$00
    bne S1B_w9_blinkScreenLoop


S1B_w9_versusScreen

    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100
    wai

    ldx #$0000                  ; reset bg#1 tilemap position
    stx MAPX
    stx MAPY

    lda #$01
    sta $212c                   ; disable all, but bg#1

    LOAD_PAL S1B_VERSUS_PAL
    wai
    LOAD_BLOCK2VRAM S1B_VERSUS_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM S1B_VERSUS_PIC,$2000,$6000
    wai
    wai

    jsl sym_SFX_DEEP_THUMP

    lda #$0f
    sta $2100


    lda #$ff
    sta a_byte
S1B_w9_versusLoop
    wai
    dec a_byte
    lda a_byte
    cmp #$00
    beq S1B_FIGHT_START
    jmp S1B_w9_versusLoop


;--------------------------------------------------


S1B_FIGHT_START

    jsl bH13_FADE_OUT_macro     ; fade out versus screen

    lda #$80
    sta $2100
    jsl bH12_INIT_VIDEO_03
    lda #$80
    sta $2100

    lda #$ff
    sta $212c                   ; enable all planes + obj

    jsl sym_MUS_SONG_ASCHE


    LOAD_PAL BG_PAL
    wai
    LOAD_BLOCK2VRAM BG_MAPDAT,$0000,$2000
    wai
    wai
    wai
    LOAD_BLOCK2VRAM BG_MAPGFX,$1000,$0800
    wai
    wai
    wai
    LOAD_BLOCK2VRAM FONT2_TILES,$2000,$1800
    wai
    wai

    jsl bH0_SPLSC_CLR
    jsl CUT_PLYFLD
    jsl bH13_BLACK_SIDES_MKAY
    jsl WRITE_STATUSBAR_LV1
    jsl ADD_BLACK_SIDES_MKAY
    jsl WRITE_FOOBAR_LV1
    jsl UPDATE_SCORE
    jsl WRITE_LIVES_REMAINING
    jsl WRITE_HP_REMAINING

    lda SPRBUF1+SX12
    sta freeForAll1
    lda SPRBUF1+SY12
    sta freeForAll2
    jsl TOTALLY_RESET_32x32_SPRITES
    lda freeForAll1
    sta SPRBUF1+SX12
    lda freeForAll2
    sta SPRBUF1+SY12

    ;---------- beginning of ebil smiley initialisation

    lda #$30
    sta SPRBUF1+SPRIORITY13     ; priority smiley sprites
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    stz SPRBUF1+SPRIORITY17     ; projectile sprites
    stz SPRBUF1+SPRIORITY18
    stz SPRBUF1+SPRIORITY19
    stz SPRBUF1+SPRIORITY20
    stz SPRBUF1+SPRIORITY21

    lda #$90                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$B0
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16

    lda #$70                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$90
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16

    lda #$48                    ; assign evil smiley gfx
    sta SPRBUF1+SFRAME13
    lda #$4c
    sta SPRBUF1+SFRAME14
    lda #$80
    sta SPRBUF1+SFRAME15
    lda #$84
    sta SPRBUF1+SFRAME16

    lda #%00111111
    sta SPRBUF2+2
    stz SPRBUF2+3
    lda #%11111100
    sta SPRBUF2+4

    ;---------- end of ebil smiley initialisation

    lda #$00
    sta SPRBUF1+SFRAME12

;   FADE_IN
    jsl bH13_FADE_IN_SCROLLBG1virreVirre

    lda #$80
S1B_FS_w0
    wai
    jsr S1B_starScroll
    jsl S1B_virreteShipShip
    dea
    cmp #$00
    bne S1B_FS_w0
    jmp S1B_FS_w1_setup


;================================
;================================
;================================
;========FIGHT CLUB==============
;================================
;================================
;================================

S1B_FS_sillyRandomising

    inc ENM_13_magica           ; play with SMILEY_TIMER
    lda ENM_13_magica
    cmp #$ff
    beq S1B_FS_sRreset13
    jmp S1B_FS_sRskip1
S1B_FS_sRreset13
    lda #$40
    sta ENM_13_magica
    rts
S1B_FS_sRskip1
    inc ENM_17_magica           ; play with SMILEY_HORizontal
    lda ENM_17_magica
    cmp #$02
    beq S1B_FS_sRreset17
    jmp S1B_FS_sRskip2
S1B_FS_sRreset17
    stz ENM_17_magica
S1B_FS_sRskip2
    rts


; ---fight variables
;   ENM_13_hp     ~ SMILEY health points
;   ENM_14_hp     ~ SMILEY projectile time
;   ENM_15_hp     ~ SMILEY projectile flip order
;   ENM_16_hp     ~ SMILEY "random" coords pattern (-:
;
;   ENM_13_magica ~ SMILEY_TIMER
;   ENM_14_magica ~ smileyIsHit (1=true)
;   ENM_15_magica ~ SMILEY_DIR (0=UP,1=DOWN)
;   ENM_16_magica ~ SMILEY_SPEED (adv. # pixels)
;   ENM_17_magica ~ SMILEY_HORizontal (0=LEFT,1=RIGHT)
;   ENM_18_magica ~ all purpose cultural variable ENM_18_magica
;
;   ENM_13_alive  ~ SHIP DAGG-R off/on (0/1)
;   ENM_14_alive  ~ temp DAGG-R y
;   ENM_15_alive  ~ SHIP DAGG-R delay
;
;   ENM_16_alive  ~ temp SMILEY X2
;   ENM_17_alive  ~ temp SMILEY Y2
;
;   ENM_18_alive  ~ w1_randomCrashSFX
;
;   Additional:
;
;   ENM_13_wait ~ SMILEY_TIMER "random" refill
;   ENM_14_wait ~ SMILEY_TIMER decrease delay
;   ENM_15_wait ~ SHIP hiccup
;   ENM_16_wait ~ SHIP motor prob
;
;   ENM_17_wait ~ temp DAGG-R X2
;   ENM_18_wait ~ temp DAGG-R Y2


S1B_FS_w1_setup

    ; initialise Evil Smiley variables

    ; please note: SMILEY_DIR, SMILEY_HORizontal and SMILEY_TIMER
    ; is "calculated randomly" which makes it a load cooler :-)

    lda #$12
    sta ENM_13_hp               ; SMILEY health points
    stz ENM_14_hp               ; SMILEY projectile time
    stz ENM_16_hp               ; SMILEY "random" coords pattern (-:
;   lda #$ff
;   sta ENM_13_magica           ; set SMILEY_TIMER to 255
    stz ENM_14_magica           ; set smileyIsHit to FALSE
    stz ENM_15_magica           ; set SMILEY_DIR to UP
    lda #$01
    sta ENM_16_magica           ; set SMILEY_SPEED to 1pix
;   stz ENM_17_magica           ; SMILEY_HORizontal (0=LEFT,1=RIGHT)
    stz ENM_14_wait             ; SMILEY_TIMER decrease delay
    stz ENM_15_wait             ; SHIP hiccup
    stz ENM_16_wait             ; SHIP motor prob
    stz ENM_13_alive            ; DAGG-R off/on (0/1)
;   stz ENM_14_alive            ; --- UNUSED ---
    stz ENM_15_alive            ; DAGG-R delay

    stz OBJ_HIT

    ; setup sprite that will be used for DAGG-R
    stz SPRBUF1+SPRIORITY11     ; sprite $11 lowest priority
    lda #$8c
    sta SPRBUF1+SFRAME11        ; sprite is invisible

    stz SPRBUF2+5               ; disable sprites 20-31
    stz SPRBUF2+6               ; for no special reason
    stz SPRBUF2+7

;   GOTOXY 10,10
;   jsl bH0_PRINTS_SB1_BARNETISS


;--------------------------------


S1B_FS_w1_loopMain

    wai

    jsr S1B_FS_controlShip
    jsr S1B_starScroll


    inc ENM_13_wait
    lda ENM_13_wait
    cmp #$9c
    beq S1B_FS_w1_reset13wait
    jmp S1B_FS_w1_skip0
S1B_FS_w1_reset13wait
    lda #$01
    sta ENM_13_wait

S1B_FS_w1_skip0
    ; if(--SMILEY_TIMER == 0)
    ;     S1B_FS_w1_teleportCenter();
    lda ENM_14_wait
    cmp #$02
    bne S1B_FS_w1_skip1
    dec ENM_13_magica
    lda ENM_13_magica
    cmp #$00
    beq sym_S1B_FS_w1_teleportToCenter
    jmp S1B_FS_w1_skip1

sym_S1B_FS_w1_teleportToCenter
    jmp S1B_FS_w1_teleportToCenter

S1B_FS_w1_skip1
    jsr S1B_chkShipSmileyColl

    ; if(smileyIsHit)
    ;     S1B_FS_w1_smileyIsHit();
;   lda ENM_14_magica
;   cmp #$01
;   beq S1B_FS_w1_smileyIsHit

    inc ENM_14_wait
    lda ENM_14_wait
    cmp #$03
    bne S1B_FS_w1_skip2
    stz ENM_14_wait

S1B_FS_w1_skip2
    ; if(!SMILEY_DIR == UP)
    ;     S1B_FS_w1_moveSmDown();
    lda ENM_15_magica
    cmp #$00
    bne S1B_FS_w1_moveSmDown

    ; ~if SMILEY_DIR = UP do
    ; if(smiley.y <= #$44(#68))
    ;    SMILEY_DIR = DOWN;
    lda SPRBUF1+SY13
    cmp #$44
    beq S1B_FS_w1_changeDir2DOWN
    bmi S1B_FS_w1_changeDir2DOWN
    ; it's okay to move (decrease y)
    dec SPRBUF1+SY13
    dec SPRBUF1+SY14
    dec SPRBUF1+SY15
    dec SPRBUF1+SY16
    jmp S1B_FS_w1_chkLftRght
S1B_FS_w1_changeDir2DOWN
    lda #$01
    sta ENM_15_magica
    jmp S1B_FS_w1_chkLftRght


    ; increase Smiley Y
S1B_FS_w1_moveSmDown

    ; ~if SMILEY_DIR = DOWN do
    ; if(smiley.y >= #$9c(#156))
    ;    SMILEY_DIR = UP;
    lda SPRBUF1+SY13
    cmp #$9c
    beq S1B_FS_w1_changeDir2UP
    bpl S1B_FS_w1_changeDir2UP
    ; it's okay to move (decrease y)
    inc SPRBUF1+SY13
    inc SPRBUF1+SY14
    inc SPRBUF1+SY15
    inc SPRBUF1+SY16
    jmp S1B_FS_w1_chkLftRght
S1B_FS_w1_changeDir2UP
    stz ENM_15_magica


S1B_FS_w1_chkLftRght
    ; if(SMILEY_HOR == 0)
    ;    S1B_FS_w1_moveSmLeft();
    ; else S1B_FS_w1_moveSmRight();
    lda ENM_17_magica
    cmp #$00
    beq S1B_FS_w1_moveSmLeft
    cmp #$01
    beq S1B_FS_w1_moveSmRight



    ; decrease Smiley X
S1B_FS_w1_moveSmLeft

    ; ~if SMILEY_HOR = LEFT do
    ; if(smiley.x <= #$24(#36))
    ;    SMILEY_HOR = RIGHT;
    lda SPRBUF1+SX13
    cmp #$24
    beq S1B_FS_w1_changeDir2RIGHT
    bmi S1B_FS_w1_changeDir2RIGHT
    ; it's okay to move (decrease x)
    dec SPRBUF1+SX13
    dec SPRBUF1+SX14
    dec SPRBUF1+SX15
    dec SPRBUF1+SX16
    jmp S1B_FS_w1_moveSmDone
S1B_FS_w1_changeDir2RIGHT
    lda #$01
    sta ENM_17_magica
    jmp S1B_FS_w1_moveSmDone



    ; increase Smiley X
S1B_FS_w1_moveSmRight

    ; ~if SMILEY_HOR = RIGHT do
    ; if(smiley.x >= #$9c(#156))
    ;    SMILEY_HOR = LEFT;
    lda SPRBUF1+SX13
    cmp #$9c
    beq S1B_FS_w1_changeDir2LEFT
    bpl S1B_FS_w1_changeDir2LEFT
    ; it's okay to move (decrease x)
    inc SPRBUF1+SX13
    inc SPRBUF1+SX14
    inc SPRBUF1+SX15
    inc SPRBUF1+SX16
    jmp S1B_FS_w1_moveSmDone
S1B_FS_w1_changeDir2LEFT
    stz ENM_17_magica



S1B_FS_w1_moveSmDone

    ; perform htidetection between DAGG-R and smiley

    jsr S1B_FS_w1_DAGGRhitDetect
    lda ENM_14_magica           ; smileyIsHit (0/1)
    cmp #$00
    beq S1B_FS_w1_moveSmDoneNoHit

    stz ENM_14_magica           ; smileyIsHit = FALSE
    ; TODO: Decrease smiley HP

    jmp S1B_FS_w1_teleportToCenter


S1B_FS_w1_moveSmDoneNoHit

    jmp S1B_FS_w1_loopMain



;================================
;================================

; blink Smiley away from screen and blink him in again
; at his original position


; BLINK HIM OUT

S1B_FS_w1_teleportToCenter
;=========================

    lda #$60
    sta a_byte                  ; counter
    stz ENM_18_magica

    jsl sym_SFX_INTERFERENCE

S1B_FS_w1_teleportToCenter_loop1
    wai
    jsr S1B_starScroll
    jsr S1B_FS_controlShip

    lda ENM_18_magica
    cmp #$00
    beq S1B_FS_w1_tToC_disableSmiley
    cmp #$02
    beq S1B_FS_w1_tToC_disableSmiley
    lda #$48                    ; enable evil smiley
    sta SPRBUF1+SFRAME13
    lda #$4c
    sta SPRBUF1+SFRAME14
    lda #$80
    sta SPRBUF1+SFRAME15
    lda #$84
    sta SPRBUF1+SFRAME16
    jmp S1B_FS_w1_tToC_cont
S1B_FS_w1_tToC_disableSmiley
    lda #$8c                    ; disable evil smiley
    sta SPRBUF1+SFRAME13
    sta SPRBUF1+SFRAME14
    sta SPRBUF1+SFRAME15
    sta SPRBUF1+SFRAME16


S1B_FS_w1_tToC_cont
    inc ENM_18_magica
    lda ENM_18_magica
    cmp #$03
    bne S1B_FS_w1_tToC_cont2
    stz ENM_18_magica

S1B_FS_w1_tToC_cont2
    dec a_byte
    lda a_byte
    cmp #$00
    bne S1B_FS_w1_teleportToCenter_loop1

    lda #$40
    sta a_byte                  ; counter

    lda #$8c                    ; disable evil smiley
    sta SPRBUF1+SFRAME13
    sta SPRBUF1+SFRAME14
    sta SPRBUF1+SFRAME15
    sta SPRBUF1+SFRAME16

; ARTISTIC SMILEY REST
; --------------------

S1B_FS_w1_teleportToCenter_paws

    wai
    jsr S1B_starScroll
    jsr S1B_FS_controlShip
    dec a_byte
    lda a_byte
    cmp #$00
    bne S1B_FS_w1_teleportToCenter_paws


; BLINK HIM/IT (whatever) IN
; Secret fact: evilSmiley equ drS

S1B_FS_w1_teleportToCenter2
    lda #$60
    sta a_byte                  ; counter
    stz ENM_18_magica

    lda #$90                    ; reset evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$B0
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16

    lda #$70                    ; reset evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$90
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16

    jsl sym_SFX_INTERFERENCE

S1B_FS_w1_teleportToCenter_loop2
    wai
    jsr S1B_starScroll
    jsr S1B_FS_controlShip

    lda ENM_18_magica
    cmp #$00
    beq S1B_FS_w1_tToC2_disableSmiley
    cmp #$02
    beq S1B_FS_w1_tToC2_disableSmiley
    lda #$48                    ; enable evil smiley
    sta SPRBUF1+SFRAME13
    lda #$4c
    sta SPRBUF1+SFRAME14
    lda #$80
    sta SPRBUF1+SFRAME15
    lda #$84
    sta SPRBUF1+SFRAME16
    jmp S1B_FS_w1_tToC2_cont
S1B_FS_w1_tToC2_disableSmiley
    lda #$8c                    ; disable evil smiley
    sta SPRBUF1+SFRAME13
    sta SPRBUF1+SFRAME14
    sta SPRBUF1+SFRAME15
    sta SPRBUF1+SFRAME16


S1B_FS_w1_tToC2_cont
    inc ENM_18_magica
    lda ENM_18_magica
    cmp #$03
    bne S1B_FS_w1_tToC2_cont2
    stz ENM_18_magica

S1B_FS_w1_tToC2_cont2
    dec a_byte
    lda a_byte
    cmp #$00
    bne S1B_FS_w1_teleportToCenter_loop2


    ; randomly refill SMILEY_TIMER

    lda #$40
    sta ENM_13_magica
    ldx #$0000
    ldx ENM_13_wait
S1B_FS_w1_SMTimerRefillLoop
    inc ENM_13_magica
    dex
    cpx #$0000
    bne S1B_FS_w1_SMTimerRefillLoop

    ;-------------
    ; "listen to ze woids of ENM_16_hp"
    ; A pretty random way to choose between the different
    ; ghastly Smiley punishment techniques.

    lda ENM_16_hp
    cmp #$01
    beq S1B_FS_w1_SMPunishMode02
    cmp #$02
    beq S1B_FS_w1_SMPunishMode03
    cmp #$03
    beq S1B_FS_w1_SMPunishMode02
    cmp #$07
    beq S1B_FS_w1_SMPunishMode02

    jsr S1B_w1_SMProj_START     ; mode01: parade of the projectiles
    jmp S1B_w1_apeturISkogen

S1B_FS_w1_SMPunishMode02
    jsr S1B_w1_SMProj2_START    ; mode02: asteroid bullies
    jmp S1B_w1_apeturISkogen

S1B_FS_w1_SMPunishMode03
    jsr S1B_w1_SMProj3_START    ; mode03: twinbee mayhem

    ;-------------
S1B_w1_apeturISkogen

    lda #$48                    ; enable evil smiley
    sta SPRBUF1+SFRAME13
    lda #$4c
    sta SPRBUF1+SFRAME14
    lda #$80
    sta SPRBUF1+SFRAME15
    lda #$84
    sta SPRBUF1+SFRAME16

    jmp S1B_FS_w1_loopMain



;================================
;================================

; UNIVERSAL ROUTINE
S1B_pause                       ; *nyan*
    lda #$0e
    sta $2100
    wai
    wai
    lda #$0d
    sta $2100
    wai
    wai
    lda #$0c
    sta $2100
    wai
    wai
    lda #$0b
    sta $2100
    wai
    wai
    lda #$0a
    sta $2100
    wai
    wai
    lda #$09
    sta $2100
    wai
    wai
    lda #$08
    sta $2100
    wai
    wai
    rtl

S1B_unpause
    lda #$09
    sta $2100
    wai
    wai
    lda #$0a
    sta $2100
    wai
    wai
    lda #$0b
    sta $2100
    wai
    wai
    lda #$0c
    sta $2100
    wai
    wai
    lda #$0d
    sta $2100
    wai
    wai
    lda #$0e
    sta $2100
    wai
    wai
    lda #$0f
    sta $2100
    wai
    wai
    rtl


sym_boss1Clear
    jmp boss1Clear

; user input for the ship

S1B_FS_controlShip
;=================
    lda ENM_13_hp
;   cmp #$11                   ; tåler kun ett slag
    cmp #$06
    beq sym_boss1Clear

    lda shipInvulnerable
    cmp #$00
    beq S1B_FS_BLUEBLOOD
    jsl INVULNERABILITY_COUNTDOWN

S1B_FS_BLUEBLOOD
    jsr S1B_FS_CS_e16HP_incie
    jsr S1B_w1_CrashSFXRandomise

    inc ENM_15_wait             ; SHIP hiccup
    lda ENM_15_wait
    cmp #$03
    bne S1B_FS_CS_motorProb
    stz ENM_15_wait

    lda joy1+1                  ; check start button
    and #$10
    beq S1B_FS_CS_motorProb
    jsl S1B_pause
S1B_FS_pauseLoop
    wai
    lda joy1+1                  ; check start button
    and #$10
    beq S1B_FS_pauseLoop
    jsl S1B_unpause

S1B_FS_CS_motorProb

    lda ENM_16_wait             ; SHIP motor prob
    cmp #$03
    beq S1B_FS_CS_motorProb03
    cmp #$02
    beq S1B_FS_CS_motorProb02
    cmp #$01
    beq S1B_FS_CS_motorProb01
    jmp S1B_FS_CS_motorProb00
S1B_FS_CS_motorProb03
    dec SPRBUF1+SX12
    jmp S1B_FS_CS_chkUP
S1B_FS_CS_motorProb02
    inc SPRBUF1+SY12
    jmp S1B_FS_CS_chkUP
S1B_FS_CS_motorProb01
    inc SPRBUF1+SX12
    jmp S1B_FS_CS_chkUP
S1B_FS_CS_motorProb00
    dec SPRBUF1+SY12


S1B_FS_CS_chkUP

    lda joy1+1                  ; is UP pressed?
    and #$08
    beq S1B_FS_CS_chkDOWN       ; branch if not pressed

    lda ENM_15_wait             ; simulate motor hiccups
    cmp #$02
    beq S1B_FS_CS_UP02
    cmp #$01
    beq S1B_FS_CS_UP01
    jmp S1B_FS_CS_UP00
S1B_FS_CS_UP02
    dec SPRBUF1+SY12
    dec SPRBUF1+SY12
S1B_FS_CS_UP01
    dec SPRBUF1+SY12
S1B_FS_CS_UP00
    jmp S1B_FS_CS_chkLEFT


S1B_FS_CS_chkDOWN

    lda joy1+1                  ; is DOWN pressed?
    and #$04
    beq S1B_FS_CS_chkLEFT       ; branch if not pressed

    lda ENM_15_wait             ; simulate motor hiccups
    cmp #$02
    beq S1B_FS_CS_DOWN02
    cmp #$01
    beq S1B_FS_CS_DOWN01
    jmp S1B_FS_CS_chkLEFT
S1B_FS_CS_DOWN02
    inc SPRBUF1+SY12
    inc SPRBUF1+SY12
S1B_FS_CS_DOWN01
    inc SPRBUF1+SY12


S1B_FS_CS_chkLEFT

    lda joy1+1                  ; is LEFT pressed?
    and #$02
    beq S1B_FS_CS_chkRIGHT      ; branch if not pressed

    lda ENM_15_wait             ; simulate motor hiccups
    cmp #$02
    beq S1B_FS_CS_LEFT02
    cmp #$01
    beq S1B_FS_CS_LEFT01
    jmp S1B_FS_CS_LEFT00
S1B_FS_CS_LEFT02
    dec SPRBUF1+SX12
    dec SPRBUF1+SX12
S1B_FS_CS_LEFT01
    dec SPRBUF1+SX12
S1B_FS_CS_LEFT00
    jsr S1B_FS_CS_e16HP_incie
    jmp S1B_FS_CS_chkXABY


S1B_FS_CS_chkRIGHT

    lda joy1+1                  ; is RIGHT pressed?
    and #$01
    beq S1B_FS_CS_chkXABY       ; branch if not pressed

    lda ENM_15_wait             ; simulate motor hiccups
    cmp #$02
    beq S1B_FS_CS_RIGHT02
    cmp #$01
    beq S1B_FS_CS_RIGHT01
    jmp S1B_FS_CS_chkXABY
S1B_FS_CS_RIGHT02
    inc SPRBUF1+SX12
    inc SPRBUF1+SX12
S1B_FS_CS_RIGHT01
    inc SPRBUF1+SX12
    jsr S1B_FS_CS_e16HP_incie
    jsr S1B_FS_CS_e16HP_incie
    jsr S1B_FS_CS_e16HP_incie

S1B_FS_CS_chkXABY
;================

    lda ENM_15_alive
    cmp #$20
    beq S1B_FS_CS_daggerInUse
    cmp #$1f
    beq S1B_FS_CS_daggerInUse
    cmp #$1e
    beq S1B_FS_CS_daggerInUse
    cmp #$1d
    beq S1B_FS_CS_daggerInUse
    jmp S1B_FS_CS_daggerNotInUse

S1B_FS_CS_daggerInUse
    lda #$01
    sta ENM_13_alive            ; SHIP DAGG-R on
    lda #$88
    sta SPRBUF1+SFRAME11        ; DAGG-R sprite
    jmp S1B_FS_CS_daggerCRAPCRAPCRAP

S1B_FS_CS_daggerNotInUse
    stz ENM_13_alive            ; SHIP DAGG-R off
    lda #$8c
    sta SPRBUF1+SFRAME11        ; invisible sprite

S1B_FS_CS_daggerCRAPCRAPCRAP

    lda ENM_15_alive
    cmp #$00
    beq S1B_FS_CS_chkXABY_chkY

    dec ENM_15_alive
    lda ENM_15_alive
    cmp #$00
    beq S1B_FS_CS_chkXABY_chkY
    jmp S1B_FS_CS_chkXABY_notY

S1B_FS_CS_chkXABY_chkY

    ; check the Y button
    lda joy1+1
    and #$40
    beq S1B_FS_CS_chkXABY_notY  ; branch if not pressed
    lda #$01
    sta ENM_13_alive            ; enable SHIP DAGG-R
    jsl sym_SFX_DING_A_LING_HIGH
    jsr S1B_FS_CS_e16HP_incie
    jsr S1B_FS_CS_e16HP_incie
    lda #$88
    sta SPRBUF1+SFRAME11        ; display DAGG-R
    lda #$20
    sta ENM_15_alive            ; set SHIP DAGG-R delay


S1B_FS_CS_chkXABY_notY

    inc ENM_16_wait             ; SHIP motor prob reset if == $04
    lda ENM_16_wait
    cmp #$04
    bne S1B_FS_CS_chkObstructions
    stz ENM_16_wait


S1B_FS_CS_chkObstructions

    lda SPRBUF1+SY12
    cmp #$38
    beq S1B_FS_CS_ObsFixUP
    cmp #$37
    beq S1B_FS_CS_ObsFixUP
    cmp #$36
    beq S1B_FS_CS_ObsFixUP
    cmp #$35
    beq S1B_FS_CS_ObsFixUP
    cmp #$34
    beq S1B_FS_CS_ObsFixUP
    jmp S1B_FS_CS_ObschkDOWN

S1B_FS_CS_ObsFixUP
    lda #$39
    sta SPRBUF1+SY12
    jmp S1B_FS_CS_ObschkLEFT



S1B_FS_CS_ObschkDOWN

    lda SPRBUF1+SY12
    cmp #$C4
    beq S1B_FS_CS_ObsFixDOWN
    cmp #$C5
    beq S1B_FS_CS_ObsFixDOWN
    cmp #$C6
    beq S1B_FS_CS_ObsFixDOWN
    cmp #$C7
    beq S1B_FS_CS_ObsFixDOWN
    cmp #$C8
    beq S1B_FS_CS_ObsFixDOWN
    jmp S1B_FS_CS_ObschkLEFT

S1B_FS_CS_ObsFixDOWN
    lda #$C3
    sta SPRBUF1+SY12



S1B_FS_CS_ObschkLEFT

    lda SPRBUF1+SX12
    cmp #$23
    beq S1B_FS_CS_ObsFixLEFT
    cmp #$22
    beq S1B_FS_CS_ObsFixLEFT
    cmp #$21
    beq S1B_FS_CS_ObsFixLEFT
    cmp #$20
    beq S1B_FS_CS_ObsFixLEFT
    cmp #$1f
    beq S1B_FS_CS_ObsFixLEFT
    jmp S1B_FS_CS_ObschkRIGHT

S1B_FS_CS_ObsFixLEFT
    lda #$24
    sta SPRBUF1+SX12
    jmp S1B_FS_CS_rts



S1B_FS_CS_ObschkRIGHT

    lda SPRBUF1+SX12
    cmp #$BE
    beq S1B_FS_CS_ObsFixRIGHT
    cmp #$BF
    beq S1B_FS_CS_ObsFixRIGHT
    cmp #$C0
    beq S1B_FS_CS_ObsFixRIGHT
    cmp #$C1
    beq S1B_FS_CS_ObsFixRIGHT
    cmp #$C2
    beq S1B_FS_CS_ObsFixRIGHT
    jmp S1B_FS_CS_rts

S1B_FS_CS_ObsFixRIGHT
    lda #$BD
    sta SPRBUF1+SX12

; etc...


S1B_FS_CS_rts

    lda SPRBUF1+SY12            ; keep DAGG-R up-to-date with SHIP
    sta SPRBUF1+SY11
    lda SPRBUF1+SX12
    sta SPRBUF1+SX11
    ldx #$001f
S1B_FS_CS_daggr_equ_shipPosLoopy
    inc SPRBUF1+SX11
    dex
    cpx #$0000
    bne S1B_FS_CS_daggr_equ_shipPosLoopy


S1B_FS_CS_rts_for_real ;-)

    ; DEBUG
;   GOTOXY 8,6
;   jsl DEBUG_ENM13A
;   GOTOXY 9,6
;   jsl DEBUG_ENM14A
;   GOTOXY 10,6
;   jsl DEBUG_ENM15A

    rts


S1B_FS_CS_e16HP_incie
    inc ENM_16_hp               ; "random" SMILEY coords pattern
    lda ENM_16_hp
    cmp #$08
    bne S1B_FS_CS_e16HP_skip
    stz ENM_16_hp
S1B_FS_CS_e16HP_skip
    rts

;=================================================================


; checks detection between DAGG-R and smiley
; return value stored in ENM_14_magica (smileyIsHit)

S1B_FS_w1_DAGGRhitDetect

    lda ENM_13_alive            ; is DAGG-R in use?
    cmp #$00
    beq sym_S1B_FS_w1_DAGGRhitDetect_rts
    jmp S1B_FS_w1_DAGGRhitDetect_OK
sym_S1B_FS_w1_DAGGRhitDetect_rts
    jmp S1B_FS_w1_DAGGRhitDetect_rts


; DAGG-R is enabled, so let's check it out!
S1B_FS_w1_DAGGRhitDetect_OK
;=====
    ; calculate smiley x2 & y2

    lda SPRBUF1+SX13
    sta ENM_16_alive            ; temp SMILEY X2
    ldx #$0040
S1B_FS_s1_DAGGRhD_stX2
    inc ENM_16_alive
    dex
    cpx #$0000
    bne S1B_FS_s1_DAGGRhD_stX2

    lda SPRBUF1+SY13
    sta ENM_17_alive            ; temp SMILEY Y2
    ldx #$0040
S1B_FS_s1_DAGGRhD_stY2
    inc ENM_17_alive
    dex
    cpx #$0000
    bne S1B_FS_s1_DAGGRhD_stY2

    ; calculate DAGG-R y, x2 & y2

    lda SPRBUF1+SY11
    sta ENM_14_alive            ; temp DAGG-R Y
    ldx #$0012
S1B_FS_s1_DAGGRhD_dtY
    inc ENM_14_alive
    dex
    cpx #$0000
    bne S1B_FS_s1_DAGGRhD_dtY

    lda SPRBUF1+SX11
    sta ENM_17_wait             ; temp DAGG-R X2
    ldx #$0009
S1B_FS_s1_DAGGRhD_dtX2
    inc ENM_17_wait
    dex
    cpx #$0000
    bne S1B_FS_s1_DAGGRhD_dtX2

.ENDASM
    lda SPRBUF1+SY11
    sta ENM_18_wait             ; temp DAGG-R Y2
    ldx #$0020
S1B_FS_s1_DAGGRhD_dtY2
    inc ENM_18_wait
    dex
    cpx #$0000
    bne S1B_FS_s1_DAGGRhD_dtY2
.ASM
    lda ENM_14_alive
    sta ENM_18_wait             ; temp DAGG-R Y2
    inc ENM_18_wait
    inc ENM_18_wait

;.X
;   if((daggr.x >= sm.x) && (daggr.x <= sm.x2) &&
;      (daggr.y >= sm.y) && (daggr.y <= sm.y2))

;======
; CHECK IF EITHER X,Y,X2,Y2 OF DAGG-R IS INSIDE OF SMILEY
;======

S1B_w1_tc_00
    stz hd_coll
    stz hd_colc                 ; to be inc'ed if suspicious, yup!
S1B_w1_tc_01                    ; is upper left corner colliding?
    lda SPRBUF1+SX11            ; ul x-wise
    cmp SPRBUF1+SX13
    bpl S1B_w1_tc_01a
    jmp S1B_w1_tc_02
S1B_w1_tc_01a
    inc hd_colc
S1B_w1_tc_02
    lda SPRBUF1+SX11
    cmp ENM_16_alive            ; ~ temp SMILEY X2
    bmi S1B_w1_tc_02a
    jmp S1B_w1_tc_03
S1B_w1_tc_02a
    inc hd_colc
S1B_w1_tc_03
    lda ENM_14_alive            ; ul y-wise
    cmp SPRBUF1+SY13
    bpl S1B_w1_tc_03b
    jmp S1B_w1_tc_04
S1B_w1_tc_03b
    inc hd_colc
S1B_w1_tc_04
    lda ENM_14_alive            ; ~ temp DAGG-R Y
    cmp ENM_17_alive            ; ~ temp SMILEY Y2
    bmi S1B_w1_tc_04a
    jmp S1B_w1_tc_05
S1B_w1_tc_04a
    inc hd_colc
S1B_w1_tc_05                    ; ARTISTIC NICE BREAK
    lda hd_colc
    cmp #$04
    bne S1B_w1_tc_05a
    inc hd_coll
S1B_w1_tc_05a
    stz hd_colc
S1B_w1_tc_06                    ; is upper right corner colliding?
    lda ENM_17_wait             ; ur x-wise
    cmp SPRBUF1+SX13
    bpl S1B_w1_tc_06a
    jmp S1B_w1_tc_07
S1B_w1_tc_06a
    inc hd_colc
S1B_w1_tc_07
    lda ENM_17_wait             ; ~ temp DAGG-R X2
    cmp ENM_16_alive            ; ~ temp SMILEY X2
    bmi S1B_w1_tc_07a
    jmp S1B_w1_tc_08
S1B_w1_tc_07a
    inc hd_colc
S1B_w1_tc_08
    lda ENM_14_alive            ; ur y-wise
    cmp SPRBUF1+SY13
    bpl S1B_w1_tc_08a
    jmp S1B_w1_tc_09
S1B_w1_tc_08a
    inc hd_colc
S1B_w1_tc_09
    lda ENM_14_alive            ; ~ temp DAGG-R Y
    cmp ENM_17_alive            ; ~ temp SMILEY Y2
    bmi S1B_w1_tc_09a
    jmp S1B_w1_tc_0A
S1B_w1_tc_09a
    inc hd_colc
S1B_w1_tc_0A                    ; IT'S TIME FOR MORE JOLLY BEER!
    lda hd_colc
    cmp #$04
    bne S1B_w1_tc_0Aa
    inc hd_coll
S1B_w1_tc_0Aa
    stz hd_colc
S1B_w1_tc_0B                    ; is lower left corner colliding?
    lda SPRBUF1+SX11            ; ll x-wise
    cmp SPRBUF1+SX13
    bpl S1B_w1_tc_0Ba
    jmp S1B_w1_tc_0C
S1B_w1_tc_0Ba
    inc hd_colc
S1B_w1_tc_0C
    lda SPRBUF1+SX11
    cmp ENM_16_alive            ; ~ temp SMILEY X2
    bmi S1B_w1_tc_0Ca
    jmp S1B_w1_tc_0D
S1B_w1_tc_0Ca
    inc hd_colc
S1B_w1_tc_0D                    ; ll y-wise
    lda ENM_18_wait             ; ~ temp DAGG-R Y2
    cmp SPRBUF1+SY13
    bpl S1B_w1_tc_0Da
    jmp S1B_w1_tc_0E
S1B_w1_tc_0Da
    inc hd_colc
S1B_w1_tc_0E
    lda ENM_18_wait             ; ~ temp DAGG-R Y2
    cmp ENM_17_alive            ; ~ temp SMILEY Y2
    bmi S1B_w1_tc_0Ea
    jmp S1B_w1_tc_0F
S1B_w1_tc_0Ea
    inc hd_colc
S1B_w1_tc_0F                    ; IT'S TIME FOR RIVERSI KIDS !!! :-)
    lda hd_colc
    cmp #$04
    bne S1B_w1_tc_0Fa
    inc hd_coll
S1B_w1_tc_0Fa
    stz hd_colc
S1B_w1_tc_10                    ; is lower right corner colliding?
    ; lr x-wise
    lda ENM_17_wait             ; ~ temp DAGG-R X2
    cmp SPRBUF1+SX13
    bpl S1B_w1_tc_10a
    jmp S1B_w1_tc_11
S1B_w1_tc_10a
    inc hd_colc
S1B_w1_tc_11
    lda ENM_17_wait             ; ~ temp DAGG-R X2
    cmp ENM_16_alive            ; ~ temp SMILEY X2
    bmi S1B_w1_tc_11a
    jmp S1B_w1_tc_12
S1B_w1_tc_11a
    inc hd_colc
S1B_w1_tc_12                    ; lr y-wise
    lda ENM_18_wait             ; ~ temp DAGG-R Y2
    cmp SPRBUF1+SY13
    bpl S1B_w1_tc_12a
    jmp S1B_w1_tc_13
S1B_w1_tc_12a
    inc hd_colc
S1B_w1_tc_13
    lda ENM_18_wait             ; ~ temp DAGG-R Y2
    cmp ENM_17_alive            ; ~ temp SMILEY Y2
    bmi S1B_w1_tc_13a
    jmp S1B_w1_tc_14
S1B_w1_tc_13a
    inc hd_colc
S1B_w1_tc_14
    lda hd_colc
    cmp #$04
    bne S1B_w1_tc_ff
    inc hd_coll
S1B_w1_tc_ff
    stz hd_colc
    lda hd_coll
    cmp #$00
    beq S1B_w1_tc_ffx2          ; no collision!
    jsr S1B_w1_randomCrashSFX   ; COLLISION !!!
    ldy #$0001
    sty score_100
    ldy #$0002
    sty score_10
    ldy #$0005
    sty score_1
    jsl ADD_SCORE
    jsl UPDATE_SCORE
    jsl S1B_w1_decreaseFoeHeart

    lda #$01
    sta ENM_14_magica           ; smileyIsHit = TRUE

    lda ENM_15_magica           ; SMILEY_DIR (0=UP,1=DOWN)
    cmp #$00
    beq S1B_w1_tc_ffSMDDOWN

    stz ENM_15_magica
    jmp S1B_FS_w1_DAGGRhitDetect_rts
S1B_w1_tc_ffSMDDOWN
    lda #$01
    sta ENM_15_magica           ; SMILEY_DIR = DOWN
    jmp S1B_FS_w1_DAGGRhitDetect_rts

S1B_w1_tc_ffx2
    stz ENM_14_magica           ; smileyIsHit = FALSE

S1B_FS_w1_DAGGRhitDetect_rts
    rts




S1B_w1_randomCrashSFX

    inc ENM_18_alive            ; w1_randomCrashSFX
    lda ENM_18_alive
    cmp #$02
    beq S1B_w1_CrashSFXR02
    cmp #$01
    beq S1B_w1_CrashSFXR01
    jmp S1B_w1_CrashSFXR00

S1B_w1_CrashSFXR02
    jsl sym_SFX_EXPLOSION
    rts
S1B_w1_CrashSFXR01
    jsl sym_SFX_GLASS_SMASH
    rts
S1B_w1_CrashSFXR00
    jsl sym_SFX_INTERFERENCE
    rts



S1B_w1_CrashSFXRandomise

    inc ENM_18_alive            ; w1_randomCrashSFX
    lda ENM_18_alive
    cmp #$03
    bne S1B_w1_CrashSFXRandomise_zutZut

    stz ENM_18_alive            ; reset that var, bitch!

S1B_w1_CrashSFXRandomise_zutZut
    rts



;================================
; EVIL SMILEY PROJECTILE HANDLING
;================================
; S1B_w1_SMProj_*


; jsr this one to make it all happen :)
S1B_w1_SMProj_START

    lda #$FF
    sta ENM_14_hp               ; SMILEY projectile time
    stz ENM_15_hp               ; SMILEY projectile flip order

    lda #$A2 ; 162
    sta SPRBUF1+SX20            ; sprbuf2+5
    sta SPRBUF1+SX21
    sta SPRBUF1+SX22
    sta SPRBUF1+SX23
    sta SPRBUF1+SX24            ; sprbuf2+6
    sta SPRBUF1+SX25
    sta SPRBUF1+SX26
    sta SPRBUF1+SX27
    sta SPRBUF1+SX28            ; sprbuf2+7

    lda #$80 ; 128
    sta SPRBUF1+SY20            ; sprbuf2+5
    sta SPRBUF1+SY21
    sta SPRBUF1+SY22
    sta SPRBUF1+SY23
    sta SPRBUF1+SY24            ; sprbuf2+6
    sta SPRBUF1+SY25
    sta SPRBUF1+SY26
    sta SPRBUF1+SY27
    sta SPRBUF1+SY28            ; sprbuf2+7

    ; set frame
    lda #$CC
    sta SPRBUF1+SFRAME20
    sta SPRBUF1+SFRAME21
    sta SPRBUF1+SFRAME22
    sta SPRBUF1+SFRAME23
    sta SPRBUF1+SFRAME24
    sta SPRBUF1+SFRAME25
    sta SPRBUF1+SFRAME26
    sta SPRBUF1+SFRAME27
    sta SPRBUF1+SFRAME28

    stz SPRBUF2+5               ; enable sprites 20-28
    stz SPRBUF2+6
    lda #%11111100
    sta SPRBUF2+7

    jsl sym_SFX_GLASS_SMASH
    wai
    jsl sym_SFX_GLASS_SMASH
    wai
    jsl sym_SFX_GLASS_SMASH
    wai
    jsl sym_SFX_GLASS_SMASH
    wai
    jsl sym_SFX_GLASS_SMASH
    wai
    jsl sym_SFX_GLASS_SMASH
    wai
    jsl sym_SFX_GLASS_SMASH
    wai
    jsl sym_SFX_GLASS_SMASH
    wai
    jsl sym_SFX_GLASS_SMASH
    wai



S1B_w1_SMProj_doYourThong

    wai
    jsr S1B_chkShipProjColl
    jsr S1B_w1_SMProj_flippy
    jsr S1B_FS_controlShip
    jsr S1B_starScroll

    dec SPRBUF1+SY20            ; y-1

    dec SPRBUF1+SX21            ; x-1, y-1
    dec SPRBUF1+SY21

    dec SPRBUF1+SX22            ; x-2, y-1
    dec SPRBUF1+SX22
    dec SPRBUF1+SY22

    dec SPRBUF1+SX23            ; x-3, y-1
    dec SPRBUF1+SX23
    dec SPRBUF1+SX23
    dec SPRBUF1+SY23

    dec SPRBUF1+SX24            ; x-1

    dec SPRBUF1+SX25            ; x-3, y+1
    dec SPRBUF1+SX25
    dec SPRBUF1+SX25
    inc SPRBUF1+SY25

    dec SPRBUF1+SX26            ; x-2, y+1
    dec SPRBUF1+SX26
    inc SPRBUF1+SY26

    dec SPRBUF1+SX27            ; x-1, y+1
    inc SPRBUF1+SY27

    inc SPRBUF1+SY28            ; y+1

    jsr S1B_w1_SMProj_blinkSM

    dec ENM_14_hp                 ; SMILEY projectile time
    lda ENM_14_hp
    cmp #$00                      ; are we done yet?
    bne S1B_w1_SMProj_doYourThong ; no!
    lda #$FF                      ; YES!!
    sta SPRBUF2+5                 ; disable sprites 20-28
    sta SPRBUF2+6
    sta SPRBUF2+7
    stz ENM_14_hp                 ; SMILEY projectile time

    lda #$3f
    sta a_byte2                   ; temp. loop countdown timer (tm)
S1B_w1_SMProj_aftMth_p1loop       ; continue with the Smiley blinking!
    wai
    jsr S1B_FS_controlShip
    jsr S1B_starScroll
    jsr S1B_w1_SMProj_blinkSM
    dec a_byte2
    lda a_byte2
    cmp #$00
    bne S1B_w1_SMProj_aftMth_p1loop   ; branch if not zero

    lda #$8c                    ; disable evil smiley
    sta SPRBUF1+SFRAME13
    sta SPRBUF1+SFRAME14
    sta SPRBUF1+SFRAME15
    sta SPRBUF1+SFRAME16

    jsr S1B_w1_SMProj_randSMcoords  ; get new ("random") coords for Big S.

    lda #$3f
    sta a_byte2                   ; temp. loop countdown timer (tm)
S1B_w1_SMProj_aftMth_p2loop       ; Blinkety-blink Smiley
    wai
    jsr S1B_FS_controlShip
    jsr S1B_starScroll
    jsr S1B_w1_SMProj_blinkSM
    dec a_byte2
    lda a_byte2
    cmp #$00
    bne S1B_w1_SMProj_aftMth_p2loop   ; branch if not zero

    rts ; RTS with big letterz 'n shit, yo!



S1B_w1_SMProj_flippy

    inc ENM_15_hp               ; SMILEY projectile flip
    lda ENM_15_hp
    cmp #$04
    beq S1B_w1_SMProj_flippyReset
    jmp S1B_w1_SMProj_flippyGOGO
S1B_w1_SMProj_flippyReset
    stz ENM_15_hp
S1B_w1_SMProj_flippyGOGO
    lda ENM_15_hp
    cmp #$03
    beq S1B_w1_SMProj_fl03
    cmp #$02
    beq S1B_w1_SMProj_fl02
    cmp #$01
    beq S1B_w1_SMProj_fl01

    lda #$00
    jsr S1B_w1_SMProj_flSTA
    jmp S1B_w1_SMProj_flDone
S1B_w1_SMProj_fl03
    lda #%10000000
    jsr S1B_w1_SMProj_flSTA
    jmp S1B_w1_SMProj_flDone
S1B_w1_SMProj_fl02
    lda #%11000000
    jsr S1B_w1_SMProj_flSTA
    jmp S1B_w1_SMProj_flDone
S1B_w1_SMProj_fl01
    lda #%01000000
    jsr S1B_w1_SMProj_flSTA
    jmp S1B_w1_SMProj_flDone
S1B_w1_SMProj_flSTA
    sta SPRBUF1+SPRIORITY20
    sta SPRBUF1+SPRIORITY21
    sta SPRBUF1+SPRIORITY22
    sta SPRBUF1+SPRIORITY23
    sta SPRBUF1+SPRIORITY24
    sta SPRBUF1+SPRIORITY25
    sta SPRBUF1+SPRIORITY26
    sta SPRBUF1+SPRIORITY27
    sta SPRBUF1+SPRIORITY28
S1B_w1_SMProj_flDone
    rts
    


S1B_w1_SMProj_blinkSM

    lda ENM_18_magica
    cmp #$00
    beq S1B_SMProj_tToC2_disableSmiley
    cmp #$02
    beq S1B_SMProj_tToC2_disableSmiley
    lda #$48                    ; enable evil smiley
    sta SPRBUF1+SFRAME13
    lda #$4c
    sta SPRBUF1+SFRAME14
    lda #$80
    sta SPRBUF1+SFRAME15
    lda #$84
    sta SPRBUF1+SFRAME16
    jmp S1B_SMProj_tToC2_cont
S1B_SMProj_tToC2_disableSmiley
    lda #$8c                    ; disable evil smiley
    sta SPRBUF1+SFRAME13
    sta SPRBUF1+SFRAME14
    sta SPRBUF1+SFRAME15
    sta SPRBUF1+SFRAME16


S1B_SMProj_tToC2_cont
    inc ENM_18_magica
    lda ENM_18_magica
    cmp #$03
    bne S1B_SMProj_tToC2_cont2
    stz ENM_18_magica

S1B_SMProj_tToC2_cont2
    rts


;---------------


S1B_w1_SMProj_randSMcoords

;   GOTOXY 20,10
;   jsl bH0_ZeDEBUGNumbah

    lda ENM_16_hp               ; "random" SMILEY coords pattern
    cmp #$07
    beq S1B_w1_SMP_rSMc_07
    cmp #$06
    beq S1B_w1_SMP_rSMc_06
    cmp #$05
    beq sym_S1B_w1_SMP_rSMc_05
    cmp #$04
    beq sym_S1B_w1_SMP_rSMc_04
    cmp #$03
    beq sym_S1B_w1_SMP_rSMc_03
    cmp #$02
    beq sym_S1B_w1_SMP_rSMc_02
    cmp #$01
    beq sym_S1B_w1_SMP_rSMc_01

    ; default:
    lda #$90                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$B0
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16
    lda #$70                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$90
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16
    jmp S1B_w1_SMP_rSMc_ff

sym_S1B_w1_SMP_rSMc_05
    jmp S1B_w1_SMP_rSMc_05
sym_S1B_w1_SMP_rSMc_04
    jmp S1B_w1_SMP_rSMc_04
sym_S1B_w1_SMP_rSMc_03
    jmp S1B_w1_SMP_rSMc_03
sym_S1B_w1_SMP_rSMc_02
    jmp S1B_w1_SMP_rSMc_02
sym_S1B_w1_SMP_rSMc_01
    jmp S1B_w1_SMP_rSMc_01

S1B_w1_SMP_rSMc_07
    lda #$5f                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$7f
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16
    lda #$91                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$B1
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16
    jmp S1B_w1_SMP_rSMc_ff

S1B_w1_SMP_rSMc_06
    lda #$3d                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$5d
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16
    lda #$71                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$91
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16
    jmp S1B_w1_SMP_rSMc_ff

S1B_w1_SMP_rSMc_05
    lda #$96                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$B6
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16
    lda #$47                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$67
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16
    jmp S1B_w1_SMP_rSMc_ff

S1B_w1_SMP_rSMc_04
    lda #$25                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$45
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16
    lda #$9a                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$BA
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16
    jmp S1B_w1_SMP_rSMc_ff

S1B_w1_SMP_rSMc_03
    lda #$97                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$B7
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16
    lda #$99                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$B9
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16
    jmp S1B_w1_SMP_rSMc_ff

S1B_w1_SMP_rSMc_02
    lda #$5e                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$7e
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16
    lda #$4b                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$6b
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16
    jmp S1B_w1_SMP_rSMc_ff

S1B_w1_SMP_rSMc_01
    lda #$2a                    ; setup evil smiley x coords
    sta SPRBUF1+SX13
    sta SPRBUF1+SX15
    lda #$4a
    sta SPRBUF1+SX14
    sta SPRBUF1+SX16
    lda #$45                    ; setup evil smiley y coords
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$65
    sta SPRBUF1+SY15
    sta SPRBUF1+SY16
    jmp S1B_w1_SMP_rSMc_ff


S1B_w1_SMP_rSMc_ff
    rts


;-----------------------------------------
; ************* SMProj mode02: ***************
;-----------------------------------------

S1B_w1_SMProj2_START

;   sta ENM_14_hp               ; SMILEY projectile time
    stz ENM_15_hp               ; SMILEY projectile flip order

    ; set up "asteroid bully" #1 out of 6

    lda #$D5                    ; #213
    sta SPRBUF1+SX20
    lda #$06
    sta SPRBUF1+SY20
    lda #$7f
    sta ENM_14_hp               ; SMILEY projectile time
    stz a_byte2                 ; projectile move pattern

    lda #%11111100
    sta SPRBUF2+5
    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj2_BULLYloop

    ; go on, laddsy!

    lda #$01
    sta SPRBUF1+SX20
    lda #$B1                    ; #177
    sta SPRBUF1+SY20
    lda #$CC
    sta SPRBUF1+SFRAME20
    lda #$3f
    sta ENM_14_hp               ; SMILEY projectile time
    lda #$01
    sta a_byte2                 ; projectile move pattern

    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj2_BULLYloop

    lda #$01
    sta SPRBUF1+SX20
    lda #$2d                    ; #45
    sta SPRBUF1+SY20
    lda #$4f
    sta ENM_14_hp               ; SMILEY projectile time
    lda #$02
    sta a_byte2                 ; projectile move pattern

    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj2_BULLYloop

    lda #$60                    ; #96
    sta SPRBUF1+SX20
    lda #$13                    ; #19
    sta SPRBUF1+SY20
    lda #$56
    sta ENM_14_hp               ; SMILEY projectile time
    lda #$03
    sta a_byte2                 ; projectile move pattern

    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj2_BULLYloop

    lda #$DF                    ; #223
    sta SPRBUF1+SX20
    lda #$92                    ; #146
    sta SPRBUF1+SY20
    lda #$56
    sta ENM_14_hp               ; SMILEY projectile time
    lda #$04
    sta a_byte2                 ; projectile move pattern

    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj2_BULLYloop
    stz SPRBUF1+SX20            ; clean-up
    stz SPRBUF1+SY20

    rts ; RTS RTS RTS :):):)

;------------
;------------
S1B_w1_SMProj2_BULLYloop
    wai
    jsr S1B_FS_controlShip
    jsr S1B_starScroll
    jsr S1B_w1_SMProj_flippy
    jsr S1B_w1_SMProj_blinkSM
    jsr S1B_w1_SMProj2_collyBolly

    lda OBJ_HIT
    cmp #$01
    bne S1B_w1_SMProj2_BLnotHit
    lda shipInvulnerable
    cmp #$00
    bne S1B_w1_SMProj2_BLnotHit
    jsl sym_SFX_EXPLOSION
    jsl HP_DROP
    

S1B_w1_SMProj2_BLnotHit

    jsr S1B_w1_SMProj2_mvPattern

    dec ENM_14_hp               ; SMILEY projectile time
    lda ENM_14_hp
    cmp #$00
    bne S1B_w1_SMProj2_BULLYloop
    rts
;------------
;------------



S1B_w1_SMProj2_mvPattern

    lda a_byte2
    cmp #$04
    beq sym_S1B_w1_SMProj2_mvP_04
    cmp #$03
    beq sym_S1B_w1_SMProj2_mvP_03
    cmp #$02
    beq sym_S1B_w1_SMProj2_mvP_02
    cmp #$01
    beq sym_S1B_w1_SMProj2_mvP_01

    ; 00
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    dec SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    dec SPRBUF1+SX20
    jmp S1B_w1_SMProj2_mvPfft


sym_S1B_w1_SMProj2_mvP_04       ; long live Sym!
    jmp S1B_w1_SMProj2_mvP_04
sym_S1B_w1_SMProj2_mvP_03
    jmp S1B_w1_SMProj2_mvP_03
sym_S1B_w1_SMProj2_mvP_02
    jmp S1B_w1_SMProj2_mvP_02
sym_S1B_w1_SMProj2_mvP_01
    jmp S1B_w1_SMProj2_mvP_01


S1B_w1_SMProj2_mvP_04
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    inc SPRBUF1+SY20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    inc SPRBUF1+SY20
    jmp S1B_w1_SMProj2_mvPfft

S1B_w1_SMProj2_mvP_03
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    jmp S1B_w1_SMProj2_mvPfft

S1B_w1_SMProj2_mvP_02
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    jmp S1B_w1_SMProj2_mvPfft

S1B_w1_SMProj2_mvP_01
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    dec SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    dec SPRBUF1+SY20


S1B_w1_SMProj2_mvPfft
    rts

;-------------

S1B_w1_SMProj2_collyBolly       ; in other words: projectile collision detection

    jsr S1B_chkSSC_doShip

    lda SPRBUF1+SX20
    sta OBJ_X2
    lda SPRBUF1+SY20
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut

    rts



;-----------------------------------------
; ************* SMProj mode03: ***************
; A little more twisted one based upon the
; previous one. A lazy programmer, I am! =^.^=
;-----------------------------------------

S1B_w1_SMProj3_START

    stz ENM_15_hp               ; SMILEY projectile flip order

    ; set up "asteroid twinbee" #1 out of 6

    lda #$D5                    ; #213
    sta SPRBUF1+SX20
    lda #$06
    sta SPRBUF1+SY20
    lda #$44
    sta SPRBUF1+SFRAME20
    lda #$7f
    sta ENM_14_hp               ; SMILEY projectile time
    lda #$03
    sta a_byte2                 ; projectile move pattern

    lda #%11111100
    sta SPRBUF2+5
    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj3_BULLYloop

    ; go on, laddsy!

    lda #$01
    sta SPRBUF1+SX20
    lda #$B1                    ; #177
    sta SPRBUF1+SY20
    lda #$3f
    sta ENM_14_hp               ; SMILEY projectile time
    lda #$02
    sta a_byte2                 ; projectile move pattern

    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj3_BULLYloop

    lda #$01
    sta SPRBUF1+SX20
    lda #$2d                    ; #45
    sta SPRBUF1+SY20
    lda #$4f
    sta ENM_14_hp               ; SMILEY projectile time
    lda #$04
    sta a_byte2                 ; projectile move pattern

    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj3_BULLYloop

    lda #$60                    ; #96
    sta SPRBUF1+SX20
    lda #$13                    ; #19
    sta SPRBUF1+SY20
    lda #$56
    sta ENM_14_hp               ; SMILEY projectile time
    lda #$01
    sta a_byte2                 ; projectile move pattern

    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj3_BULLYloop

    lda #$DF                    ; #223
    sta SPRBUF1+SX20
    lda #$92                    ; #146
    sta SPRBUF1+SY20
    lda #$56
    sta ENM_14_hp               ; SMILEY projectile time
    stz a_byte2                 ; projectile move pattern

    jsl sym_SFX_GLASS_SMASH
    jsr S1B_w1_SMProj3_BULLYloop
    stz SPRBUF1+SX20            ; clean-up
    stz SPRBUF1+SY20

    stz SPRBUF1+SX20
    stz SPRBUF1+SY20
    lda #$CC
    sta SPRBUF1+SFRAME20


    rts ; RTS RTS RTS :):):)

;------------
;------------
S1B_w1_SMProj3_BULLYloop
    wai
    jsr S1B_FS_controlShip
    jsr S1B_starScroll
    jsr S1B_w1_SMProj_flippy
    jsr S1B_w1_SMProj_blinkSM
    jsr S1B_w1_SMProj3_collyBolly

    lda OBJ_HIT
    cmp #$01
    bne S1B_w1_SMProj3_BLnotHit
    lda shipInvulnerable
    cmp #$00
    bne S1B_w1_SMProj3_BLnotHit
    jsl sym_SFX_EXPLOSION
    jsl HP_DROP
    

S1B_w1_SMProj3_BLnotHit

    jsr S1B_w1_SMProj3_mvPattern

    dec ENM_14_hp               ; SMILEY projectile time
    lda ENM_14_hp
    cmp #$00
    bne S1B_w1_SMProj3_BULLYloop
    rts
;------------
;------------



S1B_w1_SMProj3_mvPattern

    lda a_byte2
    cmp #$04
    beq sym_S1B_w1_SMProj3_mvP_04
    cmp #$03
    beq sym_S1B_w1_SMProj3_mvP_03
    cmp #$02
    beq sym_S1B_w1_SMProj3_mvP_02
    cmp #$01
    beq sym_S1B_w1_SMProj3_mvP_01

    ; 00
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    dec SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    dec SPRBUF1+SX20
    jmp S1B_w1_SMProj3_mvPfft


sym_S1B_w1_SMProj3_mvP_04       ; long live Sym!
    jmp S1B_w1_SMProj3_mvP_04
sym_S1B_w1_SMProj3_mvP_03
    jmp S1B_w1_SMProj3_mvP_03
sym_S1B_w1_SMProj3_mvP_02
    jmp S1B_w1_SMProj3_mvP_02
sym_S1B_w1_SMProj3_mvP_01
    jmp S1B_w1_SMProj3_mvP_01


S1B_w1_SMProj3_mvP_04
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    inc SPRBUF1+SY20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    dec SPRBUF1+SX20
    inc SPRBUF1+SY20
    jmp S1B_w1_SMProj3_mvPfft

S1B_w1_SMProj3_mvP_03
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    jmp S1B_w1_SMProj3_mvPfft

S1B_w1_SMProj3_mvP_02
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SY20
    jmp S1B_w1_SMProj3_mvPfft

S1B_w1_SMProj3_mvP_01
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    dec SPRBUF1+SY20
    inc SPRBUF1+SX20
    inc SPRBUF1+SX20
    dec SPRBUF1+SY20


S1B_w1_SMProj3_mvPfft
    rts

;-------------

S1B_w1_SMProj3_collyBolly       ; in other words: projectile collision detection

    jsr S1B_chkSSC_doShip

    lda SPRBUF1+SX20
    sta OBJ_X2
    lda SPRBUF1+SY20
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut

    rts



;================================
;================================


; UNIVERSAL ROUTINE
;
; call with jsl
; this routine is a "universal" one which is to be used
; for the other boss-fights as well.

S1B_w1_decreaseFoeHeart

    dec ENM_13_hp               ; dec ENM_13_hp
    jsl S1B_w1_drawFoeHearts    ; update stats
    rtl



; UNIVERSAL ROUTINE
;
; call with jsl
; this routine should only be called whenever it's needed,
; as it chews a lot of our precious CPU-power.
;
; this routine is also a "universal" one which is to be used
; for the other boss-fights.

S1B_w1_drawFoeHearts

    GOTOXY 6,13
;   PRINTS "))))))"

    lda ENM_13_hp               ; smiley health points
    cmp #$12
    beq S1B_w1_dFH_12h_sym
    cmp #$11
    beq S1B_w1_dFH_11h_sym
    cmp #$10
    beq S1B_w1_dFH_10h_sym
    cmp #$0f
    beq S1B_w1_dFH_0Fh_sym
    cmp #$0e
    beq S1B_w1_dFH_0Eh_sym
    cmp #$0d
    beq S1B_w1_dFH_0Dh_sym
    cmp #$0c
    beq S1B_w1_dFH_0Ch_sym
    cmp #$0b
    beq S1B_w1_dFH_0Bh_sym
    cmp #$0a
    beq S1B_w1_dFH_0Ah_sym
    cmp #$09
    beq S1B_w1_dFH_09h_sym
    cmp #$08
    beq S1B_w1_dFH_08h_sym
    cmp #$07
    beq S1B_w1_dFH_07h_sym
    cmp #$06
    beq S1B_w1_dFH_06h_sym
    cmp #$05
    beq S1B_w1_dFH_05h_sym
    cmp #$04
    beq S1B_w1_dFH_04h_sym
    cmp #$03
    beq S1B_w1_dFH_03h_sym
    cmp #$02
    beq S1B_w1_dFH_02h_sym
    cmp #$01
    beq S1B_w1_dFH_01h_sym

;S1B_w1_dFH_00h
    GOTOXY 6,13
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,14
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,15
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,16
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,17
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,18
    jsl bH0_PRINTZ_singleQ
    jmp S1B_w1_dFH_69h


S1B_w1_dFH_12h_sym
    jmp S1B_w1_dFH_12h
S1B_w1_dFH_11h_sym
    jmp S1B_w1_dFH_11h
S1B_w1_dFH_10h_sym
    jmp S1B_w1_dFH_10h
S1B_w1_dFH_0Fh_sym
    jmp S1B_w1_dFH_0fh
S1B_w1_dFH_0Eh_sym
    jmp S1B_w1_dFH_0eh
S1B_w1_dFH_0Dh_sym
    jmp S1B_w1_dFH_0dh
S1B_w1_dFH_0Ch_sym
    jmp S1B_w1_dFH_0ch
S1B_w1_dFH_0Bh_sym
    jmp S1B_w1_dFH_0bh
S1B_w1_dFH_0Ah_sym
    jmp S1B_w1_dFH_0ah
S1B_w1_dFH_09h_sym
    jmp S1B_w1_dFH_09h
S1B_w1_dFH_08h_sym
    jmp S1B_w1_dFH_08h
S1B_w1_dFH_07h_sym
    jmp S1B_w1_dFH_07h
S1B_w1_dFH_06h_sym
    jmp S1B_w1_dFH_06h
S1B_w1_dFH_05h_sym
    jmp S1B_w1_dFH_05h
S1B_w1_dFH_04h_sym
    jmp S1B_w1_dFH_04h
S1B_w1_dFH_03h_sym
    jmp S1B_w1_dFH_03h
S1B_w1_dFH_02h_sym
    jmp S1B_w1_dFH_02h
S1B_w1_dFH_01h_sym
    jmp S1B_w1_dFH_01h



S1B_w1_dFH_12h                  ; 6 red hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartAkai
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_11h                  ; 5 red hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartAoi
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_10h                  ; 4 red hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartAoi
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_0fh                  ; 3 red hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartAoi
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_0eh                  ; 2 red hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartAoi
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_0dh                  ; 1 red heart
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAkai
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartAoi
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_0ch                  ; 6 blue hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartAoi
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_0bh                  ; 5 blue hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartKara
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_0ah                  ; 4 blue hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartKara
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_09h                  ; 3 blue hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartKara
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_08h                  ; 2 blue hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartKara
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_07h                  ; 1 blue heart
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartAoi
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartKara
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_06h                  ; 6 black hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,18
    jsl bH0_PRINTZ_foeHeartKara
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_05h                  ; 5 black hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,17
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,18
    jsl bH0_PRINTZ_singleQ
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_04h                  ; 4 black hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,16
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,17
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,18
    jsl bH0_PRINTZ_singleQ
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_03h                  ; 3 black hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,15
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,16
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,17
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,18
    jsl bH0_PRINTZ_singleQ
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_02h                  ; 2 black hearts
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,14
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,15
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,16
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,17
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,18
    jsl bH0_PRINTZ_singleQ
    jmp S1B_w1_dFH_69h

S1B_w1_dFH_01h                  ; 1 black heart
    GOTOXY 6,13
    jsl bH0_PRINTZ_foeHeartKara
    GOTOXY 6,14
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,15
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,16
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,17
    jsl bH0_PRINTZ_singleQ
    GOTOXY 6,18
    jsl bH0_PRINTZ_singleQ


S1B_w1_dFH_69h
    rtl



;================================


S1B_chkShipSmileyColl

    ; feed the hungry anivars

    ; first out is our beloved spaceship
    jsr S1B_chkSSC_doShip
    jmp S1B_chkSSC_doSM

S1B_chkSSC_doShip

    lda SPRBUF1+SX12
    sta OBJ_X
    lda SPRBUF1+SY12
    sta OBJ_Y
    inc OBJ_Y                   ; inc OBJ_Y by 10
    inc OBJ_Y
    inc OBJ_Y
    inc OBJ_Y
    inc OBJ_Y
    inc OBJ_Y
    inc OBJ_Y
    inc OBJ_Y
    inc OBJ_Y
    inc OBJ_Y
    lda #$20
    sta OBJ_W
    lda #$17
    sta OBJ_H
    dec OBJ_H                   ; dec OBJ_H by 9
    dec OBJ_H
    dec OBJ_H
    dec OBJ_H
    dec OBJ_H
    dec OBJ_H
    dec OBJ_H
    dec OBJ_H
    dec OBJ_H

    rts


S1B_chkSSC_doSM                 ; hehe..

    ; evil smiley aka A520-STC64 "Sharonus Stonus"
    lda SPRBUF1+SX13
    sta OBJ_X2
    lda SPRBUF1+SY13
    sta OBJ_Y2
    lda #$40
    sta OBJ_W2
    sta OBJ_H2


    jsl objHitDetect            ; do it!
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    bne S1B_chkSSC_owari

    lda shipInvulnerable
    cmp #$00
    bne S1B_chkSSC_owari

    jsl sym_SFX_SQUISH
    jsl HP_DROP

S1B_chkSSC_owari                ; jatta-jatta
    stz OBJ_HIT
    rts


;---------------


S1B_chkShipProjColl

    ; feed the hungry anivars

    jsr S1B_chkSSC_doShip

    lda SPRBUF1+SX20
    sta OBJ_X2
    lda SPRBUF1+SY20
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq sym_S1B_chkSPC_ShipIsHit

    jsr S1B_chkSSC_doShip
    lda SPRBUF1+SX21
    sta OBJ_X2
    lda SPRBUF1+SY21
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq sym_S1B_chkSPC_ShipIsHit

    jsr S1B_chkSSC_doShip
    lda SPRBUF1+SX22
    sta OBJ_X2
    lda SPRBUF1+SY22
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq sym_S1B_chkSPC_ShipIsHit
    jmp S1B_chkSPC_cont01

sym_S1B_chkSPC_ShipIsHit
    jmp S1B_chkSPC_ShipIsHit

S1B_chkSPC_cont01
    jsr S1B_chkSSC_doShip
    lda SPRBUF1+SX23
    sta OBJ_X2
    lda SPRBUF1+SY23
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq sym_S1B_chkSPC_ShipIsHit

    jsr S1B_chkSSC_doShip
    lda SPRBUF1+SX24
    sta OBJ_X2
    lda SPRBUF1+SY24
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq sym_S1B_chkSPC_ShipIsHit

    jsr S1B_chkSSC_doShip
    lda SPRBUF1+SX25
    sta OBJ_X2
    lda SPRBUF1+SY25
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq S1B_chkSPC_ShipIsHit

    jsr S1B_chkSSC_doShip
    lda SPRBUF1+SX26
    sta OBJ_X2
    lda SPRBUF1+SY26
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq S1B_chkSPC_ShipIsHit

    jsr S1B_chkSSC_doShip
    lda SPRBUF1+SX27
    sta OBJ_X2
    lda SPRBUF1+SY27
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq S1B_chkSPC_ShipIsHit

    jsr S1B_chkSSC_doShip
    lda SPRBUF1+SX28
    sta OBJ_X2
    lda SPRBUF1+SY28
    sta OBJ_Y2
    lda #$0f
    sta OBJ_W2
    sta OBJ_H2
    jsr S1B_chkSPC_projXYincBy9
    jsr S1B_chkSPC_checkItOut
    ;---
    lda OBJ_HIT                 ; squeeze OBJ_HIT for info
    cmp #$01
    beq S1B_chkSPC_ShipIsHit
    jmp S1B_chkSPC_owari


S1B_chkSPC_checkItOut
    jsl objHitDetect            ; do it!
    rts

S1B_chkSPC_ShipIsHit
    lda shipInvulnerable
    cmp #$00
    bne S1B_chkSPC_owari
    jsl sym_SFX_EXPLOSION
    jsl HP_DROP

S1B_chkSPC_owari                ; jatta-jatta
    stz OBJ_HIT
    rts

S1B_chkSPC_projXYincBy9
    inc OBJ_X2
    inc OBJ_X2
    inc OBJ_X2
    inc OBJ_X2
    inc OBJ_X2
    inc OBJ_X2
    inc OBJ_X2
    inc OBJ_X2
    inc OBJ_X2
    inc OBJ_Y2
    inc OBJ_Y2
    inc OBJ_Y2
    inc OBJ_Y2
    inc OBJ_Y2
    inc OBJ_Y2
    inc OBJ_Y2
    inc OBJ_Y2
    inc OBJ_Y2

    rts


;--------------------------------



; UNIVERSAL ROUTINE
;
; objHitDetect (int OBJ_X ,OBJ_Y ,OBJ_W ,OBJ_H
;                   OBJ_X2,OBJ_Y2,OBJ_W2,OBJ_H2 )
;
; Feed it with: OBJ_X/Y/W/H for e.g Angela/obj1,
;               OBJ_X2/Y2/W2/H2 for obj2
;
; This routine works oneway, and widths and heights
; might vary as you want (byte-sized).
;
; RESULT: The result can be read from OBJ_HIT (bool).

objHitDetect
;===========
    ; calculate widths and heights of both objects

    lda OBJ_X
    sta ENM_13_speed

objHD_Wloop
    dec OBJ_W
    inc ENM_13_speed
    lda OBJ_W
    cmp #$00
    bne objHD_Wloop
    lda ENM_13_speed
    sta OBJ_W


    lda OBJ_Y
    sta ENM_13_speed

objHD_Hloop
    dec OBJ_H
    inc ENM_13_speed
    lda OBJ_H
    cmp #$00
    bne objHD_Hloop
    lda ENM_13_speed
    sta OBJ_H


    lda OBJ_X2
    sta ENM_13_speed

objHD_W2loop
    dec OBJ_W2
    inc ENM_13_speed
    lda OBJ_W2
    cmp #$00
    bne objHD_W2loop
    lda ENM_13_speed
    sta OBJ_W2


    lda OBJ_Y2
    sta ENM_13_speed

objHD_H2loop
    dec OBJ_H2
    inc ENM_13_speed
    lda OBJ_H2
    cmp #$00
    bne objHD_H2loop
    lda ENM_13_speed
    sta OBJ_H2

    
    

    ; dekimashita!


    ; LET THE DOGS OUT !!!! (not referring to the song)

objHD_tc_00
    stz hd_coll
    stz hd_colc                 ; to be inc'ed if suspicious, yarr!

    ; DOES UPPER LEFT CORNER COLLIDE?

objHD_tc_01                     ; ul x-wise
    lda OBJ_X
    cmp OBJ_X2
    bpl objHD_tc_01a
    jmp objHD_tc_02

objHD_tc_01a
    inc hd_colc

objHD_tc_02
    lda OBJ_X
    cmp OBJ_W2
    bmi objHD_tc_02a
    jmp objHD_tc_03

objHD_tc_02a
    inc hd_colc

objHD_tc_03                     ; ul y-wise
    lda OBJ_Y
    cmp OBJ_Y2
    bpl objHD_tc_03a
    jmp objHD_tc_04

objHD_tc_03a
    inc hd_colc

objHD_tc_04
    lda OBJ_Y
    cmp OBJ_H2
    bmi objHD_tc_04a
    jmp objHD_tc_05

objHD_tc_04a
    inc hd_colc

objHD_tc_05                     ; PITSTOP #1
    lda hd_colc
    cmp #$04
    bne objHD_tc_05a
    inc hd_coll

objHD_tc_05a
    stz hd_colc

    ; IS UPPER RIGHT CORNER COLLIDING?

objHD_tc_06
    lda OBJ_W                   ; ur x-wise
    cmp OBJ_X2
    bpl objHD_tc_06a
    jmp objHD_tc_07

objHD_tc_06a
    inc hd_colc

objHD_tc_07
    lda OBJ_W
    cmp OBJ_W2
    bmi objHD_tc_07a
    jmp objHD_tc_08

objHD_tc_07a
    inc hd_colc

objHD_tc_08                     ; ur y-wise
    lda OBJ_Y
    cmp OBJ_Y2
    bpl objHD_tc_08a
    jmp objHD_tc_09

objHD_tc_08a
    inc hd_colc

objHD_tc_09
    lda OBJ_Y
    cmp OBJ_H2
    bmi objHD_tc_09a
    jmp objHD_tc_0A

objHD_tc_09a
    inc hd_colc

objHD_tc_0A                     ; PITSTOP #2
    lda hd_colc
    cmp #$04
    bne objHD_tc_0Aa
    inc hd_coll

objHD_tc_0Aa
    stz hd_colc

    ; IS LOWER LEFT CORNER COLLIDING?

objHD_tc_0B                     ; ll x-wise
    lda OBJ_X
    cmp OBJ_X2
    bpl objHD_tc_0Ba
    jmp objHD_tc_0C

objHD_tc_0Ba
    inc hd_colc

objHD_tc_0C
    lda OBJ_X
    cmp OBJ_W2
    bmi objHD_tc_0Ca
    jmp objHD_tc_0D

objHD_tc_0Ca
    inc hd_colc

objHD_tc_0D                     ; ll y-wise
    lda OBJ_H
    cmp OBJ_Y2
    bpl objHD_tc_0Da
    jmp objHD_tc_0E

objHD_tc_0Da
    inc hd_colc

objHD_tc_0E
    lda OBJ_H
    cmp OBJ_H2
    bmi objHD_tc_0Ea
    jmp objHD_tc_0F

objHD_tc_0Ea
    inc hd_colc

objHD_tc_0F                     ; PITSTOP #3
    lda hd_colc
    cmp #$04
    bne objHD_tc_0Fa
    inc hd_coll

objHD_tc_0Fa
    stz hd_colc

    ; IS LOWER RIGHT CORNER COLLIDING?

objHD_tc_10                     ; lr x-wise
    lda OBJ_W
    cmp OBJ_X2
    bpl objHD_tc_10a
    jmp objHD_tc_11

objHD_tc_10a
    inc hd_colc

objHD_tc_11
    lda OBJ_W
    cmp OBJ_W2
    bmi objHD_tc_11a
    jmp objHD_tc_12

objHD_tc_11a
    inc hd_colc

objHD_tc_12                     ; lr y-wise
    lda OBJ_H
    cmp OBJ_Y2
    bpl objHD_tc_12a
    jmp objHD_tc_13

objHD_tc_12a
    inc hd_colc

objHD_tc_13
    lda OBJ_H
    cmp OBJ_H2
    bmi objHD_tc_13a
    jmp objHD_tc_14

objHD_tc_13a
    inc hd_colc

objHD_tc_14                     ; PITSTOP #4
    lda hd_colc
    cmp #$04
    bne objHD_tc_ff
    inc hd_coll

objHD_tc_ff
    stz hd_colc
    lda hd_coll
    cmp #$00
    beq objHD_tc_hamasaki       ; no collision!

    lda #$01
    sta OBJ_HIT                 ; OBJ_HIT = TRUE
    jmp objHD_tc_ayumi


objHD_tc_hamasaki
    stz OBJ_HIT                 ; OBJ_HIT = FALSE

objHD_tc_ayumi
    rtl


;================================
;================================
;================================
;================================
;================================
;================================


S1B_MAKE_SMILEY_PAL_NORM
    lda #$30
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    rts


S1B_MAKE_SMILEY_PAL_WHITE
    lda #%00111110
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    rts


S1B_MAKE_LAST_SPRPAL_WHITE
    lda #$f0
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f1
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f2
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f3
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f4
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f5
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f6
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f7
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f8
    sta $2121
    jsr S1B_whitey_smiley
    lda #$f9
    sta $2121
    jsr S1B_whitey_smiley
    lda #$fa
    sta $2121
    jsr S1B_whitey_smiley
    lda #$fb
    sta $2121
    jsr S1B_whitey_smiley
    lda #$fc
    sta $2121
    jsr S1B_whitey_smiley
    lda #$fd
    sta $2121
    jsr S1B_whitey_smiley
    lda #$fe
    sta $2121
    jsr S1B_whitey_smiley
    lda #$ff
    sta $2121
    jsr S1B_whitey_smiley

    rts

S1B_whitey_smiley
    lda #$ff
    sta $2122
    sta $2122
    rts
.ASM

;================================


S1B_starScroll

    ldx MAPX                    ; scroll bg#1 map
    inx
    inx
    inx
    stx MAPX

    rts



S1B_virreteShipShip

    lda ENM_16_wait             ; SHIP motor prob
    cmp #$03
    beq S1B_vSS_motorProb03
    cmp #$02
    beq S1B_vSS_motorProb02
    cmp #$01
    beq S1B_vSS_motorProb01
    jmp S1B_vSS_motorProb00
S1B_vSS_motorProb03
    dec SPRBUF1+SX12
    jmp S1B_vSS_bukkakeFest
S1B_vSS_motorProb02
    inc SPRBUF1+SY12
    jmp S1B_vSS_bukkakeFest
S1B_vSS_motorProb01
    inc SPRBUF1+SX12
    jmp S1B_vSS_bukkakeFest
S1B_vSS_motorProb00
    dec SPRBUF1+SY12


S1B_vSS_bukkakeFest
    inc ENM_16_wait             ; SHIP motor prob reset if == $04
    lda ENM_16_wait
    cmp #$04
    bne S1B_vSS_qwerty
    stz ENM_16_wait

S1B_vSS_qwerty
    rtl

;================================

; UNIVERSAL ROUTINE
;
; wait for blank interrupt -- uses X reg

bH12_WAIT_FOR_THE_HOLY_WAI

    wai
    dex
    cpx #$0000
    bne bH12_WAIT_FOR_THE_HOLY_WAI
    rtl



; Make sure to call these routines later from another banks --
; it's so annoying having the same code over and over.. :(


bH12_INIT_VIDEO_03              ; UNIVERSAL ROUTINE

    php
    rep #$10                    ; A/mem=8bits, X/Y=16bits
    sep #$20
    lda #$A3                    ; spr. sizes = 32x32 & 64x64
                                ; vram char data addr. = $6000.
    sta $2121
    lda #$03
    sta $2105                   ; mode #3, 8x8 (BG1=8bpp, BG2=4bpp)
    lda #$08                    ; BG#1 tilemap VRAM offs = $0000 ..
    sta $2107                   ; .. and tilemap size = 64x64 tiles
    lda #$21                    ; BG#1 chr VRAM offs = $1000
    sta $210B                   ; BG#2 chr VRAM offs = $2000
    lda #$58                    ; BG#2 tilemap VRAM offs = $5800 ..
    sta $2108                   ; .. and tilemap size = 32x32 tiles
    lda #$13                    ; Enable BG#1, BG#2 and BG#5
    sta $212C
    lda #$0F
    sta $2100                   ; Turn on screen, full brightness
    lda #$FF                    ; Scroll BG#2 down by one pixel
    sta $2110
    sta $2110
    plp

    ldx #$ffff                  ; same as above
    stx mapYbg2

    rtl



bH12_INIT_VIDEO_04              ; UNIVERSAL ROUTINE
    php
    rep #$10                    ; A/mem=8bits, X/Y=16bits
    sep #$20
    lda #$A3                    ; Spr sizes = 32x32||64x64,
                                ; VRAM chr data address = $6000
    sta $2101
    lda #$04                    ; Mode #4, 8x8 (BG#1=8bpp, BG#2=2bpp)
    sta $2105
    lda #$03                    ; BG#1 tilemap VRAM offs = $0000 ..
    sta $2107                   ; .. and tilemap size = 64x64 tiles
    lda #$52                    ; BG#1 chr VRAM offs = $1000
    sta $210B                   ; BG#2 chr VRAM offs = $2000
    lda #$58                    ; BG#2 tilemap VRAM offs = $5800 ..
    sta $2108                   ; .. and tilemap size = 32x32 tiles
    lda #$13                    ; Enable BG#1, BG#2 and BG#5
    sta $212C
    lda #$0F
    sta $2100                   ; Turn on screen, full brightness
    lda #$FF                    ; Scroll BG#2 down by one pixel
    sta $2110
    sta $2110
    plp

    ldx #$ffff                  ; same as above
    stx mapYbg2

    rtl




;=================================================================

; STAGE 1 BOSS - END SEQUENCE #2/2
; This one gets executed at "game over".

S1B_ENDSEQ_n2

    stz areWeAtFirstBoss

    jsl sym_MUS_NO_SONG
    jsl bH13_FADE_OUT_SCROLLBG1

    jsl S1B_SEQ_WARNINGLOADAH

    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100

    lda #$03
    sta $212c                   ; disable all, but bg#1 and bg#2

    LOAD_PAL SEQ_S1B_DISCUSS_PAL
    wai
    LOAD_BLOCK2VRAM INTRO_BG_GRL_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_DISCUSS_PIC,$2000,$6000
    wai
    wai
    LOAD_BLOCK2VRAM S1AM_S1B_SEQ_FONT,$5000,$0800
    wai
    wai


    jsl bH0_SPLSC_CLR

    ldx #$0000                  ; reset bg#1 tilemap position
    stx MAPX
    stx MAPY

    stz a_byte                  ; "A" button animation var

    FADE_IN_MOSAIC

    ldx #$6f
    jsl bH12_WAIT_FOR_THE_HOLY_WAI

;----
    jsl bH0_PRINTS_SB1_e2_CHIKUSHOU
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_e2_CHIKUSHOU2
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_e2_IAMHAPPY
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_PRINTS_SB1_e2_NICEKNOWINGYOU
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO

    GOTOXY 20,18
    jsl bH0_PRINTS_SB1_e2_WWWDOTCOM
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    GOTOXY 20,19
    jsl bH0_PRINTS_SB1_e2_WWWDOTCOM
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    GOTOXY 20,20
    jsl bH0_PRINTS_SB1_e2_WWWDOTCOM
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    GOTOXY 20,21
    jsl bH0_PRINTS_SB1_e2_WWWDOTCOM
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO

    jsl bH0_PRINTS_SB1_e2_ANGDOTx3
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO

_BURZUM_VIER
    wai
    wai
    wai
    wai
    wai
    wai

    inc a_byte
    lda a_byte
    cmp #$04
    bne _BURZUM_VIER_PROCEED
    stz a_byte

_BURZUM_VIER_PROCEED
    jsl bH0_PRINTZ_angelManko_AbuttAnim

    lda joy1
    and #$80
    beq _BURZUM_VIER_NOT_A
    jmp _BURZUM_VIER_NEINEI
_BURZUM_VIER_NOT_A
    jmp _BURZUM_VIER

_BURZUM_VIER_NEINEI
    GOTOXY 24,30
    jsl bH0_PRINTZ_singleEraser
    stz a_byte                  ; "A" button animation var
    jsr S1B_w69_WAKE_ME_UP_BEFORE_U_GO_GO
    jsl bH0_SPLSC_CLR
    jsl sym_MUS_SONG_GRADIUS


;-------
    ; skies and shit

    jsl bH13_FADE_OUT_MOSAIC_macro
    lda #$80
    sta $2100

    lda #%00011111
    sta $212c                  ; enable all bg+oam

    lda #$8c
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
    sta SPRBUF1+SFRAME6
    sta SPRBUF1+SFRAME7
    sta SPRBUF1+SFRAME8
    sta SPRBUF1+SFRAME9
    sta SPRBUF1+SFRAME10
    sta SPRBUF1+SFRAME11
    stz SPRBUF1+SFRAME12
    sta SPRBUF1+SFRAME13
    sta SPRBUF1+SFRAME14
    sta SPRBUF1+SFRAME15
    sta SPRBUF1+SFRAME16
    sta SPRBUF1+SFRAME17
    sta SPRBUF1+SFRAME18
    sta SPRBUF1+SFRAME19
    sta SPRBUF1+SFRAME20
    sta SPRBUF1+SFRAME21
    sta SPRBUF1+SFRAME22
    sta SPRBUF1+SFRAME23
    sta SPRBUF1+SFRAME24
    sta SPRBUF1+SFRAME25
    sta SPRBUF1+SFRAME26
    sta SPRBUF1+SFRAME27
    sta SPRBUF1+SFRAME28
    sta SPRBUF1+SFRAME29
    sta SPRBUF1+SFRAME30
    sta SPRBUF1+SFRAME31
    lda #%00010000             ; make the sprite appear between bg#1 and bg#2
    sta SPRBUF1+SPRIORITY12
    lda #$60
    sta SPRBUF1+SX12
    lda #$40
    sta SPRBUF1+SY12
    wai

    lda #$11                   ; bg#2 translucency against oam and bg#1
    sta $212d
    lda #$02
    sta $2130
    lda #$52
    sta $2131

    LOAD_PAL SEQ_SB1_ENDLVL_SKY_PAL
    wai
    LOAD_BLOCK2VRAM SEQ_SB1_ENDLVL_SKY_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_SB1_ENDLVL_SKY_PIC,$2000,$6000
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_SB1BG2GFX,$5000,$0800
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_SB1_SPRZ,$6000,$2000
    wai
    wai

    GOTOXY 2,2
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 3,2
    jsl bH0_PRINTS_SB1_SKYbtm
    GOTOXY 3,12
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 4,12
    jsl bH0_PRINTS_SB1_SKYbtm
    GOTOXY 1,17
    jsl bH0_PRINTS_SB1_SKY1top
    GOTOXY 2,17
    jsl bH0_PRINTS_SB1_SKY1btm
    GOTOXY 6,3
    jsl bH0_PRINTS_SB1_SKY1top
    GOTOXY 7,3
    jsl bH0_PRINTS_SB1_SKY1btm
    GOTOXY 7,18
    jsl bH0_PRINTS_SB1_SKY1top
    GOTOXY 8,18
    jsl bH0_PRINTS_SB1_SKY1btm
    GOTOXY 10,1
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 11,1
    jsl bH0_PRINTS_SB1_SKYbtm
    GOTOXY 10,14
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 11,14
    jsl bH0_PRINTS_SB1_SKYbtm
    GOTOXY 13,2
    jsl bH0_PRINTS_SB1_SKY1top
    GOTOXY 14,2
    jsl bH0_PRINTS_SB1_SKY1btm
    GOTOXY 12,24
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 13,24
    jsl bH0_PRINTS_SB1_SKYbtm
    GOTOXY 15,16
    jsl bH0_PRINTS_SB1_SKY1top
    GOTOXY 16,16
    jsl bH0_PRINTS_SB1_SKY1btm
    GOTOXY 17,0
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 18,0
    jsl bH0_PRINTS_SB1_SKYbtm
    GOTOXY 18,11
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 19,11
    jsl bH0_PRINTS_SB1_SKYbtm
    GOTOXY 21,7
    jsl bH0_PRINTS_SB1_SKY1top
    GOTOXY 22,7
    jsl bH0_PRINTS_SB1_SKY1btm
    GOTOXY 20,23
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 21,23
    jsl bH0_PRINTS_SB1_SKYbtm
    GOTOXY 24,17
    jsl bH0_PRINTS_SB1_SKY1top
    GOTOXY 25,17
    jsl bH0_PRINTS_SB1_SKY1btm
    GOTOXY 25,3
    jsl bH0_PRINTS_SB1_SKYtop
    GOTOXY 26,3
    jsl bH0_PRINTS_SB1_SKYbtm

    GOTOXY 28,0
    jsl bH0_PRINTZ_aLineWorthOfEraze
    GOTOXY 29,0
    jsl bH0_PRINTZ_aLineWorthOfEraze
    GOTOXY 30,0
    jsl bH0_PRINTZ_aLineWorthOfEraze
    GOTOXY 31,0
    jsl bH0_PRINTZ_aLineWorthOfEraze

    wai

    ldx #$0000
    stx MAPX
    stx MAPY
    stx mapXbg2
    stx mapYbg2

    lda #$0f
    sta freeForAll1            ; counter for $2100

    stz a_byte                 ; what spr# ?
    ldy #$0005                 ; sprite anim delay
    ldx #$0040                 ; # times of to repeat..
    stx a_word                 ; ..sprite anim delay

    lda #$0f
    sta $2100


S1B_ENDSEQ_n2_SKYFALL
    jsr SB1_ESEQn2_wainx
    dey
    cpy #$0000
    bne S1B_ENDSEQ_n2_skyFallJMP
    lda a_byte
    cmp #$02
    beq S1B_ENDSEQ_n2_skyFallSpr02
    cmp #$01
    beq S1B_ENDSEQ_n2_skyFallSpr01

    stz SPRBUF1+SFRAME12
    lda #$01
    sta a_byte
    jmp S1B_ENDSEQ_n2_skyFallSprRESY
S1B_ENDSEQ_n2_skyFallSpr02
    lda #$08
    sta SPRBUF1+SFRAME12
    stz a_byte
    jmp S1B_ENDSEQ_n2_skyFallSprRESY
S1B_ENDSEQ_n2_skyFallSpr01
    lda #$04
    sta SPRBUF1+SFRAME12
    lda #$02
    sta a_byte
    ldx a_word
    dex
    stx a_word
    ldx a_word
    cpx #$0000
    beq gtoSB1_ENDSEQ_n2_SKYFALL_prep
S1B_ENDSEQ_n2_skyFallSprRESY
    ldy #$0005

S1B_ENDSEQ_n2_skyFallJMP
    jmp S1B_ENDSEQ_n2_SKYFALL


gtoSB1_ENDSEQ_n2_SKYFALL_prep
    lda #$06
    sta a_byte2                ; $2100 dec delay
    ldy #$0005
    ldx #$0020
    stx a_word

gtoSB1_ENDSEQ_n2_SKYFALL
    dec a_byte2
    lda a_byte2
    cmp #$00
    bne gtoSB1_ESEQn2_SKFLLcont

    dec freeForAll1            ; $2100 value keeper thingie
    lda freeForAll1
    sta $2100
    cmp #$00

    beq SB1_ENDSEQ_n2_meanwhile
    lda #$06
    sta a_byte2
    inc SPRBUF1+SX12

gtoSB1_ESEQn2_SKFLLcont
    jsr SB1_ESEQn2_wainx
    inc SPRBUF1+SY12

    dey
    cpy #$0000
    bne gtoSB1_ENDSEQ_n2_skyFallJMP
    lda a_byte
    cmp #$02
    beq gtoSB1_ENDSEQ_n2_skyFallSpr02
    cmp #$01
    beq gtoSB1_ENDSEQ_n2_skyFallSpr01

    stz SPRBUF1+SFRAME12
    lda #$01
    sta a_byte
    jmp gtoSB1_ENDSEQ_n2_skyFallSprRESY
gtoSB1_ENDSEQ_n2_skyFallSpr02
    lda #$08
    sta SPRBUF1+SFRAME12
    stz a_byte
    jmp gtoSB1_ENDSEQ_n2_skyFallSprRESY
gtoSB1_ENDSEQ_n2_skyFallSpr01
    lda #$04
    sta SPRBUF1+SFRAME12
    lda #$02
    sta a_byte
gtoSB1_ENDSEQ_n2_skyFallSprRESY
    ldy #$0005

gtoSB1_ENDSEQ_n2_skyFallJMP
    jmp gtoSB1_ENDSEQ_n2_SKYFALL



SB1_ESEQn2_wainx
    wai
    ldx MAPX
    inx
    inx
    stx MAPX
    ldx MAPY
    inx
    inx
    inx
    inx
    stx MAPY
    ldx mapXbg2
    inx
    inx
    inx
    stx mapXbg2
    ldx mapYbg2
    inx
    inx
    inx
    inx
    inx
    inx
    stx mapYbg2
    rts



SB1_ENDSEQ_n2_meanwhile

    lda #$01
    sta BAD_ENDING

    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100                  ; screen off, no brightness
    lda #%00000010
    sta $212c                  ; disable all, but bg#2

    stz $212d                  ; disable translucency
    stz $2130
    stz $2131

    LOAD_PAL SEQ_S1B_DISCUSS_PAL
    wai
    LOAD_BLOCK2VRAM S1AM_S1B_SEQ_FONT,$5000,$0800
    wai
    wai
    jsl bH0_SPLSC_CLR          ; clear bg#2 tilemap
    lda #$0a
    sta $212c                  ; disable all, but bg#2

    ldx #$0000                 ; reset bg#1&2 tilemap position
    stx MAPX
    stx MAPY
    stx mapXbg2
    stx mapYbg2

    jsl sym_MUS_NO_SONG        ; turn off the music
    ldx #$0030                 ; and wait a little
    jsl bH12_WAIT_FOR_THE_HOLY_WAI

    GOTOXY 13,8
    jsl bH0_PRINTS_S1BMEANWHILE1of2
    GOTOXY 15,8
    jsl bH0_PRINTS_S1BMEANWHILE2of2

    jsl bH13_FADE_IN_macro
    ldx #$009f
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl bH13_FADE_OUT_macro

    ;---- castle from overworld (ff1.nes)

    jsl bH0_SPLSC_CLR          ; clear bg#2 tilemap
    lda #$01
    sta $212c                  ; disable all, but bg#1

    LOAD_PAL SEQ_S1BCASTLE_PAL
    wai
    LOAD_BLOCK2VRAM SEQ_S1BCASTLE_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_S1BCASTLE_PIC,$2000,$6000
    wai
    wai
    ldx #$0030                 ; wait a little
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl sym_MUS_SONG_SEASIA
    jsl bH13_FADE_IN_macro
    ldx #$013e                 ; wait before mosaic fadeout
    jsl bH12_WAIT_FOR_THE_HOLY_WAI


    jsl bH13_FADE_OUT_MOSAIC_macro
    lda #$80
    sta $2100                  ; screen off, no brightness

    ; load everything castle interior
    LOAD_PAL SEQ_S1B_CSTIN_PAL
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_CSTIN_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_CSTIN_PIC,$2000,$6000
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_SPRSETFF,$6000,$2000
    wai
    ldx #$0030                 ; wait a little
    jsl bH12_WAIT_FOR_THE_HOLY_WAI

    ;------------------------
    ; set up castle guard #1
    lda #176
    sta SPRBUF1+SX12
    lda #136
    sta SPRBUF1+SY12
    ;---
    lda #$30
    sta SPRBUF1+SPRIORITY12
    stz SPRBUF1+SFRAME12
    stz SPRBUF1+SPRIORITY13
    stz SPRBUF1+SPRIORITY14
    stz SPRBUF1+SPRIORITY15


    stz SPRBUF2+3              ; enable sprites 12, 13, 14, and 15
    lda #%00000011
    sta $212c                  ; enable only bg#1&2

    ldx #$0020
    stx MAPX
    ldx #$0144 ; #324
    stx MAPY

    jsl bH13_FADE_IN_MOSAIC_macro
    lda #%00010011
    sta $212c                  ; enable bg#1,2 and oam


    stz a_byte                 ; sprite anim frame
    lda #$07
    sta a_byte2                ; sprite anim delay
    stz ENM_17_hp              ; temp scroll count

    ;---------------------
    ; Rightward scroll
S1B_SEQ_interiorScroll_l01
    wai
    wai
    inc ENM_17_hp
    lda ENM_17_hp
    cmp #$d8
    beq S1B_SEQ_interiorScroll_l02reset

    dec a_byte2
    lda a_byte2
    cmp #$00                   ; is it time to change sprite?
    bne S1BSEQinteriorScrl01_A ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                ; refill sprite anim delay var

S1BSEQinteriorScrl01_A
    ldx MAPX
    inx
    stx MAPX
    lda SPRBUF1+SX12
    dea
    sta SPRBUF1+SX12
    lda SPRBUF1+SX12
    cmp #$01
    bne S1B_SEQ_interiorScroll_l01
    lda #$00
    sta SPRBUF1+SPRIORITY12
    jmp S1B_SEQ_interiorScroll_l01

    ;--------------------
    ; Upward scroll
S1B_SEQ_interiorScroll_l02reset
    stz a_byte                 ; sprite anim frame
    lda #$07
    sta a_byte2                ; sprite anim delay
    stz ENM_17_hp              ; temp scroll count
S1B_SEQ_interiorScroll_l02
    wai
    wai
    inc ENM_17_hp
    lda ENM_17_hp
    cmp #$b4 ; #180
    beq S1B_SEQ_interiorScroll_l03setUp

    dec a_byte2
    lda a_byte2
    cmp #$00                   ; is it time to change sprite?
    bne S1BSEQinteriorScrl02_A ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                ; refill sprite anim delay var

S1BSEQinteriorScrl02_A
    lda ENM_17_hp
    cmp #$b4
    bcs S1BSEQinteriorScrl02_B
    lda SPRBUF1+SY12
    ina
    sta SPRBUF1+SY12
S1BSEQinteriorScrl02_B
    ldx MAPY
    dex
    stx MAPY
    lda ENM_17_hp              ; setup guard #2 (outside king's chamber)
    cmp #$af ; #175              when the time is right
    bne S1B_SEQ_interiorScroll_l02
    lda #$89 ; 137
    sta SPRBUF1+SX12
    stz SPRBUF1+SY12
    lda #$30
    sta SPRBUF1+SPRIORITY12
    jmp S1B_SEQ_interiorScroll_l02


    ;---------------------
    ; Brief delay until uber-sexy hero stud appears + short delay
S1B_SEQ_interiorScroll_l03setUp
    ldx #$0024
S1B_SEQ_interiorScroll_l03
    wai
    wai
    dex
    cpx #$0000
    beq S1BSEQinteriorScrl03_A
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1B_SEQ_interiorScroll_l03 ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1B_SEQ_interiorScroll_l03
S1BSEQinteriorScrl03_A
    lda #$7a ; #122
    sta SPRBUF1+SX13           ; spr13 for hero stills and
    sta SPRBUF1+SX14           ; spr14 for animation (walking upwards)
    lda #$b5 ; #181
    sta SPRBUF1+SY13
    sta SPRBUF1+SY14
    lda #$4c
    sta SPRBUF1+SFRAME13
    lda #$30
    sta SPRBUF1+SPRIORITY13
    ldx #$0020
S1BSEQinteriorScrl03_B
    wai
    wai
    dex
    cpx #$0000
    beq S1B_SEQ_interiorScroll_l04setUp
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1BSEQinteriorScrl03_B     ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1BSEQinteriorScrl03_B


    ;---------------------
    ; Hero walks north until he stops by the guard
S1B_SEQ_interiorScroll_l04setUp
    stz ENM_17_hp              ; temp scroll count
    stz SPRBUF1+SPRIORITY13
    lda #$0a
    sta SPRBUF1+SX13
    lda #$30
    sta SPRBUF1+SPRIORITY14
    ; step 1: hero walks 112 enm_17_hp with no scrolling
S1B_SEQ_interiorScroll_l04
    wai
    wai
    lda SPRBUF1+SY14
    dea
    sta SPRBUF1+SY14
    inc ENM_17_hp
    lda ENM_17_hp
    cmp #$52 ; #82
    beq S1BSEQinteriorScrl04_AsetUp
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1B_SEQ_interiorScroll_l04 ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1B_SEQ_interiorScroll_l04
    ; step 2: hero walks against the guard with scrolling
S1BSEQinteriorScrl04_AsetUp
    stz ENM_16_hp              ; scroll switch
    stz ENM_17_hp              ; temp scroll count
S1BSEQinteriorScrl04_A
    wai
    wai
    lda ENM_16_hp
    cmp #$00
    bne S1BSEQinteriorScrl04_Aa
    lda SPRBUF1+SY14           ; dec hero.y
    dea
    sta SPRBUF1+SY14
    lda #$01
    sta ENM_16_hp
    jmp S1BSEQinteriorScrl04_Aa
S1BSEQinteriorScrl04_Aa
    ldx MAPY                   ; dec MAPY
    dex
    stx MAPY
    lda SPRBUF1+SY12           ; inc guard.y
    ina
    sta SPRBUF1+SY12
    lda SPRBUF1+SY14           ; inc hero.y
    ina
    sta SPRBUF1+SY14
    stz ENM_16_hp
S1BSEQinteriorScrl04_Ab
    inc ENM_17_hp
    lda ENM_17_hp
    cmp #$5f
    beq S1BSEQinteriorScrl04_BsetUp
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1BSEQinteriorScrl04_A     ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1BSEQinteriorScrl04_A
    ; step 3: keep on scrolling the camera for a little more
S1BSEQinteriorScrl04_BsetUp
    stz SPRBUF1+SPRIORITY14
    lda SPRBUF1+SX14
    sta SPRBUF1+SX13
    lda SPRBUF1+SY14
    sta SPRBUF1+SY13
    lda #$44                   ; hero standing straight up
    sta SPRBUF1+SFRAME13
    lda #$30
    sta SPRBUF1+SPRIORITY13
    stz ENM_17_hp              ; temp scroll count
    ldy #$0020
S1BSEQinteriorScrl04_B
    wai
    wai
    inc SPRBUF1+SY12
    inc SPRBUF1+SY13
    inc SPRBUF1+SY14
    ldx MAPY
    dex
    stx MAPY
    inc ENM_17_hp
    lda ENM_17_hp
    cmp #$30
    beq S1BSEQinteriorScrl04_C
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1BSEQinteriorScrl04_B     ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1BSEQinteriorScrl04_B
    ; step 4: just walk a little for no apparent reason
S1BSEQinteriorScrl04_C
    ; step 4 was unecessary and looked pretty lame which is why
    ; it had to be removed -- and heey, next up is..
    ; step 5: a little more guard walking + hero standing straight (up)
S1BSEQinteriorScrl04_DsetUp
;   stz SPRBUF1+SPRIORITY14
;   lda SPRBUF1+SX14
;   sta SPRBUF1+SX13
;   lda SPRBUF1+SY14
;   sta SPRBUF1+SY13
;   lda #$44                   ; hero standing straight up
;   sta SPRBUF1+SFRAME13
;   lda #$30
;   sta SPRBUF1+SPRIORITY13
    ldy #$0060
S1BSEQinteriorScrl04_D
    wai
    wai
    dey
    cpy #$0000
    beq S1BSEQinteriorScrl04_EsetUp
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1BSEQinteriorScrl04_D     ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1BSEQinteriorScrl04_D
    ; step 6: open door (sprite #15) + short rest
S1BSEQinteriorScrl04_EsetUp
    lda #$7a ; #122
    sta SPRBUF1+SX15
    lda #$86 ; #134
    sta SPRBUF1+SY15
    lda #$48
    sta SPRBUF1+SFRAME15
    ; SPILL LYDEFFEKT, VIS SPRITE OG FORTSETT!
    jsl sym_SFX_INTERFERENCE
    wai
    wai
    wai
    wai
    lda #$30
    sta SPRBUF1+SPRIORITY15
    ldy #$25
S1BSEQinteriorScrl04_E
    wai
    wai
    dey
    cpy #$0000
    beq S1BSEQinteriorScrl04_FsetUp
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1BSEQinteriorScrl04_E     ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1BSEQinteriorScrl04_E
    ; step 7: hero enters the throne room + mosaic fadeout
S1BSEQinteriorScrl04_FsetUp
    stz ENM_17_hp              ; temp scroll count
    stz SPRBUF1+SPRIORITY13
    stz SPRBUF1+SX13
    lda #$30
    sta SPRBUF1+SY13
    sta SPRBUF1+SPRIORITY14
S1BSEQinteriorScrl04_F
    wai
    wai
    dec SPRBUF1+SY14
    inc ENM_17_hp
    lda ENM_17_hp
    cmp #$0c
    beq S1BSEQinteriorScrl04_F16
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1BSEQinteriorScrl04_F     ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1BSEQinteriorScrl04_F
S1BSEQinteriorScrl04_F16
    stz SPRBUF1+SPRIORITY14    ; hide hero (sprite#14)
    stz SPRBUF1+SX14
    stz SPRBUF1+SY14
    ldx #$001a
    jsr S1BSEQ_stillAnimated
    stz SPRBUF1+SPRIORITY15
    jsl sym_SFX_GUN_FIRE
    ldx #$0018
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    stz SPRBUF1+SPRIORITY12    ; hide guard (the one outside of king's chamber)
    jsl SEQS1BthroneFADEOUTMOSA

    ;----------------------------------
    ; THRONE ROOM SEQUENCE PART

S1BSEQthroneRoom_p00
    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100
    lda #%00011111
    sta $212c                  ; enable all planes + obj

    LOAD_PAL SEQ_S1B_CSTIN2_PAL
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_CSTIN2_MAP,$0000,$2000
    wai
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_CSTIN2_PIC,$2000,$6000
    wai
    wai
    wai
    LOAD_BLOCK2VRAM FF1_FONTSET,$5000,$0800
    wai
    wai
    LOAD_BLOCK2VRAM SEQ_S1B_SPRSETFF,$6000,$2000
    wai


    jsl bH0_SPLSC_CLR          ; clear bg#2 tilemap
    ldx #$0000                 ; reset bg#1 map location
    stx MAPX
    ldx #$ffff
    stx MAPY

    jsl TOTALLY_RESET_32x32_SPRITES
    lda #%11110000
    sta SPRBUF2+3              ; enable sprites 12 and 13

    lda #48                    ; setup the king's slut daughters
    sta SPRBUF1+SX12           ; spr12 is Lubia (the blonde babe) and spr13
    lda #134                   ; is Vulva (the greenheaded gift from God =^.^=
    sta SPRBUF1+SY12
    lda #192
    sta SPRBUF1+SX13
    lda #134
    sta SPRBUF1+SY13
    lda #$30
    sta SPRBUF1+SPRIORITY12
    sta SPRBUF1+SPRIORITY13
    lda #$80
    sta SPRBUF1+SFRAME12
    lda #$08
    sta SPRBUF1+SFRAME13

    wai
    jsl SEQS1BthroneFADEINMOSA

    ; this snippets was used for testing the window/box routines
    ; do not erase it;  idolize it *chants* ;-)
    ; this nifty text window thingie looked just like the sucker
    ; as of in the original FF for the NES.
;   ldx #$0064
;   jsl bH12_WAIT_FOR_THE_HOLY_WAI
;loopyDog
;   jsr S1BSEQ_FFwinOpen
;   ldx #$0064
;   jsl bH12_WAIT_FOR_THE_HOLY_WAI
;   jsr S1BSEQ_FFwinClose
;   ldx #$0064
;   jsl bH12_WAIT_FOR_THE_HOLY_WAI
;   jmp loopyDog
;
;
;  SILLY ME FOR USING WAY MORE SPRITES THAN THE SNES CAN PROVIDE !!!! ;_;

S1BSEQthroneRoom_p01
    stz a_byte                 ; sprite anim frame
    lda #$07
    sta a_byte2                ; sprite anim delay
    ldx #$0030
    jsr SEQS1B_jegGirFaenAkkuratNaa
    jsr S1BSEQ_setAvatar_KING    ; set king avatar
    GOTOXY 4,9
    jsl bH0_PRINTS_S1BAUDIENCE_00
    GOTOXY 5,9
    jsl bH0_PRINTS_S1BAUDIENCE_01
    jsr S1BSEQ_FFwinOpen         ; open
    ldx #$0060
    jsr SEQS1B_jegGirFaenAkkuratNaa
    jsr S1BSEQ_FFwinClose        ; close
    jsr SEQS1B_windowERASE
    jsr S1BSEQ_setAvatar_HERO    ; set hero avatar
    GOTOXY 3,9
    jsl bH0_PRINTS_S1BAUDIENCE_02
    GOTOXY 4,9
    jsl bH0_PRINTS_S1BAUDIENCE_03
    GOTOXY 5,9
    jsl bH0_PRINTS_S1BAUDIENCE_04
    GOTOXY 6,9
    jsl bH0_PRINTS_S1BAUDIENCE_05
    jsr S1BSEQ_FFwinOpen         ; open
    ldx #$0060
    jsr SEQS1B_jegGirFaenAkkuratNaa
    jsr S1BSEQ_FFwinClose        ; close
    jsr SEQS1B_windowERASE
    jsr S1BSEQ_setAvatar_KING    ; set king avatar
    lda #$30
    sta SPRBUF1+SPRIORITY14
    GOTOXY 3,9
    jsl bH0_PRINTS_S1BAUDIENCE_06
    GOTOXY 4,9
    jsl bH0_PRINTS_S1BAUDIENCE_07
    GOTOXY 5,9
    jsl bH0_PRINTS_S1BAUDIENCE_08
    GOTOXY 6,9
    jsl bH0_PRINTS_S1BAUDIENCE_09
    jsr S1BSEQ_FFwinOpen         ; open
    ldx #$0060
    jsr SEQS1B_jegGirFaenAkkuratNaa
    jsr S1BSEQ_FFwinClose        ; close
    jsr SEQS1B_windowERASE
    GOTOXY 3,9
    jsl bH0_PRINTS_S1BAUDIENCE_10
    GOTOXY 4,9
    jsl bH0_PRINTS_S1BAUDIENCE_11
    GOTOXY 5,9
    jsl bH0_PRINTS_S1BAUDIENCE_12
    GOTOXY 6,9
    jsl bH0_PRINTS_S1BAUDIENCE_13
    jsr S1BSEQ_FFwinOpen         ; open
    ldx #$0060
    jsr SEQS1B_jegGirFaenAkkuratNaa
    jsr S1BSEQ_FFwinClose        ; close
    jsr SEQS1B_windowERASE
    jsr S1BSEQ_setAvatar_HERO    ; set hero avatar
    GOTOXY 4,9
    jsl bH0_PRINTS_S1BAUDIENCE_14
    jsr S1BSEQ_FFwinOpen         ; open
    ldx #$0060
    jsr SEQS1B_jegGirFaenAkkuratNaa
    jsr S1BSEQ_FFwinClose        ; close
    jsr SEQS1B_windowERASE
    ldx #$0040
    jsr SEQS1B_jegGirFaenAkkuratNaa
    jsl sym_SFX_DING_A_LING_HIGH
    ldx #$0020
    jsr SEQS1B_jegGirFaenAkkuratNaa
    GOTOXY 4,9
    jsl bH0_PRINTS_S1BAUDIENCE_15
    jsr S1BSEQ_FFwinOpen         ; open
    ldx #$0060
    jsr SEQS1B_jegGirFaenAkkuratNaa
    jsl SEQS1BthroneFADEOUTMOSA  ; MOSAIC FADE OUT (A QUICKIE)
    lda #$80
    sta $2100                    ; screen off, no brightness
    jsl sym_MUS_NO_SONG
    ldy #$000b

    ; FF CASTLE EXPLOSION "SCENE"
NAINAIBACALAO
    jsl sym_SFX_EXPLOSION
    ldx #$0010
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl sym_SFX_EXPLOSION
    ldx #$0010
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    dey
    cpy #$0000
    bne NAINAIBACALAO
    jsl sym_SFX_INTERFERENCE
    ldx #$0015
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl sym_SFX_INTERFERENCE
    ldx #$00e0
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    lda #$80
    sta $2100                  ; screen off, no brightness
    lda #$0f
    sta $2106                  ; disable mosaic for all layers
    lda #%00000010
    sta $212c                  ; disable all, but bg#2
    LOAD_PAL SEQ_S1B_DISCUSS_PAL
    wai
    LOAD_BLOCK2VRAM S1AM_S1B_SEQ_FONT,$5000,$0800
    wai
    wai
    jsl bH0_SPLSC_CLR          ; clear bg#2 tilemap
    GOTOXY 7,4
    jsl bH0_PRINTS_BADENDING_TEXT_00a
    GOTOXY 9,4
    jsl bH0_PRINTS_BADENDING_TEXT_01a
    GOTOXY 11,4
    jsl bH0_PRINTS_BADENDING_TEXT_02a
    GOTOXY 13,4
    jsl bH0_PRINTS_BADENDING_TEXT_03a
    GOTOXY 15,4
    jsl bH0_PRINTS_BADENDING_TEXT_04a
    jsl bH13_FADE_IN_macro
    ldx #$018e
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl bH13_FADE_OUT_macro
    jsl bH0_SPLSC_CLR
    ldx #$0060
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    GOTOXY 7,4
    jsl bH0_PRINTS_BADENDING_TEXT_00b
    GOTOXY 9,4
    jsl bH0_PRINTS_BADENDING_TEXT_01b
    GOTOXY 11,4
    jsl bH0_PRINTS_BADENDING_TEXT_02b
    GOTOXY 13,4
    jsl bH0_PRINTS_BADENDING_TEXT_03b
    GOTOXY 15,4
    jsl bH0_PRINTS_BADENDING_TEXT_04b
    jsl bH13_FADE_IN_macro
    ldx #$018e
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl bH13_FADE_OUT_macro
    jsl bH0_SPLSC_CLR
    ldx #$0060
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    GOTOXY 7,4
    jsl bH0_PRINTS_BADENDING_TEXT_00c
    GOTOXY 9,4
    jsl bH0_PRINTS_BADENDING_TEXT_01c
    GOTOXY 11,4
    jsl bH0_PRINTS_BADENDING_TEXT_02c
    GOTOXY 13,4
    jsl bH0_PRINTS_BADENDING_TEXT_03c
    jsl bH13_FADE_IN_macro
    ldx #$0255
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl bH13_FADE_OUT_macro
    jsl bH0_SPLSC_CLR
    ldx #$00a0
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jmp ENDING_BAD
    ;-------------------
    ; Sprite animation for characters inside the castle
S1B_SEQ_interiorFrChange
    lda a_byte
    cmp #$00
    beq S1B_SEQ_intFrChange01
    cmp #$01
    beq S1B_SEQ_intFrChange00
S1B_SEQ_intFrChange01
    lda #$04
    sta SPRBUF1+SFRAME12
    lda #$0c
    sta SPRBUF1+SFRAME14
    lda #$01
    sta a_byte
    jmp S1B_SEQ_intFrChangeEnde
S1B_SEQ_intFrChange00
    stz SPRBUF1+SFRAME12
    lda #$40
    sta SPRBUF1+SFRAME14
    stz a_byte
S1B_SEQ_intFrChangeEnde
    rts

    ; same as above, but for the characters inside the
    ; throne room (Labia, Vulva and hero).
S1B_SEQ_interiorFrChange2
    lda a_byte
    cmp #$00
    beq S1B_SEQ_intFrChange201
    cmp #$01
    beq S1B_SEQ_intFrChange200
S1B_SEQ_intFrChange201
    lda #$80
    sta SPRBUF1+SFRAME12
    lda #$08
    sta SPRBUF1+SFRAME13
    lda #$01
    sta a_byte
    jmp S1B_SEQ_intFrChangeEnde2
S1B_SEQ_intFrChange200
    lda #$84
    sta SPRBUF1+SFRAME12
    lda #$88
    sta SPRBUF1+SFRAME13
    stz a_byte
S1B_SEQ_intFrChangeEnde2
    rts

S1BSEQ_stillAnimated
    wai
    wai
    dex
    cpx #$0000
    beq S1BSEQ_stillAnimatedRTS
    dec a_byte2
    lda a_byte2
    cmp #$00                       ; is it time to change sprite?
    bne S1BSEQ_stillAnimated       ; branch if not yet
    jsr S1B_SEQ_interiorFrChange
    lda #$07
    sta a_byte2                    ; refill sprite anim delay var
    jmp S1BSEQ_stillAnimated
S1BSEQ_stillAnimatedRTS
    rts

    ; Make message window/box appear/disappear FF-style
    ;  NOT ANYMORE -- SILLY ME FOR TAKING ADVANTAGE OF SPRITES
    ; THAT DOESN'T EVEN EXIST. >.<
S1BSEQ_FFwinOpen
S1BSEQ_FFwinClose
    rts

S1BSEQ_setAvatar_KING
    jsr s1bseq_AvvyGotoThingieStuff
    jsl bH0_PRINTS_S1BAUDIENCE_AV_KING
    rts
S1BSEQ_setAvatar_HERO
    jsr s1bseq_AvvyGotoThingieStuff
    jsl bH0_PRINTS_S1BAUDIENCE_AV_HERO
    rts
s1bseq_AvvyGotoThingieStuff
    GOTOXY 4,4
    rts

SEQS1B_jegGirFaenAkkuratNaa
    wai
    wai
    dec a_byte2
    lda a_byte2
    cmp #$00                     ; is it time to change sprite?
    bne SEQS1B_jgGFANaaDEX       ; branch if not yet
    jsr S1B_SEQ_interiorFrChange2
    lda #$07
    sta a_byte2                  ; refill sprite anim delay var
SEQS1B_jgGFANaaDEX
    dex
    cpx #$0000
    bne SEQS1B_jegGirFaenAkkuratNaa
    rts

    ; --- castle/throneroom mosaic fade in (fast)
    ;---
SEQS1BthroneFADEINMOSA
    pha

    lda #$00
    sta $2100
    lda #$ff
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$01
    sta $2100
    lda #$ef
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$02
    sta $2100
    lda #$df
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$03
    sta $2100
    lda #$cf
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$04
    sta $2100
    lda #$bf
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$05
    sta $2100
    lda #$af
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$06
    sta $2100
    lda #$9f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$07
    sta $2100
    lda #$8f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$08
    sta $2100
    lda #$7f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$09
    sta $2100
    lda #$6f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0a
    sta $2100
    lda #$5f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0b
    sta $2100
    lda #$4f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0c
    sta $2100
    lda #$3f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0d
    sta $2100
    lda #$2f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0e
    sta $2100
    lda #$1f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0f
    sta $2100
    lda #$0f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    jmp SEQS1BthFADEMOSAende

SEQS1BthFADEMOSAwai
    wai
    wai
    rts
SEQS1BthFADEMOSAende
    pla
    rtl

    ; --- castle/throneroom mosaic fade out (fast)
    ;---
SEQS1BthroneFADEOUTMOSA
    pha

    lda #$0f
    sta $2100
    lda #$0f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0e
    sta $2100
    lda #$1f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0d
    sta $2100
    lda #$2f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0c
    sta $2100
    lda #$3f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0b
    sta $2100
    lda #$4f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$0a
    sta $2100
    lda #$5f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$09
    sta $2100
    lda #$6f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$08
    sta $2100
    lda #$7f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$07
    sta $2100
    lda #$8f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$06
    sta $2100
    lda #$9f
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$05
    sta $2100
    lda #$af
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$04
    sta $2100
    lda #$bf
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$03
    sta $2100
    lda #$cf
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$02
    sta $2100
    lda #$df
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$01
    sta $2100
    lda #$ef
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    lda #$00
    sta $2100
    lda #$ff
    sta $2106
    jsr SEQS1BthFADEMOSAwai
    jmp SEQS1BthFADEMOSAende

SEQS1B_windowERASE
    GOTOXY 6,9
    jsl bH0_PRINTS_S1BAUDIENCE_erase
    ldx #$0006
    jsr SEQS1B_jegGirFaenAkkuratNaa
    GOTOXY 5,9
    jsl bH0_PRINTS_S1BAUDIENCE_erase
    ldx #$0006
    jsr SEQS1B_jegGirFaenAkkuratNaa
    GOTOXY 4,9
    jsl bH0_PRINTS_S1BAUDIENCE_erase
    ldx #$0006
    jsr SEQS1B_jegGirFaenAkkuratNaa
    GOTOXY 3,9
    jsl bH0_PRINTS_S1BAUDIENCE_erase
    ldx #$0020
    jsr SEQS1B_jegGirFaenAkkuratNaa
    rts



;----
; file:/mnt/tux/bittornado/my_torrents/[Lunar] Bleach - 25 [14F9CC10].avi
; file:/mnt/tux/bittornado/my_torrents/[Lunar] Bleach - 26 [A6D4857C].avi
; bokmerke
ENDING_BAD
    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100
    lda #%00010011
    sta $212c
    LOAD_PAL ENDING_BAD_PAL
    wai
    LOAD_BLOCK2VRAM ENDING_BAD_BG1_MAP,$0000,$2000
    wai
    wai
    wai
    LOAD_BLOCK2VRAM ENDING_BAD_BG1_PIC,$2000,$6000
    wai
    wai
    wai
    LOAD_BLOCK2VRAM FONT_TILES,$5000,$0800
    wai
    wai
    wai
    LOAD_BLOCK2VRAM ENDING_BAD_SPR_PIC,$6000,$2000
    wai
    wai
    wai
    wai
    jsl bH0_SPLSC_CLR          ; clear bg#2 tilemap
    ldx #$0000                 ; reset bg#1 map location
    stx MAPX
    ldx #$ffff
    stx MAPY

    jsl TOTALLY_RESET_32x32_SPRITES

    ; Angela and Manko-chan
    lda #17
    sta SPRBUF1+SX  ; angela parachute
    sta SPRBUF1+SX2 ; angela (one and the only)
    lda #70
    sta SPRBUF1+SY
    lda #102
    sta SPRBUF1+SY2
    lda #70
    sta SPRBUF1+SX1 ; manko-chan balloon
    sta SPRBUF1+SX3 ; manko-chan herself
    lda #93
    sta SPRBUF1+SY1
    lda #125
    sta SPRBUF1+SY3

    lda #$30
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3

    stz SPRBUF1+SFRAME
    lda #$40
    sta SPRBUF1+SFRAME1
    lda #$04
    sta SPRBUF1+SFRAME2
    lda #$44
    sta SPRBUF1+SFRAME3


    stz SPRBUF2      ; ADD'D
    wai
;   lda #$ff
;   sta SPRBUF2
;   stz SPRBUF2+1

    jsl sym_MUS_SONG_SHERB
    stz a_byte                 ; sprite animation frame number
    stz a_byte2                ; sprite animation timer
    ldy #$09f6
    wai
    lda #$0f
    sta $2100

END_BAD_loop
    wai
    jsr END_BAD_sprAnim
    dey
    cpy #$0000
    bne END_BAD_loop
    ; do the Barney
    ldy #$006c
END_BAD_loop2
    wai
    ldx MAPY
    inx
    stx MAPY
    jsr END_BAD_sprAnim
    dey
    cpy #$0000
    bne END_BAD_loop2
    ; dramatic pause
    jsl sym_MUS_NO_SONG
    jsl sym_SFX_DING_A_LING_HIGH
    ldy #$005c
END_BAD_loop3
    wai
    wai
    jsr END_BAD_sprAnim
    dey
    cpy #$0000
    bne END_BAD_loop3
    ; I want my heroine shocked, not stirred!
    jsl sym_MUS_SONG_ASCHE
    wai
    lda #$c4
    sta SPRBUF1+SFRAME
    lda #$40
    sta SPRBUF1+SFRAME1
    lda #$c8
    sta SPRBUF1+SFRAME2
    lda #$c0
    sta SPRBUF1+SFRAME3
    ldy #$0114
END_BAD_loop4
    wai
    dey
    cpy #$0000
    bne END_BAD_loop4
    ;---
    jsl sym_SFX_EXPLOSION

    GOTOXY 6,23
    jsl bH0_PRINTZ_letter_E

    ldx #$0018
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl sym_SFX_EXPLOSION

    GOTOXY 6,25
    jsl bH0_PRINTZ_letter_N

    ldx #$0018
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl sym_SFX_EXPLOSION

    GOTOXY 6,27
    jsl bH0_PRINTZ_letter_D

    ldx #$0144
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl bH13_FADE_OUT_macro
    jsl bH0_SPLSC_CLR          ; clear bg#2 tilemap
    lda #$ff
    sta SPRBUF2
    sta SPRBUF2+1
    sta SPRBUF2+2
    sta SPRBUF2+3
    sta SPRBUF2+4
    sta SPRBUF2+5
    sta SPRBUF2+6
    sta SPRBUF2+7
    jml GAME_OVER

sym_END_BAD_sprAnim_ENDE
    jmp END_BAD_sprAnim_ENDE
END_BAD_sprAnim
    inc a_byte2
    lda a_byte2
    cmp #$07
    bne sym_END_BAD_sprAnim_ENDE
    stz a_byte2
END_BAD_sprAnim_doIt
    lda a_byte
    cmp #$00
    beq END_BAD_sprAnim_fr00
    cmp #$03
    beq END_BAD_sprAnim_fr03
    cmp #$02
    beq END_BAD_sprAnim_fr02
    cmp #$01
    beq END_BAD_sprAnim_fr01
END_BAD_sprAnim_fr00
    lda #%01110000
    sta SPRBUF1+SPRIORITY  ; ang
    sta SPRBUF1+SPRIORITY2
    lda #$08
    sta SPRBUF1+SFRAME
    lda #$0c
    sta SPRBUF1+SFRAME2
    lda #$40
    sta SPRBUF1+SFRAME1    ; manko
    lda #$44
    sta SPRBUF1+SFRAME3
    lda #$01
    sta a_byte
    jmp END_BAD_sprAnim_ENDE
END_BAD_sprAnim_fr03
    lda #$30
    sta SPRBUF1+SPRIORITY  ; ang
    sta SPRBUF1+SPRIORITY2
    lda #$00
    sta SPRBUF1+SFRAME
    lda #$04
    sta SPRBUF1+SFRAME2
    stz a_byte
    jmp END_BAD_sprAnim_ENDE
END_BAD_sprAnim_fr02
    lda #$30
    sta SPRBUF1+SPRIORITY  ; ang
    sta SPRBUF1+SPRIORITY2
    lda #$08
    sta SPRBUF1+SFRAME
    lda #$0c
    sta SPRBUF1+SFRAME2
    lda #$48
    sta SPRBUF1+SFRAME1    ; manko
    lda #$4c
    sta SPRBUF1+SFRAME3
    lda #$03
    sta a_byte
    jmp END_BAD_sprAnim_ENDE
END_BAD_sprAnim_fr01
    lda #$30
    sta SPRBUF1+SPRIORITY  ; ang
    sta SPRBUF1+SPRIORITY2
    lda #$00
    sta SPRBUF1+SFRAME
    lda #$04
    sta SPRBUF1+SFRAME2
    lda #$02
    sta a_byte
END_BAD_sprAnim_ENDE
    rts

;self
;   jmp self ;-)


.ENDASM

sym_END_BAD_sprAnim_ENDE
    jmp END_BAD_sprAnim_ENDE
END_BAD_sprAnim
    inc a_byte2
    lda a_byte2
    cmp #$07
    bne sym_END_BAD_sprAnim_ENDE
    stz a_byte2
END_BAD_sprAnim_doIt
    lda a_byte
    cmp #$00
    beq END_BAD_sprAnim_fr00
    cmp #$03
    beq END_BAD_sprAnim_fr03
    cmp #$02
    beq END_BAD_sprAnim_fr02
    cmp #$01
    beq END_BAD_sprAnim_fr01
END_BAD_sprAnim_fr00
    lda #%01110000
    sta SPRBUF1+SPRIORITY4 ; ang
    sta SPRBUF1+SPRIORITY6
    lda #$08
    sta SPRBUF1+SFRAME4
    lda #$0c
    sta SPRBUF1+SFRAME6
    lda #$40
    sta SPRBUF1+SFRAME5    ; manko
    lda #$44
    sta SPRBUF1+SFRAME7
    lda #$01
    sta a_byte
    jmp END_BAD_sprAnim_ENDE
END_BAD_sprAnim_fr03
    lda #$30
    sta SPRBUF1+SPRIORITY4 ; ang
    sta SPRBUF1+SPRIORITY6
    lda #$00
    sta SPRBUF1+SFRAME4
    lda #$04
    sta SPRBUF1+SFRAME6
    stz a_byte
    jmp END_BAD_sprAnim_ENDE
END_BAD_sprAnim_fr02
    lda #$30
    sta SPRBUF1+SPRIORITY4 ; ang
    sta SPRBUF1+SPRIORITY6
    lda #$08
    sta SPRBUF1+SFRAME4
    lda #$0c
    sta SPRBUF1+SFRAME6
    lda #$48
    sta SPRBUF1+SFRAME5    ; manko
    lda #$4c
    sta SPRBUF1+SFRAME7
    lda #$03
    sta a_byte
    jmp END_BAD_sprAnim_ENDE
END_BAD_sprAnim_fr01
    lda #$30
    sta SPRBUF1+SPRIORITY4 ; ang
    sta SPRBUF1+SPRIORITY6
    lda #$00
    sta SPRBUF1+SFRAME4
    lda #$04
    sta SPRBUF1+SFRAME6
    lda #$02
    sta a_byte
END_BAD_sprAnim_ENDE
    rts

.ASM

;--------------------------------

S1B_SEQ_WARNINGLOADAH

    lda #$09
    sta a_byte

    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100
    lda #$03
    sta $212c                   ; disable all, but bg#1&2
    wai
    LOAD_BLOCK2VRAM BG_SEQUENCETIME_BANNER_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM BG_SEQUENCETIME_BANNER_PIC,$2000,$6000
    wai
    wai
;   LOAD_BLOCK2VRAM S1AM_S1B_SEQ_FONT,$5000,$0800
    LOAD_BLOCK2VRAM SEQ_WARNING_FONT,$5000,$0800
    wai
    wai



    lda #$02                   ; select bg colour index #2
    sta $2121
    lda #$42
    sta $2122
    lda #$2c
    sta $2122

    ldx #$00d8                  ; set bg#1 tilemap position
    stx MAPX
    ldx #$0000
    stx MAPY

    jsl bH0_SPLSC_CLR           ; wipe current bg2 map
    jsl bH0_PRINTS_SB1_SEQWLOADAH_banner
    wai
    jsl bH0_PRINTS_SB1_SEQWLOADAH_txt1
    jsl bH0_PRINTS_SB1_SEQWLOADAH_box
    wai

    jsl bH13_FADE_IN_macro
    ldx #$6f
    jsl S1B_SEQ_WARNINGLOADAH_wai

    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 9-1=8
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 8-1=7
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 7-1=6
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    jsl bH0_PRINTS_SB1_SEQWLOADAH_txt2
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 6-1=5
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 5-1=4
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    jsl bH0_PRINTS_SB1_SEQWLOADAH_txt3
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 4-1=3
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 3-1=2
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 2-1=1
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    jsl bH0_PRINTS_SB1_SEQWLOADAH_txt4
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai
    dec a_byte ; 1-1=0
    jsl bH0_PRINTS_SB1_SEQWLOADAH_num ; num is read from 'a_byte'
    ldx #$60
    jsl S1B_SEQ_WARNINGLOADAH_wai

    jsl bH13_FADE_OUT_MOSAIC_macro
    jsl bH0_SPLSC_CLR           ; wipe current bg2 map
    rtl

S1B_SEQ_WARNINGLOADAH_wai       ; not as in Steve Vai, wai okkesom er
    wai
    jsr S1B_SEQ_WLOADAHCHKSTRT
    phx
    ldx MAPX                    ; scroll the 'sequence time' banner thingie
    inx
    inx
    stx MAPX
    plx
    dex
    cpx #$0000
    bne S1B_SEQ_WARNINGLOADAH_wai
    rtl

S1B_SEQ_WLOADAHCHKSTRT
    lda joy1+1                  ; check if 'start'-button is pressed
    and #$10
    beq S1B_SEQ_WLOADAHCHKSTRT2
    jml GAME_OVER               ; if pressed then skip the sequence
S1B_SEQ_WLOADAHCHKSTRT2
    rts



;================================================================


boss1Clear
;=========
    ; add an additional sprite palette -- this pal is put to use when
    ; when the boss is exploding for enhanced effect :D
    lda #$90
    sta $2121
    lda #$f0
    sta $2122
    lda #$43
    sta $2122
    lda #$18
    sta $2122
    lda #$21
    sta $2122
    lda #$d1
    sta $2122
    lda #$18
    sta $2122
    lda #$18
    sta $2122
    lda #$21
    sta $2122
    lda #$18
    sta $2122
    lda #$21
    sta $2122
    lda #$18
    sta $2122
    lda #$21
    sta $2122
    lda #$03
    sta $2122
    lda #$04
    sta $2122
    lda #$8c
    sta $2122
    lda #$10
    sta $2122
    lda #$da
    sta $2122
    lda #$39
    sta $2122
    lda #$b0
    sta $2122
    lda #$14
    sta $2122
    lda #$9c
    sta $2122
    lda #$52
    sta $2122
    lda #$7b
    sta $2122
    lda #$4a
    sta $2122
    lda #$d0
    sta $2122
    lda #$14
    sta $2122
    lda #$9b
    sta $2122
    lda #$4e
    sta $2122
    lda #$59
    sta $2122
    lda #$2d
    sta $2122
    lda #$ff
    sta $2122
    lda #$7f
    sta $2122

    lda #$80
    sta $2100
    LOAD_BLOCK2VRAM S1_SPRSET5b,$6000,$2000
    wai
    wai
    lda #$0f
    sta $2100


    lda #$48                    ; make sure that the evil smiley is on screen
    sta SPRBUF1+SFRAME13
    lda #$4c
    sta SPRBUF1+SFRAME14
    lda #$80
    sta SPRBUF1+SFRAME15
    lda #$84
    sta SPRBUF1+SFRAME16
    lda #$30
    sta SPRBUF1+SPRIORITY13     ; priority smiley sprites
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    stz SPRBUF1+SPRIORITY17     ; projectile sprites
    stz SPRBUF1+SPRIORITY18
    stz SPRBUF1+SPRIORITY19
    stz SPRBUF1+SPRIORITY20
    stz SPRBUF1+SPRIORITY21
    jsl PAL_setAllWhite         ; BG goes Barry WHITE
    ldx #$10
    jsl bH12_WAIT_FOR_THE_HOLY_WAI ; a short delay
    jsl PALFX_stepByStepRestoreColour

    stz ENM_14_hp               ; explosion anim (0-2)
    lda #$03
    sta ENM_15_hp               ; explosion sprite formation timer
    stz ENM_16_hp               ; explosion sprite formation (0-3)
    lda #$20
    sta ENM_17_hp ; separate delay that doesn't affect bg pal effect
    lda #$40
    sta ENM_13_speed           ; boss explosion duration counter
    stz ENM_14_speed           ; quit loop when this = 1

    stz SPRBUF2+3              ; make sure that ship stays on screen
    stz SPRBUF2+4              ; enable sprites 16,17,18,19,20 & 21
    lda #%11110000
    sta SPRBUF2+5
    lda #$ff
    sta SPRBUF2+6
    sta SPRBUF2+7

    jsr b1Clr_changeExplForm
    wai
    lda #$30
    sta SPRIORITY+SPRIORITY17
    sta SPRIORITY+SPRIORITY18
    sta SPRIORITY+SPRIORITY19
    sta SPRIORITY+SPRIORITY20
    sta SPRIORITY+SPRIORITY21

b1Clr_XPLODEsetUp
    jsl PAL_setAllWhite
    lda #$06
    sta ENM_13_hp
    stz $2121
    ldy #$0000
    ldx #$00ff
b1Clr_XPLODE
    pha
    lda ENM_14_speed
    cmp #$00
    bne b1Clr_XPLODE_finito
    pla
    phb
    lda #:BG_PAL
    pha
    plb
    lda BG_PAL, y
    plb
    sta $2122
    iny
    dec ENM_13_hp
    lda ENM_13_hp
    cmp #$00
    bne b1Clr_XPL_skipWAI
    lda #$16
    sta ENM_13_hp
    wai
    wai
b1Clr_XPL_skipWAI
    pha
    dec ENM_17_hp
    lda ENM_17_hp
    cmp #$00
    bne b1Clr_pullA
    lda #$27
    sta ENM_17_hp
    phx
    phy
    jsr b1Clr_changeExplAnim
    dec ENM_15_hp
    lda ENM_15_hp
    cmp #$00
    bne b1Clr_pullYXA
    jsr b1Clr_changeExplForm
    lda #$03
    sta ENM_15_hp
b1Clr_pullYXA
    ply
    plx
b1Clr_pullA
    pla
    dex
    cpx #$0000
    bne b1Clr_XPLODE
    jmp b1Clr_XPLODEsetUp


b1Clr_XPLODE_finito
    pla
    jsl sym_MUS_NO_SONG
    lda #$80
    sta $2100
    wai
    wai
    wai
    jsl sym_SFX_INTERFERENCE
    ldx #$0090
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl STAGE_CLEAR_SCREEN
    jsr STAGE2_SCREEN
    jmp STAGE2_INTRO_SEQUENCE
is2_GETOUTTA_S2INTSEQ
    jsl ANGELA_START_SCREEN
    jmp STAGE2TESTLESTEN
;---------------------------------------

b1Clr_changeExplAnim
    lda ENM_14_hp
    cmp #$02
    beq b1Clr_cEAnim_02
    cmp #$01
    beq b1Clr_cEAnim_01

    lda #$c0
    sta SPRBUF1+SFRAME17
    lda #$c8
    sta SPRBUF1+SFRAME18
    lda #$c4
    sta SPRBUF1+SFRAME19
    lda #$c8
    sta SPRBUF1+SFRAME20
    lda #$c4
    sta SPRBUF1+SFRAME21
    jsr b1Clr_cEAnim_disableBossGFX
    jmp b1Clr_cEAnim_ff
b1Clr_cEAnim_02
    lda #$c8
    sta SPRBUF1+SFRAME17
    lda #$c4
    sta SPRBUF1+SFRAME18
    lda #$c0
    sta SPRBUF1+SFRAME19
    lda #$c4
    sta SPRBUF1+SFRAME20
    lda #$c0
    sta SPRBUF1+SFRAME21
    jsr b1Clr_cEAnim_disableBossGFX
    jmp b1Clr_cEAnim_ff
b1Clr_cEAnim_01
    lda #$c4
    sta SPRBUF1+SFRAME17
    lda #$c0
    sta SPRBUF1+SFRAME18
    lda #$c8
    sta SPRBUF1+SFRAME19
    lda #$c0
    sta SPRBUF1+SFRAME20
    lda #$c8
    sta SPRBUF1+SFRAME21
    lda #$48
    sta SPRBUF1+SFRAME13
    lda #$4c
    sta SPRBUF1+SFRAME14
    lda #$80
    sta SPRBUF1+SFRAME15
    lda #$84
    sta SPRBUF1+SFRAME16
b1Clr_cEAnim_ff
    inc ENM_14_hp
    lda ENM_14_hp
    cmp #$03
    bne b1Clr_cEAnim_ffrts
    stz ENM_14_hp
b1Clr_cEAnim_ffrts
    rts
b1Clr_cEAnim_disableBossGFX
    lda #$8c
    sta SPRBUF1+SFRAME13
    sta SPRBUF1+SFRAME14
    sta SPRBUF1+SFRAME15
    sta SPRBUF1+SFRAME16
    phy
    ldy #$0002
    sty score_10
    dey
    sty score_1
    jsl ADD_SCORE
    jsl UPDATE_SCORE
    ply
    jsl sym_SFX_PING_LOW
    rts

;----------

b1Clr_changeExplForm
    ldx #$0000
    lda ENM_16_hp
    cmp #$03
    beq b1Clr_cEForm_03_sym
    cmp #$02
    beq b1Clr_cEForm_02_sym
    cmp #$01
    beq b1Clr_cEForm_01_sym
    jmp b1Clr_cEForm_00

b1Clr_cEForm_03_sym
    jmp b1Clr_cEForm_03
b1Clr_cEForm_02_sym
    jmp b1Clr_cEForm_02
b1Clr_cEForm_01_sym
    jmp b1Clr_cEForm_01

b1Clr_cEForm_00
    lda SPRBUF1+SX13
    ldx #10
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SX17
    lda SPRBUF1+SY13
    ldx #08
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SY17
    ;---
    lda SPRBUF1+SX13
    ldx #20
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX18
    lda SPRBUF1+SY13
    ldx #43
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY18
    ;---
    lda SPRBUF1+SX13
    lda SPRBUF1+SX13
    ldx #38
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX19
    lda SPRBUF1+SY13
    ldx #06
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SY19
    ;---
    lda SPRBUF1+SX13
    ldx #09
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SX20
    lda SPRBUF1+SY13
    ldx #30
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY20
    ;---
    lda SPRBUF1+SX13
    ldx #10
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX21
    lda SPRBUF1+SY13
    ldx #04
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY21
    lda #$01
    sta ENM_16_hp
    ;---
    lda #%00110010
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    jmp b1Clr_cEForm_ff
b1Clr_cEForm_03
    lda SPRBUF1+SX13
    ldx #22
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SX17
    lda SPRBUF1+SY13
    ldx #51
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY17
    ;---
    lda SPRBUF1+SX13
    sta SPRBUF1+SX18
    lda SPRBUF1+SY13
    ina
    sta SPRBUF1+SY18
    ;---
    lda SPRBUF1+SX13
    ldx #24
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX19
    lda SPRBUF1+SY13
    ldx #54
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY19
    ;---
    lda SPRBUF1+SX13
    ldx #40
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX20
    lda SPRBUF1+SY13
    ldx #10
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SY20
    ;---
    lda SPRBUF1+SX13
    ldx #04
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX21
    lda SPRBUF1+SY13
    ldx #22
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY21
    lda #$00
    sta ENM_16_hp
    jmp b1Clr_cEForm_ff
b1Clr_cEForm_02
    lda SPRBUF1+SX13
    ldx #28
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX17
    lda SPRBUF1+SY13
    ldx #13
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY17
    ;---
    lda SPRBUF1+SX13
    ldx #38
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX18
    lda SPRBUF1+SY13
    ldx #13
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SY18
    ;---
    lda SPRBUF1+SX13
    ldx #62
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX19
    lda SPRBUF1+SY13
    ldx #02
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY19
    ;---
    lda SPRBUF1+SX13
    ldx #04
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SX20
    lda SPRBUF1+SY13
    ldx #07
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SY20
    ;---
    lda SPRBUF1+SX13
    ldx #29
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX21
    lda SPRBUF1+SY13
    ldx #42
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY21
    lda #$03
    sta ENM_16_hp
    ;---
    lda #%00110000
    sta SPRBUF1+SPRIORITY13
    sta SPRBUF1+SPRIORITY14
    sta SPRBUF1+SPRIORITY15
    sta SPRBUF1+SPRIORITY16
    jmp b1Clr_cEForm_ff
b1Clr_cEForm_01
    lda SPRBUF1+SX13
    ldx #51
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX17
    lda SPRBUF1+SY13
    ldx #28
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY17
    ;---
    lda SPRBUF1+SX13
    ldx #10
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX18
    lda SPRBUF1+SY13
    ldx #53
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY18
    ;---
    lda SPRBUF1+SX13
    ldx #15
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SX19
    lda SPRBUF1+SY13
    ldx #03
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SY19
    ;---
    lda SPRBUF1+SX13
    ldx #12
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SX20
    lda SPRBUF1+SY13
    ldx #33
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY20
    ;---
    lda SPRBUF1+SX13
    ldx #18
    jsl MATH_ACCU_DEC_BY_X
    sta SPRBUF1+SX21
    lda SPRBUF1+SY13
    ldx #10
    jsl MATH_ACCU_INC_BY_X
    sta SPRBUF1+SY21
    lda #$02
    sta ENM_16_hp
b1Clr_cEForm_ff
    wai
    jsl sym_SFX_EXPLOSION
    dec ENM_13_speed
    lda ENM_13_speed
    cmp #$00
    bne b1Clr_cEForm_sviskerOgKruttslam
    inc ENM_14_speed
b1Clr_cEForm_sviskerOgKruttslam
    rts

;===============================

    ; this routine clears ALL bg-related colours to WHITE
    ; OAMs goes unaffected.
PAL_setAllWhite
    ldy #$007f                 ; number of times to repeat the loop
    stz $2121                  ; reset CGRAM index
PAL_sAW_loop
    lda #$ff
    sta $2122
    sta $2122
    dey
    cpy #$0000
    bne PAL_sAW_loop           ; branch if not finished
    wai
    rtl


    ; does just as it says it does -- a very simple effect
    ; that can be very cool depending on how colours/tiles
    ; are placed/organised on-screen. it looks kinda boring
    ; in the boss 1 clear explosion sequence, I'll admit that!
PALFX_stepByStepRestoreColour
    lda #$06
    sta ENM_13_hp
    stz $2121
    ldy #$0000
    ldx #$00ff
PAL_fFWTP_loop
    phb
    lda #:BG_PAL
    pha
    plb
    lda BG_PAL, y
    plb
    sta $2122
    iny
    dec ENM_13_hp
    lda ENM_13_hp
    cmp #$00
    bne PAL_fFWTP_skipWAI
    lda #$08
    sta ENM_13_hp
    wai
PAL_fFWTP_skipWAI
    dex
    cpx #$0000
    bne PAL_fFWTP_loop
    rtl

;=================

MATH_ACCU_DEC_BY_X
    dea
    dex
    cpx #$0000
    bne MATH_ACCU_DEC_BY_X
    rtl

MATH_ACCU_INC_BY_X
    ina
    dex
    cpx #$0000
    bne MATH_ACCU_INC_BY_X
    rtl

;================================================================


STAGE_CLEAR_SCREEN
    jsl bH12_INIT_VIDEO_03
    lda #$80
    sta $2100
    lda #%00010001
    sta $212c                  ; bg#1+oam only

    LOAD_PAL STAGE_CLEAR_PAL
    wai
    LOAD_BLOCK2VRAM MMENU_BG1_DAT,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM MMENU_BG1_GFX,$1000,$0800
    wai
    wai
    LOAD_BLOCK2VRAM STAGE_CLEAR_SPR,$6000,$2000

    jsl TOTALLY_RESET_32x32_SPRITES

    ldx #$0000
    stx MAPX
    stx MAPY

    lda #66
    sta SPRBUF1+SX
    lda #161
    sta SPRBUF1+SX1
    lda #129
    sta SPRBUF1+SX2
    lda #83
    sta SPRBUF1+SY
    lda #95
    sta SPRBUF1+SY1
    lda #130
    sta SPRBUF1+SY2
    lda #78
    sta SPRBUF1+SX3
    lda #102
    sta SPRBUF1+SX4
    lda #159
    sta SPRBUF1+SX5
    lda #115
    sta SPRBUF1+SY3
    lda #82
    sta SPRBUF1+SY4
    lda #113
    sta SPRBUF1+SY5  
    ;--
    lda #$3f
    sta SPRBUF1+SX6
    sta SPRBUF1+SX10
    lda #$5f
    sta SPRBUF1+SX7
    sta SPRBUF1+SX11
    lda #$7f
    sta SPRBUF1+SX8
    sta SPRBUF1+SX12
    lda #$9f
    sta SPRBUF1+SX9
    sta SPRBUF1+SX13
    lda #$4f
    sta SPRBUF1+SY6
    sta SPRBUF1+SY7
    sta SPRBUF1+SY8
    sta SPRBUF1+SY9
    lda #$6f
    sta SPRBUF1+SY10
    sta SPRBUF1+SY11
    sta SPRBUF1+SY12
    sta SPRBUF1+SY13

    lda #$c8
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1 
    sta SPRBUF1+SFRAME2
    lda #$80
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
    stz SPRBUF1+SFRAME6
    lda #$04
    sta SPRBUF1+SFRAME7
    lda #$08
    sta SPRBUF1+SFRAME8
    lda #$0c
    sta SPRBUF1+SFRAME9
    lda #$40
    sta SPRBUF1+SFRAME10
    lda #$44
    sta SPRBUF1+SFRAME11
    lda #$48
    sta SPRBUF1+SFRAME12
    lda #$4c
    sta SPRBUF1+SFRAME13

    lda #%00110010
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3
    sta SPRBUF1+SPRIORITY4
    sta SPRBUF1+SPRIORITY5
    lda #$30
    sta SPRBUF1+SPRIORITY6
    sta SPRBUF1+SPRIORITY7
    sta SPRBUF1+SPRIORITY8
    sta SPRBUF1+SPRIORITY9
    sta SPRBUF1+SPRIORITY10
    sta SPRBUF1+SPRIORITY11
    sta SPRBUF1+SPRIORITY12
    sta SPRBUF1+SPRIORITY13

    stz SPRBUF2
    stz SPRBUF2+1
    stz SPRBUF2+2
    stz SPRBUF2+3
    jsl sym_MUS_SONG_AXELAY
    ;--
    lda #$ff
    sta $2106                  ; teh blockiness
    stz ENM_13_hp              ; sprite shake animation
    stz ENM_14_hp              ; star blink frame anim
    lda #$ff
    sta ENM_15_hp              ; time it takes before player can skip screen
    stz ENM_16_hp              ; no keypresses allowed when this one = 0

    lda #$0f
    sta $2100
    jsr stgclr_SPRANIM
    wai
    wai
    lda #$ef
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$df
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$cf
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$bf
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$af
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$9f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$8f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$7f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$6f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$5f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$4f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$3f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$2f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$1f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai
    lda #$0f
    sta $2106
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    wai

stgclr_LOOP
    wai
    jsr stgclr_SPRANIM
    wai
    jsr stgclr_SCRLBG1
    jsr stgclr_SPRANIM
    jmp stgclr_chkKeyPress
stgclr_RETfromChkKeyPress
    jmp stgclr_LOOP

stgclr_SCRLBG1
    ldx MAPX
    inx
    stx MAPX
    ldx MAPY
    inx
    stx MAPY
    jsr stgclr_STARBLINK

    lda ENM_16_hp
    cmp #$01
    bne stgclr_scrlbg1DEC15HP
    jmp stgclr_scrlbg1RTS
stgclr_scrlbg1DEC15HP
    dec ENM_15_hp
    lda ENM_15_hp
    cmp #$00
    bne stgclr_scrlbg1RTS
    lda #$01
    sta ENM_16_hp
stgclr_scrlbg1RTS
    rts


stgclr_chkKeyPress
    lda joy1+1                 ; check start
    and #$10
    beq stgclr_keyX
    jmp stgclr_keyPressed
stgclr_keyX
    lda joy1                   ; check x
    and #$40
    beq stgclr_keyA
    jmp stgclr_keyPressed
stgclr_keyA
    lda joy1                   ; check a
    and #$80
    beq stgclr_keyB
    jmp stgclr_keyPressed
stgclr_keyB
    lda joy1+1                 ; check b
    and #$80
    beq stgclr_keyY
    jmp stgclr_keyPressed
stgclr_keyY
    lda joy1+1                 ; check y
    and #$40
    beq stgclr_RETfromChkKeyPress
stgclr_keyPressed
    jsl sym_MUS_NO_SONG
    jsl sym_SFX_GUN_FIRE
    lda #$08
    sta $2100
    ldx #$0020
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    lda #$80
    sta $2100
    rtl

sym_stgclr_sprAnim02
    jmp stgclr_sprAnim02
sym_stgclr_sprAnim01
    jmp stgclr_sprAnim01
stgclr_SPRANIM
    lda ENM_13_hp
    cmp #$03
    beq stgclr_sprAnim03
    cmp #$02
    beq sym_stgclr_sprAnim02
    cmp #$01
    beq sym_stgclr_sprAnim01
;stgclr_sprAnim00
    dec SPRBUF1+SY
    dec SPRBUF1+SY1
    dec SPRBUF1+SY2
    dec SPRBUF1+SY3
    dec SPRBUF1+SY4
    dec SPRBUF1+SY5
    dec SPRBUF1+SY
    dec SPRBUF1+SY1
    dec SPRBUF1+SY2
    dec SPRBUF1+SY3
    dec SPRBUF1+SY4
    dec SPRBUF1+SY5
    dec SPRBUF1+SY6
    dec SPRBUF1+SY7
    dec SPRBUF1+SY8
    dec SPRBUF1+SY9
    dec SPRBUF1+SY10
    dec SPRBUF1+SY11
    dec SPRBUF1+SY12
    dec SPRBUF1+SY13
    dec SPRBUF1+SY6
    dec SPRBUF1+SY7
    dec SPRBUF1+SY8
    dec SPRBUF1+SY9
    dec SPRBUF1+SY10
    dec SPRBUF1+SY11
    dec SPRBUF1+SY12
    dec SPRBUF1+SY13
    inc ENM_13_hp
    jmp stgclr_sprAnimFF
stgclr_sprAnim03
    dec SPRBUF1+SX
    dec SPRBUF1+SX1
    dec SPRBUF1+SX2
    dec SPRBUF1+SX3
    dec SPRBUF1+SX4
    dec SPRBUF1+SX5
    dec SPRBUF1+SX
    dec SPRBUF1+SX1
    dec SPRBUF1+SX2
    dec SPRBUF1+SX3
    dec SPRBUF1+SX4
    dec SPRBUF1+SX5
    dec SPRBUF1+SX6
    dec SPRBUF1+SX7
    dec SPRBUF1+SX8
    dec SPRBUF1+SX9
    dec SPRBUF1+SX10
    dec SPRBUF1+SX11
    dec SPRBUF1+SX12
    dec SPRBUF1+SX13
    dec SPRBUF1+SX6
    dec SPRBUF1+SX7
    dec SPRBUF1+SX8
    dec SPRBUF1+SX9
    dec SPRBUF1+SX10
    dec SPRBUF1+SX11
    dec SPRBUF1+SX12
    dec SPRBUF1+SX13
    stz ENM_13_hp
    jmp stgclr_sprAnimFF
stgclr_sprAnim02
    inc SPRBUF1+SY
    inc SPRBUF1+SY1
    inc SPRBUF1+SY2
    inc SPRBUF1+SY3
    inc SPRBUF1+SY4
    inc SPRBUF1+SY5
    inc SPRBUF1+SY
    inc SPRBUF1+SY1
    inc SPRBUF1+SY2
    inc SPRBUF1+SY3
    inc SPRBUF1+SY4
    inc SPRBUF1+SY5
    inc SPRBUF1+SY6
    inc SPRBUF1+SY7
    inc SPRBUF1+SY8
    inc SPRBUF1+SY9
    inc SPRBUF1+SY10
    inc SPRBUF1+SY11
    inc SPRBUF1+SY12
    inc SPRBUF1+SY13
    inc SPRBUF1+SY6
    inc SPRBUF1+SY7
    inc SPRBUF1+SY8
    inc SPRBUF1+SY9
    inc SPRBUF1+SY10
    inc SPRBUF1+SY11
    inc SPRBUF1+SY12
    inc SPRBUF1+SY13
    inc ENM_13_hp
    jmp stgclr_sprAnimFF
stgclr_sprAnim01
    inc SPRBUF1+SX
    inc SPRBUF1+SX1
    inc SPRBUF1+SX2
    inc SPRBUF1+SX3
    inc SPRBUF1+SX4
    inc SPRBUF1+SX5
    inc SPRBUF1+SX
    inc SPRBUF1+SX1
    inc SPRBUF1+SX2
    inc SPRBUF1+SX3
    inc SPRBUF1+SX4
    inc SPRBUF1+SX5
    inc SPRBUF1+SX6
    inc SPRBUF1+SX7
    inc SPRBUF1+SX8
    inc SPRBUF1+SX9
    inc SPRBUF1+SX10
    inc SPRBUF1+SX11
    inc SPRBUF1+SX12
    inc SPRBUF1+SX13
    inc SPRBUF1+SX6
    inc SPRBUF1+SX7
    inc SPRBUF1+SX8
    inc SPRBUF1+SX9
    inc SPRBUF1+SX10
    inc SPRBUF1+SX11
    inc SPRBUF1+SX12
    inc SPRBUF1+SX13
    inc ENM_13_hp
stgclr_sprAnimFF
    rts

sym_stgclr_strblnk06
    jmp stgclr_strblnk06
sym_stgclr_strblnk05
    jmp stgclr_strblnk05
sym_stgclr_strblnk04
    jmp stgclr_strblnk04
sym_stgclr_strblnk03
    jmp stgclr_strblnk03
sym_stgclr_strblnk02
    jmp stgclr_strblnk02
sym_stgclr_strblnk01
    jmp stgclr_strblnk01
stgclr_STARBLINK
    lda ENM_14_hp
    cmp #$06
    beq sym_stgclr_strblnk06
    cmp #$05
    beq sym_stgclr_strblnk05
    cmp #$04
    beq sym_stgclr_strblnk04
    cmp #$03
    beq sym_stgclr_strblnk03
    cmp #$02
    beq sym_stgclr_strblnk02
    cmp #$01
    beq sym_stgclr_strblnk01
    cmp #$07
    beq sym_stgclr_strblnk05
    cmp #$08
    beq sym_stgclr_strblnk04
    cmp #$09
    beq sym_stgclr_strblnk03
    cmp #$0a
    beq sym_stgclr_strblnk02
    cmp #$0b
    beq sym_stgclr_strblnk01
;stgclr_strblnk00
    lda #$8c
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    lda #$80
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
    jmp stgclr_strblnkFF
stgclr_strblnk06
    lda #$80
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    lda #$8c
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
    jmp stgclr_strblnkFF
stgclr_strblnk05
    lda #$84
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    lda #$c8
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
stgclr_strblnk04
    lda #$88
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    lda #$c4
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
    jmp stgclr_strblnkFF
stgclr_strblnk03
    lda #$c0
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
    jmp stgclr_strblnkFF
stgclr_strblnk02
    lda #$c4
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    lda #$88
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
    jmp stgclr_strblnkFF
stgclr_strblnk01
    lda #$c8
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    lda #$84
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
stgclr_strblnkFF
    inc ENM_14_hp
    lda ENM_14_hp
    cmp #$0d
    bne stgclr_strblnkENDE
    stz ENM_14_hp
stgclr_strblnkENDE
    rts


;================================================================


STAGE2_SCREEN

    jsl bH12_INIT_VIDEO_04
    lda #$80
    sta $2100
    jsl TOTALLY_RESET_32x32_SPRITES

    LOAD_PAL STAGE2_PAL
    wai
    LOAD_BLOCK2VRAM STAGE2_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM STAGE2_PIC,$2000,$6000
    wai
    wai

    lda #$01
    sta $212c                  ; bg#1 enable only
    ldx #$0000
    stx MAPX
    stx MAPY

    jsl sym_MUS_SONG_C1GO
    jsl bH13_FADE_IN_macro
    ldx #$0090
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    jsl bH13_FADE_OUT_macro
    rts


;===============================================================


ANGELA_START_SCREEN

    lda #$80
    sta $2100
    lda #$10
    sta $212c                  ; sprites only

    LOAD_PAL ANGSTART_PAL
    wai
    LOAD_BLOCK2VRAM ANGSTART_GFX,$6000,$2000
    wai
    wai

    lda #$40
    sta SPRBUF1+SX
    lda #$60
    sta SPRBUF1+SX1
    lda #$80
    sta SPRBUF1+SX2
    lda #$a0
    sta SPRBUF1+SX3
    lda #$67
    sta SPRBUF1+SY
    sta SPRBUF1+SY1
    sta SPRBUF1+SY2
    sta SPRBUF1+SY3

    stz SPRBUF1+SFRAME
    lda #$04
    sta SPRBUF1+SFRAME1
    lda #$08
    sta SPRBUF1+SFRAME2
    lda #$0c
    sta SPRBUF1+SFRAME3

    lda #$30
    sta SPRBUF1+SPRIORITY
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3

    stz SPRBUF2
    ldx #$0032
    jsl bH12_WAIT_FOR_THE_HOLY_WAI
    lda #$0f
    sta $2100
    ldx #$0064
    jsl bH12_WAIT_FOR_THE_HOLY_WAI

    lda #$80
    sta $2100
    lda #%00011111
    sta $212c
    jsl TOTALLY_RESET_32x32_SPRITES
    rtl


;=====================================================================
;=======%%%%%===%%%%%%%%====%=======%%%===%%%%%%======%%%=============
;======%%%%%%===%%%%%%%%===%%%====%%%%%===%%%%%%====%%%%%%============
;======%%==========%%=====%%=%%===%%======%%=======%%%%%%%%===========
;======%%%%%=======%%====%%===%%==%%=%%%==%%=======%%==%%%%===========
;=======%%%%%======%%====%%%%%%%==%%=%%%==%%%%%=======%%%%============
;==========%%======%%====%%%%%%%==%%==%%==%%%%%======%%%%=============
;======%%%%%%======%%====%%===%%==%%%%%%==%%========%%%%%%%%==========
;======%%%%%=======%%====%%===%%===%%%%%==%%%%%%%==%%%%%%%%%==========
;=====================================================================

.INCLUDE "stage2.s"

.ENDASM
STAGE2TESTLESTEN

    jsl bH12_INIT_VIDEO_03
    lda #$80
    sta $2100
    lda #%00010011
    sta $212c

    LOAD_PAL S2_LEVEL_PAL
    wai
    LOAD_BLOCK2VRAM S2_MAPTEST_MAP,$0000,$2000
    wai
    wai
    LOAD_BLOCK2VRAM S2_MAPTEST_PIC,$1000,$0800
    wai
    wai
    LOAD_BLOCK2VRAM FONT2_TILES,$2000,$1800
    wai
    wai
    LOAD_BLOCK2VRAM S2_SPRSET1_PIC,$6000,$2000

    jsl TOTALLY_RESET_32x32_SPRITES
    jsl INITIALIZE_HUD_PAL

    jsl bH0_SPLSC_CLR
    jsl CUT_PLYFLD
    jsl bH13_BLACK_SIDES_MKAY
    jsl WRITE_STATUSBAR_LV1
    jsl ADD_BLACK_SIDES_MKAY
    jsl WRITE_FOOBAR_LV1
    jsl UPDATE_SCORE
    jsl WRITE_LIVES_REMAINING
    jsl WRITE_HP_REMAINING

    stz $2121
    lda #$08
    sta $2122
    lda #$42
    sta $2122

    ldx #$0000
    stx MAPX
    stx MAPY

    stz ENM_13_hp              ; angela frame number
    stz ENM_14_hp              ; angela walk delay
    stz ENM_15_hp              ; angela duck frame #1 lockout
    stz ENM_16_hp              ; ball 'n chain interval

    ; angela setup
    lda #41
    sta SPRBUF1+SX
    lda #180
    sta SPRBUF1+SY
    lda #%00000100 ; #%00110100
    sta SPRBUF1+SPRIORITY
    stz SPRBUF1+SFRAME

    ; ball 'n chain setup
;   125,94 (innerste lenke) spr4
;   125,110 spr3
;   125,126 spr2
;   117,142 (ballen) spr1

    lda #117
    sta SPRBUF1+SX1
;   lda #136 ; this does for a more addams/mario like swing, but
    lda #130 ; this one makes it look much more professional ;-)
    sta SPRBUF1+SY1
    lda #125
    sta SPRBUF1+SX2
    sta SPRBUF1+SX3
    sta SPRBUF1+SX4
    lda #125
    sta SPRBUF1+SY2
    lda #110
    sta SPRBUF1+SY3
    lda #94
    sta SPRBUF1+SY4

    lda #%00110010
    sta SPRBUF1+SPRIORITY1
    sta SPRBUF1+SPRIORITY2
    sta SPRBUF1+SPRIORITY3
    sta SPRBUF1+SPRIORITY4
    lda #$4c
    sta SPRBUF1+SFRAME1
    lda #$80
    sta SPRBUF1+SFRAME2
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4


    ; sprites enabled: 0,1,2,3,4,5
    stz SPRBUF2
    lda #%11111100
    sta SPRBUF2+1

    lda #$0f                   ; screen on, full brightness
    sta $2100

    ldy #$0000                 ; ball 'n chain data pointer
                               ; DO NOT USE THIS REGISTER TO ANYTHING
                               ; OTHER THAN THE BALL 'n CHAIN ROUTINE
                               ; OR ELSE YOU'LL GET FUNNY RESULTS =]
S2_testeLoopen
    wai

    inc ENM_16_hp
    lda ENM_16_hp
    cmp #$02
    bne S2_tstLoopn_forts
    jsr S2_BALL_n_CHAIN_UPDATE
    stz ENM_16_hp
S2_tstLoopn_forts
    jsr S2_PROCESS_INPUT
    jsr S2_DRAW_ANGELA
    jmp S2_testeLoopen




S2_PROCESS_INPUT

    lda joy1+1                 ; check down
    cmp #$04
    bne s2_prcsInpt_notDown

    lda ENM_15_hp
    cmp #$05
    beq s2_prcsInpt_df1locked
    inc ENM_15_hp
    lda #$06
    sta ENM_13_hp
    jmp s2_prcsInpt_ende
s2_prcsInpt_df1locked
    lda #$07
    sta ENM_13_hp              ; set angela ducking frame #2/2
    jmp s2_prcsInpt_ende


s2_prcsInpt_notDown
;==================
    stz ENM_15_hp              ; uncheck angela duck #1 frame lockout
    lda joy1+1                 ; check left
    and #$02
    beq s2_prcsInpt_notLeft

    lda ENM_13_hp              ; restrict the player from moving the
    cmp #$07                   ; character whilst ducking.
    beq s2_prcsInpt_ende

    jsr s2_angelaFrame_WALK_INC
    lda #%01110100
    sta SPRBUF1+SPRIORITY
    dec SPRBUF1+SX
    jmp s2_prcsInpt_ende

s2_prcsInpt_notLeft
;==================
    lda joy1+1                 ; check right
    and #$01
    beq s2_prcsInpt_noMovement

    stz ENM_15_hp              ; uncheck angela duck #1 frame lockout

    lda ENM_13_hp              ; restrict the player from moving the
    cmp #$07                   ; character whilst ducking.
    beq s2_prcsInpt_ende

    jsr s2_angelaFrame_WALK_INC
    lda #%00110100
    sta SPRBUF1+SPRIORITY
    inc SPRBUF1+SX
    jmp s2_prcsInpt_ende

s2_prcsInpt_noMovement
    stz ENM_13_hp              ; reset angela frame
    stz ENM_14_hp              ; reset angela walking frame delay
    stz ENM_15_hp              ; reset angela duck frame #1 lockout

s2_prcsInpt_ende
    rts


S2_DRAW_ANGELA
    lda ENM_13_hp
    cmp #$00
    beq s2_drAng_00
    cmp #$01
    beq s2_drAng_01
    cmp #$02
    beq s2_drAng_00
    cmp #$03
    beq s2_drAng_02
    cmp #$04
    beq s2_drAng_00
    cmp #$05
    beq s2_drAng_01
    ;---
    cmp #$06
    beq s2_drAng_03
    cmp #$07
    beq s2_drAng_04
    jmp s2_drAng_ff
s2_drAng_00                    ; angela still frame
    stz SPRBUF1+SFRAME
    jmp s2_drAng_ff
s2_drAng_01                    ; angela walking frame #1/2
    lda #$04
    sta SPRBUF1+SFRAME
    jmp s2_drAng_ff
s2_drAng_02                    ; angela walking frame #2/2
    lda #$08
    sta SPRBUF1+SFRAME
    jmp s2_drAng_ff
s2_drAng_03                    ; angela ducking frame #1/2
    lda #$0c
    sta SPRBUF1+SFRAME
    jmp s2_drAng_ff
s2_drAng_04                    ; angela ducking frame #2/2
    lda #$40
    sta SPRBUF1+SFRAME
s2_drAng_ff
    rts


s2_angelaFrame_WALK_INC
    inc ENM_14_hp
    lda ENM_14_hp
    cmp #$05
    bne s2_angFrWLKINC_ende
    stz ENM_14_hp
    inc ENM_13_hp
    lda ENM_13_hp
    cmp #$06
    bne s2_angFrWLKINC_ende
    stz ENM_13_hp
s2_angFrWLKINC_ende
    rts


;----------------------------------------------------------------

; (ab)uses: 'ENM_13_leftRight' for holding the instruction byte,
;           and 'ENM_13_numfr' for amount of pixels to dec/inc.

S2_BALL_n_CHAIN_UPDATE

    jsr s2_BLnCHN_fetchChunk
    lda ENM_13_leftRight
    cmp #$ff
    beq s2_blchn_chain1Y
    cmp #$a0
    bne s2_blchn_chain1xINC
    lda SPRBUF1+SX4
    jsr s2_BLnCHN_DEC
    sta SPRBUF1+SX4
    jmp s2_blchn_chain1Y
s2_blchn_chain1xINC
    lda SPRBUF1+SX4
    jsr s2_BLnCHN_INC
    sta SPRBUF1+SX4

s2_blchn_chain1Y
    jsr s2_BLnCHN_fetchChunk
    lda ENM_13_leftRight
    cmp #$ff
    beq s2_blchn_chain2X
    cmp #$a0
    bne s2_blchn_chain1yINC
    lda SPRBUF1+SY4
    jsr s2_BLnCHN_DEC
    sta SPRBUF1+SY4
    jmp s2_blchn_chain2X
s2_blchn_chain1yINC
    lda SPRBUF1+SY4
    jsr s2_BLnCHN_INC
    sta SPRBUF1+SY4

s2_blchn_chain2X
    jsr s2_BLnCHN_fetchChunk
    lda ENM_13_leftRight
    cmp #$ff
    beq s2_blchn_chain2Y
    cmp #$a0
    bne s2_blchn_chain2xINC
    lda SPRBUF1+SX3
    jsr s2_BLnCHN_DEC
    sta SPRBUF1+SX3
    jmp s2_blchn_chain2Y
s2_blchn_chain2xINC
    lda SPRBUF1+SX3
    jsr s2_BLnCHN_INC
    sta SPRBUF1+SX3

s2_blchn_chain2Y
    jsr s2_BLnCHN_fetchChunk
    lda ENM_13_leftRight
    cmp #$ff
    beq s2_blchn_chain3X
    cmp #$a0
    bne s2_blchn_chain2yINC
    lda SPRBUF1+SY3
    jsr s2_BLnCHN_DEC
    sta SPRBUF1+SY3
    jmp s2_blchn_chain3X
s2_blchn_chain2yINC
    lda SPRBUF1+SY3
    jsr s2_BLnCHN_INC
    sta SPRBUF1+SY3

s2_blchn_chain3X
    jsr s2_BLnCHN_fetchChunk
    lda ENM_13_leftRight
    cmp #$ff
    beq s2_blchn_chain3Y
    cmp #$a0
    bne s2_blchn_chain3xINC
    lda SPRBUF1+SX2
    jsr s2_BLnCHN_DEC
    sta SPRBUF1+SX2
    jmp s2_blchn_chain3Y
s2_blchn_chain3xINC
    lda SPRBUF1+SX2
    jsr s2_BLnCHN_INC
    sta SPRBUF1+SX2

s2_blchn_chain3Y
    jsr s2_BLnCHN_fetchChunk
    lda ENM_13_leftRight
    cmp #$ff
    beq s2_blchn_chain4X
    cmp #$a0
    bne s2_blchn_chain3yINC
    lda SPRBUF1+SY2
    jsr s2_BLnCHN_DEC
    sta SPRBUF1+SY2
    jmp s2_blchn_chain4X
s2_blchn_chain3yINC
    lda SPRBUF1+SY2
    jsr s2_BLnCHN_INC
    sta SPRBUF1+SY2

s2_blchn_chain4X
    jsr s2_BLnCHN_fetchChunk
    lda ENM_13_leftRight
    cmp #$ff
    beq s2_blchn_chain4Y
    cmp #$a0
    bne s2_blchn_chain4xINC
    lda SPRBUF1+SX1
    jsr s2_BLnCHN_DEC
    sta SPRBUF1+SX1
    jmp s2_blchn_chain4Y
s2_blchn_chain4xINC
    lda SPRBUF1+SX1
    jsr s2_BLnCHN_INC
    sta SPRBUF1+SX1

s2_blchn_chain4Y
    jsr s2_BLnCHN_fetchChunk
    lda ENM_13_leftRight
    cmp #$ff
    beq s2_blchn_chainENDE
    cmp #$a0
    bne s2_blchn_chain4yINC
    lda SPRBUF1+SY1
    jsr s2_BLnCHN_DEC
    sta SPRBUF1+SY1
    jmp s2_blchn_chainENDE
s2_blchn_chain4yINC
    lda SPRBUF1+SY1
    jsr s2_BLnCHN_INC
    sta SPRBUF1+SY1

s2_blchn_chainENDE
    rts

    



s2_BLnCHN_fetchChunk
    jsr s2_BLnCHN_getDataByte  ; get instruction byte
    sta ENM_13_leftRight       ; store it
    jsr s2_BLnCHN_getDataByte  ; get value byte
    sta ENM_13_numfr           ; store it
    rts

s2_BLnCHN_getDataByte
    phb
    lda #:PATTERN_BALL_n_CHAIN
    pha
    plb
    lda PATTERN_BALL_n_CHAIN, y
    plb
    iny
    cpy #560
    beq s2_blchn_gDB_RES
    cpy #1120
    bne s2_blchn_gDB_RTS
    ldy #$0000
s2_blchn_gDB_RES
    pha
    lda #117
    sta SPRBUF1+SX1
;   lda #142                   ; this does for a more addams/mario like swing,
    lda #130                   ; but this one makes it look quite professional
    sta SPRBUF1+SY1
    lda #125
    sta SPRBUF1+SX2
    sta SPRBUF1+SX3
    sta SPRBUF1+SX4
    lda #125
    sta SPRBUF1+SY2
    lda #110
    sta SPRBUF1+SY3
    lda #94
    sta SPRBUF1+SY4
    pla
s2_blchn_gDB_RTS
    rts

s2_BLnCHN_DEC
    ldx #$0000
    ldx ENM_13_numfr
    cpx #$0000
    beq s2_BLnCHN_DECINCRTS
s2_blchn_decLoop
    dea
    dex
    cpx #$0000
    bne s2_blchn_decLoop
    rts

s2_BLnCHN_INC
    ldx #$0000
    ldx ENM_13_numfr
    cpx #$0000
    beq s2_BLnCHN_DECINCRTS
s2_blchn_incLoop
    ina
    dex
    cpx #$0000
    bne s2_blchn_incLoop
s2_BLnCHN_DECINCRTS
    rts
.ASM

;================================================================

    ; this routine totally whips the sprites and makes them learn
    ; where David bought his beer. should definitely save this
    ; project quite some bytes in the near future.   I refuse to
    ; write another game for teh snes unless I pinch myself in the
    ; arm and write a kickass game library ;)

TOTALLY_RESET_32x32_SPRITES
    lda #$ff
    sta SPRBUF2
    sta SPRBUF2+1
    sta SPRBUF2+2
    sta SPRBUF2+3
    sta SPRBUF2+4
    sta SPRBUF2+5
    sta SPRBUF2+6
    sta SPRBUF2+7
    stz SPRBUF1+SX
    stz SPRBUF1+SY
    stz SPRBUF1+SX1
    stz SPRBUF1+SY1
    stz SPRBUF1+SX2
    stz SPRBUF1+SY2
    stz SPRBUF1+SX3
    stz SPRBUF1+SY3
    stz SPRBUF1+SX4
    stz SPRBUF1+SY4
    stz SPRBUF1+SX5
    stz SPRBUF1+SY5
    stz SPRBUF1+SX6
    stz SPRBUF1+SY6
    stz SPRBUF1+SX7
    stz SPRBUF1+SY7
    stz SPRBUF1+SX8
    stz SPRBUF1+SY8
    stz SPRBUF1+SX9
    stz SPRBUF1+SY9
    stz SPRBUF1+SX10
    stz SPRBUF1+SY10
    stz SPRBUF1+SX11
    stz SPRBUF1+SY11
    stz SPRBUF1+SX12
    stz SPRBUF1+SY12
    stz SPRBUF1+SX13
    stz SPRBUF1+SY13
    stz SPRBUF1+SX14
    stz SPRBUF1+SY14
    stz SPRBUF1+SX15
    stz SPRBUF1+SY15
    stz SPRBUF1+SX16
    stz SPRBUF1+SY16
    stz SPRBUF1+SX17
    stz SPRBUF1+SY17
    stz SPRBUF1+SX18
    stz SPRBUF1+SY18
    stz SPRBUF1+SX19
    stz SPRBUF1+SY19
    stz SPRBUF1+SX20
    stz SPRBUF1+SY20
    stz SPRBUF1+SX21
    stz SPRBUF1+SY21
    stz SPRBUF1+SX22
    stz SPRBUF1+SY22
    stz SPRBUF1+SX23
    stz SPRBUF1+SY23
    stz SPRBUF1+SX24
    stz SPRBUF1+SY24
    stz SPRBUF1+SX25
    stz SPRBUF1+SY25
    stz SPRBUF1+SX26
    stz SPRBUF1+SY26
    stz SPRBUF1+SX27
    stz SPRBUF1+SY27
    stz SPRBUF1+SX28
    stz SPRBUF1+SY28
    stz SPRBUF1+SX29
    stz SPRBUF1+SY29
    stz SPRBUF1+SX30
    stz SPRBUF1+SY30
    stz SPRBUF1+SX31
    stz SPRBUF1+SY31
    stz SPRBUF1+SPRIORITY
    stz SPRBUF1+SPRIORITY1
    stz SPRBUF1+SPRIORITY2
    stz SPRBUF1+SPRIORITY3
    stz SPRBUF1+SPRIORITY4
    stz SPRBUF1+SPRIORITY5
    stz SPRBUF1+SPRIORITY6
    stz SPRBUF1+SPRIORITY7
    stz SPRBUF1+SPRIORITY8
    stz SPRBUF1+SPRIORITY9
    stz SPRBUF1+SPRIORITY10
    stz SPRBUF1+SPRIORITY11
    stz SPRBUF1+SPRIORITY12
    stz SPRBUF1+SPRIORITY13
    stz SPRBUF1+SPRIORITY14
    stz SPRBUF1+SPRIORITY15
    stz SPRBUF1+SPRIORITY16
    stz SPRBUF1+SPRIORITY17
    stz SPRBUF1+SPRIORITY18
    stz SPRBUF1+SPRIORITY19
    stz SPRBUF1+SPRIORITY20
    stz SPRBUF1+SPRIORITY21
    stz SPRBUF1+SPRIORITY22
    stz SPRBUF1+SPRIORITY23
    stz SPRBUF1+SPRIORITY24
    stz SPRBUF1+SPRIORITY25
    stz SPRBUF1+SPRIORITY26
    stz SPRBUF1+SPRIORITY27
    stz SPRBUF1+SPRIORITY28
    stz SPRBUF1+SPRIORITY29
    stz SPRBUF1+SPRIORITY30
    stz SPRBUF1+SPRIORITY31
    lda #$8c
    sta SPRBUF1+SFRAME
    sta SPRBUF1+SFRAME1
    sta SPRBUF1+SFRAME2
    sta SPRBUF1+SFRAME3
    sta SPRBUF1+SFRAME4
    sta SPRBUF1+SFRAME5
    sta SPRBUF1+SFRAME6
    sta SPRBUF1+SFRAME7
    sta SPRBUF1+SFRAME8
    sta SPRBUF1+SFRAME9
    sta SPRBUF1+SFRAME10
    sta SPRBUF1+SFRAME11
    sta SPRBUF1+SFRAME12
    sta SPRBUF1+SFRAME13
    sta SPRBUF1+SFRAME14
    sta SPRBUF1+SFRAME15
    sta SPRBUF1+SFRAME16
    sta SPRBUF1+SFRAME17
    sta SPRBUF1+SFRAME18
    sta SPRBUF1+SFRAME19
    sta SPRBUF1+SFRAME20
    sta SPRBUF1+SFRAME21
    sta SPRBUF1+SFRAME22
    sta SPRBUF1+SFRAME23
    sta SPRBUF1+SFRAME24
    sta SPRBUF1+SFRAME25
    sta SPRBUF1+SFRAME26
    sta SPRBUF1+SFRAME27
    sta SPRBUF1+SFRAME28
    sta SPRBUF1+SFRAME29
    sta SPRBUF1+SFRAME30
    sta SPRBUF1+SFRAME31
    rtl


;=================================================================


INITIALIZE_HUD_PAL             ; note: this thing overwrites the first 32
                               ; bytes of cgram.
    stz $2121

    lda #$00
    sta $2122
    lda #$00
    sta $2122
    lda #$1f
    sta $2122
    lda #$00
    sta $2122
    lda #$00
    sta $2122
    lda #$00
    sta $2122
    lda #$ff
    sta $2122
    lda #$7f
    sta $2122
    lda #$ad
    sta $2122
    lda #$35
    sta $2122
    lda #$ce
    sta $2122
    lda #$65
    sta $2122
    lda #$30
    sta $2122
    lda #$42
    sta $2122
    lda #$11
    sta $2122
    lda #$6e
    sta $2122
    lda #$ff
    sta $2122
    lda #$7f
    sta $2122
    lda #$ac
    sta $2122
    lda #$59
    sta $2122
    lda #$10
    sta $2122
    lda #$7e
    sta $2122
    lda #$d7
    sta $2122
    lda #$5e
    sta $2122
    lda #$31
    sta $2122
    lda #$46
    sta $2122
    lda #$7b
    sta $2122
    lda #$6f
    sta $2122
    lda #$3f
    sta $2122
    lda #$42
    sta $2122
    lda #$ff
    sta $2122
    lda #$7f
    sta $2122

    rtl


;=================================================================

; ball 'n chain pattern structure:
;---
; +-   X  +-   Y   +-   X  +-   Y   +-   X  +-   Y   +-   X  +-   Y
; 0i1,0v1,0i2,0v2  1i1,1v1,1i2,1v2  2i1,2v1,2i2,2v2  3i1,3v1,3i2,3v2
;
; where 'i' = instruction and 'v' = value.
; It starts with the data for the inner-most chain going towards
; the spikey ball at its end.
;
; Valid instructions are: $A0 equ DEC, $A1 equ INC and $FF equ NOP

PATTERN_BALL_n_CHAIN

;       GOING RIGHT (FROM THE MIDDLE)
;
;       [C H A I N  01] [C H A I N  02] [C H A I N  03] [  B A L L !  ]
;       [X]     [Y]     [X]     [Y]     [X]     [Y]     [X]     [Y]
    .db $a1,$01,$a0,$01,$a1,$03,$a0,$01,$a1,$05,$a0,$01,$a1,$09,$a0,$02 ; 0001
    .db $a1,$02,$ff,$00,$a1,$04,$a0,$01,$a1,$05,$a0,$01,$a1,$08,$a0,$01 ; 0002
    .db $a1,$02,$a0,$01,$a1,$03,$a0,$01,$a1,$05,$a0,$02,$a1,$07,$a0,$02 ; 0003
    .db $a1,$02,$ff,$00,$a1,$04,$a0,$01,$a1,$06,$a0,$01,$a1,$08,$a0,$02 ; 0004
    .db $a1,$02,$a0,$01,$a1,$03,$a0,$01,$a1,$04,$a0,$03,$a1,$06,$a0,$04 ; 0005
    .db $a1,$03,$a0,$01,$a1,$03,$a0,$02,$a1,$04,$a0,$03,$a1,$06,$a0,$05 ; 0006
    .db $a1,$02,$a0,$01,$a1,$02,$a0,$03,$a1,$04,$a0,$03,$a1,$06,$a0,$04 ; 0007
    .db $a1,$01,$a0,$01,$a1,$02,$a0,$02,$a1,$03,$a0,$03,$a1,$05,$a0,$05 ; 0008
    .db $a1,$01,$a0,$01,$a1,$02,$a0,$01,$a1,$03,$a0,$02,$a1,$03,$a0,$03 ; 0009
    .db $ff,$00,$a0,$01,$a1,$02,$a0,$02,$a1,$02,$a0,$03,$a1,$04,$a0,$05 ; 0010
    .db $a1,$01,$a0,$01,$a1,$01,$a0,$02,$a1,$01,$a0,$03,$a1,$02,$a0,$04 ; 0011
    .db $a1,$01,$a0,$01,$a1,$01,$a0,$02,$a1,$02,$a0,$02,$a1,$02,$a0,$03 ; 0012
    .db $ff,$00,$a0,$01,$ff,$00,$a0,$01,$a1,$01,$a0,$02,$a1,$02,$a0,$02 ; 0013
    .db $ff,$00,$ff,$00,$a1,$01,$ff,$00,$a1,$01,$ff,$00,$a1,$01,$a0,$01 ; 0014
    .db $ff,$00,$ff,$00,$ff,$00,$a0,$01,$ff,$00,$a0,$01,$ff,$00,$a0,$01 ; 0015
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$a0,$01,$ff,$00,$a0,$02 ; 0016
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00 ; 0017
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00 ; 0018
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00 ; 0019
    ; NOW GO FROM THE RIGHT TO THE LEFT
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$a1,$01,$ff,$00,$a1,$02 ; 0020
    .db $ff,$00,$ff,$00,$ff,$00,$a1,$01,$ff,$00,$a1,$01,$ff,$00,$a1,$01 ; 0021
    .db $ff,$00,$ff,$00,$a0,$01,$ff,$00,$a0,$01,$ff,$00,$a0,$01,$a1,$01 ; 0022
    .db $ff,$00,$a1,$01,$ff,$00,$a1,$01,$a0,$01,$a1,$02,$a0,$02,$a1,$02 ; 0023
    .db $a0,$01,$a1,$01,$a0,$01,$a1,$02,$a0,$02,$a1,$02,$a0,$02,$a1,$03 ; 0024
    .db $a0,$01,$a1,$01,$a0,$01,$a1,$02,$a0,$01,$a1,$03,$a0,$02,$a1,$04 ; 0025
    .db $ff,$00,$a1,$01,$a0,$02,$a1,$02,$a0,$02,$a1,$03,$a0,$04,$a1,$05 ; 0026
    .db $a0,$01,$a1,$01,$a0,$02,$a1,$01,$a0,$03,$a1,$02,$a0,$03,$a1,$03 ; 0027
    .db $a0,$01,$a1,$01,$a0,$02,$a1,$02,$a0,$03,$a1,$03,$a0,$05,$a1,$05 ; 0028
    .db $a0,$02,$a1,$01,$a0,$02,$a1,$03,$a0,$04,$a1,$03,$a0,$06,$a1,$04 ; 0029
    .db $a0,$03,$a1,$01,$a0,$03,$a1,$02,$a0,$04,$a1,$03,$a0,$06,$a1,$05 ; 0030
    .db $a0,$02,$a1,$01,$a0,$03,$a1,$01,$a0,$04,$a1,$03,$a0,$06,$a1,$04 ; 0031
    .db $a0,$02,$ff,$00,$a0,$04,$a1,$01,$a0,$06,$a1,$01,$a0,$08,$a1,$02 ; 0032
    .db $a0,$02,$a1,$01,$a0,$03,$a1,$01,$a0,$05,$a1,$02,$a0,$07,$a1,$02 ; 0033
    .db $a0,$02,$ff,$00,$a0,$04,$a1,$01,$a0,$05,$a1,$01,$a0,$08,$a1,$01 ; 0034
    .db $a0,$01,$a1,$01,$a0,$03,$a1,$01,$a0,$05,$a1,$01,$a0,$08,$a1,$02 ; 0035
    ; (HALFWAYS IN BETWEEN LEFT AND RIGHT: ZA MIDDLE, HOHO!)
    .db $a0,$01,$a0,$01,$a0,$03,$a0,$01,$a0,$05,$a0,$01,$a0,$09,$a0,$02 ; 0036
    .db $a0,$02,$ff,$00,$a0,$04,$a0,$01,$a0,$05,$a0,$01,$a0,$08,$a0,$01 ; 0037
    .db $a0,$02,$a0,$01,$a0,$03,$a0,$01,$a0,$05,$a0,$02,$a0,$07,$a0,$02 ; 0038
    .db $a0,$02,$ff,$00,$a0,$04,$a0,$01,$a0,$06,$a0,$01,$a0,$08,$a0,$02 ; 0039
    .db $a0,$02,$a0,$01,$a0,$03,$a0,$01,$a0,$04,$a0,$03,$a0,$06,$a0,$04 ; 0040
    .db $a0,$03,$a0,$01,$a0,$03,$a0,$02,$a0,$04,$a0,$03,$a0,$06,$a0,$05 ; 0041
    .db $a0,$02,$a0,$01,$a0,$02,$a0,$03,$a0,$04,$a0,$03,$a0,$06,$a0,$04 ; 0042
    .db $a0,$01,$a0,$01,$a0,$02,$a0,$02,$a0,$03,$a0,$03,$a0,$05,$a0,$05 ; 0043
    .db $a0,$01,$a0,$01,$a0,$02,$a0,$01,$a0,$03,$a0,$02,$a0,$03,$a0,$03 ; 0044
    .db $ff,$00,$a0,$01,$a0,$02,$a0,$02,$a0,$02,$a0,$03,$a0,$04,$a0,$05 ; 0045
    .db $a0,$01,$a0,$01,$a0,$01,$a0,$02,$a0,$01,$a0,$03,$a0,$02,$a0,$04 ; 0046
    .db $a0,$01,$a0,$01,$a0,$01,$a0,$02,$a0,$02,$a0,$02,$a0,$02,$a0,$03 ; 0047
    .db $ff,$00,$a0,$01,$ff,$00,$a0,$01,$a0,$01,$a0,$02,$a0,$02,$a0,$02 ; 0048
    .db $ff,$00,$ff,$00,$a0,$01,$ff,$00,$a0,$01,$ff,$00,$a0,$01,$a0,$01 ; 0049
    .db $ff,$00,$ff,$00,$ff,$00,$a0,$01,$ff,$00,$a0,$01,$ff,$00,$a0,$01 ; 0050
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$a0,$01,$ff,$00,$a0,$02 ; 0051
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00 ; 0052
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00 ; 0053
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00 ; 0054
    ; WE'RE NOW ALL LEFT,(ENGRISH PAWA~ UNITE!!) SO TO THE MIDDLE WE'LL GO!
    .db $ff,$00,$ff,$00,$ff,$00,$ff,$00,$ff,$00,$a1,$01,$ff,$00,$a1,$02 ; 0055
    .db $ff,$00,$ff,$00,$ff,$00,$a1,$01,$ff,$00,$a1,$01,$ff,$00,$a1,$01 ; 0056
    .db $ff,$00,$ff,$00,$a1,$01,$ff,$00,$a1,$01,$ff,$00,$a1,$01,$a1,$01 ; 0057
    .db $ff,$00,$a1,$01,$ff,$00,$a1,$01,$a1,$01,$a1,$02,$a1,$02,$a1,$02 ; 0058
    .db $a1,$01,$a1,$01,$a1,$01,$a1,$02,$a1,$02,$a1,$02,$a1,$02,$a1,$03 ; 0059
    .db $a1,$01,$a1,$01,$a1,$01,$a1,$02,$a1,$01,$a1,$03,$a1,$02,$a1,$04 ; 0060
    .db $ff,$00,$a1,$01,$a1,$02,$a1,$02,$a1,$02,$a1,$03,$a1,$04,$a1,$05 ; 0061
    .db $a1,$01,$a1,$01,$a1,$02,$a1,$01,$a1,$03,$a1,$02,$a1,$03,$a1,$03 ; 0062
    .db $a1,$01,$a1,$01,$a1,$02,$a1,$02,$a1,$03,$a1,$03,$a1,$05,$a1,$05 ; 0063
    .db $a1,$02,$a1,$01,$a1,$02,$a1,$03,$a1,$04,$a1,$03,$a1,$06,$a1,$04 ; 0064
    .db $a1,$03,$a1,$01,$a1,$03,$a1,$02,$a1,$04,$a1,$03,$a1,$06,$a1,$05 ; 0065
    .db $a1,$02,$a1,$01,$a1,$03,$a1,$01,$a1,$04,$a1,$03,$a1,$06,$a1,$04 ; 0066
    .db $a1,$02,$ff,$00,$a1,$04,$a1,$01,$a1,$06,$a1,$01,$a1,$08,$a1,$02 ; 0067
    .db $a1,$02,$a1,$01,$a1,$03,$a1,$01,$a1,$05,$a1,$02,$a1,$07,$a1,$02 ; 0068
    .db $a1,$02,$ff,$00,$a1,$04,$a1,$01,$a1,$05,$a1,$01,$a1,$08,$a1,$01 ; 0069
    .db $a1,$01,$a1,$01,$a1,$03,$a1,$01,$a1,$05,$a1,$01,$a1,$08,$a1,$02 ; 0070

.ENDS ; bank #18 ($12)
