From 11dc1bdad9da6e2021c2f8160a15a3f8e42a560e Mon Sep 17 00:00:00 2001 From: Bradford Lamson-Scribner Date: Wed, 27 May 2020 22:08:30 -0600 Subject: [PATCH] internal/cpu: add cpu status register flags --- README.md | 3 ++- internal/cpu/cpu.go | 38 ++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 62dde7b..952bf92 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,5 @@ Current references: - [6502 memory test](http://www.willegal.net/appleii/6502mem.htm) - [6502 instructions description with undocumented commands](http://www.zimmers.net/anonftp/pub/cbm/documents/chipdata/64doc) - [a rust implementation](https://github.com/alexander-akhmetov/mos6502) -- [MOS hardware manual](http://bytecollector.com/archive/misc/6500-10A_MCS6500hwMan_Jan76.pdf) \ No newline at end of file +- [MOS hardware manual](http://bytecollector.com/archive/misc/6500-10A_MCS6500hwMan_Jan76.pdf) +- [6502 registers](http://www.obelisk.me.uk/6502/registers.html) \ No newline at end of file diff --git a/internal/cpu/cpu.go b/internal/cpu/cpu.go index 0fe8f06..00f33c8 100644 --- a/internal/cpu/cpu.go +++ b/internal/cpu/cpu.go @@ -28,6 +28,8 @@ // // Processor Stack: // LIFO, top down, 8 bit range, 0x0100 - 0x01FF +// +// 6502 instructions have the general form AAABBBCC, where AAA and CC define the opcode, and BBB defines the addressing mode package cpu // addrMode is a type alias for a string, used below for defining addressing modes @@ -50,15 +52,27 @@ const ( ) // Available cpu flags written as binary integer literals +// https://wiki.nesdev.com/w/index.php/Status_flags +// 7 bit 0 +// - - - - - - - - +// N V s s D I Z C +// | | | | | | | | +// | | | | | | | +- Carry +// | | | | | | +--- Zero +// | | | | | + ---- Interrupt Disable +// | | | | + ------ Decimal +// | | + +--------- No CPU effect, see: the B flag +// | + ------------ Overflow +// +--------------- Negative const ( - flagDefault uint8 = 0B_00110000 - flagNegative uint8 = 0B_10000000 - flagOverflow uint8 = 0B_01000000 - flagB uint8 = 0B_00010000 - flagDecimal uint8 = 0B_00001000 - flagInterrupt uint8 = 0B_00000100 - flagZero uint8 = 0B_00000010 - flagCarry uint8 = 0B_00000001 + flagDefault uint8 = 0B_00110000 + flagNegative uint8 = 0B_10000000 + flagOverflow uint8 = 0B_01000000 + flagBrk uint8 = 0B_00010000 + flagDecimalMode uint8 = 0B_00001000 + flagDisableInterrupts uint8 = 0B_00000100 + flagZero uint8 = 0B_00000010 + flagCarry uint8 = 0B_00000001 ) // StackBottom represents the bottom address @@ -69,9 +83,9 @@ type Mos6502 struct { sp uint8 // stack pointer pc uint16 // program counter a uint8 // accumulator register - x uint8 // X index register - y uint8 // Y index register - p uint8 // processor flags + x uint8 // x index register + y uint8 // y index register + ps uint8 // processor status register } // New TODO: docs @@ -82,6 +96,6 @@ func New() *Mos6502 { a: 0, x: 0, y: 0, - p: flagDefault, + ps: flagDefault, } }