;=========================================
;The return of Sheba "Il ritorno di Sheba"
;
; The originale song use a Basic/machine
; code for generating music
; This is a machine code port 
; The code can generate a PRG or SID file.
;=========================================

.ifdef sid
 .byte "PSID"
 .word $0200         ; version 2
 .word $7C00         ; data offset
 .word $0000         ; load address in cbm format
 .byte >initMusic
 .byte <initMusic 
 .byte >playMusic
 .byte <playMusic 
 .word $0100         ; 1 song
 .word $0100         ; default song
 .word $FFFF
 .word $FFFF
 .byte "The return of Sheba",0,0,0,0,0,0,0,0,0,0,0,0,0
 .byte "Stefano Tognon",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 .byte "1986-87 Stefano Tognon",0,0,0,0,0,0,0,0,0,0
 .word $0000
 .word $0000
 .word $0000
 
.endif

.org $0801

 ;=================================
 ; PRG start address
 ;=================================
 .byte $01,$08

 ;=================================
 ; BASIC startup program
 ;=================================
 .byte $0b,$08,$e8,$03,$9e,"2061",0,0,0

.org 2061
     jsr initMusic

     sei
     lda #<interr
     sta $0314
     lda #>interr
     sta $0315

     cli

aaa:
 jmp aaa

interr =*
     ;lda  $01
     ;and  #$fe
     ;sta  $01
     lda  contr+0
     bne  playMusic
kernal:
     ;lda  $01
     ;ora  #$01
     ;sta  $01
     jmp  $ea31

playMusic:  
     ldx #$00
     lda instr+0,x                ; Voice 1: Control registers
     beq nend
     inc instr+5,x
     bne nend
     inc instr+6,x
     bne nend
     lda instr+1,x                ; Voice 1: notes address lo 
     sta $fe
     lda instr+2,x                ; Voice 1: notes address hi
     sta $ff
     ldy #$00
     lda ($fe),y
     asl
     tay
     lda contr+2,y
     sta $d400,x                  ; Voice 1: Frequency control (lo byte)
     lda contr+3,y
     sta $d401,x                  ; Voice 1: Frequency control (hi byte)
     lda instr+3,x                ; Voice 1: notes duration address lo 
     sta $fe
     lda instr+4,x                ; Voice 1: notes duration address hi
     sta $ff
     ldy #$00
     lda ($fe),y
     bne skip
     sta instr+0,x                ; Voice 1: Control registers
     jmp nend
skip:
     tay
loop:     
     lda instr+5,x
     sec
     sbc contr+1
     sta instr+5,x
     lda instr+6,x
     sbc #$00
     sta instr+6,x
     dey
     bne loop
     inc instr+1,x                ; Voice 1: notes address lo 
     bne skip1
     inc instr+2,x                ; Voice 1: notes address hi
skip1:
     inc instr+3,x                ; Voice 1: notes duration address lo 
     bne skip2
     inc instr+4,x                ; Voice 1: notes duration address hi
skip2:
     lda #$00
     sta $d404,x                  ; Voice 1: Control registers
     lda instr+0,x                ; Voice 1: Control registers
     sta $d404,x                  ; Voice 1: Control registers
nend:
     txa
     clc
     adc #$07
     tax
     cmp #$15
     bne skip3
.ifdef sid
     rts
.endif
     jmp kernal
skip3:
     jmp playMusic+2


initMusic =*
                                  ; initialize control registers 
     lda #$00
     ;sta contr+0
     sta contr+2
     sta contr+3
     lda #$8
     sta contr+1
                                  ; erase all sid registers
     ldx  #24
     lda  #0
loop1:
     sta  $D400,x
     dex
     bpl  loop1
                                  ; initialze sid registers
     lda  #25
     sta  $D405                   ; Generator 1: Attack/Decay (voice 1)
     sta  $D40C                   ; Generator 1: Attack/Decay (voice 2)
     sta  $D413                   ; Generator 1: Attack/Decay (voice 2)
     lda  #79
     sta  $D418                   ; Select volume and filter mode 
     lda  #200
     sta  $D402                   ; Voice 1: Wave form pulsation amplitude (lo byte)
     lda  #60
     sta  $D409                   ; Voice 2: Wave form pulsation amplitude (lo byte)
     sta  $D410                   ; Voice 3: Wave form pulsation amplitude (lo byte)
     lda  #50
     sta  $D416                   
     lda  #0
     sta  $D417
     
     rts

contr =*                          ; control register
  .byte 1;0
  .byte 8
  .byte 0
  .byte 0
  
freq =*  
  .byte 76, 4
  .byte 141, 4
  .byte 210, 4
  .byte 28, 5
  .byte 105, 5
  .byte 188, 5
  .byte 19, 6
  .byte 112, 6
  .byte 210, 6
  .byte 57, 7
  .byte 167, 7
  .byte 28, 8
  .byte 152, 8
  .byte 26, 9
  .byte 165, 9
  .byte 56, 10
  .byte 211, 10
  .byte 120, 11
  .byte 39, 12
  .byte 224, 12
  .byte 164, 13
  .byte 115, 14
  .byte 79, 15
  .byte 57, 16
  .byte 48, 17
  .byte 53, 18
  .byte 74, 19 
  .byte 112, 20
  .byte 167, 21
  .byte 241, 22
  .byte 78, 24
  .byte 192, 25
  .byte 72, 27
  .byte 231, 28
  .byte 159, 30
  .byte 114, 32
  .byte 96, 34
  .byte 107, 36
  .byte 149, 38
  .byte 225, 40
  .byte 79, 43
  .byte 226, 45
  .byte 157, 48
  .byte 129, 51
  .byte 145, 54
  .byte 207, 57
  .byte 63, 61
  .byte 228, 64
  .byte 192, 68
  .byte 214, 72
  .byte 43, 77
  .byte 194, 81
  .byte 158, 86
  .byte 197, 91
  .byte 58, 97
  .byte 2, 103
  .byte 34, 109
  .byte 159, 115
  .byte 127, 122
  .byte 200, 129
  .byte 128, 137
  .byte 173, 145
  .byte 86, 154
  ;.byte 132, 163
  ;.byte 61, 173
  ;.byte 138, 183
  ;.byte 116, 194
  ;.byte 4, 206
  
instr=*
  .byte 65                        ; Voice 1: Control registers
  .byte <note1                    ; Voice 1: notes address lo 
  .byte >note1                    ; Voice 1: notes address hi
  .byte <len1                     ; Voice 1: notes duration address lo 
  .byte >len1                     ; Voice 1: notes duration address hi
  .byte 255
  .byte 255
  
  .byte 17                        ; Voice 2: Control registers
  .byte <note2                    ; Voice 2: notes address lo 
  .byte >note2                    ; Voice 2: notes address hi
  .byte <len2                     ; Voice 2: notes duration address lo 
  .byte >len2                     ; Voice 2: notes duration address hi
  .byte 255
  .byte 255
  
  .byte 17                        ; Voice 3: Control registers
  .byte <note3                    ; Voice 3: notes address lo 
  .byte >note3                    ; Voice 3: notes address hi
  .byte <len3                     ; Voice 3: notes duration address lo 
  .byte >len3                     ; Voice 3: notes duration address hi
  .byte 255
  .byte 255
  
note1 =*                          ; note value for voice 1
  .byte $1d, $1d, $1e, $1b, $20, $1d, $29, $29
  .byte $2a, $27, $2c, $29, $24, $20, $22, $1e
  .byte $1d, $1d, $1e, $22, $20, $24, $27, $25
  .byte $24, $22, $20, $1e, $1d, $00, $19, $1b
  .byte $1d, $19, $1b, $1d, $19, $1b, $1d, $19
  .byte $1e, $24, $25, $24, $20, $19, $1e, $24
  .byte $22, $25, $29, $27, $26, $24, $23, $20
  .byte $1f, $1d, $1c, $19, $1b, $1c, $1d, $1e
  .byte $1d, $1e, $22, $25, $22, $1e, $1d, $1e
  .byte $1d, $1e, $22, $25, $24, $22, $20, $24
  .byte $24, $24, $24, $1e, $00, $20, $20, $20
  .byte $20, $21, $00, $20, $20, $20, $20, $21
  .byte $00, $29, $25, $22, $1e, $22, $25, $29
  .byte $25, $22, $1e, $22, $25, $29, $25, $22
  .byte $1e, $29, $25, $22, $1e, $22, $25, $29
  .byte $25, $22, $1e, $22, $25, $29, $25, $22
  .byte $1e, $1e, $1d, $1d, $00, $24, $1e, $1d
  .byte $1d, $00, $24, $22, $20, $20, $00, $27
  .byte $00, $25, $25, $25, $25, $25, $24, $24
  .byte $00

  .byte $1d, $1d, $1e, $1b, $20, $1d, $29, $29
  .byte $2a, $27, $2c, $29, $24, $20, $22, $1e
  .byte $1d, $1d, $1e, $22, $20, $24, $27, $25
  .byte $24, $22, $20, $1e, $1d, $00, $19, $1b
  .byte $1d, $19, $1b, $1d, $19, $1b, $1d, $19
  .byte $1e, $24, $25, $24, $20, $19, $1e, $24
  .byte $22, $25, $29, $27, $26, $24, $23, $20
  .byte $1f, $1d, $1c, $19, $1b, $1c, $1d, $1e
  .byte $1d, $1e, $22, $25, $22, $1e, $1d, $1e
  .byte $1d, $1e, $22, $25, $24, $22, $20, $24
  .byte $24, $24, $24, $1e, $00, $20, $20, $20
  .byte $20, $21, $00, $20, $20, $20, $20, $21
  .byte $00, $29, $25, $22, $1e, $22, $25, $29
  .byte $25, $22, $1e, $22, $25, $29, $25, $22
  .byte $1e, $29, $25, $22, $1e, $22, $25, $29
  .byte $25, $22, $1e, $22, $25, $29, $25, $22
  .byte $1e, $1e, $1d, $1d, $00, $24, $1e, $1d
  .byte $1d, $00, $24, $22, $20, $20, $00, $27
  .byte $00, $25, $25, $25, $25, $25, $24, $24
  .byte $00

  .byte $1d, $1d, $1e, $1b, $20, $1d, $29, $29
  .byte $2a, $27, $2c, $29, $24, $20, $22, $1e
  .byte $1d, $1d, $1e, $22, $20, $24, $27, $25
  .byte $24, $22, $20, $1e, $1d, $00, $19, $1b
  .byte $1d, $19, $1b, $1d, $19, $1b, $20, $20
  .byte $22, $1e, $24, $20, $25, $25, $27, $24
  .byte $29, $25, $20, $1b, $20, $1b, $1d, $1d
  .byte $1d, $1e, $1b, $20, $1d, $00, $24, $24
  .byte $24, $24, $1e, $00, $00, $20, $20, $20
  .byte $20, $21, $00, $20, $20, $20, $20, $21
  .byte $00, $29, $25, $22, $1e, $22, $25, $29
  .byte $25, $22, $1e, $22, $25, $29, $25, $22
  .byte $1e, $29, $25, $27, $24, $20, $24, $27
  .byte $25, $20, $1d, $1d, $1e, $1b, $20, $1d
  .byte $1d, $1b, $20, $20, $20, $20, $1f, $00
  .byte $0f, $0f, $0f, $0f, $0a, $00, $1d, $1d
  .byte $1e, $1b, $20, $1d, $00

  .byte $1d, $1d, $1e, $1b, $20, $1d, $29, $29
  .byte $2a, $27, $2c, $29, $24, $20, $22, $1e
  .byte $1d, $1d, $1e, $22, $20, $24, $27, $25
  .byte $24, $22, $20, $1e, $1d, $00, $19, $1b
  .byte $1d, $19, $1b, $1d, $19, $1b, $20, $20
  .byte $22, $1e, $24, $20, $25, $25, $27, $24
  .byte $29, $25, $20, $1b, $20, $1b, $1d, $1d
  .byte $1d, $1e, $1b, $20, $1d, $00, $24, $24
  .byte $24, $24, $1e, $00, $00, $20, $20, $20
  .byte $20, $21, $00, $20, $20, $20, $20, $21
  .byte $00, $29, $25, $22, $1e, $22, $25, $29
  .byte $25, $22, $1e, $22, $25, $29, $25, $22
  .byte $1e, $29, $25, $27, $24, $20, $24, $27
  .byte $25, $20, $1d, $1d, $1e, $1b, $20, $1d
  .byte $1d, $1b, $20, $20, $20, $20, $1f, $00
  .byte $0f, $0f, $0f, $0f, $0a, $00, $1d, $1d
  .byte $1e, $1b, $20, $1d, $00

  .byte $0d, $0d, $0d, $0d, $0b, $00, $0c, $0c
  .byte $0c, $0c, $09, $00, $00, $0a, $08, $0a
  .byte $0a, $0a, $0d, $0c, $0f, $0f, $0f, $0f
  .byte $0f, $0c, $0c, $0c, $00, $0c, $0c, $00
  .byte $1d, $1d, $1e, $1b, $20, $1d, $29, $29
  .byte $2a, $27, $2c, $29, $24, $20, $22, $1e
  .byte $1d, $1d, $1e, $22, $20, $24, $27, $25
  .byte $24, $22, $20, $1e, $1d, $00, $1e, $00
  .byte $19, $19, $00, $20, $1d, $19, $1e, $24
  .byte $25, $24, $1e, $19, $1e, $24, $22, $29
  .byte $26, $27, $23, $20, $1f, $1d, $1c, $19
  .byte $1b, $1c, $1d, $24, $24, $19, $00, $00
  .byte $00, $00
  
len1 =*                           ; note duration for voice 1
  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $02, $02, $04, $04
  .byte $04, $04, $04, $04, $02, $02, $01, $01
  .byte $01, $01, $01, $01, $02, $08, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $08, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $0c, $10, $04, $02, $03
  .byte $02, $03, $02, $04, $02, $03, $02, $03
  .byte $02, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $01, $01, $04, $08, $02, $01
  .byte $01, $04, $08, $02, $01, $01, $04, $08
  .byte $04, $02, $02, $04, $04, $08, $02, $02
  .byte $04

  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $02, $02, $04, $04
  .byte $04, $04, $04, $04, $02, $02, $01, $01
  .byte $01, $01, $01, $01, $02, $08, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $08, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $0c, $10, $04, $02, $03
  .byte $02, $03, $02, $04, $02, $03, $02, $03
  .byte $02, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $01, $01, $04, $08, $02, $01
  .byte $01, $04, $08, $02, $01, $01, $04, $08
  .byte $04, $02, $02, $04, $04, $08, $02, $02
  .byte $04

  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $02, $02, $04, $04
  .byte $04, $04, $04, $04, $02, $02, $01, $01
  .byte $01, $01, $01, $01, $02, $08, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $01, $01
  .byte $02, $01, $02, $01, $01, $01, $02, $01
  .byte $02, $01, $04, $04, $04, $04, $08, $02
  .byte $02, $04, $02, $04, $02, $04, $01, $01
  .byte $01, $01, $06, $02, $08, $04, $02, $03
  .byte $02, $03, $02, $04, $02, $03, $02, $03
  .byte $02, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $08, $04, $04, $08, $04, $08, $04
  .byte $08, $08, $04, $02, $03, $02, $03, $02
  .byte $01, $01, $01, $01, $08, $04, $01, $01
  .byte $02, $01, $02, $01, $08

  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $02, $02, $04, $04
  .byte $04, $04, $04, $04, $02, $02, $01, $01
  .byte $01, $01, $01, $01, $02, $08, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $01, $01
  .byte $02, $01, $02, $01, $01, $01, $02, $01
  .byte $02, $01, $04, $04, $04, $04, $08, $02
  .byte $02, $04, $02, $04, $02, $04, $01, $01
  .byte $01, $01, $06, $02, $08, $04, $02, $03
  .byte $02, $03, $02, $04, $02, $03, $02, $03
  .byte $02, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $08, $04, $04, $08, $04, $08, $04
  .byte $08, $08, $04, $02, $03, $02, $03, $02
  .byte $01, $01, $01, $01, $08, $04, $01, $01
  .byte $02, $01, $02, $01, $08

  .byte $04, $02, $03, $02, $03, $02, $04, $02
  .byte $03, $02, $03, $02, $10, $10, $08, $08
  .byte $08, $08, $08, $08, $02, $02, $02, $02
  .byte $04, $04, $08, $04, $04, $04, $04, $08
  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $02, $02, $04, $04
  .byte $04, $04, $04, $04, $02, $02, $01, $01
  .byte $01, $01, $01, $01, $02, $02, $02, $02
  .byte $02, $02, $02, $04, $08, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $04, $04, $08, $10, $10
  .byte $10, $00

note2 =*                          ; note value for voice 2
  .byte $14, $14, $16, $12, $18, $14, $06, $06
  .byte $06, $06, $06, $06, $0d, $12, $12, $11
  .byte $0f, $0d, $0c, $0a, $08, $00, $08, $06
  .byte $05, $08, $06, $05, $08, $06, $05, $06
  .byte $08, $00, $05, $05, $06, $06, $08, $08
  .byte $0a, $0a, $0c, $0c, $00, $14, $14, $16
  .byte $12, $18, $14, $06, $06, $06, $06, $06
  .byte $06, $11, $11, $11, $11, $0a, $00, $05
  .byte $05, $05, $05, $05, $00, $05, $05, $05
  .byte $05, $05, $00, $14, $11, $0d, $0a, $0d
  .byte $11, $14, $11, $0d, $0a, $0d, $11, $14
  .byte $11, $0d, $0a, $11, $0d, $0a, $06, $0a
  .byte $0d, $11, $0d, $0a, $06, $0a, $0d, $11
  .byte $0d, $0a, $06, $0f, $0f, $11, $0d, $14
  .byte $0f, $0d, $0d, $0f, $0c, $11, $0d, $0a
  .byte $00, $0a, $00, $00, $0d, $00, $0d, $0d
  .byte $11, $0f, $0d, $0a, $0c, $0c, $0c, $00

  .byte $14, $14, $16, $12, $18, $14, $06, $06
  .byte $06, $06, $06, $06, $0d, $12, $12, $11
  .byte $0f, $0d, $0c, $0a, $08, $00, $08, $06
  .byte $05, $08, $06, $05, $08, $06, $05, $06
  .byte $08, $00, $05, $05, $06, $06, $08, $08
  .byte $0a, $0a, $0c, $0c, $00, $14, $14, $16
  .byte $12, $18, $14, $06, $06, $06, $06, $06
  .byte $06, $11, $11, $11, $11, $0a, $00, $05
  .byte $05, $05, $05, $05, $00, $05, $05, $05
  .byte $05, $05, $00, $14, $11, $0d, $0a, $0d
  .byte $11, $14, $11, $0d, $0a, $0d, $11, $14
  .byte $11, $0d, $0a, $11, $0d, $0a, $06, $0a
  .byte $0d, $11, $0d, $0a, $06, $0a, $0d, $11
  .byte $0d, $0a, $06, $0f, $0f, $11, $0d, $14
  .byte $0f, $0d, $0d, $0f, $0c, $11, $0d, $0a
  .byte $00, $0a, $00, $00, $0d, $00, $0d, $0d
  .byte $11, $0f, $0d, $0a, $0c, $0c, $0c, $00

  .byte $14, $14, $16, $12, $18, $14, $06, $06
  .byte $06, $06, $06, $06, $0d, $0d, $12, $12
  .byte $12, $11, $0f, $0d, $0c, $0a, $08, $00
  .byte $08, $06, $05, $08, $06, $05, $08, $06
  .byte $05, $08, $06, $05, $05, $14, $14, $16
  .byte $12, $18, $14, $06, $06, $06, $06, $06
  .byte $06, $0d, $0d, $0d, $0d, $0d, $0d, $0c
  .byte $0a, $08, $08, $14, $14, $18, $12, $18
  .byte $14, $00, $0a, $0a, $0a, $0a, $00, $06
  .byte $00, $00, $05, $05, $05, $05, $05, $00
  .byte $06, $05, $06, $05, $06, $00, $0f, $0d
  .byte $0d, $0f, $0c, $0c, $0f, $0d, $0d, $0f
  .byte $0c, $0c, $0c, $0c, $0d, $00, $0c, $1b
  .byte $1b, $1d, $1b, $20, $1d, $1d, $1d, $1b
  .byte $1b, $1b, $20, $20, $20, $20, $1f, $00
  .byte $24, $24, $24, $24, $22, $00, $1e, $1e
  .byte $20, $1d, $22, $1e, $00

  .byte $14, $14, $16, $12, $18, $14, $06, $06
  .byte $06, $06, $06, $06, $0d, $0d, $12, $12
  .byte $12, $11, $0f, $0d, $0c, $0a, $08, $00
  .byte $08, $06, $05, $08, $06, $05, $08, $06
  .byte $05, $08, $06, $05, $05, $14, $14, $16
  .byte $12, $18, $14, $06, $06, $06, $06, $06
  .byte $06, $0d, $0d, $0d, $0d, $0d, $0d, $0c
  .byte $0a, $08, $08, $14, $14, $18, $12, $18
  .byte $14, $00, $0a, $0a, $0a, $0a, $00, $06
  .byte $00, $00, $05, $05, $05, $05, $05, $00
  .byte $06, $05, $06, $05, $06, $00, $0f, $0d
  .byte $0d, $0f, $0c, $0c, $0f, $0d, $0d, $0f
  .byte $0c, $0c, $0c, $0c, $0d, $00, $0c, $1b
  .byte $1b, $1d, $1b, $20, $1d, $1d, $1d, $1b
  .byte $1b, $1b, $20, $20, $20, $20, $1f, $00
  .byte $24, $24, $24, $24, $22, $00, $1e, $1e
  .byte $20, $1d, $22, $1e, $00

  .byte $22, $00, $22, $00, $1b, $1b, $00, $1e
  .byte $00, $1e, $00, $19, $19, $00, $24, $24
  .byte $20, $20, $1b, $19, $00, $1e, $22, $25
  .byte $1d, $00, $1e, $22, $0a, $08, $0a, $08
  .byte $00, $0a, $08, $0a, $08, $00, $1e, $1f
  .byte $1e, $1f, $00, $1e, $1f, $1e, $1f, $00
  .byte $1f, $00, $1f, $00, $1b, $1b, $00, $1e
  .byte $00, $1e, $00, $19, $19, $19, $19, $00
  .byte $19, $19, $00, $29, $29, $2a, $27, $2c
  .byte $29, $1b, $1b, $1b, $1b, $1b, $1b, $20
  .byte $20, $20, $20, $21, $00, $20, $20, $20
  .byte $20, $21, $00, $22, $00, $22, $00, $1b
  .byte $1b, $00, $1e, $19, $1b, $1d, $19, $1b
  .byte $1d, $19, $1b, $19, $1b, $1d, $00, $1b
  .byte $1b, $1d, $1d, $22, $00, $22, $00, $1b
  .byte $1b, $00, $1e, $00, $1e, $00, $19, $19
  .byte $00, $20, $24, $24, $19, $00, $19, $00

len2 =*                           ; note duration for voice 2
  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $10, $10, $01, $01
  .byte $01, $01, $01, $01, $02, $08, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $04, $01, $01, $02
  .byte $01, $02, $01, $01, $01, $02, $01, $02
  .byte $01, $01, $01, $01, $01, $0c, $10, $04
  .byte $02, $03, $02, $03, $02, $04, $02, $03
  .byte $02, $03, $02, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $01, $01, $02, $01, $02
  .byte $01, $01, $01, $02, $01, $02, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04, $02
  .byte $02, $02, $02, $08, $08, $02, $02, $04

  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $10, $10, $01, $01
  .byte $01, $01, $01, $01, $02, $08, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $04, $01, $01, $02
  .byte $01, $02, $01, $01, $01, $02, $01, $02
  .byte $01, $01, $01, $01, $01, $0c, $10, $04
  .byte $02, $03, $02, $03, $02, $04, $02, $03
  .byte $02, $03, $02, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $01, $01, $02, $01, $02
  .byte $01, $01, $01, $02, $01, $02, $01, $04
  .byte $04, $04, $04, $04, $04, $04, $04, $02
  .byte $02, $02, $02, $08, $08, $02, $02, $04

  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $08, $08, $08, $08
  .byte $01, $01, $01, $01, $01, $01, $02, $08
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $04, $01, $01, $02
  .byte $01, $02, $01, $01, $01, $02, $01, $02
  .byte $01, $01, $01, $02, $02, $02, $01, $04
  .byte $04, $04, $04, $02, $02, $04, $02, $04
  .byte $02, $04, $01, $01, $01, $01, $02, $04
  .byte $02, $08, $04, $02, $03, $02, $03, $02
  .byte $04, $02, $03, $02, $03, $02, $02, $01
  .byte $01, $02, $01, $01, $02, $01, $01, $02
  .byte $01, $01, $02, $02, $02, $02, $08, $04
  .byte $04, $08, $04, $08, $04, $04, $04, $02
  .byte $02, $04, $04, $02, $03, $02, $03, $02
  .byte $01, $01, $01, $01, $08, $04, $01, $01
  .byte $02, $01, $02, $01, $08

  .byte $01, $01, $02, $01, $02, $01, $01, $01
  .byte $02, $01, $02, $01, $08, $08, $08, $08
  .byte $01, $01, $01, $01, $01, $01, $02, $08
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $04, $01, $01, $02
  .byte $01, $02, $01, $01, $01, $02, $01, $02
  .byte $01, $01, $01, $02, $02, $02, $01, $04
  .byte $04, $04, $04, $02, $02, $04, $02, $04
  .byte $02, $04, $01, $01, $01, $01, $02, $04
  .byte $02, $08, $04, $02, $03, $02, $03, $02
  .byte $04, $02, $03, $02, $03, $02, $02, $01
  .byte $01, $02, $01, $01, $02, $01, $01, $02
  .byte $01, $01, $02, $02, $02, $02, $08, $04
  .byte $04, $08, $04, $08, $04, $04, $04, $02
  .byte $02, $04, $04, $02, $03, $02, $03, $02
  .byte $01, $01, $01, $01, $08, $04, $01, $01
  .byte $02, $01, $02, $01, $08

  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $04, $04
  .byte $02, $02, $02, $02, $04, $02, $02, $02
  .byte $04, $02, $02, $02, $01, $01, $01, $01
  .byte $04, $01, $01, $01, $01, $04, $01, $01
  .byte $01, $01, $04, $01, $01, $01, $01, $04
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $04, $02, $04, $04, $08, $04, $04
  .byte $04, $04, $08, $01, $01, $02, $01, $02
  .byte $01, $02, $01, $01, $02, $01, $01, $04
  .byte $02, $03, $02, $03, $02, $04, $02, $03
  .byte $02, $03, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $04, $04, $04, $08, $10, $10, $00

note3 =*                          ; note value for voice 3
  .byte $0f, $0d, $0d, $0f, $0c, $0c, $0f, $0d
  .byte $0d, $0f, $0c, $0c, $16, $08, $11, $01
  .byte $05, $06, $08, $00, $08, $08, $0a, $0a
  .byte $0c, $0c, $0e, $0e, $00, $0f, $0f, $0f
  .byte $0d, $0d, $0f, $0c, $0c, $0f, $0d, $0d
  .byte $0f, $0c, $0c, $0d, $0d, $0d, $0d, $00
  .byte $16, $00, $00, $08, $08, $0a, $06, $0c
  .byte $08, $14, $14, $16, $12, $18, $14, $11
  .byte $0d, $0a, $06, $0a, $0d, $11, $0d, $0a
  .byte $06, $0a, $0d, $11, $06, $0d, $0a, $06
  .byte $0d, $0a, $06, $03, $06, $0a, $0d, $0a
  .byte $06, $03, $06, $0a, $0d, $0a, $06, $03
  .byte $0a, $08, $08, $00, $0f, $06, $0a, $0d
  .byte $11, $00

  .byte $0f, $0d, $0d, $0f, $0c, $0c, $0f, $0d
  .byte $0d, $0f, $0c, $0c, $16, $08, $11, $01
  .byte $05, $06, $08, $00, $08, $08, $0a, $0a
  .byte $0c, $0c, $0e, $0e, $00, $0f, $0f, $0f
  .byte $0d, $0d, $0f, $0c, $0c, $0f, $0d, $0d
  .byte $0f, $0c, $0c, $0d, $0d, $0d, $0d, $00
  .byte $16, $00, $00, $08, $08, $0a, $06, $0c
  .byte $08, $14, $14, $16, $12, $18, $14, $11
  .byte $0d, $0a, $06, $0a, $0d, $11, $0d, $0a
  .byte $06, $0a, $0d, $11, $06, $0d, $0a, $06
  .byte $0d, $0a, $06, $03, $06, $0a, $0d, $0a
  .byte $06, $03, $06, $0a, $0d, $0a, $06, $03
  .byte $0a, $08, $08, $00, $0f, $06, $0a, $0d
  .byte $11, $00

  .byte $0f, $0d, $0d, $0f, $0c, $0c, $0f, $0d
  .byte $0d, $0f, $0c, $0c, $14, $14, $0a, $0a
  .byte $11, $06, $0f, $0c, $0c, $0d, $0a, $0a
  .byte $0f, $0c, $0c, $0f, $0d, $0d, $11, $11
  .byte $06, $06, $06, $06, $0a, $0d, $0a, $0d
  .byte $0f, $0d, $0d, $00, $0f, $0f, $0f, $0f
  .byte $08, $00, $00, $00, $08, $08, $0a, $06
  .byte $0c, $08, $14, $14, $16, $12, $18, $14
  .byte $0d, $0d, $0f, $0c, $11, $0d, $11, $0d
  .byte $0d, $0c, $0c, $0f, $00, $0f, $0d, $0d
  .byte $0f, $0c, $0c, $08, $08, $08, $08, $06
  .byte $06, $06, $06, $03, $0a, $0a, $0a, $0a
  .byte $0c, $00, $0c, $0c, $0d, $0a, $0f, $0c
  .byte $00

  .byte $0f, $0d, $0d, $0f, $0c, $0c, $0f, $0d
  .byte $0d, $0f, $0c, $0c, $14, $14, $0a, $0a
  .byte $11, $06, $0f, $0c, $0c, $0d, $0a, $0a
  .byte $0f, $0c, $0c, $0f, $0d, $0d, $11, $11
  .byte $06, $06, $06, $06, $0a, $0d, $0a, $0d
  .byte $0f, $0d, $0d, $00, $0f, $0f, $0f, $0f
  .byte $08, $00, $00, $00, $08, $08, $0a, $06
  .byte $0c, $08, $14, $14, $16, $12, $18, $14
  .byte $0d, $0d, $0f, $0c, $11, $0d, $11, $0d
  .byte $0d, $0c, $0c, $0f, $00, $0f, $0d, $0d
  .byte $0f, $0c, $0c, $08, $08, $08, $08, $06
  .byte $06, $06, $06, $03, $0a, $0a, $0a, $0a
  .byte $0c, $00, $0c, $0c, $0d, $0a, $0f, $0c
  .byte $00

  .byte $22, $00, $22, $00, $1b, $1b, $00, $1e
  .byte $00, $1e, $00, $19, $19, $00, $24, $24
  .byte $20, $20, $1b, $19, $00, $22, $24, $25
  .byte $20, $00, $22, $24, $24, $25, $24, $25
  .byte $00, $24, $25, $24, $25, $00, $25, $29
  .byte $25, $29, $00, $25, $29, $25, $29, $00
  .byte $22, $25, $22, $25, $00, $22, $25, $22
  .byte $25, $00, $1e, $22, $1e, $22, $00, $22
  .byte $1b, $1b, $00, $1b, $1b, $00, $24, $22
  .byte $22, $24, $20, $20, $24, $22, $22, $24
  .byte $20, $20, $20, $24, $22, $25, $24, $20
  .byte $1d, $1d, $1e, $1b, $20, $1d, $00, $1d
  .byte $1d, $1e, $1b, $20, $1d, $24, $24, $1b
  .byte $1b, $00, $00
  
len3 =*                           ; note duration for voice 3
  .byte $02, $01, $01, $02, $01, $01, $02, $01
  .byte $01, $02, $01, $01, $10, $10, $10, $10
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $04, $02, $02, $02
  .byte $01, $01, $02, $01, $01, $02, $01, $01
  .byte $02, $01, $01, $01, $01, $01, $01, $08
  .byte $04, $04, $10, $10, $01, $01, $02, $01
  .byte $02, $01, $01, $01, $02, $01, $02, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $01, $01, $02, $04, $08, $10, $10, $10
  .byte $08, $08

  .byte $02, $01, $01, $02, $01, $01, $02, $01
  .byte $01, $02, $01, $01, $10, $10, $10, $10
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $04, $02, $02, $02
  .byte $01, $01, $02, $01, $01, $02, $01, $01
  .byte $02, $01, $01, $01, $01, $01, $01, $08
  .byte $04, $04, $10, $10, $01, $01, $02, $01
  .byte $02, $01, $01, $01, $02, $01, $02, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $01, $01, $01, $01, $01, $01, $01, $01
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $01, $01, $02, $04, $08, $10, $10, $10
  .byte $08, $08

  .byte $02, $01, $01, $02, $01, $01, $02, $01
  .byte $01, $02, $01, $01, $08, $08, $08, $08
  .byte $10, $10, $02, $01, $01, $02, $01, $01
  .byte $02, $01, $01, $02, $01, $01, $08, $08
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $04, $02, $02, $04, $01, $01, $01, $01
  .byte $06, $02, $08, $10, $01, $01, $02, $01
  .byte $02, $01, $01, $01, $02, $01, $02, $01
  .byte $01, $01, $02, $01, $02, $01, $04, $04
  .byte $08, $02, $02, $02, $02, $08, $04, $04
  .byte $08, $04, $04, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $10, $01, $01, $01, $01
  .byte $08, $04, $01, $01, $02, $01, $02, $01
  .byte $08

  .byte $02, $01, $01, $02, $01, $01, $02, $01
  .byte $01, $02, $01, $01, $08, $08, $08, $08
  .byte $10, $10, $02, $01, $01, $02, $01, $01
  .byte $02, $01, $01, $02, $01, $01, $08, $08
  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $04, $02, $02, $04, $01, $01, $01, $01
  .byte $06, $02, $08, $10, $01, $01, $02, $01
  .byte $02, $01, $01, $01, $02, $01, $02, $01
  .byte $01, $01, $02, $01, $02, $01, $04, $04
  .byte $08, $02, $02, $02, $02, $08, $04, $04
  .byte $08, $04, $04, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $10, $01, $01, $01, $01
  .byte $08, $04, $01, $01, $02, $01, $02, $01
  .byte $08

  .byte $02, $02, $02, $02, $02, $02, $02, $02
  .byte $02, $02, $02, $02, $02, $02, $04, $04
  .byte $02, $02, $02, $02, $04, $02, $02, $02
  .byte $04, $02, $02, $02, $01, $01, $01, $01
  .byte $04, $01, $01, $01, $01, $04, $01, $01
  .byte $01, $01, $04, $01, $01, $01, $01, $04
  .byte $01, $01, $01, $01, $04, $01, $01, $01
  .byte $01, $04, $02, $02, $02, $02, $04, $04
  .byte $08, $04, $04, $04, $04, $08, $02, $01
  .byte $01, $02, $01, $01, $02, $01, $01, $02
  .byte $01, $01, $10, $10, $08, $08, $08, $08
  .byte $01, $01, $02, $01, $02, $01, $08, $04
  .byte $04, $08, $04, $08, $04, $04, $04, $08
  .byte $10, $10, $00

