1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-07-14 05:28:55 +00:00

Fix code tracing bug

If you set things up just right, it's possible for flag status
changes to fail to get merged.

Added a regression test to 1003-flags-and-branches.

Also, tweaked the instruction operand editor to be a bit smoother
from the keyboard: added alt-key shortcuts, and put the focus on the
OK button after creating/editing a label so you can just hit the
return key twice.
This commit is contained in:
Andy McFadden 2019-09-17 14:38:16 -07:00
parent c1056839b1
commit 1ddf4bed48
11 changed files with 130 additions and 75 deletions

View File

@ -821,6 +821,7 @@ namespace Asm65 {
BaseMemEffect = MemoryEffect.Read, BaseMemEffect = MemoryEffect.Read,
FlagsAffected = FlagsAffected_NVZC, FlagsAffected = FlagsAffected_NVZC,
StatusFlagUpdater = FlagUpdater_NVZC StatusFlagUpdater = FlagUpdater_NVZC
// We can assert C=0 after ADC #$00, but only if C=0 on entry. Doesn't seem useful.
}; };
private static OpDef OpAND = new OpDef() { private static OpDef OpAND = new OpDef() {
Mnemonic = OpName.AND, Mnemonic = OpName.AND,

View File

@ -757,14 +757,16 @@ namespace SourceGen {
// If we've already visited the next offset, and the updated status flags are // If we've already visited the next offset, and the updated status flags are
// the same as the previous status flags, then there's nothing to gain by // the same as the previous status flags, then there's nothing to gain by
// continuing forward. // continuing forward.
if (mAnattribs[nextOffset].IsVisited) { if (mAnattribs[nextOffset].IsVisited && !mAnattribs[nextOffset].IsChanged) {
if (!mAnattribs[nextOffset].IsChanged && if (nextStatusBefore == mAnattribs[nextOffset].StatusFlags) {
nextStatusBefore == mAnattribs[nextOffset].StatusFlags) {
// Instruction has been visited, hasn't been flagged as changed, // Instruction has been visited, hasn't been flagged as changed,
// and our status flag merge had no effect. No need to continue // and our status flag merge had no effect. No need to continue
// through. // through.
LogV(offset, "Not re-examining " + nextOffset); LogV(offset, "Not re-examining " + nextOffset);
break; break;
} else {
// We changed the flags, need to re-evaluate conditional branches.
mAnattribs[nextOffset].IsChanged = true;
} }
} }

View File

@ -228,32 +228,41 @@ L10FA clc
.byte $00 .byte $00
.byte $00 .byte $00
L1102 rep #$20 L1102 sec
.al bcs L1106
sep #$10
jsr L111D L1105 clc
rep #$30 L1106 lda $33
.xl beq L1105
jsr L1123 bcs L110E
sep #$30 lda $44
.as L110E nop
.xs
jsr L1123
rep #$20 rep #$20
.al .al
sep #$10 sep #$10
jsr L111D jsr L112A
rep #$30
.xl
jsr L1130
sep #$30
.as
.xs
jsr L1130
rep #$20
.al
sep #$10
jsr L112A
sep #$30 sep #$30
.as .as
rts rts
.al .al
L111D lda #$1234 L112A lda #$1234
ldx #$ff ldx #$ff
rts rts
.as .as
L1123 lda #$ff L1130 lda #$ff
ldx #$ee ldx #$ee
ldy #$dd ldy #$dd
rts rts

View File

@ -223,31 +223,40 @@ L10FA clc
dfb $00 dfb $00
dfb $00 dfb $00
L1102 rep #$20 L1102 sec
mx %01 bcs L1106
sep #$10
jsr L111D L1105 clc
rep #$30 L1106 lda $33
mx %00 beq L1105
jsr L1123 bcs L110E
sep #$30 lda $44
mx %11 L110E nop
jsr L1123
rep #$20 rep #$20
mx %01 mx %01
sep #$10 sep #$10
jsr L111D jsr L112A
rep #$30
mx %00
jsr L1130
sep #$30
mx %11
jsr L1130
rep #$20
mx %01
sep #$10
jsr L112A
sep #$30 sep #$30
mx %11 mx %11
rts rts
mx %01 mx %01
L111D lda #$1234 L112A lda #$1234
ldx #$ff ldx #$ff
rts rts
mx %11 mx %11
L1123 lda #$ff L1130 lda #$ff
ldx #$ee ldx #$ee
ldy #$dd ldy #$dd
rts rts

View File

@ -228,32 +228,41 @@ L10FA clc
!byte $00 !byte $00
!byte $00 !byte $00
L1102 rep #$20 L1102 sec
!al bcs L1106
sep #$10
jsr L111D L1105 clc
rep #$30 L1106 lda $33
!rl beq L1105
jsr L1123 bcs L110E
sep #$30 lda $44
!as L110E nop
!rs
jsr L1123
rep #$20 rep #$20
!al !al
sep #$10 sep #$10
jsr L111D jsr L112A
rep #$30
!rl
jsr L1130
sep #$30
!as
!rs
jsr L1130
rep #$20
!al
sep #$10
jsr L112A
sep #$30 sep #$30
!as !as
rts rts
!al !al
L111D lda #$1234 L112A lda #$1234
ldx #$ff ldx #$ff
rts rts
!as !as
L1123 lda #$ff L1130 lda #$ff
ldx #$ee ldx #$ee
ldy #$dd ldy #$dd
rts rts

View File

@ -229,32 +229,41 @@ L10FA: clc
.byte $00 .byte $00
.byte $00 .byte $00
L1102: rep #$20 L1102: sec
.a16 bcs L1106
sep #$10
jsr L111D L1105: clc
rep #$30 L1106: lda $33
.i16 beq L1105
jsr L1123 bcs L110E
sep #$30 lda $44
.a8 L110E: nop
.i8
jsr L1123
rep #$20 rep #$20
.a16 .a16
sep #$10 sep #$10
jsr L111D jsr L112A
rep #$30
.i16
jsr L1130
sep #$30
.a8
.i8
jsr L1130
rep #$20
.a16
sep #$10
jsr L112A
sep #$30 sep #$30
.a8 .a8
rts rts
.a16 .a16
L111D: lda #$1234 L112A: lda #$1234
ldx #$ff ldx #$ff
rts rts
.a8 .a8
L1123: lda #$ff L1130: lda #$ff
ldx #$ee ldx #$ee
ldy #$dd ldy #$dd
rts rts

View File

@ -1,7 +1,7 @@
# 6502bench SourceGen generated linker script for 1003-flags-and-branches # 6502bench SourceGen generated linker script for 1003-flags-and-branches
MEMORY { MEMORY {
MAIN: file=%O, start=%S, size=65536; MAIN: file=%O, start=%S, size=65536;
# MEM000: file=%O, start=$1000, size=298; # MEM000: file=%O, start=$1000, size=311;
} }
SEGMENTS { SEGMENTS {
CODE: load=MAIN, type=rw; CODE: load=MAIN, type=rw;

View File

@ -204,6 +204,18 @@ ok_rol1
brk $00 brk $00
ok_plp ok_plp
; regression test for bug in analyzer
sec ;here carry is clear
bcs flg2
flg1 clc
flg2 lda $33
beq flg1
bcs flg3 ;this should NOT be branch-always
lda $44
flg3 nop
; test tracking across subroutine calls
rep #$20 ;long a rep #$20 ;long a
sep #$10 ;short x/y sep #$10 ;short x/y
mx %01 mx %01

View File

@ -35,15 +35,15 @@ limitations under the License.
<system:String x:Key="str_SymbolNotValid">[invalid symbol name]</system:String> <system:String x:Key="str_SymbolNotValid">[invalid symbol name]</system:String>
<system:String x:Key="str_SymbolUnknown">?</system:String> <system:String x:Key="str_SymbolUnknown">?</system:String>
<system:String x:Key="str_CreateLocalVariable">Create Local Variable</system:String> <system:String x:Key="str_CreateLocalVariable">Create Local _Variable</system:String>
<system:String x:Key="str_EditLocalVariable">Edit Local Variable</system:String> <system:String x:Key="str_EditLocalVariable">Edit Local _Variable</system:String>
<system:String x:Key="str_LvMatchFoundAddress">Match found (ZP address):</system:String> <system:String x:Key="str_LvMatchFoundAddress">Match found (ZP address):</system:String>
<system:String x:Key="str_LvMatchFoundConstant">Match found (StackRel constant):</system:String> <system:String x:Key="str_LvMatchFoundConstant">Match found (StackRel constant):</system:String>
<system:String x:Key="str_CreateLabel">Create Label</system:String> <system:String x:Key="str_CreateLabel">Create _Label</system:String>
<system:String x:Key="str_EditLabel">Edit Label</system:String> <system:String x:Key="str_EditLabel">Edit _Label</system:String>
<system:String x:Key="str_CreateProjectSymbol">Create Project Symbol</system:String> <system:String x:Key="str_CreateProjectSymbol">Create _Project Symbol</system:String>
<system:String x:Key="str_EditProjectSymbol">Edit Project Symbol</system:String> <system:String x:Key="str_EditProjectSymbol">Edit _Project Symbol</system:String>
<system:String x:Key="str_CurrentLabel">Current label:</system:String> <system:String x:Key="str_CurrentLabel">Current label:</system:String>
<system:String x:Key="str_CurrentLabelAdjustedFmt">Current label (adjusted {0}):</system:String> <system:String x:Key="str_CurrentLabelAdjustedFmt">Current label (adjusted {0}):</system:String>
</Window.Resources> </Window.Resources>
@ -67,7 +67,7 @@ limitations under the License.
<StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="0,0,0,8"> <StackPanel Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="0,0,0,8">
<RadioButton GroupName="Main" Margin="0,2,0,0" <RadioButton GroupName="Main" Margin="0,2,0,0"
Content="Default (auto-format as hex, local var, or reference to label/platform/project symbol)" Content="D_efault (auto-format as hex, local var, or reference to label/platform/project symbol)"
IsChecked="{Binding FormatDefault}"/> IsChecked="{Binding FormatDefault}"/>
</StackPanel> </StackPanel>
@ -79,17 +79,17 @@ limitations under the License.
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<RadioButton GroupName="Main" Content="Hexadecimal" <RadioButton GroupName="Main" Content="_Hexadecimal"
IsChecked="{Binding FormatHex}"/> IsChecked="{Binding FormatHex}"/>
<RadioButton GroupName="Main" Content="Decimal" Margin="0,2,0,0" <RadioButton GroupName="Main" Content="_Decimal" Margin="0,2,0,0"
IsChecked="{Binding FormatDecimal}"/> IsChecked="{Binding FormatDecimal}"/>
<RadioButton GroupName="Main" Content="Binary" Margin="0,2,0,0" <RadioButton GroupName="Main" Content="_Binary" Margin="0,2,0,0"
IsChecked="{Binding FormatBinary}"/> IsChecked="{Binding FormatBinary}"/>
<RadioButton GroupName="Main" Content="ASCII (low or high) character" Margin="0,2,0,0" <RadioButton GroupName="Main" Content="_ASCII (low or high) character" Margin="0,2,0,0"
IsEnabled="{Binding IsFormatAsciiAllowed}" IsChecked="{Binding FormatAscii}"/> IsEnabled="{Binding IsFormatAsciiAllowed}" IsChecked="{Binding FormatAscii}"/>
<RadioButton GroupName="Main" Content="C64 PETSCII character" Margin="0,2,0,0" <RadioButton GroupName="Main" Content="C64 _PETSCII character" Margin="0,2,0,0"
IsEnabled="{Binding IsFormatPetsciiAllowed}" IsChecked="{Binding FormatPetscii}"/> IsEnabled="{Binding IsFormatPetsciiAllowed}" IsChecked="{Binding FormatPetscii}"/>
<RadioButton GroupName="Main" Content="C64 Screen character" Margin="0,2,0,0" <RadioButton GroupName="Main" Content="C64 Sc_reen character" Margin="0,2,0,0"
IsEnabled="{Binding IsFormatScreenCodeAllowed}" IsChecked="{Binding FormatScreenCode}"/> IsEnabled="{Binding IsFormatScreenCodeAllowed}" IsChecked="{Binding FormatScreenCode}"/>
</StackPanel> </StackPanel>
@ -104,7 +104,7 @@ limitations under the License.
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<RadioButton Name="formatSymbolButton" Grid.Column="0" Grid.Row="0" GroupName="Main" <RadioButton Name="formatSymbolButton" Grid.Column="0" Grid.Row="0" GroupName="Main"
Content="Symbol" IsChecked="{Binding FormatSymbol}"/> Content="_Symbol" IsChecked="{Binding FormatSymbol}"/>
<StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal" Margin="18,1,0,0"> <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal" Margin="18,1,0,0">
<TextBox Name="symbolTextBox" Grid.Column="0" Grid.Row="1" Width="150" <TextBox Name="symbolTextBox" Grid.Column="0" Grid.Row="1" Width="150"
FontFamily="{StaticResource GeneralMonoFont}" FontFamily="{StaticResource GeneralMonoFont}"
@ -118,7 +118,7 @@ limitations under the License.
IsEnabled="{Binding IsPartPanelEnabled}"> IsEnabled="{Binding IsPartPanelEnabled}">
<RadioButton GroupName="Part" Content="Low" <RadioButton GroupName="Part" Content="Low"
IsChecked="{Binding FormatPartLow}"/> IsChecked="{Binding FormatPartLow}"/>
<RadioButton GroupName="Part" Content="High" Margin="10,0,0,0" <RadioButton GroupName="Part" Content="_High" Margin="10,0,0,0"
IsChecked="{Binding FormatPartHigh}"/> IsChecked="{Binding FormatPartHigh}"/>
<RadioButton GroupName="Part" Content="Bank" Margin="10,0,0,0" <RadioButton GroupName="Part" Content="Bank" Margin="10,0,0,0"
IsChecked="{Binding FormatPartBank}"/> IsChecked="{Binding FormatPartBank}"/>
@ -221,7 +221,7 @@ limitations under the License.
<DockPanel Grid.Column="0" Grid.Row="5" Grid.ColumnSpan="2" Margin="0,8,0,0" LastChildFill="False"> <DockPanel Grid.Column="0" Grid.Row="5" Grid.ColumnSpan="2" Margin="0,8,0,0" LastChildFill="False">
<Button DockPanel.Dock="Right" Content="Cancel" Width="70" IsCancel="True" Margin="8,0,0,0"/> <Button DockPanel.Dock="Right" Content="Cancel" Width="70" IsCancel="True" Margin="8,0,0,0"/>
<Button DockPanel.Dock="Right" Content="OK" Width="70" IsDefault="True" <Button Name="okButton" DockPanel.Dock="Right" Content="OK" Width="70" IsDefault="True"
IsEnabled="{Binding IsValid}" Click="OkButton_Click"/> IsEnabled="{Binding IsValid}" Click="OkButton_Click"/>
</DockPanel> </DockPanel>
</Grid> </Grid>

View File

@ -946,6 +946,10 @@ namespace SourceGen.WpfGui {
CreateEditLabelText = EDIT_LABEL; CreateEditLabelText = EDIT_LABEL;
NarTargetLabel = mEditedLabel.Label; NarTargetLabel = mEditedLabel.Label;
} }
// Sort nice to just hit return twice after entering a label, so move the focus
// to the OK button.
okButton.Focus();
} }
private void EditProjectSymbol_Click(object sender, RoutedEventArgs e) { private void EditProjectSymbol_Click(object sender, RoutedEventArgs e) {