gba

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2025 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AND = iota
	EOR
	SUB
	RSB
	ADD
	ADC
	SBC
	RSC
	TST
	TEQ
	CMP
	CMN
	ORR
	MOV
	BIC
	MVN
)
View Source
const (
	MUL   = 0b0
	MLA   = 0b1
	UMAAL = 0b010
	UMULL = 0b100
	UMLAL = 0b101
	SMULL = 0b110
	SMLAL = 0b111
)
View Source
const (
	STR = iota
	LDR_PLD
)
View Source
const (
	RESERVED = 0
	STRH     = 1
	LDRD     = 2
	STRD     = 3

	LDRH  = 1
	LDRSB = 2
	LDRSH = 3
)
View Source
const (
	PRIV_MASK  uint32 = 0xF8FF_03DF
	USR_MASK   uint32 = 0xF8FF_0000
	STATE_MASK uint32 = 0x0100_0020
)
View Source
const (
	INTRWAIT_NONE   = 0
	INTRWAIT_VBLANK = 1
)
View Source
const (
	SYS_SoftReset                      = 0x00
	SYS_RegisterRamReset               = 0x01
	SYS_Halt                           = 0x02
	SYS_StopSleep                      = 0x03
	SYS_IntrWait                       = 0x04
	SYS_VBlankIntrWait                 = 0x05
	SYS_Div                            = 0x06
	SYS_DivArm                         = 0x07
	SYS_Sqrt                           = 0x08
	SYS_ArcTan                         = 0x09
	SYS_ArcTan2                        = 0x0A
	SYS_CpuSet                         = 0x0B
	SYS_CpuFastSet                     = 0x0C
	SYS_GetBiosChecksum                = 0x0D
	SYS_BgAffineSet                    = 0x0E
	SYS_ObjAffineSet                   = 0x0F
	SYS_BitUnPack                      = 0x10
	SYS_LZ77UnCompReadNormalWrite8bit  = 0x11
	SYS_LZ77UnCompReadNormalWrite16bit = 0x12
	SYS_HuffUnCompReadNormal           = 0x13
	SYS_RLUnCompReadNormalWrite8bit    = 0x14
	SYS_RLUnCompReadNormalWrite16bit   = 0x15
	SYS_Diff8bitUnFilterWrite8bit      = 0x16
	SYS_Diff8bitUnFilterWrite16bit     = 0x17
	SYS_Diff16bitUnFilter              = 0x18
	SYS_SoundBias                      = 0x19
	SYS_SoundDriverInit                = 0x1A
	SYS_SoundDriverMode                = 0x1B
	SYS_SoundDriverMain                = 0x1C
	SYS_SoundDriverVSync               = 0x1D
	SYS_SoundChannelClear              = 0x1E
	SYS_MidiKey2Freq                   = 0x1F
	SYS_SoundWhatever0                 = 0x20
	SYS_SoundWhatever1                 = 0x21
	SYS_SoundWhatever2                 = 0x22
	SYS_SoundWhatever3                 = 0x23
	SYS_SoundWhatever4                 = 0x24
	SYS_MultiBoot                      = 0x25
	SYS_HardReset                      = 0x26
	SYS_CustomHalt                     = 0x27
	SYS_SoundDriverVSyncOff            = 0x28
	SYS_SoundDriverVSyncOn             = 0x29
	SYS_SoundGetJumpList               = 0x2A
)
View Source
const (
	SP = 13
	LR = 14
	PC = 15

	FLAG_N = 31
	FLAG_Z = 30
	FLAG_C = 29
	FLAG_V = 28
	FLAG_Q = 27
	FLAG_I = 7
	FLAG_F = 6
	FLAG_T = 5

	MODE_USR = 0x10
	MODE_FIQ = 0x11
	MODE_IRQ = 0x12
	MODE_SWI = 0x13
	MODE_ABT = 0x17
	MODE_UND = 0x1B
	MODE_SYS = 0x1F

	BIOS_STARTUP  = 0
	BIOS_SWI      = 1
	BIOS_IRQ      = 2
	BIOS_IRQ_POST = 3
)
View Source
const (
	DMA_MODE_IMM = 0
	DMA_MODE_VBL = 1
	DMA_MODE_HBL = 2
	DMA_MODE_REF = 3

	DMA_ADJ_INC = 0
	DMA_ADJ_DEC = 1
	DMA_ADJ_NON = 2
	DMA_ADJ_RES = 3

	IRQ_DMA_0 = 8
	IRQ_DMA_1 = 9
	IRQ_DMA_2 = 10
	IRQ_DMA_3 = 11
)
View Source
const (
	VEC_RESET         = 0x00
	VEC_UND           = 0x04
	VEC_SWI           = 0x08
	VEC_PREFETCHABORT = 0x0C
	VEC_DATAABORT     = 0x10
	VEC_ADDR26BIT     = 0x14
	VEC_IRQ           = 0x18
	VEC_FIQ           = 0x1C
)
View Source
const (
	SCREEN_WIDTH  = 240
	SCREEN_HEIGHT = 160

	NUM_SCANLINES   = SCREEN_HEIGHT + 68
	CYCLES_HDRAW    = 1006
	CYCLES_HBLANK   = 226
	CYCLES_SCANLINE = CYCLES_HDRAW + CYCLES_HBLANK
	CYCLES_VDRAW    = CYCLES_SCANLINE * SCREEN_HEIGHT
	CYCLES_VBLANK   = CYCLES_SCANLINE * 68
	CYCLES_FRAME    = CYCLES_VDRAW + CYCLES_VBLANK
)
View Source
const (
	MAX_HEIGHT = 256
	MAX_WIDTH  = 512
)
View Source
const (
	BLD_MODE_OFF   = 0
	BLD_MODE_STD   = 1
	BLD_MODE_WHITE = 2
	BLD_MODE_BLACK = 3
)
View Source
const (
	THUMB_AND = iota
	THUMB_EOR
	THUMB_LSL
	THUMB_LSR
	THUMB_ASR
	THUMB_ADC
	THUMB_SBC
	THUMB_ROR
	THUMB_TST
	THUMB_NEG // arm eq is RSBS
	THUMB_CMP
	THUMB_CMN
	THUMB_ORR
	THUMB_MUL
	THUMB_BIC
	THUMB_MVN
)
View Source
const (
	THUMB_ADD = iota
	THUMB_SUB
	THUMB_ADDMOV
	THUMB_SUBImm
)
View Source
const (
	THUMB_IMM_MOV = iota
	THUMB_IMM_CMP
	THUMB_IMM_ADD
	THUMB_IMM_SUB
)
View Source
const (
	THUMB_STRH = iota
	THUMB_LDSB
	THUMB_LDRH
	THUMB_LDSH
)
View Source
const (
	THUMB_STR_REG = iota
	THUMB_STRB_REG
	THUMB_LDR_REG
	THUMB_LDRB_REG
)
View Source
const (
	THUMB_STR_IMM = iota
	THUMB_LDR_IMM
	THUMB_STRB_IMM
	THUMB_LDRB_IMM
)

Variables

View Source
var BANK_ID = map[uint32]uint32{
	MODE_USR: 0,
	MODE_SYS: 0,
	MODE_FIQ: 1,
	MODE_IRQ: 2,
	MODE_SWI: 3,
	MODE_ABT: 4,
	MODE_UND: 5,
}
View Source
var BIOS_ADDR = map[uint32]uint32{
	BIOS_STARTUP:  0xE129F000,
	BIOS_SWI:      0xE3A02004,
	BIOS_IRQ:      0xE25EF004,
	BIOS_IRQ_POST: 0xE55EC002,
}
View Source
var CURR_INST = uint64(0)

Functions

func ArcTan

func ArcTan(gba *GBA)

func ArcTan2

func ArcTan2(gba *GBA)

func BGAffineSet

func BGAffineSet(gba *GBA) int

func BitUnPack

func BitUnPack(gba *GBA)

func CheckEeprom

func CheckEeprom(gba *GBA, addr uint32) bool

func CpuFastSet

func CpuFastSet(gba *GBA) int

func CpuSet

func CpuSet(gba *GBA) int

func DecompressDiff8bit

func DecompressDiff8bit(gba *GBA, src, dst uint32) int

func DecompressDiff16bit

func DecompressDiff16bit(gba *GBA, src, dst uint32) int

func DecompressHuff

func DecompressHuff(gba *GBA, src, dst uint32) int

func DecompressLZ77

func DecompressLZ77(gba *GBA, src, dst uint32, half bool) int

func DecompressRLU

func DecompressRLU(gba *GBA, src, dst uint32) int

func Div

func Div(gba *GBA, arm bool)

func DivOld

func DivOld(gba *GBA, arm bool)

func GetBiosChecksum

func GetBiosChecksum(gba *GBA)

func Huff

func Huff(gba *GBA) int

func HuffUnCompReadNormal

func HuffUnCompReadNormal(gba *GBA) int

func InitTrig

func InitTrig()

func LZ77UnCompReadNormalWrite8bit

func LZ77UnCompReadNormalWrite8bit(gba *GBA) int

func LZ77UnCompReadNormalWrite16bit

func LZ77UnCompReadNormalWrite16bit(gba *GBA) int

func MidiKey2Freq

func MidiKey2Freq(gba *GBA)

func ObjAffineSet

func ObjAffineSet(gba *GBA) int

func RLUUnCompReadNormalWrite8bit

func RLUUnCompReadNormalWrite8bit(gba *GBA) int

func RLUUnCompReadNormalWrite16bit

func RLUUnCompReadNormalWrite16bit(gba *GBA) int

func ReadSound

func ReadSound(addr uint32, a *apu.Apu) uint8

func RegisterRamReset

func RegisterRamReset(gba *GBA)

func SoftReset

func SoftReset(gba *GBA)

func Sqrt

func Sqrt(gba *GBA)

func UpdateAffineParams

func UpdateAffineParams(obj *Object, m *Memory)

func WriteSound

func WriteSound(addr uint32, v uint8, a *apu.Apu)

Types

type Alu

type Alu struct {
	Opcode, Rd, Rn, Rm, RnValue, Op2, Inst uint32
	Immediate, Set                         bool
	LogicalFlags, Test                     bool
	Carry                                  bool
}

func NewAluData

func NewAluData(opcode uint32, cpu *Cpu) *Alu

type Background

type Background struct {
	Enabled          bool
	Invalid          bool
	W, H             uint32
	Pa, Pb, Pc, Pd   uint32
	Priority         uint32
	CharBaseBlock    uint32
	Mosaic           bool
	Palette256       bool
	ScreenBaseBlock  uint32
	AffineWrap       bool
	Size             uint32
	XOffset, YOffset uint32

	Affine bool

	//PbCalc, PdCalc float64
	OutX, OutY float64
	// contains filtered or unexported fields
}

func (*Background) BgAffineReset

func (bg *Background) BgAffineReset()

func (*Background) BgAffineUpdate

func (bg *Background) BgAffineUpdate()

type Blend

type Blend struct {
	Mode uint32
	// contains filtered or unexported fields
}

blends are [6]... because Bg0, Bg1, Bg2, Bg3, Obj, Bd

type BlendPalettes

type BlendPalettes struct {
	Bld                                *Blend
	NoBlendPalette, APalette, BPalette uint32
	// contains filtered or unexported fields
}

func NewBlendPalette

func NewBlendPalette(i uint32, bld *Blend, gba *GBA) *BlendPalettes

type Block

type Block struct {
	Opcode, Rn, RnValue, Rlist    uint32
	Pre, Up, PSR, Writeback, Load bool
}

type Cond

type Cond uint32

func (*Cond) GetFlag

func (c *Cond) GetFlag(flag uint32) bool

func (*Cond) SetField

func (c *Cond) SetField(loBit uint32, value uint32)

func (*Cond) SetFlag

func (c *Cond) SetFlag(flag uint32, value bool)

func (*Cond) SetMode

func (c *Cond) SetMode(mode uint32)

func (*Cond) SetThumb

func (c *Cond) SetThumb(value bool, cpu *Cpu)

type Cpu

type Cpu struct {
	Gba *GBA
	Reg Reg
}

func NewCpu

func NewCpu(gba *GBA) *Cpu

func (*Cpu) Alu

func (cpu *Cpu) Alu(opcode uint32)

func (*Cpu) B

func (cpu *Cpu) B(opcode uint32)

func (*Cpu) BX

func (cpu *Cpu) BX(opcode uint32)

func (*Cpu) Block

func (c *Cpu) Block(opcode uint32)

func (*Cpu) CheckCond

func (cpu *Cpu) CheckCond(cond uint32) bool

func (*Cpu) DecodeARM

func (cpu *Cpu) DecodeARM() int

func (*Cpu) DecodeTHUMB

func (cpu *Cpu) DecodeTHUMB() int

func (*Cpu) Execute

func (c *Cpu) Execute() int

func (*Cpu) GetOp2

func (cpu *Cpu) GetOp2(opcode uint32) (uint32, bool)

func (*Cpu) Half

func (c *Cpu) Half(opcode uint32)

func (*Cpu) HiRegBX

func (cpu *Cpu) HiRegBX(opcode uint16) int

func (*Cpu) Mul

func (cpu *Cpu) Mul(opcode uint32)

func (*Cpu) Psr

func (cpu *Cpu) Psr(opcode uint32)

func (*Cpu) Sdt

func (c *Cpu) Sdt(opcode uint32) uint32

func (*Cpu) Swp

func (cpu *Cpu) Swp(opcode uint32)

func (*Cpu) ThumbAddSub

func (cpu *Cpu) ThumbAddSub(opcode uint16)

func (*Cpu) ThumbAlu

func (cpu *Cpu) ThumbAlu(opcode uint16)

type DMA

type DMA struct {
	Gba *GBA
	Idx int

	Src     uint32
	Dst     uint32
	InitSrc uint32
	InitDst uint32

	Control   uint32
	WordCount uint32

	DstAdj uint32
	SrcAdj uint32
	Repeat bool

	DRQ     bool
	Mode    uint32
	IRQ     bool
	Enabled bool

	Value uint32
	// contains filtered or unexported fields
}

func (*DMA) MaskAddr

func (dma *DMA) MaskAddr(v uint32, src bool) uint32

func (*DMA) ReadControl

func (dma *DMA) ReadControl(hi bool) uint8

func (*DMA) WriteControl

func (dma *DMA) WriteControl(v uint8, hi bool)

func (*DMA) WriteCount

func (dma *DMA) WriteCount(v uint8, hi bool)

func (*DMA) WriteDst

func (dma *DMA) WriteDst(v uint8, byte uint32)

func (*DMA) WriteSrc

func (dma *DMA) WriteSrc(v uint8, byte uint32)

type Debugger

type Debugger struct {
	Gba     *GBA
	Version int
}

type Dispcnt

type Dispcnt struct {
	Mode               uint32
	CGB                bool
	DisplayFrame1      bool
	HBlankIntervalFree bool
	OneDimensional     bool
	ForcedBlank        bool
	//DisplayBg [4]bool
	DisplayObj    bool
	DisplayWin0   bool
	DisplayWin1   bool
	DisplayObjWin bool
}

type Dispstat

type Dispstat uint16

func (*Dispstat) GetLYC

func (d *Dispstat) GetLYC() uint8

func (*Dispstat) SetHBlank

func (d *Dispstat) SetHBlank(v bool)

func (*Dispstat) SetVBlank

func (d *Dispstat) SetVBlank(v bool)

func (*Dispstat) SetVCFlag

func (d *Dispstat) SetVCFlag(v bool)

func (*Dispstat) Write

func (d *Dispstat) Write(v uint8, hi bool)

type GBA

type GBA struct {
	Debugger  Debugger
	Cartridge cart.Cartridge
	Cpu       Cpu
	Mem       Memory
	PPU       PPU
	Timers    [4]Timer
	Dma       [4]DMA
	Irq       Irq
	Apu       *apu.Apu

	Paused, Muted, Save, Halted, Drawn bool
	OpenBusOpcode                      uint32
	AccCycles                          uint32
	Keypad                             Keypad

	SoundCycles     uint32
	SoundCyclesMask uint32

	Pixels []byte
	Image  *ebiten.Image

	Frame uint64
	// contains filtered or unexported fields
}

func NewGBA

func NewGBA(path string, ctx *oto.Context) *GBA

func (*GBA) Close

func (gba *GBA) Close()

func (*GBA) ExitException

func (gba *GBA) ExitException(mode uint32)

func (*GBA) InputHandler

func (gba *GBA) InputHandler(keys []ebiten.Key, buttons []ebiten.StandardGamepadButton)

func (*GBA) LoadBios

func (gba *GBA) LoadBios()

func (*GBA) LoadGame

func (gba *GBA) LoadGame(path string)

func (*GBA) SetIdleAddr

func (gba *GBA) SetIdleAddr()

func (*GBA) SoftReset

func (gba *GBA) SoftReset()

func (*GBA) SysCall

func (gba *GBA) SysCall(inst uint32) (int, bool)

func (*GBA) Tick

func (gba *GBA) Tick(cycles uint32)

func (*GBA) ToggleMute

func (gba *GBA) ToggleMute() bool

func (*GBA) TogglePause

func (gba *GBA) TogglePause() bool

func (*GBA) Update

func (gba *GBA) Update()

func (*GBA) UpdateTimers

func (gba *GBA) UpdateTimers(cycles uint32)

func (*GBA) VideoUpdate

func (gba *GBA) VideoUpdate(cycles uint32)

RidgeX/ygba BSD3

type Half

type Half struct {
	Rn, Rd, Imm, Inst, Rm, RdValue, RnValue, RmValue      uint32
	Pre, Up, Immediate, WriteBack, Load, MemoryManagement bool
}

func NewHalf

func NewHalf(opcode uint32, c *Cpu) *Half

type Irq

type Irq struct {
	Gba    *GBA
	IF, IE uint16
	IME    bool

	IdleIrq uint16
}

func (*Irq) ReadIME

func (s *Irq) ReadIME() uint8

func (*Irq) WriteIE

func (s *Irq) WriteIE(v uint8, hi bool)

func (*Irq) WriteIF

func (s *Irq) WriteIF(v uint8, hi bool)

func (*Irq) WriteIME

func (s *Irq) WriteIME(v uint8)

type Keypad

type Keypad struct {
	KEYINPUT uint16
	KEYCNT   uint16
}

type Logger

type Logger struct {
	Instruction    int
	MaxInstruction int
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(path string, gba *GBA) *Logger

func (*Logger) Close

func (l *Logger) Close()

func (*Logger) WriteLog

func (l *Logger) WriteLog()

type Memory

type Memory struct {
	GBA   *GBA
	BIOS  [0x4000]uint8
	WRAM1 [0x40000]uint8
	WRAM2 [0x8000]uint8

	PRAM [0x200]uint16
	VRAM [0x18001]uint8
	OAM  [0x400]uint8
	IO   [0x400]uint8

	BIOS_MODE uint32
	Dispstat  Dispstat
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory(gba *GBA) Memory

func (*Memory) InitSaveLoop

func (m *Memory) InitSaveLoop()

func (*Memory) Read

func (m *Memory) Read(addr uint32) uint8

func (*Memory) Read8

func (m *Memory) Read8(addr uint32) uint32

func (*Memory) Read16

func (m *Memory) Read16(addr uint32) uint32

Accessing SRAM Area by 16bit/32bit Reading retrieves 8bit value from specified address, multiplied by 0101h (LDRH) or by 01010101h (LDR). Writing changes the 8bit value at the specified address only, being set to LSB of (source_data ROR (address*8)).

func (*Memory) Read32

func (m *Memory) Read32(addr uint32) uint32

func (*Memory) ReadBadRom

func (m *Memory) ReadBadRom(addr uint32, bytesRead uint8) uint32

func (*Memory) ReadBios

func (m *Memory) ReadBios(addr uint32) uint8

func (*Memory) ReadIO

func (m *Memory) ReadIO(addr uint32) uint8

func (*Memory) ReadIODirect

func (m *Memory) ReadIODirect(addr uint32, size uint32) uint32

func (*Memory) ReadIODirectByte

func (m *Memory) ReadIODirectByte(addr uint32) uint32

func (*Memory) ReadOpenBus

func (m *Memory) ReadOpenBus(addr uint32) uint8

func (*Memory) ReadSoundIO

func (m *Memory) ReadSoundIO(addr uint32) uint8

func (*Memory) Write

func (m *Memory) Write(addr uint32, v uint8, byteWrite bool)

func (*Memory) Write8

func (m *Memory) Write8(addr uint32, v uint8)

func (*Memory) Write16

func (m *Memory) Write16(addr uint32, v uint16)

func (*Memory) Write32

func (m *Memory) Write32(addr uint32, v uint32)

func (*Memory) WriteIO

func (m *Memory) WriteIO(addr uint32, v uint8)

type Mosaic

type Mosaic struct {
	BgH, BgV, ObjH, ObjV uint32
}

type Object

type Object struct {
	X, Y, W, H     uint32
	Pa, Pb, Pc, Pd float32
	RotScale       bool
	DoubleSize     bool
	Disable        bool
	Mode           uint32
	Mosaic         bool
	Palette256     bool
	Shape          uint32
	HFlip, VFlip   bool
	Size           uint32
	RotParams      uint32
	CharName       uint32
	Priority       uint32
	Palette        uint32
	OneDimensional bool
}

type PPU

type PPU struct {
	Dispcnt Dispcnt

	Objects     [128]Object
	Backgrounds [4]Background
	Windows     Windows
	Blend       Blend
	Mosaic      Mosaic
	// contains filtered or unexported fields
}

func (*PPU) UpdateAffine

func (p *PPU) UpdateAffine(relAddr uint32)

func (*PPU) UpdateBackgrounds

func (p *PPU) UpdateBackgrounds(addr, v uint32)

func (*PPU) UpdateOAM

func (p *PPU) UpdateOAM(relAddr uint32)

func (*PPU) UpdatePPU

func (p *PPU) UpdatePPU(addr uint32, v uint32)

func (*PPU) UpdateWin

func (p *PPU) UpdateWin(addr uint32, v uint32)

type PSR

type PSR struct {
	Opcode, Rd, Rm, Shift, Imm       uint32
	SPSR, MSR, Immediate, F, S, X, C bool
}

func NewPSR

func NewPSR(opcode uint32, cpu *Cpu) *PSR

type Reg

type Reg struct {
	R    [16]uint32
	SP   [6]uint32
	LR   [6]uint32
	FIQ  [5]uint32 // r8 - r12
	USR  [5]uint32 // r8 - r12 // tmp to restore after FIQ
	CPSR Cond
	SPSR [6]Cond
	// contains filtered or unexported fields
}

type Sdt

type Sdt struct {
	Opcode, Rd, Rn, RnValue, RdValue, Offset, Shift, ShiftType, Rm uint32
	Set, I, Load, WriteBack, MemoryMgmt, Pre, Up, Byte, Pld        bool
}

func NewSdtData

func NewSdtData(opcode uint32, cpu *Cpu) *Sdt

type ThumbAlu

type ThumbAlu struct {
	Opcode, Inst, Rs, Rd uint16
}

type Timer

type Timer struct {
	Gba               *GBA
	Idx               int
	CNT, D            uint32
	SavedInitialValue uint32
	SavedCycles       uint32
	Elapsed           uint32

	Enabled     bool
	OverflowIRQ bool
	Cascade     bool
	Freq        uint32
	FreqShift   uint32
}

func (*Timer) ReadCnt

func (t *Timer) ReadCnt(hi bool) uint8

func (*Timer) ReadD

func (t *Timer) ReadD(hi bool) uint8

func (*Timer) Update

func (t *Timer) Update(overflow bool, cycles uint32) bool

func (*Timer) WriteCnt

func (t *Timer) WriteCnt(v uint8, hi bool)

func (*Timer) WriteD

func (t *Timer) WriteD(v uint8, hi bool)

type Window

type Window struct {
	Enabled    bool
	L, R, T, B uint32

	InBg         [4]bool
	InObj, InBld bool
	// contains filtered or unexported fields
}

type Windows

type Windows struct {
	Enabled            bool
	Win0, Win1, WinObj Window
	OutBg              [4]bool
	OutObj, OutBld     bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL