Add sound module
authorRobert Hogan <robhogan@gmail.com>
Tue, 13 Jul 2021 14:59:11 +0000 (15:59 +0100)
committerRobert Hogan <robhogan@gmail.com>
Tue, 13 Jul 2021 14:59:11 +0000 (15:59 +0100)
Sourced from https://github.com/historicalsource/williams-soundroms

src/VSNDRM1.SRC [new file with mode: 0755]

diff --git a/src/VSNDRM1.SRC b/src/VSNDRM1.SRC
new file mode 100755 (executable)
index 0000000..a87e237
--- /dev/null
@@ -0,0 +1,1162 @@
+       NOGEN
+       NAM     DEFENDER SOUNDS REV. 1.0 BY SAM D 10/80
+*COPYRIGHT WILLIAMS ELECTRONICS 1980
+*PROGRAM ORIGINATION DATE 10/24/80
+*PROGRAM RELEASE 10/31/80
+*PROGRAMMER: SAM DICKER
+*
+*SYSTEM CONSTANTS
+*
+ROM    EQU     $F800
+SOUND  EQU     $400
+CKORG  EQU     $F700   CHECKSUM PROG ORG
+ENDRAM EQU     $7F
+VECTOR EQU     $FFF8   RESET,INT VECTORS
+WVELEN EQU     72
+BG2MAX EQU     29
+SP1SND EQU     $0E     SPINNER SOUND #1 CODE
+B2SND  EQU     $12     BONUS SOUND #2 CODE
+SP1MAX EQU     32
+TACC   EQU     4       TACCATA TEMPO CONSTANT
+PHANC  EQU     3       PHANTOM TEMPO CONTANT
+TAF    EQU     34715!>1        NOTE TIMES
+TA     EQU     36780!>1
+TBF    EQU     38967!>1
+TB     EQU     41284!>1
+TC     EQU     43739!>1
+TCS    EQU     46340!>1
+TD     EQU     49096!>1
+TEF    EQU     52015!>1
+TE     EQU     55108!>1
+TF     EQU     58385!>1
+TFS    EQU     61857!>1
+TG     EQU     65535!>1
+*
+* TALKING EQUATES
+*
+TALK   EQU     $EFFD   ENTRY TO TALKING
+TALKD  EQU     $EFFA   ENTRY FOR DIAGNOSTICS
+*
+* SCREAM EQUATES
+*
+ECHOS  EQU     4
+FREQ   EQU     0               
+TIMER  EQU     1
+*
+*GLOBALS
+*
+       ORG     0
+TLKGL  RMB     4       TALKING GLOBALS
+BG1FLG RMB     1       BACKGROUND SOUND 1
+BG2FLG RMB     1       BACKGROUND SOUND 2
+SP1FLG RMB     1       SPINNER FLAG
+B2FLG  RMB     1       BONUS #2 FLAG
+ORGFLG RMB     1       ORGAN FLAG
+HI     RMB     1       RANDOM SEED
+LO     RMB     1       RANDOM SEED
+*
+*TEMPORARIES
+*
+TMPRAM EQU     *       TEMPORARY RAM
+TEMPX  RMB     2       X TEMPS
+XPLAY  RMB     2
+XPTR   RMB     2
+TEMPA  RMB     1       ACCA TEMP
+TEMPB  RMB     1
+LOCRAM EQU     *
+*
+*GWAVE PARAMETERS
+*
+       ORG     LOCRAM
+GECHO  RMB     1       ECHO FLAG
+GCCNT  RMB     1       CYCLE COUNT
+GECDEC RMB     1       # OF DECAYS PER ECHO
+GDFINC RMB     1       DELTA FREQ INC
+GDCNT  RMB     1       DELTA FREQ COUNT
+GWFRM  RMB     2       WAVEFORM ADDRESS
+*TEMPORARY OR COMPUTED PARAMETERS
+PRDECA RMB     1       PRE-DECAY FACTOR
+GWFRQ  RMB     2       FREQ TABLE ADDR
+FRQEND RMB     2       END ADDR FREQ TABLE
+WVEND  RMB     2       WAVE END ADDR
+GPER   RMB     1       PERIOD
+GECNT  RMB     1       # OF ECHOES COUNTER
+FOFSET RMB     1       FREQUENCY OFFSET
+*
+*GWAVE TABLES
+*
+GWTAB  RMB     WVELEN  WAVE TABLE
+*
+*VARIWAVE PARAMETERS
+*
+       ORG     LOCRAM
+LOPER  RMB     1       LO PERIOD
+HIPER  RMB     1       HIPERIOD
+LODT   RMB     1       PERIOD DELTAS
+HIDT   RMB     1
+HIEN   RMB     1       END PERIOD
+SWPDT  RMB     2       SWEEP PERIOD
+LOMOD  RMB     1       BASE FREQ MOD
+VAMP   RMB     1       AMPLITUDE
+LOCNT  RMB     1       PERIOD COUNTERS
+HICNT  RMB     1
+*
+*NOISE ROUTINE PARAMETERS
+*
+       ORG     LOCRAM
+DECAY  RMB     1
+NAMP   RMB     1
+CYCNT  RMB     1
+NFRQ1  RMB     2
+NFFLG  RMB     1
+LFREQ  RMB     1
+DFREQ  RMB     1
+*
+*FILTERED NOISE ROUTINE PARAMETERS
+*
+       ORG     LOCRAM
+FMAX   RMB     1       MAXIMUM_FREQUENCY
+FHI    RMB     1       FREQUENCY
+FLO    RMB     1 
+SAMPC  RMB     2       SAMPLE COUNT
+FDFLG  RMB     1       FREQUENCY DECREMENT FLAG
+DSFLG  RMB     1       DISTORTION FLAG
+*
+*SCREAM TABLES
+*
+       ORG     LOCRAM
+STABLE RMB     2*ECHOS SCREAM TABLE
+SRMEND EQU     *
+*
+*ORGAN PARAMETERS
+*
+       ORG     LOCRAM
+DUR    RMB     2       NOTE DURATION
+OSCIL  RMB     1       OSCILLATORS
+RDELAY RMB     60      RAM DELAY LOAD
+*
+* CHECKSUM CALCULATOR & RELOCATOR
+*
+       ORG     CKORG
+CKSUM  LDS     #$F7FF  SET STACK POINTER
+       LDX     #$FFFF  INDEX TO END OF ROM
+       CLRB            ZERO CHECKSUM
+CKSUM1 ADCB    0,X     ADD IN PROGRAM BYTE
+       DEX             TO NEXT BYTE
+       CPX     #$F800  DONE YET?
+       BNE     CKSUM1  NOPE...
+       STAB    0,X     SAVE CHECKSUM AT BEGINNING
+       STX     FROM    SAVE FOR RELO
+       LDX     #$6800  DESTINATION
+       STX     TO      SAVE FOR LATER
+RELO   LDX     FROM    GET SOURCE
+       LDAA    0,X     GRAB THE BYTE
+       INX             UPDATE
+       STX     FROM    UPDATE SOURCE ADDRESS
+       LDX     TO      GET DESTINATION ADDRESS
+       STAA    0,X     SAVE IT IN NEW LOCATION
+       INX             UPDATE
+       STX     TO      UPDATE DESTINATION ADDRESS
+       LDX     FROM    GET THE SOURCE
+       BNE     RELO    KEEP MOVING
+       WAI             TURN OFF LEDS
+FROM   RMB     2       FOR POINTER
+TO     RMB     2       FOR POINTER
+*
+* MAIN PROGRAM
+*
+       ORG     ROM
+       FCB     $FE     CHECKSUM BYTE
+SETUP  SEI             SET INTERRUPT MASK
+       LDS     #ENDRAM INITIALIZE STACK POINTER
+       LDX     #SOUND  INDEX TO PIA
+       CLR     1,X     ACCESS DDRA
+       CLR     3,X     ACCESS DDRB
+       LDAA    #$FF    PA0-PA7
+       STAA    0,X     SET SIDE A AS OUTPUTS
+       CLR     2,X     SET B SIDE AS INPUTS
+       LDAA    #$37    CB2 LOW, IRQ ALLOWED
+       STAA    3,X     PROGRAM B CONTROL REG
+       LDAA    #$3C    CA2 SET INIT HIGH, NO IRQS
+       STAA    1,X     PROGRAM A SIDE
+       STAA    HI      START RANDOM GENERATOR
+       CLRA
+       STAA    B2FLG
+       STAA    BG1FLG
+       STAA    BG2FLG
+       STAA    SP1FLG
+       STAA    ORGFLG
+       CLI             CLEAR INTERRUPTS
+       BRA     *       WAIT FOR INTERRUPT
+*
+*VARI LOADER
+*
+VARILD TAB
+       ASLA            X2
+       ASLA            X4
+       ASLA            X8
+       ABA             X9
+       LDX     #LOCRAM
+       STX     XPTR    SET XSFER
+       LDX     #VVECT
+       JSR     ADDX
+       LDAB    #9      GET COUNT
+VTRAN  JMP     TRANS
+*
+*VARIABLE DUTY CYCLE SQUARE WAVE ROUTINE
+*
+VARI   LDAA    VAMP
+       STAA    SOUND
+VAR0   LDAA    LOPER
+       STAA    LOCNT
+       LDAA    HIPER
+       STAA    HICNT
+V0     LDX     SWPDT
+V0LP   LDAA    LOCNT   LO CYCLE
+       COM     SOUND
+V1     DEX
+       BEQ     VSWEEP
+       DECA
+       BNE     V1
+       COM     SOUND
+       LDAA    HICNT   HI CYCLE
+V2     DEX
+       BEQ     VSWEEP
+       DECA
+       BNE     V2
+       BRA     V0LP    LOOP BACK
+VSWEEP LDAA    SOUND
+       BMI     VS1
+       COMA
+VS1    ADDA    #0
+       STAA    SOUND   OUTPUT
+       LDAA    LOCNT
+       ADDA    LODT
+       STAA    LOCNT
+       LDAA    HICNT
+       ADDA    HIDT
+       STAA    HICNT
+       CMPA    HIEN
+       BNE     V0
+       LDAA    LOMOD
+       BEQ     VARX
+       ADDA    LOPER
+       STAA    LOPER
+       BNE     VAR0
+VARX   RTS
+*
+*LIGHTNING
+*
+LITE   LDAA    #1
+       STAA    DFREQ
+       LDAB    #3
+       BRA     LITEN
+*
+*APPEAR
+*
+APPEAR LDAA    #$FE
+       STAA    DFREQ
+       LDAA    #$C0
+       LDAB    #$10
+       BRA     LITEN
+*
+*LIGHTNING+APPEAR NOISE ROUTINE
+*
+LITEN  STAA    LFREQ
+       LDAA    #$FF    HIGHEST AMP
+       STAA    SOUND
+       STAB    CYCNT
+LITE0  LDAB    CYCNT
+LITE1  LDAA    LO      GET RANDOM
+       LSRA
+       LSRA
+       LSRA
+       EORA    LO
+       LSRA
+       ROR     HI
+       ROR     LO
+       BCC     LITE2
+       COM     SOUND
+LITE2  LDAA    LFREQ   COUNT FREQ
+LITE3  DECA
+       BNE     LITE3
+       DECB            COUNT CYCLES
+       BNE     LITE1
+       LDAA    LFREQ
+       ADDA    DFREQ
+       STAA    LFREQ
+       BNE     LITE0
+       RTS
+*
+*TURBO
+*
+TURBO  LDAA    #$20
+       STAA    CYCNT
+       STAA    NFFLG
+       LDAA    #$1
+       LDX     #1
+       LDAB    #$FF
+       BRA     NOISE
+*
+*WHITE NOISE ROUTINE
+*X=INIT PERIOD, ACCB=INIT AMP, ACCA DECAY RATE
+*CYCNT=CYCLE COUNT, NFFLG= FREQ DECAY FLAG
+*
+NOISE  STAA    DECAY
+NOISE0 STX     NFRQ1
+NOIS00 STAB    NAMP
+       LDAB    CYCNT
+NOISE1 LDAA    LO      GET RANDOM BIT
+       LSRA
+       LSRA
+       LSRA
+       EORA    LO
+       LSRA
+       ROR     HI
+       ROR     LO
+       LDAA    #$0
+       BCC     NOISE2
+       LDAA    NAMP
+NOISE2 STAA    SOUND
+       LDX     NFRQ1   INCREASING DELAY
+NOISE3 DEX
+       BNE     NOISE3
+       DECB            FINISH CYCLE COUNT?
+       BNE     NOISE1  NO
+       LDAB    NAMP    DECAY AMP
+       SUBB    DECAY
+       BEQ     NSEND
+       LDX     NFRQ1   INC FREQ
+       INX
+       LDAA    NFFLG   DECAY FREQ?
+       BEQ     NOIS00  NO
+       BRA     NOISE0
+NSEND  RTS             
+*
+*BACKGROUND 1 ROUTINE
+*
+BG1    LDAB    #1
+       STAB    BG1FLG  
+       CLRA
+       STAA    DSFLG
+       BRA     FNOISE
+*
+*THRUST
+*
+THRUST CLRA    
+       STAA    DSFLG
+       LDAB    #3
+       BRA     FNOISE  
+*
+*CANNON
+*
+CANNON LDAA    #1      
+       STAA    DSFLG
+       LDX     #1000   
+       LDAA    #1      
+       LDAB    #$FF    
+       BRA     FNOISE 
+*
+*FILTERED NOISE ROUTINE
+*X=SAMPLE COUNT, ACCB=INITIAL MAX FREQ
+*ACCA=FREQ DECAY FLAG ,DSFLG=DISTORTION FLAG
+*
+FNOISE STAA    FDFLG
+       STAB    FMAX
+       STX     SAMPC
+       CLR     FLO
+FNOIS0 LDX     SAMPC
+       LDAA    SOUND
+FNOIS1 TAB             NEXT RANDOM NUMBER
+       LSRB
+       LSRB
+       LSRB
+       EORB    LO
+       LSRB
+       ROR     HI
+       ROR     LO
+       LDAB    FMAX    SET FREQ
+       TST     DSFLG
+       BEQ     FNOIS2
+       ANDB    HI      DISTORT FREQUENCY
+FNOIS2 STAB    FHI
+       LDAB    FLO
+       CMPA    LO
+       BHI     FNOIS4
+FNOIS3 DEX             SLOPE UP
+       BEQ     FNOIS6
+       STAA    SOUND
+       ADDB    FLO
+       ADCA    FHI
+       BCS     FNOIS5
+       CMPA    LO
+       BLS     FNOIS3
+       BRA     FNOIS5
+FNOIS4 DEX             SLOPE DOWN
+       BEQ     FNOIS6
+       STAA    SOUND
+       SUBB    FLO
+       SBCA    FHI
+       BCS     FNOIS5
+       CMPA    LO
+       BHI     FNOIS4
+FNOIS5 LDAA    LO
+       STAA    SOUND
+       BRA     FNOIS1
+FNOIS6 LDAB    FDFLG
+       BEQ     FNOIS1
+       LDAA    FMAX    DECAY MAX FREQ
+       LDAB    FLO
+       LSRA
+       RORB
+       LSRA
+       RORB
+       LSRA
+       RORB
+       COMA
+       NEGB
+       SBCA    #-1
+       ADDB    FLO
+       ADCA    FMAX
+       STAB    FLO
+       STAA    FMAX
+       BNE     FNOIS0
+       CMPB    #7
+       BNE     FNOIS0
+       RTS
+*
+*RADIO
+*
+RADIO  LDAA    #RADSND/$100 SOUND TABLE
+       STAA    XPTR
+       LDX     #100    STARTING FREQ
+       STX     TEMPX
+RADIO1 ADDB    TEMPX+1 ADD FREQ TO TIMER
+       LDAA    TEMPA
+       ADCA    TEMPX
+       STAA    TEMPA
+       LDX     TEMPX
+       BCS     RADIO2  
+       BRA     *+2     EQUALIZE TIME
+       BRA     RADIO3
+RADIO2 INX             CARRY?, RAISE FREQ
+       BEQ     RADIO4  DONE?
+RADIO3 STX     TEMPX
+       ANDA    #$F     SET POINTER
+       ADDA    #RADSND!.$FF
+       STAA    XPTR+1
+       LDX     XPTR
+       LDAA    ,X
+       STAA    SOUND   PLAY SOUND
+       BRA     RADIO1
+RADIO4 RTS     
+*
+*HYPER
+*
+HYPER  CLRA
+       STAA    SOUND   
+       STAA    TEMPA   ZERO PHASE
+HYPER1 CLRA            ZERO TIME COUNTER
+HYPER2 CMPA    TEMPA
+       BNE     HYPER3
+       COM     SOUND   PHASE EDGE?, COMPLEMENT SOUND
+HYPER3 LDAB    #18     DELAY
+HYPER4 DECB
+       BNE     HYPER4
+       INCA            ADVANCE TIME COUNTER
+       BPL     HYPER2  
+       COM     SOUND   CYCLE DONE?, CYCLE EDGE
+       INC     TEMPA   NEXT PHASE
+       BPL     HYPER1  DONE?
+       RTS
+*
+*SCREAM
+*
+SCREAM LDX     #STABLE ZERO FREQS AND TIMES
+SCREM1 CLR     ,X
+       INX
+       CPX     #SRMEND
+       BNE     SCREM1
+       LDAA    #$40    START FIRST ECHO
+       STAA    STABLE+FREQ
+SCREM2 LDX     #STABLE INITIALIZE COUNTER
+       LDAA    #$80    INITIALIZE AMPLITUDE
+       STAA    TEMPA
+       CLRB            ZERO OUTPUT BUFFER
+SCREM3 LDAA    TIMER,X ADD FREQ TO TIMER
+       ADDA    FREQ,X
+       STAA    TIMER,X
+       BPL     SCREM4  ADD AMPLITUDE IF MINUS
+       ADDB    TEMPA
+SCREM4 LSR     TEMPA   DECAY AMPLITUDE
+       INX             NEXT ECHO
+       INX
+       CPX     #SRMEND LAST ECHO?
+       BNE     SCREM3  
+       STAB    SOUND   OUTPUT SOUND
+       INC     TEMPB   ADVANCE TIMER
+       BNE     SCREM2  
+       LDX     #STABLE LOWER NON-ZERO FREQUENCIES
+       CLRB            ALL ZERO NOT FLAG
+SCREM5 LDAA    FREQ,X  
+       BEQ     SCREM7  
+       CMPA    #$37    
+       BNE     SCREM6
+       LDAB    #$41    START NEXT ECHO
+       STAB    FREQ+2,X
+SCREM6 DEC     FREQ,X
+       INCB            SET FLAG
+SCREM7 INX 
+       INX
+       CPX     #SRMEND
+       BNE     SCREM5
+       TSTB            DONE?
+       BNE     SCREM2
+       RTS
+*
+*ORGAN TUNE
+*
+ORGANT DEC     ORGFLG  MINUS ORGAN FLAG
+       RTS             
+ORGNT1 CLR     ORGFLG
+       STAA    TEMPA   TUNE NUMBER
+       LDX     #ORGTAB 
+ORGNT2 LDAA    ,X      TUNE TABLE LENGTH
+       BEQ     ORGNT5  INVALID TUNE
+       DEC     TEMPA
+       BEQ     ORGNT3  
+       INCA
+       JSR     ADDX
+       BRA     ORGNT2
+ORGNT3 INX
+       STX     XPTR    NOTE POINTER
+       JSR     ADDX
+       STX     XPLAY   TUNE END
+       LDX     XPTR    
+ORGNT4 LDAA    ,X      TUNE LOOP 
+       STAA    OSCIL
+       LDAA    1,X
+       LDX     2,X
+       STX     DUR     
+       BSR     ORGANL
+       LDX     XPTR
+       INX
+       INX     
+       INX
+       INX
+       STX     XPTR
+       CPX     XPLAY
+       BNE     ORGNT4  
+ORGNT5 JMP     IRQ3
+*
+*ORGAN NOTE
+*4 BYTES(MODE,OSCILLATOR MASK HI+1,LO+1,NOTE#)
+ORGANN LDAA    #3      SET ORGAN NOTE FLAG
+       STAA    ORGFLG
+       RTS
+ORGNN1 DEC     ORGFLG
+       BEQ     ORGNN2  
+       LDAB    OSCIL   OSCILLATOR MASK
+       ASLB
+       ASLB
+       ASLB    
+       ASLB    
+       ABA
+       STAA    OSCIL
+       CLRA
+       BRA     *       WAIT FOR NEXT CODE
+ORGNN2 DECA            DELAY
+       CMPA    #11     
+       BLS     ORGNN3  
+       CLRA    
+ORGNN3 LDX     #NOTTAB 
+       JSR     ADDX
+       LDAA    ,X
+       LDX     #$FFFF  DURATION
+       STX     DUR
+       BSR     ORGANL
+ORGNN4 BSR     ORGAN   KEEP PLAYING
+       BRA     ORGNN4
+*
+*ORGAN LOADER
+*OSCIL=OSCILLATOR MASK, ACCA=DELAY, DUR=DURATION
+*
+ORGANL LDX     #RDELAY
+LDLP   CMPA    #0
+       BEQ     LD1
+       CMPA    #3
+       BEQ     LD2
+       LDAB    #1      NOP
+       STAB    ,X
+       INX
+       SUBA    #2
+       BRA     LDLP
+LD2    LDAB    #$91    CMPA 0
+       STAB    ,X
+       CLR     1,X
+       INX
+       INX
+LD1    LDAB    #$7E    JMP START2
+       STAB    ,X
+       LDAB    #ORGAN1!>8 MSB
+       STAB    1,X
+       LDAB    #ORGAN1!.$FF LSB
+       STAB    2,X
+*
+*ORGAN ROUTINE
+*DUR=DURATION, OSCILLATOR MASK
+*
+ORGAN  LDX     DUR
+ORGAN1 CLRA            
+       FCB     $F6     LOAD B EXTND TEMPB
+       FDB     TEMPB   
+       INCB            
+       STAB    TEMPB   
+       ANDB    OSCIL   MASK OSCILLATORS
+       LSRB
+       ADCA    #0
+       LSRB
+       ADCA    #0
+       LSRB
+       ADCA    #0
+       LSRB
+       ADCA    #0
+       LSRB
+       ADCA    #0      
+       LSRB
+       ADCA    #0
+       LSRB
+       ADCA    #0      
+       ABA             
+       ASLA
+       ASLA
+       ASLA
+       ASLA            
+       STAA    SOUND   
+       DEX             
+       BEQ     ORGAN2  NOTE OVER?
+       JMP     RDELAY  
+ORGAN2 RTS
+*
+*PARAMETER TRANSFER
+*
+TRANS  PSHA
+TRANS1 LDAA    0,X
+       STX     XPLAY
+       LDX     XPTR
+       STAA    0,X
+       INX
+       STX     XPTR
+       LDX     XPLAY
+       INX
+       DECB
+       BNE     TRANS1
+       PULA
+       RTS
+*
+*BACKGROUND END ROUTINE
+*
+BGEND  CLRA 
+       STAA    BG1FLG  
+       STAA    BG2FLG  
+       RTS
+*
+*BACKGROUND SOUND #2 INCREMENT
+*
+BG2INC CLR     BG1FLG  KILL BG1
+       LDAA    BG2FLG  ACTIVATE BG2
+       ANDA    #$7F    REMOVE OVERRIDE
+       CMPA    #BG2MAX
+       BNE     BG2I0
+       CLRA
+BG2I0  INCA
+       STAA    BG2FLG
+       RTS
+*
+*BACKGROUND 2 ROUTINE
+*
+BG2    LDAA    #(TRBV-SVTAB)/7 GET SOUND#
+       JSR     GWLD
+       LDAA    BG2FLG
+       ASLA
+       ASLA
+       COMA
+       JSR     GEND60
+BG2LP  INC     GDCNT
+       JSR     GEND61
+       BRA     BG2LP
+*
+*SPINNER #1 SOUND
+*
+SP1    LDAA    #(CABSHK-VVECT)/9
+       JSR     VARILD
+       LDAB    SP1FLG
+       CMPB    #SP1MAX-1
+       BNE     SP1A
+       CLRB
+SP1A   INCB
+       STAB    SP1FLG
+       LDAA    #SP1MAX
+       SBA
+       CLRB
+SP11   CMPA    #20
+       BLS     SP12
+       ADDB    #14
+       DECA
+       BRA     SP11
+SP12   ADDB    #5
+       DECA
+       BNE     SP12
+       STAB    LOPER
+SP1LP  JSR     VARI    DO IT
+       BRA     SP1LP
+*
+*LASER BALL BONUS #2
+*
+BON2   LDAA    B2FLG
+       BNE     BON21
+       INC     B2FLG
+       LDAA    #(BONV-SVTAB)/7
+       BSR     GWLD
+       BRA     GWAVE
+BON21  JMP     GEND50
+*
+*GWAVE LOADER
+*
+GWLD   TAB             MULKT BY 7
+       ASLB
+       ABA
+       ABA
+       ABA
+       LDX     #SVTAB  SOUND VECTOR TABLE
+       JSR     ADDX
+       LDAA    ,X
+       TAB
+       ANDA    #$F
+       STAA    GCCNT   GET CYCLE COUNT
+       LSRB
+       LSRB
+       LSRB
+       LSRB
+       STAB    GECHO   GET #ECHOS
+       LDAA    1,X
+       TAB
+       LSRB
+       LSRB
+       LSRB
+       LSRB
+       STAB    GECDEC
+       ANDA    #$F     WAVE #
+       STAA    TEMPA   SAVE
+       STX     TEMPX   SAVE INDEX
+       LDX     #GWVTAB CALC WAVEFORM ADDR
+GWLD2  DEC     TEMPA   WAVE FORM #
+       BMI     GWLD3   FINIS
+       LDAA    ,X
+       INCA
+       JSR     ADDX
+       BRA     GWLD2
+GWLD3  STX     GWFRM
+       JSR     WVTRAN  XSFER WAVE TO RAM
+       LDX     TEMPX   RESTORE INDEX
+       LDAA    2,X     GET PREDECAY
+       STAA    PRDECA
+       JSR     WVDECA  DECAY IT
+       LDX     TEMPX
+       LDAA    3,X     GET FREQ INC
+       STAA    GDFINC
+       LDAA    4,X     GET DELTA FREQ COUNT
+       STAA    GDCNT
+       LDAA    5,X     GET PATTERN COUNT
+       TAB             SAVE
+       LDAA    6,X     PATTERN OFFSET
+       LDX     #GFRTAB
+       JSR     ADDX
+       TBA             GET PATTERN LENGTH
+       STX     GWFRQ   FREQ TABLE ADDR
+       CLR     FOFSET
+       JSR     ADDX
+       STX     FRQEND
+       RTS
+*
+*GWAVE ROUTINE
+*ACCA= FREQ PATTERN LENGTH, X= FREQ PAT ADDR
+*
+GWAVE  LDAA    GECHO
+       STAA    GECNT
+GWT4   LDX     GWFRQ
+       STX     XPLAY
+GPLAY  LDX     XPLAY   GET NEW PERIOD
+       LDAA    ,X
+       ADDA    FOFSET
+       STAA    GPER
+       CPX     FRQEND
+       BEQ     GEND    FINISH ON ZERO
+       LDAB    GCCNT   CYCLE COUNT
+       INX
+       STX     XPLAY
+GOUT   LDX     #GWTAB  SETUP WAVEFORM POINTER
+GOUTLP LDAA    GPER
+GPRLP  DECA            WAIT FOR PERIOD
+       BNE     GPRLP
+       LDAA    ,X      OUTPUT SOUND
+       STAA    SOUND
+GPR1   INX
+       CPX     WVEND   END OF WAVE?
+       BNE     GOUTLP
+       DECB
+       BEQ     GPLAY
+       INX
+       DEX
+       INX
+       DEX
+       INX
+       DEX
+       INX
+       DEX
+       NOP
+       NOP
+       BRA     GOUT    SYNC 36
+GEND   LDAA    GECDEC
+       BSR     WVDECA
+GEND40 DEC     GECNT   ECHO ON?
+       BNE     GWT4    YES
+       LDAA    B2FLG   STOP BONUS
+       BNE     GEND1
+GEND50 LDAA    GDFINC  CONTINUE FOR FREQ MOD SOUNDS
+       BEQ     GEND1   NO
+       DEC     GDCNT   DELTA FREQ OVER?
+       BEQ     GEND1   YES...
+       ADDA    FOFSET  UPDATE FREQ OFFSET
+GEND60 STAA    FOFSET
+GEND61 LDX     GWFRQ   GET INDEX
+       CLRB            START FOUND FLAG INIT CLEAR
+GW0    LDAA    FOFSET  INC OR DEC?
+       TST     GDFINC
+       BMI     GW1     DEC
+       ADDA    ,X      INC
+       BCS     GW2     CARRY=OVERFLOW
+       BRA     GW2A
+GW1    ADDA    ,X      DEC
+       BEQ     GW2     OVERFLOW ON EQ
+       BCS     GW2A    OVERFLOW IF CARRY CLEAR
+GW2    TSTB            FOUND START YET?
+       BEQ     GW2B    NO
+       BRA     GW3     YES, THIS IS THE END
+GW2A   TSTB
+       BNE     GW2B    ALREADY FOUND START
+       STX     GWFRQ   FOUND START
+       INCB
+GW2B   INX
+       CPX     FRQEND
+       BNE     GW0     NOT OVER YET
+       TSTB            FOUND START?
+       BNE     GW3     YES
+       RTS             ALL OVER
+GW3    STX     FRQEND
+       LDAA    GECDEC  RE:XSFER WAVE?
+       BEQ     GEND0   NO
+       BSR     WVTRAN  XSFER WAVE
+       LDAA    PRDECA
+       BSR     WVDECA
+GEND0  JMP     GWAVE
+GEND1  RTS             TERMINATE
+*
+*WAVE TRANSFER ROUTINE
+*
+WVTRAN LDX     #GWTAB
+       STX     XPTR
+       LDX     GWFRM
+       LDAB    ,X      GET WAVE LENGTH
+       INX
+       JSR     TRANS
+       LDX     XPTR
+       STX     WVEND   GET END ADDR
+       RTS
+*
+*WAVE DECAY ROUTINE/ DECAY AMOUNT IN ACCA(1/16 PER DECAY)
+*
+WVDECA TSTA
+       BEQ     WVDCX   NO DECAY
+       LDX     GWFRM   ROM WAVE INDEX
+       STX     XPLAY
+       LDX     #GWTAB
+       STAA    TEMPB   DECAY FACTOR
+WVDLP  STX     XPTR
+       LDX     XPLAY
+       LDAB    TEMPB
+       STAB    TEMPA   DECAY FACTOR TEMP
+       LDAB    1,X     OFFSET FOR WAVE LENGTH
+       LSRB
+       LSRB
+       LSRB
+       LSRB            CALC 1/16TH
+       INX
+       STX     XPLAY
+       LDX     XPTR
+       LDAA    ,X
+WVDLP1 SBA             DECAY
+       DEC     TEMPA
+       BNE     WVDLP1
+       STAA    ,X
+       INX
+       CPX     WVEND   END OF WAVE?
+       BNE     WVDLP   NO
+WVDCX  RTS
+*
+* INTERRUPT PROCESSING
+*
+IRQ    LDS     #ENDRAM RE-INITIALIZE STACK
+       LDAA    SOUND+2 GET INPUT TRIGGER
+       CLI             NOW ALLOW IRQS
+       COMA            INVERT INPUT
+       ANDA    #$1F    MASK GARB
+       LDAB    ORGFLG
+       BEQ     IRQ00
+       BPL     IRQ0
+       JSR     ORGNT1  ORGAN TUNE
+IRQ0   DECA            ORGAN NOTE
+       JSR     ORGNN1  
+IRQ00  CLRB
+       CMPA    #SP1SND
+       BEQ     IRQ00A
+       STAB    SP1FLG
+IRQ00A CMPA    #B2SND  
+       BEQ     IRQ000
+       STAB    B2FLG
+*
+* CHECK FOR PRESENCE OF TALKING PROGRAM
+*
+IRQ000 LDAB    TALK    CHECK FOR PROGRAM TO BE THERE
+       CMPB    #$7E    IS IT?
+       BNE     IRQ1    NO, SKIP THE TALKING
+       JSR     TALK    GO PLAY OUT 1 PHRASE
+IRQ1   TSTA
+       BEQ     IRQ3    INVALID INPUT
+       DECA            REMOVE OFFSET
+       CMPA    #$C
+       BHI     IRQ10
+       JSR     GWLD    GWAVE SOUNDS
+       JSR     GWAVE
+       BRA     IRQ3
+IRQ10  CMPA    #$1B    SPECIAL SOUND?
+       BHI     IRQ20   VARI SOUND
+       SUBA    #$D     SUB OFFSET
+       ASLA            DOUBLE FOR ADDRESSING
+       LDX     #JMPTBL INDEX TO JUMP TABLE
+       BSR     ADDX    GET CORRECT INDEX
+       LDX     0,X     GET ADDRESS TO INDEX
+       JSR     0,X     PERFORM IT
+       BRA     IRQ3
+IRQ20  SUBA    #$1C
+       JSR     VARILD
+       JSR     VARI
+IRQ3   LDAA    BG1FLG  BGROUND ACTIVE?
+       ORAA    BG2FLG
+       BEQ     *       NOPE
+       CLRA
+       STAA    B2FLG   KILL BONUSES
+       LDAA    BG1FLG
+       BEQ     IRQXX
+       JMP     BG1
+IRQXX  JMP     BG2
+*
+* ADD A TO INDEX REGISTER
+*
+ADDX   STX     XPLAY
+       ADDA    XPLAY+1
+       STAA    XPLAY+1
+       BCC     ADDX1
+       INC     XPLAY   
+ADDX1  LDX     XPLAY
+       RTS
+*
+* DIAGNOSTIC PROCESSING HERE
+*
+NMI    SEI
+       LDS     #ENDRAM RESET THE STACK
+       LDX     #$FFFF
+       CLRB
+NMI1   ADCB    0,X
+       DEX
+       CPX     #$F800
+       BNE     NMI1
+       CMPB    0,X
+       BEQ     NMI2
+       WAI
+NMI2   LDAA    #1      
+       JSR     VARILD
+       JSR     VARI
+       LDAB    TALKD   TALKING PRESENT?
+       CMPB    #$7E
+       BNE     NMI
+       JSR     TALKD   
+       BRA     NMI     KEEP LOOPING
+*
+*SPECIAL ROUTINE JUMP TABLE
+*
+JMPTBL FDB     SP1,BG1,BG2INC,LITE
+       FDB     BON2,BGEND,TURBO,APPEAR
+       FDB     THRUST,CANNON,RADIO,HYPER
+       FDB     SCREAM,ORGANT,ORGANN
+*
+*VARI VECTORS
+*
+VVECT  EQU     *
+SAW    FCB     $40,$01,$00,$10,$E1,$00,$80,$FF,$FF
+FOSHIT FCB     $28,$01,$00,$08,$81,$02,$00,$FF,$FF
+QUASAR FCB     $28,$81,$00,$FC,$01,$02,$00,$FC,$FF
+CABSHK FCB     $FF,$01,$00,$18,$41,$04,$80,$00,$FF
+*
+*RADIO SOUND WAVEFORM
+*
+RADSND FCB     $8C,$5B,$B6,$40,$BF,$49,$A4,$73
+       FCB     $73,$A4,$49,$BF,$40,$B6,$5B,$8C
+*
+*ORGAN TUNE TABLE
+*OSCILLATOR MASK(1),DELAY(1),DURATION(2)
+*
+*PHANTOM
+ORGTAB FCB     3*4     
+       FDB     $7F1D,TD/PHANC/2*1      D2 1/4  NOTE
+       FDB     $7F23,TCS/PHANC/2*1     CS2 1/4 NOTE
+       FDB     $FE08,(TFS/PHANC/1*1)*2 FS1 1   NOTE
+*TACCATA
+       FCB     34*4
+       FDB     $3E3F,TA/TACC/8*1       A3 1/16 NOTE
+       FDB     $7C04,TG/TACC/8*1       G2 1/16 NOTE
+       FDB     $3E3F,TA/TACC/2*5       A3 5/4  NOTE
+       FDB     $7C12,TE/TACC/2*1       E2 1/4  NOTE 
+       FDB     $7C0D,TF/TACC/2*1       F2 1/4  NOTE    
+       FDB     $7C23,TCS/TACC/2*1      CS2 1/4 NOTE
+       FDB     $7C1D,TD/TACC/4*7       D2 7/8  NOTE    
+       FDB     $7C3F,TA/TACC/8*1       A2 1/16 NOTE
+       FDB     $F804,TG/TACC/8*1       G1 1/16 NOTE
+       FDB     $7C3F,TA/TACC/2*5       A2 5/4  NOTE
+       FDB     $F812,TE/TACC/2*1       E1 1/4  NOTE 
+       FDB     $F80D,TF/TACC/2*1       F1 1/4  NOTE    
+       FDB     $F823,TCS/TACC/2*1      CS1 1/4 NOTE
+       FDB     $F81D,(TD/TACC/1*1)*2   D1 1    NOTE    
+       FDB     $F823,TCS/TACC/4*1      CS1 1/8 NOTE
+       FDB     $F812,TE/TACC/4*1       E1 1/8  NOTE
+       FDB     $F804,TG/TACC/4*1       G1 1/8  NOTE 
+       FDB     $7C37,TBF/TACC/4*1      BF2 1/8 NOTE 
+       FDB     $7C23,TCS/TACC/4*1      CS2 1/8 NOTE 
+       FDB     $7C12,TE/TACC/4*1       E2 1/8  NOTE 
+       FDB     $3E04,TG/TACC/4*1       G3 1/8  NOTE 
+       FDB     $3E37,TBF/TACC/4*1      BF3 1/8 NOTE 
+       FDB     $3E23,TCS/TACC/4*1      CS3 1/8 NOTE 
+       FDB     $1F12,TE/TACC/4*1       E4 1/8  NOTE 
+       FDB     $1F04,TG/TACC/4*1       G4 1/8  NOTE 
+       FDB     $1F37,TBF/TACC/4*1      BF4 1/8 NOTE 
+       FDB     $1F23,TCS/TACC/1*1      CS4 1/2 NOTE 
+       FDB     $FE1D,TD/TACC/1*1       D1 1/2  NOTE 
+       FDB     $7F37,TBF/TACC/1*1      BF2 1/2 NOTE 
+       FDB     $7F3F,TA/TACC/2*1       A2 1/4  NOTE 
+       FDB     $FE04,TG/TACC/2*1       G1 1/4  NOTE 
+       FDB     $FE0D,TF/TACC/2*1       F1 1/4  NOTE
+       FDB     $FE23,TCS/TACC/2*1      CS1 1/4 NOTE 
+       FDB     $FE1D,(TD/TACC/1*2)*2   D1 2    NOTE 
+       FCB     0        LAST TUNE
+*
+*ORGAN NOTE TABLE
+*SCALE         AF  A   BF  B   C   CS
+NOTTAB FCB     $47,$3F,$37,$30,$29,$23
+*              D   EF  E   F   FS  G
+       FCB     $1D,$17,$12,$0D,$08,$04 
+*
+*WAVE TABLE
+*1ST BYTE= WAVELENGTH
+*
+GWVTAB EQU     *
+GS2    FCB     8,127,217,255,217,127,36,0,36
+GSSQ2  FCB     8,0,64,128,0,255,0,128,64
+GS1    FCB     16,127,176,217,245,255,245,217,176
+       FCB     127,78,36,9,0,9,36,78
+GS12   FCB     16,127,197,236,231,191,141,109,106
+       FCB     127,148,146,113,64,23,18,57
+GSQ22  FCB     16,$FF,$FF,$FF,$FF,0,0,0,0
+       FCB     $FF,$FF,$FF,$FF,0,0,0,0
+GS72   FCB     72,138,149,160,171,181,191,200,209
+       FCB     218,225,232,238,243,247,251,253,254,255
+       FCB     254,253,251,247,243,238,232,225,218
+       FCB     209,200,191,181,171,160,149,138,127
+       FCB     117,106,95,84,74,64,55,46,37,30,23,17,12
+       FCB     8,4,2,1,0
+       FCB     1,2,4,8,12,17,23,30,37,46,55,64,74,84
+       FCB     95,106,117,127
+GS1.7  FCB     16,89,123,152,172,179,172,152,123
+       FCB     89,55,25,6,0,6,25,55
+*
+*GWAVE SOUND VECTOR TABLE
+*VECTOR FORMAT
+*BYTE 0: GECHO,GCCNT
+*BYTE 1: GECDEC,WAVE#
+*BYTE 2: PREDECAY FACTOR
+*BYTE 3: GDFINC
+*BYTE 4: VARIABLE FREQ COUNT
+*BYTE 5: FREQ PATTERN LENGTH
+*BYTE 6: FREQ PATTERN OFFSET
+*
+SVTAB  EQU     *
+HBDV   FCB     $81,$24,0,0,0,22,HBDSND-GFRTAB 1
+STDV   FCB     $12,$05,$1A,$FF,0,39,STDSND-GFRTAB 2
+DP1V   FCB     $11,$05,$11,1,15,1,SWPAT-GFRTAB 3
+XBV    FCB     $11,$31,0,1,0,13,SPNSND-GFRTAB 4
+BBSV   FCB     $F4,$12,$0,0,0,20,BBSND-GFRTAB 5
+HBEV   FCB     $41,$45,0,0,0,15,HBESND-GFRTAB 6
+PROTV  FCB     $21,$35,$11,$FF,0,13,SPNSND-GFRTAB 7
+SPNRV  FCB     $15,$00,0,$FD,0,1,SPNR-GFRTAB 8
+CLDWNV FCB     $31,$11,0,1,0,3,COOLDN-GFRTAB 9
+SV3    FCB     $01,$15,1,1,1,1,BBSND-GFRTAB 10
+ED10   FCB     $F6,$53,3,0,2,6,ED10FP-GFRTAB 11
+ED12   FCB     $6A,$10,2,0,2,6,ED13FP-GFRTAB 12
+ED17   FCB     $1F,$12,0,$FF,$10,4,SPNR-GFRTAB 13
+BONV   FCB     $31,$11,0,$FF,0,13,BONSND-GFRTAB
+TRBV   FCB     $12,$06,$0,$FF,1,9,TRBPAT-GFRTAB
+*
+*GWAVE FREQ PATTERN TABLE
+*
+GFRTAB EQU     *
+*BONUS SOUND
+BONSND FCB     $A0,$98,$90,$88,$80,$78,$70,$68
+       FCB     $60,$58,$50,$44,$40
+*HUNDRED POINT SOUND
+HBTSND FCB     1,1,2,2,4,4,8,8,$10,$10,$30,$60,$C0,$E0
+*SPINNER SOUND
+SPNSND FCB     1,1,2,2,3,4,5,6,7,8,9,$A,$C
+*TURBINE START UP
+TRBPAT FCB     $80,$7C,$78,$74,$70,$74,$78,$7C,$80
+*HEARTBEAT DISTORTO
+HBDSND FCB     1,1,2,2,4,4,8,8,$10,$20,$28
+       FCB     $30,$38,$40,$48,$50,$60,$70,$80,$A0,$B0,$C0
+*SWEEP PATTERN
+SWPAT  EQU     *
+*BIGBEN SOUNDS
+BBSND  FCB     8,64,8,64,8,64,8,64,8,64
+       FCB     8,64,8,64,8,64,8,64,8,64
+*HEARTBEAT ECHO
+HBESND FCB     1,2,4,8,9,$A,$B,$C,$E,$F,$10
+       FCB     $12,$14,$16
+*SPINNER SOUND "DRIP"
+SPNR   FCB     $40
+*COOL DOWNER
+COOLDN FCB     $10,8,1
+*START DISTORTO SOUND
+STDSND FCB     1,1,1,1,2,2,3,3,4,4,5,6,8,$A,$C,$10
+       FCB     $14,$18,$20,$30,$40,$50,$40,$30
+       FCB     $20,$10,$C,$A,8,7,6,5,4,3,2,2,1,1,1
+*ED'S SOUND 10
+ED10FP FCB     7,8,9,$A,$C,8
+*ED'S SOUND 13
+ED13FP FCB     $17,$18,$19,$1A,$1B,$1C
+       FCB     $0,$0,$0        MATCH THE PROMS 
+*
+* VECTORS HERE
+*
+       ORG     VECTOR
+IRQV   FDB     IRQ
+SWIV   FDB     SETUP
+NMIV   FDB     NMI
+RESETV FDB     SETUP
+       END     CKSUM