;cartoon.asm

     proc

cartoon4
  lda #0
  sta scrollflag
  sta pirx
  sta fishx
  sta crabx
  lda #127
  sta fishy
  lda #124
  sta piry
  lda #255
  sta pird
  lda #1
  sta scrollpos+1
  lda #0
  sta scrollpos
  inc scrollflag
  lda #64+10
  ldy #0
  jsr savedata
  lda #64+10
  ldy #0
  jsr drawbigclam
  ldx #0
  stx fishd
:lp1
  stx fishx
  txa
  sec
  sbc #24
  bcc :nopir1
  sta pirx
:nopir1
  lda 20
  cmp 20
  beq *-2
  and #8
  lsr a
  lsr a
  lsr a
  sta autotail
  inx
  bne :lp1
  lda 20
  cmp 20
  beq *-2
  lda 20
  cmp 20
  beq *-2
  ldx #1
  stx fishd
  stx pird
  lda #203-4
  sta fishy
  lda #199-4
  sta piry
  ldx #254
:lp9
  stx fishx
  txa
  clc
  adc #24
  bcs :nof1
  cmp #75
  beq :nof2
  bcc :nof1
  sta pirx
  jmp :nof1
:nof2
  lda #64+10
  ldy #0
  stx :t1
  jsr drawbig2clam
  ldx :t1
  lda 20
  cmp 20
  beq *-2
  lda #0
  sta pirx
  lda #64+10
  ldy #0
  stx :t1
  jsr drawbig3clam
  lda #low closesound
  sta snd0adr
  lda #high closesound
  sta snd0adr+1
  ldx :t1
:nof1
  lda 20
  cmp 20
  beq *-2
  lda 20
  and #8
  lsr a
  lsr a
  lsr a
  sta autotail
:mm1
  dex
  bne :lp9

  lda #0
  sta autotail
  sta 20
:lp2
  lda 20
  cmp #180
  bne :lp2
  rts

bigclamdata
  db 27+128,28+128,28+128,28+128,29+128
  db 53+128,66+128,66+128,66+128,54+128
  db 30+128,31+128,31+128,31+128,32+128
  db 66,66,66,66,66
bigclam2data
  db 0,0,0,0,0
  db 27+128,28+128,28+128,28+128,29+128
  db 30+128,31+128,31+128,31+128,32+128
  db 66,66,66,66,66
bigclam3data
  db 0,0,0,0,0
  db 21+128,22+128,22+128,22+128,23+128
  db 24+128,25+128,25+128,25+128,26+128
  db 66,66,66,66,66

;draw big clam at loc xpos a/x
drawbigclam
  ldx #low bigclamdata
  stx :lpdclam+1
  ldx #high bigclamdata
  stx :lpdclam+2
  bne :drawbc
drawbig2clam
  ldx #low bigclam2data
  stx :lpdclam+1
  ldx #high bigclam2data
  stx :lpdclam+2
  bne :drawbc
drawbig3clam
  ldx #low bigclam3data
  stx :lpdclam+1
  ldx #high bigclam3data
  stx :lpdclam+2
:drawbc
  clc
  adc adrtabl-3+21
  sta ztmp1
  tya
  adc adrtabh-3+21
  sta ztmp1+1
  ldx #4
:lp2dclam
  ldy #4
:lpdclam
  lda bigclamdata,y
  sta (ztmp1),y
  dey
  bpl :lpdclam
  clc
  lda ztmp1+1
  adc #4
  sta ztmp1+1
  clc
  lda :lpdclam+1
  adc #5
  sta :lpdclam+1
  bcc *+5
  inc :lpdclam+2
  dex
  bne :lp2dclam
  rts

:t1 db 0

savedata
  clc
  adc adrtabl-3+21
  sta ztmp1
  tya
  adc adrtabh-3+21
  sta ztmp1+1
  ldy #4
:lpsd
  lda (ztmp1),y
  sta bigclam2data,y
  sta bigclam3data,y
  dey
  bpl :lpsd
  clc
  lda ztmp1+1
  adc #4
  sta ztmp1+1
  ldy #4
:lp2sd
  lda (ztmp1),y
  sta bigclam3data+5,y
  dey
  bpl :lp2sd
  rts

  eproc

