
 1000  *SAVE S.PROFILER
 1010  *--------------------------------
 1020  A2L    .EQ $3E
 1030  A2H    .EQ $3F
 1040  A3L    .EQ $40
 1050  A3H    .EQ $41
 1060  
 1070  STACK      .EQ $100
 1080  IRQ.VECTOR .EQ $3FE
 1090  CONTROL.Y.VECTOR .EQ $3F9
 1100  *--------------------------------
 1110         .TF PROFILER
 1120         LDA /INITIALIZE
 1130         STA CONTROL.Y.VECTOR+1
 1140         LDA #INITIALIZE
 1150         STA CONTROL.Y.VECTOR
 1160         RTS
 1170  *--------------------------------
 1180  INITIALIZE
 1190         LDA #HANDLER      install vector
 1200         STA IRQ.VECTOR
 1210         LDA /HANDLER
 1220         STA IRQ.VECTOR+1
 1230         LDA #0       initialize variables
 1240         STA HITS
 1250         STA HITS+1
 1260         SEC
 1270         LDA A2L
 1280         SBC A3L      calculate step size
 1290         STA STEP
 1300         LDA A2H
 1310         SBC A3H
 1320         BCC ERROR    end<start
 1330         STA STEP+1
 1340  
 1350         LDX #3       divide STEP by 16
 1360  .1     LSR STEP+1   (shift it right 4)
 1370         ROR STEP
 1380         DEX
 1390         BPL .1
 1400  
 1410  BUILD.TABLE
 1420         LDA A3L       first table entry
 1430         STA TABLE     is start address
 1440         LDA A3H
 1450         STA TABLE+1
 1460         LDX #0
 1470         STX TABLE+2   zero count
 1480         STX TABLE+3   and fill byte
 1490  
 1500  .1     INX           next entry
 1510         INX
 1520         INX
 1530         INX
 1540         CLC
 1550         LDA TABLE-4,X
 1560         ADC STEP      add step size to
 1570         STA TABLE,X   last entry
 1580         LDA TABLE-3,X
 1590         ADC STEP+1
 1600         STA TABLE+1,X
 1610         LDA #0
 1620         STA TABLE+2,X zero count
 1630         STA TABLE+3,X and fill byte
 1640         CPX #$3C      done?
 1650         BCC .1        no
 1660  
 1670         LDA A2L
 1680         STA TABLE+4,X and make last entry
 1690         LDA A2H       equal end
 1700         STA TABLE+5,X
 1710  ERROR  RTS
 1720  *--------------------------------
 1730  HANDLER
 1740         LDA $45      get A back from where
 1750         PHA          Monitor stashed it
 1760         TXA
 1770         PHA          save registers
 1780         TYA
 1790         PHA
 1800         TSX
 1810         LDA STACK+6,X     get PC from stack
 1820         STA PCH
 1830         LDA STACK+5,X
 1840         STA PCL
 1850  *---SEARCH TABLE----------------
 1860         LDX #0            compare PC to start
 1870         JSR COMPARE.ENTRY   of table
 1880         BCC EXIT          below table
 1890         LDX #$40          and compare to
 1900         JSR COMPARE.ENTRY   end of table
 1910         BCS EXIT          above table
 1920  
 1930  .1     DEX               next entry
 1940         DEX
 1950         DEX
 1960         DEX
 1970         JSR COMPARE.ENTRY
 1980         BCC .1            not there yet
 1990  
 2000         INC HITS      count hit in total
 2010         BNE .2
 2020         INC HITS+1
 2030  .2     INC TABLE+2,X count hit in bracket
 2040         BNE EXIT
 2050  
 2060  * counter overflowed, so put it back to $FF and end
 2070         DEC TABLE+2,X
 2080         BRK
 2090  * ... do whatever it takes to clean up the stack
 2100  *     and display the results
 2110   
 2120  EXIT   LDY #55      delay about 275 usec so
 2130  .1     DEY            V5 will be high on exit
 2140         BNE .1
 2150         PLA          restore registers
 2160         TAY
 2170         PLA
 2180         TAX
 2190         PLA
 2200         RTI          and exit
 2210  *--------------------------------
 2220  COMPARE.ENTRY
 2230         LDA PCL
 2240         CMP TABLE,X
 2250         LDA PCH
 2260         SBC TABLE+1,X
 2270         RTS
 2280  *--------------------------------
 2290  VARIABLES
 2300  PCL    .BS 1        program counter
 2310  PCH    .BS 1
 2320  HITS   .BS 2        total count
 2330  STEP   .BS 2        bracket size
 2340  FILLER .BS */8*8+8-* align table
 2350  *--------------------------------
 2360  TABLE  .EQ *

