1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-07-06 16:29:03 +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,
FlagsAffected = FlagsAffected_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() {
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
// the same as the previous status flags, then there's nothing to gain by
// continuing forward.
if (mAnattribs[nextOffset].IsVisited) {
if (!mAnattribs[nextOffset].IsChanged &&
nextStatusBefore == mAnattribs[nextOffset].StatusFlags) {
if (mAnattribs[nextOffset].IsVisited && !mAnattribs[nextOffset].IsChanged) {
if (nextStatusBefore == mAnattribs[nextOffset].StatusFlags) {
// Instruction has been visited, hasn't been flagged as changed,
// and our status flag merge had no effect. No need to continue
// through.
LogV(offset, "Not re-examining " + nextOffset);
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
L1102 rep #$20
.al
sep #$10
jsr L111D
rep #$30
.xl
jsr L1123
sep #$30
.as
.xs
jsr L1123
L1102 sec
bcs L1106
L1105 clc
L1106 lda $33
beq L1105
bcs L110E
lda $44
L110E nop
rep #$20
.al
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
.as
rts
.al
L111D lda #$1234
L112A lda #$1234
ldx #$ff
rts
.as
L1123 lda #$ff
L1130 lda #$ff
ldx #$ee
ldy #$dd
rts

View File

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

View File

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

View File

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

View File

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

View File

@ -204,6 +204,18 @@ ok_rol1
brk $00
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
sep #$10 ;short x/y
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_SymbolUnknown">?</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_CreateLocalVariable">Create 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_LvMatchFoundConstant">Match found (StackRel constant):</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_CreateProjectSymbol">Create Project Symbol</system:String>
<system:String x:Key="str_EditProjectSymbol">Edit Project Symbol</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_CreateProjectSymbol">Create _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_CurrentLabelAdjustedFmt">Current label (adjusted {0}):</system:String>
</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">
<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}"/>
</StackPanel>
@ -79,17 +79,17 @@ limitations under the License.
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<RadioButton GroupName="Main" Content="Hexadecimal"
<RadioButton GroupName="Main" Content="_Hexadecimal"
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}"/>
<RadioButton GroupName="Main" Content="Binary" Margin="0,2,0,0"
<RadioButton GroupName="Main" Content="_Binary" Margin="0,2,0,0"
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}"/>
<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}"/>
<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}"/>
</StackPanel>
@ -104,7 +104,7 @@ limitations under the License.
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<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">
<TextBox Name="symbolTextBox" Grid.Column="0" Grid.Row="1" Width="150"
FontFamily="{StaticResource GeneralMonoFont}"
@ -118,7 +118,7 @@ limitations under the License.
IsEnabled="{Binding IsPartPanelEnabled}">
<RadioButton GroupName="Part" Content="Low"
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}"/>
<RadioButton GroupName="Part" Content="Bank" Margin="10,0,0,0"
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">
<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"/>
</DockPanel>
</Grid>

View File

@ -946,6 +946,10 @@ namespace SourceGen.WpfGui {
CreateEditLabelText = EDIT_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) {