libtonc
Data routines

Modules

 Miscellaneous routines
 
 DMA
 

Macros

#define countof(_array)   ( sizeof(_array)/sizeof(_array[0]) )
 Get the number of elements in an array.
 
#define SND_RATE(note, oct)   ( 2048-(__snd_rates[note]>>(4+(oct))) )
 Gives the period of a note for the tone-gen registers.
 

Enumerations

enum  eSndNoteId {
  NOTE_C =0 , NOTE_CIS , NOTE_D , NOTE_DIS ,
  NOTE_E , NOTE_F , NOTE_FIS , NOTE_G ,
  NOTE_GIS , NOTE_A , NOTE_BES , NOTE_B
}
 

Functions

INLINE uint align (uint x, uint width)
 Align x to the next multiple of width.
 
INLINE void profile_start (void)
 Start a profiling run.
 
INLINE uint profile_stop (void)
 Stop a profiling run and return the time since its start.
 

Variables

const uint __snd_rates [12]
 

Copying and filling routines

void * tonccpy (void *dst, const void *src, uint size)
 VRAM-safe cpy.
 
void * __toncset (void *dst, u32 fill, uint size)
 VRAM-safe memset, internal routine.
 
INLINE void * toncset (void *dst, u8 src, uint count)
 VRAM-safe memset, byte version. Size in bytes.
 
INLINE void * toncset16 (void *dst, u16 src, uint count)
 VRAM-safe memset, halfword version. Size in hwords.
 
INLINE void * toncset32 (void *dst, u32 src, uint count)
 VRAM-safe memset, word version. Size in words.
 
void memset16 (void *dst, u16 hw, uint hwcount)
 Fastfill for halfwords, analogous to memset()
 
void memcpy16 (void *dst, const void *src, uint hwcount)
 Copy for halfwords.
 
IWRAM_CODE void memset32 (void *dst, u32 wd, uint wdcount)
 Fast-fill by words, analogous to memset()
 
IWRAM_CODE void memcpy32 (void *dst, const void *src, uint wdcount)
 Fast-copy by words.
 
#define GRIT_CPY(dst, name)   memcpy16(dst, name, name##Len/2)
 Simplified copier for GRIT-exported data.
 

Repeated-value creators

These function take a hex-value and duplicate it to all fields, like 0x88 -> 0x88888888.

INLINE u16 dup8 (u8 x)
 Duplicate a byte to form a halfword: 0x12 -> 0x1212.
 
INLINE u32 dup16 (u16 x)
 Duplicate a halfword to form a word: 0x1234 -> 0x12341234.
 
INLINE u32 quad8 (u8 x)
 Quadruple a byte to form a word: 0x12 -> 0x12121212.
 
INLINE u32 octup (u8 x)
 Octuple a nybble to form a word: 0x1 -> 0x11111111.
 

Packing routines.

INLINE u16 bytes2hword (u8 b0, u8 b1)
 Pack 2 bytes into a word. Little-endian order.
 
INLINE u32 bytes2word (u8 b0, u8 b1, u8 b2, u8 b3)
 Pack 4 bytes into a word. Little-endian order.
 
INLINE u32 hword2word (u16 h0, u16 h1)
 Pack 2 bytes into a word. Little-endian order.
 

Detailed Description

Macro Definition Documentation

◆ SND_RATE

#define SND_RATE (   note,
  oct 
)    ( 2048-(__snd_rates[note]>>(4+(oct))) )

Gives the period of a note for the tone-gen registers.

GBA sound range: 8 octaves: [-2, 5]; 8*12= 96 notes (kinda).

Parameters
noteID (range: [0,11>). See eSndNoteId.
octoctave (range [-2,4)>).

Function Documentation

◆ __toncset()

void * __toncset ( void *  dst,
u32  fill,
uint  size 
)

VRAM-safe memset, internal routine.

This version mimics memset in functionality, with the benefit of working for VRAM as well. It is also slightly faster than the original memset.

Parameters
dstDestination pointer.
fillWord to fill with.
sizeFill-length in bytes.
Returns
dst.
Note
The dst pointer and size need not be word-aligned. In the case of unaligned fills, fill will be masked off to match the situation.

References BIT_MASK.

Referenced by toncset(), toncset16(), and toncset32().

◆ memcpy16()

void memcpy16 ( void *  dst,
const void *  src,
uint  hwcount 
)

Copy for halfwords.

Uses memcpy32() if hwn>6 and src and dst are aligned equally.

Parameters
dstDestination address.
srcSource address.
hwcountNumber of halfwords to fill.
Note
dst and src must be halfword aligned.
r0 and r1 return as dst + hwcount*2 and src + hwcount*2.

Referenced by sbmp16_blit(), and srf_pal_copy().

◆ memcpy32()

IWRAM_CODE void memcpy32 ( void *  dst,
const void *  src,
uint  wdcount 
)

Fast-copy by words.

Like CpuFastFill(), only without the requirement of 32byte chunks

Parameters
dstDestination address.
srcSource address.
wdcountNumber of words.
Note
src and dst must be word aligned.
r0 and r1 return as dst + wdcount*4 and src + wdcount*4.

Referenced by oam_copy(), and schr4c_blit().

◆ memset16()

void memset16 ( void *  dst,
u16  hw,
uint  hwcount 
)

Fastfill for halfwords, analogous to memset()

Uses memset32() if hwcount>5

Parameters
dstDestination address.
hwSource halfword (not address).
hwcountNumber of halfwords to fill.
Note
dst must be halfword aligned.
r0 returns as dst + hwcount*2.

Referenced by bmp16_frame(), bmp16_hline(), bmp16_rect(), bmp8_hline(), bmp8_rect(), sbmp16_floodfill_internal(), sbmp16_frame(), sbmp16_hline(), and sbmp16_rect().

◆ memset32()

IWRAM_CODE void memset32 ( void *  dst,
u32  wd,
uint  wdcount 
)

Fast-fill by words, analogous to memset()

Like CpuFastSet(), only without the requirement of 32byte chunks and no awkward store-value-in-memory-first issue.

Parameters
dstDestination address.
wdFill word (not address).
wdcountNumber of words to fill.
Note
dst must be word aligned.
r0 returns as dst + wdcount*4.

Referenced by irq_init(), m3_fill(), m4_fill(), m5_fill(), schr4c_rect(), schr4r_rect(), and se_fill().

◆ profile_start()

INLINE void profile_start ( void  )

Start a profiling run.

Note
Routine uses timers 3 and 3; if you're already using these somewhere, chaos is going to ensue.

References REG_TM2CNT, REG_TM2D, REG_TM3CNT, REG_TM3D, TM_CASCADE, and TM_ENABLE.

◆ profile_stop()

INLINE uint profile_stop ( void  )

Stop a profiling run and return the time since its start.

Returns
32bit cycle count

References REG_TM2CNT, REG_TM2D, and REG_TM3D.

◆ tonccpy()

void * tonccpy ( void *  dst,
const void *  src,
uint  size 
)

VRAM-safe cpy.

This version mimics memcpy in functionality, with the benefit of working for VRAM as well. It is also slightly faster than the original memcpy, but faster implementations can be made.

Parameters
dstDestination pointer.
srcSource pointer.
sizeFill-length in bytes.
Returns
dst.
Note
The pointers and size need not be word-aligned.

Referenced by sbmp8_blit().