mirror of
https://github.com/Ed94/pikuma_ps1.git
synced 2026-06-01 18:41:13 -07:00
hello gp routines
This commit is contained in:
@@ -32,6 +32,15 @@ rtmp_1 equ $t1
|
||||
rtmp_2 equ $t2
|
||||
rtmp_3 equ $t3
|
||||
rtmp_4 equ $t4
|
||||
; Static Variables
|
||||
rstatic_0 equ $s0
|
||||
rstatic_1 equ $s1
|
||||
rstatic_2 equ $s2
|
||||
rstatic_3 equ $s3
|
||||
rstatic_4 equ $s4
|
||||
rstatic_5 equ $s5
|
||||
rstatic_6 equ $s6
|
||||
rstatic_7 equ $s7
|
||||
; Subroutine arguments
|
||||
rarg_0 equ $a0
|
||||
rarg_1 equ $a1
|
||||
|
||||
@@ -127,3 +127,43 @@ gp_b16_Y equ 16
|
||||
load_imm reg_scratch, cmd
|
||||
store_word reg_scratch, port
|
||||
.endmacro
|
||||
|
||||
.org 0x80010000 + 2000
|
||||
|
||||
.func gp_draw_tri_flat ;(
|
||||
@@io_offset equ rarg_0
|
||||
@@color equ rarg_1
|
||||
@@vert_1 equ rarg_2
|
||||
@@vert_2 equ rarg_3
|
||||
@@vert_3 equ rstatic_0
|
||||
;)
|
||||
@@cmd equ rtmp_2
|
||||
load_imm @@cmd, gp_Polygon
|
||||
or @@cmd, @@cmd, @@color
|
||||
store_word @@cmd, gpio_port0(@@io_offset)
|
||||
store_word @@vert_1, gpio_port0(@@io_offset)
|
||||
store_word @@vert_2, gpio_port0(@@io_offset)
|
||||
store_word @@vert_3, gpio_port0(@@io_offset)
|
||||
jump_reg rret_addr :: nop
|
||||
.endfunc
|
||||
|
||||
.func gp_draw_tri_grouand ;(
|
||||
@@io_offset equ rarg_0
|
||||
@@color equ rarg_1
|
||||
@@color_2 equ rstatic_1
|
||||
@@color_3 equ rstatic_2
|
||||
@@vert_1 equ rarg_2
|
||||
@@vert_2 equ rarg_3
|
||||
@@vert_3 equ rstatic_0
|
||||
;)
|
||||
@@cmd equ rtmp_2
|
||||
load_imm @@cmd, gp_Polygon | gp_Poly_ShadeGourand
|
||||
or @@cmd, @@cmd, @@color
|
||||
store_word @@cmd, gpio_port0(@@io_offset)
|
||||
store_word @@vert_1, gpio_port0(@@io_offset)
|
||||
store_word @@color_2, gpio_port0(@@io_offset)
|
||||
store_word @@vert_2, gpio_port0(@@io_offset)
|
||||
store_word @@color_3, gpio_port0(@@io_offset)
|
||||
store_word @@vert_3, gpio_port0(@@io_offset)
|
||||
jump_reg rret_addr :: nop
|
||||
.endfunc
|
||||
|
||||
@@ -27,11 +27,11 @@ main:
|
||||
gp1 equ gpio_port1(reg_io_offset)
|
||||
|
||||
; Setup Display Control
|
||||
gcmd_push gp0, rtmp_1, gp_Reset
|
||||
gcmd_push gp0, rtmp_1, gp_DisplayEnabled
|
||||
gcmd_push gp0, rtmp_1, gp_DisplayMode_320x240_15bit_NTSC
|
||||
gcmd_push gp0, rtmp_1, gp_HorizontalDisplayRange_3168_608
|
||||
gcmd_push gp0, rtmp_1, gp_VerticalDisplayRange_264_24
|
||||
gcmd_push gp1, rtmp_1, gp_Reset
|
||||
gcmd_push gp1, rtmp_1, gp_DisplayEnabled
|
||||
gcmd_push gp1, rtmp_1, gp_DisplayMode_320x240_15bit_NTSC
|
||||
gcmd_push gp1, rtmp_1, gp_HorizontalDisplayRange_3168_608
|
||||
gcmd_push gp1, rtmp_1, gp_VerticalDisplayRange_264_24
|
||||
gcmd_push gp0, rtmp_1, gp_ModeSetting_DipArea
|
||||
gcmd_push gp0, rtmp_1, gp_SetArea_TopLeft | 0 << gp_b10_Y | 0 << gp_b10_X
|
||||
gcmd_push gp0, rtmp_1, gp_SetArea_BottomRight | Display_Height << gp_b10_Y | Display_Width << gp_b10_X
|
||||
@@ -67,4 +67,3 @@ idle:
|
||||
jump idle :: nop
|
||||
|
||||
.close
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
.psx
|
||||
.create "./build/hello_gp_routines.bin", 0x80010000
|
||||
|
||||
.include "./code/graphics_system/dsl.s"
|
||||
.include "./code/graphics_system/gp.s"
|
||||
|
||||
; Entry Point of Code
|
||||
.org 0x80010000
|
||||
|
||||
Color_RedFF equ 0x0000FF
|
||||
Color_22 equ 0x222222
|
||||
Color_PS_CadmiumRed equ 0x2400DF
|
||||
Color_PS_CelticBlue equ 0x723F00
|
||||
Color_PS_GoldenPoppy equ 0x00C3F3
|
||||
Color_PS_PersianGreen equ 0x9FAC00
|
||||
|
||||
Display_Width equ 320
|
||||
Display_Height equ 239
|
||||
Display_HalfWidth equ 320 / 2
|
||||
Display_HalfHeight equ 240 / 2
|
||||
|
||||
main:
|
||||
reg_io_offset equ rtmp_0
|
||||
load_uimm rtmp_0, IO_BASE_ADDR
|
||||
|
||||
gp0 equ gpio_port0(reg_io_offset)
|
||||
gp1 equ gpio_port1(reg_io_offset)
|
||||
|
||||
; Setup Display Control
|
||||
gcmd_push gp1, rtmp_1, gp_Reset
|
||||
gcmd_push gp1, rtmp_1, gp_DisplayEnabled
|
||||
gcmd_push gp1, rtmp_1, gp_DisplayMode_320x240_15bit_NTSC
|
||||
gcmd_push gp1, rtmp_1, gp_HorizontalDisplayRange_3168_608
|
||||
gcmd_push gp1, rtmp_1, gp_VerticalDisplayRange_264_24
|
||||
gcmd_push gp0, rtmp_1, gp_ModeSetting_DipArea
|
||||
gcmd_push gp0, rtmp_1, gp_SetArea_TopLeft | 0 << gp_b10_Y | 0 << gp_b10_X
|
||||
gcmd_push gp0, rtmp_1, gp_SetArea_BottomRight | Display_Height << gp_b10_Y | Display_Width << gp_b10_X
|
||||
gcmd_push gp0, rtmp_1, gp_SetOffset | 0 << gp_b10_Y | 0 << gp_b10_X
|
||||
gcmd_push gp0, rtmp_1, gp_RectFillVM | Color_22
|
||||
gcmd_push gp0, rtmp_1, 0 << gp_b16_Y | 0 << gp_b16_X
|
||||
gcmd_push gp0, rtmp_1, Display_Height << gp_b16_Y | Display_Width << gp_b16_X
|
||||
; Draw a flat-shaded quad
|
||||
gcmd_push gp0, rtmp_1, gp_Quad | Color_PS_CelticBlue
|
||||
gcmd_push gp0, rtmp_1, 15 * -1 + Display_HalfHeight << gp_b16_Y | 0 + Display_HalfWidth << gp_b16_X
|
||||
gcmd_push gp0, rtmp_1, 24 * -1 + Display_HalfHeight << gp_b16_Y | 100 + Display_HalfWidth << gp_b16_X
|
||||
gcmd_push gp0, rtmp_1, -30 * -1 + Display_HalfHeight << gp_b16_Y | -100 + Display_HalfWidth << gp_b16_X
|
||||
gcmd_push gp0, rtmp_1, -50 * -1 + Display_HalfHeight << gp_b16_Y | 55 + Display_HalfWidth << gp_b16_X
|
||||
; Draw a flat-shaded triangle
|
||||
move rarg_0, reg_io_offset ; arg 1 for gp_draw_tri_flat
|
||||
load_imm rarg_1, Color_PS_GoldenPoppy
|
||||
load_imm rarg_2, 100 * -1 + Display_HalfHeight << gp_b16_Y | -100 + Display_HalfWidth << gp_b16_X
|
||||
load_imm rarg_3, 20 * -1 + Display_HalfHeight << gp_b16_Y | 20 + Display_HalfWidth << gp_b16_X
|
||||
load_imm rstatic_0, 50 * -1 + Display_HalfHeight << gp_b16_Y | 30 + Display_HalfWidth << gp_b16_X
|
||||
jump_nlink gp_draw_tri_flat :: nop
|
||||
; Bonus traingle
|
||||
load_imm rarg_1, Color_PS_CadmiumRed
|
||||
load_imm rarg_2, 50 * -1 + Display_HalfHeight << gp_b16_Y | -100 + Display_HalfWidth << gp_b16_X
|
||||
load_imm rarg_3, 0 * -1 + Display_HalfHeight << gp_b16_Y | 20 + Display_HalfWidth << gp_b16_X
|
||||
load_imm rstatic_0, -100 * -1 + Display_HalfHeight << gp_b16_Y | 30 + Display_HalfWidth << gp_b16_X
|
||||
jump_nlink gp_draw_tri_flat :: nop
|
||||
; Gourand shaded triangle
|
||||
load_imm rarg_1, Color_PS_PersianGreen
|
||||
load_imm rstatic_1, Color_PS_GoldenPoppy
|
||||
load_imm rstatic_2, Color_PS_CadmiumRed
|
||||
load_imm rarg_2, -35 * -1 + Display_HalfHeight << gp_b16_Y | 145 + Display_HalfWidth << gp_b16_X
|
||||
load_imm rarg_3, 0 * -1 + Display_HalfHeight << gp_b16_Y | 50 + Display_HalfWidth << gp_b16_X
|
||||
load_imm rstatic_0, 40 * -1 + Display_HalfHeight << gp_b16_Y | 60 + Display_HalfWidth << gp_b16_X
|
||||
jump_nlink gp_draw_tri_grouand :: nop
|
||||
|
||||
idle:
|
||||
jump idle :: nop
|
||||
|
||||
.close
|
||||
@@ -1,78 +0,0 @@
|
||||
.psx
|
||||
.create "./build/hellogpu_instructors.bin", 0x80010000
|
||||
|
||||
.org 0x80010000
|
||||
|
||||
; ---------------------
|
||||
; IO Port
|
||||
; ---------------------
|
||||
IO_BASE_ADDR equ 0x1F80 ; IO Ports Memory map base address
|
||||
|
||||
; ---------------------
|
||||
; GPU Registers
|
||||
; ---------------------
|
||||
GP0 equ 0x1810 ; GP0 @ $1F801810: Rendering data & VRAM Access
|
||||
GP1 equ 0x1814 ; GP1 @ $1F801814: Display Control & Environment setup
|
||||
|
||||
Main:
|
||||
lui $t0, IO_BASE_ADDR ; t0 = I/O Port Base Address (mapped at 0x1F80****)
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Send commands to GP1 (mapped at 0x1F801814)
|
||||
; These GP1 is for display control and environment setup
|
||||
; (Command = 8-Bit MSB, Parameter = 24-Bit LSB)
|
||||
; CCPPPPPP: CC=Command PPPPPP=Parameter
|
||||
; ---------------------------------------------------------------------------
|
||||
li $t1, 0x00000000 ; 00 = Reset GPU
|
||||
sw $t1, GP1($t0) ; Write to GP1
|
||||
|
||||
li $t1, 0x03000000 ; 03 = Display enable
|
||||
sw $t1, GP1($t0) ; Write to GP1
|
||||
|
||||
li $t1, 0x08000001 ; 08 = Display mode (320x240, 15-bit, NTSC)
|
||||
sw $t1, GP1($t0) ; Write to GP1
|
||||
|
||||
li $t1, 0x06C60260 ; 06 = Horz Display Range - 0bxxxxxxxxxxXXXXXXXXXX (3168..608)
|
||||
sw $t1, GP1($t0) ; Write to GP1
|
||||
|
||||
li $t1, 0x07042018 ; 07 = Vert Display Range - 0byyyyyyyyyyYYYYYYYYYY (264..24)
|
||||
sw $t1, GP1($t0) ; Write to GP1
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Send commands to GP0 (mapped at 0x1F801810)
|
||||
; These GP0 commands are to setup the drawing area
|
||||
; (Command = 8-Bit MSB, Parameter = 24-Bit LSB)
|
||||
; CCPPPPPP CC=Command PPPPPP=Parameter
|
||||
; ---------------------------------------------------------------------------
|
||||
li $t1, 0xE1000400 ; E1 = Draw Mode Settings
|
||||
sw $t1, GP0($t0) ; Write to GP0
|
||||
|
||||
li $t1, 0xE3000000 ; E3 = Drawing Area TopLeft - 0bYYYYYYYYYYXXXXXXXXXX (10 bits for Y and X)
|
||||
sw $t1, GP0($t0) ; Write to GP0
|
||||
|
||||
li $t1, 0xE403BD3F ; E4 = Drawing area BottomRight - 0bYYYYYYYYYYXXXXXXXXXX (10 bits for X=319 and Y=239)
|
||||
sw $t1, GP0($t0) ; Write to GP0
|
||||
|
||||
li $t1, 0xE5000000 ; E5 = Drawing Offset - 0bYYYYYYYYYYYXXXXXXXXXXXX (X=0, Y=0)
|
||||
sw $t1, GP0($t0) ; Write to GP0
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Clear the screen (draw a rectangle on VRAM).
|
||||
; ---------------------------------------------------------------------------
|
||||
li $t1, 0x020000FF ; 02 = Fill Rectancle in VRAM (Parameter Color: 0xBBGGRR)
|
||||
sw $t1, GP0($t0) ; Write GP0 Command
|
||||
li $t1, 0x00000000 ; Fill Area, Parameter: 0xYYYYXXXX - Topleft (0,0)
|
||||
sw $t1, GP0($t0) ; Write to GP0
|
||||
|
||||
li $t1, 0x00EF013F ; Fill Area, 0xHHHHWWWW (Height=239, Width=319)
|
||||
sw $t1, GP0($t0) ; Write to GP0
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; TODO: Draw a flat-shaded triangle
|
||||
; ---------------------------------------------------------------------------
|
||||
|
||||
LoopForever:
|
||||
j LoopForever ; Continuous loop
|
||||
nop
|
||||
|
||||
.close
|
||||
+8
-7
@@ -32,10 +32,11 @@ function build-program { param(
|
||||
write-host 'Done!'
|
||||
pop-location
|
||||
}
|
||||
build-program 'fillmem' 'fillmem'
|
||||
build-program 'warmup' 'exercise_1'
|
||||
build-program 'warmup' 'exercise_2'
|
||||
build-program 'warmup' 'exercise_3'
|
||||
build-program 'factorial' 'factorial'
|
||||
build-program 'graphics_system' 'hellogpu'
|
||||
build-program 'graphics_system' 'hello_gouraud'
|
||||
# build-program 'fillmem' 'fillmem'
|
||||
# build-program 'warmup' 'exercise_1'
|
||||
# build-program 'warmup' 'exercise_2'
|
||||
# build-program 'warmup' 'exercise_3'
|
||||
# build-program 'factorial' 'factorial'
|
||||
# build-program 'graphics_system' 'hellogpu'
|
||||
# build-program 'graphics_system' 'hello_gouraud'
|
||||
build-program 'graphics_system' 'hello_gp_routines'
|
||||
|
||||
Reference in New Issue
Block a user