CON
  L_PIN = 32
  R_PIN = 31

CON
  _XTALFREQ     = 20_000_000                                    ' crystal frequency
  _XDIV         = 4             '\                              '\ crystal divider                      to give 5.0MHz
  _XMUL         = 72            '| 180MHz                       '| crystal / div * mul                  to give 360MHz
  _XDIVP        = 2             '/                              '/ crystal / div * mul /divp            to give 180MHz
  _XOSC         = %01                                   'OSC    ' %00=OFF, %01=OSC, %10=15pF, %11=30pF
  _XSEL         = %11                                   'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms)
  _XPPPP        = ((_XDIVP>>1) + 15) & $F                       ' 1->15, 2->0, 4->1, 6->2...30->14
  _CLOCKFREQ    = _XTALFREQ / _XDIV * _XMUL / _XDIVP            ' internal clock frequency                
  _SETFREQ      = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2  ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00  ' setup  oscillator
  _ENAFREQ      = _SETFREQ + _XSEL                                             ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss  ' enable oscillator


DAT
        orgh 0
        org
'-----------------------------------------------------------
'      Configure oscillator for 180 MHz operation
'-----------------------------------------------------------
        hubset  #0                                    ' Set 20MHz+ mode
        hubset  ##_SETFREQ                            ' Setup oscillator
        waitx   ##20_000_000/100                      ' ~10ms
        hubset  ##_ENAFREQ                            ' Enable oscillator

'-----------------------------------------------------------
'                  Start SIDcog in cog 2
'-----------------------------------------------------------
        coginit #3, #@SIDEMU 

'-----------------------------------------------------------
'             Start to dump register data at 50 Hz
'-----------------------------------------------------------
        mov     dumpPtr, ##@dumpFile

.justLoop

        mov     sidRegisterPtr, ##@ch1_frequencyLo

        ' Read 7 bytes of channel 1 data from memory and write it to the corresponding emulated SID register
        rep     #4, #7
        rdbyte  tempData, dumpPtr
        wrbyte  tempData, sidRegisterPtr
        add     dumpPtr, #1
        add     sidRegisterPtr, #1

        ' Handle SIDcog register alignment between channel 1 and 2
        add     sidRegisterPtr, #1

        ' Read 7 bytes of channel 2 data from memory and write it to the corresponding emulated SID register
        rep     #4, #7
        rdbyte  tempData, dumpPtr
        wrbyte  tempData, sidRegisterPtr
        add     dumpPtr, #1
        add     sidRegisterPtr, #1

        ' Handle SIDcog register alignment between channel 2 and 3
        add     sidRegisterPtr, #1

        ' Read 7 bytes of channel 3 data from memory and write it to the corresponding emulated SID register
        rep     #4, #7
        rdbyte  tempData, dumpPtr
        wrbyte  tempData, sidRegisterPtr
        add     dumpPtr, #1
        add     sidRegisterPtr, #1

        ' Handle SIDcog register alignment between channel 3 and the filter/mixer/volume register
        add     sidRegisterPtr, #1

        ' Read 4 bytes of filter/mixer/volume from memory and write it to the corresponding emulated SID register
        rep     #4, #4
        rdbyte  tempData, dumpPtr
        wrbyte  tempData, sidRegisterPtr
        add     dumpPtr, #1
        add     sidRegisterPtr, #1

        waitx   ##180_000_000 / 50 ' 50 Hz wait
        jmp #.justLoop             ' Loop and read register updates for the next 50 Hz frame
'-----------------------------------------------------------


dumpPtr         long 0
sidRegisterPtr  long 0
tempData        long 0














{
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%              SIDcog - SID/MOS8580 emulator v1.3 P2 experimental (C) 2019 Johannes Ahlebrand                                  %                                                            
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$%
%                                    TERMS OF USE: Parallax Object Exchange License                                            %                                                            
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$%
%Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    % 
%files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    %
%modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software%
%is furnished to do so, subject to the following conditions:                                                                   %
%                                                                                                                              %
%The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.%
%                                                                                                                              %
%THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          %
%WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         %
%COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   %
%ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Revision History

v0.7 (December 2009)   - Initial release

v0.8 (February 2010)   - Added support for "combined waveforms"
                       - Optimized code
                       - Fixed bugs

v1.0 (May 2011)        - First OBEX release
                       - Added convenient API methods

v1.2 (August 2011)     - Increased ADSR accuracy  (Almost perfect now; The famous ADSR bug isn't implemented though)
                       - Increased Noise accuracy (As close as we will get without decreasing the sample rate of SIDcog)
                       - Fixed a bug when no waveform was selected
                       - Decreased the "max cutoff frequency" a bit to fix aliasing issues
                       - Made some small optimizations 

v1.3 (April 2012)      - Fixed a bug when noise + any other waveform was selected at the same time
                       - Calibrated the cutoff frequency to better match a real 8580
                       - Cycle optimized code to "make room" for the point below ¢ð
                       - Increased resonance accuracy (replaced "4 step logaritmic lookup table" with "16 step bit linear multiplication")
                       - Increased ADSR accuracy a little bit more (the ADSR bug is still not implemented)

v1.3.P2 (Januari 2019) - "Tweeked" the SIDcog v1.3 P1 code to run as unmodified as possible on the P2
                       - NO improvements regarding audio quality or accuracy (still 31.25 kHz sample rate)
                       - NO improvements of using more optimized P2 instructions or LUT RAM or anything
                       - Still uses a subroutine for multiplication (that ate around half the cycles each sample on the P1)

v1.3.E1 (Januari 2019) - SIDcog now runs at a sample rate of ~250 kHz on a 80 MHz P2 (8 times higher than before) thanks to the points below
                       - Changed multiplication to hardware instructions
                       - Changed shift/mask instruction to getnib, getword, getbyte
                       - Changed hub access to fast "burst" mode by reading everything at once to cog memory

}

CON  PAL = 985248.0, NTSC = 1022727.0, MAXF = 1031000.0, TRIANGLE = 16, SAW = 32, SQUARE = 64, NOISE = 128   

  C64_CLOCK_FREQ   = PAL
  '                                  ___ 
  RESONANCE_OFFSET = 7'                 %
  RESONANCE_FACTOR = 5'                 %
  'CUTOFF_LIMIT    = 1100'              %
  LP_MAX_CUTOFF    = 14'                % Don't alter these constants unless you know what you are doing! 
  BP_MAX_CUTOFF    = 12'                %
  FILTER_OFFSET    = 32'                %
  START_LOG_LEVEL  = $5d5d5d5d'         %
  DECAY_DIVIDE_REF = $6C6C6C6C'         %   
  ENV_CAL_FACTOR   = 545014038.181330/8.0'  % ENV_CAL_FACTOR = (MaxUint32  / SIDcogSampleFreq) / (1 / SidADSR_1secRomValue)   
  NOISE_ADD        = %1010_1010_101<<23'%     ENV_CAL_FACTOR = (4294967295 / 30789           ) / (1 / 3907                ) = 545014038,181330
  NOISE_TAP        = %100001 << 8'   ___%

  'DAC_MODE             = 0
  'DAC_MODE             = %00001_0 ' DAC 8-bit noise
  'DAC_MODE             = %00010_0 ' DAC 16-bit dither, noise
  DAC_MODE             = %00011_0 ' DAC 16-bit dither, PWM
  DIR_MODE             = %01      ' Output enabled, overrides DIR
  INIT_8BIT_DAC_VALUE  = 128
  'ANALOG_OUT_MODE      = %10100 ' 990 ohm, 3.3V DAC mode
  ANALOG_OUT_MODE      = %10101 ' 600 ohm, 2.0V DAC mode
  'ANALOG_OUT_MODE      = %10110 ' 123 ohm, 3.3V DAC mode
  'ANALOG_OUT_MODE      = %10111 '  75 ohm, 2.0V DAC mode
  SMARTPIN_DAC_MODE    = (ANALOG_OUT_MODE << 16) | (INIT_8BIT_DAC_VALUE << 8) | (DIR_MODE << 6) | DAC_MODE
  'SAMPLE_PERIOD        = 190_000_000 / (32_250 * 8)  'clocks between samples ( ~31.250 khz )
  SAMPLE_PERIOD        = 180_000_000 / trunc(C64_CLOCK_FREQ / 4.0)  'clocks between samples 

DAT org
'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
'                Assembly SID emulator                      
'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
SIDEMU

' Configure audio output, left and right
              wrpin   smartConfigAudioDAC, #L_PIN           ' Config smartpin DAC mode on left pin
              wrpin   smartConfigAudioDAC, #R_PIN           ' Config smartpin DAC mode on right pin
              wxpin   samplePeriod, #L_PIN                  ' Sample period for left audio channel
              wxpin   samplePeriod, #R_PIN                  ' Sample period for right audio channel
              dirh    #L_PIN                                ' Enable smartpin DAC mode on left pin
              dirh    #R_PIN                                ' Enable smartpin DAC mode on right pin
              setse1  #%001_100000 '| L_PIN                 ' Event triggered every new sample period (when "left in pin rises")

'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
' Read all SID-registers from hub memory and convert
' them to more convenient representations.
'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
getRegisters  setq      #7-1                                ' Number of longs, minus 1, to read
              rdlong    sidRegsCogCopy, par                 ' Read 6 longs to cog address
              getword   frequency1, sidRegsCogCopy, #0
              getword   pulseWidth1, sidRegsCogCopy, #1
              shl       pulseWidth1, #20                    ' Shift in "12 bit" pulse width value( make it 32 bits )
              shl       frequency1, #10
'-----------------------------------------------------------
              getnib    selectedWaveform1, sidRegsCogCopy + 1, #1
              mov       controlRegister1, sidRegsCogCopy + 1
'-----------------------------------------------------------
              getnib    r1, sidRegsCogCopy + 1, #2
              alts      r1, #ADSRTable
              mov       decay1, 0
              getnib    r1, sidRegsCogCopy + 1, #3
              alts      r1, #ADSRTable                      '|  Convert 4bit ADSR "presets" to their corresponding
              mov       attack1, 0                          '|  32bit values using the attack/decay table.
              getnib    r1, sidRegsCogCopy + 1, #4
              alts      r1, #ADSRTable
              mov       release1, 0
              getnib    r1, sidRegsCogCopy + 1, #5
              setnib    sustain1, r1, #7
              setnib    sustain1, r1, #6
'-----------------------------------------------------------
              test      controlRegister1, #1            wc
              cmp       envelopeState1, #2              wz
 if_z_and_c   mov       envelopeState1, #0
 if_nz_and_nc mov       envelopeState1, #2

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                        Channel 2  
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
              getword   frequency2, sidRegsCogCopy + 2, #0
              getword   pulseWidth2, sidRegsCogCopy + 2, #1
              shl       pulseWidth2, #20                    ' Shift in "12 bit" pulse width value( make it 32 bits )
              shl       frequency2, #10
'----------------------------------------------------------- 
              getnib    selectedWaveform2, sidRegsCogCopy + 3, #1
              mov       controlRegister2,  sidRegsCogCopy + 3
'----------------------------------------------------------- 
              getnib    r1, sidRegsCogCopy + 3, #2
              alts      r1, #ADSRTable
              mov       decay2, 0
              getnib    r1, sidRegsCogCopy + 3, #3
              alts      r1, #ADSRTable                      '|  Convert 4bit ADSR "presets" to their corresponding
              mov       attack2, 0                          '|  32bit values using attack/decay tables. 
              getnib    r1, sidRegsCogCopy + 3, #4
              alts      r1, #ADSRTable
              mov       release2, 0
              getnib    r1, sidRegsCogCopy + 3, #5
              setnib    sustain2, r1, #7
              setnib    sustain2, r1, #6
'----------------------------------------------------------- 
              test      controlRegister2, #1            wc
              cmp       envelopeState2, #2              wz
 if_z_and_c   mov       envelopeState2, #0
 if_nz_and_nc mov       envelopeState2, #2           

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                        Channel 3
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
              getword   frequency3, sidRegsCogCopy + 4, #0
              getword   pulseWidth3, sidRegsCogCopy + 4, #1
              shl       pulseWidth3, #20                    ' Shift in "12 bit" pulse width value( make it 32 bits )
              shl       frequency3, #10
'-----------------------------------------------------------
              getnib    selectedWaveform3, sidRegsCogCopy + 5, #1
              mov       controlRegister3,  sidRegsCogCopy + 5
'-----------------------------------------------------------
              getnib     r1, sidRegsCogCopy + 5, #2
              alts       r1, #ADSRTable
              mov        decay3, 0
              getnib     r1, sidRegsCogCopy + 5, #3
              alts       r1, #ADSRTable                      '|  Convert 4bit ADSR "presets" to their corresponding
              mov        attack3, 0                          '|  32bit values using attack/decay tables.    
              getnib     r1, sidRegsCogCopy + 5, #4
              alts       r1, #ADSRTable
              mov        release3, 0
              getnib     r1, sidRegsCogCopy + 5, #5
              setnib     sustain3, r1, #7
              setnib     sustain3, r1, #6
'-----------------------------------------------------------
              test      controlRegister3, #1            wc
              cmp       envelopeState3, #2              wz
 if_z_and_c   mov       envelopeState3, #0
 if_nz_and_nc mov       envelopeState3, #2

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                      Filter / Volume
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
              getword   filterControl, sidRegsCogCopy + 6, #1     '|  Filter control        
              getbyte   filterCutoff, sidRegsCogCopy + 6, #1      '|  Filter cutoff frequency
              shl       filterCutoff, #3
              add       filterCutoff, filterOffset
              getnib    filterMode_Volume, sidRegsCogCopy + 6, #7 '|  Main volume and filter mode
              getnib    filterResonance, sidRegsCogCopy + 6, #6

'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
' Calculate sid samples channel 1-3 and store in out1-out3 
'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
'    Increment phase accumulator 1-3 and handle syncing
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
SID           add      phaseAccumulator1, frequency1    wc ' Add frequency value to phase accumulator 1
  if_nc       andn     controlRegister2, #2
              test     controlRegister2, #10            wz ' Sync oscilator 2 to oscillator 1 if sync = on 
  if_nz       mov      phaseAccumulator2, #0               ' Or reset oscilator 2 when bit 4 of control register is 1
'-----------------------------------------------------------      
              add      phaseAccumulator2, frequency2    wc
  if_nc       andn     controlRegister3, #2
              test     controlRegister3, #10            wz ' Sync oscilator 3 to oscillator 2 if sync = on 
  if_nz       mov      phaseAccumulator3, #0               ' Or reset oscilator 3 when bit 4 of control register is 1
'-----------------------------------------------------------
              add      phaseAccumulator3, frequency3    wc
  if_nc       andn     controlRegister1, #2
              test     controlRegister1, #10            wz ' Sync oscilator 1 to oscillator 3 if sync = on 
  if_nz       mov      phaseAccumulator1, #0               ' Or reset oscilator 1 when bit 4 of control register is 1

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'            Waveform shaping channel 1 -> arg1
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Saw1          cmp      selectedWaveform1, #2            wz
              mov      arg1, phaseAccumulator1
  if_z        jmp      #Envelope1
'-----------------------------------------------------------
Triangle1     cmp      selectedWaveform1, #1            wcz
  if_nz       jmp      #Square1
              shl      arg1, #1                         wc
  if_c        xor      arg1, mask32bit
              test     controlRegister1, #4             wz '|
  if_nz       test     phaseAccumulator3, val31bit      wz '| These 3 lines handles ring modulation
  if_nz       xor      arg1, mask32bit                     '|
              jmp      #Envelope1
'-----------------------------------------------------------
Square1       cmp      selectedWaveform1, #4            wz
  if_z        sub      pulseWidth1, phaseAccumulator1   wc
  if_z        muxc     arg1, mask32bit
  if_z        jmp      #Envelope1
'-----------------------------------------------------------
Noise1        cmp      selectedWaveform1, #8            wz
  if_nz       jmp      #Combined1
              and      arg1, mask28bit
              sub      arg1, frequency1                 wc
              mov      arg1, noiseValue1
              add      arg1, noiseAddValue
  if_nc       jmp      #Envelope1
              test     noiseValue1, noiseTap            wc
              rcr      noiseValue1, #1
              jmp      #Envelope1
'-----------------------------------------------------------                
Combined1     test     selectedWaveform1, #8            wz
              sub      selectedWaveform1, #4             
              fges     selectedWaveform1, #0         
              shl      selectedWaveform1, #8
              mov      tempValue, phaseAccumulator1
              shr      tempValue, #24
              add      selectedWaveform1, tempValue
              add      selectedWaveform1, combTableAddr
  if_nc_and_z rdbyte   arg1, selectedWaveform1
  if_nc_and_z shl      arg1, #24
  if_c_or_nz  mov      arg1, val31bit

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
'            Envelope shaping channel 1 -> arg2           
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
Envelope1     mov      tempValue, decayDivideRef
              shr      tempValue, decayDivide1
              cmp      envelopeLevel1, tempValue        wc
              tjnz     envelopeState1, #Env_Dec1
'----------------------------------------------------------- 
Env_At1 if_nc cmpsub   decayDivide1, #1    
              add      envelopeLevel1, attack1          wc
  if_c        mov      envelopeLevel1, mask32bit         
  if_c        mov      envelopeState1, #1
              jmp      #Amplitude1
'----------------------------------------------------------- 
Env_Dec1 if_c add      decayDivide1, #1
              cmp      startLogLevel, envelopeLevel1    wc 
              cmp      envelopeState1, #1               wz
  if_nz       jmp      #Rel1
  if_nc       shr      decay1, decayDivide1  
              sub      envelopeLevel1, decay1
              fge      envelopeLevel1, sustain1         wc
              jmp      #Amplitude1
'----------------------------------------------------------- 
Rel1 if_nc    shr      release1, decayDivide1  
              cmpsub   envelopeLevel1, release1

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
'Calculate sample out1 = arg1 * arg2 (waveform * amplitude)    
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Amplitude1    shr      arg1, #14
              sub      arg1, val15bit             
              mov      arg2, envelopeLevel1     
              shr      arg2, #24
              call     #multiply
              mov      out1, r1

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
'            Waveform shaping channel 2 -> arg1                           
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Saw2          cmp      selectedWaveform2, #2            wz
              mov      arg1, phaseAccumulator2
  if_z        jmp      #Envelope2   
'----------------------------------------------------------- 
Triangle2     cmp      selectedWaveform2, #1            wcz
  if_nz       jmp      #Square2
              shl      arg1, #1                         wc
  if_c        xor      arg1, mask32bit
              test     controlRegister2, #4             wz '|
  if_nz       test     phaseAccumulator1, val31bit      wz '| These 3 lines handles ring modulation
  if_nz       xor      arg1, mask32bit                     '|
              jmp      #Envelope2   
'-----------------------------------------------------------  
Square2       cmp      selectedWaveform2, #4            wz
  if_z        sub      pulseWidth2, phaseAccumulator2   wc ' C holds the pulse width modulated square wave  
  if_z        muxc     arg1, mask32bit              
  if_z        jmp      #Envelope2   
'----------------------------------------------------------- 
Noise2        cmp      selectedWaveform2, #8            wz
  if_nz       jmp      #Combined2
              and      arg1, mask28bit
              sub      arg1, frequency2                 wc
              mov      arg1, noiseValue2
              add      arg1, noiseAddValue
  if_nc       jmp      #Envelope2 
              test     noiseValue2, noiseTap            wc
              rcr      noiseValue2, #1
              jmp      #Envelope2
'-----------------------------------------------------------                
Combined2     test     selectedWaveform2, #8            wz
              sub      selectedWaveform2, #4
              fges     selectedWaveform2, #0     
              shl      selectedWaveform2, #8
              mov      tempValue, phaseAccumulator2
              shr      tempValue, #24
              add      selectedWaveform2, tempValue
              add      selectedWaveform2, combTableAddr    
  if_nc_and_z rdbyte   arg1, selectedWaveform2
  if_nc_and_z shl      arg1, #24                         
  if_c_or_nz  mov      arg1, val31bit

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
'            Envelope shaping channel 2 -> arg2           
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Envelope2     mov      tempValue, decayDivideRef
              shr      tempValue, decayDivide2
              cmp      envelopeLevel2, tempValue        wc
              tjnz     envelopeState2, #Env_Dec2
'----------------------------------------------------------- 
Env_At2 if_nc cmpsub   decayDivide2, #1                    
              add      envelopeLevel2, attack2          wc
  if_c        mov      envelopeLevel2, mask32bit         
  if_c        mov      envelopeState2, #1
              jmp      #Amplitude2
'----------------------------------------------------------- 
Env_Dec2 if_c add      decayDivide2, #1    
              cmp      startLogLevel,envelopeLevel2     wc   
              cmp      envelopeState2, #1               wz
  if_nz       jmp      #Rel2 
  if_nc       shr      decay2, decayDivide2  
              sub      envelopeLevel2, decay2
              fge      envelopeLevel2, sustain2         wc
              jmp      #Amplitude2
'-----------------------------------------------------------   
Rel2 if_nc    shr      release2, decayDivide2  
              cmpsub   envelopeLevel2, release2

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Calculate sample out2 = arg1 * arg2 (waveform * amplitude)     
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Amplitude2    shr      arg1, #14
              sub      arg1, val17bit
              mov      arg2, envelopeLevel2
              shr      arg2, #24
              call     #multiply
              mov      out2, r1

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%              
'            Waveform shaping channel 3 -> arg1                           
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Saw3          cmp      selectedWaveform3, #2            wz
              mov      arg1, phaseAccumulator3
  if_z        jmp      #Envelope3   
'----------------------------------------------------------- 
Triangle3     cmp      selectedWaveform3, #1            wcz
  if_nz       jmp      #Square3
              shl      arg1, #1                         wc
  if_c        xor      arg1, mask32bit
              test     controlRegister3, #4             wz '|
  if_nz       test     phaseAccumulator2, val31bit      wz '| These 3 lines handles ring modulation 
  if_nz       xor      arg1, mask32bit                     '|
              jmp      #Envelope3   
'-----------------------------------------------------------  
Square3       cmp      selectedWaveform3, #4            wz
  if_z        sub      pulseWidth3, phaseAccumulator3   wc ' C holds the pulse width modulated square wave  
  if_z        muxc     arg1, mask32bit                   
  if_z        jmp      #Envelope3 
'----------------------------------------------------------- 
Noise3        cmp      selectedWaveform3, #8            wz 
  if_nz       jmp      #Combined3  
              and      arg1, mask28bit
              sub      arg1, frequency3                 wc
              mov      arg1, noiseValue3
              add      arg1, noiseAddValue
  if_nc       jmp      #Envelope3 
              test     noiseValue3, noiseTap            wc 
              rcr      noiseValue3, #1 
              jmp      #Envelope3
'-----------------------------------------------------------
Combined3     test     selectedWaveform3, #8            wz
              sub      selectedWaveform3, #4             
              fges     selectedWaveform3, #0
              shl      selectedWaveform3, #8
              mov      tempValue, phaseAccumulator3
              shr      tempValue, #24
              add      selectedWaveform3, tempValue
              add      selectedWaveform3, combTableAddr    
  if_nc_and_z rdbyte   arg1, selectedWaveform3
  if_nc_and_z shl      arg1, #24                         
  if_c_or_nz  mov      arg1, val31bit

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'            Envelope shaping channel 3 -> arg2           
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Envelope3     mov      tempValue, decayDivideRef           
              shr      tempValue, decayDivide3             
              cmp      envelopeLevel3, tempValue        wc 
              tjnz     envelopeState3, #Env_Dec3
'----------------------------------------------------------- 
Env_At3 if_nc cmpsub   decayDivide3, #1                    
              add      envelopeLevel3, attack3          wc 
  if_c        mov      envelopeLevel3, mask32bit           
  if_c        mov      envelopeState3, #1                  
              jmp      #Amplitude3                         
'----------------------------------------------------------- 
Env_Dec3 if_c add      decayDivide3, #1                    
              cmp      startLogLevel, envelopeLevel3    wc   
              cmp      envelopeState3, #1               wz 
  if_nz       jmp      #Rel3                       
  if_nc       shr      decay3, decayDivide3                
              sub      envelopeLevel3, decay3              
              fge      envelopeLevel3, sustain3         wc
              jmp      #Amplitude3                         
'-----------------------------------------------------------  
Rel3 if_nc    shr      release3, decayDivide3              
              cmpsub   envelopeLevel3, release3            

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Calculate sample out3 = arg1 * arg2 (waveform * amplitude)     
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Amplitude3    shr      arg1, #14
              sub      arg1, val17bit            
              mov      arg2, envelopeLevel3
              shr      arg2, #24
              call     #multiply
              mov      out3, r1

'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð 
'              Handle multi-mode filtering 
'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
filter        mov      ordinaryOutput, #0                  '|
              mov      highPassFilter, #0                  '|
              test     filterControl, #1                wc '|
  if_c        add      highPassFilter, out1                '|
  if_nc       add      ordinaryOutput, out1                '|
              test     filterControl, #2                wc '| Route channels trough the filter
  if_c        add      highPassFilter, out2                '| or bypass them
  if_nc       add      ordinaryOutput, out2                '|  
              test     filterControl, #4                wc '|
  if_c        add      highPassFilter, out3                '|
  if_nc       add      ordinaryOutput, out3                '|  
'-----------------------------------------------------------
              mov      arg2, filterResonance               '|
              add      arg2, #RESONANCE_OFFSET             '|
              mov      arg1, bandPassFilter                '|  
              sar      arg1, #RESONANCE_FACTOR             '|
              call     #multiply                           '| High pass filter
              sub      highPassFilter, bandPassFilter      '|
              add      highPassFilter, r1                  '| 
              sub      highPassFilter, lowPassFilter       '|
'----------------------------------------------------------- 
              mov      arg1, highPassFilter                '|
              sar      arg1, #BP_MAX_CUTOFF                '|
              mov      arg2, filterCutoff                  '| Band pass filter
              'fle      arg2, maxCutoff                     '|
              call     #multiply                           '|
              add      bandPassFilter, r1                  '|
'----------------------------------------------------------- 
              mov      arg1, bandPassFilter                '| 
              sar      arg1, #LP_MAX_CUTOFF                '| 
              mov      arg2, filterCutoff                  '| Low pass filter 
              call     #multiply                           '| 
              add      lowPassFilter, r1                   '| 
'-----------------------------------------------------------  
              mov      filterOutput, #0                    '|
              test     filterMode_Volume, #1            wc '|
  if_c        add      filterOutput, lowPassFilter         '|
              test     filterMode_Volume, #2            wc '| Enable/Disable
  if_c        add      filterOutput, bandPassFilter        '| Low/Band/High pass filtering
              test     filterMode_Volume, #4            wc '|
  if_c        add      filterOutput, highPassFilter        '|

'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð 
'      Mix channels and update FRQA/FRQB PWM-values
'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
mixer         mov      arg1, filterOutput
              add      arg1, ordinaryOutput
'-----------------------------------------------------------
              fles     arg1, clipLevelHigh                 '|
              fges     arg1, clipLevelLow                  '|
              getnib   arg2, sidRegsCogCopy + 6, #6
              call     #multiply                           '|
'-----------------------------------------------------------
              add      r1, val31bit                        '  DC offset
'-----------------------------------------------------------  
              shr      r1, #16 
              wypin    r1, #L_PIN                          ' Output sample on left channel
              wypin    r1, #R_PIN                          ' Output sample on right channel
              waitse1
'-----------------------------------------------------------  
              mov      tempValue, par
              add      tempValue, #28
              wrlong   r1, tempValue                       '| Write the sample to hub ram
              jmp      #getRegisters

'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð 
'    Multiplication     r1(I32) = arg1(I32) * arg2(I32)
'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
multiply      mov        r1, arg1
              sar        r1, #16
              'getnib     r1, arg1, #1
              mul        r1, arg2
              shl        r1, #16
              mul        arg1, arg2
              add        r1, arg1
multiply_ret  ret

'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð 
'    Variables, tables, masks and reference values
'‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð‹ð
ADSRTable           long trunc(ENV_CAL_FACTOR * (1.0 / 9.0    )) '2   ms   
                    long trunc(ENV_CAL_FACTOR * (1.0 / 32.0   )) '8   ms        
                    long trunc(ENV_CAL_FACTOR * (1.0 / 63.0   )) '16  ms     
                    long trunc(ENV_CAL_FACTOR * (1.0 / 95.0   )) '24  ms        
                    long trunc(ENV_CAL_FACTOR * (1.0 / 149.0  )) '38  ms       
                    long trunc(ENV_CAL_FACTOR * (1.0 / 220.0  )) '56  ms           
                    long trunc(ENV_CAL_FACTOR * (1.0 / 267.0  )) '68  ms         
                    long trunc(ENV_CAL_FACTOR * (1.0 / 313.0  )) '80  ms      
                    long trunc(ENV_CAL_FACTOR * (1.0 / 392.0  )) '100 ms            
                    long trunc(ENV_CAL_FACTOR * (1.0 / 977.0  )) '250 ms      
                    long trunc(ENV_CAL_FACTOR * (1.0 / 1954.0 )) '500 ms        
                    long trunc(ENV_CAL_FACTOR * (1.0 / 3126.0 )) '800 ms          
                    long trunc(ENV_CAL_FACTOR * (1.0 / 3907.0 )) '1   s       
                    long trunc(ENV_CAL_FACTOR * (1.0 / 11720.0)) '3   s         
                    long trunc(ENV_CAL_FACTOR * (1.0 / 19532.0)) '5   s          
                    long trunc(ENV_CAL_FACTOR * (1.0 / 31251.0)) '8   s              

'Masks and reference values
startLogLevel       long START_LOG_LEVEL
sustainAdd          long $0f000000
mask32bit           long $ffffffff
mask31bit           long $7fffffff
mask28bit           long $fffffff
mask24bit           long $ffffff
mask20bit           long $fffff
mask16bit           long $ffff
mask11bit           long $7ff
val31bit            long $80000000
val28bit            long $10000000
val27bit            long $8000000
val17bit            long $20000
val16bit            long $10000
val15bit            long $8000
clipLevelHigh       long $8000000
clipLevelLow        long-$8000000
filterOffset        long FILTER_OFFSET
decayDivideRef      long DECAY_DIVIDE_REF
'maxCutoff           long CUTOFF_LIMIT
combTableAddr       long $1000
par                 long @ch1_frequencyLo
lpin                long 1 << L_PIN
rpin                long 1 << R_PIN
samplePeriod        long SAMPLE_PERIOD                 'clocks between samples ( ~31.250 khz )
smartConfigAudioDAC long SMARTPIN_DAC_MODE

'Setup and subroutine parameters
arg1                long 1
arg2                long 1
r1                  long 1

'Sid variables
noiseAddValue       long NOISE_ADD
noiseTap            long NOISE_TAP
noiseValue1         long $ffffff
noiseValue2         long $ffffff
noiseValue3         long $ffffff
decayDivide1        long 0
decayDivide2        long 0
decayDivide3        long 0
envelopeLevel1      res  1 
envelopeLevel2      res  1 
envelopeLevel3      res  1 
controlRegister1    res  1 
controlRegister2    res  1
controlRegister3    res  1
frequency1          res  1
frequency2          res  1
frequency3          res  1 
phaseAccumulator1   res  1
phaseAccumulator2   res  1
phaseAccumulator3   res  1
pulseWidth1         res  1 
pulseWidth2         res  1
pulseWidth3         res  1
selectedWaveform1   res  1
selectedWaveform2   res  1
selectedWaveform3   res  1 
envelopeState1      res  1
envelopeState2      res  1
envelopeState3      res  1
attack1             res  1
attack2             res  1
attack3             res  1 
decay1              res  1
decay2              res  1
decay3              res  1 
sustain1            res  1
sustain2            res  1
sustain3            res  1 
release1            res  1
release2            res  1
release3            res  1
out1                res  1
out2                res  1
out3                res  1
filterResonance     res  1
filterCutoff        res  1
highPassFilter      res  1
bandPassFilter      res  1 
lowPassFilter       res  1
filterMode_Volume   res  1
filterControl       res  1
filterOutput        res  1
ordinaryOutput      res  1

'Working variables
waitCounter         res  1
tempValue           res  1
sidRegsCogCopy      res  7
                    fit                          

DAT orgh            $1000
combinedWaveforms   file "CombinedWaveforms.bin"

DAT orgh
  ch1_frequencyLo        byte 0    
  ch1_frequencyHi        byte 0    
  ch1_pulseWidthLo       byte 0    
  ch1_pulseWidthHi       byte 0    
  ch1_controlRegister    byte 0    
  ch1_attackDecay        byte 0    
  ch1_sustainRelease     byte 0    
  ch1_dummy              byte 0    
  ch2_frequencyLo        byte 0    
  ch2_frequencyHi        byte 0    
  ch2_pulseWidthLo       byte 0    
  ch2_pulseWidthHi       byte 0    
  ch2_controlRegister    byte 0    
  ch2_attackDecay        byte 0    
  ch2_sustainRelease     byte 0
  ch2_dummy              byte 0
  ch3_frequencyLo        byte 0
  ch3_frequencyHi        byte 0
  ch3_pulseWidthLo       byte 0
  ch3_pulseWidthHi       byte 0
  ch3_controlRegister    byte 0
  ch3_attackDecay        byte 0
  ch3_sustainRelease     byte 0
  ch3_dummy              byte 0
  Filter1                byte 0
  Filter2                byte 0
  Filter3                byte 0
  Volume                 byte 0
  oldVolume              byte 0    
  SIDSample long 0


DAT orgh   

dumpFile            file "Last_Ninja_3.dmp"
'dumpFile            file "Mr_Marvellous.dmp"
'dumpFile            file "Russian.dmp"
'dumpFile            file "Foundations.dmp"
'dumpFile            file "Fly_Around_the_World.dmp"
'dumpFile            file "Lost_Friend.dmp"

'dumpFile            file "Last_Ninja2.dmp"
'dumpFile            file "Krakout2.dmp"
'dumpFile            file "Comic_Bakery.dmp"
'dumpFile            file "Commando.dmp"
'dumpFile            file "Ocean_Loader_2.dmp"
'dumpFile            file "Ocean_Loader_5.dmp"
'dumpFile            file "International_Karate.dmp"
'dumpFile            file "Monty_on_the_Run.dmp"
'dumpFile            file "Auf_Wiedersehen_Monty.dmp"
'dumpFile            file "CrazyComet.dmp"

'dumpFile            file "Batman_The_Movie.dmp"
'dumpFile            file "Batman_The_Movie2.dmp"
'dumpFile            file "Batman_The_Movie4.dmp"
'dumpFile            file "Batman_The_Movie6.dmp"
'dumpFile            file "Chimera.dmp"
'dumpFile            file "Cobra.dmp"
'dumpFile            file "Delta.dmp"
'dumpFile            file "Dragons_Legend.dmp"
'dumpFile            file "Flimbos_Quest.dmp"
'dumpFile            file "Eleminator.dmp"
'dumpFile            file "Gauntlet_III.dmp"
'dumpFile            file "Geir_Tjelta-11.dmp"
'dumpFile            file "Ghouls_n_Ghosts.dmp"
'dumpFile            file "Ghouls_n_Ghosts.dmp"

'dumpFile            file "Lambada2.dmp"
'dumpFile            file "OutrunRemix.dmp"
'dumpFile            file "Ghostbusters.dmp"
'dumpFile            file "Jabdah.dmp"
'dumpFile            file "Sagyrs_Castle.dmp"
'dumpFile            file "Autumn_Symphony.dmp"
