Documentation ¶
Index ¶
- Variables
- type CPU
- type Cartridge
- type CartridgeProps
- type Channel
- type Core
- func (core *Core) BIT(pos byte, getter func() byte)
- func (core *Core) Break(code byte)
- func (core *Core) DoDMA(data byte)
- func (core *Core) DrawScanLine()
- func (core *Core) ExecuteNextOPCode() int
- func (core *Core) ExecuteOPCode(code byte) int
- func (core *Core) GetColour(colourNum byte, address uint16) int
- func (core *Core) GetJoypadStatus() byte
- func (core *Core) Init(romData []byte, u fyne.URI)
- func (core *Core) IsLCDEnabled() bool
- func (core *Core) OP00() int
- func (core *Core) OP01() int
- func (core *Core) OP02() int
- func (core *Core) OP03() int
- func (core *Core) OP04() int
- func (core *Core) OP05() int
- func (core *Core) OP06() int
- func (core *Core) OP07() int
- func (core *Core) OP08() int
- func (core *Core) OP09() int
- func (core *Core) OP0A() int
- func (core *Core) OP0B() int
- func (core *Core) OP0C() int
- func (core *Core) OP0D() int
- func (core *Core) OP0E() int
- func (core *Core) OP0F() int
- func (core *Core) OP10() int
- func (core *Core) OP11() int
- func (core *Core) OP12() int
- func (core *Core) OP13() int
- func (core *Core) OP14() int
- func (core *Core) OP15() int
- func (core *Core) OP16() int
- func (core *Core) OP17() int
- func (core *Core) OP18() int
- func (core *Core) OP19() int
- func (core *Core) OP1A() int
- func (core *Core) OP1B() int
- func (core *Core) OP1C() int
- func (core *Core) OP1D() int
- func (core *Core) OP1E() int
- func (core *Core) OP1F() int
- func (core *Core) OP20() int
- func (core *Core) OP21() int
- func (core *Core) OP22() int
- func (core *Core) OP23() int
- func (core *Core) OP24() int
- func (core *Core) OP25() int
- func (core *Core) OP26() int
- func (core *Core) OP27() int
- func (core *Core) OP28() int
- func (core *Core) OP29() int
- func (core *Core) OP2A() int
- func (core *Core) OP2B() int
- func (core *Core) OP2C() int
- func (core *Core) OP2D() int
- func (core *Core) OP2E() int
- func (core *Core) OP2F() int
- func (core *Core) OP30() int
- func (core *Core) OP31() int
- func (core *Core) OP32() int
- func (core *Core) OP33() int
- func (core *Core) OP34() int
- func (core *Core) OP35() int
- func (core *Core) OP36() int
- func (core *Core) OP37() int
- func (core *Core) OP38() int
- func (core *Core) OP39() int
- func (core *Core) OP3A() int
- func (core *Core) OP3B() int
- func (core *Core) OP3C() int
- func (core *Core) OP3D() int
- func (core *Core) OP3E() int
- func (core *Core) OP3F() int
- func (core *Core) OP40() int
- func (core *Core) OP41() int
- func (core *Core) OP42() int
- func (core *Core) OP43() int
- func (core *Core) OP44() int
- func (core *Core) OP45() int
- func (core *Core) OP46() int
- func (core *Core) OP47() int
- func (core *Core) OP48() int
- func (core *Core) OP49() int
- func (core *Core) OP4A() int
- func (core *Core) OP4B() int
- func (core *Core) OP4C() int
- func (core *Core) OP4D() int
- func (core *Core) OP4E() int
- func (core *Core) OP4F() int
- func (core *Core) OP50() int
- func (core *Core) OP51() int
- func (core *Core) OP52() int
- func (core *Core) OP53() int
- func (core *Core) OP54() int
- func (core *Core) OP55() int
- func (core *Core) OP56() int
- func (core *Core) OP57() int
- func (core *Core) OP58() int
- func (core *Core) OP59() int
- func (core *Core) OP5A() int
- func (core *Core) OP5B() int
- func (core *Core) OP5C() int
- func (core *Core) OP5D() int
- func (core *Core) OP5E() int
- func (core *Core) OP5F() int
- func (core *Core) OP60() int
- func (core *Core) OP61() int
- func (core *Core) OP62() int
- func (core *Core) OP63() int
- func (core *Core) OP64() int
- func (core *Core) OP65() int
- func (core *Core) OP66() int
- func (core *Core) OP67() int
- func (core *Core) OP68() int
- func (core *Core) OP69() int
- func (core *Core) OP6A() int
- func (core *Core) OP6B() int
- func (core *Core) OP6C() int
- func (core *Core) OP6D() int
- func (core *Core) OP6E() int
- func (core *Core) OP6F() int
- func (core *Core) OP70() int
- func (core *Core) OP71() int
- func (core *Core) OP72() int
- func (core *Core) OP73() int
- func (core *Core) OP74() int
- func (core *Core) OP75() int
- func (core *Core) OP76() int
- func (core *Core) OP77() int
- func (core *Core) OP78() int
- func (core *Core) OP79() int
- func (core *Core) OP7A() int
- func (core *Core) OP7B() int
- func (core *Core) OP7C() int
- func (core *Core) OP7D() int
- func (core *Core) OP7E() int
- func (core *Core) OP7F() int
- func (core *Core) OP80() int
- func (core *Core) OP81() int
- func (core *Core) OP82() int
- func (core *Core) OP83() int
- func (core *Core) OP84() int
- func (core *Core) OP85() int
- func (core *Core) OP86() int
- func (core *Core) OP87() int
- func (core *Core) OP88() int
- func (core *Core) OP89() int
- func (core *Core) OP8A() int
- func (core *Core) OP8B() int
- func (core *Core) OP8C() int
- func (core *Core) OP8D() int
- func (core *Core) OP8E() int
- func (core *Core) OP8F() int
- func (core *Core) OP90() int
- func (core *Core) OP91() int
- func (core *Core) OP92() int
- func (core *Core) OP93() int
- func (core *Core) OP94() int
- func (core *Core) OP95() int
- func (core *Core) OP96() int
- func (core *Core) OP97() int
- func (core *Core) OP98() int
- func (core *Core) OP99() int
- func (core *Core) OP9A() int
- func (core *Core) OP9B() int
- func (core *Core) OP9C() int
- func (core *Core) OP9D() int
- func (core *Core) OP9E() int
- func (core *Core) OP9F() int
- func (core *Core) OPA0() int
- func (core *Core) OPA1() int
- func (core *Core) OPA2() int
- func (core *Core) OPA3() int
- func (core *Core) OPA4() int
- func (core *Core) OPA5() int
- func (core *Core) OPA6() int
- func (core *Core) OPA7() int
- func (core *Core) OPA8() int
- func (core *Core) OPA9() int
- func (core *Core) OPAA() int
- func (core *Core) OPAB() int
- func (core *Core) OPAC() int
- func (core *Core) OPAD() int
- func (core *Core) OPAE() int
- func (core *Core) OPAF() int
- func (core *Core) OPB0() int
- func (core *Core) OPB1() int
- func (core *Core) OPB2() int
- func (core *Core) OPB3() int
- func (core *Core) OPB4() int
- func (core *Core) OPB5() int
- func (core *Core) OPB6() int
- func (core *Core) OPB7() int
- func (core *Core) OPB8() int
- func (core *Core) OPB9() int
- func (core *Core) OPBA() int
- func (core *Core) OPBB() int
- func (core *Core) OPBC() int
- func (core *Core) OPBD() int
- func (core *Core) OPBE() int
- func (core *Core) OPBF() int
- func (core *Core) OPC0() int
- func (core *Core) OPC1() int
- func (core *Core) OPC2() int
- func (core *Core) OPC3() int
- func (core *Core) OPC4() int
- func (core *Core) OPC5() int
- func (core *Core) OPC6() int
- func (core *Core) OPC7() int
- func (core *Core) OPC8() int
- func (core *Core) OPC9() int
- func (core *Core) OPCA() int
- func (core *Core) OPCB() int
- func (core *Core) OPCC() int
- func (core *Core) OPCD() int
- func (core *Core) OPCE() int
- func (core *Core) OPCF() int
- func (core *Core) OPD0() int
- func (core *Core) OPD1() int
- func (core *Core) OPD2() int
- func (core *Core) OPD4() int
- func (core *Core) OPD5() int
- func (core *Core) OPD6() int
- func (core *Core) OPD7() int
- func (core *Core) OPD8() int
- func (core *Core) OPD9() int
- func (core *Core) OPDA() int
- func (core *Core) OPDC() int
- func (core *Core) OPDE() int
- func (core *Core) OPDF() int
- func (core *Core) OPE0() int
- func (core *Core) OPE1() int
- func (core *Core) OPE2() int
- func (core *Core) OPE5() int
- func (core *Core) OPE6() int
- func (core *Core) OPE7() int
- func (core *Core) OPE8() int
- func (core *Core) OPE9() int
- func (core *Core) OPEA() int
- func (core *Core) OPEE() int
- func (core *Core) OPEF() int
- func (core *Core) OPF0() int
- func (core *Core) OPF1() int
- func (core *Core) OPF2() int
- func (core *Core) OPF3() int
- func (core *Core) OPF5() int
- func (core *Core) OPF6() int
- func (core *Core) OPF7() int
- func (core *Core) OPF8() int
- func (core *Core) OPF9() int
- func (core *Core) OPFA() int
- func (core *Core) OPFB() int
- func (core *Core) OPFE() int
- func (core *Core) OPFF() int
- func (core *Core) Pause()
- func (core *Core) RL(getter func() byte, setter func(byte))
- func (core *Core) RLC(getter func() byte, setter func(byte))
- func (core *Core) RR(getter func() byte, setter func(byte))
- func (core *Core) RRC(getter func() byte, setter func(byte))
- func (core *Core) ReadMemory(address uint16) byte
- func (core *Core) RenderScreen()
- func (core *Core) RenderSprites()
- func (core *Core) RenderTiles()
- func (core *Core) Resume()
- func (core *Core) Run()
- func (core *Core) SLA(getter func() byte, setter func(byte))
- func (core *Core) SRA(getter func() byte, setter func(byte))
- func (core *Core) SRL(getter func() byte, setter func(byte))
- func (core *Core) SWAP(getter func() byte, setter func(byte))
- func (core *Core) SaveRAM()
- func (core *Core) SetLCDStatus()
- func (core *Core) StackPop() uint16
- func (core *Core) StackPush(val uint16)
- func (core *Core) UpdateGraphics(cycles int)
- func (core *Core) WriteMemory(address uint16, data byte)
- type Flags
- type MBC
- type MBC1
- func (mbc *MBC1) DoChangeHiRomBank(val byte)
- func (mbc *MBC1) DoChangeLoROMBank(val byte)
- func (mbc *MBC1) DoChangeROMRAMMode(val byte)
- func (mbc *MBC1) DoRAMBankChange(val byte)
- func (mbc *MBC1) DoRamBankEnable(address uint16, val byte)
- func (mbc *MBC1) HandleBanking(address uint16, val byte)
- func (mbc *MBC1) ReadRamBank(address uint16) byte
- func (mbc *MBC1) ReadRom(address uint16) byte
- func (mbc *MBC1) ReadRomBank(address uint16) byte
- func (mbc *MBC1) SaveRam(path fyne.URI)
- func (mbc *MBC1) WriteRamBank(address uint16, data byte)
- type MBC2
- func (mbc *MBC2) DoChangeHiRomBank(val byte)
- func (mbc *MBC2) DoChangeLoROMBank(val byte)
- func (mbc *MBC2) DoChangeROMRAMMode(val byte)
- func (mbc *MBC2) DoRAMBankChange(val byte)
- func (mbc *MBC2) DoRamBankEnable(address uint16, val byte)
- func (mbc *MBC2) HandleBanking(address uint16, val byte)
- func (mbc *MBC2) ReadRamBank(address uint16) byte
- func (mbc *MBC2) ReadRom(address uint16) byte
- func (mbc *MBC2) ReadRomBank(address uint16) byte
- func (mbc *MBC2) SaveRam(path fyne.URI)
- func (mbc *MBC2) WriteRamBank(address uint16, data byte)
- type MBC3
- func (mbc *MBC3) DoChangeHiRomBank(val byte)
- func (mbc *MBC3) DoChangeLoROMBank(val byte)
- func (mbc *MBC3) DoChangeROMRAMMode(val byte)
- func (mbc *MBC3) DoRAMBankChange(val byte)
- func (mbc *MBC3) DoRamBankEnable(address uint16, val byte)
- func (mbc *MBC3) HandleBanking(address uint16, val byte)
- func (mbc *MBC3) ReadRamBank(address uint16) byte
- func (mbc *MBC3) ReadRom(address uint16) byte
- func (mbc *MBC3) ReadRomBank(address uint16) byte
- func (mbc *MBC3) SaveRam(path fyne.URI)
- func (mbc *MBC3) WriteRamBank(address uint16, data byte)
- type MBCRom
- func (mbc *MBCRom) HandleBanking(address uint16, val byte)
- func (mbc *MBCRom) ReadRamBank(address uint16) byte
- func (mbc *MBCRom) ReadRom(address uint16) byte
- func (mbc *MBCRom) ReadRomBank(address uint16) byte
- func (mbc *MBCRom) SaveRam(path fyne.URI)
- func (mbc *MBCRom) WriteRamBank(address uint16, data byte)
- type Memory
- type OPCodeUnit
- type Registers
- type Sound
- type Timer
Constants ¶
This section is empty.
Variables ¶
var CBCycles = []int{} //0 1 2 3 4 5 6 7 8 9 a b c d e f /* 256 elements not displayed */
var DAATable = []uint16{}/* 2048 elements not displayed */
Reference: https://github.com/gabrielrcouto/php-terminal-gameboy-emulator/blob/master/src/Data.php
var OPCodeFunctionMap = [0x100]OPCodeUnit{}/* 245 elements not displayed */
var RamBankMap = map[byte]uint8{ byte(0x00): 0, byte(0x01): 1, byte(0x02): 1, byte(0x03): 4, }
RAM bank number is linked to the RAM Size byte (0149).
1 bank = 8 KBytes
0x00 means no bank required.
var RomBankMap = map[byte]uint8{ byte(0x00): 2, byte(0x01): 4, byte(0x02): 8, byte(0x03): 16, byte(0x04): 32, byte(0x05): 64, byte(0x06): 128, byte(0x52): 72, byte(0x53): 80, byte(0x54): 96, }
ROM bank number is linked to the ROM Size byte (0148).
1 bank = 16 KBytes
0x00 means no bank required.
Functions ¶
This section is empty.
Types ¶
type Cartridge ¶
type Cartridge struct { Props *CartridgeProps MBC MBC }
type CartridgeProps ¶
Cartridge props
type Core ¶
type Core struct { Cartridge Cartridge CPU CPU Memory Memory Sound Sound /* +++++++++++++++++++++++ + Serial Port + +++++++++++++++++++++++ */ Serial driver.ChannelIO SerialByte byte InterruptCount int /* +++++++++++++++++++++++ + Joypad + +++++++++++++++++++++++ */ Controller driver.ControllerDriver JoypadStatus byte //Screen pixel data Screen [160][144][3]uint8 ScanLineBG [160]bool //Display driver DisplayDriver driver.DisplayDriver // Signal to tell display driver to draw DrawSignal chan bool /* +++++++++++++++++++++++++++ + Clock and speed options + +++++++++++++++++++++++++++ */ //Frames per-second FPS int //CPU clock Clock int //in CBG mode, clock might change to twice as original SpeedMultiple int /* ++++++++++++++++++++++++++ + Development options + ++++++++++++++++++++++++++ */ //Debug mode Debug bool //Commands num to be executed in DEBUG mode DebugControl uint16 StepExe int /* ++++++++++++++++++++++++++ + Other options + ++++++++++++++++++++++++++ */ ToggleSound bool /* Timer */ Timer Timer Exit bool GameTitle string RamURI fyne.URI // contains filtered or unexported fields }
func (*Core) DoDMA ¶
Perform DMA transfer. The written value specifies the transfer source address divided by 100h, ie. source & destination are:
Source: XX00-XX9F ;XX in range from 00-F1h Destination: FE00-FE9F
func (*Core) ExecuteNextOPCode ¶
Execute the next OPCode and return used CPU clock
func (*Core) ExecuteOPCode ¶
Execute given OPCode and return used CPU clock
func (*Core) GetColour ¶
Get colour id via colour palette and colour Num
0 - WHITE 1 - LIGHT_GRAY 2 - DARK_GRAY 3 - BLACK
TODO: GCB mode
func (*Core) GetJoypadStatus ¶
func (*Core) ReadMemory ¶
func (*Core) RenderScreen ¶
func (core *Core) RenderScreen()
func (*Core) SetLCDStatus ¶
func (core *Core) SetLCDStatus()
* FF41 - STAT - LCDC Status (R/W)
Bit 6 - LYC=LY Coincidence Interrupt (1=Enable) (Read/Write) Bit 5 - Mode 2 OAM Interrupt (1=Enable) (Read/Write) Bit 4 - Mode 1 V-Blank Interrupt (1=Enable) (Read/Write) Bit 3 - Mode 0 H-Blank Interrupt (1=Enable) (Read/Write) Bit 2 - Coincidence Flag (0:LYC<>LY, 1:LYC=LY) (Read Only) Bit 1-0 - Mode Flag (Mode 0-3, see below) (Read Only) 0: During H-Blank 1: During V-Blank 2: During Searching OAM-RAM 3: During Transfering Data to LCD Driver
The two lower STAT bits show the current status of the LCD controller.
Mode 0: The LCD controller is in the H-Blank period and the CPU can access both the display RAM (8000h-9FFFh) and OAM (FE00h-FE9Fh) Mode 1: The LCD contoller is in the V-Blank period (or the display is disabled) and the CPU can access both the display RAM (8000h-9FFFh) and OAM (FE00h-FE9Fh) Mode 2: The LCD controller is reading from OAM memory. The CPU <cannot> access OAM memory (FE00h-FE9Fh) during this period. Mode 3: The LCD controller is reading from both OAM and VRAM, The CPU <cannot> access OAM and VRAM during this period. CGB Mode: Cannot access Palette Data (FF69,FF6B) either.
The following are typical when the display is enabled:
Mode 2 2_____2_____2_____2_____2_____2___________________2____ Mode 3 _33____33____33____33____33____33__________________3___ Mode 0 ___000___000___000___000___000___000________________000 Mode 1 ____________________________________11111111111111_____
The Mode Flag goes through the values 0, 2, and 3 at a cycle of about 109uS. 0 is present about 48.6uS, 2 about 19uS, and 3 about 41uS. This is interrupted every 16.6ms by the VBlank (1). The mode flag stays set at 1 for about 1.08 ms.
Mode 0 is present between 201-207 clks, 2 about 77-83 clks, and 3 about 169-175 clks. A complete cycle through these states takes 456 clks. VBlank lasts 4560 clks. A complete screen refresh occurs every 70224 clks.)
func (*Core) WriteMemory ¶
type Flags ¶
type Flags struct { Zero bool Sub bool HalfCarry bool Carry bool // IME - Interrupt Master Enable Flag (Write Only) // 0 - Disable all Interrupts // 1 - Enable all Interrupts that are enabled in IE Register (FFFF) InterruptMaster bool PendingInterruptEnabled bool }
The Flag Register (lower 8bit of AF register)
Bit Name Set Clr Expl. 7 zf Z NZ Zero Flag 6 n - - Add/Sub-Flag (BCD) 5 h - - Half Carry Flag (BCD) 4 cy C NC Carry Flag 3-0 - - - Not used (always zero)
Contains the result from the recent instruction which has affected flags.
type MBC1 ¶
type MBC1 struct { CurrentROMBank byte RAMBank []byte CurrentRAMBank byte EnableRAM bool ROMBankingMode bool // contains filtered or unexported fields }
====================================
MBC1
func (*MBC1) DoChangeHiRomBank ¶
func (*MBC1) DoChangeLoROMBank ¶
func (*MBC1) DoChangeROMRAMMode ¶
func (*MBC1) DoRAMBankChange ¶
func (*MBC1) DoRamBankEnable ¶
func (*MBC1) HandleBanking ¶
func (*MBC1) ReadRamBank ¶
A000-BFFF - RAM Bank 00-03, if any (Read/Write)
This area is used to address external RAM in the cartridge (if any). External RAM is often battery buffered, allowing to store game positions or high score tables, even if the gameboy is turned off, or if the cartridge is removed from the gameboy. Available RAM sizes are: 2KByte (at A000-A7FF), 8KByte (at A000-BFFF), and 32KByte (in form of four 8K banks at A000-BFFF).
func (*MBC1) ReadRomBank ¶
4000-7FFF - ROM Bank 01-7F (Read Only)
This area may contain any of the further 16KByte banks of the ROM, allowing to address up to 125 ROM Banks (almost 2MByte). As described below, bank numbers 20h, 40h, and 60h cannot be used, resulting in the odd amount of 125 banks.
func (*MBC1) WriteRamBank ¶
type MBC2 ¶
type MBC2 struct { CurrentROMBank byte RAMBank []byte CurrentRAMBank byte EnableRAM bool ROMBankingMode bool // contains filtered or unexported fields }
====================================
MBC2
func (*MBC2) DoChangeHiRomBank ¶
func (*MBC2) DoChangeLoROMBank ¶
func (*MBC2) DoChangeROMRAMMode ¶
func (*MBC2) DoRAMBankChange ¶
func (*MBC2) DoRamBankEnable ¶
func (*MBC2) HandleBanking ¶
func (*MBC2) ReadRamBank ¶
func (*MBC2) ReadRomBank ¶
func (*MBC2) WriteRamBank ¶
type MBC3 ¶
type MBC3 struct { CurrentROMBank byte RAMBank []byte CurrentRAMBank byte EnableRAM bool // contains filtered or unexported fields }
====================================
MBC3
func (*MBC3) DoChangeHiRomBank ¶
func (*MBC3) DoChangeLoROMBank ¶
func (*MBC3) DoChangeROMRAMMode ¶
func (*MBC3) DoRAMBankChange ¶
func (*MBC3) DoRamBankEnable ¶
func (*MBC3) HandleBanking ¶
func (*MBC3) ReadRamBank ¶
func (*MBC3) ReadRomBank ¶
func (*MBC3) WriteRamBank ¶
type MBCRom ¶
type MBCRom struct { // Current ROM-Bank number CurrentROMBank byte RAMBank [0x8000]byte // Current RAM-Bank number CurrentRAMBank byte EnableRAM bool // contains filtered or unexported fields }
==================================== Single ROM without MBC
func (*MBCRom) HandleBanking ¶
func (*MBCRom) ReadRamBank ¶
* Read a byte from RAM bank. In ROM only cartridge, RAM is not supported.
func (*MBCRom) ReadRomBank ¶
* Read a byte from ROM bank. In ROM only cartridge, ROM banking is not supported.
func (*MBCRom) WriteRamBank ¶
* Write a byte from RAM bank. In ROM only cartridge, RAM is not supported.
type Memory ¶
type Memory struct { MainMemory [0x10000]byte // contains filtered or unexported fields }
General Memory Map
0000-3FFF 16KB ROM Bank 00 (in cartridge, fixed at bank 00) 4000-7FFF 16KB ROM Bank 01..NN (in cartridge, switchable bank number) 8000-9FFF 8KB Video RAM (VRAM) (switchable bank 0-1 in CGB Mode) A000-BFFF 8KB External RAM (in cartridge, switchable bank, if any) C000-CFFF 4KB Work RAM Bank 0 (WRAM) D000-DFFF 4KB Work RAM Bank 1 (WRAM) (switchable bank 1-7 in CGB Mode) E000-FDFF Same as C000-DDFF (ECHO) (typically not used) FE00-FE9F Sprite Attribute Table (OAM) FEA0-FEFF Not Usable FF00-FF7F I/O Ports FF80-FFFE High RAM (HRAM) FFFF Interrupt Enable Register
type Registers ¶
Registers
16bit Hi Lo Name/Function AF A - Accumulator & Flags BC B C BC DE D E DE HL H L HL SP - - Stack Pointer PC - - Program Counter/Pointer