****************************************************************
*
* Init Sound DOC
*
****************************************************************
ProDOS         gequ $e100a8
               longa on
               longi on

InitSound      START ReggaeMan

               Using InstDef
               Using PictureBuffer
               Using SequenceNotes
               Using SeqEffects1
               Using SeqEffects2

               ldx #$00
               lda #$8080
bcle           sta >WaveBuffer,x                ; 256 bytes buffer
               inx
               inx
               cpx #256
               bne bcle

               sei

               PushLong #WaveBuffer             ; Copy to DOC ram 256 $80 bytes
               PushWord #0                      ; to make sure that there are no
               PushWord #256                    ; $00 bytes that would stop the
               _WriteRamBlock                   ; oscilator.

               sep #$20
               longa off

bcleWait       lda >$E1C03C
               bmi bcleWait
               ora #%00100000
               and #%10111111
               sta >$E1C03C

               lda #$40
               sta >$E1C03E             ; Set Volume Registers
               ldy #0
               lda #0                   ; Volume=0
bcleWrite1     sta >$E1C03D
               iny
               cpy #30
               bne bcleWrite1

               lda #$80
               sta >$E1C03E             ; Set Wavetable Pointer Registers
               ldy #0
               lda #0                   ; Wavetable Pointer register=0
bcleWrite2     sta >$E1C03D
               iny
               cpy #30
               bne bcleWrite2

               lda #$A0
               sta >$E1C03E             ; Set Control Registers
               ldy #0
bcleWrite3     lda #1                   ; Control Byte=1 (osc. stopped)
               sta >$E1C03D
               iny
               cpy #30
               bne bcleWrite3

               lda #$C0
               sta >$E1C03E             ; Set Wavetable Size Registers
               ldy #0
bcleWrite4     lda #0                   ; Size=0
               sta >$E1C03D
               iny
               cpy #30
               bne bcleWrite4

               lda #$00
               sta >$E1C03E
               lda #$FA
               sta >$E1C03D             ; Frequency low 0=$7D =50Hz
               lda #$20
               sta >$E1C03E
               lda #$0
               sta >$E1C03D             ; Frequency high 0=0

               lda #$E1
               sta >$E1C03E
               lda #60
               sta >$E1C03D             ; 30 osc. enabled

               lda #$A0
               sta >$E1C03E
               lda #$8
               sta >$E1C03D             ; Osc 0 generates interrupts

               rep #$20
               longa on

               cli

               rts


****************************************************************
*
* Load Music
*
****************************************************************
LoadMusic      ENTRY

               Using SequenceNotes
               Using SeqEffects1
               Using SeqEffects2
               Using InstDef

               PushLong #Parmblock
               PushWord #$2010          ; Open
               jsl GSOS
               jsl ProDOSErrJSL

               lda parmblock+2
               sta parmblock2+2
               sta parmblock3+2
               sta parmblock4+2
               sta parmblock5+2
               sta parmblock6+2
               sta parmblock7+2

               PushLong #Parmblock2
               PushWord #$2012          ; Read Header
               jsl GSOS
               jsl ProDOSErrJSL

               ldx #44
               ldy #0
bcleSetVolume  lda >HeaderBuffer,x
               sta VolumeTable,y
               iny
               iny
               txa
               clc
               adc #30
               tax
               cmp #470
               bcc bcleSetVolume

ReadFile       lda >HeaderBuffer+6
               sta Length
               sta Length2
               sta Length3

               PushLong #Parmblock3
               PushWord #$2012          ; Read Notes
               jsl GSOS
               jsl ProDOSErrJSL

               PushLong #Parmblock4
               PushWord #$2012          ; Read Effects1
               jsl GSOS
               jsl ProDOSErrJSL

               PushLong #Parmblock5
               PushWord #$2012          ; Read Effects2
               jsl GSOS
               jsl ProDOSErrJSL

               PushLong #Parmblock6
               PushWord #$2012          ; Read Stereo
               jsl GSOS
               jsl ProDOSErrJSL

               PushLong #Parmblock7
               PushWord #$2014          ; Close
               jsl GSOS
               jsl ProDOSErrJSL

               rts

               MSB OFF
MusicPathname  dc i2'MusicPNEnd-MusicPathName-2'
               dc c'1/PnP.Datas/PnP.sng'       ;Song !!!
MusicPNEnd     anop

parmblock      dc i2'2'
               ds 2                     ; ref_num
               dc i4'MusicPathname'     ; pathname

parmblock2     dc i2'4'
               ds 2                     ; ref_num
               dc i4'HeaderBuffer'      ; data_buffer
               dc i4'600'               ; request_count
               ds 4                     ; transfer_count

parmblock3     dc i2'4'
               ds 2                     ; ref_num
               dc i4'Notes'             ; data_buffer
Length         dc i4'$0000'             ; request_count
               ds 4                     ; transfer_count

parmblock4     dc i2'4'
               ds 2                     ; ref_num
               dc i4'Effects1'          ; data_buffer
Length2        dc i4'$0000'             ; request_count
               ds 4                     ; transfer_count

parmblock5     dc i2'4'
               ds 2                     ; ref_num
               dc i4'Effects2'          ; data_buffer
Length3        dc i4'$0000'             ; request_count
               ds 4                     ; transfer_count

parmblock6     dc i2'4'
               ds 2                     ; ref_num
               dc i4'StereoTable'       ; data_buffer
               dc i4'30'                ; request_count
               ds 4                     ; transfer_count

parmblock7     dc i2'1'
               ds 2

LoadDOCFile    anop

               PushLong #Parmblock8
               PushWord #$2010          ; Open
               jsl GSOS
               jsl ProDOSErrJSL

               lda parmblock8+2
               sta parmblock10+2
               sta parmblock11+2
               sta parmblock12+2
               sta parmblock13+2

               PushLong #Parmblock10
               PushWord #$2012          ; Read Index
               jsl GSOS
               jsl ProDOSErrJSL

               PushLong #Parmblock11
               PushWord #$2012          ; Read wbk
               jsl GSOS
               jsl ProDOSErrJSL

WaveReadOk     anop
               ldx InstIndex
               lda #0
bcleCalc       cpx #0
               beq EndCalc
               dex
               clc
               adc #92
               bra bcleCalc

EndCalc        sta InstLength

               PushLong #Parmblock12
               PushWord #$2012          ; Read Instruments
               jsl GSOS
               jsl ProDOSErrJSL

               PushLong #Parmblock13
               PushWord #$2014          ; Close
               jsl GSOS
               jsl ProDOSErrJSL

               rts




Write2DOC      sei

               PushLong #WaveBuffer     ; PicBuf
               Pushword #$000           ; doc start address
               PushWord #$FFFF          ; byte count
               _WriteRamBlock

               cli

               rts






InitSmith      ENTRY
               phb
               phk
               plb
               jsr InitSound
               plb
               rtl
LoadMusic2     ENTRY
               phb
               phk
               plb
               jsr LoadMusic
               plb
               rtl
LoadMusic4     ENTRY
               phb
               phk
               plb
               jsr LoadDOCFile
               plb
               rtl
WriteDOC2      ENTRY
               phb
               phk
               plb
               jsr Write2DOC
               plb
               rtl
Play2          ENTRY
               phb
               phk
               plb
               jsr Play
               plb
               rtl


****************************************************************
*                                                              *
* Play the music                                               *
*                                                              *
****************************************************************
Play           anop

               PushLong #SoundIRQrtn
               _SetSoundMIRQV

               stz Timer
               lda >HeaderBuffer+8
               sta Tempo
               lda >HeaderBuffer+470
               and #%0000000011111111
               sta NumberOfBlocks               ; If NumberOfBlocks=0
               beq SkipPlay                     ; do not play.
               stz NotePlayed
               stz BlockIndex
               lda >HeaderBuffer+472
               and #%0000000011111111
               asl a
               tax
               lda BlockTable,x
               sta NoteIndex
               lda #1
               sta Performing

SkipPlay       rts



FatalError     ENTRY
               brk $0
               brk $0
               dc c'SoundS... error'

DOCStr         dc i2'DOCStrEnd-DOCStr-2'
               dc c'1/PnP.Datas/PnP.wbk'       ; WaveBank !!!
DOCStrEnd      anop

parmblock8     dc i2'2'
               ds 2                     ; ref_num
               dc i4'DOCStr'            ; pathname

parmblock10    dc i2'4'
               ds 2                     ; ref_num
               dc i4'InstIndex'         ; data_buffer
               dc i4'$0002'             ; request_count
               ds 4                     ; transfer_count

parmblock11    dc i2'4'
               ds 2                     ; ref_num
               dc i4'WaveBuffer'        ; data_buffer
               dc i4'$10000'            ; request_count
               ds 4                     ; transfer_count

parmblock12    dc i2'4'
               ds 2                     ; ref_num
               dc i4'Instrument1'       ; data_buffer
instlength     dc i4'0000'              ; request_count
               ds 4                     ; transfer_count

parmblock13    dc i2'1'
               ds 2


****************************************************************
*                                                              *
* Sound IRQ routine  (This routine is called 50 times/second)  *
*                                                              *
****************************************************************
SoundIRQrtn    anop

               longa off
               longi off

               phb
               phd

               rep #$30
               lda >MyZP
               tcd
               sep #$30

               phk
               plb

               lda Performing
               bne BcleWaitUn
               jmp Stopped

BcleWaitUn     anop
               lda >$E1C03C
               bmi BcleWaitUn
               and #%10011111           ; Disable auto-inc. and access DOC reg.
               sta >$E1C03C

               lda #$E0
               sta >$E1C03E             ; Read Interrupt register to find out
               lda >$E1C03D             ; wich osc. generated the interrupt.
               lda >$E1C03D
               and #%01111111
               sta >$E1C03D

               and #%00111110           ; If it is osc. #0 then it means that
               lsr a                    ; it is the 50Hz interrupt.
               beq TimerInterrupt

               clc                      ; If osc<>#0 then find wich pair of
               adc #$A0                 ; osc. caused the interrupt.

               sta >$E1C03E             ; Then we clear the interrupt bit
               lda >$E1C03D             ; of the first osc. of that pair
               lda >$E1C03D             ; and we launch the second one.
               bit #%00001000           ; This may  be used in future versions
               beq Stopped              ; of SoundSmith to allow instruments to
               and #%11111110           ; loop smoothly.
               sta >$E1C03D

Stopped        clc

               pld
               plb

               rtl

TimerInterrupt lda Performing           ; Performing is used to know if the
               bne WeCanPlay            ; music must be played. Set Performing
               jmp EndInterrupt         ; to 0/1 to stop/play the music.

WeCanPlay      stz Temporary            ; Temporary contains the number of the
!                                       ; track that is being processed.
               inc Timer
               lda Timer                ; If Timer=Tempo, play the notes.
               cmp Tempo                ; Else, handle Arpegiatto effects.
               beq PlayTracks

               jmp HandleEffects

PlayTracks     stz Timer                ; resets the Timer

NewTrack       rep #$30
               longa on
               longi on

               lda Temporary
               asl a
               tax
               lda ActiveTrkTable,x     ; Look if the current track is active
               beq TrackActive          ; (0=active, $FFFF=inactive)

               inc NoteIndex            ; If the track is inactive, skip it.
               inc Temporary            ; (You can save much processor time by
               lda Temporary            ; disabling the unused tracks!)
               cmp #14
               bne NewTrack

               jmp EndPlay              ; When all 14 tracks have been played,
!                                       ; exit
TrackActive    sep #$20
               longa off

               ldx NoteIndex
               lda >Notes,x             ; Reads the note to play.

               rep #$20
               longa on

               and #%0000000011111111
               beq NotValid
               cmp #128                 ; If the value of the note is >=128,
               bcs NotValid             ; then it means that it's a command.
               bra NoteFound

NotValid       inc NoteIndex            ; Point to next note (x register still
!                                         points to the current note)

               cmp #128                 ; is it STP ?
               bne NotSTP

               sep #$20
               longa off

               lda >$E1C03C             ; disable auto-increment
               and #%10011111
               sta >$E1C03C

               lda Temporary            ; Stops the osc. pair used to play
               inc a                    ; the current track
               asl a
               sta OscNumber
               clc
               adc #$A0
               sta >$E1C03E
               lda #$01
               sta >$E1C03D             ; Stop osc.a
               lda OscNumber
               clc
               adc #$A1
               sta >$E1C03E
               lda #$01
               sta >$E1C03D             ; Stop osc.b

NotACommand    sep #$20
               longa off

               inc Temporary            ; Handle next track.
               lda Temporary
               cmp #14
               beq NoMoreTracks
               jmp NewTrack

NotSTP         longa on
               cmp #129                 ; is it NXT ?
               bne NotACommand

               lda #63                  ; this will cause the player to jump
               sta NotePlayed           ; to the next block when the line of
!                                       ; notes is completed.
               bra NotACommand

NoMoreTracks   rep #$20
               longa on

               jmp EndPlay

NoteFound      sta Semitone             ; Save the note that we read.

               sep #$20
               longa off

               lda >Effects1,x          ; Read the sample number. If its value
               ldy Temporary            ; is 0, we must use the sample played
               and #%11110000           ; last.
               bne ThereIsASample
               lda SampleTable,y
ThereIsASample sta SampleTable,y        ; Else, save the sample number.
               lsr a
               lsr a
               lsr a
               lsr a
               dec a                    ; Convert the sample number*64 into
               asl a                    ; an index to tables containing words.
               tay
               lda VolumeTable,y        ; Get the volume of the sample,
               lsr a                    ; divide it by two,
               sta VolumeInt            ; and save it for later.

               rep #$20
               longa on

               lda >Effects1,x          ; Read the effect
               and #%0000000000001111
               bne NotArpegiatto        ; If effect=0, its maybe an arpegiatto.
               lda >Effects2,x          ; Read the value for the effect,

               sep #$20
               longa off

               ldy Temporary            ; and save it in this table.
               sta ArpegiattoTbl,y
               lda Semitone             ; Save the note that will be modified
               sta ArpegeToneTbl,y      ; by the arpegiatto.

               rep #$20
               longa on

               jmp NoTempoChange

NotArpegiatto  pha                      ; Save the value of the effect.

               sep #$20
               longa off

               ldy Temporary            ; First, if the effect <> 0, we must
               lda #0                   ; stop the arpegiatto effect on this
               sta ArpegiattoTbl,y      ; track.

               rep #$20
               longa on

               pla                      ; Recover the effect value.

               cmp #$03                 ; Effect $3=set volume
               bne noVolChange

               lda >Effects2,x          ; Read new volume
               and #%0000000011111111
               lsr a
               sta VolumeInt            ; and save it.

ChangeVol      lda Semitone             ; If Semitone=0, it means that we must
               beq ChangeIt             ; change the volume of a note that is
               jmp NoTempoChange        ; being played.

ChangeIt       lda Temporary
               inc a
               asl a
               sta OscNumber

               sep #$20
               longa off

SetAutoInc     lda >$E1C03C
               bmi SetAutoInc
               ora #%00100000           ; Auto-incrementation
               and #%10111111
               sta >$E1C03C

               lda OscNumber
               clc
               adc #$40
               sta >$E1C03E
               lda VolumeInt            ; Set new volume
               sta >$E1C03D             ; for osc.a
               sta >$E1C03D             ; for osc.b

               rep #$20
               longa on

               bra NoTempoChange

NoVolChange    cmp #$06                 ; Effect $6=lower the volume
               bne NoVolChange2

               lda >Effects2,x
               and #%0000000011111111
               lsr a
               sta TempInterrupt
               lda VolumeInt
               sec
               sbc TempInterrupt
               bpl VolOk
               lda #0
VolOk          sta VolumeInt
               jmp ChangeVol

NoVolChange2   cmp #$05                 ; Effect $5=Increase the volume
               bne NoVolChange3

               lda >Effects2,x
               and #%0000000011111111
               lsr a
               clc
               adc VolumeInt
               cmp #$80
               bcc VolOk2
               lda #$7F
VolOk2         sta VolumeInt
               jmp ChangeVol

NoVolChange3   cmp #$0F                 ; Effect $F=New tempo
               bne NoTempoChange
               lda >Effects2,x          ; The tempo value uses only the lowest
               and #%0000000000001111   ; nibble (1-$F)
               sta Tempo

NoTempoChange  lda Semitone
               bne PlayIt

               inc NoteIndex
               jmp NotSTP

PlayIt         lda Temporary            ; The 0-1 osc. pair is used to generate
               inc a                    ; interrupts. Therefore, the track 0
               asl a                    ; uses the pair 2-3, etc.
               sta OscNumber

               sep #$20
               longa off

               lda >$E1C03C
               and #%10011111
               sta >$E1C03C

               lda OscNumber
               clc
               adc #$A0
               sta >$E1C03E
               lda >$E1C03D
               lda >$E1C03D
               and #%11110111
               ora #%00000001
               sta >$E1C03D             ; Stop even osc.
               lda OscNumber
               clc
               adc #$A1
               sta >$E1C03E
               lda >$E1C03D
               lda >$E1C03D
               and #%11110111
               ora #%00000001
               sta >$E1C03D             ; Stop odd osc.

               ldy Temporary
               lda SampleTable,y

               rep #$20
               longa on

               and #%0000000011110000
               lsr a
               lsr a
               lsr a
               lsr a
               dec a
               cmp InstIndex            ; do not play instruments that have not
               bcc SampleExists         ; been loaded.
               jmp IgnoreSample
SampleExists   sta CurrInstInt
               asl a
               tax
               lda >InstIndexTable,x    ; Offset to the beginning of the instru-
               clc                      ; ment definition table.
               adc #32                  ; Points to the first Wavelist of osc.a
SearchingA     tax
               lda >Instrument1,x
               and #%0000000011111111
               cmp Semitone             ; If Semitone < Topkey we use this
               bcs FoundWaveListA       ; WaveList. Otherwise, we must try the
               txa                      ; next one.
               clc
               adc #6
               bra SearchingA

FoundWaveListA stx IndexInterrupt
               inx
               lda >Instrument1,x       ; Read the size & adress of the wave for
               sta TempInterrupt        ; osc.a
               inx
               inx
               lda >Instrument1,x       ; Read mode byte for osc.a
               and #%0000000011111111
               sta Temp2Interrupt
               lda StereoMode           ; If StereoMode=zero, we use the Mode
               beq StereoOk             ; byte for the channel stereo.
               lda Temp2Interrupt       ; Otherwise, we must use StereoTable
               and #%0000000000001111   ; to find out what channel to use.
               sta Temp2Interrupt
               lda Temporary            ; (0=right $FFFF=left)
               asl a
               tax
               lda StereoTable,x
               beq StereoOk
               lda Temp2Interrupt
               ora #%0000000000010000
               sta Temp2Interrupt

StereoOk       lda IndexInterrupt       ; Look for a  WaveList starting with $7F
SearchEndOfA   tax                      ; The first WaveList for osc.b starts
               lda >Instrument1,x       ; 6 bytes further.
               and #%0000000011111111
               cmp #$7F
               beq FoundEndOfA
               txa
               clc
               adc #6
               bra SearchEndOfA

FoundEndOfA    txa
               clc
               adc #6

SearchingB     tax                      ; We repeat the operations for osc.b
               lda >Instrument1,x
               and #%0000000011111111
               cmp Semitone
               bcs FoundWaveListB
               txa
               clc
               adc #6
               bra SearchingB

FoundWaveListB inx
               lda >Instrument1,x
               sta Temp3Interrupt
               inx
               inx
               lda >Instrument1,x
               and #%0000000011111111
               sta Temp4Interrupt
               lda StereoMode
               beq StereoOk2
               lda Temp4Interrupt
               and #%0000000000001111
               sta Temp4Interrupt
               lda Temporary
               asl a
               tax
               lda StereoTable,x
               beq StereoOk2
               lda Temp4Interrupt
               ora #%0000000000010000
               sta Temp4Interrupt

StereoOk2      lda Semitone             ; Converts the semitone into a
               asl a                    ; frequence.
               tax
               lda >FreqTable,x
               sta TempFreqInt
               lda CurrInstInt
               asl a
               tax
               lda CompactTable,x       ; If the instrument is compacted,
               tax                      ; the frequence must be divided by two.
bcleFreq       cpx #0                   ; (If the instrument has been compacted
               beq EndBcleFreq          ; twice, the frequence must be divided
               lsr TempFreqInt          ; by four, etc.)
               dex
               bra bcleFreq

EndBcleFreq    lda #0

               sep #$20
               longa off

bcleWait2      lda >$E1C03C
               bmi bcleWait2
               ora #%00100000           ; Set auto-incrementation
               and #%10111111
               sta >$E1C03C

               lda OscNumber
               sta >$E1C03E
               lda TempFreqInt
               sta >$E1C03D             ; Frequency low even
               sta >$E1C03D             ; Frequency low odd
               lda OscNumber
               clc
               adc #$20
               sta >$E1C03E
               lda TempFreqInt+1
               sta >$E1C03D             ; Frequency high even
               sta >$E1C03D             ; Frequency high odd
               lda OscNumber
               clc
               adc #$40
               sta >$E1C03E
               lda VolumeInt
               tax
               lda VolumeTable2,x
               sta >$E1C03D             ; Volume even
               sta >$E1C03D             ; Volume odd
               lda OscNumber
               clc
               adc #$80
               sta >$E1C03E
               lda TempInterrupt
               sta >$E1C03D             ; Wave Adress even
               lda Temp3Interrupt
               sta >$E1C03D             ; Wave Adress odd
               lda OscNumber
               clc
               adc #$C0
               sta >$E1C03E
               lda TempInterrupt+1
               sta >$E1C03D             ; Wave Size even
               lda Temp3Interrupt+1
               sta >$E1C03D             ; Wave Size odd
               lda OscNumber
               clc
               adc #$A0
               sta >$E1C03E
               lda Temp2Interrupt
               sta >$E1C03D             ; Control register even
               lda Temp4Interrupt
               sta >$E1C03D             ; Control register odd

IgnoreSample   rep #$20
               longa on

               inc NoteIndex            ; It's finished, we can go to the
               inc Temporary            ; next track...
               lda Temporary
               cmp #14
               beq EndPlay

               sep #$20
               longa off

               jmp NewTrack

               longa on

EndPlay        inc NotePlayed           ; Point to next line.
               lda NotePlayed           ; If NotePlayed=64, we must play the
               cmp #64                  ; next block.
               beq ReadNewBlock
               jmp EndInterrupt
ReadNewBlock   stz NotePlayed
               inc BlockIndex           ; Check if the music is finished.
               ldx BlockIndex
               cpx NumberOfBlocks
               beq Finished
               lda >HeaderBuffer+472,x  ; If it is not, find next block to play.
               and #%0000000011111111
               sta BlockPlayed
               asl a
               tax
               lda BlockTable,x         ; Compute new NoteIndex.
               sta NoteIndex
               bra EndInterrupt

Finished       lda #0                   ; If it is finished, set Performing to
               sta Performing           ; zero.

               lda Loop                 ; If Loop <> 0 start the song over again
               beq NoLoop
               lda >HeaderBuffer+470
               and #%0000000011111111
               sta NumberOfBlocks
               stz NotePlayed
               stz BlockIndex
               lda >HeaderBuffer+472
               and #%0000000011111111
               asl a
               tax
               lda BlockTable,x
               sta NoteIndex
               lda #1
               sta Performing

NoLoop         sep #$30                 ; Stop all the osc.
               longa off
               longi off

bcleStopAll    lda >$E1C03C
               bmi bcleStopAll
               and #%10011111           ; acces DOC registers and disable
               sta >$E1C03C             ; auto-incrementation.

               lda #2
               sta OscNumber

bcleStopAll2   lda OscNumber
               clc
               adc #$A0
               sta >$E1C03E
               lda #$01
               sta >$E1C03D             ; Stop even osc.
               lda OscNumber
               inc a
               clc
               adc #$A0
               sta >$E1C03E
               lda #$01
               sta >$E1C03D             ; Stop odd osc.

               lda OscNumber
               clc
               adc #2
               sta OscNumber
               cmp #30
               bne bcleStopAll2

EndInterrupt   sep #$30
               longa off
               longi off

               pld
               plb

               clc

               rtl                      ; End of Interrupt routine.

HandleEffects  sep #$30                 ; Handle Arpegiatto effects.
               longa off
               longi off

               stz Temporary
bcleHandleArp  ldy Temporary
               lda ArpegiattoTbl,y      ; If 0, no arpegiatto.
               bne ThereIsAnArp
               jmp NoArpegiatto

ThereIsAnArp   lda Timer                ; Timer modulo 6
               cmp #6
TryAgain       bcc StartArp
               sec
               sbc #6
               bra TryAgain

StartArp2      bne StartArp2
               jmp NoArpegiatto
StartArp       cmp #1                   ; The arpegiatto changes the
               beq Stage1               ; frequence of the note in function
               cmp #4                   ; of the time.
               beq Stage1               ; When Timer=1 ou 4 the first nibble of
               cmp #2                   ; the effect value is added to the
               beq Stage2               ; semitone of the played note.
               cmp #5                   ; When Timer=2 ou 5 the second nibble of
               beq Stage2               ; the effect value is added to the
!                                       ; semitone of the played note.
Stage3         lda ArpegiattoTbl,y      ; When Timer=3 the value of the first &
               and #%00001111           ; second nibbles of the effect value are
               sta TempInterrupt        ; substracted from the semitone of the
               lda ArpegiattoTbl,y      ; played note.
               lsr a
               lsr a
               lsr a
               lsr a
               clc
               adc TempInterrupt
               sta TempInterrupt
               lda ArpegeToneTbl,y
               sec
               sbc TempInterrupt
               sta ArpegeToneTbl,y      ; save new semitone
               bra ModifieFreq

Stage1         lda ArpegiattoTbl,y
               lsr a
               lsr a
               lsr a
               lsr a
               clc
               adc ArpegeToneTbl,y
               sta ArpegeToneTbl,y      ; save new semitone
               bra ModifieFreq

Stage2         lda ArpegiattoTbl,y
               and #%00001111
               clc
               adc ArpegeToneTbl,y
               sta ArpegeToneTbl,y      ; save new semitone

ModifieFreq    rep #$20
               longa on

               and #%0000000011111111   ; Compute the new frequence.
               asl a
               tax
               lda >FreqTable,x
               sta TempFreqInt

               sep #$20
               longa off

               ldy Temporary
               lda SampleTable,y

               rep #$20
               longa on

               asl a
               tax
               lda CompactTable,x       ; The frequency changes if the instru-
               tax                      ; ments is compacted.
bcleFreq2      cpx #0
               beq EndBcleFreq2
               lsr TempFreqInt
               dex
               bra bcleFreq2

EndBcleFreq2   sep #$20
               longa off

               lda Temporary
               inc a
               asl a
               sta OscNumber
bcleWait3      lda >$E1C03C             ; Update Frequency registers
               bmi bcleWait3
               ora #%00100000
               and #%10111111
               sta >$E1C03C

               lda OscNumber
               sta >$E1C03E
               lda TempFreqInt
               sta >$E1C03D             ; Frequency low even.
               sta >$E1C03D             ; Frequency low odd.
               lda OscNumber
               clc
               adc #$20
               sta >$E1C03E
               lda TempFreqInt+1
               sta >$E1C03D             ; Frequency high even.
               sta >$E1C03D             ; Frequency high odd.

NoArpegiatto   inc Temporary
               lda Temporary
               cmp #14
               beq Fini
               jmp bcleHandleArp

Fini           pld
               plb

               clc

               rtl

               longa on
               longi on

SampleTable    ds 14
ArpegiattoTbl  ds 14
ArpegeToneTbl  ds 14

OscNumber      ds 2
DataBank       ds 2
Temporary      ds 2
Semitone       ds 2
TempInterrupt  ds 2
Temp2Interrupt ds 2
Temp3Interrupt ds 2
Temp4Interrupt ds 2
TempFreqInt    ds 2
IndexInterrupt ds 2
VolumeInt      ds 2
CurrInstInt    ds 2


****************************************************************
*
* GlobalDATA
*
****************************************************************
InstIndex      ds 2
BlockIndex     ds 2
NotePlayed     ds 2
BlockPlayed    ds 2
NoteIndex      ds 2
Timer          ds 2
Tempo          ds 2
NumberOfBlocks ds 2
Performing     ENTRY
               dc i2'0'
Loop           ENTRY
               dc i2'0'

VolumeTable    dc i2'255,255,255,220,100,255,105,175,255,255,255,255,255,255,255'
CompactTable   dc i2'0,0,0,0,0,0,0,0,0,0,0,0,0,0,0'

ActiveTrkTable ds 14*2
StereoTable    ds 14*2
StereoMode     ds 2

VolumeTable2   dc i1'0,1,3,4,6,7,9,10,12,13,15,16,18,19,21,22,24,25,27,28'
               dc i1'30,31,33,34,36,37,39,40,42,43,45,46,48,49,51,52,54,55,57'
               dc i1'58,60,61,63,64,66,67,69,70,72,73,75,76,78,79,81,82,84,85'
               dc i1'87,88,90,91,93,94,96,97,99,100,102,103,105,106,108,109'
               dc i1'111,112,114,115,117,118,120,121,123,124,126,127,129,130'
               dc i1'132,133,135,136,138,139,141,142,144,145,147,148,150,151'
               dc i1'153,154,156,157,159,160,162,163,165,166,168,169,171,172'
               dc i1'174,175,177,178,180,181,183,184,186,187,189,190,192'

BlockTable     dc i2'0,896,1792,2688,3584,4480,5376,6272,7168,8064'
               dc i2'8960,9856,10752,11648,12544,13440,14336,15232,16128,17024'
               dc i2'17920,18816,19712,20608,21504,22400,23296,24192,25088,25984'
               dc i2'26880,27776,28672,29568,30464,31360,32256,33152,34048,34944'
               dc i2'35840,36736,37632,38528,39424,40320,41216,42112,43008,43904'
               dc i2'44800,45696,46592,47488,48384,49280,50176,51072,51968,52864'
               dc i2'53760,54656,55552,56448,57344,58240,59136,60032,60928,61824'
               dc i2'62720,63616,64512'

               END

****************************************************************
*
* Some general use buffers
*
****************************************************************
Buffer2        DATA WaveBank

WaveBuffer     ENTRY
               ds $ffff

               END

****************************************************************
*
* Instdef: Instrument definition
*
****************************************************************
instdef        DATA InstDefinition

Instrument1    ENTRY
               dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
PriorityInc1   dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount1    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount1    dc i1'0'                       ; number of waveptrs for osc B
WaveLists1     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument2    dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount2    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount2    dc i1'0'                       ; number of waveptrs for osc B
WaveLists2     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument3    dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount3    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount3    dc i1'0'                       ; number of waveptrs for osc B
WaveLists3     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument4    dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount4    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount4    dc i1'0'                       ; number of waveptrs for osc B
WaveLists4     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument5    dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount5    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount5    dc i1'0'                       ; number of waveptrs for osc B
WaveLists5     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument6    dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount6    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount6    dc i1'0'                       ; number of waveptrs for osc B
WaveLists6     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument7    dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount7    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount7    dc i1'0'                       ; number of waveptrs for osc B
WaveLists7     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument8    dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount8    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount8    dc i1'0'                       ; number of waveptrs for osc B
WaveLists8     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument9    dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount9    dc i1'0'                       ; number of waveptrs for osc A
BWaveCount9    dc i1'0'                       ; number of waveptrs for osc B
WaveLists9     dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument10   dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount10   dc i1'0'                       ; number of waveptrs for osc A
BWaveCount10   dc i1'0'                       ; number of waveptrs for osc B
WaveLists10    dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument11   dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount11   dc i1'0'                       ; number of waveptrs for osc A
BWaveCount11   dc i1'0'                       ; number of waveptrs for osc B
WaveLists11    dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument12   dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount12   dc i1'0'                       ; number of waveptrs for osc A
BWaveCount12   dc i1'0'                       ; number of waveptrs for osc B
WaveLists12    dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument13   dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount13   dc i1'0'                       ; number of waveptrs for osc A
BWaveCount13   dc i1'0'                       ; number of waveptrs for osc B
WaveLists13    dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument14   dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount14   dc i1'0'                       ; number of waveptrs for osc A
BWaveCount14   dc i1'0'                       ; number of waveptrs for osc B
WaveLists14    dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

Instrument15   dc i1'0,0,0'                   ; enveloppe
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'
               dc i1'0,0,0'                   ; fill out 8 stages with 0's
               dc i1'0'                       ; release segment - 1
               dc i1'0'                       ; priority inc
               dc i1'0'                       ; pitch bend range
               dc i1'0'                       ; slight vibrato
               dc i1'0'                       ; vibrato speed
               dc i1'0'                       ; spare
AWaveCount15   dc i1'0'                       ; number of waveptrs for osc A
BWaveCount15   dc i1'0'                       ; number of waveptrs for osc B
WaveLists15    dc i1'0,0,0,0,0,0'             ; topkey,addr,size,ctrl,pitch
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem   this size supports
               dc i1'0,0,0,0,0,0'             ; idem   up to 5 wave lists
               dc i1'0,0,0,0,0,0'             ; idem   for each wave.
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem
               dc i1'0,0,0,0,0,0'             ; idem

InstIndexTable dc i2'0,92,184,276,368,460,552,644,736,828,920,1012,1104,1196,1288,1380'

FreqTable      dc i2'$00,$16,$17,$18,$1A,$1B,$1D,$1E,$20,$22,$24,$26'                   ; Octave 0
               dc i2'$29,$2B,$2E,$31,$33,$36,$3A,$3D,$41,$45,$49,$4D'                   ; Octave 1
               dc i2'$52,$56,$5C,$61,$67,$6D,$73,$7A,$81,$89,$91,$9A'                   ; Octave 2
               dc i2'$0A3,$0AD,$0B7,$0C2,$0CE,$0D9,$0E6,$0F4,$102,$112,$122,$133'       ; Octave 3
               dc i2'$146,$15A,$16F,$184,$19B,$1B4,$1CE,$1E9,$206,$225,$246,$269'       ; Octave 4
               dc i2'$28D,$2B4,$2DD,$309,$337,$368,$39C,$3D3,$40D,$44A,$48C,$4D1'       ; Octave 5
               dc i2'$51A,$568,$5BA,$611,$66E,$6D0,$737,$7A5,$81A,$895,$918,$9A2'       ; Octave 6
               dc i2'$A35,$AD0,$B75,$C23,$CDC,$D9F,$E6F,$F4B,$1033,$112A,$122F,$1344'   ; Octave 7
               dc i2'$1469,$15A0,$16E9,$1846,$19B7,$1B3F,$1CDE,$1E95,$2066,$2254,$245E,2688' ; Octave 8

               END


*******************************************************************
*                                                                 *
* Memoire reservee au stockage des notes et effects du sequenceur *
*                                                                 *
*******************************************************************
PictureBuffer  DATA PictureSeg

HeaderBuffer   ENTRY
               ds 600

               END


SequenceNotes  DATA NoteSeg

Notes          ENTRY
               ds 25000
;               ds 65408                 ; =14*64*73

               END


SeqEffects1    DATA EffectsSeg1

Effects1       ENTRY
               ds 25000
;               ds 65408

               END


SeqEffects2    DATA EffectsSeg2

Effects2       ENTRY
               ds 25000
;               ds 65408

               END
