gba

package
v0.0.0-...-0e8e2e2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

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 (
	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 (
	PC            = 15
	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
)

Variables

View Source
var CURR_INST = uint64(0)

Functions

func CheckEeprom

func CheckEeprom(gba *GBA, addr uint32) bool

func ReadSound

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

func ReplaceByte

func ReplaceByte(value uint32, newByte uint32, byteOffset uint32) uint32

func UpdateAffineParams

func UpdateAffineParams(obj *Object, m *Memory)

func WriteSound

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

Types

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 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
}

import (

"bufio"
"fmt"

_ "image/png"
"os"

)

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       *arm7.Cpu
	Mem       Memory
	PPU       PPU
	Timers    [4]Timer
	Dma       [4]DMA
	Irq       cpu.Irq
	Apu       *apu.Apu

	Paused, Muted, Save, 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) 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) 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(stdFps bool)

func (*GBA) UpdateTimers

func (gba *GBA) UpdateTimers(cycles uint32)

func (*GBA) VideoUpdate

func (gba *GBA) VideoUpdate(cycles uint32)

RidgeX/ygba BSD3

type Keypad

type Keypad struct {
	KEYINPUT uint16
	KEYCNT   uint16
}

type Logger

type Logger struct {
}
func (d *Debugger) print(i int) {
	reg := &d.Gba.Cpu.Reg
	p := func(a string, b uint32) { fmt.Printf("% 8s: % 9X\n", a, b) }
	s := func(a string) { fmt.Printf("%s\n", a) }

	s("--------  --------")
	fmt.Printf("inst dec %d\n", uint32(i))
	p("inst", uint32(i))

	if d.Gba.Cpu.Reg.isThumb {
		p("opcode", d.Gba.Mem.Read16(reg.R[15]))
	} else {
		p("opcode", d.Gba.Mem.Read32(reg.R[15]))
	}
	mode := d.Gba.Cpu.Reg.getMode()
	s("--------  --------")
	p("r00", reg.R[0])
	p("r01", reg.R[1])
	p("r02", reg.R[2])
	p("r03", reg.R[3])
	p("r04", reg.R[4])
	p("r05", reg.R[5])
	p("r06", reg.R[6])
	p("r07", reg.R[7])
	p("r08", reg.R[8])
	p("r09", reg.R[9])
	p("r10", reg.R[10])
	p("r11", reg.R[11])
	p("r12", reg.R[12])
	p("sp/r13", reg.R[13])
	p("lr/r14", reg.R[14])
	p("pc/r15", reg.R[15])
	s("--------  --------")
	p("cpsr", uint32(reg.CPSR))
	p("spsr", uint32(reg.SPSR[BANK_ID[mode]]))
	p("MODE", BANK_ID[mode])
	//p("0x3007FFC", d.Gba.Mem.Read32(0x3007FFC))
	//p("0x4000004", d.Gba.Mem.Read16(0x4000004))
	p("40000B0", d.Gba.Mem.Read32(0x40000B0))
	//p("4000208", d.Gba.Mem.Read16(0x4000208))
	//p("4000200", d.Gba.Mem.Read16(0x4000200))
	//p("4000004", d.Gba.Mem.Read32(0x4000004))
	//p("4000000", d.Gba.Mem.Read32(0x4000000))
	//p("3000000", d.Gba.Mem.Read32(0x3000000))
	//p("3008000", d.Gba.Mem.Read32(0x3008000))

	s("--------  --------")

	//for i := range len(reg.LR) {
	//	p(fmt.Sprintf("LR %02d", i), uint32(reg.LR[uint32(i)]))
	//}

	//s("--------  --------")
	////p(fmt.Sprintf("4744 %08X", i), d.Gba.Mem.Read32(0x802E7A4))
	//count := 0x20
	//start := 0x6003800 + count*4
	//for i := start; i >= start-(count*4); i -= 4 {
	//	p(fmt.Sprintf("IO %X", i), d.Gba.Mem.Read32(uint32(i)))
	//}

	//s("--------  --------")

	//j := uint32(0x4000208)
	//p(fmt.Sprintf("IME %04X", j), d.Gba.Mem.Read16(uint32(j)))
	//j = uint32(0x4000204)
	//p(fmt.Sprintf("WS  %04X", j), d.gba.Mem.Read16(uint32(j)))
	//j = uint32(0x4000202)
	//p(fmt.Sprintf("IF  %04X", j), d.gba.Mem.Read16(uint32(j)))
	//j = uint32(0x4000200)
	//p(fmt.Sprintf("IE  %04X", j), d.gba.Mem.Read16(uint32(j)))

	//s("\n\n")
	//p(fmt.Sprintf("STACK %X", 0x3007E2E), d.gba.Mem.Read32(0x3007E2E))
	//for i := 0x0400_00E0; i >= 0x0400_00D0; i -= 4 {

	//start := 0x40000E0
	//count := 0x10
	//for i := start; i >= start - (count * 4); i -= 4 {
	//    p(fmt.Sprintf("IO %X", i), d.gba.Mem.Read32(uint32(i)))
	//}
	//s("------")

	//start := 0x3007EB0
	//start := 0x30014B0
	//start := 0xE000080
	//count := 0x20
	//for i := start; i >= start - (count * 4); i -= 4 {
	//    p(fmt.Sprintf("IO %X", i), d.Gba.Mem.Read32(uint32(i)))
	//}
}

func (d *Debugger) dump(s, e uint32) {

	// fix to buffer some day
	tmp := ""

	for i := s; i <= e; i += 4 {
		tmp += fmt.Sprintf("%08X", d.Gba.Mem.Read32(uint32(i)))
	}
	f, err := os.Create("./dump")
	if err != nil {
		panic(err)
	}
	w := bufio.NewWriter(f)
	_, err = w.WriteString(tmp)

	if err != nil {
		panic(err)
	}

	w.Flush()
}

func NewLogger

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

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, _ bool) uint32

func (*Memory) Read16

func (m *Memory) Read16(addr uint32, _ bool) 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, _ bool) 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) ReadPtr

func (m *Memory) ReadPtr(addr uint32, _ bool) (unsafe.Pointer, bool)

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, _ bool)

func (*Memory) Write16

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

func (*Memory) Write32

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

func (*Memory) WriteIO

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

func (*Memory) WritePtr

func (m *Memory) WritePtr(addr uint32, _ bool) (unsafe.Pointer, bool)

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 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