Alchemy
Loading...
Searching...
No Matches

io_queue.c

Go to the documentation of this file.
1/// @file
2/// The register write queue that VBlank carries out after each finished frame.
3/// Part of runtime.c, the runtime object, compiled only through it.
4
6
7typedef void (*QueueFlushRoutine)(struct IoWriteQueue *queue, u32 count);
8
9/// The queued register writers: each adds a write of `value` to `address`
10/// that the VBlank handler carries out once the frame loop has finished the
11/// frame. The control word gives the width and whether the value is stored,
12/// ORed in or cleared.
13#define IO_QUEUE_DEFINE_WRITE(name, control) \
14 void name(u32 address, u32 value) { \
15 IO_WRITE_QUEUE_PUSH(address, value, control); \
16 }
17
18/// Queues a byte store.
20/// Queues a halfword store.
22/// Queues a word store.
24/// Queues setting a byte register's bits.
26/// Queues setting a halfword register's bits.
28/// Queues setting a word register's bits.
30/// Queues clearing a byte register's bits.
32/// Queues clearing a halfword register's bits.
34/// Queues clearing a word register's bits.
36
37/// Runs the queued register writes and empties the queue, with a copy of the
38/// executor routine on the stack. Called by System_VBlankHandler once the
39/// frame loop has finished a frame.
41 struct IoWriteQueue *queue;
42 u32 count;
43
44 queue = &gIoWriteQueue;
45 count = queue->count;
46 if (count != 0) {
47 QueueFlushRoutine routine;
49 u32 wordCount = size >> 2;
50 u32 zero = 0;
51 u32 control = 0x84;
52
53 control <<= 24;
54 {
55 u8 routineBytes[wordCount << 2];
56
57 // The executor must finish before this stack buffer goes out of scope.
58 routine = (QueueFlushRoutine)routineBytes;
59 Dma_Set(Resource_ExecuteTransfer, (void *)routine, wordCount | control,
60 REG_DMA3);
61 routine(queue, count);
62 queue->count = zero;
63 }
64 }
65}
66
67#undef IO_QUEUE_DEFINE_WRITE
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
Definition dma.h:62
void IoWriteQueue_ClearBits16(u32 address, u32 value)
Queues clearing a halfword register's bits.
Definition io_queue.c:33
void(*) QueueFlushRoutine(struct IoWriteQueue *queue, u32 count)
Definition io_queue.c:7
void IoWriteQueue_Store32(u32 address, u32 value)
Queues a word store.
Definition io_queue.c:23
#define IO_QUEUE_DEFINE_WRITE(name, control)
The queued register writers: each adds a write of value to address that the VBlank handler carries ou...
Definition io_queue.c:13
void IoWriteQueue_FlushPending(void)
Runs the queued register writes and empties the queue, with a copy of the executor routine on the sta...
Definition io_queue.c:40
void IoWriteQueue_ClearBits8(u32 address, u32 value)
Queues clearing a byte register's bits.
Definition io_queue.c:31
void IoWriteQueue_SetBits32(u32 address, u32 value)
Queues setting a word register's bits.
Definition io_queue.c:29
void IoWriteQueue_SetBits16(u32 address, u32 value)
Queues setting a halfword register's bits.
Definition io_queue.c:27
void IoWriteQueue_SetBits8(u32 address, u32 value)
Queues setting a byte register's bits.
Definition io_queue.c:25
void IoWriteQueue_Store8(u32 address, u32 value)
Queues a byte store.
Definition io_queue.c:19
void IoWriteQueue_ClearBits32(u32 address, u32 value)
Queues clearing a word register's bits.
Definition io_queue.c:35
void IoWriteQueue_Store16(u32 address, u32 value)
Queues a halfword store.
Definition io_queue.c:21
#define REG_DMA3
Definition io_reg.h:153
#define IO_WRITE_16
Writes a halfword.
struct IoWriteQueue gIoWriteQueue
#define IO_WRITE_32
Writes a word.
#define IO_WRITE_CLEAR
Clears the value's bits in the register instead of storing it.
#define IO_WRITE_8
Writes a byte.
#define IO_WRITE_SET
ORs the value into the register instead of storing it.
What every part of the runtime object shares: its includes and the library call two parts make.
The register writes VBlank carries out once the frame loop has finished a frame; IoWriteQueue_FlushPe...
u16 count
Entries waiting, at most 32.
u8 TransferCommandExecutor_Size[]
const u8 Resource_ExecuteTransfer[]
unsigned int u32
Definition types.h:15
unsigned char u8
Definition types.h:11