Skip to content

Commit edf8530

Browse files
committed
initial commit from coranac download
https://www.coranac.com/projects/tonc/
0 parents  commit edf8530

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+18632
-0
lines changed

Makefile

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#
2+
# Makefile for tonclib.
3+
#
4+
5+
#---------------------------------------------------------------------------------
6+
.SUFFIXES:
7+
#---------------------------------------------------------------------------------
8+
9+
ifeq ($(strip $(DEVKITARM)),)
10+
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
11+
endif
12+
ifeq ($(strip $(DEVKITPRO)),)
13+
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPro)
14+
endif
15+
include $(DEVKITARM)/gba_rules
16+
17+
BUILD := build
18+
SRCDIRS := asm src src/font src/tte src/pre1.3
19+
INCDIRS := include
20+
DATADIRS := data
21+
22+
DATESTRING := $(shell date +%Y)$(shell date +%m)$(shell date +%d)
23+
24+
ARCH := -mthumb -mthumb-interwork
25+
RARCH := -mthumb-interwork -mthumb
26+
IARCH := -mthumb-interwork -marm
27+
28+
bTEMPS := 0 # Save gcc temporaries (.i and .s files)
29+
bDEBUG2 := 0 # Generate debug info (bDEBUG2? Not a full DEBUG flag. Yet)
30+
31+
#---------------------------------------------------------------------------------
32+
# Options for code generation
33+
#---------------------------------------------------------------------------------
34+
35+
CBASE := $(INCLUDE) -Wall -fno-strict-aliasing #-fno-tree-loop-optimize
36+
CBASE += -O2
37+
38+
RCFLAGS := $(CBASE) $(RARCH)
39+
ICFLAGS := $(CBASE) $(IARCH) -mlong-calls #-fno-gcse
40+
CFLAGS := $(RCFLAGS)
41+
42+
ASFLAGS := $(INCLUDE) -Wa,--warn $(ARCH)
43+
44+
# --- Save temporary files ? ---
45+
ifeq ($(strip $(bTEMPS)), 1)
46+
RCFLAGS += -save-temps
47+
ICFLAGS += -save-temps
48+
CFLAGS += -save-temps
49+
CXXFLAGS += -save-temps
50+
endif
51+
52+
# --- Debug info ? ---
53+
54+
ifeq ($(strip $(bDEBUG2)), 1)
55+
CFLAGS += -g
56+
LDFLAGS += -g
57+
endif
58+
59+
#---------------------------------------------------------------------------------
60+
# Path to tools - this can be deleted if you set the path in windows
61+
#---------------------------------------------------------------------------------
62+
63+
export PATH := $(DEVKITARM)/bin:$(PATH)
64+
65+
#---------------------------------------------------------------------------------
66+
67+
ifneq ($(BUILD),$(notdir $(CURDIR)))
68+
69+
export TARGET := $(CURDIR)/lib/libtonc.a
70+
71+
export VPATH := $(foreach dir,$(DATADIRS),$(CURDIR)/$(dir)) $(foreach dir,$(SRCDIRS),$(CURDIR)/$(dir))
72+
73+
ICFILES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.iwram.c)))
74+
RCFILES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.c)))
75+
CFILES := $(ICFILES) $(RCFILES)
76+
77+
SFILES := $(foreach dir,$(SRCDIRS),$(notdir $(wildcard $(dir)/*.s)))
78+
BINFILES := $(foreach dir,$(DATADIRS),$(notdir $(wildcard $(dir)/*.*)))
79+
80+
export OFILES := $(addsuffix .o,$(BINFILES)) $(CFILES:.c=.o) $(SFILES:.s=.o)
81+
export INCLUDE := $(foreach dir,$(INCDIRS),-I$(CURDIR)/$(dir))
82+
export DEPSDIR := $(CURDIR)/build
83+
84+
.PHONY: $(BUILD) clean docs
85+
86+
$(BUILD):
87+
@[ -d lib ] || mkdir -p lib
88+
@[ -d $@ ] || mkdir -p $@
89+
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
90+
91+
docs:
92+
doxygen libtonc.dox
93+
94+
clean:
95+
@echo clean ...
96+
@rm -fr $(BUILD)
97+
98+
#---------------------------------------------------------------------------------
99+
100+
else
101+
102+
DEPENDS := $(OFILES:.o=.d)
103+
104+
#---------------------------------------------------------------------------------
105+
106+
%.a :
107+
108+
$(TARGET): $(OFILES)
109+
110+
%.a : $(OFILES)
111+
@echo Building $@
112+
@rm -f $@
113+
@$(AR) -crs $@ $^
114+
$(PREFIX)nm -Sn $@ > $(basename $(notdir $@)).map
115+
116+
%.iwram.o : %.iwram.c
117+
@echo $(notdir $<)
118+
$(CC) -MMD -MP -MF $(DEPSDIR)/$(@:.o=.d) $(ICFLAGS) -c $< -o $@
119+
120+
%.o : %.c
121+
@echo $(notdir $<)
122+
$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(RCFLAGS) -c $< -o $@
123+
124+
-include $(DEPENDS)
125+
126+
endif
127+
128+
#---------------------------------------------------------------------------------

asm/clr_blend_fast.s

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// Color blend with 33 alpha levels
3+
//
4+
//! \file tonc_memcpy.s
5+
//! \author J Vijn
6+
//! \date 20071130 - 20090801
7+
8+
#include "tonc_asminc.h"
9+
10+
#ifndef CLR_ROUND
11+
#define CLR_ROUND 1
12+
#endif
13+
14+
/*
15+
void clr_blend_fast(COLOR *srca, COLOR *srcb, COLOR *dst,
16+
int nclrs, u32 alpha) IWRAM_CODE;
17+
*/
18+
//! Blends color arrays \a srca and \a srcb into \a dst.
19+
/*! \param srca Source array A.
20+
\param srcb Source array B
21+
\param dst Destination array.
22+
\param nclrs Number of colors.
23+
\param alpha Blend weight (range: 0-32).
24+
\note u32 version, 2 clrs/loop. Loop: 18i/32c, Barrel shifter FTW.
25+
\note Properly rounds the blending. If you don't want that, remove
26+
the references to lr.
27+
*/
28+
BEGIN_FUNC_ARM(clr_blend_fast, CSEC_IWRAM)
29+
movs r3, r3, lsr #1 @ adjust nclrs for u32 run
30+
bxeq lr @ quit on nclrs=0
31+
ldr r12, [sp] @ get alpha from stack
32+
stmfd sp!, {r4-r10, lr}
33+
#if(CLR_ROUND==1)
34+
ldr lr, =0x00200401 @ -1-|1-1
35+
rsb r7, lr, lr, lsl #5 @ MASKLO: -g-|b-r
36+
#else
37+
ldr r7, =0x03E07C1F @ MASKLO: -g-|b-r
38+
#endif
39+
mov r6, r7, lsl #5 @ MASKHI: g-|b-r-
40+
.Lbld_fast_loop:
41+
ldr r8, [r0], #4 @ a= *pa++
42+
ldr r9, [r1], #4 @ b= *pb++
43+
@ --- -g-|b-r
44+
and r4, r6, r8, lsl #5 @ x/32: (-g-|b-r)
45+
and r5, r7, r9 @ y: -g-|b-r
46+
sub r5, r5, r4, lsr #5 @ z: y-x
47+
mla r4, r5, r12, r4 @ z: (y-x)*w + x*32
48+
#if(CLR_ROUND==1)
49+
add r4, r4, lr, lsl #4 @ round
50+
#endif
51+
and r10, r7, r4, lsr #5 @ blend(-g-|b-r)
52+
@ --- b-r|-g- (rotated by 16 for great awesome)
53+
and r4, r6, r8, ror #11 @ x/32: -g-|b-r (ror16)
54+
and r5, r7, r9, ror #16 @ y: -g-|b-r (ror16)
55+
sub r5, r5, r4, lsr #5 @ z: y-x
56+
mla r4, r5, r12, r4 @ z: (y-x)*w + x*32
57+
#if(CLR_ROUND==1)
58+
add r4, r4, lr, lsl #4 @ round
59+
#endif
60+
and r4, r7, r4, lsr #5 @ blend(-g-|b-r (ror16))
61+
@ --- mix -g-|b-r and b-r|-g-
62+
orr r10, r10, r4, ror #16
63+
@ --- write blended, loop
64+
str r10, [r2], #4 @ *dst++= c
65+
subs r3, r3, #1
66+
bgt .Lbld_fast_loop
67+
ldmfd sp!, {r4-r10, lr}
68+
bx lr
69+
END_FUNC(clr_blend_fast)
70+
71+
72+
@ EOF

asm/clr_fade_fast.s

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//
2+
// Color fade with 33 alpha levels
3+
//
4+
//! \file tonc_memcpy.s
5+
//! \author J Vijn
6+
//! \date 20071130 - 20071130
7+
8+
#include "tonc_asminc.h"
9+
10+
#ifndef CLR_ROUND
11+
#define CLR_ROUND 1
12+
#endif
13+
14+
/*
15+
void clr_fade_fast(COLOR *src, COLOR clr, COLOR *dst,
16+
int nclrs, u32 alpha) IWRAM_CODE;
17+
*/
18+
//! Fades color arrays \a srca to \a clr into \a dst.
19+
/*! \param src Source array.
20+
* \param clr Final color (at alpha=32).
21+
* \param dst Destination array.
22+
* \param nclrs Number of colors.
23+
* \param alpha Blend weight (range: 0-32).
24+
* \note u32 version, 2 clrs/loop. Loop: 18i/32c, Barrel shifter FTW.
25+
*/
26+
.section .iwram,"ax", %progbits
27+
.align 2
28+
.arm
29+
.global clr_fade_fast
30+
clr_fade_fast:
31+
movs r3, r3, lsr #1 @ adjust nclrs for u32 run
32+
bxeq lr @ quit on nclrs=0
33+
ldr r12, [sp] @ get alpha from stack
34+
stmfd sp!, {r4-r10, lr}
35+
#if(CLR_ROUND==1)
36+
ldr lr, =0x00200401 @ -1-|1-1
37+
rsb r7, lr, lr, lsl #5 @ MASKLO: -g-|b-r
38+
#else
39+
ldr r7, =0x03E07C1F @ MASKLO: -g-|b-r
40+
#endif
41+
mov r6, r7, lsl #5 @ MASKHI: g-|b-r-
42+
43+
@ Precalc y1 and y2
44+
orr r1, r1, r1, lsl #16
45+
and r9, r7, r1, ror #16 @ precalc: y2= -g-|b-r (ror16)
46+
and r1, r7, r1 @ precalc: y1= -g-|b-r
47+
.Lfade_fast_loop:
48+
ldr r8, [r0], #4 @ a= *pa++
49+
@ --- -g-|b-r
50+
and r4, r6, r8, lsl #5 @ x/32: (-g-|b-r)
51+
sub r5, r1, r4, lsr #5 @ z: y1-x
52+
mla r4, r5, r12, r4 @ z: (y1-x)*w + x*32
53+
#if(CLR_ROUND==1)
54+
add r4, r4, lr, lsl #4 @ round
55+
#endif
56+
and r10, r7, r4, lsr #5 @ blend(-g-|b-r)
57+
@ --- b-r|-g- (rotated by 16 for great awesome)
58+
and r4, r6, r8, ror #11 @ x/32: -g-|b-r (ror16)
59+
sub r5, r9, r4, lsr #5 @ z: y2-x
60+
mla r4, r5, r12, r4 @ z: (y2-x)*w + x*32
61+
#if(CLR_ROUND==1)
62+
add r4, r4, lr, lsl #4 @ round
63+
#endif
64+
and r4, r7, r4, lsr #5 @ blend(-g-|b-r (ror16))
65+
@ --- mix -g-|b-r and b-r|-g-
66+
orr r10, r10, r4, ror #16
67+
@ --- write faded, loop
68+
str r10, [r2], #4 @ *dst++= c
69+
subs r3, r3, #1
70+
bgt .Lfade_fast_loop
71+
ldmfd sp!, {r4-r10, lr}
72+
bx lr
73+
74+
@ EOF

asm/div_lut.s

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
@ ======================================================================
2+
@ Look-Up Tables
3+
@ div_lut: ceil(2^16/x)
4+
@
5+
@ Exported by Cearn's excellut v1.0
6+
@ (comments, kudos, flames to [email protected])
7+
@
8+
@ ======================================================================
9+
10+
.section .rodata
11+
@ -----------------------------------------------------------------------
12+
@ div_lut: a 257 long LUT of 32bit values in 16.16 format
13+
@ ceil(1/x)
14+
.global div_lut
15+
.align 2
16+
div_lut:
17+
.word 0x7FFFFFFF,0x00010000,0x00008000,0x00005556,0x00004000,0x00003334,0x00002AAB,0x00002493
18+
.word 0x00002000,0x00001C72,0x0000199A,0x00001746,0x00001556,0x000013B2,0x0000124A,0x00001112
19+
.word 0x00001000,0x00000F10,0x00000E39,0x00000D7A,0x00000CCD,0x00000C31,0x00000BA3,0x00000B22
20+
.word 0x00000AAB,0x00000A3E,0x000009D9,0x0000097C,0x00000925,0x000008D4,0x00000889,0x00000843
21+
.word 0x00000800,0x000007C2,0x00000788,0x00000751,0x0000071D,0x000006EC,0x000006BD,0x00000691
22+
.word 0x00000667,0x0000063F,0x00000619,0x000005F5,0x000005D2,0x000005B1,0x00000591,0x00000573
23+
.word 0x00000556,0x0000053A,0x0000051F,0x00000506,0x000004ED,0x000004D5,0x000004BE,0x000004A8
24+
.word 0x00000493,0x0000047E,0x0000046A,0x00000457,0x00000445,0x00000433,0x00000422,0x00000411
25+
26+
.word 0x00000400,0x000003F1,0x000003E1,0x000003D3,0x000003C4,0x000003B6,0x000003A9,0x0000039C
27+
.word 0x0000038F,0x00000382,0x00000376,0x0000036A,0x0000035F,0x00000354,0x00000349,0x0000033E
28+
.word 0x00000334,0x0000032A,0x00000320,0x00000316,0x0000030D,0x00000304,0x000002FB,0x000002F2
29+
.word 0x000002E9,0x000002E1,0x000002D9,0x000002D1,0x000002C9,0x000002C1,0x000002BA,0x000002B2
30+
.word 0x000002AB,0x000002A4,0x0000029D,0x00000296,0x00000290,0x00000289,0x00000283,0x0000027D
31+
.word 0x00000277,0x00000271,0x0000026B,0x00000265,0x0000025F,0x0000025A,0x00000254,0x0000024F
32+
.word 0x0000024A,0x00000244,0x0000023F,0x0000023A,0x00000235,0x00000231,0x0000022C,0x00000227
33+
.word 0x00000223,0x0000021E,0x0000021A,0x00000215,0x00000211,0x0000020D,0x00000209,0x00000205
34+
35+
.word 0x00000200,0x000001FD,0x000001F9,0x000001F5,0x000001F1,0x000001ED,0x000001EA,0x000001E6
36+
.word 0x000001E2,0x000001DF,0x000001DB,0x000001D8,0x000001D5,0x000001D1,0x000001CE,0x000001CB
37+
.word 0x000001C8,0x000001C4,0x000001C1,0x000001BE,0x000001BB,0x000001B8,0x000001B5,0x000001B3
38+
.word 0x000001B0,0x000001AD,0x000001AA,0x000001A7,0x000001A5,0x000001A2,0x0000019F,0x0000019D
39+
.word 0x0000019A,0x00000198,0x00000195,0x00000193,0x00000190,0x0000018E,0x0000018B,0x00000189
40+
.word 0x00000187,0x00000184,0x00000182,0x00000180,0x0000017E,0x0000017B,0x00000179,0x00000177
41+
.word 0x00000175,0x00000173,0x00000171,0x0000016F,0x0000016D,0x0000016B,0x00000169,0x00000167
42+
.word 0x00000165,0x00000163,0x00000161,0x0000015F,0x0000015D,0x0000015B,0x00000159,0x00000158
43+
44+
.word 0x00000156,0x00000154,0x00000152,0x00000151,0x0000014F,0x0000014D,0x0000014B,0x0000014A
45+
.word 0x00000148,0x00000147,0x00000145,0x00000143,0x00000142,0x00000140,0x0000013F,0x0000013D
46+
.word 0x0000013C,0x0000013A,0x00000139,0x00000137,0x00000136,0x00000134,0x00000133,0x00000131
47+
.word 0x00000130,0x0000012F,0x0000012D,0x0000012C,0x0000012A,0x00000129,0x00000128,0x00000126
48+
.word 0x00000125,0x00000124,0x00000122,0x00000121,0x00000120,0x0000011F,0x0000011D,0x0000011C
49+
.word 0x0000011B,0x0000011A,0x00000119,0x00000117,0x00000116,0x00000115,0x00000114,0x00000113
50+
.word 0x00000112,0x00000110,0x0000010F,0x0000010E,0x0000010D,0x0000010C,0x0000010B,0x0000010A
51+
.word 0x00000109,0x00000108,0x00000107,0x00000106,0x00000105,0x00000104,0x00000103,0x00000102
52+
.word 0x00000100
53+
54+
.size div_lut, .-div_lut

0 commit comments

Comments
 (0)