examples/majora: slight cleanup

This commit is contained in:
Zack Buhman 2024-09-04 23:28:04 -05:00
parent 140f243ad3
commit 41bff80752
4 changed files with 27 additions and 43 deletions

View File

@ -2,11 +2,14 @@ OPT = -Os
all: cartridge.bin
phony: res
phony: res registers
res:
make -C res/
registers:
make -C registers/
arm9/%.bin: phony
make -C arm9/ $(notdir $@)
@ -28,4 +31,4 @@ OBJARCH = -O elf32-littlearm -B armv4t
LDSCRIPT = cartridge.lds
include common.mk
.PHONY: phony res
.PHONY: phony res registers

View File

@ -220,12 +220,6 @@ void main()
io_registers.a.MTX_MODE = MTX_MODE__matrix_mode__projection;
io_registers.a.MTX_IDENTITY = 0;
/*
io_registers.a.MTX_SCALE = ((192 << 12) / (256)) / 2;
io_registers.a.MTX_SCALE = 0.5 * 4096;
io_registers.a.MTX_SCALE = 0.5 * 4096;
*/
// load a symmetric perspective matrix, with aspect ratio correction
io_registers.a.MTX_LOAD_4X4 = (192 << 12) / 256;
io_registers.a.MTX_LOAD_4X4 = 0;
@ -283,7 +277,7 @@ void main()
// normalized 45° vector
int c = 0.57735 * 512;
// lighting
// lighting vectors and colors for 3 directional lights
io_registers.a.LIGHT_VECTOR = 0
| LIGHT_VECTOR__light_number(0)
| LIGHT_VECTOR__decimal_z(-c)
@ -320,7 +314,7 @@ void main()
| LIGHT_COLOR__green(31)
| LIGHT_COLOR__red(31);
// degrees
// integer degrees
int theta = 0;
while (1) {
@ -383,8 +377,7 @@ void main()
io_registers.a.MTX_MULT_3X3 = sin2;
io_registers.a.MTX_MULT_3X3 = cos2;
// cube faces
// lighting parameters
io_registers.a.DIF_AMB = 0
| DIF_AMB__ambient_blue(3)
| DIF_AMB__ambient_green(3)
@ -398,13 +391,6 @@ void main()
| SPE_EMI__specular_green(25)
| SPE_EMI__specular_red(25);
/*
io_registers.a.COLOR = 0
| COLOR__blue(31)
| COLOR__green(31)
| COLOR__red(31);
*/
// the following polygons are fully opaque; backface culling is
// enabled
io_registers.a.POLYGON_ATTR = 0
@ -417,7 +403,7 @@ void main()
| POLYGON_ATTR__light_1__enable
| POLYGON_ATTR__light_0__enable;
// the following vertices are a triangles
// the following vertices are triangles
io_registers.a.BEGIN_VTXS = BEGIN_VTXS__type__triangle;
@ -436,12 +422,9 @@ void main()
// "When texture mapping, the Geometry Engine works faster if you
// issue commands in the following order: TexCoord→Normal→Vertex."
struct vertex_texture * at = &majora_texture[obj->triangle[i].a.texture];
// convert from UV space to ST space
int au = at->u;
int av = at->v;
io_registers.a.TEXCOORD = 0
| TEXCOORD__t_coordinate(v_to_t(av, dimension))
| TEXCOORD__s_coordinate(u_to_s(au, dimension));
| TEXCOORD__t_coordinate(v_to_t(at->v, dimension))
| TEXCOORD__s_coordinate(u_to_s(at->u, dimension));
struct vertex_normal * an = &majora_normal[obj->triangle[i].a.normal];
io_registers.a.NORMAL = 0
@ -456,12 +439,9 @@ void main()
| VTX_10__x_coordinate(a->x);
struct vertex_texture * bt = &majora_texture[obj->triangle[i].b.texture];
// convert from UV space to ST space
int bu = bt->u;
int bv = bt->v;
io_registers.a.TEXCOORD = 0
| TEXCOORD__t_coordinate(v_to_t(bv, dimension))
| TEXCOORD__s_coordinate(u_to_s(bu, dimension));
| TEXCOORD__t_coordinate(v_to_t(bt->v, dimension))
| TEXCOORD__s_coordinate(u_to_s(bt->u, dimension));
struct vertex_normal * bn = &majora_normal[obj->triangle[i].b.normal];
io_registers.a.NORMAL = 0
@ -476,12 +456,9 @@ void main()
| VTX_10__x_coordinate(b->x);
struct vertex_texture * ct = &majora_texture[obj->triangle[i].c.texture];
// convert from UV space to ST space
int cu = ct->u;
int cv = ct->v;
io_registers.a.TEXCOORD = 0
| TEXCOORD__t_coordinate(v_to_t(cv, dimension))
| TEXCOORD__s_coordinate(u_to_s(cu, dimension));
| TEXCOORD__t_coordinate(v_to_t(ct->v, dimension))
| TEXCOORD__s_coordinate(u_to_s(ct->u, dimension));
struct vertex_normal * cn = &majora_normal[obj->triangle[i].c.normal];
io_registers.a.NORMAL = 0
@ -498,7 +475,7 @@ void main()
}
// end of the triangle
// end of triangles
io_registers.a.END_VTXS = 0;
// wait for the geometry engine

View File

@ -1,2 +1,13 @@
all: ../include/graphics_engine_a.h ../include/graphics_engine_b.h ../include/bits.h
%.csv: %.ods
libreoffice --headless --convert-to csv:"Text - txt - csv (StarCalc)":44,34,76,,,,true --outdir $(dir $@) $<
../include/graphics_engine_a.h: 0x04000000.txt
python format.py $< graphics_engine_a 0x1000 > $@
../include/graphics_engine_b.h: 0x04001000.txt
python format.py $< graphics_engine_b 0 > $@
../include/bits.h: graphics_engine_bits.csv
python format_bits.py $< > $@

View File

@ -1,7 +0,0 @@
set -eux
python format.py 0x04000000.txt graphics_engine_a 0x1000 > ../include/graphics_engine_a.h
python format.py 0x04001000.txt graphics_engine_b 0 > ../include/graphics_engine_b.h
make graphics_engine_bits.csv
python format_bits.py graphics_engine_bits.csv > ../include/bits.h