home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_14_1986_Transactor_Publishing.d64 / trace.pal (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  9KB  |  518 lines

  1. 1000 open 1,8,1,"0:trace.com"
  2. 1010 sys700
  3. 1020 .opt o1
  4. 1030 ;
  5. 1040 ;program name-trace/nmi
  6. 1050 ;
  7. 1060 ;purpose     -to trace and record
  8. 1070 ;the data from the <pc> in order
  9. 1080 ;to analyze the performance of
  10. 1090 ;a program
  11. 1100 ;
  12. 1110 ;last update -12/26/85
  13. 1120 ;
  14. 1130 ;author      -r.w.stringer
  15. 1140 ;            7805 villa cliff #111
  16. 1150 ;            dallas texas 75228
  17. 1160 ;            (214)-327-3039
  18. 1170 ;
  19. 1180 ;special note-i/o cannot operate
  20. 1190 ;with nmi interrupts functioning
  21. 1200 ;the unset routine (kill jmp
  22. 1210 ;vector ) should be called before
  23. 1220 ;any input/output
  24. 1230 ;            -buffer size in the
  25. 1240 ;present configuration is limited
  26. 1250 ;to 3 kbytes.this is room for a
  27. 1260 ;trace of 24kbytes of address
  28. 1270 ;space.to trace more space the
  29. 1280 ;program will need to move the
  30. 1290 ;buffer or remove basic from the
  31. 1300 ;current address space.no basic
  32. 1310 ;routines are used
  33. 1320 ;
  34. 1330 ;
  35. 1340 ;     system equates
  36. 1350 zpg =$fb
  37. 1360 temp =53
  38. 1370 skey =653    ;shft/ctrl/cmdre flag
  39. 1380 cbegin =$a0  ;trace start address
  40. 1390 cfinsh =$ff  ;trace end address
  41. 1400 ;above set range for trace
  42. 1410 ccycle =100  ;cycle count timer a
  43. 1420 milli =828   ;timer b count
  44. 1430 vector =792  ;nmi vector
  45. 1440 irqoff =%01111111 ;interrupt mask
  46. 1450 bmask =%00000010  ;timer b mask
  47. 1460 talo =$dd04  ;timer a latch low
  48. 1470 tahi =$dd05  ;              hi
  49. 1480 tactrl =$dd0e ;timer a control reg
  50. 1490 tblo =$dd06  ;timer b latch low
  51. 1500 tbhi =$dd07  ;              hi
  52. 1510 tbctrl =$dd0f ;timer b control reg
  53. 1520 irc =$dd0d  ;interrupt control reg
  54. 1530 ;    kernal equates
  55. 1540 setlfs =$ffba
  56. 1550 setnam =$ffbd
  57. 1560 open =$ffc0
  58. 1570 chrout =$ffd2
  59. 1580 close =$ffc3
  60. 1590 clrchn =$ffcc
  61. 1600 chkout =$ffc9
  62. 1610 ;
  63. 1620 ;the difference between cbegin
  64. 1630 ;and cfinsh can be no larger than
  65. 1640 ;$5f.the buffer at the present
  66. 1650 ;location is only 3k long
  67. 1660 ;in order to trace the complete
  68. 1670 ;64k address space you will need
  69. 1680 ;to allocate an 8k buffer.the
  70. 1690 ;chart will be 256 lines long.the
  71. 1700 ;buffer space formula is
  72. 1710 ;buffer =(#kbytes to trace)/8
  73. 1720 ;
  74. 1730 *=$8000       ;program orgin
  75. 1740 ;
  76. 1750 ;       jump vectors
  77. 1760 trace      jmp setirq  ;start
  78. 1770 kill       jmp unset   ;stop
  79. 1780 chart      jmp pntcht  ;printout
  80. 1790 reset      jmp settwo  ;restart
  81. 1800 ;
  82. 1810 ;set up vectors zero variables
  83. 1820 ;set up and start timers
  84. 1830 ;timer b counts underflows
  85. 1840 ;from timer a and counts down
  86. 1850 ;the number of underflows in
  87. 1860 ;milli.on timer b underflow a
  88. 1870 ;nmi is generated.vector points
  89. 1880 ;to tstprg
  90. 1890 ;
  91. 1900 setirq     jsr zbuff
  92. 1910 lda #0
  93. 1920 sta freq
  94. 1930 sta freq+1
  95. 1940 sta freq+2
  96. 1950 sta vflag
  97. 1960 settwo     lda vector
  98. 1970 sta oldvec
  99. 1980 lda #<tstprg
  100. 1990 sta vector
  101. 2000 lda vector+1
  102. 2010 sta oldvec+1
  103. 2020 lda #>tstprg
  104. 2030 sta vector+1
  105. 2040 settmr     lda milli
  106. 2050 bne sttimb
  107. 2060 lda #1
  108. 2070 sta milli
  109. 2080 sttimb     sta tblo
  110. 2090 lda #0
  111. 2100 sta tbhi
  112. 2110 lda #>ccycle
  113. 2120 sta tahi
  114. 2130 lda #<ccycle
  115. 2140 sta talo
  116. 2150 sei
  117. 2160 lda #%01000001
  118. 2170 sta tbctrl
  119. 2180 lda #%00000001
  120. 2190 sta tactrl
  121. 2200 lda #%10000010
  122. 2210 sta irc
  123. 2220 cli
  124. 2230 rts
  125. 2240 ;
  126. 2250 ;reset vectors to normal and
  127. 2260 ;turn interrupts off.needed for
  128. 2270 ;i/o operations
  129. 2280 ;
  130. 2290 unset      lda #irqoff
  131. 2300 sta irc
  132. 2310 lda #0
  133. 2320 sta tbctrl
  134. 2330 sta tactrl
  135. 2340 lda oldvec
  136. 2350 sta vector
  137. 2360 lda oldvec+1
  138. 2370 sta vector+1
  139. 2380 rts
  140. 2390 ;
  141. 2400 ;stop interrupts.pull address
  142. 2410 ;of next program step from stack
  143. 2420 ;check if in range.subtract offset
  144. 2430 ;from hibyte and store.store
  145. 2440 ;lobyte and jsr to array routine
  146. 2450 ;on return turn interrupts on
  147. 2460 ;reset timers and exit.
  148. 2470 ;
  149. 2480 tstprg     pha
  150. 2490 txa
  151. 2500 pha
  152. 2510 tya
  153. 2520 pha
  154. 2530 lda #bmask
  155. 2540 bit irc
  156. 2550 beq outjmp
  157. 2560 jmp swich
  158. 2570 outjmp     jsr unset
  159. 2580 lda #irqoff
  160. 2590 sta irc
  161. 2600 jmp $fe4c
  162. 2610 swich      lda #irqoff
  163. 2620 sta irc
  164. 2630 lda #0
  165. 2640 sta tactrl
  166. 2650 sta tbctrl
  167. 2660 tsx
  168. 2670 lda $0105,x
  169. 2680 sta lobyte
  170. 2690 lda $0106,x
  171. 2700 cmp #cbegin
  172. 2710 beq tryhi
  173. 2720 bcc bu(NULL)ut
  174. 2730 tryhi      cmp #cfinsh
  175. 2740 beq issame
  176. 2750 bcs bu(NULL)ut
  177. 2760 issame     sec
  178. 2770 sbc #cbegin
  179. 2780 sta hibyte
  180. 2790 ;
  181. 2800 ;we need to allow system irq
  182. 2810 ;requests here because we are
  183. 2820 ;stealing so much cpu time
  184. 2830 ;
  185. 2840 cli
  186. 2850 jsr mainpg ;index array
  187. 2860 bu(NULL)ut     jsr settmr
  188. 2870 jmp $ea81
  189. 2880 ;
  190. 2890 ;calculate array index and
  191. 2900 ;increment the proper array var
  192. 2910 ;array is-  array[0...xx,0...15]
  193. 2920 ;of double integer [0...65535]
  194. 2930 ;array index is calculated as
  195. 2940 ;  (hibyte-#cbegin)*32  +
  196. 2950 ;  (lobyte/16)*2        +
  197. 2960 ;  buffer start address
  198. 2970 ;overflow is checked for and
  199. 2980 ;sample count incremented.sample
  200. 2990 ;count is maintained as a 24 bit
  201. 3000 ;integer (2^24)-1.trace is
  202. 3010 ;terminated on sample overflow
  203. 3020 ;a flag is set on var overflow
  204. 3030 ;var's are kept in lo/high format
  205. 3040 ;
  206. 3050 mainpg     jsr setbuf
  207. 3060 lda #0
  208. 3070 sta hibyte+1
  209. 3080 lda lobyte
  210. 3090 and #$f0
  211. 3100 lsr a
  212. 3110 lsr a
  213. 3120 lsr a
  214. 3130 sta lobyte
  215. 3140 lda hibyte
  216. 3150 ldx #4
  217. 3160 mul32      asl a
  218. 3170 rol hibyte+1
  219. 3180 dex
  220. 3190 bpl mul32
  221. 3200 adc zpg
  222. 3210 sta zpg
  223. 3220 lda zpg+1
  224. 3230 adc hibyte+1
  225. 3240 sta zpg+1
  226. 3250 ldy lobyte
  227. 3260 lda (zpg),y
  228. 3270 clc
  229. 3280 adc #1
  230. 3290 sta (zpg),y ;indexed
  231. 3300 iny         ;element
  232. 3310 lda (zpg),y
  233. 3320 adc #0
  234. 3330 sta (zpg),y
  235. 3340 bcc test1
  236. 3350 lda #0
  237. 3360 adc vflag
  238. 3370 sta vflag
  239. 3380 lda #$ff
  240. 3390 sta (zpg),y
  241. 3400 dey
  242. 3410 sta (zpg),y
  243. 3420 test1      inc freq
  244. 3430 bne test2
  245. 3440 inc freq+1
  246. 3450 bne test2
  247. 3460 inc freq+2
  248. 3470 bne test2
  249. 3480 jsr unset
  250. 3490 test2      rts
  251. 3500 ;
  252. 3510 ;print results in chart form
  253. 3520 ;with proper formating.leading
  254. 3530 ;zeros are suppressed on two
  255. 3540 ;byte hexadecimal numbers
  256. 3550 ;
  257. 3560 ;
  258. 3570 pntcht      lda #cbegin
  259. 3580 sta fre2
  260. 3590 jsr p2scr
  261. 3600 ldx #4
  262. 3610 jsr chkout
  263. 3620 jsr phead
  264. 3630 jsr setbuf
  265. 3640 pnch1       lda #13
  266. 3650 jsr chrout
  267. 3660 lda fre2
  268. 3670 beq pfini
  269. 3680 cmp #cfinsh
  270. 3690 beq chks
  271. 3700 bcs pfini
  272. 3710 chks        jsr pnthex
  273. 3720 lda #":"
  274. 3730 jsr chrout
  275. 3740 lda #32
  276. 3750 jsr chrout
  277. 3760 ldy #255
  278. 3770 pnloop      iny
  279. 3780 cpy #32
  280. 3790 beq pnch2
  281. 3800 lda skey
  282. 3810 cmp #3
  283. 3820 bne pnch
  284. 3830 lda #13
  285. 3840 jsr chrout
  286. 3850 bcc pfini
  287. 3860 pnch        lda (zpg),y
  288. 3870 sta lcnt
  289. 3880 bne bumpy
  290. 3890 iny
  291. 3900 lda (zpg),y
  292. 3910 bne pntit
  293. 3920 jsr pnt3sp
  294. 3930 jmp pnloop
  295. 3940 pnch2       inc fre2
  296. 3950 clc
  297. 3960 lda zpg
  298. 3970 adc #32
  299. 3980 sta zpg
  300. 3990 lda zpg+1
  301. 4000 adc #0
  302. 4010 sta zpg+1
  303. 4020 jmp pnch1
  304. 4030 pfini       jsr phead
  305. 4040 jsr pntsta
  306. 4050 lda #4
  307. 4060 jsr close
  308. 4070 jsr clrchn
  309. 4080 rts
  310. 4090 bumpy       iny
  311. 4100 lda (zpg),y
  312. 4110 pntit       sty ysave
  313. 4120 ldy lcnt
  314. 4130 jsr hex16
  315. 4140 lda #32
  316. 4150 jsr chrout
  317. 4160 ldy ysave
  318. 4170 bne pnloop
  319. 4180 ;
  320. 4190 ;output hexnumber <two bytes>
  321. 4200 ;
  322. 4210 hex16      sty 829
  323. 4220 jsr pnthex
  324. 4230 lda 829
  325. 4240 jsr hexout
  326. 4250 jmp nozera
  327. 4260 ;
  328. 4270 ;output hex number <one byte>
  329. 4280 ;
  330. 4290 pnthex     jsr hexout
  331. 4300 cmp #"0"
  332. 4310 bne nozera
  333. 4320 cpy #"0"
  334. 4330 bne nozery
  335. 4340 ldy #32
  336. 4350 bne nozery
  337. 4360 nozera     jsr chrout
  338. 4370 nozery     tya
  339. 4380 jsr chrout
  340. 4390 rts
  341. 4400 hexout     tax
  342. 4410 and #$f0
  343. 4420 lsr a
  344. 4430 lsr a
  345. 4440 lsr a
  346. 4450 lsr a
  347. 4460 jsr ho2
  348. 4470 pha
  349. 4480 txa
  350. 4490 and #$0f
  351. 4500 jsr ho2
  352. 4510 tay
  353. 4520 pla
  354. 4530 rts
  355. 4540 ho2        cmp #10
  356. 4550 bcc nixadd
  357. 4560 clc
  358. 4570 adc #7
  359. 4580 nixadd     adc #"0"
  360. 4590 rts
  361. 4600 ;
  362. 4610 ;open printer as device #4
  363. 4620 ;
  364. 4630 p2scr      lda #255
  365. 4640 sta pindex+1
  366. 4650 lda 53272
  367. 4660 and #2
  368. 4670 beq ucase
  369. 4680 lda #7
  370. 4690 sta pindex+1
  371. 4700 ucase      lda #4
  372. 4710 ldx #4
  373. 4720 pindex     ldy #255
  374. 4730 jsr setlfs
  375. 4740 lda #0
  376. 4750 jsr setnam
  377. 4760 jsr open
  378. 4770 rts
  379. 4780 ;
  380. 4790 ;reset buffer to start
  381. 4800 ;
  382. 4810 setbuf    lda #<trbuf
  383. 4820 sta zpg
  384. 4830 lda #>trbuf
  385. 4840 sta zpg+1
  386. 4850 rts
  387. 4860 ;
  388. 4870 ;zero buffer area
  389. 4880 ;
  390. 4890 zbuff     jsr setbuf
  391. 4900 ldx #(cfinsh+1-cbegin)>3
  392. 4910 ldy #0
  393. 4920 tya
  394. 4930 zloop1    sta (zpg),y
  395. 4940 iny
  396. 4950 bne zloop1
  397. 4960 inc zpg+1
  398. 4970 dex
  399. 4980 bne zloop1
  400. 4990 rts
  401. 5000 ;
  402. 5010 ;print 3 spaces and a colon
  403. 5020 ;
  404. 5030 pnt3sp     sty ysave
  405. 5040 ldy #<space
  406. 5050 lda #>space
  407. 5060 jsr pstrng
  408. 5070 ldy ysave
  409. 5080 rts
  410. 5090 ;
  411. 5100 ;print top of chart
  412. 5110 ;
  413. 5120 phead      ldy #<messg
  414. 5130 lda #>messg
  415. 5140 jsr pstrng
  416. 5150 rts
  417. 5160 ;
  418. 5170 ;print string a => y =< address
  419. 5180 ;
  420. 5190 pstrng      sty temp
  421. 5200 sta temp+1
  422. 5210 ldy #0
  423. 5220 pstrg1      lda (temp),y
  424. 5230 beq pstrg2
  425. 5240 jsr chrout
  426. 5250 iny
  427. 5260 bne pstrg1
  428. 5270 pstrg2      rts
  429. 5280 ;
  430. 5290 ;print sample stats
  431. 5300 ;
  432. 5310 pntsta      ldy #<messg2
  433. 5320 lda #>messg2
  434. 5330 jsr pstrng
  435. 5340 ldy milli
  436. 5350 lda #0
  437. 5360 jsr hex16
  438. 5370 ldy #<messg5
  439. 5380 lda #>messg5
  440. 5390 jsr pstrng
  441. 5400 ldy #<messg3
  442. 5410 lda #>messg3
  443. 5420 jsr pstrng
  444. 5430 ldy #<ccycle
  445. 5440 lda #>ccycle
  446. 5450 jsr hex16
  447. 5460 ldy #<messg5
  448. 5470 lda #>messg5
  449. 5480 jsr pstrng
  450. 5490 ldy #<messg4
  451. 5500 lda #>messg4
  452. 5510 jsr pstrng
  453. 5520 lda freq+2
  454. 5530 jsr hexout
  455. 5540 jsr nozera
  456. 5550 lda freq+1
  457. 5560 jsr hexout
  458. 5570 jsr nozera
  459. 5580 lda freq
  460. 5590 jsr hexout
  461. 5600 jsr nozera
  462. 5610 ldy #<messg5
  463. 5620 lda #>messg5
  464. 5630 jsr pstrng
  465. 5640 ldy #<messg7
  466. 5650 lda #>messg7
  467. 5660 jsr pstrng
  468. 5670 lda vflag
  469. 5680 jsr hexout
  470. 5690 jsr nozera
  471. 5700 ldy #<messg5
  472. 5710 lda #>messg5
  473. 5720 jsr pstrng
  474. 5730 lda #13
  475. 5740 jsr chrout
  476. 5750 rts
  477. 5760 ;
  478. 5770 ;program  data and message tables
  479. 5780 ;
  480. 5790 space  .asc  "   :"
  481. 5800 .byte 0
  482. 5810 ;
  483. 5820 messg3 .byte 13
  484. 5830 .asc "clock cycle (a)  ["
  485. 5840 .byte 0
  486. 5850 ;
  487. 5860 messg2 .byte 13,13,13
  488. 5870 .asc "cycles      (b)  ["
  489. 5880 .byte 0
  490. 5890 ;
  491. 5900 messg4 .byte 13
  492. 5910 .asc "sample count     [ "
  493. 5920 .byte 0
  494. 5930 ;
  495. 5940 messg5 .asc " ]"
  496. 5950 .byte 0
  497. 5960 ;
  498. 5970 messg =*
  499. 5980 .asc "     00  10  20"
  500. 5990 .asc "  30  40  50  60"
  501. 6000 .asc "  70  80  90  a0"
  502. 6010 .asc "  b0  c0  d0  e0  f0"
  503. 6020 .byte 0
  504. 6030 messg7 .byte 13
  505. 6040 .asc "overflows        [ "
  506. 6050 .byte 0
  507. 6060 ;               data
  508. 6070 ysave  .byte 0
  509. 6080 oldvec .byte 0,0
  510. 6090 lcnt   .byte 0
  511. 6100 fre2   .byte 0,0
  512. 6110 hibyte .byte 0,0
  513. 6120 lobyte .byte 0
  514. 6130 freq   .byte 0,0,0
  515. 6140 vflag  .byte 0
  516. 6150 trbuf =*
  517. 6160 .end
  518.