Alchemy
Loading...
Searching...
No Matches

decompress.c

Go to the documentation of this file.
1/// @file
2/// Resource decoding and pixel buffer shading, through RAM copies of ARM code.
3/// Part of runtime.c, the runtime object, compiled only through it.
4
6
7/// Decompresses the halfword LZ stream at `source` to `destination`, with a
8/// copy of the ARM decoder on the stack. Called by the palette editor.
9void Resource_DecompressHalfwords(const void *source, void *destination) {
11 u32 routine[words];
13 ((void (*)(const void *, void *))routine)(source, destination);
14}
15
16/// Each decoder copies its ARM routine `code` to RAM, runs it and frees the
17/// copy, and returns the number of bytes it decoded.
18#define RESOURCE_DEFINE_DECODE(name, code, bytes) \
19 s32 name(const void *source, void *destination) { \
20 s32 (*routine)(const void *, void *); \
21 s32 result; \
22 \
23 RamCode_Load(routine, code, bytes); \
24 result = routine(source, destination); \
25 MemFree(routine); \
26 return result; \
27 }
28
29/// Decodes a type-01 resource and returns its unpacked byte count.
32/// Decodes a type-02 resource and returns its unpacked byte count.
35/// Decodes a byte-oriented LZ resource and returns its unpacked byte count.
38
39// Shading of 8-bit pixel buffers whose values are steps 0 to 63 of a colour
40// ramp. Each function copies `bytes` of `buffer` to `backup`, then shades the
41// buffer in place with a stack copy of its ARM kernel. `amount` is added to
42// every byte of the four-byte groups at once, so it holds the step in each
43// byte. The Nonzero and Partial forms only write back four-byte groups that
44// can change: not all zero, or not all at the limit already.
45
46/// Raises every pixel by `amount`, stopping at 63.
47void ColorBuffer_BackupAndBrighten(u8 *buffer, u32 amount, u8 *backup,
48 u32 bytes) {
50 u32 routine[words];
52 ((void (*)(u8 *, u32, u8 *, u32))routine)(buffer, amount, backup, bytes);
53}
54
55/// Lowers every pixel by `amount`, stopping at 0.
56void ColorBuffer_BackupAndDarken(u8 *buffer, u32 amount, u8 *backup,
57 u32 bytes) {
59 u32 routine[words];
61 ((void (*)(u8 *, u32, u8 *, u32))routine)(buffer, amount, backup, bytes);
62}
63
64/// Scales every pixel to three quarters.
66 u32 bytes) {
68 u32 routine[words];
70 REG_DMA3);
71 ((void (*)(u8 *, u8 *, u32))routine)(buffer, backup, bytes);
72}
73
74/// Halves every pixel. Called by the battle effect canvas's transfers.
75void ColorBuffer_BackupAndHalve(u8 *buffer, u8 *backup, u32 bytes) {
77 u32 routine[words];
79 ((void (*)(u8 *, u8 *, u32))routine)(buffer, backup, bytes);
80}
81
82/// As ColorBuffer_BackupAndBrighten, skipping groups already all at 63.
83void ColorBuffer_BackupAndBrightenPartial(u8 *buffer, u32 amount, u8 *backup,
84 u32 bytes) {
86 u32 routine[words];
88 REG_DMA3);
89 ((void (*)(u8 *, u32, u8 *, u32))routine)(buffer, amount, backup, bytes);
90}
91
92/// As ColorBuffer_BackupAndDarken, skipping groups already all at 0.
93void ColorBuffer_BackupAndDarkenPartial(u8 *buffer, u32 amount, u8 *backup,
94 u32 bytes) {
96 u32 routine[words];
98 REG_DMA3);
99 ((void (*)(u8 *, u32, u8 *, u32))routine)(buffer, amount, backup, bytes);
100}
101
102/// Scales every pixel to three quarters, skipping all-zero groups.
104 u32 bytes) {
106 u32 routine[words];
108 DMA_COPY_WORDS(words), REG_DMA3);
109 ((void (*)(u8 *, u8 *, u32))routine)(buffer, backup, bytes);
110}
111
112/// Halves every pixel, skipping all-zero groups. Called by the slot reels'
113/// canvas transfer.
114void ColorBuffer_BackupAndHalveNonzero(u8 *buffer, u8 *backup, u32 bytes) {
116 u32 routine[words];
118 REG_DMA3);
119 ((void (*)(u8 *, u8 *, u32))routine)(buffer, backup, bytes);
120}
121
122#undef RESOURCE_DEFINE_DECODE
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
const u8 Resource_DecodeHalfwordLz[]
const u8 ColorBuffer_DarkenKernel[]
const u8 Resource_DecodeByteLzArm[]
const u8 ColorBuffer_BrightenPartialKernel[]
u8 ColorBuffer_BackupAndHalveNonzeroCodeSize[]
u8 ColorBuffer_BackupAndDarkenCodeSize[]
u8 Resource_DecodeByteLzCodeSize[]
const u8 ColorBuffer_BrightenKernel[]
const u8 ColorBuffer_HalveNonzeroKernel[]
u8 Resource_Decode2CodeSize[]
const u8 Resource_DecodeType01Arm[]
u8 ColorBuffer_BackupAndBrightenCodeSize[]
const u8 ColorBuffer_DarkenPartialKernel[]
u8 ColorBuffer_BackupAndDarkenPartialCodeSize[]
u8 ColorBuffer_BackupAndHalveCodeSize[]
u8 Resource_DecodeType01CodeSize[]
u8 ColorBuffer_BackupAndScaleNonzeroThreeQuartersCodeSize[]
u8 Resource_DecompressHalfwordsCodeSize[]
const u8 ColorBuffer_HalveKernel[]
const u8 Resource_Decode2[]
const u8 ColorBuffer_ScaleThreeQuartersKernel[]
const u8 ColorBuffer_ScaleNonzeroThreeQuartersKernel[]
u8 ColorBuffer_BackupAndScaleThreeQuartersCodeSize[]
u8 ColorBuffer_BackupAndBrightenPartialCodeSize[]
#define REG_DMA3
Definition io_reg.h:153
#define DMA_COPY_WORDS(n)
Definition io_reg.h:226
void ColorBuffer_BackupAndBrightenPartial(u8 *buffer, u32 amount, u8 *backup, u32 bytes)
As ColorBuffer_BackupAndBrighten, skipping groups already all at 63.
Definition decompress.c:83
void ColorBuffer_BackupAndScaleThreeQuarters(u8 *buffer, u8 *backup, u32 bytes)
Scales every pixel to three quarters.
Definition decompress.c:65
void Resource_DecompressHalfwords(const void *source, void *destination)
Decompresses the halfword LZ stream at source to destination, with a copy of the ARM decoder on the s...
Definition decompress.c:9
s32 Resource_DecodeType01(const void *source, void *destination)
Decodes a type-01 resource and returns its unpacked byte count.
Definition decompress.c:31
void ColorBuffer_BackupAndHalve(u8 *buffer, u8 *backup, u32 bytes)
Halves every pixel. Called by the battle effect canvas's transfers.
Definition decompress.c:75
void ColorBuffer_BackupAndBrighten(u8 *buffer, u32 amount, u8 *backup, u32 bytes)
Raises every pixel by amount, stopping at 63.
Definition decompress.c:47
void ColorBuffer_BackupAndHalveNonzero(u8 *buffer, u8 *backup, u32 bytes)
Halves every pixel, skipping all-zero groups.
Definition decompress.c:114
void ColorBuffer_BackupAndDarken(u8 *buffer, u32 amount, u8 *backup, u32 bytes)
Lowers every pixel by amount, stopping at 0.
Definition decompress.c:56
s32 Resource_DecodeByteLz(const void *source, void *destination)
Decodes a byte-oriented LZ resource and returns its unpacked byte count.
Definition decompress.c:37
void ColorBuffer_BackupAndScaleNonzeroThreeQuarters(u8 *buffer, u8 *backup, u32 bytes)
Scales every pixel to three quarters, skipping all-zero groups.
Definition decompress.c:103
#define RESOURCE_DEFINE_DECODE(name, code, bytes)
Each decoder copies its ARM routine code to RAM, runs it and frees the copy, and returns the number o...
Definition decompress.c:18
void ColorBuffer_BackupAndDarkenPartial(u8 *buffer, u32 amount, u8 *backup, u32 bytes)
As ColorBuffer_BackupAndDarken, skipping groups already all at 0.
Definition decompress.c:93
s32 Resource_DecodeType2(const void *source, void *destination)
Decodes a type-02 resource and returns its unpacked byte count.
Definition decompress.c:34
What every part of the runtime object shares: its includes and the library call two parts make.
unsigned int u32
Definition types.h:15
unsigned char u8
Definition types.h:11