From 41bff8075262e52f967dbd88e90ec6703b08b949 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Wed, 4 Sep 2024 23:28:04 -0500 Subject: [PATCH] examples/majora: slight cleanup --- Makefile | 7 +++++-- arm9/examples/majora.c | 45 +++++++++++------------------------------- registers/Makefile | 11 +++++++++++ registers/generate.sh | 7 ------- 4 files changed, 27 insertions(+), 43 deletions(-) delete mode 100644 registers/generate.sh diff --git a/Makefile b/Makefile index 94c4fec..b26585f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/arm9/examples/majora.c b/arm9/examples/majora.c index 5451ab8..f87f8ac 100644 --- a/arm9/examples/majora.c +++ b/arm9/examples/majora.c @@ -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 diff --git a/registers/Makefile b/registers/Makefile index 6693a37..a6ab071 100644 --- a/registers/Makefile +++ b/registers/Makefile @@ -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 $< > $@ diff --git a/registers/generate.sh b/registers/generate.sh deleted file mode 100644 index 0e09d0b..0000000 --- a/registers/generate.sh +++ /dev/null @@ -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