Skip to content

Commit 717f675

Browse files
committed
documentation for subroutine cycle watches
1 parent f210a8d commit 717f675

File tree

9 files changed

+60
-9
lines changed

9 files changed

+60
-9
lines changed

README.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ You can watch registers or variables at certain program counter addresses by ins
6363
FOO EQU $8000
6464
6565
JSR TEST
66-
RTS
66+
BRK
6767
6868
TEST LDA #64 ; load 64 into accumulator
6969
ASL ; multiply by two @Au
@@ -94,7 +94,7 @@ In addition to watching individual registers, you can also watch global variable
9494
FOO EQU $8000 ; @u16
9595
9696
JSR TEST
97-
RTS
97+
BRK
9898
9999
TEST LDA #0
100100
STA FOO
@@ -114,10 +114,10 @@ Here's another example with some more interesting plots ([example03.yaml](exampl
114114
MX %11
115115
ORG $6000
116116
117-
FOO EQU $8000
117+
FOO EQU $8000 ; @u8
118118
119119
JSR TEST
120-
RTS
120+
BRK
121121
122122
TEST LDX #$FF
123123
LDA #1
@@ -130,8 +130,9 @@ LOOP TAY
130130
TYA
131131
CLC
132132
ADC FOO ; @Au(post)
133-
DEX ; @Xu(post)
133+
DEX ; @Xu(post) @Au,FOO(post)
134134
BNE LOOP
135+
RTS
135136
```
136137

137138
This is a small program which lets the accumulator grow exponentially while X decreases linearly:
@@ -151,6 +152,36 @@ This will plot FOO against X:
151152

152153
![FOO against A at PC 0x6015](doc/example03_3.gif?raw=true)
153154

155+
### Subroutine cycle watches
156+
157+
If you want to know the distribution of cycles spent in certain subroutines, use the `@cycles` directive to add a watch for this information:
158+
159+
```
160+
DSK test
161+
MX %11
162+
ORG $6000
163+
164+
LDX #$20
165+
JSR COUNT
166+
LDX #$30
167+
JSR COUNT
168+
LDX #$40
169+
JSR COUNT
170+
171+
BRK
172+
173+
COUNT DEX ; @Xu(post) @cycles
174+
BNE COUNT
175+
RTS
176+
```
177+
178+
This programm calls the `COUNT` subroutine three times with different X arguments, and we get both X and the number of cycles spent in `COUNT`:
179+
180+
![X at PC 0x6010](doc/example04_1.gif?raw=true)
181+
![COUNT cycles](doc/example04_2.gif?raw=true)
182+
183+
We see the three incantations of `COUNT` with `X` decreasing to 0 each time, and at the end of every loop, the amount of cycles spent in `COUNT`.
184+
154185
### Disabling watches
155186

156187
To disable a watch, add a `;` right behind the `@`:

champ.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def write_report
584584
end
585585
end
586586

587-
if @cycles_per_function.include?(watch[:pc])
587+
if (!@watch_values.include?(index)) && @cycles_per_function.include?(watch[:pc])
588588
max_cycle_count_for_function = @cycles_per_function[watch[:pc]].map do |x|
589589
x[:call_cycles]
590590
end.max

doc/example04_1.gif

3.75 KB
Loading

doc/example04_2.gif

3.06 KB
Loading

examples/example01.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
FOO EQU $8000
66

77
JSR TEST
8-
RTS
8+
BRK
99
1010
TEST LDA #64 ; load 64 into accumulator
1111
ASL ; multiply by two @Au

examples/example02.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
FOO EQU $8000 ; @u16
66

77
JSR TEST
8-
RTS
8+
BRK
99

1010
TEST LDA #0
1111
STA FOO

examples/example03.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
FOO EQU $8000 ; @u8
66

77
JSR TEST
8-
RTS
8+
BRK
99

1010
TEST LDX #$FF
1111
LDA #1
@@ -20,3 +20,4 @@ LOOP TAY
2020
ADC FOO ; @Au(post)
2121
DEX ; @Xu(post) @Au,FOO(post)
2222
BNE LOOP
23+
RTS

examples/example04.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
DSK test
2+
MX %11
3+
ORG $6000
4+
5+
LDX #$20
6+
JSR COUNT
7+
LDX #$30
8+
JSR COUNT
9+
LDX #$40
10+
JSR COUNT
11+
12+
BRK
13+
14+
COUNT DEX ; @Xu(post) @cycles
15+
BNE COUNT
16+
RTS

examples/example04.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
load:
2+
0x6000: example04.s
3+
entry: 0x6000

0 commit comments

Comments
 (0)