mirror of
https://github.com/zellyn/go6502.git
synced 2025-04-09 15:38:49 +00:00
Removed Mode field from instructions.
This commit is contained in:
parent
498b6c5a7d
commit
495a2473e2
@ -30,7 +30,6 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
}
|
||||
in.Op = op.Byte
|
||||
in.Width = 2
|
||||
in.Mode = opcodes.MODE_INDIRECT_X
|
||||
in.Var = inst.VarOpByte
|
||||
if valKnown {
|
||||
in.Final = true
|
||||
@ -46,7 +45,6 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
return in, fmt.Errorf("%s (addr),Y doesn't have a wide variant", in.Command)
|
||||
}
|
||||
in.Width = 2
|
||||
in.Mode = opcodes.MODE_INDIRECT_Y
|
||||
in.Op = op.Byte
|
||||
in.Var = inst.VarOpByte
|
||||
if valKnown {
|
||||
@ -61,7 +59,6 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
}
|
||||
in.Op = op.Byte
|
||||
in.Width = 3
|
||||
in.Mode = opcodes.MODE_INDIRECT
|
||||
in.Var = inst.VarOpWord
|
||||
if valKnown {
|
||||
in.Final = true
|
||||
@ -83,7 +80,6 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
|
||||
in.Op = op.Byte
|
||||
in.Width = 2
|
||||
in.Mode = opcodes.MODE_RELATIVE
|
||||
in.Var = inst.VarOpBranch
|
||||
if valKnown {
|
||||
b, err := RelativeAddr(c, in, val)
|
||||
@ -104,7 +100,6 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
}
|
||||
in.Op = op.Byte
|
||||
in.Width = 2
|
||||
in.Mode = opcodes.MODE_IMMEDIATE
|
||||
in.Var = inst.VarOpByte
|
||||
if valKnown {
|
||||
in.Data = []byte{in.Op, byte(val)}
|
||||
@ -137,9 +132,7 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
if !zpOk {
|
||||
in.Op = opWide.Byte
|
||||
in.Width = 3
|
||||
in.Mode = wide
|
||||
in.Var = inst.VarOpWord
|
||||
in.Mode = wide
|
||||
if valKnown {
|
||||
in.Data = []byte{in.Op, byte(val), byte(val >> 8)}
|
||||
in.Final = true
|
||||
@ -152,9 +145,7 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
}
|
||||
in.Op = opZp.Byte
|
||||
in.Width = 2
|
||||
in.Mode = zp
|
||||
in.Var = inst.VarOpByte
|
||||
in.Mode = zp
|
||||
if valKnown {
|
||||
in.Data = []byte{in.Op, byte(val)}
|
||||
in.Final = true
|
||||
@ -165,7 +156,6 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
if forceWide {
|
||||
in.Op = opWide.Byte
|
||||
in.Width = 3
|
||||
in.Mode = wide
|
||||
in.Var = inst.VarOpWord
|
||||
if valKnown {
|
||||
in.Data = []byte{in.Op, byte(val), byte(val >> 8)}
|
||||
@ -180,7 +170,6 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
in.Data = []byte{in.Op, byte(val)}
|
||||
in.Width = 2
|
||||
in.Var = inst.VarOpByte
|
||||
in.Mode = zp
|
||||
in.Final = true
|
||||
return in, nil
|
||||
}
|
||||
@ -188,21 +177,18 @@ func DecodeOp(c context.Context, in inst.I, summary opcodes.OpSummary, indirect
|
||||
in.Data = []byte{in.Op, byte(val), byte(val >> 8)}
|
||||
in.Width = 3
|
||||
in.Var = inst.VarOpWord
|
||||
in.Mode = wide
|
||||
in.Final = true
|
||||
return in, nil
|
||||
}
|
||||
|
||||
if in.Exprs[0].Width() == 1 {
|
||||
in.Op = opZp.Byte
|
||||
in.Mode = zp
|
||||
in.Width = 2
|
||||
in.Var = inst.VarOpByte
|
||||
return in, nil
|
||||
}
|
||||
|
||||
in.Op = opWide.Byte
|
||||
in.Mode = wide
|
||||
in.Width = 3
|
||||
in.Var = inst.VarOpWord
|
||||
return in, nil
|
||||
|
@ -326,7 +326,6 @@ func (a *Base) parseOpArgs(ctx context.Context, in inst.I, lp *lines.Parse, summ
|
||||
in.Data = []byte{op.Byte}
|
||||
in.Width = 1
|
||||
in.Final = true
|
||||
in.Mode = opcodes.MODE_IMPLIED
|
||||
return in, nil
|
||||
}
|
||||
|
||||
@ -353,7 +352,6 @@ func (a *Base) parseOpArgs(ctx context.Context, in inst.I, lp *lines.Parse, summ
|
||||
in.Data = []byte{op.Byte}
|
||||
in.Width = 1
|
||||
in.Final = true
|
||||
in.Mode = opcodes.MODE_A
|
||||
return in, nil
|
||||
}
|
||||
|
||||
@ -381,7 +379,6 @@ func (a *Base) parseOpArgs(ctx context.Context, in inst.I, lp *lines.Parse, summ
|
||||
in.Data = []byte{op.Byte}
|
||||
in.Width = 1
|
||||
in.Final = true
|
||||
in.Mode = opcodes.MODE_A
|
||||
in.Exprs = nil
|
||||
return in, nil
|
||||
|
||||
|
@ -55,9 +55,9 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
{mm, " >>> M1,$42 ;$43", `{call M1 {"$42"}}`, ""},
|
||||
{mm, " >>> M1.$42", `{call M1 {"$42"}}`, ""},
|
||||
{mm, " >>> M1/$42;$43", `{call M1 {"$42", "$43"}}`, ""},
|
||||
{mm, " BEQ $2343", "{BEQ/rel $2343}", "f0fc"},
|
||||
{mm, " BEQ $2345", "{BEQ/rel $2345}", "f0fe"},
|
||||
{mm, " BEQ $2347", "{BEQ/rel $2347}", "f000"},
|
||||
{mm, " BEQ $2343", "{BEQ $2343}", "f0fc"},
|
||||
{mm, " BEQ $2345", "{BEQ $2345}", "f0fe"},
|
||||
{mm, " BEQ $2347", "{BEQ $2347}", "f000"},
|
||||
{mm, " DA $12,$34,$1234", "{data/wle $0012,$0034,$1234}", "120034003412"},
|
||||
{mm, " DA $1234", "{data/wle $1234}", "3412"},
|
||||
{mm, " DB <L4,<L5", "{data/b (lsb L4),(lsb L5)}", "deef"},
|
||||
@ -69,34 +69,34 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
{mm, " HEX 00,01,FF,AB", "{data/b}", "0001ffab"},
|
||||
{mm, " HEX 0001FFAB", "{data/b}", "0001ffab"},
|
||||
{mm, " INCW $42;$43", `{call INCW {"$42", "$43"}}`, ""},
|
||||
{mm, " JMP $1234", "{JMP/abs $1234}", "4c3412"},
|
||||
{mm, " JMP ($1234)", "{JMP/ind $1234}", "6c3412"},
|
||||
{mm, " LDA #$12", "{LDA/imm (lsb $0012)}", "a912"},
|
||||
{mm, " LDA #$1234", "{LDA/imm (lsb $1234)}", "a934"},
|
||||
{mm, " LDA #/$1234", "{LDA/imm (msb $1234)}", "a912"},
|
||||
{mm, " LDA #<$1234", "{LDA/imm (lsb $1234)}", "a934"},
|
||||
{mm, " LDA #>$1234", "{LDA/imm (msb $1234)}", "a912"},
|
||||
{mm, " LDA $12", "{LDA/zp $0012}", "a512"},
|
||||
{mm, " LDA $12", "{LDA/zp $0012}", "a512"},
|
||||
{mm, " LDA $12,X", "{LDA/zpX $0012}", "b512"},
|
||||
{mm, " LDA $1234", "{LDA/abs $1234}", "ad3412"},
|
||||
{mm, " LDA $1234", "{LDA/abs $1234}", "ad3412"},
|
||||
{mm, " LDA $1234,X", "{LDA/absX $1234}", "bd3412"},
|
||||
{mm, " LDA ($12),Y", "{LDA/indY $0012}", "b112"},
|
||||
{mm, " LDA ($12,X)", "{LDA/indX $0012}", "a112"},
|
||||
{mm, " LDA: $12", "{LDA/abs $0012}", "ad1200"},
|
||||
{mm, " LDA@ $12", "{LDA/abs $0012}", "ad1200"},
|
||||
{mm, " LDAX $12", "{LDA/abs $0012}", "ad1200"},
|
||||
{mm, " LDX $12,Y", "{LDX/zpY $0012}", "b612"},
|
||||
{mm, " JMP $1234", "{JMP $1234}", "4c3412"},
|
||||
{mm, " JMP ($1234)", "{JMP $1234}", "6c3412"},
|
||||
{mm, " LDA #$12", "{LDA (lsb $0012)}", "a912"},
|
||||
{mm, " LDA #$1234", "{LDA (lsb $1234)}", "a934"},
|
||||
{mm, " LDA #/$1234", "{LDA (msb $1234)}", "a912"},
|
||||
{mm, " LDA #<$1234", "{LDA (lsb $1234)}", "a934"},
|
||||
{mm, " LDA #>$1234", "{LDA (msb $1234)}", "a912"},
|
||||
{mm, " LDA $12", "{LDA $0012}", "a512"},
|
||||
{mm, " LDA $12", "{LDA $0012}", "a512"},
|
||||
{mm, " LDA $12,X", "{LDA $0012}", "b512"},
|
||||
{mm, " LDA $1234", "{LDA $1234}", "ad3412"},
|
||||
{mm, " LDA $1234", "{LDA $1234}", "ad3412"},
|
||||
{mm, " LDA $1234,X", "{LDA $1234}", "bd3412"},
|
||||
{mm, " LDA ($12),Y", "{LDA $0012}", "b112"},
|
||||
{mm, " LDA ($12,X)", "{LDA $0012}", "a112"},
|
||||
{mm, " LDA: $12", "{LDA $0012}", "ad1200"},
|
||||
{mm, " LDA@ $12", "{LDA $0012}", "ad1200"},
|
||||
{mm, " LDAX $12", "{LDA $0012}", "ad1200"},
|
||||
{mm, " LDX $12,Y", "{LDX $0012}", "b612"},
|
||||
{mm, " ORG $D000", "{org $d000}", ""},
|
||||
{mm, " PMC M1($42", `{call M1 {"$42"}}`, ""},
|
||||
{mm, " PMC M1-$42", `{call M1 {"$42"}}`, ""},
|
||||
{mm, " PUT !FILE.NAME", "{inc 'FILE.NAME'}", ""},
|
||||
{mm, " ROL $12", "{ROL/zp $0012}", "2612"},
|
||||
{mm, " ROL $1234", "{ROL/abs $1234}", "2e3412"},
|
||||
{mm, " ROL", "{ROL/a}", "2a"},
|
||||
{mm, " ROL $12", "{ROL $0012}", "2612"},
|
||||
{mm, " ROL $1234", "{ROL $1234}", "2e3412"},
|
||||
{mm, " ROL", "{ROL}", "2a"},
|
||||
{mm, " SAV OUTFILE", "{-}", ""},
|
||||
{mm, " STA $1234,Y", "{STA/absY $1234}", "993412"},
|
||||
{mm, " STA $1234,Y", "{STA $1234}", "993412"},
|
||||
{mm, "* Comment", "{-}", ""},
|
||||
{mm, "ABC = $800", "{= 'ABC' $0800}", ""},
|
||||
{mm, "L1 = 'A.2", "{= 'L1' (| $0041 $0002)}", ""},
|
||||
@ -148,8 +148,8 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
{ra, " MSB OFF", "{set MSB OFF}", ""},
|
||||
{ra, " MSB ON", "{set MSB ON}", ""},
|
||||
{ra, " ORG $D000", "{org $d000}", ""},
|
||||
{ra, " ROL A", "{ROL/a}", "2a"}, // two spaces is no big deal
|
||||
{ra, " ROL A", "{ROL/a}", "2a"},
|
||||
{ra, " ROL A", "{ROL}", "2a"}, // two spaces is no big deal
|
||||
{ra, " ROL A", "{ROL}", "2a"},
|
||||
{ra, "* Comment", "{-}", ""},
|
||||
{ra, "Label", "{- 'Label'}", ""},
|
||||
{ra, "Label:", "{- 'Label'}", ""},
|
||||
@ -160,9 +160,9 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
{ra, ` DCI "ABC"`, "{data/b}", "4142c3"},
|
||||
{ra, ` SBTL Title here`, "{-}", ""},
|
||||
{ra, ` TITLE Title here`, "{-}", ""},
|
||||
{rb, " ROL Comment after three spaces", "{ROL/a}", "2a"},
|
||||
{rb, " ROL X", "{ROL/a}", "2a"}, // two spaces = comment
|
||||
{rb, " ROL", "{ROL/a}", "2a"},
|
||||
{rb, " ROL Comment after three spaces", "{ROL}", "2a"},
|
||||
{rb, " ROL X", "{ROL}", "2a"}, // two spaces = comment
|
||||
{rb, " ROL", "{ROL}", "2a"},
|
||||
{ss, " far-out-comment", "{-}", ""},
|
||||
{ss, " .BS $8", "{block $0008}", "xxxxxxxxxxxxxxxx"},
|
||||
{ss, " .DA $1234", "{data $1234}", "3412"},
|
||||
@ -179,27 +179,27 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
{ss, " .OR $D000", "{org $d000}", ""},
|
||||
{ss, " .TF OUT.BIN", "{-}", ""},
|
||||
{ss, " .TI 76,Title here", "{-}", ""},
|
||||
{ss, " BEQ $2343", "{BEQ/rel $2343}", "f0fc"},
|
||||
{ss, " BEQ $2345", "{BEQ/rel $2345}", "f0fe"},
|
||||
{ss, " BEQ $2347", "{BEQ/rel $2347}", "f000"},
|
||||
{ss, " CMP #';'+1", "{CMP/imm (lsb (+ $003b $0001))}", "c93c"},
|
||||
{ss, " JMP $1234", "{JMP/abs $1234}", "4c3412"},
|
||||
{ss, " JMP ($1234)", "{JMP/ind $1234}", "6c3412"},
|
||||
{ss, " LDA #$12", "{LDA/imm (lsb $0012)}", "a912"},
|
||||
{ss, " LDA $12", "{LDA/zp $0012}", "a512"},
|
||||
{ss, " LDA $12,X", "{LDA/zpX $0012}", "b512"},
|
||||
{ss, " LDA $1234", "{LDA/abs $1234}", "ad3412"},
|
||||
{ss, " LDA $1234,X", "{LDA/absX $1234}", "bd3412"},
|
||||
{ss, " LDA ($12),Y", "{LDA/indY $0012}", "b112"},
|
||||
{ss, " LDA ($12,X)", "{LDA/indX $0012}", "a112"},
|
||||
{ss, " LDX #']+$80", "{LDX/imm (lsb (+ $005d $0080))}", "a2dd"},
|
||||
{ss, " LDX $12,Y", "{LDX/zpY $0012}", "b612"},
|
||||
{ss, " ROL Comment after two spaces", "{ROL/a}", "2a"},
|
||||
{ss, " ROL X", "{ROL/a}", "2a"}, // two spaces = comment
|
||||
{ss, " ROL $12", "{ROL/zp $0012}", "2612"},
|
||||
{ss, " ROL $1234", "{ROL/abs $1234}", "2e3412"},
|
||||
{ss, " ROL", "{ROL/a}", "2a"},
|
||||
{ss, " STA $1234,Y", "{STA/absY $1234}", "993412"},
|
||||
{ss, " BEQ $2343", "{BEQ $2343}", "f0fc"},
|
||||
{ss, " BEQ $2345", "{BEQ $2345}", "f0fe"},
|
||||
{ss, " BEQ $2347", "{BEQ $2347}", "f000"},
|
||||
{ss, " CMP #';'+1", "{CMP (lsb (+ $003b $0001))}", "c93c"},
|
||||
{ss, " JMP $1234", "{JMP $1234}", "4c3412"},
|
||||
{ss, " JMP ($1234)", "{JMP $1234}", "6c3412"},
|
||||
{ss, " LDA #$12", "{LDA (lsb $0012)}", "a912"},
|
||||
{ss, " LDA $12", "{LDA $0012}", "a512"},
|
||||
{ss, " LDA $12,X", "{LDA $0012}", "b512"},
|
||||
{ss, " LDA $1234", "{LDA $1234}", "ad3412"},
|
||||
{ss, " LDA $1234,X", "{LDA $1234}", "bd3412"},
|
||||
{ss, " LDA ($12),Y", "{LDA $0012}", "b112"},
|
||||
{ss, " LDA ($12,X)", "{LDA $0012}", "a112"},
|
||||
{ss, " LDX #']+$80", "{LDX (lsb (+ $005d $0080))}", "a2dd"},
|
||||
{ss, " LDX $12,Y", "{LDX $0012}", "b612"},
|
||||
{ss, " ROL Comment after two spaces", "{ROL}", "2a"},
|
||||
{ss, " ROL X", "{ROL}", "2a"}, // two spaces = comment
|
||||
{ss, " ROL $12", "{ROL $0012}", "2612"},
|
||||
{ss, " ROL $1234", "{ROL $1234}", "2e3412"},
|
||||
{ss, " ROL", "{ROL}", "2a"},
|
||||
{ss, " STA $1234,Y", "{STA $1234}", "993412"},
|
||||
{ss, "* Comment", "{-}", ""},
|
||||
{ss, "A.B .EQ *-C.D", "{= 'A.B' (- * C.D)}", ""},
|
||||
{ss, "Label", "{- 'Label'}", ""},
|
||||
@ -212,7 +212,7 @@ func TestSimpleCommonFunctions(t *testing.T) {
|
||||
{ss, ` .AT -DABCD`, "{data/b}", "c1c243"},
|
||||
{ss, ` .AT /ABC/`, "{data/b}", "4142c3"},
|
||||
{ss, `>SAM AB,$12,"A B","A, B, "" C"`, `{call SAM {"AB", "$12", "A B", "A, B, \" C"}}`, ""},
|
||||
// {ss, " LDA #3/0", "{LDA/imm (lsb (/ $0003 $0000))}", "a9ff"},
|
||||
// {ss, " LDA #3/0", "{LDA (lsb (/ $0003 $0000))}", "a9ff"},
|
||||
}
|
||||
|
||||
// TODO(zellyn): Add tests for finalization of four SCMA directives:
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/zellyn/go6502/asm/context"
|
||||
"github.com/zellyn/go6502/asm/expr"
|
||||
"github.com/zellyn/go6502/asm/lines"
|
||||
"github.com/zellyn/go6502/opcodes"
|
||||
)
|
||||
|
||||
type Type int
|
||||
@ -59,22 +58,21 @@ const (
|
||||
)
|
||||
|
||||
type I struct {
|
||||
Type Type // Type of instruction
|
||||
Label string // Text of label part
|
||||
MacroArgs []string // Macro args
|
||||
Command string // Text of command part
|
||||
TextArg string // Text of argument part
|
||||
Exprs []*expr.E // Expression(s)
|
||||
Data []byte // Actual bytes
|
||||
Width uint16 // width in bytes
|
||||
Final bool // Do we know the actual bytes yet?
|
||||
Op byte // Opcode
|
||||
Mode opcodes.AddressingMode // Opcode mode
|
||||
Value uint16 // For Equates, the value
|
||||
DeclaredLine uint16 // Line number listed in file
|
||||
Line *lines.Line // Line object for this line
|
||||
Addr uint16 // Current memory address
|
||||
Var Variant // Variant of instruction type
|
||||
Type Type // Type of instruction
|
||||
Label string // Text of label part
|
||||
MacroArgs []string // Macro args
|
||||
Command string // Text of command part
|
||||
TextArg string // Text of argument part
|
||||
Exprs []*expr.E // Expression(s)
|
||||
Data []byte // Actual bytes
|
||||
Width uint16 // width in bytes
|
||||
Final bool // Do we know the actual bytes yet?
|
||||
Op byte // Opcode
|
||||
Value uint16 // For Equates, the value
|
||||
DeclaredLine uint16 // Line number listed in file
|
||||
Line *lines.Line // Line object for this line
|
||||
Addr uint16 // Current memory address
|
||||
Var Variant // Variant of instruction type
|
||||
}
|
||||
|
||||
func (i I) TypeString() string {
|
||||
@ -127,37 +125,7 @@ func (i I) TypeString() string {
|
||||
case TypeSetting:
|
||||
return "set"
|
||||
case TypeOp:
|
||||
modeStr := "?"
|
||||
switch i.Mode {
|
||||
case opcodes.MODE_IMPLIED:
|
||||
modeStr = "imp"
|
||||
case opcodes.MODE_ABSOLUTE:
|
||||
modeStr = "abs"
|
||||
case opcodes.MODE_INDIRECT:
|
||||
modeStr = "ind"
|
||||
case opcodes.MODE_RELATIVE:
|
||||
modeStr = "rel"
|
||||
case opcodes.MODE_IMMEDIATE:
|
||||
modeStr = "imm"
|
||||
case opcodes.MODE_ABS_X:
|
||||
modeStr = "absX"
|
||||
case opcodes.MODE_ABS_Y:
|
||||
modeStr = "absY"
|
||||
case opcodes.MODE_ZP:
|
||||
modeStr = "zp"
|
||||
case opcodes.MODE_ZP_X:
|
||||
modeStr = "zpX"
|
||||
case opcodes.MODE_ZP_Y:
|
||||
modeStr = "zpY"
|
||||
case opcodes.MODE_INDIRECT_Y:
|
||||
modeStr = "indY"
|
||||
case opcodes.MODE_INDIRECT_X:
|
||||
modeStr = "indX"
|
||||
case opcodes.MODE_A:
|
||||
modeStr = "a"
|
||||
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", i.Command, modeStr)
|
||||
return i.Command
|
||||
}
|
||||
return "?"
|
||||
}
|
||||
@ -311,7 +279,7 @@ func (i *I) computeOp(c context.Context) error {
|
||||
// If we got here, we got an actual value.
|
||||
|
||||
// It's a branch
|
||||
if i.Mode == opcodes.MODE_RELATIVE {
|
||||
if i.Var == VarOpBranch {
|
||||
curr := c.GetAddr()
|
||||
offset := int32(val) - (int32(curr) + 2)
|
||||
if offset > 127 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user