; Silent Night
; A little Christmas Demo
; (C) 2002 ICE TEAM

; This demo born as a test of a full screen engine I'm coded for the
; first Italian Demo of the new millennium (a cooperation between Ice Team and Fire).
; As you see the engine is not completed, but it just arranged for working with
; this demo.

; The image is just picked on Internet (the right remains to the original author
; - that I did non know -, I only adapt it to C64 format).
; The music is the simple Silent Night
;
; Enjoy all the other Ice Team releases at htpp://digilander.iol.it/ice00)

; Image format:
; SP2 SP0 SP1 SP4 SP5 SP6 SP7 SP3 (used only last 14 pixels)
; SP2 SP0 SP1 SP4 SP5 SP6 SP7 SP3 (used all 21 pixels)
; SP2     normal MCM image    SP3
; ..      with background c.
; SP2     for 8 lines         SP3
; SP2 SP0 SP1 SP4 SP5 SP6 SP7 SP3
; SP2 SP0 SP1 SP4 SP5 SP6 SP7 SP3
; SP2 SP0 SP1 SP4 SP5 SP6 SP7 SP3 (used only 7 pixels)

; all SPs are x expanded


    processor 6502

CYCLES = 63     ; 6569 (all revisions), PAL-B
COL = 5         ; color for the string

phase = $8b     ; phase effect

cinv = $314
cnmi = $318
raster = 12     ; start of raster interrupt
limit = $fb     ; zero page variable

LIMIT = 50     ; limit the cycle velocity

BIND = $01      ; start index for background color table

SPIND0 = $CFFF ;2040   ; sprite 0 index
SPIND1 = $CFFF; 2041
SPIND2 = $CFFF;2042
SPIND3 = $CFFF;2043
SPIND4 = $CFFF;2044
SPIND5 = $CFFF;2045
SPIND6 = $CFFF; 2046
SPIND7 = $CFFF; 2047

POINT1 = $18    ; pointer to memory for first block
POINT2 = $18    ; pointer to memory for second block

BSP0 = 1        ; mob 0 index when in start of border
BSP1 = 1        ; mob 1 index when in start of border
BSP4 = 1        ; mob 4 index when in start of border
BSP5 = 1        ; mob 5 index when in start of border
BSP6 = 1        ; mob 6 index when in start of border
BSP7 = 1        ; mob 7 index when in start of border


  .org $840

mob_IC:
  .byte 170, 0, 0, 170, 16, 0, 40, 16, 0
  .byte 40, 80, 0, 40, 80, 243, 40, 67, 255
  .byte 40, 79, 255, 40, 79, 15, 40, 79, 16
  .byte 40, 79, 17, 40, 79, 16, 40, 79, 16
  .byte 40, 79, 0, 40, 79, 207, 40, 79, 255
  .byte 40, 67, 255, 170, 0, 255, 170, 17, 0
  .byte 0, 16, 85, 21, 80, 21, 5, 80, 0, 0

mob_E:
  .byte 0, 0, 0, 0, 0, 0, 0, 0, 0
  .byte 0, 0, 0, 0, 40, 0, 64, 170, 16
  .byte 18, 170, 132, 18, 128, 132, 18, 132, 132
  .byte 66, 128, 132, 2, 170, 132, 2, 170, 132
  .byte 2, 128, 20, 2, 132, 128, 18, 128, 132
  .byte 16, 170, 132, 16, 42, 4, 64, 64, 16
  .byte 64, 21, 80, 0, 5, 64, 0, 0, 0, 0

mob_TEAM:
  .byte 228, 200, 0, 74, 47, 128, 78, 106, 128
  .byte 72, 170, 128, 76, 234, 128, 0, 0, 0
  .byte 0, 0, 0, 0, 0, 0, 0, 0, 0
  .byte 0, 0, 0, 0, 0, 0, 0, 0, 0
  .byte 0, 0, 0, 0, 0, 0, 0, 0, 0
  .byte 0, 0, 0, 0, 0, 0, 0, 0, 0
  .byte 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

SCREEN     = $E544    ; clean the screen
STRING     = $AB1E    ; put a string
SET_COOR   = $E50C    ; set x/y coord
KSCAN      = $FF9F    ; keyboard scan
GETIN      = $FFE4    ; get char
POSX      = 35      ; x pos of sprites
POSY      = 60      ; y pos of sprites
POSXX     = 32

      mac write
      ldx  {1}
      ldy  {1}+1
      jsr  SET_COOR
      lda  #<({1}+2)
      ldy  #>({1}+2)
      jsr  STRING
      endm


 .org $903
start:

                                  ; init logo sprites
      ldx  #13                    ; light green
      stx  $D026                  ; mob multicolor 1
      inx
      stx  $D027                  ; mob 0 color
      stx  $D02A                  ; mob 3 color
      inx
      stx  $D025                  ; mob multi color 0
      stx  $D029                  ; mob 2 color
      stx  $D02C                  ; mob 5 color

      ldx  #$1B                   ; set 0,1 and 3,4 as multicolor
      stx  $D01C
      ldx  #02
      stx  $D028                  ; red color for mob 1
      stx  $D02B
                                  ; insert sprite pointer to $840
      ldx  #33
      stx  2040
      stx  2043
      inx
      stx  2041
      stx  2044
      inx
      stx  2042
      stx  2045

                                   ; set x position of sprites
      ldx  #POSX
      stx  $D000
      ldx  #POSX+24
      stx  $D002
      ldx  #POSX+21
      stx  $D004

      ldx  #$38                    ; MSB of position
      stx  $D010

      ldx  #POSXX
      stx  $D006
      ldx  #POSXX+24
      stx  $D008
      ldx  #POSXX+21
      stx  $D00A

      ldy  #POSY
      sty  $D001
      sty  $D003
      sty  $D007
      sty  $D009
      dey
      dey
      sty  $D005
      sty  $D00b
                                  ; init screen color
      jsr  SCREEN
      lda  #3
      sta  53280
      lda  #1
      sta  53281
                                       ; show sprites
      lda  #$3F
      sta  $D015

      write str1
      write str2
      write str3
      write str4
      write str5
      write str6
      write str7
      write str8
      write str9
      write str10
      write str11

loop:
      jsr  KSCAN
      jsr  GETIN
      cmp  #0
      beq  loop


  jmp install
  jmp deinstall

install:        ; install the raster routine
  jsr restore   ; Disable the Restore key (disable NMI interrupts)
checkirq:
  lda cinv      ; check the original IRQ vector
  ldx cinv+1    ; (to avoid multiple installation)
  cmp #<irq1
  bne irqinit
  cpx #>irq1
  beq skipinit
irqinit:
  sei
  sta oldirq    ; store the old IRQ vector
  stx oldirq+1
  lda #<irq1
  ldx #>irq1
  sta cinv      ; set the new interrupt vector
  stx cinv+1
skipinit:
  lda #$1b
  sta $d011     ; set the raster interrupt location
  lda #raster
  sta $d012

       ldx  #8              ; 2  [12] set position for the first row of sprites
       stx  $D001           ; 4  [16]
       stx  $D003           ; 4  [20]
       stx  $D005           ; 4  [24]
       stx  $D007           ; 4  [28]
       stx  $D009           ; 4  [32]
       stx  $D00B           ; 4  [36]
       stx  $D00D           ; 4  [40]
       stx  $D00F           ; 4  [44]


  jsr initSpriteImage
  jsr initGraphics
  lda #00
  jsr $4800     ; init music

  lda #$7f
  sta $dc0d     ; disable timer interrupts
  sta $dd0d
  ldx #1
  stx $d01a     ; enable raster interrupt
  lda $dc0d     ; acknowledge CIA interrupts
  lsr $d019     ; and video interrupts
  ldy #$ff
  ;sty $d015     ; turn on all sprites
  cli
aaa: jmp aaa
  rts

deinstall:
  sei           ; disable interrupts
  lda #$1b
  sta $d011     ; restore text screen mode
  lda #$81
  sta $dc0d     ; enable Timer A interrupts on CIA 1
  lda #0
  sta $d01a     ; disable video interrupts
  lda oldirq
  sta cinv      ; restore old IRQ vector
  lda oldirq+1
  sta cinv+1
  bit $dd0d     ; re-enable NMI interrupts
  cli
  rts

;==================================
; Init the paramethers for making
; the big image
;==================================
initSpriteImage:
       lda  #$F0      ; set x position from left to right
       sta  $D004     ; mob 2 x
       lda  #$28
       sta  $D000     ; mob 0 x
       lda  #$58
       sta  $D002     ; mob 1 x
       lda  #$88
       sta  $D008     ; mob 4 x
       lda  #$B8
       sta  $D00A     ; mob 5 x
       lda  #$E8
       sta  $D00C     ; mob 6 x
       lda  #$18
       sta  $D00E     ; mob 7 x
       lda  #$48
       sta  $D006     ; mob 3 x
       lda  #$8C      ; msb for sprite 2, 3 and 7
       sta  $D010
       lda  #$FF
       sta  $D01D     ; expand all sprites in x
       
       lda  #$0C
       sta  $D01c     ; and 2/3 multicolor

       lda  #254      ; left column for mob 2
       sta  2042

       lda  #255      ; right column for mob 3
       sta  2043

       lda  #253      ; 'buon natale' for all the others
       sta  2040
       sta  2041
       sta  2044
       sta  2045
       sta  2046
       sta  2047

       lda  #14
       sta  $d025     ; multicolor 0
       lda  #3
       sta  $d026     ; multicolor 1
       lda  #6
       sta  $d029     ; color mob 2
       sta  $d02a     ; color mob 3



       rts

;============================
; init Bitmap graphics
;============================
initGraphics:               ; set pointer for graphics data
      lda  $d018
      ora  #$08
      and  #$f8
      sta  $d018
                            ; enable multicolor bitmap mode
      lda  $d011
      ora  #$20
      sta  $d011
      lda  $d016
      ora  #$10
      sta  $d016

                            ; copy color to screen coord
      ldx #39
iscr1:
N     SET  0
      REPEAT 25
      lda  s2+N*40,x
      sta  $400+N*40,x
      lda  s1+N*40,x
      sta  $d800+N*40,x
N     SET  N+1
      REPEND
      lda  s4
      sta  53281
      dex
      bmi iscrdone1
      jmp iscr1
iscrdone1:
      rts


; all sprite are enabled when the interrupt is called so cycles are available
; from 11 to 56
irq1:                       ; LINE 12
     ; irq  (event)         ; 9 [11-20] 14 [11-25] >7 + at least 2 c. of last ins.
     ; pha                  ; 3 [21-23] [26-28]
     ; txa                  ; 2 [24-25] [29-30]
     ; pha                  ; 3 [26-28] [31-33]
     ; tya                  ; 2 [29-30] [34-35]
     ; pha                  ; 3 [31-33] [36-38]
     ; tsx                  ; 2 [34-35] [39-40]
     ; lda  $0104,x         ; 4 [36-39] [41-44]
     ; and  #xx             ; 2 [40-41] [45-46]
     ; beq                  ; 3 [42-44] [47-49]
     ; jmp  ($314)          ; 5 [45-49] [50-54]
                            ; go for LINE 13
       inc  $cFFF           ; 6 [50-56]
       dec  $CFFF           ; 6 [11-16]
       inc  $cFFF           ; 6 [17-22]
       dec  $CFFF           ; 6 [23-28]
       inc  $cFFF           ; 6 [29-34]
       dec  $CFFF           ; 6 [35-40]
       inc  $cFFF           ; 6 [41-46]
       dec  $CFFF           ; 6 [47-52]
                            ; go for LINE 14
       inc  $cFFF           ; 6 [53-14]
       dec  $CFFF           ; 6 [15-20]
       inc  $cFFF           ; 6 [21-26]
       dec  $CFFF           ; 6 [27-32]
       inc  $cFFF           ; 6 [33-38]
       dec  $CFFF           ; 6 [39-44]
       inc  $cFFF           ; 6 [45-50]
       dec  $CFFF           ; 6 [51-56]

       ; here we are synchronized (why? ok: it works)

                            ; LINE 15
; set the next rows of sprite y position: the pointer will be changed only before
; the last line of the current being displayed mobs.
       ldx  #29             ; 2 [11-12] set position for the second row of sprites
       stx  $D001           ; 4 [13-16]
       stx  $D003           ; 4 [17-20]
       stx  $D005           ; 4 [21-24]
       stx  $D007           ; 4 [25-28]
       stx  $D009           ; 4 [29-32]
       stx  $D00B           ; 4 [33-36]
       stx  $D00D           ; 4 [37-40]
       stx  $D00F           ; 4 [41-44]
       ldx  #$ff            ; 2 [43-46] they are already enabled
       stx  $D015           ; 4 [47-50] enable all 8 sprites
       dec  $d016           ; 6 [51-56] turn off side border
                            ; all sprites are fetching: next cycle is 11
                            ; LINE 16
       lda  #$18            ; 2 [11-12]
       sta  $D016           ; 4 [13-16]
       bit  $ea             ; 3 [17-19]
       bit  $ae             ; 3 [20-22]
       jsr  c29_22          ; 6 [23-22] into LINE 17
       jsr  c29_22          ; 6 [23-22] into LINE 18
       jsr  c29_22          ; 6 [23-22] into LINE 19
       jsr  c29_22          ; 6 [23-22] into LINE 20
       jsr  c29_22          ; 6 [23-22] into LINE 21
       jsr  c29_22          ; 6 [23-22] into LINE 22
       jsr  c29_22          ; 6 [23-22] into LINE 23
       jsr  c29_22          ; 6 [23-22] into LINE 24
       jsr  c29_22          ; 6 [23-22] into LINE 25
       jsr  c29_22          ; 6 [23-22] into LINE 26
       jsr  c29_22          ; 6 [23-22] into LINE 27
       jsr  c29_22          ; 6 [23-22] into LINE 28
       jsr  c29_22          ; 6 [23-22] into LINE 29

; now it is time to change the memory pointer for changing the sprites
       lda  #$18            ; 2 [23-24]
       sta  $D016           ; 4 [25-28] restore screen size
       bit  $4444           ; 4 [29-32]
       ldx  #POINT1         ; 2 [33-34]
       stx  $D018           ; 4 [35-38] change mem pointer
       bit  70              ; 3 [39-41]
       bit  73              ; 3 [42-44]
       bit  82              ; 3 [45-47]
       bit  66              ; 3 [48-50]
       dec  $D016           ; 6 [51-56] turn off side border
                            ; LINE 30
       lda  #$18            ; 2 [11-12]
       sta  $D016           ; 4 [13-16] restore screen size
       bit  $ea             ; 3 [17-19]
       bit  $ae             ; 3 [20-22]

       jsr  c29_22          ; 6 [23-22] into LINE 31
       jsr  c29_22          ; 6 [23-22] into LINE 32
       jsr  c29_22          ; 6 [23-22] into LINE 33
       jsr  c29_22          ; 6 [23-22] into LINE 34
       jsr  c29_22          ; 6 [23-22] into LINE 35
       jsr  c29_22          ; 6 [23-22] into LINE 36
       jsr  c29_22          ; 6 [23-22] into LINE 37
       jsr  c29_22          ; 6 [23-22] into LINE 38
       jsr  c29_22          ; 6 [23-22] into LINE 39
       jsr  c29_22          ; 6 [23-22] into LINE 40
       jsr  c29_22          ; 6 [23-22] into LINE 41
       jsr  c29_22          ; 6 [23-22] into LINE 42
       jsr  c29_22          ; 6 [23-22] into LINE 43
       jsr  c29_22          ; 6 [23-22] into LINE 44
       jsr  c29_22          ; 6 [23-22] into LINE 45
       jsr  c29_22          ; 6 [23-22] into LINE 46
       jsr  c29_22          ; 6 [23-22] into LINE 47
       jsr  c29_22          ; 6 [23-22] into LINE 48
       jsr  c29_22          ; 6 [23-22] into LINE 49
       
; set the new sprites y location for mob 2 and 3 before the first visible line
       lda  #50             ; 2 [23-24]
       sta  $D005           ; 4 [25-28] set sprite 2 y coord
       nop                  ; 2 [29-30]
       sta  $D007           ; 4 [31-34] set sprite 3 y coord
       bit  $ea             ; 3 [35-37] set new sprite pointers
       bit  $ea             ; 3 [38-40]
       bit  $ea             ; 3 [41-43]
       bit  $ea             ; 3 [44-46]
       nop                  ; 2 [47-48]
       nop                  ; 2 [49-50]
       dec  $D016           ; 6 [51-56] turn off side border

                            ; LINE 50
       lda  #$18            ; 2 [11-12]
       sta  $D016           ; 4 [13-16]
       bit  $ea             ; 3 [17-19]
       bit  $ae             ; 3 [20-22]

       lda  #$0C            ; 2 [23-24]
       sta  $D015           ; 4 [25-28] enable only sprite 2 and 3
       lda  #BC_BLK0        ; 2 [29-30] background color of block 0
       nop                  ; 2 [31-32]
       nop                  ; 2 [33-34]
       inc  SPIND2          ; 6 [35-40] set new sprite pointers
       inc  SPIND3          ; 6 [41-46]
       ldy  #$10            ; 2 [47-48]
       ldx  #$18            ; 2 [49-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 51: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 52
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 53
       jsr  c17_10          ; 6 [11-10] into LINE 54
       jsr  c17_10          ; 6 [11-10] into LINE 55
       jsr  c17_10          ; 6 [11-10] into LINE 56
       jsr  c17_10          ; 6 [11-10] into LINE 57
       jsr  c17_10          ; 6 [11-10] into LINE 58
       lda  #BC_BLK1        ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 59: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 60
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 61
       jsr  c17_10          ; 6 [11-10] into LINE 62
       jsr  c17_10          ; 6 [11-10] into LINE 63
       jsr  c17_10          ; 6 [11-10] into LINE 64
       jsr  c17_10          ; 6 [11-10] into LINE 65
       jsr  c17_10          ; 6 [11-10] into LINE 66
       lda  #BC_BLK2        ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 67: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 68
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 69
       jsr  c17_10          ; 6 [11-10] into LINE 70
                            ; change the sprite position/pointer before the end of line
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       lda  #71             ; 2 [17-18]
       sta  $D005           ; 4 [19-22] set sprite 2 y coord
       sta  $D007           ; 4 [23-26] set sprite 3 y coord
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       bit  $6666           ; 4 [35-38]
       inc  SPIND2          ; 6 [39-44] set new sprite pointers
       inc  SPIND3          ; 6 [45-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 71: where new sprite may be activated
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 72
       jsr  c17_10          ; 6 [11-10] into LINE 73
       jsr  c17_10          ; 6 [11-10] into LINE 73
       lda  #BC_BLK3        ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 75: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 76
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 77
       jsr  c17_10          ; 6 [11-10] into LINE 78
       jsr  c17_10          ; 6 [11-10] into LINE 79
       jsr  c17_10          ; 6 [11-10] into LINE 80
       jsr  c17_10          ; 6 [11-10] into LINE 81
       jsr  c17_10          ; 6 [11-10] into LINE 82
       lda  #BC_BLK4        ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 83: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 84
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 85
       jsr  c17_10          ; 6 [11-10] into LINE 86
       jsr  c17_10          ; 6 [11-10] into LINE 87
       jsr  c17_10          ; 6 [11-10] into LINE 88
       jsr  c17_10          ; 6 [11-10] into LINE 89
       jsr  c17_10          ; 6 [11-10] into LINE 90

       lda  #92             ; 2 [11-12]
       sta  $D005           ; 4 [13-16] set sprite 2 y coord
       sta  $D007           ; 4 [17-20] set sprite 3 y coord
       bit  $11             ; 3 [21-23]
       bit  $3333           ; 4 [24-27]
       bit  $4444           ; 4 [28-31]
       bit  $5555           ; 4 [32-35]
       bit  $6666           ; 4 [36-39]
       bit  $7777           ; 4 [40-43]
       bit  $8888           ; 4 [44-47]
       bit  $ea             ; 3 [48-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 91: bad line
;::::::
       bit  $ea             ; 3 [5-7] set the background color
       lda  #POINT2         ; 2 [8-9] read next memory pointer
       sty  $d016           ; 4 [10-56] turn off side border
       sta  $D018           ; 4 [57-4] change mem pointer
                            ; sprite 2 and 3 are fetching
                            ; LINE 92: where new sprite may be activated
       lda  #BC_BLK5        ; 2 [5-6]
       sta  $d021           ; 4 [7-10]
                            ; change the sprite position/pointer before the end of line
       stx  $D016           ; 4 [11-14] restore side border
       ldy  #$10            ; 2 [15-16] restore the common value
       nop                  ; 2 [17-18]
       sta  $2222           ; 4 [19-22]
       sta  $3333           ; 4 [23-26]
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       bit  $6666           ; 4 [35-38]
       bit  $7777           ; 4 [39-42]
       nop                  ; 2 [43-44]
       bit  $7777           ; 4 [45-48]
       nop                  ; 2 [49-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 93
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 94
       jsr  c17_10          ; 6 [11-10] into LINE 95
       jsr  c17_10          ; 6 [11-10] into LINE 96
       jsr  c17_10          ; 6 [11-10] into LINE 97
       jsr  c17_10          ; 6 [11-10] into LINE 98
       lda  #BC_BLK6        ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 99: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 100
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 101
       jsr  c17_10          ; 6 [11-10] into LINE 192
       jsr  c17_10          ; 6 [11-10] into LINE 103
       jsr  c17_10          ; 6 [11-10] into LINE 104
       jsr  c17_10          ; 6 [11-10] into LINE 105
       jsr  c17_10          ; 6 [11-10] into LINE 106
       lda  #BC_BLK7        ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 107: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 108
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 109
       jsr  c17_10          ; 6 [11-10] into LINE 110
       jsr  c17_10          ; 6 [11-10] into LINE 111
       jsr  c17_10          ; 6 [11-10] into LINE 112
                            ; change the sprite position/pointer before the end of line
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       lda  #113            ; 2 [17-18]
       sta  $D005           ; 4 [19-22] set sprite 2 y coord
       sta  $D007           ; 4 [23-26] set sprite 3 y coord
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       bit  $6666           ; 4 [35-38]
       inc  SPIND2          ; 6 [39-44] set new sprite pointers
       inc  SPIND3          ; 6 [45-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 113: where new sprite may be activated
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 114
       lda  #BC_BLK8        ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 115: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 116
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 117
       jsr  c17_10          ; 6 [11-10] into LINE 118
       jsr  c17_10          ; 6 [11-10] into LINE 119
       jsr  c17_10          ; 6 [11-10] into LINE 120
       jsr  c17_10          ; 6 [11-10] into LINE 121
       jsr  c17_10          ; 6 [11-10] into LINE 122
       lda  #BC_BLK9        ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 123: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 124
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 125
       jsr  c17_10          ; 6 [11-10] into LINE 126
       jsr  c17_10          ; 6 [11-10] into LINE 127
       jsr  c17_10          ; 6 [11-10] into LINE 128
       jsr  c17_10          ; 6 [11-10] into LINE 129
       jsr  c17_10          ; 6 [11-10] into LINE 130
       lda  #BC_BLK10       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 131: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 132
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 133
                            ; change the sprite position/pointer before the end of line
       bit  $1234           ; 4 [11-14]
       nop                  ; 2 [15-16]
       lda  #134            ; 2 [17-18]
       sta  $D005           ; 4 [19-22] set sprite 2 y coord
       sta  $D007           ; 4 [23-26] set sprite 3 y coord
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       bit  $6666           ; 4 [35-38]
       inc  SPIND2          ; 6 [39-44] set new sprite pointers
       inc  SPIND3          ; 6 [45-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 134: where new sprite may be activated
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 135
       jsr  c17_10          ; 6 [11-10] into LINE 136
       jsr  c17_10          ; 6 [11-10] into LINE 137
       jsr  c17_10          ; 6 [11-10] into LINE 138
       lda  #BC_BLK11       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 139: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 140
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 141
       jsr  c17_10          ; 6 [11-10] into LINE 142
       jsr  c17_10          ; 6 [11-10] into LINE 143
       jsr  c17_10          ; 6 [11-10] into LINE 144
       jsr  c17_10          ; 6 [11-10] into LINE 145
       jsr  c17_10          ; 6 [11-10] into LINE 146
       lda  #BC_BLK12       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 147: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 148
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 149
       jsr  c17_10          ; 6 [11-10] into LINE 150
       jsr  c17_10          ; 6 [11-10] into LINE 151
       jsr  c17_10          ; 6 [11-10] into LINE 152
       jsr  c17_10          ; 6 [11-10] into LINE 153
       jsr  c17_10          ; 6 [11-10] into LINE 154
                            ; change the sprite position/pointer before the end of line
       nop                  ; 2 [11-12]
       bit  $1111           ; 4 [13-16]
       lda  #155            ; 2 [17-18]
       sta  $D005           ; 4 [19-22] set sprite 2 y coord
       sta  $D007           ; 4 [23-26] set sprite 3 y coord
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       nop                  ; 4 [35-36]
       lda  #BC_BLK13       ; 2 [37-38]
       inc  SPIND2          ; 6 [39-44] set new sprite pointers
       inc  SPIND3          ; 6 [45-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 155: bad line and where new sprite may be activated
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 156
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 157
       jsr  c17_10          ; 6 [11-10] into LINE 158
       jsr  c17_10          ; 6 [11-10] into LINE 159
       jsr  c17_10          ; 6 [11-10] into LINE 160
       jsr  c17_10          ; 6 [11-10] into LINE 161
       jsr  c17_10          ; 6 [11-10] into LINE 162
       lda  #BC_BLK14       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 163: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 164
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 165
       jsr  c17_10          ; 6 [11-10] into LINE 166
       jsr  c17_10          ; 6 [11-10] into LINE 167
       jsr  c17_10          ; 6 [11-10] into LINE 168
       jsr  c17_10          ; 6 [11-10] into LINE 169
       jsr  c17_10          ; 6 [11-10] into LINE 170
       lda  #BC_BLK15       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 171: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 172
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 173
       jsr  c17_10          ; 6 [11-10] into LINE 174
       jsr  c17_10          ; 6 [11-10] into LINE 175
                            ; change the sprite position/pointer before the end of line
       bit  $1234           ; 4 [11-14]
       nop                  ; 2 [15-16]
       lda  #176            ; 2 [17-18]
       sta  $D005           ; 4 [19-22] set sprite 2 y coord
       sta  $D007           ; 4 [23-26] set sprite 3 y coord
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       bit  $6666           ; 4 [35-38]
       inc  SPIND2          ; 6 [39-44] set new sprite pointers
       inc  SPIND3          ; 6 [45-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 176: where new sprite may be activated
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 177
       jsr  c17_10          ; 6 [11-10] into LINE 178
       lda  #BC_BLK16       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 179: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 180
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 181
       jsr  c17_10          ; 6 [11-10] into LINE 182
       jsr  c17_10          ; 6 [11-10] into LINE 183
       jsr  c17_10          ; 6 [11-10] into LINE 184
       jsr  c17_10          ; 6 [11-10] into LINE 185
       jsr  c17_10          ; 6 [11-10] into LINE 186
       lda  #BC_BLK17       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 187: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 188
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 189
       jsr  c17_10          ; 6 [11-10] into LINE 190
       jsr  c17_10          ; 6 [11-10] into LINE 191
       jsr  c17_10          ; 6 [11-10] into LINE 192
       jsr  c17_10          ; 6 [11-10] into LINE 193
       jsr  c17_10          ; 6 [11-10] into LINE 194
       lda  #BC_BLK18       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 195: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 196
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
                            ; change the sprite position/pointer before the end of line
       bit  $1234           ; 4 [11-14]
       nop                  ; 2 [15-16]
       lda  #197            ; 2 [17-18]
       sta  $D005           ; 4 [19-22] set sprite 2 y coord
       sta  $D007           ; 4 [23-26] set sprite 3 y coord
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       bit  $6666           ; 4 [35-38]
       inc  SPIND2          ; 6 [39-44] set new sprite pointers
       inc  SPIND3          ; 6 [45-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 197: where new sprite may be activated
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 198
       jsr  c17_10          ; 6 [11-10] into LINE 199
       jsr  c17_10          ; 6 [11-10] into LINE 200
       jsr  c17_10          ; 6 [11-10] into LINE 201
       jsr  c17_10          ; 6 [11-10] into LINE 202
       lda  #BC_BLK19       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 203: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 204
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 205
       jsr  c17_10          ; 6 [11-10] into LINE 206
       jsr  c17_10          ; 6 [11-10] into LINE 207
       jsr  c17_10          ; 6 [11-10] into LINE 208
       jsr  c17_10          ; 6 [11-10] into LINE 209
       jsr  c17_10          ; 6 [11-10] into LINE 210
       lda  #BC_BLK20       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 211: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 212
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 213
       jsr  c17_10          ; 6 [11-10] into LINE 214
       jsr  c17_10          ; 6 [11-10] into LINE 215
       jsr  c17_10          ; 6 [11-10] into LINE 216
       jsr  c17_10          ; 6 [11-10] into LINE 217
                            ; change the sprite position/pointer before the end of line
       bit  $1234           ; 4 [11-14]
       nop                  ; 2 [15-16]
       lda  #218            ; 2 [17-18]
       sta  $D005           ; 4 [19-22] set sprite 2 y coord
       sta  $D007           ; 4 [23-26] set sprite 3 y coord
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       bit  $6666           ; 4 [35-38]
       inc  SPIND2          ; 6 [39-44] set new sprite pointers
       inc  SPIND3          ; 6 [45-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 218: where new sprite may be activated
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       lda  #BC_BLK21       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 219: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 220
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 221
       jsr  c17_10          ; 6 [11-10] into LINE 222
       jsr  c17_10          ; 6 [11-10] into LINE 223
       jsr  c17_10          ; 6 [11-10] into LINE 224
       jsr  c17_10          ; 6 [11-10] into LINE 225
       jsr  c17_10          ; 6 [11-10] into LINE 226
       lda  #BC_BLK22       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 227: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 228
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 229
       jsr  c17_10          ; 6 [11-10] into LINE 230
       jsr  c17_10          ; 6 [11-10] into LINE 231
       jsr  c17_10          ; 6 [11-10] into LINE 232
       jsr  c17_10          ; 6 [11-10] into LINE 233
       jsr  c17_10          ; 6 [11-10] into LINE 234
       lda  #BC_BLK23       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 235: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 236
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 237
       jsr  c17_10          ; 6 [11-10] into LINE 238
                            ; change the sprite position/pointer before the end of line
       bit  $1234           ; 4 [11-14]
       nop                  ; 2 [15-16]
       lda  #239            ; 2 [17-18]
       sta  $D005           ; 4 [19-22] set sprite 2 y coord
       sta  $D007           ; 4 [23-26] set sprite 3 y coord
       bit  $4444           ; 4 [27-30]
       bit  $5555           ; 4 [31-34]
       bit  $6666           ; 4 [35-38]
       inc  SPIND2          ; 6 [39-44] set new sprite pointers
       inc  SPIND3          ; 6 [45-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 239: where new sprite may be activated
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 240
       jsr  c17_10          ; 6 [11-10] into LINE 241
       jsr  c17_10          ; 6 [11-10] into LINE 242
       lda  #BC_BLK24       ; 2 [11-12]
       jsr  c18_50          ; 6 [13-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; sprite 2 and 3 are fetching
                            ; LINE 243: bad line
;::::::
       sta  $d021-$10,y     ; 5 [5-9] set the background color
       sty  $d016           ; 4 [10-56] turn off side border
       stx  $D016           ; 4 [57-4]
                            ; sprite 2 and 3 are fetching
                            ; LINE 244
       bit  $1234           ; 4 [5-8]
       nop                  ; 2 [9-10]
       jsr  c17_10          ; 6 [11-10] into LINE 245
       jsr  c17_10          ; 6 [11-10] into LINE 246
       jsr  c17_10          ; 6 [11-10] into LINE 247
       jsr  c17_10          ; 6 [11-10] into LINE 248
       jsr  c17_10          ; 6 [11-10] into LINE 249
       lda  #$33            ; 2 [11-12]
       sta  $d011           ; 4 [13-16] open upper/lower border
       lda  #250            ; 2 [17-18]
       sta  $d001           ; 4 [19-22] set mob 0 pos y
       sta  $d003           ; 4 [23-26] set mob 1 pos y
       sta  $d009           ; 4 [27-30] set mob 4 pos y
       sta  $d00b           ; 4 [31-34] set mob 5 pos y
       sta  $d00d           ; 4 [35-38] set mob 6 pos y
       sta  $d00f           ; 4 [39-42] set mob 7 pos y
       lda  #BSP0           ; 2 [43-44]
       sta  SPIND0          ; 4 [45-48] set index for mob 0
       lda  #BSP1           ; 2 [49-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
                            ; LINE 250
       sta  SPIND1          ; 4 [5-8] set index for mob 1
       lda  #BSP4           ; 2 [9-10]
       sta  SPIND4          ; 4 [11-14] set index for mob 4
       lda  #BSP5           ; 2 [15-16]
       sta  SPIND5          ; 4 [17-20] set index for mob 5
       lda  #BSP6           ; 2 [21-22]
       sta  SPIND6          ; 4 [23-26] set index for mob 6
       lda  #BSP7           ; 2 [27-28]
       sta  SPIND7          ; 4 [29-32] set index for mob 7
       lda  #$ff            ; 2 [33-34]
       sta  $d015           ; 4 [35-38] enable all sprites
       bit  $1234           ; 4 [39-42]
       bit  $5678           ; 4 [43-46]
       bit  $9012           ; 4 [47-50]
       dec  $D016           ; 6 [51-10] turn off side border
                            ; LINE 251: all sprites are fetching
       stx  $D016           ; 4 [11-14] restore side border
       bit  $1234           ; 4 [15-18]
       bit  $5678           ; 4 [19-22]
       jsr  c29_22          ; 6 [23-22] into LINE 252
       jsr  c29_22          ; 6 [23-22] into LINE 253
       jsr  c29_22          ; 6 [23-22] into LINE 254
       jsr  c29_22          ; 6 [23-22] into LINE 255
       jsr  c29_22          ; 6 [23-22] into LINE 256
       jsr  c29_22          ; 6 [23-22] into LINE 257
       jsr  c29_22          ; 6 [23-22] into LINE 258
       jsr  c29_22          ; 6 [23-22] into LINE 259

 ; update sprite 2 and 3 position/pointers
       lda  #$18            ; 2 [23-24]
       sta  $D016           ; 4 [25-28] restore screen size
       lda  #(260-256)      ; 2 [29-30]
       sta  $d005           ; 4 [31-34] new mob 2 y pos
       sta  $d007           ; 4 [35-38] new mob 3 y pos
       inc  SPIND2          ; 6 [39-44] change mob 2 pointer
       inc  SPIND3          ; 6 [45-50] change mob 3 pointer
       dec  $D016           ; 6 [51-56] turn off side border
                            ; LINE 260
       lda  #$18            ; 2 [11-12]
       sta  $D016           ; 4 [13-16] restore screen size
       bit  $1234           ; 4 [17-20]
       nop                  ; 2 [21-22]
       jsr  c29_22          ; 6 [23-22] into LINE 261
       jsr  c29_22          ; 6 [23-22] into LINE 262
       jsr  c29_22          ; 6 [23-22] into LINE 263
       jsr  c29_22          ; 6 [23-22] into LINE 264
       jsr  c29_22          ; 6 [23-22] into LINE 265
       jsr  c29_22          ; 6 [23-22] into LINE 266
       jsr  c29_22          ; 6 [23-22] into LINE 267
       jsr  c29_22          ; 6 [23-22] into LINE 268
       jsr  c29_22          ; 6 [23-22] into LINE 269

; set the next rows of sprite y position: the pointer will be changed only before
; the last line of the current being displayed mobs.
       ldx  #(271-256)      ; 2 [23-24] set position for sprites
       stx  $D001           ; 4 [25-28] mob 0
       stx  $D003           ; 4 [29-32] mob 1
       stx  $D009           ; 4 [33-36] mob 4
       stx  $D00B           ; 4 [37-40] mob 5
       stx  $D00D           ; 4 [41-44] mob 6
       stx  $D00F           ; 4 [45-48] mob 7
       nop                  ; 2 [49-50]
       dec  $d016           ; 6 [51-56] turn off side border
                            ; all sprites are fetching: next cycle is 11
                            ; LINE 270
       sta  $D016           ; 4 [11-14]
       inc  SPIND0          ; 6 [15-20]
       inc  SPIND1          ; 6 [21-26]
       inc  SPIND4          ; 6 [27-32]
       inc  SPIND5          ; 6 [33-38]
       inc  SPIND6          ; 6 [39-44]
       inc  SPIND7          ; 6 [45-50]
       dec  $d016           ; 6 [51-56] turn off side border
                            ; all sprites are fetching: next cycle is 11
                            ; LINE 271
       lda  #$18            ; 2 [11-12]
       sta  $D016           ; 4 [13-16] restore screen size
       bit  $1234           ; 4 [17-20]
       nop                  ; 2 [21-22]
       jsr  c29_22          ; 6 [23-22] into LINE 272
       jsr  c29_22          ; 6 [23-22] into LINE 273
       jsr  c29_22          ; 6 [23-22] into LINE 274
       jsr  c29_22          ; 6 [23-22] into LINE 275
       jsr  c29_22          ; 6 [23-22] into LINE 276
       jsr  c29_22          ; 6 [23-22] into LINE 277
       jsr  c29_22          ; 6 [23-22] into LINE 278
       jsr  c29_22          ; 6 [23-22] into LINE 279
       jsr  c29_22          ; 6 [23-22] into LINE 280
       jsr  c29_22          ; 6 [23-22] into LINE 281
       ldx  #(281-256)      ; 2 [23-24] set position for sprites
       stx  $D005           ; 4 [25-28] mob 2
       stx  $D007           ; 4 [29-32] mob 3
       bit  $1234           ; 4 [33-36]
       nop                  ; 4 [37-38]
       inc  SPIND2          ; 6 [39-44]
       inc  SPIND3          ; 6 [45-50]
       dec  $d016           ; 6 [51-56] turn off side border
                            ; all sprites are fetching: next cycle is 11
                            ; LINE 282
       lda  #$18            ; 2 [11-12]
       sta  $D016           ; 4 [13-16] restore screen size
       lda  #$3b            ; 2 [17-18]
       sta  $d011           ; 4 [19-22] ripristinate for upper/lower border
       jsr  c29_22          ; 6 [23-22] into LINE 283
       jsr  c29_22          ; 6 [23-22] into LINE 284
       jsr  c29_22          ; 6 [23-22] into LINE 285
       jsr  c29_22          ; 6 [23-22] into LINE 286
       jsr  c29_22          ; 6 [23-22] into LINE 287
       jsr  c29_22          ; 6 [23-22] into LINE 288

; this operation must be executed after the last lower border line
; we set the new sprite y position to be at line 8
       ldx  #8              ; 2 [23-24] set position for the first row of sprites
       stx  $D001           ; 4 [25-28]
       stx  $D003           ; 4 [29-32]
       stx  $D005           ; 4 [33-26]
       stx  $D007           ; 4 [37-40]
       stx  $D009           ; 4 [41-44]
       stx  $D00B           ; 4 [45-48]
       stx  $D00D           ; 4 [49-52]
       stx  $D00F           ; 4 [53-56]
       ldx  #$ff            ; 2 []
       stx  $D015           ; 4 [] enable all 8 sprites


       lda  limit
       bne  jump_end

       lda  phase
       cmp  #1
       bne  next1

       lda  #COL
       sta  $D027         ; sprite 0 color
       jmp  end_eff

next1: cmp  #3
       bne  next2

       lda  #COL
       sta  $D028         ; sprite 1 color
       jmp  end_eff

next2: cmp  #5
       bne  next3

       lda  #COL
       sta  $D02b         ; sprite 4 color
       jmp  end_eff

next3: cmp  #7
       bne  next4

       lda  #COL
       sta  $D02c         ; sprite 5 color
       jmp  end_eff

next4: cmp  #9
       bne  next5

       lda  #COL
       sta  $D02d         ; sprite 6 color
       jmp  end_eff

next5: cmp  #11
       bne  next6

       lda  #COL
       sta  $D02e         ; sprite 7 color
       jmp  end_eff

next6: lda  #1        ; all the others to white color
       sta  $d027
       sta  $d028
       sta  $d02b
       sta  $d02c
       sta  $d02d
       sta  $d02e

end_eff:
       inc  phase
       lda  phase
       and  #15
       sta  phase

       lda  #LIMIT
       sta  limit
jump_end:
       dec  limit

       lda  $FF
       cmp  #$CC                ; timing for cycle effect
       bne  playmusic

       ; cicle for color to the border columns according to music notes
       ldx  $d026

       lda  $d025
       sta  $d026

       lda  $d029
       sta  $d025

       stx  $d029
       stx  $d02a

playmusic:
       jsr  $4803  ; play music

       ldx  #raster         ; 2 []
       stx  $d012           ; 4 [] restore original raster interrupt position
       ldx  #1              ; 2 []
       stx  $d019           ; 4 [] acknowledge the raster interrupt
                            ; 15 cycles from this line
endirq:
       jmp  $ea81           ; return to the auxiliary raster interrupt


;====================================
; performe cycle 29 to 23 with 8
; sprites and opened side border
;====================================
c29_22:
       bit 87               ; 3  [29-31] waste some time
       bit 73               ; 3  [32-34]
       bit 84               ; 3  [35-37]
       bit 65               ; 3  [38-40]
       bit 76               ; 3  [41-43]
       bit 73               ; 3  [45-46]
       nop                  ; 2  [47-48]
       nop                  ; 2  [49-50]
       dec $d016            ; 6  [51-56] turn off side border

       lda  #$18            ; 2  [11-12]
       sta  $D016           ; 4  [13-16] restore side border
       rts                  ; 6  [17-22]

;====================================
; performe cycle 17 to 10 with 2
; sprites and opened side border
;====================================
c17_10:
       bit  $11             ; 4 [17-19] waste some time
       bit  $2222           ; 4 [20-23]
       bit  $3333           ; 4 [24-27]
       bit  $4444           ; 4 [28-31]
       bit  $5555           ; 4 [32-35]
       bit  $6666           ; 4 [36-39]
       bit  $7777           ; 4 [40-43]
       bit  $8888           ; 4 [44-47]
       bit  $99             ; 3 [48-50]
       dec  $D016           ; 6 [51-56] turn off side border
       stx  $D016           ; 4 [57-4] restore side border
       rts                  ; 6 [5-10]

;====================================
; performe cycle 18 to 50 with 2
; sprites and opened side border
;====================================
c18_50:
       bit  $1111           ; 4 [19-22] waste some time
       bit  $2222           ; 4 [23-26]
       bit  $3333           ; 4 [27-30]
       bit  $4444           ; 4 [31-34]
       bit  $5555           ; 4 [35-38]
       bit  $6666           ; 4 [39-42]
       nop                  ; 2 [43-44]
       rts                  ; 6 [45-50]


restore:              ; disable the Restore key
       lda  cnmi
       ldy  cnmi+1
       pha
       lda  #<nmi     ; Set the NMI vector
       sta  cnmi
       lda  #>nmi
       sta  cnmi+1
       ldx  #$81
       stx  $dd0d     ; Enable CIA 2 Timer A interrupt
       ldx  #0
       stx  $dd05
       inx
       stx  $dd04     ; Prepare Timer A to count from 1 to 0.
       ldx  #$dd
       stx  $dd0e     ; Cause an interrupt.
nmi = * + 1
       lda  #$40      ; RTI placeholder
       pla
       sta  cnmi
       sty  cnmi+1    ; restore original NMI vector (although it won't be used)
       rts

oldirq:
 .byte 22, 55


BC_BLK0 = $1    ; color for block 0
BC_BLK1 = $1    ; color for block 1
BC_BLK2 = $1    ; color for block 2
BC_BLK3 = $1    ; color for block 3
BC_BLK4 = $1    ; color for block 4
BC_BLK5 = $1    ; color for block 5
BC_BLK6 = $1    ; color for block 6
BC_BLK7 = $1    ; color for block 7
BC_BLK8 = $1    ; color for block 8
BC_BLK9 = $1    ; color for block 9
BC_BLK10 = $1   ; color for block 10
BC_BLK11 = $1   ; color for block 11
BC_BLK12 = $1   ; color for block 12
BC_BLK13 = $1   ; color for block 13
BC_BLK14 = $1   ; color for block 14
BC_BLK15 = $1   ; color for block 15
BC_BLK16 = $1   ; color for block 16
BC_BLK17 = $1   ; color for block 17
BC_BLK18 = $1   ; color for block 18
BC_BLK19 = $1   ; color for block 19
BC_BLK20 = $1   ; color for block 20
BC_BLK21 = $1   ; color for block 21
BC_BLK22 = $1   ; color for block 22
BC_BLK23 = $1   ; color for block 23
BC_BLK24 = $1   ; color for block 24


str1: .byte 2, 16, "PRESENT",0
str2: .byte 7, 9,   32, 164, 164, 164, 32
      .byte         32, 119,  32
      .byte        167, 163, 165
      .byte         32, 164, 164, 32
      .byte         32, 164, 32,  32
      .byte        111, 108, 0
str3: .byte 8, 9, 110, 32,  164, 164, 165
      .byte        167, 163, 165
      .byte        167, 32,  165
      .byte        110, 32,  164, 109
      .byte        167, 32,  109, 32
      .byte        165, 186, 0
str4: .byte 9, 9, 109, 164, 164,  32, 109
      .byte        167, 32,  165
      .byte        167, 32,  165
      .byte        165, 164, 164, 110
      .byte        167, 32,  165, 165
      .byte        165, 108, 0
str5: .byte 10, 9, 167, 164, 164, 164, 110
      .byte        167, 164, 165
      .byte        167, 164, 165
      .byte        109, 164, 164, 165
      .byte        167, 164, 108, 165
      .byte        109, 186, 0

str6: .byte 12, 11,  32, 164, 32,  32
      .byte         32, 119,  32
      .byte         32,  32,  32
      .byte        167, 112, 32, 32
      .byte        111, 108, 0
str7: .byte 13, 11, 167,  32, 109, 32
      .byte        167, 163, 165
      .byte        110, 163, 109
      .byte        167,  32, 109, 32
      .byte        165, 186, 0
str8: .byte 14, 11, 167,  32, 165, 165
      .byte        167,  32, 165
      .byte        165, 119, 167
      .byte        167, 167, 167, 32
      .byte        165, 108, 0
str9: .byte 15, 11, 167, 164, 108, 165
      .byte        167, 164, 165
      .byte        109, 164, 167
      .byte        167, 186, 186, 32
      .byte        109, 186, 0
str10:.byte 16, 11,  32,  32,  32
      .byte         32,  32,  32, 32
      .byte         32, 108, 110, 0
str11:.byte 21, 7, "A VERY SHORT CHRISTMAS DEMO",0

 org 8192
 .incbin "b3.raw"

  ; 'Buon Natale'
  .byte 25, 93, 32, 21, 85, 160, 29, 85, 224
  .byte 21, 85, 96, 25, 221, 32, 0, 0, 0
  .byte 0, 0, 0, 146, 114, 71, 213, 37, 68
  .byte 213, 37, 68, 183, 39, 71, 183, 39, 68
  .byte 149, 37, 68, 149, 37, 119, 0, 0, 0
  .byte 0,0,0,0,0,0,0,0,0
  .byte 0,0,0,0,0,0,0,0,0
  .byte 0

  ; Left column
  .byte 86, 168, 0, 90, 172, 0, 90, 172, 0
  .byte 106, 188, 0, 106, 188, 0, 170, 252, 0
  .byte 170, 252, 0, 171, 252, 0, 175, 244, 0
  .byte 175, 244, 0, 191, 212, 0, 191, 212, 0
  .byte 255, 84, 0, 255, 84, 0, 253, 84, 0
  .byte 245, 88, 0, 245, 88, 0, 213, 104, 0
  .byte 213, 104, 0, 85, 168, 0, 85, 168, 0
  .byte 0

  ; Right column
  .byte 0, 21, 170, 0, 22, 171, 0, 22, 171
  .byte 0, 26, 175, 0, 26, 175, 0, 42, 191
  .byte 0, 42, 191, 0, 42, 255, 0, 43, 253
  .byte 0, 43, 253, 0, 47, 245, 0, 47, 245
  .byte 0, 63, 213, 0, 63, 213, 0, 63, 85
  .byte 0, 61, 86, 0, 61, 86, 0, 53, 90
  .byte 0, 53, 90, 0, 21, 106, 0, 21, 106

s2:
 .incbin "b2.raw"
s1:
 .incbin "b1.raw"
s4:
 .incbin "b4.raw"

  .org $4800
 .incbin sn.bin


