1
0
mirror of https://github.com/zellyn/go6502.git synced 2024-06-16 10:29:29 +00:00

Use specific types for enums.

This commit is contained in:
Zellyn Hunter 2013-02-28 16:33:39 -08:00
parent f1299f6f7f
commit 77c24879e3
3 changed files with 21 additions and 20 deletions

View File

@ -25,7 +25,7 @@ func bytesString(byte0, byte1, byte2 byte, length int) string {
// addrString returns the address part of a 6502 assembly language
// 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
addrRel := uint16(int32(pc+2) + int32(int8(byte1)))
switch mode {

View File

@ -11,8 +11,10 @@ import (
)
// Chip versions.
type CpuVersion int
const (
VERSION_6502 = iota
VERSION_6502 CpuVersion = iota
VERSION_65C02
)
@ -76,11 +78,11 @@ type cpu struct {
t Ticker
r registers
oldPC uint16
version int
version CpuVersion
}
// 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.r.P |= FLAG_UNUSED // Set unused flag to 1
return &c

View File

@ -6,8 +6,10 @@ function tables.
package opcodes
// Opcode addressing modes.
type AddressingMode int
const (
MODE_IMPLIED = iota
MODE_IMPLIED AddressingMode = iota
MODE_ABSOLUTE
MODE_INDIRECT
MODE_RELATIVE
@ -22,16 +24,20 @@ const (
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 (
MEM_NONE = 0
MEM_R = 1
MEM_W = 2
MEM_RMW = 3
RW_X ReadWrite = 0 // Don't care
RW_R ReadWrite = 1
RW_W ReadWrite = 2
RW_RMW ReadWrite = 3
)
// Lengths of instructions for each addressing mode.
var ModeLengths = map[int]int{
var ModeLengths = map[AddressingMode]int{
MODE_IMPLIED: 1,
MODE_ABSOLUTE: 3,
MODE_INDIRECT: 3,
@ -47,18 +53,11 @@ var ModeLengths = map[int]int{
MODE_A: 1,
}
const (
RW_X = 0 // Don't care
RW_R = 1
RW_W = 2
RW_RMW = 3
)
// Opcode stores information about instructions.
type Opcode struct {
Name string
Mode int
RW int
Mode AddressingMode
RW ReadWrite
}
// Fake NoOp instruction used when disassembling.