mirror of
https://github.com/zellyn/go6502.git
synced 2024-06-25 12:29:33 +00:00
Use specific types for enums.
This commit is contained in:
parent
f1299f6f7f
commit
77c24879e3
|
@ -25,7 +25,7 @@ func bytesString(byte0, byte1, byte2 byte, length int) string {
|
||||||
|
|
||||||
// addrString returns the address part of a 6502 assembly language
|
// addrString returns the address part of a 6502 assembly language
|
||||||
// instruction.
|
// instruction.
|
||||||
func addrString(pc uint16, byte1, byte2 byte, length int, mode int) string {
|
func addrString(pc uint16, byte1, byte2 byte, length int, mode opcodes.AddressingMode) string {
|
||||||
addr16 := uint16(byte1) + uint16(byte2)<<8
|
addr16 := uint16(byte1) + uint16(byte2)<<8
|
||||||
addrRel := uint16(int32(pc+2) + int32(int8(byte1)))
|
addrRel := uint16(int32(pc+2) + int32(int8(byte1)))
|
||||||
switch mode {
|
switch mode {
|
||||||
|
|
|
@ -11,8 +11,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Chip versions.
|
// Chip versions.
|
||||||
|
type CpuVersion int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION_6502 = iota
|
VERSION_6502 CpuVersion = iota
|
||||||
VERSION_65C02
|
VERSION_65C02
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,11 +78,11 @@ type cpu struct {
|
||||||
t Ticker
|
t Ticker
|
||||||
r registers
|
r registers
|
||||||
oldPC uint16
|
oldPC uint16
|
||||||
version int
|
version CpuVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and return a new Cpu object with the given memory, ticker, and of the given version.
|
// Create and return a new Cpu object with the given memory, ticker, and of the given version.
|
||||||
func NewCPU(memory Memory, ticker Ticker, version int) Cpu {
|
func NewCPU(memory Memory, ticker Ticker, version CpuVersion) Cpu {
|
||||||
c := cpu{m: memory, t: ticker, version: version}
|
c := cpu{m: memory, t: ticker, version: version}
|
||||||
c.r.P |= FLAG_UNUSED // Set unused flag to 1
|
c.r.P |= FLAG_UNUSED // Set unused flag to 1
|
||||||
return &c
|
return &c
|
||||||
|
|
|
@ -6,8 +6,10 @@ function tables.
|
||||||
package opcodes
|
package opcodes
|
||||||
|
|
||||||
// Opcode addressing modes.
|
// Opcode addressing modes.
|
||||||
|
type AddressingMode int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MODE_IMPLIED = iota
|
MODE_IMPLIED AddressingMode = iota
|
||||||
MODE_ABSOLUTE
|
MODE_ABSOLUTE
|
||||||
MODE_INDIRECT
|
MODE_INDIRECT
|
||||||
MODE_RELATIVE
|
MODE_RELATIVE
|
||||||
|
@ -22,16 +24,20 @@ const (
|
||||||
MODE_A
|
MODE_A
|
||||||
)
|
)
|
||||||
|
|
||||||
// Opcode read/write semantics
|
// Opcode read/write semantics: does the opcode read, write, or
|
||||||
|
// rmw. Useful to distinguish between instructions further than just
|
||||||
|
// addressing mode.
|
||||||
|
type ReadWrite int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MEM_NONE = 0
|
RW_X ReadWrite = 0 // Don't care
|
||||||
MEM_R = 1
|
RW_R ReadWrite = 1
|
||||||
MEM_W = 2
|
RW_W ReadWrite = 2
|
||||||
MEM_RMW = 3
|
RW_RMW ReadWrite = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
// Lengths of instructions for each addressing mode.
|
// Lengths of instructions for each addressing mode.
|
||||||
var ModeLengths = map[int]int{
|
var ModeLengths = map[AddressingMode]int{
|
||||||
MODE_IMPLIED: 1,
|
MODE_IMPLIED: 1,
|
||||||
MODE_ABSOLUTE: 3,
|
MODE_ABSOLUTE: 3,
|
||||||
MODE_INDIRECT: 3,
|
MODE_INDIRECT: 3,
|
||||||
|
@ -47,18 +53,11 @@ var ModeLengths = map[int]int{
|
||||||
MODE_A: 1,
|
MODE_A: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
RW_X = 0 // Don't care
|
|
||||||
RW_R = 1
|
|
||||||
RW_W = 2
|
|
||||||
RW_RMW = 3
|
|
||||||
)
|
|
||||||
|
|
||||||
// Opcode stores information about instructions.
|
// Opcode stores information about instructions.
|
||||||
type Opcode struct {
|
type Opcode struct {
|
||||||
Name string
|
Name string
|
||||||
Mode int
|
Mode AddressingMode
|
||||||
RW int
|
RW ReadWrite
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fake NoOp instruction used when disassembling.
|
// Fake NoOp instruction used when disassembling.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user