diff options
Diffstat (limited to 'arm9/lib')
| -rw-r--r-- | arm9/lib/include/NNS_FND_allocator.h | 34 | ||||
| -rw-r--r-- | arm9/lib/include/NNS_FND_expheap.h | 55 | ||||
| -rw-r--r-- | arm9/lib/include/NNS_FND_heapcommon.h | 26 | ||||
| -rw-r--r-- | arm9/lib/include/NNS_FND_list.h | 20 | ||||
| -rw-r--r-- | arm9/lib/include/OS_irqHandler.h | 2 | ||||
| -rw-r--r-- | arm9/lib/include/consts.h | 1 | ||||
| -rw-r--r-- | arm9/lib/include/gx.h | 23 | ||||
| -rw-r--r-- | arm9/lib/include/registers.h | 38 | ||||
| -rw-r--r-- | arm9/lib/include/tp.h | 8 | ||||
| -rw-r--r-- | arm9/lib/src/GX.c | 52 | 
10 files changed, 224 insertions, 35 deletions
| diff --git a/arm9/lib/include/NNS_FND_allocator.h b/arm9/lib/include/NNS_FND_allocator.h new file mode 100644 index 00000000..48df282a --- /dev/null +++ b/arm9/lib/include/NNS_FND_allocator.h @@ -0,0 +1,34 @@ +#ifndef GUARD_NNS_FND_ALLOCATOR_H
 +#define GUARD_NNS_FND_ALLOCATOR_H
 +
 +#include "NNS_FND_heapcommon.h"
 +
 +typedef struct NNSFndAllocator NNSFndAllocator;
 +
 +typedef void*   (*NNSFndFuncAllocatorAlloc)(
 +    NNSFndAllocator*    pAllocator,
 +    u32                 size);
 +
 +typedef void    (*NNSFndFuncAllocatorFree)(
 +    NNSFndAllocator*    pAllocator,
 +    void*               memBlock);
 +
 +typedef struct NNSFndAllocatorFunc NNSFndAllocatorFunc;
 +
 +struct NNSFndAllocatorFunc
 +{
 +    NNSFndFuncAllocatorAlloc    pfAlloc;
 +    NNSFndFuncAllocatorFree     pfFree;
 +};
 +
 +struct NNSFndAllocator
 +{
 +    NNSFndAllocatorFunc const * pFunc;
 +    void*                       pHeap;
 +    u32                         heapParam1;
 +    u32                         heapParam2;
 +};
 +
 +void NNS_FndInitAllocatorForExpHeap(NNSFndAllocator * pAllocator, NNSFndHeapHandle heap, int alignment);
 +
 +#endif //GUARD_NNS_FND_ALLOCATOR_H
 diff --git a/arm9/lib/include/NNS_FND_expheap.h b/arm9/lib/include/NNS_FND_expheap.h new file mode 100644 index 00000000..c0008f28 --- /dev/null +++ b/arm9/lib/include/NNS_FND_expheap.h @@ -0,0 +1,55 @@ +#ifndef GUARD_NNS_FND_EXPHEAP_H
 +#define GUARD_NNS_FND_EXPHEAP_H
 +
 +#include "NNS_FND_heapcommon.h"
 +
 +typedef struct NNSiFndExpHeapMBlockHead NNSiFndExpHeapMBlockHead;
 +
 +struct NNSiFndExpHeapMBlockHead
 +{
 +    u16                         signature;      // Signature
 +    u16                         attribute;      // Attribute
 +    // [8:groupID]
 +    // [7:alignment]
 +    // [1:temporary flag]
 +
 +    u32                         blockSize;      // Block size (data area only)
 +
 +    NNSiFndExpHeapMBlockHead*   pMBHeadPrev;    // Previous block
 +    NNSiFndExpHeapMBlockHead*   pMBHeadNext;    // Next block
 +};
 +
 +typedef struct NNSiFndExpMBlockList NNSiFndExpMBlockList;
 +
 +struct NNSiFndExpMBlockList
 +{
 +    NNSiFndExpHeapMBlockHead*   head;   // Pointer for memory block linked to header
 +    NNSiFndExpHeapMBlockHead*   tail;   // Pointer to the memory block linked to the tail of the expanded heap
 +};
 +
 +typedef struct NNSiFndExpHeapHead NNSiFndExpHeapHead;
 +
 +struct NNSiFndExpHeapHead
 +{
 +    NNSiFndExpMBlockList        mbFreeList;     // Free list
 +    NNSiFndExpMBlockList        mbUsedList;     // Used list
 +
 +    u16                         groupID;        // Current group ID (lower 8 bits only)
 +    u16                         feature;        // Attribute
 +};
 +
 +NNSFndHeapHandle NNS_FndCreateExpHeapEx(void *startAddress, u32 size, u32 optFlag);
 +void *NNS_FndAllocFromExpHeapEx(NNSFndHeapHandle heap, u32 size, int alignment);
 +void NNS_FndDestroyExpHeap(NNSFndHeapHandle heap);
 +void NNS_FndFreeToExpHeap(NNSFndHeapHandle heap, void *memBlock);
 +u32 NNS_FndGetTotalFreeSizeForExpHeap(NNSFndHeapHandle heap);
 +u32 NNS_FndGetSizeForMBlockExpHeap(const void *memBlock);
 +void NNS_FndResizeForMBlockExpHeap(NNSFndHeapHandle heap, void *memBlock, u32 size);
 +
 +#define             NNS_FndCreateExpHeap(startAddress, size) \
 +                        NNS_FndCreateExpHeapEx(startAddress, size, 0)
 +#define             NNS_FndAllocFromExpHeap(heap, size) \
 +                        NNS_FndAllocFromExpHeapEx(heap, size, NNS_FND_HEAP_DEFAULT_ALIGNMENT)
 +
 +
 +#endif //GUARD_NNS_FND_EXPHEAP_H
 diff --git a/arm9/lib/include/NNS_FND_heapcommon.h b/arm9/lib/include/NNS_FND_heapcommon.h new file mode 100644 index 00000000..eb6f1bdb --- /dev/null +++ b/arm9/lib/include/NNS_FND_heapcommon.h @@ -0,0 +1,26 @@ +#ifndef GUARD_NNS_FND_HEAPCOMMON_H
 +#define GUARD_NNS_FND_HEAPCOMMON_H
 +
 +#include "NNS_FND_list.h"
 +
 +#define NNS_FND_HEAP_DEFAULT_ALIGNMENT          4
 +
 +typedef struct NNSiFndHeapHead NNSiFndHeapHead;
 +
 +struct NNSiFndHeapHead
 +{
 +    u32             signature;
 +
 +    NNSFndLink      link;
 +    NNSFndList      childList;
 +
 +    void*           heapStart;      // Heap start address
 +    void*           heapEnd;        // Heap end (+1) address
 +
 +    u32             attribute;      // Attribute
 +    // [8:Option flag]
 +};
 +
 +typedef NNSiFndHeapHead* NNSFndHeapHandle;   // Type to represent heap handle
 +
 +#endif //GUARD_NNS_FND_HEAPCOMMON_H
 diff --git a/arm9/lib/include/NNS_FND_list.h b/arm9/lib/include/NNS_FND_list.h new file mode 100644 index 00000000..5df01e5f --- /dev/null +++ b/arm9/lib/include/NNS_FND_list.h @@ -0,0 +1,20 @@ +#ifndef GUARD_NNS_FND_LIST_H
 +#define GUARD_NNS_FND_LIST_H
 +
 +typedef struct
 +{
 +    void*       prevObject;     // Pointer to the previous linked object.
 +    void*       nextObject;     // Pointer to the next linked object.
 +
 +} NNSFndLink;
 +
 +typedef struct
 +{
 +    void*       headObject;     // Pointer for the object linked to the top of the list.
 +    void*       tailObject;     // Pointer for the object linked to the end of the list.
 +    u16         numObjects;     // Number of objects linked in the list.
 +    u16         offset;         // Offset for NNSFndLink type structure member.
 +
 +} NNSFndList;
 +
 +#endif //GUARD_NNS_FND_LIST_H
 diff --git a/arm9/lib/include/OS_irqHandler.h b/arm9/lib/include/OS_irqHandler.h index f052016d..ea12a0ad 100644 --- a/arm9/lib/include/OS_irqHandler.h +++ b/arm9/lib/include/OS_irqHandler.h @@ -16,6 +16,6 @@ static inline OSIrqMask OS_GetIrqCheckFlag(void)  void OS_IrqHandler(void);  void OS_IrqHandler_ThreadSwitch(void); -void OS_WaitIrq(BOOL param1, u32 param2); +void OS_WaitIrq(BOOL clear, OSIrqMask irqFlags);  #endif //POKEDIAMOND_OS_IRQHANDLER_H diff --git a/arm9/lib/include/consts.h b/arm9/lib/include/consts.h index a41f22ae..1ad79b93 100644 --- a/arm9/lib/include/consts.h +++ b/arm9/lib/include/consts.h @@ -52,6 +52,7 @@  #define OSi_TCM_REGION_BASE_MASK   0xfffff000  #define OS_IE_V_BLANK              (1UL << 0) +#define OS_IE_H_BLANK              (1UL << 1)  #define HW_CPU_CLOCK_ARM9          67027964 diff --git a/arm9/lib/include/gx.h b/arm9/lib/include/gx.h index 11081942..acd23b39 100644 --- a/arm9/lib/include/gx.h +++ b/arm9/lib/include/gx.h @@ -27,15 +27,6 @@ void GXi_NopClearFifo128_(void *);  #include "GX_g3imm.h"  #include "GX_dma.h" -void GX_Init(); -u32 GX_HBlankIntr(u32 enable); -u32 GX_VBlankIntr(u32 enable); -void GX_DispOff(); -void GX_DispOn(); -void GX_SetGraphicsMode(u32 mode1, u32 mode2, u32 mode3); -void GXS_SetGraphicsMode(u32 mode); -void GXx_SetMasterBrightness_(vu16 *dst, s32 brightness); -  typedef union  {      u32     raw; @@ -181,4 +172,18 @@ typedef enum  }      GXOBJVRamModeChar; +void GX_Init(); +u32 GX_HBlankIntr(u32 enable); +u32 GX_VBlankIntr(u32 enable); +void GX_DispOff(); +void GX_DispOn(); +void GX_SetGraphicsMode(GXDispMode dispMode, GXBGMode bgMode, GXBG0As bg0_2d3d); +void GXS_SetGraphicsMode(GXBGMode mode); +void GXx_SetMasterBrightness_(vu16 *dst, s32 brightness); + +static inline void GX_SetMasterBrightness(int brightness) +{ +    GXx_SetMasterBrightness_(®_GX_MASTER_BRIGHT, brightness); +} +  #endif //GUARD_GX_H diff --git a/arm9/lib/include/registers.h b/arm9/lib/include/registers.h index 7a0155da..73ae7ccf 100644 --- a/arm9/lib/include/registers.h +++ b/arm9/lib/include/registers.h @@ -659,4 +659,42 @@  #define REG_GXS_DB_DISPCNT_EXOBJ_CH_SIZE                   2  #define REG_GXS_DB_DISPCNT_EXOBJ_CH_MASK                   0x00300000 +// MASTER BRIGHT +#define REG_GX_MASTER_BRIGHT_E_MOD_SHIFT                   14 +#define REG_GX_MASTER_BRIGHT_E_MOD_SIZE                    2 +#define REG_GX_MASTER_BRIGHT_E_MOD_MASK                    0xc000 + +#define REG_GX_MASTER_BRIGHT_E_VALUE_SHIFT                 0 +#define REG_GX_MASTER_BRIGHT_E_VALUE_SIZE                  5 +#define REG_GX_MASTER_BRIGHT_E_VALUE_MASK                  0x001f + +// DISPSTAT +#define REG_GX_DISPSTAT_VCOUNTER_SHIFT                     7 +#define REG_GX_DISPSTAT_VCOUNTER_SIZE                      9 +#define REG_GX_DISPSTAT_VCOUNTER_MASK                      0xff80 + +#define REG_GX_DISPSTAT_VQI_SHIFT                          5 +#define REG_GX_DISPSTAT_VQI_SIZE                           1 +#define REG_GX_DISPSTAT_VQI_MASK                           0x0020 + +#define REG_GX_DISPSTAT_HBI_SHIFT                          4 +#define REG_GX_DISPSTAT_HBI_SIZE                           1 +#define REG_GX_DISPSTAT_HBI_MASK                           0x0010 + +#define REG_GX_DISPSTAT_VBI_SHIFT                          3 +#define REG_GX_DISPSTAT_VBI_SIZE                           1 +#define REG_GX_DISPSTAT_VBI_MASK                           0x0008 + +#define REG_GX_DISPSTAT_LYC_SHIFT                          2 +#define REG_GX_DISPSTAT_LYC_SIZE                           1 +#define REG_GX_DISPSTAT_LYC_MASK                           0x0004 + +#define REG_GX_DISPSTAT_HBLK_SHIFT                         1 +#define REG_GX_DISPSTAT_HBLK_SIZE                          1 +#define REG_GX_DISPSTAT_HBLK_MASK                          0x0002 + +#define REG_GX_DISPSTAT_VBLK_SHIFT                         0 +#define REG_GX_DISPSTAT_VBLK_SIZE                          1 +#define REG_GX_DISPSTAT_VBLK_MASK                          0x0001 +  #endif //POKEDIAMOND_ARM9_REGISTERS_H diff --git a/arm9/lib/include/tp.h b/arm9/lib/include/tp.h index d2687545..dc762f10 100644 --- a/arm9/lib/include/tp.h +++ b/arm9/lib/include/tp.h @@ -1,6 +1,14 @@  #ifndef NITRO_TP_H_  #define NITRO_TP_H_ +#define     TP_TOUCH_OFF                0       // Not being touched +#define     TP_TOUCH_ON                 1       // Being touched + +#define     TP_VALIDITY_VALID           0       // Valid +#define     TP_VALIDITY_INVALID_X       1       // Data with invalid X coordinate +#define     TP_VALIDITY_INVALID_Y       2       // Data with invalid Y coordinate +#define     TP_VALIDITY_INVALID_XY      (TP_VALIDITY_INVALID_X | TP_VALIDITY_INVALID_Y) // Data with invalid X and Y coordinates +  // Touch panel input structure  typedef struct  { diff --git a/arm9/lib/src/GX.c b/arm9/lib/src/GX.c index 69ad8718..688e41b7 100644 --- a/arm9/lib/src/GX.c +++ b/arm9/lib/src/GX.c @@ -7,16 +7,18 @@ vu16 GXi_VRamLockId = 0;  static u16 sDispMode = 0;  static u16 sIsDispOn = TRUE; +#define _powcnt_init_mask (REG_GX_POWCNT_E2DGB_MASK | REG_GX_POWCNT_E2DG_MASK | REG_GX_POWCNT_RE_MASK | REG_GX_POWCNT_GE_MASK) +  ARM_FUNC void GX_Init(){ -    reg_GX_POWCNT |= 0x8000; -    reg_GX_POWCNT = (u16)((reg_GX_POWCNT & ~0x20E) | 0x20E); -    reg_GX_POWCNT = (u16)(reg_GX_POWCNT | 0x1); +    reg_GX_POWCNT |= REG_GX_POWCNT_DSEL_MASK; +    reg_GX_POWCNT = (u16)((reg_GX_POWCNT & ~_powcnt_init_mask) | _powcnt_init_mask); +    reg_GX_POWCNT = (u16)(reg_GX_POWCNT | REG_GX_POWCNT_LCD_MASK);      GX_InitGXState();      s32 temp;      while (GXi_VRamLockId == 0)      {          temp = OS_GetLockID(); -        if (temp == -3) +        if (temp == OS_LOCK_ID_ERROR)          {              OS_Terminate();          } @@ -47,62 +49,62 @@ ARM_FUNC void GX_Init(){  }  ARM_FUNC u32 GX_HBlankIntr(u32 enable){ -    u32 temp = (u32)(reg_GX_DISPSTAT & 0x10); +    u32 temp = (u32)(reg_GX_DISPSTAT & REG_GX_DISPSTAT_HBI_MASK);      if (enable)      { -        reg_GX_DISPSTAT |= 0x10; +        reg_GX_DISPSTAT |= REG_GX_DISPSTAT_HBI_MASK;      }      else      { -        reg_GX_DISPSTAT &= ~0x10; +        reg_GX_DISPSTAT &= ~REG_GX_DISPSTAT_HBI_MASK;      }      return temp;  }  ARM_FUNC u32 GX_VBlankIntr(u32 enable){ -    u32 temp = (u32)(reg_GX_DISPSTAT & 0x8); +    u32 temp = (u32)(reg_GX_DISPSTAT & REG_GX_DISPSTAT_VBI_MASK);      if (enable)      { -        reg_GX_DISPSTAT |= 0x8; +        reg_GX_DISPSTAT |= REG_GX_DISPSTAT_VBI_MASK;      }      else      { -        reg_GX_DISPSTAT &= ~0x8; +        reg_GX_DISPSTAT &= ~REG_GX_DISPSTAT_VBI_MASK;      }      return temp;  }  ARM_FUNC void GX_DispOff(){      u32 temp = reg_GX_DISPCNT; -    sIsDispOn = 0x0; -    sDispMode = (u16)((temp & 0x30000) >> 0x10); -    reg_GX_DISPCNT = temp & ~0x30000; +    sIsDispOn = FALSE; +    sDispMode = (u16)((temp & REG_GX_DISPCNT_MODE_MASK) >> REG_GX_DISPCNT_MODE_SHIFT); +    reg_GX_DISPCNT = temp & ~REG_GX_DISPCNT_MODE_MASK;  }  ARM_FUNC void GX_DispOn(){ -    sIsDispOn = 0x1; +    sIsDispOn = TRUE;      if (sDispMode)      { -        reg_GX_DISPCNT = (reg_GX_DISPCNT & ~0x30000) | (sDispMode << 0x10); +        reg_GX_DISPCNT = (reg_GX_DISPCNT & ~REG_GX_DISPCNT_MODE_MASK) | (sDispMode << REG_GX_DISPCNT_MODE_SHIFT);      }      else      { -        reg_GX_DISPCNT = reg_GX_DISPCNT | 0x10000; +        reg_GX_DISPCNT = reg_GX_DISPCNT | (GX_DISPMODE_GRAPHICS << REG_GX_DISPCNT_MODE_SHIFT);      }  } -ARM_FUNC void GX_SetGraphicsMode(u32 mode1, u32 mode2, u32 mode3){ +ARM_FUNC void GX_SetGraphicsMode(GXDispMode dispMode, GXBGMode bgMode, GXBG0As bg0_2d3d){      u32 temp2 = reg_GX_DISPCNT; -    sDispMode = (u16)mode1; +    sDispMode = (u16)dispMode;      if (!sIsDispOn) -        mode1 = 0; -    reg_GX_DISPCNT = (mode2 | ((temp2 & 0xFFF0FFF0) | (mode1 << 0x10))) | (mode3 << 0x3); +        dispMode = 0; +    reg_GX_DISPCNT = ((bgMode << REG_GX_DISPCNT_BGMODE_SHIFT) | ((temp2 & ~(REG_GX_DISPCNT_BGMODE_MASK | REG_GX_DISPCNT_MODE_MASK | REG_GX_DISPCNT_BG02D3D_MASK | REG_GX_DISPCNT_VRAM_MASK)) | (dispMode << REG_GX_DISPCNT_MODE_SHIFT))) | (bg0_2d3d << REG_GX_DISPCNT_BG02D3D_SHIFT);      if (!sDispMode) -        sIsDispOn = 0x0; +        sIsDispOn = FALSE;  } -ARM_FUNC void GXS_SetGraphicsMode(u32 mode){ -    reg_GXS_DB_DISPCNT = (reg_GXS_DB_DISPCNT & ~0x7) | mode; +ARM_FUNC void GXS_SetGraphicsMode(GXBGMode mode){ +    reg_GXS_DB_DISPCNT = (reg_GXS_DB_DISPCNT & ~REG_GXS_DB_DISPCNT_BGMODE_MASK) | mode;  }  ARM_FUNC void GXx_SetMasterBrightness_(vu16 *dst, s32 brightness){ @@ -112,10 +114,10 @@ ARM_FUNC void GXx_SetMasterBrightness_(vu16 *dst, s32 brightness){      }      else if (brightness > 0)      { -        *dst = (u16)(0x4000 | brightness); +        *dst = (u16)((1 << REG_GX_MASTER_BRIGHT_E_MOD_SHIFT) | brightness);      }      else      { -        *dst = (u16)(0x8000 | -brightness); +        *dst = (u16)((2 << REG_GX_MASTER_BRIGHT_E_MOD_SHIFT) | -brightness);      }  } | 
