diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 99c5ca1..cc2d581 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -8,12 +8,13 @@ "${workspaceFolder}/toolchain/pcsx-redux/src/mips", "${workspaceFolder}/toolchain/psyq-4_7/include" ], - "cStandard": "c17", + "cStandard": "c11", "defines": [ "__STDC_HOSTED__ = 0", - "INTELLISENSE_DIRECTIVES=1" + "INTELLISENSE_DIRECTIVES" ], - "intelliSenseMode": "gcc-x86" + "intelliSenseMode": "gcc-x86", + "compilerPath": "C:\\Users\\Ed\\AppData\\Roaming\\mips\\versions\\v14.2.0\\bin\\mipsel-none-elf-gcc.exe", } ], "version": 4 diff --git a/.vscode/settings.json b/.vscode/settings.json index d72c5fa..67276d8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "files.associations": { "*.rmd": "markdown", "*.s": "gas", + "*.dasm": "lldb.disassembly", "*.asm": "gas", "stdlib.h": "c", "libetc.h": "c", @@ -16,6 +17,12 @@ "iterator": "c", "regex": "c", "dsl.h": "c", - "xlocale": "c" + "xlocale": "c", + "gp.h": "c", + "array": "c", + "initializer_list": "c", + "string_view": "c", + "functional": "c", + "tuple": "c" } } \ No newline at end of file diff --git a/code/asmdd/dsl.s b/code/asmdd/dsl.s index c41e36d..b2f2b04 100644 --- a/code/asmdd/dsl.s +++ b/code/asmdd/dsl.s @@ -3,94 +3,94 @@ # Instructions # Load .macro load_addr p1, p2 - la \p1, \p2 + la \p1, \p2 .endm .macro load_imm p1, p2 - li \p1, \p2 + li \p1, \p2 .endm .macro load_uimm p1, p2 - lui \p1, \p2 + lui \p1, \p2 .endm .macro load_word p1, p2 - lw \p1, \p2 + lw \p1, \p2 .endm # Store .macro store_word p1, p2 - sw \p1, \p2 + sw \p1, \p2 .endm # Shift .macro shift_ll p1, p2, p3 - sll \p1, \p2, \p3 + sll \p1, \p2, \p3 .endm .macro shift_rl p1, p2, p3 - srl \p1, \p2, \p3 + srl \p1, \p2, \p3 .endm .macro shift_ra p1, p2, p3 - sra \p1, \p2, \p3 + sra \p1, \p2, \p3 .endm # Addition .macro add_s p1, p2, p3 - add \p1, \p2, \p3 + add \p1, \p2, \p3 .endm .macro add_u p1, p2, p3 - add \p1, \p2, \p3 + add \p1, \p2, \p3 .endm .macro add_si p1, p2, p3 - addi \p1, \p2, \p3 + addi \p1, \p2, \p3 .endm .macro add_ui p1, p2, p3 - addiu \p1, \p2, \p3 + addiu \p1, \p2, \p3 .endm # Subtraction .macro sub_s p1, p2, p3 - sub \p1, \p2, \p3 + sub \p1, \p2, \p3 .endm .macro sub_u p1, p2, p3 - subu \p1, \p2, \p3 + subu \p1, \p2, \p3 .endm # Multiplication # Division .macro div_s p1, p2 - div \p1, \p2 + div \p1, \p2 .endm .macro div_u p1, p2 - divu \p1, \p2 + divu \p1, \p2 .endm .macro mov_from_high p1 - mfhi \p1 + mfhi \p1 .endm .macro mov_from_low p1 - mflo \p1 + mflo \p1 .endm # Branch .macro branch_ne_zero p1, p2 - bnez \p1, \p2 + bnez \p1, \p2 .endm .macro branch_equal p1, p2, p3 - beq \p1, \p2, \p3 + beq \p1, \p2, \p3 .endm .macro branch_gt_equal p1, p2, p3 - bge \p1, \p2, \p3 + bge \p1, \p2, \p3 .endm .macro branch_gt p1, p2, p3 - bgt \p1, \p2, \p3 + bgt \p1, \p2, \p3 .endm .macro branch_lt p1, p2, p3 - blt \p1, \p2, \p3 + blt \p1, \p2, \p3 .endm # Jump .macro jump p1 - j \p1 + j \p1 .endm .macro jump_nlink p1 - jal \p1 + jal \p1 .endm .macro jump_reg p1 - jr \p1 + jr \p1 .endm .macro jump_nreg p1 - jalr \p1 + jalr \p1 .endm # Registers diff --git a/code/asmdd/gp.s b/code/asmdd/gp.s index 01d385a..b0ab4a3 100644 --- a/code/asmdd/gp.s +++ b/code/asmdd/gp.s @@ -176,6 +176,11 @@ .equiv gp_b10_Y, 10 .equiv gp_b16_X, 0 .equiv gp_b16_Y, 16 + +.equiv RGB8_r, 0 +.equiv RGB8_g, 1 +.equiv RGB8_b, 2 +.equiv sizeof_RGB8, 3 .equiv gp_pixel16, (2 * byte) .equiv gp_pixel24, (3 * byte) diff --git a/code/asmdd/math.s b/code/asmdd/math.s new file mode 100644 index 0000000..75220d7 --- /dev/null +++ b/code/asmdd/math.s @@ -0,0 +1,44 @@ +# Extent_2S16 { S16 width; S16 height; } +.equ Extent_2S16_width, 0 +.equ Extent_2S16_height, 2 +.equ sizeof_Extent_2S16, 4 +# Extent_2S32 { S32 width; S32 height; } +.equ Extent_2S32_width, 0 +.equ Extent_2S32_height, 4 +.equ sizeof_Extent_2S32, 8 +# Vec_2S16 { S16 x; S16 y; } +.equ Vec_2S16_x, 0 +.equ Vec_2S16_y, 2 +.equ sizeof_Vec_2S16, 4 +# Vec_2S32 { S32 x; S32 y; } +.equ Vec_2S32_x, 0 +.equ Vec_2S32_y, 4 +.equ sizeof_Vec_2S32, 8 +# Range_2S16 { Vec_2S16 p0; Vec_2S16 p1; } +.equ Range_2S16_p0, 0 +.equ Range_2S16_p0_x, 0 +.equ Range_2S16_p0_y, 2 +.equ Range_2S16_p1, 4 +.equ Range_2S16_p1_x, 4 +.equ Range_2S16_p1_y, 6 +.equ sizeof_Range_2S16, 8 +# Range_2S32 { Vec_2S32 p0; Vec_2S32 p1; } +.equ Range_2S32_p0, 0 +.equ Range_2S32_p0_x, 0 +.equ Range_2S32_p0_y, 4 +.equ Range_2S32_p1, 8 +.equ Range_2S32_p1_x, 8 +.equ Range_2S32_p1_y, 12 +.equ sizeof_Range_2S32, 16 +# Rect_S16 { S16 x; S16 y; S16 width; S16 height; } +.equ Rect_S16_x, 0 +.equ Rect_S16_y, 2 +.equ Rect_S16_width, 4 +.equ Rect_S16_height, 6 +.equ sizeof_Rect_S16, 8 +# Rect_S32 { S32 x; S32 y; S32 width; S32 height; } +.equ Rect_S32_x, 0 +.equ Rect_S32_y, 4 +.equ Rect_S32_width, 8 +.equ Rect_S32_height, 12 +.equ sizeof_Rect_S32, 16 diff --git a/code/duffle/dsl.h b/code/duffle/dsl.h index 8bd1b4d..3eedc04 100644 --- a/code/duffle/dsl.h +++ b/code/duffle/dsl.h @@ -34,7 +34,7 @@ enum { #define def_enum(underlying_type, symbol) underlying_type symbol; enum symbol #define def_struct(symbol) struct symbol symbol; struct symbol #define def_union(symbol) union symbol symbol; union symbol -#define fn(symbol) symbol +#define def_proc(symbol) symbol #define opt_args(symbol, ...) &(symbol){__VA_ARGS__} #define ret_type(type) type #define local_persist static @@ -54,19 +54,19 @@ enum { #define giga(n) (cast(SSIZE, n) << 30) #define tera(n) (cast(SSIZE, n) << 40) -#define range_iter(type, iter, m_begin, op, m_end) \ - tmpl(Iter_Range,type) iter = { \ - .r = {(m_begin), (m_end)}, \ - .cursor = (m_begin) }; \ - iter.cursor op iter.r.end; \ +#define span_iter(type, iter, m_begin, op, m_end) \ + tmpl(Iter_Span,type) iter = { \ + .r = {(m_begin), (m_end)}, \ + .cursor = (m_begin) }; \ + iter.cursor op iter.r.end; \ ++ iter.cursor -#define def_range(type) \ - def_struct(tmpl( Range,type)) { type begin; type end; }; \ - typedef def_struct(tmpl(Iter_Range,type)) { tmpl(Range,type) r; type cursor; } +#define def_span(type) \ + def_struct(tmpl( Span,type)) { type begin; type end; }; \ + typedef def_struct(tmpl(Iter_Span,type)) { tmpl(Span,type) r; type cursor; } -typedef def_range(S32); -typedef def_range(U32); -typedef def_range(SSIZE); +typedef def_span(S32); +typedef def_span(U32); +typedef def_span(SSIZE); -typedef void fn(VoidFn) (void); +typedef void def_proc(VoidFn) (void); diff --git a/code/duffle/gp.h b/code/duffle/gp.h index 322e6d5..8a733f5 100644 --- a/code/duffle/gp.h +++ b/code/duffle/gp.h @@ -1,6 +1,7 @@ #ifdef INTELLISENSE_DIRECTIVES # pragma once # include "dsl.h" +# include "math.h" #endif typedef def_enum(U32, gp_Commands) { @@ -72,6 +73,8 @@ typedef def_enum(U32, gp_Commands) { #define gp_SetArea_TopLeft (gcmd_SetDrawArea_TopLeft << gcmd_offset) #define gp_SetArea_BottomRight (gcmd_SetDrawArea_BotRight << gcmd_offset) +typedef def_struct(RGB8) { BYTE r; BYTE g; BYTE b; }; + typedef BYTE gp_Pixel16[1]; typedef BYTE gp_Pixel24[3]; @@ -80,9 +83,6 @@ typedef BYTE gp_Pixel24[3]; #define gp_b16_X 0 #define gp_b16_Y 16 -typedef def_struct(gp_Vec2) { - U16 x; - U16 y; -}; +typedef def_struct(gp_Vec2) { U16 y; U16 x; }; -void gp_screen_init(); +void gp_screen_init(void) __asm__("gp_screen_init"); diff --git a/code/duffle/math.h b/code/duffle/math.h new file mode 100644 index 0000000..2484ba7 --- /dev/null +++ b/code/duffle/math.h @@ -0,0 +1,21 @@ +#ifdef INTELLISENSE_DIRECTIVES +# pragma once +# include "dsl.h" +#endif + +typedef def_farray(S16, 2); +typedef def_farray(S32, 2); +// typedef def_farray(F32, 2); + +typedef def_struct(Extent_2S16) { S16 width; S16 height; }; +typedef def_struct(Extent_2S32) { S32 width; S32 height; }; +// typedef def_struct(Extent_2F32) { F32 width; F32 height; } +typedef def_struct(Vec_2S16) { S16 x; S16 y; }; +typedef def_struct(Vec_2S32) { S32 x; S32 y; }; +// typedef def_struct(Vec_2F32) { F32 x; F32 y; }; +typedef def_struct(Range_2S16) { Vec_2S16 p0; Vec_2S16 p1; }; +typedef def_struct(Range_2S32) { Vec_2S32 p0; Vec_2S32 p1; }; +// typedef def_struct(Range_2F32) { Vec_2F32 p0; Vec_2F32 p1; }; + +typedef def_struct(Rect_S16) { S16 x; S16 y; S16 width; S16 height; }; +typedef def_struct(Rect_S32) { S32 x; S32 y; S32 width; S32 height; }; diff --git a/code/graphics_hello_psyq/hello_gpu.c b/code/graphics_hello_psyq/hello_gpu.c index d0f90ba..3c647d5 100644 --- a/code/graphics_hello_psyq/hello_gpu.c +++ b/code/graphics_hello_psyq/hello_gpu.c @@ -1,11 +1,12 @@ // #include #include "duffle/dsl.h" +#include "duffle/math.h" #include "duffle/gp.h" +#include "hello_gpu.h" + +DoubleBuffer screen_buffer; +S16 active_screen_buffer; -#define ScreenRes_X 320 -#define ScreenRes_Y 240 -#define ScreenRes_CenterX (ScreenRes_X >> 1) -#define ScreenRes_CenterY (ScreenRes_Y >> 1) int main(void) { diff --git a/code/graphics_hello_psyq/hello_gpu.h b/code/graphics_hello_psyq/hello_gpu.h new file mode 100644 index 0000000..161dd4a --- /dev/null +++ b/code/graphics_hello_psyq/hello_gpu.h @@ -0,0 +1,40 @@ +#ifdef INTELLISENSE_DIRECTIVES +# pragma once +# include "duffle/dsl.h" +# include "duffle/math.h" +# include "duffle/gp.h" +#endif + +typedef def_struct(DrawEnv_Packed) { U32 tag; U32 code[15]; }; +typedef def_struct(DrawEnv) { + Rect_S16 clip_area; + A2_S16 drawwing_offset; + Rect_S16 texture_page; + BYTE flag_dither; + BYTE flag_draw_on_display; + BYTE enable_auto_clear; + RGB8 initial_bg_color; + DrawEnv_Packed dr_env; // reserved +}; +typedef def_struct(DisplayEnv) { + Rect_S16 display_area; + Rect_S16 screen; + BYTE vinterlace; + BYTE color24; + BYTE pad0; + BYTE pad1; +}; +typedef def_farray(DrawEnv, 2); +typedef def_farray(DisplayEnv, 2); +typedef def_struct(DoubleBuffer) { + A2_DrawEnv draw; + A2_DisplayEnv display; +}; + +#define ScreenRes_X 320 +#define ScreenRes_Y 240 +#define ScreenRes_CenterX (ScreenRes_X >> 1) +#define ScreenRes_CenterY (ScreenRes_Y >> 1) + +extern DoubleBuffer screen_buffer; +extern S16 active_screen_buffer; diff --git a/code/graphics_hello_psyq/hello_gpu.s b/code/graphics_hello_psyq/hello_gpu.s index 690827e..e619166 100644 --- a/code/graphics_hello_psyq/hello_gpu.s +++ b/code/graphics_hello_psyq/hello_gpu.s @@ -1,9 +1,67 @@ // .include "./toolchain/pcsx-redux/src/mips/common/crt0/crt0.s" .include "./asmdd/dsl.s" +.include "./asmdd/math.s" .include "./asmdd/io.s" .include "./asmdd/gp.s" +# DrawEnv_Packed { U32 tag; U32 code[15]; } +.equ DrawEnv_Packed_tag, 0 +.equ DrawEnv_Packed_code, 4 +.equ sizeof_DrawEnv_Packed, 64 +# DrawEnv { +# Rect_S16 clip_area; +# A2_S16 drawwing_offset; +# Rect_S16 texture_page; +# BYTE flag_dither; +# BYTE flag_draw_on_display; +# BYTE enable_auto_clear; +# RGB8 initial_bg_color; +# // 2 bytes padding +# DrawEnv_Packed dr_env; +# }; +.equ DrawEnv_clip_area, 0 +.equ DrawEnv_drawwing_offset, 8 +.equ DrawEnv_texture_page, 12 +.equ DrawEnv_flag_dither, 20 +.equ DrawEnv_flag_draw_on_display, 21 +.equ DrawEnv_enable_auto_clear, 22 +.equ DrawEnv_initial_bg_color, 23 +.equ DrawEnv_dr_env, 28 +.equ sizeof_DrawEnv, 92 +# DisplayEnv { +# Rect_S16 display_area; +# Rect_S16 screen; +# BYTE vinterlace; +# BYTE color24; +# BYTE pad0; +# BYTE pad1; +# }; +.equ DisplayEnv_display_area, 0 +.equ DisplayEnv_screen, 8 +.equ DisplayEnv_vinterlace, 16 +.equ DisplayEnv_color24, 17 +.equ DisplayEnv_pad0, 18 +.equ DisplayEnv_pad1, 19 +.equ sizeof_DisplayEnv, 20 +# DoubleBuffer { +# DrawEnv draw[2]; +# DisplayEnv display[2]; +# }; +.equ DoubleBuffer_draw, 0 +.equ DoubleBuffer_draw_0, 0 +.equ DoubleBuffer_draw_1, 92 # 0 + sizeof_DrawEnv +.equ DoubleBuffer_display, 184 # 92 * 2 +.equ DoubleBuffer_display_0, 184 +.equ DoubleBuffer_display_1, 204 # 184 + sizeof_DisplayEnv +.equ sizeof_DoubleBuffer, 224 +# Screen Constants +.equ ScreenRes_X, 320 +.equ ScreenRes_Y, 240 +.equ ScreenRes_CenterX, (ScreenRes_X >> 2) +.equ ScreenRes_CenterY, (ScreenRes_Y >> 2) + + .global gp_screen_init .type gp_screen_init, @function gp_screen_init: diff --git a/scripts/build_armips.ps1 b/scripts/build_armips.ps1 index 3b16afa..5505211 100644 --- a/scripts/build_armips.ps1 +++ b/scripts/build_armips.ps1 @@ -40,5 +40,5 @@ function build-program { param( # build-program 'graphics_hello' 'hellogpu' # build-program 'graphics_hello' 'hello_gouraud' # build-program 'graphics_hello' 'hello_gp_routines' -# build-program 'graphics_hello' 'hello_image' -build-program 'graphics_hello' 'hello_logo' +build-program 'graphics_hello' 'hello_image' +# build-program 'graphics_hello' 'hello_logo' diff --git a/scripts/build_psyq.ps1 b/scripts/build_psyq.ps1 index 1cc7bab..6e87078 100644 --- a/scripts/build_psyq.ps1 +++ b/scripts/build_psyq.ps1 @@ -109,8 +109,8 @@ function assemble-unit { param( $assemble_args += '-x', 'assembler-with-cpp' $assemble_args += $f_compile, $unit, ($f_output + $link_module) - write-host "Assembling '$unit' -> '$link_module'" -ForegroundColor Cyan - $assemble_args | ForEach-Object { Write-Host "`t$_" -ForegroundColor Green } + write-host "Assembling '$unit' -> '$link_module'" -ForegroundColor DarkCyan + # $assemble_args | ForEach-Object { Write-Host "`t$_" -ForegroundColor Green } & $Compiler $assemble_args if ($LASTEXITCODE -ne 0) { write-error "Compilation failed for $unit. Aborting."; exit 1 } } @@ -150,8 +150,8 @@ function compile-unit { param( $compile_args += $f_compile $compile_args += $unit, ($f_output + $link_module) - write-host "Compiling '$unit' -> '$link_module'" -ForegroundColor Cyan - $compile_args | ForEach-Object { Write-Host "`t$_" -ForegroundColor Green } + write-host "Compiling '$unit' -> '$link_module'" -ForegroundColor DarkCyan + # $compile_args | ForEach-Object { Write-Host "`t$_" -ForegroundColor Green } & $Compiler $compile_args if ($LASTEXITCODE -ne 0) { write-error "Compilation failed for $unit. Aborting."; exit 1 } } @@ -220,9 +220,9 @@ function link-modules { param( $base_name = [System.IO.Path]::GetFileNameWithoutExtension($elf) $dasm = "$(join-path $path_build $base_name).dasm" - write-host "Linking modules into '$elf'" -ForegroundColor Cyan + write-host "Linking modules into '$elf'" -ForegroundColor DarkCyan $final_link_args += ($f_link_pass_through_prefix + $f_link_end_group) - $final_link_args | foreach-object { write-host $_ } + # $final_link_args | foreach-object { write-host $_ } & $Compiler $final_link_args & mipsel-none-elf-objdump.exe -W $elf >> $dasm if ($LASTEXITCODE -ne 0) { write-error "Linking failed. Aborting."; exit 1 } @@ -275,18 +275,19 @@ function build-graphis_hello { $path_module = join-path $path_code 'graphics_hello_psyq' - $src_asm_crt = join-path $path_nugget_common 'crt0/crt0.s' - $module_asm_crt = join-path $path_build 'crt0.o' - - $src_asm = join-path $path_module 'hello_gpu.s' - $module_asm = join-path $path_build 'hello_gpu.o' - $assemble_args = @() $assemble_args += $f_debug $assemble_args += $f_optimize_none $assemble_args += ($f_include + $path_code) - assemble-unit $src_asm_crt $module_asm_crt $includes $assemble_args - assemble-unit $src_asm $module_asm $includes $assemble_args + + $src_asm_crt = join-path $path_nugget_common 'crt0/crt0.s' + $module_asm_crt = join-path $path_build 'crt0.o' + # assemble-unit $src_asm_crt $module_asm_crt $includes $assemble_args + + $src_asm = join-path $path_module 'hello_gpu.s' + $module_asm = join-path $path_build 'hello_gpu.o' + + assemble-unit $src_asm $module_asm $includes $assemble_args $src_c = join-path $path_module 'hello_gpu.c' $module_c = join-path $path_build 'hello_gpu_c.o'