github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/device/gba/gba.go (about)

     1  // Hand written file mostly derived from https://problemkaputt.de/gbatek.htm
     2  
     3  //go:build gameboyadvance
     4  
     5  package gba
     6  
     7  import (
     8  	"runtime/volatile"
     9  	"unsafe"
    10  )
    11  
    12  // Interrupt numbers.
    13  const (
    14  	IRQ_VBLANK  = 0
    15  	IRQ_HBLANK  = 1
    16  	IRQ_VCOUNT  = 2
    17  	IRQ_TIMER0  = 3
    18  	IRQ_TIMER1  = 4
    19  	IRQ_TIMER2  = 5
    20  	IRQ_TIMER3  = 6
    21  	IRQ_COM     = 7
    22  	IRQ_DMA0    = 8
    23  	IRQ_DMA1    = 9
    24  	IRQ_DMA2    = 10
    25  	IRQ_DMA3    = 11
    26  	IRQ_KEYPAD  = 12
    27  	IRQ_GAMEPAK = 13
    28  )
    29  
    30  // Peripherals
    31  var (
    32  	// Display registers
    33  	DISP = (*DISP_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0000)))
    34  
    35  	// Background control registers
    36  	BGCNT0 = (*BGCNT_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0008)))
    37  	BGCNT1 = (*BGCNT_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x000A)))
    38  	BGCNT2 = (*BGCNT_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x000C)))
    39  	BGCNT3 = (*BGCNT_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x000E)))
    40  
    41  	BG0 = (*BG_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0010)))
    42  	BG1 = (*BG_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0014)))
    43  	BG2 = (*BG_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0018)))
    44  	BG3 = (*BG_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x001C)))
    45  
    46  	BGA2 = (*BG_AFFINE_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0020)))
    47  	BGA3 = (*BG_AFFINE_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0030)))
    48  
    49  	WIN = (*WIN_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0040)))
    50  
    51  	GRAPHICS = (*GRAPHICS_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x004C)))
    52  
    53  	// GBA Sound Channel 1 - Tone & Sweep
    54  	SOUND1 = (*SOUND1_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0060)))
    55  
    56  	// GBA Sound Channel 2 - Tone
    57  	SOUND2 = (*SOUND2_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0068)))
    58  
    59  	// GBA Sound Channel 3 - Wave Output
    60  	SOUND3 = (*SOUND3_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0070)))
    61  
    62  	// GBA Sound Channel 4 - Noise
    63  	SOUND4 = (*SOUND4_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0078)))
    64  
    65  	// GBA Sound Control
    66  	SOUND = (*SOUND_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0080)))
    67  
    68  	DMA0 = (*DMA_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x00B0)))
    69  	DMA1 = (*DMA_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x00BC)))
    70  	DMA2 = (*DMA_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x00C8)))
    71  	DMA3 = (*DMA_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x00D4)))
    72  
    73  	TM0 = (*TIMER_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0100)))
    74  	TM1 = (*TIMER_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0104)))
    75  	TM2 = (*TIMER_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0108)))
    76  	TM3 = (*TIMER_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x010C)))
    77  
    78  	// Communication 1
    79  	SIODATA32 = (*SIODATA32_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0120)))
    80  	SIOMULTI  = (*SIOMULTI_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0120)))
    81  
    82  	KEY = (*KEY_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0130)))
    83  
    84  	// Communication 2
    85  	SIO = (*SIO_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0134)))
    86  
    87  	INTERRUPT = (*INTERRUPT_Type)(unsafe.Add(unsafe.Pointer(REG_BASE), uintptr(0x0200)))
    88  )
    89  
    90  // Main memory sections
    91  const (
    92  	// External work RAM
    93  	MEM_EWRAM uintptr = 0x02000000
    94  
    95  	// Internal work RAM
    96  	MEM_IWRAM uintptr = 0x03000000
    97  
    98  	// I/O registers
    99  	MEM_IO uintptr = 0x04000000
   100  
   101  	// Palette. Note: no 8bit write !!
   102  	MEM_PAL uintptr = 0x05000000
   103  
   104  	// Video RAM. Note: no 8bit write !!
   105  	MEM_VRAM uintptr = 0x06000000
   106  
   107  	// Object Attribute Memory (OAM) Note: no 8bit write !!
   108  	MEM_OAM uintptr = 0x07000000
   109  
   110  	// ROM. No write at all (duh)
   111  	MEM_ROM uintptr = 0x08000000
   112  
   113  	// Static RAM. 8bit write only
   114  	MEM_SRAM uintptr = 0x0E000000
   115  )
   116  
   117  // Main section sizes
   118  const (
   119  	EWRAM_SIZE uintptr = 0x40000
   120  	IWRAM_SIZE uintptr = 0x08000
   121  	PAL_SIZE   uintptr = 0x00400
   122  	VRAM_SIZE  uintptr = 0x18000
   123  	OAM_SIZE   uintptr = 0x00400
   124  	SRAM_SIZE  uintptr = 0x10000
   125  )
   126  
   127  // Sub section sizes
   128  const (
   129  	// BG palette size
   130  	PAL_BG_SIZE = 0x00200
   131  
   132  	// Object palette size
   133  	PAL_OBJ_SIZE = 0x00200
   134  
   135  	// Charblock size
   136  	CBB_SIZE = 0x04000
   137  
   138  	// Screenblock size
   139  	SBB_SIZE = 0x00800
   140  
   141  	// BG VRAM_MODE_0_2 size
   142  	VRAM_BG_SIZE_MODE_0_2 = 0x10000
   143  
   144  	// BG VRAM size
   145  	VRAM_BG_SIZE_MODE_3_5 = 0x14000
   146  
   147  	// Object VRAM size
   148  	VRAM_OBJ_SIZE = 0x08000
   149  
   150  	// Mode 3 buffer size
   151  	M3_SIZE = 0x12C00
   152  
   153  	// Mode 4 buffer size
   154  	M4_SIZE = 0x09600
   155  
   156  	// Mode 5 buffer size
   157  	M5_SIZE = 0x0A000
   158  
   159  	// Bitmap page size
   160  	VRAM_PAGE_SIZE = 0x0A000
   161  )
   162  
   163  // Sub sections
   164  var (
   165  	REG_BASE uintptr = MEM_IO
   166  
   167  	// Background palette address
   168  	MEM_PAL_BG = MEM_PAL
   169  
   170  	// Object palette address
   171  	MEM_PAL_OBJ = MEM_PAL + PAL_BG_SIZE
   172  
   173  	// Front page address
   174  	MEM_VRAM_FRONT = MEM_VRAM
   175  
   176  	// Back page address
   177  	MEM_VRAM_BACK = MEM_VRAM + VRAM_PAGE_SIZE
   178  
   179  	// Object VRAM address - BG Mode 0-2
   180  	MEM_VRAM_OBJ_MODE0_2 = MEM_VRAM + VRAM_BG_SIZE_MODE_0_2
   181  
   182  	// Object VRAM address - BG Mode 3-5
   183  	MEM_VRAM_OBJ_MODE_3_5 = MEM_VRAM + VRAM_BG_SIZE_MODE_3_5
   184  )
   185  
   186  // Display registers
   187  type DISP_Type struct {
   188  	DISPCNT  volatile.Register16
   189  	_        [2]byte
   190  	DISPSTAT volatile.Register16
   191  	VCOUNT   volatile.Register16
   192  }
   193  
   194  // Background control registers
   195  type BGCNT_Type struct {
   196  	CNT volatile.Register16
   197  }
   198  
   199  // Regular background scroll registers. (write only!)
   200  type BG_Type struct {
   201  	HOFS volatile.Register16
   202  	VOFS volatile.Register16
   203  }
   204  
   205  // Affine background parameters. (write only!)
   206  type BG_AFFINE_Type struct {
   207  	PA volatile.Register16
   208  	PB volatile.Register16
   209  	PC volatile.Register16
   210  	PD volatile.Register16
   211  	X  volatile.Register32
   212  	Y  volatile.Register32
   213  }
   214  
   215  type WIN_Type struct {
   216  	// win0 right, left (0xLLRR)
   217  	WIN0H volatile.Register16
   218  
   219  	// win1 right, left (0xLLRR)
   220  	WIN1H volatile.Register16
   221  
   222  	// win0 bottom, top (0xTTBB)
   223  	WIN0V volatile.Register16
   224  
   225  	// win1 bottom, top (0xTTBB)
   226  	WIN1V volatile.Register16
   227  
   228  	// win0, win1 control
   229  	IN volatile.Register16
   230  
   231  	// winOut, winObj control
   232  	OUT volatile.Register16
   233  }
   234  
   235  type GRAPHICS_Type struct {
   236  	// Mosaic control
   237  	MOSAIC volatile.Register32
   238  
   239  	// Alpha control
   240  	BLDCNT volatile.Register16
   241  
   242  	// Fade level
   243  	BLDALPHA volatile.Register16
   244  
   245  	// Blend levels
   246  	BLDY volatile.Register16
   247  }
   248  
   249  type SOUND1_Type struct {
   250  	// Sweep register
   251  	CNT_L volatile.Register16
   252  
   253  	// Duty/Len/Envelope
   254  	CNT_H volatile.Register16
   255  
   256  	// Frequency/Control
   257  	CNT_X volatile.Register16
   258  }
   259  
   260  type SOUND2_Type struct {
   261  	// Duty/Len/Envelope
   262  	CNT_L volatile.Register16
   263  
   264  	// not used
   265  	_ volatile.Register16
   266  
   267  	// Frequency/Control
   268  	CNT_H volatile.Register16
   269  }
   270  
   271  type SOUND3_Type struct {
   272  	// Stop/Wave RAM select
   273  	CNT_L volatile.Register16
   274  
   275  	// Length/Volume
   276  	CNT_H volatile.Register16
   277  
   278  	// Frequency/Control
   279  	CNT_X volatile.Register16
   280  }
   281  
   282  type SOUND4_Type struct {
   283  	// Length/Envelope
   284  	CNT_L volatile.Register16
   285  
   286  	// not used
   287  	_ volatile.Register16
   288  
   289  	// Frequency/Control
   290  	CNT_H volatile.Register16
   291  }
   292  
   293  type SOUND_Type struct {
   294  	// Control Stereo/Volume/Enable
   295  	CNT_L volatile.Register16
   296  
   297  	// Control Mixing/DMA Control
   298  	CNT_H volatile.Register16
   299  
   300  	// Control Sound on/off
   301  	CNT_X volatile.Register16
   302  }
   303  
   304  // DMA
   305  type DMA_Type struct {
   306  	SAD_L volatile.Register16
   307  	SAD_H volatile.Register16
   308  	DAD_L volatile.Register16
   309  	DAD_H volatile.Register16
   310  	CNT_L volatile.Register16
   311  	CNT_H volatile.Register16
   312  }
   313  
   314  // TIMER
   315  type TIMER_Type struct {
   316  	DATA volatile.Register16
   317  	CNT  volatile.Register16
   318  }
   319  
   320  // serial
   321  type SIODATA32_Type struct {
   322  	DATA32_L volatile.Register16
   323  	DATA32_H volatile.Register16
   324  	_        volatile.Register16
   325  	_        volatile.Register16
   326  	CNT      volatile.Register16
   327  	DATA8    volatile.Register16
   328  }
   329  
   330  type SIOMULTI_Type struct {
   331  	MULTI0   volatile.Register16
   332  	MULTI1   volatile.Register16
   333  	MULTI2   volatile.Register16
   334  	MULTI3   volatile.Register16
   335  	CNT      volatile.Register16
   336  	MLT_SEND volatile.Register16
   337  }
   338  
   339  type SIO_Type struct {
   340  	RCNT volatile.Register16
   341  }
   342  
   343  // Keypad registers
   344  type KEY_Type struct {
   345  	INPUT volatile.Register16
   346  	CNT   volatile.Register16
   347  }
   348  
   349  // TODO: Joybus communication
   350  
   351  // Interrupt / System registers
   352  type INTERRUPT_Type struct {
   353  	IE      volatile.Register16
   354  	IF      volatile.Register16
   355  	WAITCNT volatile.Register16
   356  	IME     volatile.Register16
   357  	PAUSE   volatile.Register16
   358  }
   359  
   360  // LCD OBJ Attributes
   361  type OAMOBJ_Type struct {
   362  	ATT0 volatile.Register16
   363  	ATT1 volatile.Register16
   364  	ATT2 volatile.Register16
   365  	_    volatile.Register16
   366  }
   367  
   368  // OAM Rotation/Scaling Parameters
   369  type OAMROT_Type struct {
   370  	_  volatile.Register16
   371  	_  volatile.Register16
   372  	_  volatile.Register16
   373  	PA volatile.Register16
   374  	_  volatile.Register16
   375  	_  volatile.Register16
   376  	_  volatile.Register16
   377  	PB volatile.Register16
   378  	_  volatile.Register16
   379  	_  volatile.Register16
   380  	_  volatile.Register16
   381  	PC volatile.Register16
   382  	_  volatile.Register16
   383  	_  volatile.Register16
   384  	_  volatile.Register16
   385  	PD volatile.Register16
   386  }
   387  
   388  // Constants for DISP: display
   389  const (
   390  	// BGMODE: background mode.
   391  	// Position of BGMODE field.
   392  	DISPCNT_BGMODE_Pos = 0x0
   393  	// Bit mask of BGMODE field.
   394  	DISPCNT_BGMODE_Msk = 0x4
   395  	// BG Mode 0.
   396  	DISPCNT_BGMODE_0 = 0x0
   397  	// BG Mode 1.
   398  	DISPCNT_BGMODE_1 = 0x1
   399  	// BG Mode 2.
   400  	DISPCNT_BGMODE_2 = 0x2
   401  	// BG Mode 3.
   402  	DISPCNT_BGMODE_3 = 0x3
   403  	// BG Mode 4.
   404  	DISPCNT_BGMODE_4 = 0x4
   405  
   406  	// FRAMESELECT: frame select (mode 4 and 5 only).
   407  	DISPCNT_FRAMESELECT_Pos    = 0x4
   408  	DISPCNT_FRAMESELECT_FRAME0 = 0x0
   409  	DISPCNT_FRAMESELECT_FRAME1 = 0x1
   410  
   411  	// HBLANKINTERVAL: 1=Allow access to OAM during H-Blank
   412  	DISPCNT_HBLANKINTERVAL_Pos     = 0x5
   413  	DISPCNT_HBLANKINTERVAL_NOALLOW = 0x0
   414  	DISPCNT_HBLANKINTERVAL_ALLOW   = 0x1
   415  
   416  	// OBJCHARVRAM: (0=Two dimensional, 1=One dimensional)
   417  	DISPCNT_OBJCHARVRAM_Pos = 0x6
   418  	DISPCNT_OBJCHARVRAM_2D  = 0x0
   419  	DISPCNT_OBJCHARVRAM_1D  = 0x1
   420  
   421  	// FORCEDBLANK: (1=Allow FAST access to VRAM,Palette,OAM)
   422  	DISPCNT_FORCEDBLANK_Pos     = 0x7
   423  	DISPCNT_FORCEDBLANK_NOALLOW = 0x0
   424  	DISPCNT_FORCEDBLANK_ALLOW   = 0x1
   425  
   426  	// Screen Display BG0
   427  	DISPCNT_SCREENDISPLAY_BG0_Pos     = 0x8
   428  	DISPCNT_SCREENDISPLAY_BG0_ENABLE  = 0x1
   429  	DISPCNT_SCREENDISPLAY_BG0_DISABLE = 0x0
   430  
   431  	// Screen Display BG1
   432  	DISPCNT_SCREENDISPLAY_BG1_Pos     = 0x9
   433  	DISPCNT_SCREENDISPLAY_BG1_ENABLE  = 0x1
   434  	DISPCNT_SCREENDISPLAY_BG1_DISABLE = 0x0
   435  
   436  	// Screen Display BG2
   437  	DISPCNT_SCREENDISPLAY_BG2_Pos     = 0xA
   438  	DISPCNT_SCREENDISPLAY_BG2_ENABLE  = 0x1
   439  	DISPCNT_SCREENDISPLAY_BG2_DISABLE = 0x0
   440  
   441  	// Screen Display BG3
   442  	DISPCNT_SCREENDISPLAY_BG3_Pos     = 0xB
   443  	DISPCNT_SCREENDISPLAY_BG3_ENABLE  = 0x1
   444  	DISPCNT_SCREENDISPLAY_BG3_DISABLE = 0x0
   445  
   446  	// Screen Display OBJ
   447  	DISPCNT_SCREENDISPLAY_OBJ_Pos     = 0xC
   448  	DISPCNT_SCREENDISPLAY_OBJ_ENABLE  = 0x1
   449  	DISPCNT_SCREENDISPLAY_OBJ_DISABLE = 0x0
   450  
   451  	// Window 0 Display Flag (0=Off, 1=On)
   452  	DISPCNT_WINDOW0_DISPLAY_Pos     = 0xD
   453  	DISPCNT_WINDOW0_DISPLAY_ENABLE  = 0x1
   454  	DISPCNT_WINDOW0_DISPLAY_DISABLE = 0x0
   455  
   456  	// Window 1 Display Flag (0=Off, 1=On)
   457  	DISPCNT_WINDOW1_DISPLAY_Pos     = 0xE
   458  	DISPCNT_WINDOW1_DISPLAY_ENABLE  = 0x1
   459  	DISPCNT_WINDOW1_DISPLAY_DISABLE = 0x0
   460  
   461  	// OBJ Window Display Flag
   462  	DISPCNT_WINDOWOBJ_DISPLAY_Pos     = 0xF
   463  	DISPCNT_WINDOWOBJ_DISPLAY_ENABLE  = 0x1
   464  	DISPCNT_WINDOWOBJ_DISPLAY_DISABLE = 0x0
   465  
   466  	// DISPSTAT: display status.
   467  	// V-blank
   468  	DISPSTAT_VBLANK_Pos     = 0x0
   469  	DISPSTAT_VBLANK_ENABLE  = 0x1
   470  	DISPSTAT_VBLANK_DISABLE = 0x0
   471  
   472  	// H-blank
   473  	DISPSTAT_HBLANK_Pos     = 0x1
   474  	DISPSTAT_HBLANK_ENABLE  = 0x1
   475  	DISPSTAT_HBLANK_DISABLE = 0x0
   476  
   477  	// V-counter match
   478  	DISPSTAT_VCOUNTER_Pos     = 0x2
   479  	DISPSTAT_VCOUNTER_MATCH   = 0x1
   480  	DISPSTAT_VCOUNTER_NOMATCH = 0x0
   481  
   482  	// V-blank IRQ
   483  	DISPSTAT_VBLANK_IRQ_Pos     = 0x3
   484  	DISPSTAT_VBLANK_IRQ_ENABLE  = 0x1
   485  	DISPSTAT_VBLANK_IRQ_DISABLE = 0x0
   486  
   487  	// H-blank IRQ
   488  	DISPSTAT_HBLANK_IRQ_Pos     = 0x4
   489  	DISPSTAT_HBLANK_IRQ_ENABLE  = 0x1
   490  	DISPSTAT_HBLANK_IRQ_DISABLE = 0x0
   491  
   492  	// V-counter IRQ
   493  	DISPSTAT_VCOUNTER_IRQ_Pos     = 0x5
   494  	DISPSTAT_VCOUNTER_IRQ_ENABLE  = 0x1
   495  	DISPSTAT_VCOUNTER_IRQ_DISABLE = 0x0
   496  
   497  	// V-count setting
   498  	DISPSTAT_VCOUNT_SETTING_Pos = 0x8
   499  )
   500  
   501  const (
   502  	BGCNT_PRIORITY_Pos = 0x0
   503  	BGCNT_PRIORITY_Msk = 0x3
   504  
   505  	BGCNT_CHAR_BASE_Pos = 0x2
   506  	BGCNT_CHAR_BASE_Msk = 0x3
   507  
   508  	BGCNT_MOSAIC_Pos     = 0x6
   509  	BGCNT_MOSAIC_DISABLE = 0x0
   510  	BGCNT_MOSAIC_ENABLE  = 0x1
   511  
   512  	BGCNT_COLORS_Pos = 0x7
   513  	BGCNT_COLORS_16  = 0x0
   514  	BGCNT_COLORS_256 = 0x1
   515  
   516  	BGCNT_BASE_Pos = 0x8
   517  	BGCNT_BASE_Msk = 0x1F
   518  
   519  	BGCNT_OVERFLOW_Pos   = 0xD
   520  	BGCNT_OVERFLOW_TRANS = 0x0
   521  	BGCNT_OVERFLOW_WRAP  = 0x1
   522  
   523  	BGCNT_SIZE_Pos = 0xE
   524  	BGCNT_SIZE_Msk = 0x3
   525  )
   526  
   527  const (
   528  	BG_HOFS_Pos = 0x0
   529  	BG_HOFS_Msk = 0x1FF
   530  
   531  	BG_VOFS_Pos = 0x0
   532  	BG_VOFS_Msk = 0x1FF
   533  )
   534  
   535  // Constants for TIMER
   536  const (
   537  	// PRESCALER: Prescaler Selection (0=F/1, 1=F/64, 2=F/256, 3=F/1024)
   538  	// Position of PRESCALER field.
   539  	TIMERCNT_PRESCALER_Pos = 0x0
   540  	// Bit mask of PRESCALER field.
   541  	TIMERCNT_PRESCALER_Msk = 0x2
   542  	// 0=F/1
   543  	TIMERCNT_PRESCALER_1 = 0x0
   544  	// 1=F/64
   545  	TIMERCNT_PRESCALER_64 = 0x1
   546  	// 2=F/256
   547  	TIMERCNT_PRESCALER_256 = 0x2
   548  	// F/1024
   549  	TIMERCNT_PRESCALER_1024 = 0x3
   550  
   551  	// COUNTUP: Count-up Timing   (0=Normal, 1=See below)  ;Not used in TM0CNT_H
   552  	// Position of COUNTUP_TIMING field.
   553  	TIMERCNT_COUNTUP_TIMING_Pos     = 0x2
   554  	TIMERCNT_COUNTUP_TIMING_NORMAL  = 0x0
   555  	TIMERCNT_COUNTUP_TIMING_ENABLED = 0x1
   556  
   557  	TIMERCNT_TIMER_IRQ_ENABLED_Pos = 0x06
   558  	TIMERCNT_TIMER_IRQ_ENABLED     = 0x01
   559  	TIMERCNT_TIMER_IRQ_DISABLED    = 0x00
   560  
   561  	TIMERCNT_TIMER_STARTSTOP_Pos = 0x07
   562  	TIMERCNT_TIMER_START         = 0x1
   563  	TIMERCNT_TIMER_STOP          = 0x0
   564  )
   565  
   566  const (
   567  	// normal mode
   568  	SIOCNT_NORMAL_SC_Pos      = 0x0
   569  	SIOCNT_NORMAL_SC_INTERNAL = 0x1
   570  	SIOCNT_NORMAL_SC_EXTERNAL = 0x0
   571  
   572  	SIOCNT_NORMAL_SCSPEED_Pos  = 0x1
   573  	SIOCNT_NORMAL_SCSPEED_256K = 0x0
   574  	SIOCNT_NORMAL_SCSPEED_2M   = 0x1
   575  
   576  	SIOCNT_NORMAL_SCSTATE_Pos  = 0x2
   577  	SIOCNT_NORMAL_SCSTATE_LOW  = 0x0
   578  	SIOCNT_NORMAL_SCSTATE_HIGH = 0x1
   579  
   580  	SIOCNT_NORMAL_SO_INACTIVE_Pos  = 0x3
   581  	SIOCNT_NORMAL_SO_INACTIVE_LOW  = 0x0
   582  	SIOCNT_NORMAL_SO_INACTIVE_HIGH = 0x1
   583  
   584  	SIOCNT_NORMAL_START_Pos    = 0x7
   585  	SIOCNT_NORMAL_START_READY  = 0x0
   586  	SIOCNT_NORMAL_START_ACTIVE = 0x1
   587  
   588  	SIOCNT_NORMAL_LEN_Pos = 0xC
   589  	SIOCNT_NORMAL_LEN8    = 0x0
   590  	SIOCNT_NORMAL_LEN32   = 0x1
   591  
   592  	SIOCNT_NORMAL_MODE_Pos = 0xD
   593  	SIOCNT_NORMAL_MODE     = 0x0
   594  
   595  	// multiplayer mode
   596  	SIOCNT_MULTI_BR_Pos    = 0x0
   597  	SIOCNT_MULTI_BR_Msk    = 0x3
   598  	SIOCNT_MULTI_BR_9600   = 0x0
   599  	SIOCNT_MULTI_BR_38400  = 0x1
   600  	SIOCNT_MULTI_BR_57600  = 0x2
   601  	SIOCNT_MULTI_BR_115200 = 0x3
   602  
   603  	SIOCNT_MULTI_SI_Pos    = 0x2
   604  	SIOCNT_MULTI_SI_PARENT = 0x0
   605  	SIOCNT_MULTI_SI_CHILD  = 0x1
   606  
   607  	SIOCNT_MULTI_SD_Pos   = 0x3
   608  	SIOCNT_MULTI_SD_BAD   = 0x0
   609  	SIOCNT_MULTI_SD_READY = 0x1
   610  
   611  	SIOCNT_MULTI_ID_Pos    = 0x4
   612  	SIOCNT_MULTI_ID_Msk    = 0x3
   613  	SIOCNT_MULTI_ID_PARENT = 0x0
   614  	SIOCNT_MULTI_ID_CHILD1 = 0x1
   615  	SIOCNT_MULTI_ID_CHILD2 = 0x2
   616  	SIOCNT_MULTI_ID_CHILD3 = 0x3
   617  
   618  	SIOCNT_MULTI_ERR_Pos    = 0x6
   619  	SIOCNT_MULTI_ERR_NORMAL = 0x0
   620  	SIOCNT_MULTI_ERR_ERROR  = 0x1
   621  
   622  	SIOCNT_MULTI_STARTBUSY_Pos       = 0x7
   623  	SIOCNT_MULTI_STARTBUSY_INACTIVE  = 0x0
   624  	SIOCNT_MULTI_STARTBUSY_STARTBUSY = 0x1
   625  
   626  	SIOCNT_MULTI_MODE_Pos = 0xC
   627  	SIOCNT_MULTI_MODE_Msk = 0x3
   628  	SIOCNT_MULTI_MODE     = 0x01
   629  
   630  	// uart mode
   631  	SIOCNT_UART_BR_Pos    = 0x0
   632  	SIOCNT_UART_BR_Msk    = 0x3
   633  	SIOCNT_UART_BR_9600   = 0x0
   634  	SIOCNT_UART_BR_38400  = 0x1
   635  	SIOCNT_UART_BR_57600  = 0x2
   636  	SIOCNT_UART_BR_115200 = 0x3
   637  
   638  	SIOCNT_UART_CTS_Pos     = 0x2
   639  	SIOCNT_UART_CTS_ALWAYS  = 0x0
   640  	SIOCNT_UART_CTS_SENDLOW = 0x1
   641  
   642  	SIOCNT_UART_PARITY_Pos  = 0x3
   643  	SIOCNT_UART_PARITY_EVEN = 0x0
   644  	SIOCNT_UART_PARITY_ODD  = 0x1
   645  
   646  	SIOCNT_UART_SEND_Pos     = 0x4
   647  	SIOCNT_UART_SEND_NOTFULL = 0x0
   648  	SIOCNT_UART_SEND_FULL    = 0x1
   649  
   650  	SIOCNT_UART_REC_Pos      = 0x5
   651  	SIOCNT_UART_REC_NOTEMPTY = 0x0
   652  	SIOCNT_UART_REC_EMPTY    = 0x1
   653  
   654  	SIOCNT_UART_ERR_Pos     = 0x6
   655  	SIOCNT_UART_ERR_NOERROR = 0x0
   656  	SIOCNT_UART_ERR_ERROR   = 0x1
   657  
   658  	SIOCNT_UART_DATALEN_Pos = 0x7
   659  	SIOCNT_UART_DATALEN_7   = 0x0
   660  	SIOCNT_UART_DATALEN_8   = 0x1
   661  
   662  	SIOCNT_UART_FIFO_Pos     = 0x8
   663  	SIOCNT_UART_FIFO_DISABLE = 0x0
   664  	SIOCNT_UART_FIFO_ENABLE  = 0x1
   665  
   666  	SIOCNT_UART_PARITY_ENABLE_Pos = 0x9
   667  	SIOCNT_UART_PARITY_DISABLE    = 0x0
   668  	SIOCNT_UART_PARITY_ENABLE     = 0x1
   669  
   670  	SIOCNT_UART_SEND_ENABLE_Pos = 0xA
   671  	SIOCNT_UART_SEND_DISABLE    = 0x0
   672  	SIOCNT_UART_SEND_ENABLE     = 0x1
   673  
   674  	SIOCNT_UART_REC_ENABLE_Pos = 0xB
   675  	SIOCNT_UART_REC_DISABLE    = 0x0
   676  	SIOCNT_UART_REC_ENABLE     = 0x1
   677  
   678  	SIOCNT_UART_MODE_Pos = 0xC
   679  	SIOCNT_UART_MODE_Msk = 0x3
   680  	SIOCNT_UART_MODE     = 0x11
   681  
   682  	// IRQs used by all
   683  	SIOCNT_IRQ_Pos     = 0xE
   684  	SIOCNT_IRQ_DISABLE = 0x0
   685  	SIOCNT_IRQ_ENABLE  = 0x1
   686  )
   687  
   688  const (
   689  	SIO_RCNT_MODE_Pos    = 0xF
   690  	SIO_RCNT_MODE_NORMAL = 0x0
   691  	SIO_RCNT_MODE_MULTI  = 0x0
   692  	SIO_RCNT_MODE_UART   = 0x0
   693  )
   694  
   695  // Constants for KEY
   696  const (
   697  	// KEYINPUT
   698  	KEYINPUT_PRESSED           = 0x0
   699  	KEYINPUT_RELEASED          = 0x1
   700  	KEYINPUT_BUTTON_A_Pos      = 0x0
   701  	KEYINPUT_BUTTON_B_Pos      = 0x1
   702  	KEYINPUT_BUTTON_SELECT_Pos = 0x2
   703  	KEYINPUT_BUTTON_START_Pos  = 0x3
   704  	KEYINPUT_BUTTON_RIGHT_Pos  = 0x4
   705  	KEYINPUT_BUTTON_LEFT_Pos   = 0x5
   706  	KEYINPUT_BUTTON_UP_Pos     = 0x6
   707  	KEYINPUT_BUTTON_DOWN_Pos   = 0x7
   708  	KEYINPUT_BUTTON_R_Pos      = 0x8
   709  	KEYINPUT_BUTTON_L_Pos      = 0x9
   710  
   711  	// KEYCNT
   712  	KEYCNT_IGNORE                = 0x0
   713  	KEYCNT_SELECT                = 0x1
   714  	KEYCNT_BUTTON_A_Pos          = 0x0
   715  	KEYCNT_BUTTON_B_Pos          = 0x1
   716  	KEYCNT_BUTTON_SELECT_Pos     = 0x2
   717  	KEYCNT_BUTTON_START_Pos      = 0x3
   718  	KEYCNT_BUTTON_RIGHT_Pos      = 0x4
   719  	KEYCNT_BUTTON_LEFT_Pos       = 0x5
   720  	KEYCNT_BUTTON_UP_Pos         = 0x6
   721  	KEYCNT_BUTTON_DOWN_Pos       = 0x7
   722  	KEYCNT_BUTTON_R_Pos          = 0x8
   723  	KEYCNT_BUTTON_L_Pos          = 0x9
   724  	KEYCNT_BUTTON_IRQ_DISABLE    = 0x0
   725  	KEYCNT_BUTTON_IRQ_ENABLE     = 0x1
   726  	KEYCNT_BUTTON_IRQ_ENABLE_Pos = 0xE
   727  	KEYCNT_BUTTON_IRQ_COND_OR    = 0x0
   728  	KEYCNT_BUTTON_IRQ_COND_AND   = 0x1
   729  	KEYCNT_BUTTON_IRQ_COND_Pos   = 0xF
   730  )
   731  
   732  // Constants for INTERRUPT
   733  const (
   734  	// IE
   735  	INTERRUPT_IE_ENABLED             = 0x1
   736  	INTERRUPT_IE_DISABLED            = 0x0
   737  	INTERRUPT_IE_VBLANK_Pos          = 0x0
   738  	INTERRUPT_IE_HBLANK_Pos          = 0x1
   739  	INTERRUPT_IE_VCOUNTER_MATCH_Pos  = 0x2
   740  	INTERRUPT_IE_TIMER0_OVERFLOW_Pos = 0x3
   741  	INTERRUPT_IE_TIMER1_OVERFLOW_Pos = 0x4
   742  	INTERRUPT_IE_TIMER2_OVERFLOW_Pos = 0x5
   743  	INTERRUPT_IE_TIMER3_OVERFLOW_Pos = 0x6
   744  	INTERRUPT_IE_SERIAL_Pos          = 0x7
   745  	INTERRUPT_IE_DMA0_Pos            = 0x8
   746  	INTERRUPT_IE_DMA1_Pos            = 0x9
   747  	INTERRUPT_IE_DMA2_Pos            = 0xA
   748  	INTERRUPT_IE_DMA3_Pos            = 0xB
   749  	INTERRUPT_IE_KEYPAD_Pos          = 0xC
   750  	INTERRUPT_IE_GAMPAK_Pos          = 0xD
   751  
   752  	// IF
   753  	INTERRUPT_IF_ENABLED             = 0x1
   754  	INTERRUPT_IF_DISABLED            = 0x0
   755  	INTERRUPT_IF_VBLANK_Pos          = 0x0
   756  	INTERRUPT_IF_HBLANK_Pos          = 0x1
   757  	INTERRUPT_IF_VCOUNTER_MATCH_Pos  = 0x2
   758  	INTERRUPT_IF_TIMER0_OVERFLOW_Pos = 0x3
   759  	INTERRUPT_IF_TIMER1_OVERFLOW_Pos = 0x4
   760  	INTERRUPT_IF_TIMER2_OVERFLOW_Pos = 0x5
   761  	INTERRUPT_IF_TIMER3_OVERFLOW_Pos = 0x6
   762  	INTERRUPT_IF_SERIAL_Pos          = 0x7
   763  	INTERRUPT_IF_DMA0_Pos            = 0x8
   764  	INTERRUPT_IF_DMA1_Pos            = 0x9
   765  	INTERRUPT_IF_DMA2_Pos            = 0xA
   766  	INTERRUPT_IF_DMA3_Pos            = 0xB
   767  	INTERRUPT_IF_KEYPAD_Pos          = 0xC
   768  	INTERRUPT_IF_GAMPAK_Pos          = 0xD
   769  )
   770  
   771  const (
   772  	OAMOBJ_ATT0_Y_Pos = 0x0
   773  	OAMOBJ_ATT0_Y_Msk = 0xFF
   774  
   775  	OAMOBJ_ATT0_OM_Pos  = 0x8
   776  	OAMOBJ_ATT0_OM_Msk  = 0x3
   777  	OAMOBJ_ATT0_OM_REG  = 0x0
   778  	OAMOBJ_ATT0_OM_AFF  = 0x1
   779  	OAMOBJ_ATT0_OM_HIDE = 0x2
   780  	OAMOBJ_ATT0_OM_DBL  = 0x3
   781  
   782  	OAMOBJ_ATT0_GM_Pos   = 0xA
   783  	OAMOBJ_ATT0_GM_Msk   = 0x3
   784  	OAMOBJ_ATT0_GM_REG   = 0x0
   785  	OAMOBJ_ATT0_GM_BLEND = 0x1
   786  	OAMOBJ_ATT0_GM_WIN   = 0x2
   787  
   788  	OAMOBJ_ATT0_MOSAIC_Pos     = 0xC
   789  	OAMOBJ_ATT0_MOSAIC_DISABLE = 0x0
   790  	OAMOBJ_ATT0_MOSAIC_ENABLE  = 0x1
   791  
   792  	OAMOBJ_ATT0_COLOR_Pos  = 0xD
   793  	OAMOBJ_ATT0_COLOR_4BPP = 0x0
   794  	OAMOBJ_ATT0_COLOR_8BPP = 0x1
   795  
   796  	OAMOBJ_ATT0_SH_Pos    = 0xE
   797  	OAMOBJ_ATT0_SH_Msk    = 0x3
   798  	OAMOBJ_ATT0_SH_SQUARE = 0x0
   799  	OAMOBJ_ATT0_SH_WIDE   = 0x1
   800  	OAMOBJ_ATT0_SH_TALL   = 0x2
   801  
   802  	OAMOBJ_ATT1_X_Pos = 0x0
   803  	OAMOBJ_ATT1_X_Msk = 0xFF
   804  
   805  	OAMOBJ_ATT1_AID_Pos = 0x9
   806  	OAMOBJ_ATT1_AID_Msk = 0x1F
   807  
   808  	OAMOBJ_ATT1_HF_Pos    = 0xC
   809  	OAMOBJ_ATT1_HF_NOFLIP = 0x0
   810  	OAMOBJ_ATT1_HF_FLIP   = 0x1
   811  
   812  	OAMOBJ_ATT1_VF_Pos    = 0xD
   813  	OAMOBJ_ATT1_VF_NOFLIP = 0x0
   814  	OAMOBJ_ATT1_VF_FLIP   = 0x1
   815  
   816  	OAMOBJ_ATT1_SZ_Pos = 0xE
   817  	OAMOBJ_ATT1_SZ_Msk = 0x3
   818  
   819  	OAMOBJ_ATT2_TID_Pos = 0x0
   820  	OAMOBJ_ATT2_TID_Msk = 0xFF
   821  
   822  	OAMOBJ_ATT2_PR_Pos = 0xA
   823  	OAMOBJ_ATT2_PR_Msk = 0x3
   824  
   825  	OAMOBJ_ATT2_PB_Pos = 0xC
   826  	OAMOBJ_ATT2_PB_Msk = 0xF
   827  )