From 77c24879e3a5a06064e9dabaf2f601c19b33e3fd Mon Sep 17 00:00:00 2001 From: Zellyn Hunter Date: Thu, 28 Feb 2013 16:33:39 -0800 Subject: [PATCH] Use specific types for enums. --- asm/disasm.go | 2 +- cpu/cpu.go | 8 +++++--- opcodes/opcodes.go | 31 +++++++++++++++---------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/asm/disasm.go b/asm/disasm.go index e3ab291..4107fbc 100644 --- a/asm/disasm.go +++ b/asm/disasm.go @@ -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 { diff --git a/cpu/cpu.go b/cpu/cpu.go index 59c0776..a93e27e 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -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 diff --git a/opcodes/opcodes.go b/opcodes/opcodes.go index f06ed5a..f2cd1ab 100644 --- a/opcodes/opcodes.go +++ b/opcodes/opcodes.go @@ -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.