i6502/instruction.go

29 lines
977 B
Go
Raw Permalink Normal View History

2014-08-13 11:51:53 +00:00
package i6502
import (
"fmt"
)
type Instruction struct {
2014-08-17 13:53:35 +00:00
OpType // Embed OpType
2014-08-13 11:51:53 +00:00
2014-08-17 13:53:35 +00:00
Op8 byte // 8-bit operand for 2-byte instructions
Op16 uint16 // 16-bit operand for 3-byte instructions
2014-08-13 11:51:53 +00:00
2014-08-17 13:53:35 +00:00
Address uint16 // Address location where this instruction got read, for debugging purposes
2014-08-13 11:51:53 +00:00
}
2014-08-17 13:53:35 +00:00
// Return a string containing debug information about the instruction and operands.
2014-08-13 11:51:53 +00:00
func (i Instruction) String() (output string) {
switch i.Size {
case 1:
output = fmt.Sprintf("~~~ 0x%04X: 0x%02X - %s [%s] {%d}\n", i.Address, i.Opcode, instructionNames[i.opcodeId], addressingNames[i.addressingId], i.Cycles)
2014-08-13 11:51:53 +00:00
case 2:
output = fmt.Sprintf("~~~ 0x%04X: 0x%02X - %s 0x%02X [%s] {%d}\n", i.Address, i.Opcode, instructionNames[i.opcodeId], i.Op8, addressingNames[i.addressingId], i.Cycles)
2014-08-13 11:51:53 +00:00
case 3:
output = fmt.Sprintf("~~~ 0x%04X: 0x%02X - %s 0x%04X [%s] {%d}\n", i.Address, i.Opcode, instructionNames[i.opcodeId], i.Op16, addressingNames[i.addressingId], i.Cycles)
2014-08-13 11:51:53 +00:00
}
return
}