Documentation ¶
Overview ¶
Package nes contains everything that lives within the NES system. main entry point above it should be portable.
Index ¶
- Constants
- Variables
- func Adc(self *Cpu)
- func And(self *Cpu)
- func Asl(self *Cpu)
- func Bcc(self *Cpu)
- func Bcs(self *Cpu)
- func Beq(self *Cpu)
- func Bit(self *Cpu)
- func Bmi(self *Cpu)
- func Bne(self *Cpu)
- func BooleanArrayFromByte(b byte) [8]bool
- func Bpl(self *Cpu)
- func Brk(self *Cpu)
- func Bvc(self *Cpu)
- func Bvs(self *Cpu)
- func Clc(self *Cpu)
- func Cld(self *Cpu)
- func Cli(self *Cpu)
- func Clv(self *Cpu)
- func Cmp(self *Cpu)
- func Cpx(self *Cpu)
- func Cpy(self *Cpu)
- func Dec(self *Cpu)
- func Dex(self *Cpu)
- func Dey(self *Cpu)
- func Eor(self *Cpu)
- func Inc(self *Cpu)
- func Inx(self *Cpu)
- func Iny(self *Cpu)
- func Jmp(self *Cpu)
- func Jsr(self *Cpu)
- func Lda(self *Cpu)
- func Ldx(self *Cpu)
- func Ldy(self *Cpu)
- func Lsr(self *Cpu)
- func Nop(self *Cpu)
- func Ora(self *Cpu)
- func Pause()
- func Pha(self *Cpu)
- func Php(self *Cpu)
- func Pla(self *Cpu)
- func Plp(self *Cpu)
- func Rol(self *Cpu)
- func Ror(self *Cpu)
- func Rti(self *Cpu)
- func Rts(self *Cpu)
- func Sbc(self *Cpu)
- func Sec(self *Cpu)
- func Sed(self *Cpu)
- func Sei(self *Cpu)
- func Sta(self *Cpu)
- func Stx(self *Cpu)
- func Sty(self *Cpu)
- func Tax(self *Cpu)
- func Tay(self *Cpu)
- func Tsx(self *Cpu)
- func Txa(self *Cpu)
- func Txs(self *Cpu)
- func Tya(self *Cpu)
- type Cpu
- func (self *Cpu) CheckNZ(value byte)
- func (self *Cpu) DecodeInstruction()
- func (self *Cpu) EmulateCycle()
- func (self *Cpu) GetFlag(flag int) bool
- func (self *Cpu) Init()
- func (self *Cpu) Pull() byte
- func (self *Cpu) Pull16Bit() uint16
- func (self *Cpu) Push(value byte)
- func (self *Cpu) Push16Bit(value uint16)
- func (self *Cpu) ReadAddress(start uint16) uint16
- func (self *Cpu) ReadAddressByte(start uint16) uint8
- func (self *Cpu) ReadWrappedAddress(a uint16) uint16
- func (self *Cpu) SetFlag(flag int, tovalue bool)
- func (self *Cpu) WriteMemory(address uint16, value byte)
- type Nes
- type OpCodeInfo
- type Ppu
- type Rom
- type RomHeader
Constants ¶
const ( Mode_Immediate Mode_Absolute Mode_AbsoluteX Mode_AbsoluteY Mode_Accumulator Mode_Implied Mode_Indirect Mode_IndirectX Mode_IndirectY Mode_Relative Mode_ZeroPage Mode_ZeroPageX Mode_ZeroPageY )
addressing modes
const ( ADC AND ASL BCC BCS BEQ BIT BMI BNE BPL BRK BVC BVS CLC CLD CLI CLV CMP CPX CPY DEC DEX DEY EOR INC INX INY JMP JSR LDA LDX LDY LSR NOP ORA PHA PHP PLA PLP ROL ROR RTI RTS SBC SEC SED SEI STA STX STY TAX TAY TSX TXA TXS TYA )
const ( // _ = iota // 7 6 5 4 3 2 1 0 // N V B D I Z C // 0-C=Carry // 1 Z=Zero Flag // 2 I=Interupt Disable // 3 D=Decimal // 4 B=Brk/software interupt // 5 // 6 V Overflow Flag // 7 N Negative Flag Status_C = iota //Carry Flag Status_Z //Zero Flag Status_I //Interupt Disable Status_D //Decimale Flag, no system need but coded anyway Status_B //If break executed, causing an IRQ Status_V //Overflow Status_N //Negative flag (1 for negative numb) )
const CuclesPerFrame = 29780.5
const CyclesPerSecond = 1789773
CyclesPerSecond = 1.79mhz
Variables ¶
var Blue = "\033[34m"
var Cyan = "\033[36m"
var Gray = "\033[37m"
var Green = "\033[32m"
var OpTable = map[int]OpCodeInfo{}/* 151 elements not displayed */
var Palette = map[int]color.RGBA{
0x00: {0x75, 0x75, 0x75, 0xff},
0x01: {0x27, 0x1B, 0x8F, 0xff},
0x02: {0x00, 0x00, 0xAB, 0xff},
0x03: {0x47, 0x00, 0x9F, 0xff},
0x04: {0x8F, 0x00, 0x77, 0xff},
0x05: {0xAB, 0x00, 0x13, 0xff},
0x06: {0xA7, 0x00, 0x00, 0xff},
0x07: {0x7F, 0x0B, 0x00, 0xff},
0x08: {0x43, 0x2F, 0x00, 0xff},
0x09: {0x00, 0x47, 0x00, 0xff},
0x0A: {0x00, 0x51, 0x00, 0xff},
0x0B: {0x00, 0x3F, 0x17, 0xff},
0x0C: {0x1B, 0x3F, 0x5F, 0xff},
0x0D: {0x00, 0x00, 0x00, 0xff},
0x0E: {0x00, 0x00, 0x00, 0xff},
0x0F: {0x00, 0x00, 0x00, 0xff},
0x10: {0xBC, 0xBC, 0xBC, 0xff},
0x11: {0x00, 0x73, 0xEF, 0xff},
0x12: {0x23, 0x3B, 0xEF, 0xff},
0x13: {0x83, 0x00, 0xF3, 0xff},
0x14: {0xBF, 0x00, 0xBF, 0xff},
0x15: {0xE7, 0x00, 0x5B, 0xff},
0x16: {0xDB, 0x2B, 0x00, 0xff},
0x17: {0xCB, 0x4F, 0x0F, 0xff},
0x18: {0x8B, 0x73, 0x00, 0xff},
0x19: {0x00, 0x97, 0x00, 0xff},
0x1A: {0x00, 0xAB, 0x00, 0xff},
0x1B: {0x00, 0x93, 0x3B, 0xff},
0x1C: {0x00, 0x83, 0x8B, 0xff},
0x1D: {0x00, 0x00, 0x00, 0xff},
0x1E: {0x00, 0x00, 0x00, 0xff},
0x1F: {0x00, 0x00, 0x00, 0xff},
0x20: {0xFF, 0xFF, 0xFF, 0xff},
0x21: {0x3F, 0xBF, 0xFF, 0xff},
0x22: {0x5F, 0x97, 0xFF, 0xff},
0x23: {0xA7, 0x8B, 0xFD, 0xff},
0x24: {0xF7, 0x7B, 0xFF, 0xff},
0x25: {0xFF, 0x77, 0xB7, 0xff},
0x26: {0xFF, 0x77, 0x63, 0xff},
0x27: {0xFF, 0x9B, 0x3B, 0xff},
0x28: {0xF3, 0xBF, 0x3F, 0xff},
0x29: {0x83, 0xD3, 0x13, 0xff},
0x2A: {0x4F, 0xDF, 0x4B, 0xff},
0x2B: {0x58, 0xF8, 0x98, 0xff},
0x2C: {0x00, 0xEB, 0xDB, 0xff},
0x2D: {0x00, 0x00, 0x00, 0xff},
0x2E: {0x00, 0x00, 0x00, 0xff},
0x2F: {0x00, 0x00, 0x00, 0xff},
0x30: {0xFF, 0xFF, 0xFF, 0xff},
0x31: {0xAB, 0xE7, 0xFF, 0xff},
0x32: {0xC7, 0xD7, 0xFF, 0xff},
0x33: {0xD7, 0xCB, 0xFF, 0xff},
0x34: {0xFF, 0xC7, 0xFF, 0xff},
0x35: {0xFF, 0xC7, 0xDB, 0xff},
0x36: {0xFF, 0xBF, 0xB3, 0xff},
0x37: {0xFF, 0xDB, 0xAB, 0xff},
0x38: {0xFF, 0xE7, 0xA3, 0xff},
0x39: {0xE3, 0xFF, 0xA3, 0xff},
0x3A: {0xAB, 0xF3, 0xBF, 0xff},
0x3B: {0xB3, 0xFF, 0xCF, 0xff},
0x3C: {0x9F, 0xFF, 0xF3, 0xff},
0x3D: {0x00, 0x00, 0x00, 0xff},
0x3E: {0x00, 0x00, 0x00, 0xff},
0x3F: {0x00, 0x00, 0x00, 0xff},
}
Palette contains 64 colors, referenced in Hex for rendering. This is the default palette, I think you can have others? No tests for this file, as go coverage requires functions for test coverage.
var Purple = "\033[35m"
var Red = "\033[31m"
var Reset = "\033[0m"
Testing colors
var White = "\033[97m"
var Yellow = "\033[33m"
Functions ¶
func Adc ¶
func Adc(self *Cpu)
Adc Add Memory to Accumulator with Carry Must set Carry and Overflow Flag
func BooleanArrayFromByte ¶
BooleanArrayFromByte Returns an array of booleans from a byte to do easier creation of sprites
func Brk ¶
func Brk(self *Cpu)
// BRK - Force Interupt Chat GPT's description The BRK (Break) instruction on the NES (Nintendo Entertainment System) CPU is used to signal an interrupt and halt the execution of the current program. The BRK instruction consists of a single byte opcode (0x00) and is typically used for software debugging purposes. When the CPU encounters the BRK instruction, it performs the following steps: Push the address of the next instruction on the stack. Set the interrupt flag (I flag) in the status register to prevent any further interrupts. Push the status register on the stack. Load the interrupt vector at address 0xFFFE and jump to that address. The interrupt vector at 0xFFFE is a 16-bit address that points to the location of the interrupt service routine (ISR) for the BRK instruction. The ISR typically contains code that handles the software debugging operations and then returns control to the main program. Once the ISR is finished executing, it will load the program counter with the address that was pushed onto the stack during step 1, then restore the status register from the stack during step 3. The CPU will then continue executing instructions from the program counter that was loaded, as if the BRK instruction never happened. In summary, the NES BRK instruction is used to signal an interrupt and halt the execution of the current program, allowing the CPU to perform a software debugging operation before returning to the main program. push PC+2, push SR
func Pause ¶
func Pause()
Pause is a helper function that lets me manually step through op code execution one at a time
Types ¶
type Cpu ¶
type Cpu struct { PC uint16 //Programing Counter, which instruction to read next SP byte //Stack pointer, //Registers A byte //Accumlator, copying to and from memory + maths fuctions X byte //X Register Y byte //Y Register S byte //Status, 8 flags, for more info see statusflags.go file //64 kb of memory, adressing space of 0x0000 to 0xFFFF Memory [0xFFFF + 1]byte RomReader Rom CycleCount uint64 FrameCount uint64 Quiet bool // // contains filtered or unexported fields }
func (*Cpu) DecodeInstruction ¶
func (self *Cpu) DecodeInstruction()
func (*Cpu) EmulateCycle ¶
func (self *Cpu) EmulateCycle()
func (*Cpu) GetFlag ¶
GetFlag Made possible by http://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit-in-c-c
func (*Cpu) ReadAddress ¶
func (*Cpu) ReadAddressByte ¶
func (*Cpu) ReadWrappedAddress ¶
func (*Cpu) SetFlag ¶
SetFlag was Made possible by http://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit-in-c-c
func (*Cpu) WriteMemory ¶
type Nes ¶
Nes is the top level, representing the physical system, it contains all NES Compontents, trying to keep as close to the original system at possible
type OpCodeInfo ¶
type OpCodeInfo struct { Mode int Operation int No_Bytes byte No_Cycles byte BoundaryCross byte Function fn }
func (*OpCodeInfo) ModeString ¶
func (o *OpCodeInfo) ModeString() string
func (*OpCodeInfo) OperationString ¶
func (o *OpCodeInfo) OperationString() string
func (*OpCodeInfo) RunOperation ¶
func (o *OpCodeInfo) RunOperation(cpu *Cpu)
type Ppu ¶
type Ppu struct { Cycle int // 0-340 ScanLine int // 0-261, 0-239=are visible frames, 240=post, 241-260=vblank, 261=pre Frame uint64 Memory [0x3FFF + 1]byte // 16kb address space. }
func (*Ppu) EmulateCycle ¶
func (p *Ppu) EmulateCycle()
EmulateCycle is called 3 times for ever 1 CPU Cycle. There are 262 Scanlines per frame. Each scanline is 341 PPU Cycles
func (*Ppu) GetColorFromPalette ¶
GetColorFromPalette is used to grab an color.RGBA value from it's hex index of 64 colors. This is mostly used for some basic tests of the default color Palette.
func (*Ppu) GetInfoForPatternTable ¶
func (p *Ppu) GetInfoForPatternTable()