START:
    MTPS #0
    MOV #2,@#102
    MOV #102,@#100
    MOV #5400, @#177662
    MOV PC,R1
    ADD #PT3FILE-.,R1
    CALL INIT
0:  WAIT
    CALL PLAY
    BR 0

INIT:
  			MOV     R1, MODULE_ADDRESS  
  			MOV     R1, R5      
  			MOVB    100.(R5), DELAY 
  			ADD     #200., R1       
  			MOV     R1, CURRENTPOSITION 
  			MOVB    102.(R5), R2    
  			ADD     R2, R1
  			INC     R1
  			MOV     R1, LOOPPOSITION    
  			CLR     R1
  			BISB    104.(R5), R1 
  			SWAB    R1
  			BISB    103.(R5), R1 
  			ADD     R5, R1      
  			MOV     R1, PATTERNSPOINTER 
  			MOV     #169., R1
  			ADD     R5, R1      
  			MOV     R1, ORNAMENTSPOINTERS   
  			MOV     #105., R1
  			ADD     R5, R1      
  			MOV     R1, SAMPLESPOINTERS 
  			BICB    #200, SETUP

 			PUSH    R5
 
 			MOV     #T_PACK, R4 
  			MOV     #T1_ + 98., R5  
  			MOV     #4, R3
  			MOV     #12., R2
3$: 		MOV     (R4)+, R0   
  			ASL     R0          
  			BR      1$          

2$: 		CLR     R1
  			BISB    (R4)+, R1   
  			ADD     R1, R0      
  			ADD     R1, R0
1$: 		MOV     R0, -(R5)   
  			SOB     R2, 2$      
  			MOVB    (R4)+, R2   
  			INC     R4
  			BIC     #1, R4      
  			SOB     R3, 3$      
  			POP     R5
 
 			MOV     #VAR0START, R1
  			MOV     #VAR0END-VAR0START, R3
4$: 		CLRB    (R1)+
  			SOB     R3, 4$

  			MOVB    #1, DELAYCOUNTER
  			MOV     #0XF001, R0     
  			MOV     #EMPTYSAMORN, R2
  			MOV     #CHANNEL_A, R4
  			MOV     (PC)+, R3
  			.BYTE   AY_TONA, AY_AMPLITUDEA
  			CALL    FILL
  			MOV     (PC)+, R3
  			.BYTE   AY_TONB, AY_AMPLITUDEB
  			CALL    FILL
  			MOV     (PC)+, R3
  			.BYTE   AY_TONC, AY_AMPLITUDEC
  			CALL    FILL

  			MOVB    13.(R5), R0         
  			SUB     #60, R0             
  			BCS     20$  
  			CMPB    R0, #10.
  			BLO     21$  
20$: 		MOV     #6, R0              
21$: 		MOVB    R0, VERSION         
  			PUSH    R0   
  			CMPB    R0, #4              
  			MOVB    99.(R5), R0         
  			ROLB    R0   
  			BICB    #177770, R0         

NOTETABLECREATOR:
  			MOV     R1, -(SP)       
  			MOV     #NT_DATA, R1
  			ADD     R0, R1
  			ADD     R0, R1
  			ADD     R0, R1          
  			CLR     R2
  			BISB    (R1)+, R2       
  			MOV     (PC)+, R0
      		NOP
  			TSTB    (R1)+           
  			BEQ     11$
  			MOV     (PC)+, R0       
 			CLC
11$: 		MOV     R0, M2

  			CLR     R3
  			BISB    (R1), R3
  			ADD #T_ ,R3
  			ADD  (SP)+, R2       

  			PUSH    R3
  			MOV     #NT_, R1            
  			PUSH    R1

  			MOV     #12., R4            
13$: 		MOV     (R2)+, R3       

  			PUSH    R1
  			MOV     #8., R5         
12$:		CLC
  			ROR     R3
  			CALL    M2              
  			MOV     R3, R0
  			ADC     R0
  			MOV     R0, (R1)
  			ADD     #24., R1
  			SOB     R5, 12$
  			POP     R1
  			TST     (R1)+           
  			SOB     R4, 13$

  			POP     R2              
  			POP     R1              

  			CMP     R1, #TCOLD_1
  			BNE     16$
  			MOVB    #0XFD, NT_ + 56
16$:		CLR     R0
  			BISB    (R1)+, R0
  			BEQ     14$
  			CLR     R5
  			RORB    R0  
  			ROL     R5  
  			ASLB    R0  
  			ADD     R0, R2  
  			TST     R5  
  			BEQ     15$ 
  			DEC     (R2)
  			DEC     (R2)
15$: 		INC     (R2)
  			SUB     R0, R2 
  			BR      16$

14$: 		POP     R0              

VOLTABLECREATOR:
  			MOV     #21, R3 
  			CLR     R1      
  			CMPB    R0, #5  
  			MOV     (PC)+, R0
      		ASLB    R0  
  			BHIS    1$      
  			DEC     R3      
  			MOV     R3, R1  
  			MOV     (PC)+, R0
      		NOP         
1$: 		MOV     R0, M2

			MOV     #VT_, R4    
  			MOV     R4, R5
  			MOV     #16., R2    
  			ADD     R2, R5
  			MOV     #256., R0
2$: 		CLRB    (R4)+   
  			SOB     R0, 2$

5$: 		PUSH    R3      

  			ADD     R3, R1  
  			MOV     #0, R3  
  			SBC     R3      

4$: 		MOVB    R3, R0  
  			MOV     R3, R4  
  			CLRB    R4
  			SWAB    R4      
  			CALL    M2
  			ADCB    R4
  			MOVB    R4, (R5)+
  			ADD     R1, R3
  			INC     R2      
  			MOV     R2, R0
  			BIC     #177760, R0
  			BNE     4$

  			POP     R3
  			CMP     R1, #119.
  			BNE     3$
  			INC     R1
3$: 		TSTB    R2      
  			BNE     5$
  			JMP     ROUT

M2: 		NOP
  			RET

PLAY:		CLR ADDTOENVELOPE
			CLRB AYREGS + AY_MIXER
			MOVB #-1, AYREGS + AY_ENVELOPETYPE
			DECB DELAYCOUNTER    
 			BGT 0PL2            
 			MOV #CHANNEL_A, R5
 			DECB CHP_NOTE_SKIP_COUNTER(R5)
 			BNE 0PL1B
 			MOV CHP_ADDRESS_IN_PATTERN(R5), R3
 			TSTB (R3)
 			BNE 0PL1A
 			CLRB NOISE_BASE
 			MOV CURRENTPOSITION, R0
 			INC R0
 			MOVB (R0), R1
 			CMPB #377, R1
 			BNE 0PLNLP
 			CALL CHECKLP
 			MOV LOOPPOSITION, R0
 			MOVB (R0), R1
0PLNLP:		MOV R0, CURRENTPOSITION
			BIC #177400, R1
			ASL R1
 			ADD     PATTERNSPOINTER, R1 
 			MOV     MODULE_ADDRESS, R2

			CLR     R3
 			BISB    (R1)+, R3       
 			SWAB    R3
 			BISB    (R1)+, R3       
 			SWAB    R3              
 			ADD     R2, R3

 			CLR     R0
 			BISB    (R1)+, R0
  			SWAB    R0
  			BISB    (R1)+, R0
  			SWAB    R0
  			ADD     R2, R0
  			MOV     R0, CHANNEL_B + CHP_ADDRESS_IN_PATTERN

  			CLR     R0
  			BISB    (R1)+, R0
  			SWAB    R0
  			BISB    (R1)+, R0
  			SWAB    R0
  			ADD     R2, R0
  			MOV     R0, CHANNEL_C + CHP_ADDRESS_IN_PATTERN

0PL1A: 		CALL    PATTERNINTERPRETER
 			MOV     R3, CHP_ADDRESS_IN_PATTERN(R5)

0PL1B: 		ADD     #CHP, R5
 			DECB    CHP_NOTE_SKIP_COUNTER(R5)
 			BNE     0PL1C
 			MOV     CHP_ADDRESS_IN_PATTERN(R5), R3
 			CALL    PATTERNINTERPRETER
 			MOV     R3, CHP_ADDRESS_IN_PATTERN(R5)

0PL1C: 		ADD     #CHP, R5
 			DECB    CHP_NOTE_SKIP_COUNTER(R5)
 			BNE     0PL1D
 			MOV     CHP_ADDRESS_IN_PATTERN(R5), R3
 			CALL    PATTERNINTERPRETER
 			MOV     R3, CHP_ADDRESS_IN_PATTERN(R5)

0PL1D: 		MOVB    DELAY, DELAYCOUNTER

0PL2: 		MOV     #CHANNEL_A, R5
			CALL    CHANGEREGISTERS
			CALL    CHANGEREGISTERS
 			CALL    CHANGEREGISTERS

 			MOVB    NOISE_BASE, R0  
 			ADD     ADDTONOISE, R0
 			MOVB    R0, AYREGS + AY_NOISE

  			MOV     ENVELOPE_BASE, R0
  			ADD     ADDTOENVELOPE, R0
  			ADD     CUR_ENV_SLIDE, R0
  			MOVB    R0, AYREGS + AY_ENVELOPE
  			SWAB    R0
  			MOVB    R0, AYREGS + AY_ENVELOPE + 1

  			MOV     #CUR_ENV_DELAY, R0
  			TSTB    (R0)
  			BEQ     ROUT
  			DECB    (R0)
  			BNE     ROUT
  			MOVB    ENV_DELAY, (R0)
  			ADD     ENV_SLIDE_ADD, CUR_ENV_SLIDE

ROUT: 		MOV     #177714, R5
  			MOV     #362, R1
  			MOV     #AYREGS + AY_ENVELOPETYPE, R4
  			MOVB    (R4), R0
  			BMI     1$
  			MOV     R1, (R5)
  			COMB    R0
  			MOVB    R0, (R5)
1$: 		INC     R1
2$: 		MOV     R1, (R5)
  			MOVB    -(R4), R0
  			COMB    R0
  			MOVB    R0, (R5)
  			INCB    R1
  			BMI     2$
  			RET

PD_ORSM: 	CLRB    CHP_ENVELOPE_ENABLED(R5)
  			CALL    SETORNAMENT
  			MOVB    (R3)+, R0
  			BR      PD_SAM_

PD_SAM: 	SUB     #0XD0, R0
  			ASL     R0
PD_SAM_: 	ADD     SAMPLESPOINTERS, R0
  			CLR     R1
  			BISB    (R0)+, R1
  			SWAB    R1
  			BISB    (R0), R1
  			SWAB    R1
  			TST     R1
  			BEQ     3$  
  			ADD     MODULE_ADDRESS, R1
  			MOV     R1, CHP_SAMPLEPOINTER(R5)
3$: 		BR      PD_LOOP

PD_VOL: 	BIC     #0XFFF0, R0
  			ASL     R0
  			ASL     R0
  			ASL     R0
  			ASL     R0
  			MOVB    R0, CHP_VOLUME(R5)
  			BR      PD_LOOP

PD_EOFF: 	CLRB    CHP_ENVELOPE_ENABLED(R5)
  			CLRB    CHP_POSITION_IN_ORNAMENT(R5)
  			BR      PD_LOOP

PD_SORE: 	BIC     #0XFFF0, R0
  			DECB    R0
  			BNE     PD_ENV
  			MOVB    (R3)+, CHP_NUMBER_OF_NOTES_TO_SKIP(R5)
  			BR      PD_LOOP

PD_ENV: 	CALL    SETENVELOPE
  			CLRB    CHP_POSITION_IN_ORNAMENT(R5)
  			BR      PD_LOOP

PD_ORN: 	CALL    SETORNAMENT
  			BR      PD_LOOP

PD_ESAM: 	CLRB    CHP_ENVELOPE_ENABLED(R5)
  			BIC     #0XFFF0, R0
  			BEQ     1$
  			CALL    SETENVELOPE
1$: 		CLRB    CHP_POSITION_IN_ORNAMENT(R5)
  			MOVB    (R3)+, R0
  			BR      PD_SAM_

PATTERNINTERPRETER:
  			MOV     CHP_NOTE(R5), PRNOTE
  			MOV     CHP_CURRENT_TON_SLIDING(R5), PRSLIDING

PD_LOOP: 	CLR     R0
  			BISB    (R3)+, R0
  			CMPB    R0, #0XF0
  			BHIS    PD_ORSM         
  			CMPB    R0, #0XD0
  			BEQ     PD_FIN          
  			BHI     PD_SAM          
  			CMPB    R0, #0XC0
  			BEQ     PD_REL          
  			BHI     PD_VOL
  			CMPB    R0, #0XB0
  			BEQ     PD_EOFF         
  			BHI     PD_SORE         
          
  			CMPB    R0, #0X50
  			BHIS    PD_NOTE         
  			CMPB    R0, #0X40
  			BHIS    PD_ORN          
  			CMPB    R0, #0X20
  			BHIS    PD_NOIS        
  			CMPB    R0, #0X10
  			BHIS    PD_ESAM        
         
  			ASL     R0
  			MOV     SPCCOMS(R0), -(SP)  
  			BR      PD_LOOP

PD_NOIS: 	BIC     #0XFFE0, R0
  			MOVB    R0, NOISE_BASE
  			BR      PD_LOOP

PD_REL: 	CLRB    CHP_ENABLED(R5)
  			BR      PD_RES

PD_NOTE:	SUB     #0X50, R0
  			MOV     R0, CHP_NOTE(R5)
  			MOVB    #-1, CHP_ENABLED(R5)

PD_RES: 	MOV     R5, R0
  			CLR     (R0)+   
  			CLR     (R0)+   
  			CLR     (R0)+   
  			CLR     (R0)+   
  			CLR     (R0)+   
  			CLR     (R0)    

PD_FIN: 	MOVB    CHP_NUMBER_OF_NOTES_TO_SKIP(R5), CHP_NOTE_SKIP_COUNTER(R5)
  			RET

C_PORTM: 	CLRB    CHP_SIMPLEGLISS(R5)
  			MOVB    (R3)+, R0

 			INC     R3
  			INC     R3
  			MOVB    R0, CHP_TON_SLIDE_DELAY(R5)
  			MOVB    R0, CHP_TON_SLIDE_COUNT(R5)
  			MOV     CHP_NOTE(R5), R2
  			MOV     R2, CHP_SLIDE_TO_NOTE(R5)
  			ASL     R2
  			MOV     NT_(R2), R2
  			MOV     PRNOTE, R1
  			MOV     R1, CHP_NOTE(R5)
  			ASL     R1
  			MOV     NT_(R1), R1
  			SUB     R1, R2
  			MOV     R2, CHP_TON_DELTA(R5)   
  			MOV     CHP_CURRENT_TON_SLIDING(R5), R1
  			CMPB    VERSION, #6
  			BLO     OLDPRTM         
  			MOV     PRSLIDING, R1
  			MOV     R1, CHP_CURRENT_TON_SLIDING(R5)
OLDPRTM: 	CLR     R0
  			BISB    (R3)+, R0       
  			SWAB    R0
  			BISB    (R3)+, R0       
  			SWAB    R0
  			TST     R0              
  			BPL     1$
  			NEG     R0
1$: 		SUB     R1, R2          
  			BPL     2$              
  			NEG     R0
2$: 		MOV     R0, CHP_TON_SLIDE_STEP(R5)
  			CLRB    CHP_CURRENT_ONOFF(R5)
  			RET

C_GLISS: 	MOVB    (PC), CHP_SIMPLEGLISS(R5)
  			MOVB    (R3)+, R0
  			MOVB    R0, CHP_TON_SLIDE_DELAY(R5)
  			BNE     GL36
 
  			CMPB    VERSION, #7     
  			BLO     GL36
  			INCB    R0  
GL36: 		MOVB    R0, CHP_TON_SLIDE_COUNT(R5)
  			MOVB    (R3)+, CHP_TON_SLIDE_STEP(R5) 
  			MOVB    (R3)+, CHP_TON_SLIDE_STEP + 1(R5) 
  			CLRB    CHP_CURRENT_ONOFF(R5)
  			RET

C_SMPOS: 	MOVB    (R3)+, CHP_POSITION_IN_SAMPLE(R5)
  			RET

C_ORPOS: 	MOVB    (R3)+, CHP_POSITION_IN_ORNAMENT(R5)
  			RET

C_VIBRT: 	MOVB    (R3), CHP_ONOFF_DELAY(R5)
  			MOVB    (R3)+, CHP_CURRENT_ONOFF(R5)
  			MOVB    (R3)+, CHP_OFFON_DELAY(R5)
  			CLRB    CHP_TON_SLIDE_COUNT(R5)
  			CLR     CHP_CURRENT_TON_SLIDING(R5)
  			RET

C_ENGLS: 	MOVB    (R3), ENV_DELAY
  			MOVB    (R3)+, CUR_ENV_DELAY
  			MOVB    (R3)+, ENV_SLIDE_ADD
  			MOVB    (R3)+, ENV_SLIDE_ADD + 1
  			RET

C_DELAY: 	MOVB    (R3)+, DELAY
  			RET

SETENVELOPE:
			MOVB    #0X10, CHP_ENVELOPE_ENABLED(R5)
  			MOVB    R0, AYREGS + AY_ENVELOPETYPE
  			MOVB    (R3)+, ENVELOPE_BASE + 1    
  			MOVB    (R3)+, ENVELOPE_BASE        
  			CLRB    CUR_ENV_DELAY
  			CLR     CUR_ENV_SLIDE
C_NOP: 		RET

SETORNAMENT:
 			BIC     #0XFFF0, R0
  			ASL     R0
  			ADD     ORNAMENTSPOINTERS, R0
  			CLR     R1
  			BISB    (R0)+, R1
  			SWAB    R1
  			BISB    (R0), R1
  			SWAB    R1
  			TST     R1
  			BNE     1$ 
  			MOV     #EMPTYSAMORN, R1
  			BR      2$
1$: 		ADD     MODULE_ADDRESS, R1
2$: 		MOV     R1, CHP_ORNAMENTPOINTER(R5)
  			CLRB    CHP_POSITION_IN_ORNAMENT(R5)
  			RET

SPCCOMS: 	.WORD   C_NOP
  			.WORD   C_GLISS 
  			.WORD   C_PORTM 
  			.WORD   C_SMPOS 
  			.WORD   C_ORPOS 
  			.WORD   C_VIBRT 
  			.WORD   C_NOP
  			.WORD   C_NOP
  			.WORD   C_ENGLS 
  			.WORD   C_DELAY 
  			.WORD   C_NOP
  			.WORD   C_NOP
  			.WORD   C_NOP
  			.WORD   C_NOP
  			.WORD   C_NOP
  			.WORD   C_NOP

CHANGEREGISTERS:
  			CLR     R1  
  			TSTB    CHP_ENABLED(R5)
  			BEQ     EX$0
  			MOV     CHP_ORNAMENTPOINTER(R5), R1 
  			MOVB    (R1)+, R4       
  			MOVB    (R1)+, R3       
  			MOVB    CHP_POSITION_IN_ORNAMENT(R5), R0    
  			ADD     R0, R1
  			INCB    R0
  			CMPB    R0, R3
  			BLO     CH_ORPS
  			MOVB    R4, R0
CH_ORPS:
 			MOVB    R0, CHP_POSITION_IN_ORNAMENT(R5)
  			MOV     CHP_NOTE(R5), R0    
  			MOVB    (R1), R1    
  			ADD     R1, R0
  			BPL     CH_NTP
  			CLR     R0
CH_NTP: 	CMP     R0, #96.
  			BLO     CH_NOK
  			MOV     #95., R0
CH_NOK: 	ASL     R0
  			MOV     R0, -(SP)   
  			MOV     CHP_SAMPLEPOINTER(R5), R1   
  			MOVB    (R1)+, R4       
  			MOVB    (R1)+, R3       
  			MOVB    CHP_POSITION_IN_SAMPLE(R5), R0  
  			ADD     R0, R1
  			ADD     R0, R1
  			ADD     R0, R1
  			ADD     R0, R1
  			INCB    R0
  			CMPB    R0, R3
  			BLO     CH_SMPS
  			MOVB    R4, R0
CH_SMPS: 	MOVB    R0, CHP_POSITION_IN_SAMPLE(R5)
  			MOVB    (R1)+, R3   
  			MOVB    (R1)+, R4   
  			CLR     R2
  			BISB    (R1)+, R2   
  			SWAB    R2
  			BISB    (R1), R2
  			SWAB    R2
  			ADD     CHP_TON_ACCUMULATOR(R5), R2
  			BITB    #0X40, R4   
  			BEQ     CH_NOAC
  			MOV     R2, CHP_TON_ACCUMULATOR(R5)
CH_NOAC: 	MOV     (SP)+, R1   
  			ADD     NT_(R1), R2 
  			MOV     CHP_CURRENT_TON_SLIDING(R5), R1 
  			ADD     R1, R2      
  			BIC     #0XF000, R2
  			MOVB    CHP_TONE_REG(R5), R0
  			MOV     R2, AYREGS(R0)      

  			TSTB    CHP_TON_SLIDE_COUNT(R5)
  			BEQ     CH_AMP
  			DECB    CHP_TON_SLIDE_COUNT(R5)
  			BNE     CH_AMP
  			MOVB    CHP_TON_SLIDE_DELAY(R5), CHP_TON_SLIDE_COUNT(R5)
  			MOV     CHP_TON_SLIDE_STEP(R5), R2
  			ADD     R2, R1  
  			MOV     R1, CHP_CURRENT_TON_SLIDING(R5)
  			TSTB    CHP_SIMPLEGLISS(R5) 
  			BNE     CH_AMP
  			MOV     CHP_TON_DELTA(R5), R0
  			TST     R2          
      
  			BPL     PP1$
  			CMP     R1, R0
  			BLE     PP2$
  			BR      CH_AMP

EX$0:		BR      CH_EXIT

PP1$:		CMP     R1, R0
  			BLT     CH_AMP
PP2$:		MOV     CHP_SLIDE_TO_NOTE(R5), CHP_NOTE(R5)
  			CLRB    CHP_TON_SLIDE_COUNT(R5)
  			CLR     CHP_CURRENT_TON_SLIDING(R5)

CH_AMP: 	MOVB    CHP_CURRENT_AMPLITUDE_SLIDING(R5), R0   
  			BITB    #0X80, R3       
  			BEQ     CH_NOAM
  			BITB    #0X40, R3       
  			BEQ     CH_AMIN
  			CMPB    R0, #15.            
  			BEQ     CH_NOAM
  			INCB    R0              
  			BR      CH_SVAM
 
CH_AMIN: 	CMPB    R0, #-15.       
  			BEQ     CH_NOAM
  			DECB    R0              
CH_SVAM: 	MOVB    R0, CHP_CURRENT_AMPLITUDE_SLIDING(R5)
CH_NOAM: 	MOV     R4, R1          
  			BIC     #0XFFF0, R1     
  			ADD     R1, R0          
  			BPL     CH_APOS
  			CLR     R0
CH_APOS:	CMP     R0, #16.
  			BLO     CH_VOL
  			MOV     #15., R0            
CH_VOL:		BISB    CHP_VOLUME(R5), R0  
  			MOVB    VT_(R0), R1     
  			BITB    #1, R3          
  			BNE     CH_NOEN
  			BISB    CHP_ENVELOPE_ENABLED(R5), R1    
CH_NOEN:        
 
  			MOV     R3, R0
  			ASR     R0
  			BIC     #0XFFE0, R0     
  			BITB    #0X80, R4       
  			BEQ     NO_ENSL
  			BIT     #0X10, R0       
  			BEQ     3$              
  			BIS     #0XFFE0, R0     
3$: 		ADD     CHP_CURRENT_ENVELOPE_SLIDING(R5), R0
  			BITB    #0X20, R4       
  			BEQ     NO_ENAC
  			MOV     R0, CHP_CURRENT_ENVELOPE_SLIDING(R5)
NO_ENAC: 	ADD     R0, ADDTOENVELOPE
  			BR      CH_MIX

NO_ENSL: 	MOVB    CHP_CURRENT_NOISE_SLIDING(R5), R3   
  			ADD     R3, R0
  			MOV     R0, ADDTONOISE
  			BITB    #0X20, R4       
  			BEQ     CH_MIX
  			MOVB    R0, CHP_CURRENT_NOISE_SLIDING(R5)

CH_MIX: 	ASR     R4  
  			BIC     #177667, R4 
  			BISB    R4, AYREGS + AY_MIXER

CH_EXIT: 	MOVB    CHP_AMPL_REG(R5), R0
  			MOVB    R1, AYREGS(R0)
  			ASRB    AYREGS + AY_MIXER
  			TSTB    CHP_CURRENT_ONOFF(R5)
  			BEQ     RET0$
  			DECB    CHP_CURRENT_ONOFF(R5)
  			BNE     RET0$
  			MOVB    CHP_ONOFF_DELAY(R5), R0
  			COMB    CHP_ENABLED(R5)
  			BNE     CH_ONDL
  			MOVB    CHP_OFFON_DELAY(R5), R0
CH_ONDL: 	MOVB    R0, CHP_CURRENT_ONOFF(R5)
RET0$: 		ADD     #CHP, R5
  			RET

CHECKLP: 	BISB    #200, SETUP
  			BITB    #1, SETUP
  			BNE     1$
  			RET
1$: 		TST     (SP)+
  			INCB    DELAYCOUNTER
  			INCB    CHANNEL_A + CHP_NOTE_SKIP_COUNTER
MUTE: 		CLR     AYREGS + AY_AMPLITUDEA
  			CLRB    AYREGS + AY_AMPLITUDEC
  			MOVB    #77, AYREGS + AY_MIXER
  			JMP     ROUT

FILL:	 	MOV     R0, CHP_NOTE_SKIP_COUNTER(R4)
  			MOV     R2, CHP_ADDRESS_IN_PATTERN(R4)  
  			MOV     R2, CHP_ORNAMENTPOINTER(R4) 
  			MOV     R2, CHP_SAMPLEPOINTER(R4)   
  			MOV     R3, CHP_TONE_REG(R4)
  			ADD     #CHP, R4
  			RET

AY_TONA = 0
AY_TONB = 2
AY_TONC = 4
AY_NOISE = 6
AY_MIXER = 7
AY_AMPLITUDEA = 8.
AY_AMPLITUDEB = 9.
AY_AMPLITUDEC = 10.
AY_ENVELOPE = 11.
AY_ENVELOPETYPE = 13.

CHP_POSITION_IN_ORNAMENT = 0     
CHP_POSITION_IN_SAMPLE = 1     
CHP_CURRENT_AMPLITUDE_SLIDING= 2     
CHP_CURRENT_NOISE_SLIDING = 3     
CHP_CURRENT_ENVELOPE_SLIDING = 4     
CHP_CURRENT_TON_SLIDING = 6     
CHP_TON_ACCUMULATOR = 8.    
CHP_TON_SLIDE_COUNT = 10.   
CHP_CURRENT_ONOFF = 11.   
CHP_ONOFF_DELAY = 12.   
CHP_OFFON_DELAY = 13.   
CHP_ENVELOPE_ENABLED = 14.   
CHP_SIMPLEGLISS = 15.   
CHP_ENABLED = 16.   
CHP_ADDRESS_IN_PATTERN = 18.   
CHP_ORNAMENTPOINTER = 20.   
CHP_SAMPLEPOINTER = 22.   
CHP_SLIDE_TO_NOTE = 24.   
CHP_NOTE = 26.   
CHP_TON_SLIDE_STEP = 28.   
CHP_TON_DELTA = 30.   
CHP_NUMBER_OF_NOTES_TO_SKIP = 32.   
CHP_TON_SLIDE_DELAY = 33.   
CHP_NOTE_SKIP_COUNTER = 34.   
CHP_VOLUME = 35.   
CHP_TONE_REG = 36.   
CHP_AMPL_REG = 37.   
CHP = 38.



T_:

TCOLD_0:
 			.BYTE 0X00 + 1, 0X04 + 1, 0X08 + 1, 0X0A + 1, 0X0C + 1, 0X0E + 1, 0X12 + 1, 0X14 + 1
 			.BYTE 0X18 + 1, 0X24 + 1, 0X3C + 1, 0
TCNEW_1:
TCOLD_1: 	.BYTE 0X5C + 1, 0
TCOLD_2: 	.BYTE 0X30 + 1, 0X36 + 1, 0X4C + 1, 0X52 + 1, 0X5E + 1, 0X70 + 1, 0X82, 0X8C
 			.BYTE 0X9C, 0X9E, 0XA0, 0XA6, 0XA8, 0XAA, 0XAC, 0XAE, 0XAE, 0

TCNEW_3: 	.BYTE 0X56 + 1
TCOLD_3: 	.BYTE 0X1E + 1, 0X22 + 1, 0X24 + 1, 0X28 + 1, 0X2C + 1, 0X2E + 1, 0X32 + 1, 0XBE + 1, 0

TCNEW_0: 	.BYTE 0X1C + 1, 0X20 + 1, 0X22 + 1, 0X26 + 1, 0X2A + 1, 0X2C + 1, 0X30 + 1, 0X54 + 1
 			.BYTE 0XBC + 1, 0XBE + 1, 0

TCNEW_2: 	.BYTE 0X1A + 1, 0X20 + 1, 0X24 + 1, 0X28 + 1, 0X2A + 1, 0X3A + 1, 0X4C + 1, 0X5E + 1
 			.BYTE 0XBA + 1, 0XBC + 1, 0XBE + 1, 0

EMPTYSAMORN: 
 			.BYTE 0, 1, 0, 0X90, 0, 0 
 			.EVEN
T_PACK: 	.WORD 0X06EC
 			.BYTE 0X0755-0X06EC
  			.BYTE 0X07C5-0X0755
  			.BYTE 0X083B-0X07C5
  			.BYTE 0X08B8-0X083B
  			.BYTE 0X093D-0X08B8
  			.BYTE 0X09CA-0X093D
  			.BYTE 0X0A5F-0X09CA
  			.BYTE 0X0AFC-0X0A5F
  			.BYTE 0X0BA4-0X0AFC
  			.BYTE 0X0C55-0X0BA4
  			.BYTE 0X0D10-0X0C55
  			.BYTE 13.   
  			.EVEN
  			.WORD 0X066D
  			.BYTE 0X06CF-0X066D
  			.BYTE 0X0737-0X06CF
  			.BYTE 0X07A4-0X0737
  			.BYTE 0X0819-0X07A4
  			.BYTE 0X0894-0X0819
  			.BYTE 0X0917-0X0894
  			.BYTE 0X09A1-0X0917
  			.BYTE 0X0A33-0X09A1
  			.BYTE 0X0ACF-0X0A33
  			.BYTE 0X0B73-0X0ACF
  			.BYTE 0X0C22-0X0B73
  			.BYTE 0X0CDA-0X0C22
  			.BYTE 12.   
  			.EVEN
  			.WORD 0X0704
  			.BYTE 0X076E-0X0704
  			.BYTE 0X07E0-0X076E
  			.BYTE 0X0858-0X07E0
  			.BYTE 0X08D6-0X0858
  			.BYTE 0X095C-0X08D6
  			.BYTE 0X09EC-0X095C
  			.BYTE 0X0A82-0X09EC
  			.BYTE 0X0B22-0X0A82
  			.BYTE 0X0BCC-0X0B22
  			.BYTE 0X0C80-0X0BCC
  			.BYTE 0X0D3E-0X0C80
  			.BYTE 12.   
  			.EVEN
  			.WORD 0X07E0
  			.BYTE 0X0858-0X07E0
  			.BYTE 0X08E0-0X0858
  			.BYTE 0X0960-0X08E0
  			.BYTE 0X09F0-0X0960
  			.BYTE 0X0A88-0X09F0
  			.BYTE 0X0B28-0X0A88
  			.BYTE 0X0BD8-0X0B28
  			.BYTE 0X0C80-0X0BD8
  			.BYTE 0X0D60-0X0C80
  			.BYTE 0X0E10-0X0D60
  			.BYTE 0X0EF8-0X0E10
  			.EVEN

SETUP: 		.BYTE 0 
  
VERSION: 	.BYTE 0
DELAY:		.BYTE 0 
ENV_DELAY:	.BYTE 0
 			.EVEN
MODULE_ADDRESS:         .WORD 0 
SAMPLESPOINTERS:    	.WORD 0 
ORNAMENTSPOINTERS:  	.WORD 0 
PATTERNSPOINTER:    	.WORD 0 
LOOPPOSITION:           .WORD 0 
CURRENTPOSITION:        .WORD 0 

VAR0START:  

PRNOTE:					.WORD 0 
PRSLIDING:              .WORD 0 
ADDTOENVELOPE:          .WORD 0 
ENV_SLIDE_ADD:          .WORD 0
CUR_ENV_SLIDE:          .WORD 0
ADDTONOISE:             .WORD 0
DELAYCOUNTER:           .BYTE 0 
CUR_ENV_DELAY:          .BYTE 0
NOISE_BASE:             .BYTE 0
         				.EVEN

CHANNEL_A:              .BLKB   CHP
CHANNEL_B:              .BLKB   CHP
CHANNEL_C:              .BLKB   CHP

AYREGS:
VT_:            .BLKB   256.    
  
  
ENVELOPE_BASE = AYREGS + 14.

T1_ = VT_ + 16. 
T_OLD_1 = T1_
T_OLD_2 = T_OLD_1 + 24.
T_OLD_3 = T_OLD_2 + 24.
T_OLD_0 = T_OLD_3 + 2.

T_NEW_0 = T_OLD_0
T_NEW_1 = T_OLD_1
T_NEW_2 = T_NEW_0 + 24.
T_NEW_3 = T_OLD_3

NT_DATA:        .BYTE   T_NEW_0-T1_, 0  
 .BYTE   TCNEW_0-T_      
 .BYTE   T_OLD_0-T1_, 1
 .BYTE   TCOLD_0-T_
 .BYTE   T_NEW_1-T1_, 1
 .BYTE   TCNEW_1-T_
 .BYTE   T_OLD_1-T1_, 1
 .BYTE   TCOLD_1-T_
 .BYTE   T_NEW_2-T1_, 0
 .BYTE   TCNEW_2-T_
 .BYTE   T_OLD_2-T1_, 0
 .BYTE   TCOLD_2-T_
 .BYTE   T_NEW_3-T1_, 0
 .BYTE   TCNEW_3-T_
 .BYTE   T_OLD_3-T1_, 0
 .BYTE   TCOLD_3-T_
 .EVEN

NT_:            .BLKW   96. 

VAR0END = T1_           

PT3FILE:
	insert_file "2018_EA_demosong.pt3"