video

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CNT_FBLANK     = 1 << 7
	CNT_3D         = 1 << 3
	CNT_BG0        = 1 << 8
	CNT_BG_EXTPAL  = 1 << 30
	CNT_OBJ_EXTPAL = 1 << 31
)

DISPCNT (0x0400_0000)

View Source
const (
	IN_VBLANK   = 1 << 0
	IN_HBLANK   = 1 << 1
	LYC_MATCH   = 1 << 2
	VBLANK_IRQ  = 1 << 3
	HBLANK_IRQ  = 1 << 4
	LYC_IRQ     = 1 << 5
	DISPSTAT_RO = (IN_VBLANK | IN_HBLANK | LYC_MATCH | (1 << 6)) // 0x47
)

DISPSTAT (0x0400_0004)

View Source
const (
	LCD_ENABLED    = 1 << 0
	PPU1_ENABLED   = 1 << 1
	RASTER_ENABLED = 1 << 2
	GEOM_ENABLED   = 1 << 3
	PPU2_ENABLED   = 1 << 9
	DISPLAY_SWAP   = 1 << 15 // 上画面と下画面を入れ替える
)

POWCNT1: 0x0400_0304 (NDS9)

View Source
const (
	ARM9 = iota
	ARM7
)
View Source
const (
	DMA_VBLANK = 1
	DMA_HBLANK = 2
	DMA_HDRAW  = 3
)
View Source
const (
	VRAM_BANK_A bankID = iota
	VRAM_BANK_B
	VRAM_BANK_C
	VRAM_BANK_D
	VRAM_BANK_E
	VRAM_BANK_F
	VRAM_BANK_G
	VRAM_BANK_H
	VRAM_BANK_I
)
View Source
const KB, MB = 1024, 1024 * 1024

Variables

View Source
var BGbBanks = [3]bankID{VRAM_BANK_C, VRAM_BANK_H, VRAM_BANK_I}
View Source
var VRAMCNT_MASK = [9]uint8{
	0b1001_1011,
	0b1001_1011,
	0b1001_1111,
	0b1001_1111,
	0b1000_0111,
	0b1001_1111,
	0b1001_1111,
	0b1000_0011,
	0b1000_0011,
}
View Source
var VRAMMask = [9]uint32{0x1FFFF, 0x1FFFF, 0x1FFFF, 0x1FFFF, 0xFFFF, 0x3FFF, 0x3FFF, 0x7FFF, 0x3FFF}

Functions

This section is empty.

Types

type CPU

type CPU interface {
	AddEvent(cpu uint8, delay33MHz int64, taskID uint16)
	RegisterTask(name string, cb func(late int64, _ uint64), prio uint8) (taskID uint16)
	IRQ(cpu uint8, irqID int, late33MHz int64)
	CheckDMAs(cpu uint8, mode uint8)
}

type Extpal

type Extpal struct {
	Bg  [(32 * KB) / 2]uint16 // 32KB
	Obj [(8 * KB) / 2]uint16  // 8KB
}

type ExtpalMapping

type ExtpalMapping struct {
	Bg  [4]mapFlag // 4 * 8KB ; e.g [[E, F], [E, F], [E, G], [E, G]] -> スロット0 には バンク E, F がマッピングされている, スロット2 には バンク E, G がマッピングされている
	Obj mapFlag    // 8KB; とりうる値は [], [F], [G], [F, G] の4つのどれか
}

拡張パレットがマッピングされているかどうか 拡張パレットのスロットサイズは8KBなので、それに合わせる ただし、拡張パレットはCPUのアドレス空間には配置されないので、拡張パレットを変更するときは、(例えばエンジンBの場合は、)バンクH,Iをまず 6898000h-689FFFFh と 68A0000h-68A3FFFh にマッピングして書き込んでから、拡張パレットにマッピングする

type Fastmem

type Fastmem struct {
	BGa  [32]([]uint8)
	BGb  [8]([]uint8)
	OBJa [16]([]uint8)
	OBJb [8]([]uint8)
}

最適化用(ほとんどの場合、アドレスに対して1つのバンクがマッピングされるので)

type Mapping

type Mapping struct {
	// マッピングのブロックサイズは全部同じサイズにしたいので、最低サイズに合わせる(例: BGa は 16KB の バンクF, G がマッピングされる可能性があるので 16KB にする)
	BGa  [32]mapFlag // 32 * 16KB = 512KB; e.g. BGa[7] が ((1 << VRAM_BANK_A) | (1 << VRAM_BANK_C) | (1 << VRAM_BANK_D)) -> 0x0601_C000..0601_FFFF に書き込んだとき、バンク A, C, D に書き込む
	BGb  [8]mapFlag  // 8 * 16KB = 128KB
	OBJa [16]mapFlag // 16 * 16KB = 256KB
	OBJb [8]mapFlag  // 8 * 16KB = 128KB
	LCDC mapFlag

	WRAM7   [2]mapFlag       // 2 * 128KB = 256KB (バンクC,Dしかマッピングされないので最低サイズが128KB); e.g. WRAM7[0] が ((1 << VRAM_BANK_C) | (1 << VRAM_BANK_D)) -> wram7領域のオフセット0(NDS7アドレス: 0x0600_0000..0601_FFFF) に書き込んだとき、バンク C, D に書き込む
	Extpal  [2]ExtpalMapping // [EngineA, EngineB], 本来、最低サイズは BG:32KB, OBJ:16KB だがスロットサイズは8KBなので、それに合わせる
	Texture [4]mapFlag       // 4 * 128KB = 512KB (バンクA,B,C,Dしかマッピングされないので最低サイズが128KB)
	Texpal  [6]mapFlag       // 6 * 16KB = 96KB (バンクE,F,Gがマッピングされるので最低サイズが16KB)
}

type PPU

type PPU struct {
	Power bool // falseだとレジスタが読み取り専用になる

	// Registers
	LCDC                       uint32    // DISPCNT
	BGCNT                      [4]uint16 // BGnCNT
	BGOFS                      [4]scroll // BGnOFS
	BG2X, BG2Y, BG3X, BG3Y     uint32
	BG2Xi, BG2Yi, BG3Xi, BG3Yi uint32    // BG2XYとBG3XYの内部(ラッチ)レジスタ(実際にハードウェアに存在)
	BG2P, BG3P                 [4]uint16 // BG2PA, BG2PB, BG2PC, BG2PD, BG3PA, BG3PB, BG3PC, BG3PD
	WININ                      [3]uint8  // WININ0, WININ1, WININ2
	WINOUT                     uint8     // WINOUT
	MOSAIC                     uint16    // 0x0400004C(BG), 0x0400004D(OBJ)
	BLDCNT, BLDALPHA           uint16

	Extpal Extpal // Extended Palettes
	CAPCNT uint32 // DISPCAPCNT (エンジンAのみ)
	// contains filtered or unexported fields
}

2Dエンジン

func (*PPU) ReadIO8

func (p *PPU) ReadIO8(addr uint32) uint8

func (*PPU) ReadIO16

func (p *PPU) ReadIO16(addr uint32) uint16

func (*PPU) ReadIO32

func (p *PPU) ReadIO32(addr uint32) uint32

func (*PPU) ReadPalette

func (p *PPU) ReadPalette(width int, addr uint32) uint32

func (*PPU) Reset

func (p *PPU) Reset()

func (*PPU) WriteIO8

func (p *PPU) WriteIO8(addr uint32, data uint8)

func (*PPU) WriteIO16

func (p *PPU) WriteIO16(addr uint32, data uint16)

func (*PPU) WriteIO32

func (p *PPU) WriteIO32(addr uint32, data uint32)

func (*PPU) WritePalette

func (p *PPU) WritePalette(width int, addr uint32, value uint32)

type VRAM

type VRAM struct {
	STAT    uint8    // NDS7.0x04000240
	Cnt     [9]uint8 // bit0-2: MST, bit3-5: Offset, bit7: Enable(NDS9アドレス空間にマッピングされているか)
	Data    [656 * KB]uint8
	Bank    [9][]uint8 // A:128KB, B:128KB, C:128KB, D:128KB, E:64KB, F:16KB, G:16KB, H:32KB, I:16KB
	Mapping Mapping
	Tracker vramTracking // 3Dエンジン や その他コンポーネント とのVRAMのコピーのためにVRAMの変更を追跡する
	Ptr     Fastmem
}

func (*VRAM) Read

func (v *VRAM) Read(width int, addr uint32) uint32

func (*VRAM) ReadABG

func (v *VRAM) ReadABG(width int, addr uint32) uint32

ReadABG for BG(Engine A, 0x0600_0000, 512KB)

func (*VRAM) ReadAOBJ

func (v *VRAM) ReadAOBJ(width int, addr uint32) uint32

ReadAOBJ for OBJ(Engine A, 0x0640_0000)

func (*VRAM) ReadBBG

func (v *VRAM) ReadBBG(width int, addr uint32) uint32

ReadBBG for BG(Engine B, 0x0620_0000)

func (*VRAM) ReadBOBJ

func (v *VRAM) ReadBOBJ(width int, addr uint32) uint32

ReadBOBJ for OBJ(Engine B, 0x0660_0000)

func (*VRAM) ReadVRAM_LCDC

func (v *VRAM) ReadVRAM_LCDC(width int, addr uint32) uint32

func (*VRAM) Reset

func (v *VRAM) Reset()

func (*VRAM) Write

func (v *VRAM) Write(width int, addr, data uint32)

func (*VRAM) WriteABG

func (v *VRAM) WriteABG(width int, addr uint32, value uint32)

func (*VRAM) WriteAOBJ

func (v *VRAM) WriteAOBJ(width int, addr uint32, value uint32)

func (*VRAM) WriteBBG

func (v *VRAM) WriteBBG(width int, addr uint32, value uint32)

func (*VRAM) WriteBOBJ

func (v *VRAM) WriteBOBJ(width int, addr uint32, value uint32)

func (*VRAM) WriteCNT

func (v *VRAM) WriteCNT(bank int, data uint8)

func (*VRAM) WriteVRAM_LCDC

func (v *VRAM) WriteVRAM_LCDC(width int, addr uint32, value uint32)

type Video

type Video struct {
	CPU         CPU
	Frame       uint64
	FrontBuffer uint8 // 0 or 1 (現在画面に表示されているフレームバッファのインデックス)
	FrameBuffer [2][256 * (192 * 2)]color.NRGBA
	Ly          int16
	PPU         [2]*PPU // 2Dエンジン, [EngineA(下画面), EngineB(上画面)] (ただしPOWCNT1のDisplay Swapで上下入れ替え可能)
	GPU         *gpu.GPU

	// Memory
	Palette [512 + 512]uint16 // GBAと同じパレットx2(エンジンAとエンジンB), 合計2KB
	VRAM    *VRAM
	OAM     [(1 * KB) * 2]uint8 // GBAと同じOAMx2(エンジンAとエンジンB), 合計2KB

	// Registers
	/*
		  DISPSTAT (0x0400_0004)
		  2DエンジンA,Bに1つずつではなく,ARM9とARM7で1つずつ(VBlankのときにARM7にだけ割り込みをかけたい場合などに使う)
			bit0,1,2 は共有しているらしい (https://discord.com/channels/465585922579103744/667132407262216272/1181684466477973635)
	*/
	STAT    [2]uint16
	Powcnt9 uint16 // POWCNT1

	// Task
	Task struct {
		HBlank uint16 // HBlank タスクID
		HDraw  uint16 // LYをインクリメントするタスクID
	}

	// デバッグ用
	Debug struct {
		SwapBuffer bool // このフレームで SWAP_BUFFERS が実行されたかどうか
	}
	// contains filtered or unexported fields
}

func New

func New(nds CPU, gxfifoirq func(bool)) *Video

func (*Video) ReadVRAM7

func (v *Video) ReadVRAM7(width int, addr uint32) uint32

func (*Video) Reset

func (v *Video) Reset()

func (*Video) Screen

func (v *Video) Screen() []color.NRGBA

func (*Video) SetDISPSTAT

func (v *Video) SetDISPSTAT(n int, val uint16)

func (*Video) SetPOWCNT1

func (v *Video) SetPOWCNT1(val uint16)

POWCNT1: 0x0400_0304 (NDS9)

func (*Video) SetVCOUNT

func (v *Video) SetVCOUNT(val uint16)

func (*Video) VCOUNT

func (v *Video) VCOUNT() uint16

func (*Video) WriteVRAM7

func (v *Video) WriteVRAM7(width int, addr uint32, value uint32)

Directories

Path Synopsis
gpu

Jump to

Keyboard shortcuts

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