diff --git a/code/hello_joypad/hello_joypad.c b/code/hello_joypad/hello_joypad.c index 83ccc7f..868c7e7 100644 --- a/code/hello_joypad/hello_joypad.c +++ b/code/hello_joypad/hello_joypad.c @@ -21,10 +21,13 @@ #include "duffle/lottes_tape.h" #include "duffle/word_count.metadata.h" +#include "psyq.h" + # include "gen/hello_joypad.macs.h" # include "gen/hello_joypad.offsets.h" #include "hello_joypad.h" +#include "psyq.c" #include "hello_joypad.tape.c" diff --git a/code/hello_joypad/hello_joypad.h b/code/hello_joypad/hello_joypad.h index fe939e0..72ae480 100644 --- a/code/hello_joypad/hello_joypad.h +++ b/code/hello_joypad/hello_joypad.h @@ -10,109 +10,12 @@ enum { OrderingTbl_Len = 2048 }; -typedef Struct_(DrawEnv_Packed) { U4 tag; U4 code[15]; }; -typedef Struct_(DrawEnv) { - Rect_S2 clip_area; - V2_S2 drawing_offset[2]; - Rect_S2 texture_window; - S2 texture_page; - B1 flag_dither; - B1 flag_draw_on_display; - B1 enable_auto_clear; - RGB8 initial_bg_color; - DrawEnv_Packed dr_env; // reserved -}; -typedef Struct_(DisplayEnv) { - Rect_S2 display_area; - Rect_S2 screen; - B1 vinterlace; - B1 color24; - B1 pad0; - B1 pad1; -}; -typedef Array_(DrawEnv, 2); -typedef Array_(DisplayEnv, 2); - -typedef Struct_(DoubleBuffer) { - A2_DrawEnv draw; - A2_DisplayEnv display; -}; - #define ScreenRes_X 320 #define ScreenRes_Y 240 #define ScreenZ 320 #define ScreenRes_CenterX (ScreenRes_X >> 1) #define ScreenRes_CenterY (ScreenRes_Y >> 1) -DisplayEnv* displayenv_init(DisplayEnv* env, S4 x, S4 y, S4 w, S4 h) asm("SetDefDispEnv"); -DrawEnv* drawenv_init (DrawEnv* env, S4 x, S4 y, S4 w, S4 h) asm("SetDefDrawEnv"); - -DisplayEnv* displayenv_put(DisplayEnv* env) asm("PutDispEnv"); -DrawEnv* drawenv_put (DrawEnv* env) asm("PutDrawEnv"); - -U4 geom_init(void) asm("InitGeom"); -void geom_set_offset(U4 x, U4 y) asm("SetGeomOffset"); -void geom_set_screen(U4 h) asm("SetGeomScreen"); - -U4* orderingtbl_clear_reverse(U4* ot, U4 len) asm("ClearOTagR"); - -U4 reset_graph(U4 mode) asm("ResetGraph"); -void set_display_enabled(U4 mask) asm("SetDispMask"); - -U4 draw_sync(U4 mode) asm("DrawSync"); -U4 vsync(U4 mode) asm("VSync"); - -void draw_orderingtbl(U4* buf) asm("DrawOTag"); - -typedef Struct_(Tile) { - U4 tag; - RGB8 color; - B1 code; - Rect_S2 rect; -}; - -/* - Linear Algebra -*/ - -M3_S2* m3s2_rotation (V3_S2* vec, M3_S2* mat) asm("RotMatrix"); -M3_S2* m3s2_translation(M3_S2* mat, V3_S4* vec) asm("TransMatrix"); -M3_S2* m3s2_scale (M3_S2* mat, V3_S4* vec) asm("ScaleMatrix"); - -// Rotation, Translation, Perspective - -S4 rtp_v3s2_raw(V3_S2* vec, S4* xy, S4* pp, S4* flag) asm("RotTransPers"); -FI_ S4 rtp_v3s2(V3_S2* vec, V2_S2* xy, A2_S2* pp, S4* flag) { return rtp_v3s2_raw(vec, C_(S4*R_, & xy->x), C_(S4*R_, pp), r_(flag)); } - -S4 rtp_avg_nclip_a3_v3s2_raw(V3_S2* v0, V3_S2* v1, V3_S2* v2, S4* xy1, S4* xy2, S4* xy3, S4* pp, S4* otz, S4* flag) asm("RotAverageNclip3"); -FI_ S4 rtp_avg_nclip_a3_v3s2( - V3_S2* v0, V3_S2* v1, V3_S2* v2, - V2_S2* xy0, V2_S2* xy1, V2_S2* xy2, - A2_S2* pp, S4* otz, S4* flag -){ - return rtp_avg_nclip_a3_v3s2_raw( - v0, v1, v2, - C_(S4*R_, xy0), C_(S4*R_, xy1), C_(S4*R_, xy2), - C_(S4*R_, pp), C_(S4*R_, otz), C_(S4*R_, flag) - ); -} - -S4 rtp_avg_nclip_a4_v3s2_raw(V3_S2* v0, V3_S2* v1, V3_S2* v2, V3_S2* v3, S4* xy1, S4* xy2, S4* xy3, S4* xy4, S4* pp, S4* otz, S4* flag) asm("RotAverageNclip4"); -FI_ S4 rtp_avg_nclip_a4_v3s2( - V3_S2* v0, V3_S2* v1, V3_S2* v2, V3_S2* v3, - V2_S2* xy0, V2_S2* xy1, V2_S2* xy2, V2_S2* xy3, - A2_S2* pp, S4* otz, S4* flag -){ - return rtp_avg_nclip_a4_v3s2_raw( - v0, v1, v2, v3, - C_(S4*R_, xy0), C_(S4*R_, xy1), C_(S4*R_, xy2), C_(S4*R_, xy3), - C_(S4*R_, pp), C_(S4*R_, otz), C_(S4*R_, flag) - ); -} - -void gte_matrix_set_rotation (M3_S2* mat) asm("SetRotMatrix"); -void gte_matrix_set_translation(M3_S2* mat) asm("SetTransMatrix"); - enum { fp_one = (1 << 12), }; diff --git a/code/hello_joypad/hello_joypad.tape.c b/code/hello_joypad/hello_joypad.tape.c index 37c94c0..cde981d 100644 --- a/code/hello_joypad/hello_joypad.tape.c +++ b/code/hello_joypad/hello_joypad.tape.c @@ -8,6 +8,7 @@ # include "duffle/gte.h" # include "duffle/gp.h" # include "duffle/word_count.metadata.h" +# include "psyq.h" # include "gen/hello_joypad.offsets.h" # include "gen/hello_joypad.macs.h" # include "hello_joypad.h" @@ -112,7 +113,7 @@ MipsAtomComp_Proc_(ac_put_draw_env, { enum { R_ScreenX = R_T5 atom_reg atom_type(U2), R_ScreenY = R_T6 atom_reg atom_type(U2), - R_ScreenBuf = R_T7 atom_reg, /* Caller-pinned: &smem.screen_buf */ + R_ScreenBuf = R_T7 atom_reg, /* Caller-pinned: & smem.screen_buf */ #define R_ScreenBuf_Code R_T7_Code }; //screen_env_init. Mirrors the libpsyx's SetDefDispEnv + SetDefDrawEnv + the manual enable_auto_clear / initial_bg_color writes. diff --git a/code/hello_joypad/psyq.c b/code/hello_joypad/psyq.c new file mode 100644 index 0000000..0bf105d --- /dev/null +++ b/code/hello_joypad/psyq.c @@ -0,0 +1,3 @@ +#ifdef INTELLISENSE_DIRECTIVES +# include "psyq.h" +#endif diff --git a/code/hello_joypad/psyq.h b/code/hello_joypad/psyq.h new file mode 100644 index 0000000..c94a00f --- /dev/null +++ b/code/hello_joypad/psyq.h @@ -0,0 +1,103 @@ +#ifdef INTELLISENSE_DIRECTIVES +# pragma once +# include "duffle/dsl.h" +# include "duffle/math.h" +# include "duffle/gp.h" +#endif + +typedef Struct_(DrawEnv_Packed) { U4 tag; U4 code[15]; }; +typedef Struct_(DrawEnv) { + Rect_S2 clip_area; + V2_S2 drawing_offset[2]; + Rect_S2 texture_window; + S2 texture_page; + B1 flag_dither; + B1 flag_draw_on_display; + B1 enable_auto_clear; + RGB8 initial_bg_color; + DrawEnv_Packed dr_env; // reserved +}; +typedef Struct_(DisplayEnv) { + Rect_S2 display_area; + Rect_S2 screen; + B1 vinterlace; + B1 color24; + B1 pad0; + B1 pad1; +}; +typedef Array_(DrawEnv, 2); +typedef Array_(DisplayEnv, 2); + +typedef Struct_(DoubleBuffer) { + A2_DrawEnv draw; + A2_DisplayEnv display; +}; + +DisplayEnv* displayenv_init(DisplayEnv* env, S4 x, S4 y, S4 w, S4 h) asm("SetDefDispEnv"); +DrawEnv* drawenv_init (DrawEnv* env, S4 x, S4 y, S4 w, S4 h) asm("SetDefDrawEnv"); + +DisplayEnv* displayenv_put(DisplayEnv* env) asm("PutDispEnv"); +DrawEnv* drawenv_put (DrawEnv* env) asm("PutDrawEnv"); + +U4 geom_init(void) asm("InitGeom"); +void geom_set_offset(U4 x, U4 y) asm("SetGeomOffset"); +void geom_set_screen(U4 h) asm("SetGeomScreen"); + +U4* orderingtbl_clear_reverse(U4* ot, U4 len) asm("ClearOTagR"); + +U4 reset_graph(U4 mode) asm("ResetGraph"); +void set_display_enabled(U4 mask) asm("SetDispMask"); + +U4 draw_sync(U4 mode) asm("DrawSync"); +U4 vsync(U4 mode) asm("VSync"); + +void draw_orderingtbl(U4* buf) asm("DrawOTag"); + +typedef Struct_(Tile) { + U4 tag; + RGB8 color; + B1 code; + Rect_S2 rect; +}; + +/* + Linear Algebra +*/ + +M3_S2* m3s2_rotation (V3_S2* vec, M3_S2* mat) asm("RotMatrix"); +M3_S2* m3s2_translation(M3_S2* mat, V3_S4* vec) asm("TransMatrix"); +M3_S2* m3s2_scale (M3_S2* mat, V3_S4* vec) asm("ScaleMatrix"); + +// Rotation, Translation, Perspective + +S4 rtp_v3s2_raw(V3_S2* vec, S4* xy, S4* pp, S4* flag) asm("RotTransPers"); +FI_ S4 rtp_v3s2(V3_S2* vec, V2_S2* xy, A2_S2* pp, S4* flag) { return rtp_v3s2_raw(vec, C_(S4*R_, & xy->x), C_(S4*R_, pp), r_(flag)); } + +S4 rtp_avg_nclip_a3_v3s2_raw(V3_S2* v0, V3_S2* v1, V3_S2* v2, S4* xy1, S4* xy2, S4* xy3, S4* pp, S4* otz, S4* flag) asm("RotAverageNclip3"); +FI_ S4 rtp_avg_nclip_a3_v3s2( + V3_S2* v0, V3_S2* v1, V3_S2* v2, + V2_S2* xy0, V2_S2* xy1, V2_S2* xy2, + A2_S2* pp, S4* otz, S4* flag +){ + return rtp_avg_nclip_a3_v3s2_raw( + v0, v1, v2, + C_(S4*R_, xy0), C_(S4*R_, xy1), C_(S4*R_, xy2), + C_(S4*R_, pp), C_(S4*R_, otz), C_(S4*R_, flag) + ); +} + +S4 rtp_avg_nclip_a4_v3s2_raw(V3_S2* v0, V3_S2* v1, V3_S2* v2, V3_S2* v3, S4* xy1, S4* xy2, S4* xy3, S4* xy4, S4* pp, S4* otz, S4* flag) asm("RotAverageNclip4"); +FI_ S4 rtp_avg_nclip_a4_v3s2( + V3_S2* v0, V3_S2* v1, V3_S2* v2, V3_S2* v3, + V2_S2* xy0, V2_S2* xy1, V2_S2* xy2, V2_S2* xy3, + A2_S2* pp, S4* otz, S4* flag +){ + return rtp_avg_nclip_a4_v3s2_raw( + v0, v1, v2, v3, + C_(S4*R_, xy0), C_(S4*R_, xy1), C_(S4*R_, xy2), C_(S4*R_, xy3), + C_(S4*R_, pp), C_(S4*R_, otz), C_(S4*R_, flag) + ); +} + +void gte_matrix_set_rotation (M3_S2* mat) asm("SetRotMatrix"); +void gte_matrix_set_translation(M3_S2* mat) asm("SetTransMatrix");