mirror of
https://github.com/fadden/6502bench.git
synced 2025-09-21 23:24:34 +00:00
Expand 20152-local-variables test
Added a compiled C implementation of strlen(). The most interesting part about this is that it references a 16-bit value via direct-page address $ff, which means you'd want a local variable with address=$ff and width=2. The current UI prevents this.
This commit is contained in:
@@ -1181,6 +1181,17 @@ namespace SourceGen {
|
|||||||
/// <returns>File data.</returns>
|
/// <returns>File data.</returns>
|
||||||
private byte[] FindValidDataFile(ref string dataPathName, DisasmProject proj,
|
private byte[] FindValidDataFile(ref string dataPathName, DisasmProject proj,
|
||||||
out bool cancel) {
|
out bool cancel) {
|
||||||
|
// TODO(someday):
|
||||||
|
// It would be nice to "fix" the length and CRC if they don't match while we're
|
||||||
|
// making manual edits to test files. We can pass "can fix" to the ChooseDataFile
|
||||||
|
// dialog, and have it return a "want fix" if they click on the "fix" button, and
|
||||||
|
// only enable this if the DEBUG menu is enabled. It's a little ugly but mostly
|
||||||
|
// works. One issue that must be handled is that "proj" has sized a bunch of data
|
||||||
|
// structures based on the expected file length, and will blow up if the actual
|
||||||
|
// length is different. So we really need to check both len/crc here, and if
|
||||||
|
// all broken things are fixable, return the "do fix" back to the caller so
|
||||||
|
// it can re-generate the DisasmProject object with the corrected length.
|
||||||
|
|
||||||
FileInfo fi = new FileInfo(dataPathName);
|
FileInfo fi = new FileInfo(dataPathName);
|
||||||
if (!fi.Exists) {
|
if (!fi.Exists) {
|
||||||
Debug.WriteLine("File '" + dataPathName + "' doesn't exist");
|
Debug.WriteLine("File '" + dataPathName + "' doesn't exist");
|
||||||
|
@@ -41,7 +41,7 @@ namespace SourceGen {
|
|||||||
/// and mask may be hex, decimal, or binary; these are simply tokenized by regex.
|
/// and mask may be hex, decimal, or binary; these are simply tokenized by regex.
|
||||||
///
|
///
|
||||||
/// Looks like:
|
/// Looks like:
|
||||||
/// NAME {@,=,<,>} VALUE [& MASK] [WIDTH] [;COMMENT]
|
/// NAME {@,=,<,>} VALUE [WIDTH] [;COMMENT]
|
||||||
///
|
///
|
||||||
/// Regex output groups are:
|
/// Regex output groups are:
|
||||||
/// 1. NAME (2+ alphanumeric or underscore, cannot start with number)
|
/// 1. NAME (2+ alphanumeric or underscore, cannot start with number)
|
||||||
|
Binary file not shown.
@@ -1,8 +1,8 @@
|
|||||||
### 6502bench SourceGen dis65 v1.0 ###
|
### 6502bench SourceGen dis65 v1.0 ###
|
||||||
{
|
{
|
||||||
"_ContentVersion":4,
|
"_ContentVersion":4,
|
||||||
"FileDataLength":151,
|
"FileDataLength":237,
|
||||||
"FileDataCrc32":-814797830,
|
"FileDataCrc32":1833028653,
|
||||||
"ProjectProps":{
|
"ProjectProps":{
|
||||||
"CpuName":"65816",
|
"CpuName":"65816",
|
||||||
"IncludeUndocumentedInstr":false,
|
"IncludeUndocumentedInstr":false,
|
||||||
@@ -183,6 +183,20 @@
|
|||||||
"Value":145,
|
"Value":145,
|
||||||
"Source":"User",
|
"Source":"User",
|
||||||
"Type":"LocalOrGlobalAddr",
|
"Type":"LocalOrGlobalAddr",
|
||||||
|
"LabelAnno":"None"},
|
||||||
|
|
||||||
|
"170":{
|
||||||
|
"Label":"STRING",
|
||||||
|
"Value":172,
|
||||||
|
"Source":"User",
|
||||||
|
"Type":"GlobalAddr",
|
||||||
|
"LabelAnno":"None"},
|
||||||
|
|
||||||
|
"178":{
|
||||||
|
"Label":"STRLEN",
|
||||||
|
"Value":180,
|
||||||
|
"Source":"User",
|
||||||
|
"Type":"GlobalAddr",
|
||||||
"LabelAnno":"None"}},
|
"LabelAnno":"None"}},
|
||||||
|
|
||||||
"OperandFormats":{
|
"OperandFormats":{
|
||||||
@@ -216,7 +230,15 @@
|
|||||||
"Length":2,
|
"Length":2,
|
||||||
"Format":"NumericLE",
|
"Format":"NumericLE",
|
||||||
"SubFormat":"Ascii",
|
"SubFormat":"Ascii",
|
||||||
"SymbolRef":null}},
|
"SymbolRef":null},
|
||||||
|
|
||||||
|
"155":{
|
||||||
|
"Length":3,
|
||||||
|
"Format":"NumericLE",
|
||||||
|
"SubFormat":"Symbol",
|
||||||
|
"SymbolRef":{
|
||||||
|
"Label":"STRING",
|
||||||
|
"Part":"Bank"}}},
|
||||||
|
|
||||||
"LvTables":{
|
"LvTables":{
|
||||||
"12":{
|
"12":{
|
||||||
@@ -756,6 +778,59 @@
|
|||||||
|
|
||||||
"145":{
|
"145":{
|
||||||
"Variables":[],
|
"Variables":[],
|
||||||
|
"ClearPrevious":false},
|
||||||
|
|
||||||
|
"178":{
|
||||||
|
"Variables":[{
|
||||||
|
"DataDescriptor":{
|
||||||
|
"Length":2,
|
||||||
|
"Format":"NumericLE",
|
||||||
|
"SubFormat":"Hex",
|
||||||
|
"SymbolRef":null},
|
||||||
|
|
||||||
|
"Comment":"",
|
||||||
|
"HasWidth":true,
|
||||||
|
"Direction":"ReadWrite",
|
||||||
|
"MultiMask":null,
|
||||||
|
"Label":"LEN",
|
||||||
|
"Value":242,
|
||||||
|
"Source":"Variable",
|
||||||
|
"Type":"ExternalAddr",
|
||||||
|
"LabelAnno":"None"},
|
||||||
|
|
||||||
|
{
|
||||||
|
"DataDescriptor":{
|
||||||
|
"Length":4,
|
||||||
|
"Format":"NumericLE",
|
||||||
|
"SubFormat":"Hex",
|
||||||
|
"SymbolRef":null},
|
||||||
|
|
||||||
|
"Comment":"",
|
||||||
|
"HasWidth":true,
|
||||||
|
"Direction":"ReadWrite",
|
||||||
|
"MultiMask":null,
|
||||||
|
"Label":"PTR",
|
||||||
|
"Value":244,
|
||||||
|
"Source":"Variable",
|
||||||
|
"Type":"ExternalAddr",
|
||||||
|
"LabelAnno":"None"},
|
||||||
|
|
||||||
|
{
|
||||||
|
"DataDescriptor":{
|
||||||
|
"Length":3,
|
||||||
|
"Format":"NumericLE",
|
||||||
|
"SubFormat":"Hex",
|
||||||
|
"SymbolRef":null},
|
||||||
|
|
||||||
|
"Comment":"",
|
||||||
|
"HasWidth":true,
|
||||||
|
"Direction":"ReadWrite",
|
||||||
|
"MultiMask":null,
|
||||||
|
"Label":"ARG",
|
||||||
|
"Value":253,
|
||||||
|
"Source":"Variable",
|
||||||
|
"Type":"ExternalAddr",
|
||||||
|
"LabelAnno":"None"}],
|
||||||
"ClearPrevious":false}},
|
"ClearPrevious":false}},
|
||||||
|
|
||||||
"Visualizations":[],
|
"Visualizations":[],
|
||||||
|
@@ -114,6 +114,65 @@ SPLITTER .var $80
|
|||||||
_SPLIT2 lda ','
|
_SPLIT2 lda ','
|
||||||
ldx $5678
|
ldx $5678
|
||||||
beq _SPLIT2
|
beq _SPLIT2
|
||||||
|
nop
|
||||||
|
clc
|
||||||
|
xce
|
||||||
|
rep #$30
|
||||||
|
.al
|
||||||
|
.xl
|
||||||
|
pea STRING >> 16
|
||||||
|
pea STRING
|
||||||
|
jsl STRLEN
|
||||||
|
sec
|
||||||
|
xce
|
||||||
|
.as
|
||||||
|
.xs
|
||||||
|
jmp L00E6
|
||||||
|
|
||||||
|
STRING .text "testing"
|
||||||
|
.byte $00
|
||||||
|
|
||||||
|
LEN .var $f2
|
||||||
|
PTR .var $f4
|
||||||
|
ARG .var $fd
|
||||||
|
.al
|
||||||
|
.xl
|
||||||
|
STRLEN phd
|
||||||
|
tsc
|
||||||
|
sec
|
||||||
|
sbc #$00f7
|
||||||
|
tcd
|
||||||
|
adc #$00f0
|
||||||
|
tcs
|
||||||
|
stz LEN
|
||||||
|
_L00C1 ldx ARG+2
|
||||||
|
lda ARG
|
||||||
|
inc ARG
|
||||||
|
bne _L00CB
|
||||||
|
inc ARG+2
|
||||||
|
_L00CB sta PTR
|
||||||
|
stx PTR+2
|
||||||
|
lda [PTR]
|
||||||
|
and #$00ff
|
||||||
|
beq _L00DA
|
||||||
|
inc LEN
|
||||||
|
bra _L00C1
|
||||||
|
|
||||||
|
_L00DA lda LEN
|
||||||
|
tay
|
||||||
|
tdc
|
||||||
|
clc
|
||||||
|
adc #$00f7
|
||||||
|
tcs
|
||||||
|
tya
|
||||||
|
pld
|
||||||
|
rtl
|
||||||
|
|
||||||
|
.as
|
||||||
|
.xs
|
||||||
|
L00E6 bit ARG+2
|
||||||
|
bit @w$00ff
|
||||||
|
bit $0100
|
||||||
rts
|
rts
|
||||||
|
|
||||||
.here
|
.here
|
||||||
|
@@ -224,6 +224,76 @@ DPCODE nop
|
|||||||
.SPLITTER = $80
|
.SPLITTER = $80
|
||||||
ldx $5678
|
ldx $5678
|
||||||
beq @SPLIT2
|
beq @SPLIT2
|
||||||
|
nop
|
||||||
|
clc
|
||||||
|
xce
|
||||||
|
rep #$30
|
||||||
|
!al
|
||||||
|
!rl
|
||||||
|
pea STRING >> 16
|
||||||
|
pea STRING
|
||||||
|
jsl STRLEN
|
||||||
|
sec
|
||||||
|
xce
|
||||||
|
!as
|
||||||
|
!rs
|
||||||
|
jmp L00E6
|
||||||
|
|
||||||
|
STRING !text "testing"
|
||||||
|
!byte $00
|
||||||
|
|
||||||
|
!zone Z0000b2
|
||||||
|
.NH0 = $00 ;not hidden
|
||||||
|
.NH1 = $01 ;not hidden
|
||||||
|
.PTR0 = $10
|
||||||
|
.CONST0 = $10
|
||||||
|
.PTR_C = $1d
|
||||||
|
.PTR_D = $21
|
||||||
|
.VAL0 = $30
|
||||||
|
.VAL14 = $31
|
||||||
|
.VAL5 = $35
|
||||||
|
.SPLITTER = $80
|
||||||
|
.LEN = $f2
|
||||||
|
.PTR = $f4
|
||||||
|
.ARG = $fd
|
||||||
|
!al
|
||||||
|
!rl
|
||||||
|
STRLEN phd
|
||||||
|
tsc
|
||||||
|
sec
|
||||||
|
sbc #$00f7
|
||||||
|
tcd
|
||||||
|
adc #$00f0
|
||||||
|
tcs
|
||||||
|
stz .LEN
|
||||||
|
@L00C1 ldx .ARG+2
|
||||||
|
lda .ARG
|
||||||
|
inc .ARG
|
||||||
|
bne @L00CB
|
||||||
|
inc .ARG+2
|
||||||
|
@L00CB sta .PTR
|
||||||
|
stx .PTR+2
|
||||||
|
lda [.PTR]
|
||||||
|
and #$00ff
|
||||||
|
beq @L00DA
|
||||||
|
inc .LEN
|
||||||
|
bra @L00C1
|
||||||
|
|
||||||
|
@L00DA lda .LEN
|
||||||
|
tay
|
||||||
|
tdc
|
||||||
|
clc
|
||||||
|
adc #$00f7
|
||||||
|
tcs
|
||||||
|
tya
|
||||||
|
pld
|
||||||
|
rtl
|
||||||
|
|
||||||
|
!as
|
||||||
|
!rs
|
||||||
|
L00E6 bit .ARG+2
|
||||||
|
bit+2 $00ff
|
||||||
|
bit $0100
|
||||||
rts
|
rts
|
||||||
|
|
||||||
} ;!pseudopc
|
} ;!pseudopc
|
||||||
|
@@ -114,5 +114,64 @@ SPLITTER .set $80
|
|||||||
@SPLIT2: lda ','
|
@SPLIT2: lda ','
|
||||||
ldx $5678
|
ldx $5678
|
||||||
beq @SPLIT2
|
beq @SPLIT2
|
||||||
|
nop
|
||||||
|
clc
|
||||||
|
xce
|
||||||
|
rep #$30
|
||||||
|
.a16
|
||||||
|
.i16
|
||||||
|
pea STRING >> 16
|
||||||
|
pea STRING
|
||||||
|
jsl STRLEN
|
||||||
|
sec
|
||||||
|
xce
|
||||||
|
.a8
|
||||||
|
.i8
|
||||||
|
jmp L00E6
|
||||||
|
|
||||||
|
STRING: .byte "testing"
|
||||||
|
.byte $00
|
||||||
|
|
||||||
|
LEN .set $f2
|
||||||
|
PTR .set $f4
|
||||||
|
ARG .set $fd
|
||||||
|
.a16
|
||||||
|
.i16
|
||||||
|
STRLEN: phd
|
||||||
|
tsc
|
||||||
|
sec
|
||||||
|
sbc #$00f7
|
||||||
|
tcd
|
||||||
|
adc #$00f0
|
||||||
|
tcs
|
||||||
|
stz LEN
|
||||||
|
@L00C1: ldx ARG+2
|
||||||
|
lda ARG
|
||||||
|
inc ARG
|
||||||
|
bne @L00CB
|
||||||
|
inc ARG+2
|
||||||
|
@L00CB: sta PTR
|
||||||
|
stx PTR+2
|
||||||
|
lda [PTR]
|
||||||
|
and #$00ff
|
||||||
|
beq @L00DA
|
||||||
|
inc LEN
|
||||||
|
bra @L00C1
|
||||||
|
|
||||||
|
@L00DA: lda LEN
|
||||||
|
tay
|
||||||
|
tdc
|
||||||
|
clc
|
||||||
|
adc #$00f7
|
||||||
|
tcs
|
||||||
|
tya
|
||||||
|
pld
|
||||||
|
rtl
|
||||||
|
|
||||||
|
.a8
|
||||||
|
.i8
|
||||||
|
L00E6: bit ARG+2
|
||||||
|
bit a:$00ff
|
||||||
|
bit $0100
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
MEMORY {
|
MEMORY {
|
||||||
MAIN: file=%O, start=%S, size=65536;
|
MAIN: file=%O, start=%S, size=65536;
|
||||||
# MEM000: file=%O, start=$1000, size=126;
|
# MEM000: file=%O, start=$1000, size=126;
|
||||||
# MEM001: file=%O, start=$0080, size=25;
|
# MEM001: file=%O, start=$0080, size=111;
|
||||||
}
|
}
|
||||||
SEGMENTS {
|
SEGMENTS {
|
||||||
CODE: load=MAIN, type=rw;
|
CODE: load=MAIN, type=rw;
|
||||||
|
@@ -109,5 +109,60 @@ DPCODE nop
|
|||||||
:SPLIT2 lda $2c
|
:SPLIT2 lda $2c
|
||||||
ldx $5678
|
ldx $5678
|
||||||
beq :SPLIT2
|
beq :SPLIT2
|
||||||
|
nop
|
||||||
|
clc
|
||||||
|
xce
|
||||||
|
rep #$30
|
||||||
|
mx %00
|
||||||
|
pea ^STRING
|
||||||
|
pea STRING
|
||||||
|
jsl STRLEN
|
||||||
|
sec
|
||||||
|
xce
|
||||||
|
mx %11
|
||||||
|
jmp L00E6
|
||||||
|
|
||||||
|
STRING asc 'testing'
|
||||||
|
dfb $00
|
||||||
|
|
||||||
|
]LEN equ $f2
|
||||||
|
]PTR equ $f4
|
||||||
|
]ARG equ $fd
|
||||||
|
mx %00
|
||||||
|
STRLEN phd
|
||||||
|
tsc
|
||||||
|
sec
|
||||||
|
sbc #$00f7
|
||||||
|
tcd
|
||||||
|
adc #$00f0
|
||||||
|
tcs
|
||||||
|
stz ]LEN
|
||||||
|
:L00C1 ldx ]ARG+2
|
||||||
|
lda ]ARG
|
||||||
|
inc ]ARG
|
||||||
|
bne :L00CB
|
||||||
|
inc ]ARG+2
|
||||||
|
:L00CB sta ]PTR
|
||||||
|
stx ]PTR+2
|
||||||
|
lda []PTR]
|
||||||
|
and #$00ff
|
||||||
|
beq :L00DA
|
||||||
|
inc ]LEN
|
||||||
|
bra :L00C1
|
||||||
|
|
||||||
|
:L00DA lda ]LEN
|
||||||
|
tay
|
||||||
|
tdc
|
||||||
|
clc
|
||||||
|
adc #$00f7
|
||||||
|
tcs
|
||||||
|
tya
|
||||||
|
pld
|
||||||
|
rtl
|
||||||
|
|
||||||
|
mx %11
|
||||||
|
L00E6 bit ]ARG+2
|
||||||
|
bit: $00ff
|
||||||
|
bit $0100
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@@ -155,4 +155,92 @@ LOCAL1 lda #$2c ;EDIT: format as ASCII
|
|||||||
LOCAL2 lda $2c ;EDIT: format as ASCII
|
LOCAL2 lda $2c ;EDIT: format as ASCII
|
||||||
ldx $5678 ;put empty variable table here
|
ldx $5678 ;put empty variable table here
|
||||||
beq LOCAL2
|
beq LOCAL2
|
||||||
|
|
||||||
|
; Test C-style call frame (issue #96).
|
||||||
|
nop
|
||||||
|
clc
|
||||||
|
xce
|
||||||
|
rep #$30
|
||||||
|
pea ^STRING
|
||||||
|
pea STRING
|
||||||
|
jsl STRLEN
|
||||||
|
sec
|
||||||
|
xce
|
||||||
|
|
||||||
|
jmp AFTER_STRLEN
|
||||||
|
|
||||||
|
STRING asc 'testing',00
|
||||||
|
|
||||||
|
; C sample, for something like:
|
||||||
|
|
||||||
|
; int strlen(const char* arg) {
|
||||||
|
; len = 0;
|
||||||
|
; while (*arg++ != '\0')
|
||||||
|
; len++;
|
||||||
|
; return len;
|
||||||
|
; }
|
||||||
|
;
|
||||||
|
; Assume SP at $2000 before call. On entry:
|
||||||
|
; $2000 string-$00
|
||||||
|
; $1fff string-bank
|
||||||
|
; $1ffe string-hi
|
||||||
|
; $1ffd string-lo
|
||||||
|
; $1ffc ret-bank
|
||||||
|
; $1ffb ret-hi
|
||||||
|
; $1ffa ret-lo
|
||||||
|
; S=$1ff9
|
||||||
|
;
|
||||||
|
; After call frame set up:
|
||||||
|
; $1ff9 saved-D-hi
|
||||||
|
; $1ff8 saved-D-lo
|
||||||
|
; S=$1ff7 before SBC/ADC
|
||||||
|
; $1ff7 (ptr-$00)
|
||||||
|
; $1ff6 (ptr-bank)
|
||||||
|
; $1ff5 (ptr-hi)
|
||||||
|
; $1ff4 (ptr-lo)
|
||||||
|
; $1ff3 (len-hi)
|
||||||
|
; $1ff2 (len-lo)
|
||||||
|
;
|
||||||
|
; D=$1f00
|
||||||
|
; S=$1ff1
|
||||||
|
;
|
||||||
|
]LEN equ $f2 ;2 bytes
|
||||||
|
]PTR equ $f4 ;4 bytes
|
||||||
|
]ARG equ $fd ;4 bytes; spans [$fd,$100]
|
||||||
|
|
||||||
|
mx %00
|
||||||
|
STRLEN phd
|
||||||
|
tsc
|
||||||
|
sec
|
||||||
|
sbc #$00f7
|
||||||
|
tcd
|
||||||
|
adc #$00f0 ;note carry set
|
||||||
|
tcs
|
||||||
|
stz ]LEN
|
||||||
|
:Loop ldx ]ARG+2
|
||||||
|
lda ]ARG
|
||||||
|
inc ]ARG
|
||||||
|
bne :NoInc
|
||||||
|
inc ]ARG+2
|
||||||
|
:NoInc sta ]PTR
|
||||||
|
stx ]PTR+2
|
||||||
|
lda []PTR]
|
||||||
|
and #$00ff
|
||||||
|
beq :Ret
|
||||||
|
inc ]LEN
|
||||||
|
bra :Loop
|
||||||
|
:Ret lda ]LEN
|
||||||
|
tay
|
||||||
|
tdc
|
||||||
|
clc
|
||||||
|
adc #$00f7
|
||||||
|
tcs
|
||||||
|
tya
|
||||||
|
pld
|
||||||
|
rtl
|
||||||
|
|
||||||
|
AFTER_STRLEN
|
||||||
|
bit $ff
|
||||||
|
bit: $00ff
|
||||||
|
bit $0100
|
||||||
rts
|
rts
|
||||||
|
Reference in New Issue
Block a user