From fcbf5b60fff09ed28247b91f22af3c376d45ec05 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Tue, 13 Apr 2021 05:36:05 +0100 Subject: [PATCH] [gs] fill in most of the register types (#355) * [gs] fill in most of the register types that was kinda boring to do * [display-h] minor decompiler fixes * Update all-types.gc --- decompiler/config/all-types.gc | 344 ++++++++++++--- .../jak1_ntsc_black_label/var_names.jsonc | 9 + goal_src/engine/gfx/hw/display-h.gc | 4 +- goal_src/engine/gfx/hw/gs.gc | 414 ++++++++++++++---- 4 files changed, 627 insertions(+), 144 deletions(-) diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 3963dd95b3..11354a331c 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -2743,17 +2743,23 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~; -;; L139 - #x900000008 -;; L138 - -;; L137 - - (deftype gs-pmode (uint64) - () + ((en1 uint8 :offset 0 :size 1) + (en2 uint8 :offset 1 :size 1) + (crtmd uint8 :offset 2 :size 3) + (mmod uint8 :offset 5 :size 1) + (amod uint8 :offset 6 :size 1) + (slbg uint8 :offset 7 :size 1) + (alp uint8 :offset 8 :size 8) + ) :flag-assert #x900000008 ) (deftype gs-smode2 (uint64) - () + ((int uint8 :offset 0 :size 1) + (ffmd uint8 :offset 1 :size 1) + (dpms uint8 :offset 2 :size 2) + ) :flag-assert #x900000008 ) @@ -2762,25 +2768,59 @@ (define-extern psm->string (function int string)) (deftype gs-display-fb (uint64) - () + ((fbp uint16 :offset 0 :size 9) + (fbw uint8 :offset 9 :size 6) + (psm uint8 :offset 15 :size 5) + (dbx uint16 :offset 32 :size 11) + (dby uint16 :offset 43 :size 11) + ) :flag-assert #x900000008 ) - +;; the GS's DISPLAY registers make settings for the display position on the screen regarding +;; information on Rectangular Area Read Output Circuit n for the PCRTC. +;; write-only (deftype gs-display (uint64) - () + ((dx uint16 :offset 0 :size 12) + (dy uint16 :offset 12 :size 11) + (magh uint8 :offset 23 :size 4) + (magv uint8 :offset 27 :size 2) + (dw uint16 :offset 32 :size 12) + (dh uint16 :offset 44 :size 11) + ) :flag-assert #x900000008 ) - +;; the GS's BGCOLOR register sets the background color of the PCRTC with RGB value. +;; write-only (deftype gs-bgcolor (uint64) - () + ((r uint8 :offset 0 :size 8) + (g uint8 :offset 0 :size 8) + (b uint8 :offset 0 :size 8) + ) :flag-assert #x900000008 ) - +;; the GS's CSR register sets and obtains various GS statuses. +;; read-write. the fields have different effects depending on whether they're being read from +;; or written to. +;; bits 5 and 6 (0x20 and 0x40) should be zero (deftype gs-csr (uint64) - () + ((signal uint8 :offset 0 :size 1) + (finish uint8 :offset 1 :size 1) + (hsint uint8 :offset 2 :size 1) + (vsint uint8 :offset 3 :size 1) + (edwint uint8 :offset 4 :size 1) + (flush uint8 :offset 8 :size 1) + (reset uint8 :offset 9 :size 1) + (nfield uint8 :offset 12 :size 1) + (field uint8 :offset 13 :size 1) + (fifo uint8 :offset 14 :size 2) + (rev uint8 :offset 16 :size 8) + (id uint8 :offset 24 :size 8) + ) :flag-assert #x900000008 ) +;; memory layout of the GS's privileged registers +;; it is missing the SIGLBLID/LABELID register at 4224 (useless anyway?) (deftype gs-bank (structure) ((pmode gs-pmode :offset-assert 0) (smode2 gs-smode2 :offset 32) @@ -2800,134 +2840,317 @@ :size-assert #x1048 :flag-assert #x900001048 ) - +;; the GS's FRAME registers store various settings related to the frame buffer. (deftype gs-frame (uint64) - () + ((fbp uint16 :offset 0 :size 9) + (fbw uint8 :offset 16 :size 6) + (psm uint8 :offset 24 :size 6) + (fbmsk uint32 :offset 32 :size 32) + ) :flag-assert #x900000008 ) +;; the GS's ZBUF registers make various settings regarding Z buffer. (deftype gs-zbuf (uint64) - () + ((zbp uint16 :offset 0 :size 9) + (psm uint8 :offset 24 :size 4) + (zmsk uint8 :offset 32 :size 1) + ) :flag-assert #x900000008 ) +;; the GS's XYOFFSET registers set the offset value for converting from the primitive coordinate +;; system to the window coordinate system. (deftype gs-xy-offset (uint64) - () + ((ofx uint16 :offset 0 :size 16) + (ofy uint16 :offset 32 :size 16) + ) :flag-assert #x900000008 ) +;; the GS's SCISSOR registers specify the scissoring area. The coordinate values for +;; the upper-left/lower-right points of the enabled drawing area are specified by the window +;; coordinate system. (deftype gs-scissor (uint64) - () + ((scax0 uint16 :offset 0 :size 11) + (scax1 uint16 :offset 16 :size 11) + (scay0 uint16 :offset 32 :size 11) + (scay1 uint16 :offset 48 :size 11) + ) :flag-assert #x900000008 ) +;; the GS's PRMODECONT register sets whether to use primitive attributes (IIP, TME, FGE, ABE, +;; AA1, FST, CTXT, FIX) specified by the PRMODE register or the PRIM register. (deftype gs-prmode-cont (uint64) - () + ((ac uint8 :offset 0 :size 1)) :flag-assert #x900000008 ) +;; the GS's COLCLAMP register stores settings as to whether clamping for the RGB value of the +;; pixel is performed. (deftype gs-color-clamp (uint64) - () + ((clamp uint8 :offset 0 :size 1)) :flag-assert #x900000008 ) +;; the GS's DTHE register stores settings for dithering (performed/not performed). (deftype gs-dthe (uint64) - () + ((dthe uint8 :offset 0 :size 1)) :flag-assert #x900000008 ) +;; the GS's TEST register performs settings related to the pixel test. (deftype gs-test (uint64) - () + ((ate uint8 :offset 0 :size 1) ;; alpha test enable + (atst uint8 :offset 1 :size 3) ;; alpha test method + (aref uint8 :offset 4 :size 8) ;; alpha val reference + (afail uint8 :offset 12 :size 2) ;; processing method on alpha test fail + (date uint8 :offset 14 :size 1) ;; dest alpha test enable + (datm uint8 :offset 15 :size 1) ;; dest alpha test mode + (zte uint8 :offset 16 :size 1) ;; depth test enable + (ztst uint8 :offset 17 :size 2) ;; depth test method + ) :flag-assert #x900000008 ) +;; the GS's PRIM register specifies the types of drawing primitives and various attributes, and +;; initializes the contents of the vertex queue. (deftype gs-prim (uint64) - () + (;; type of primitive: + ;; - 0: point + ;; - 1: line + ;; - 2: line strip + ;; - 3: tri + ;; - 4: tri strip + ;; - 5: tri fan + ;; - 6: sprite (what?) + ;; - 7: dark magic? + (prim uint8 :offset 0 :size 3) + (iip uint8 :offset 3 :size 1) + (tme uint8 :offset 4 :size 1) + (fge uint8 :offset 5 :size 1) + (abe uint8 :offset 6 :size 1) + (aa1 uint8 :offset 7 :size 1) + (fst uint8 :offset 8 :size 1) + (ctxt uint8 :offset 9 :size 1) + (fix uint8 :offset 10 :size 1) + ) :flag-assert #x900000008 ) +;; the GS's RGBAQ register sets the RGBA value of the vertex and the Q value of the normalized +;; texture coordinates. (deftype gs-rgbaq (uint64) - () + ((r uint8 :offset 0 :size 8) + (g uint8 :offset 8 :size 8) + (b uint8 :offset 16 :size 8) + (a uint8 :offset 24 :size 8) ;; 0x80 --> 1.0 + (q float :offset 32 :size 32) ;; affects some LOD behavior apparently? + ) :flag-assert #x900000008 ) +;; GS XYZ registers (deftype gs-xyz (uint64) - () + ((x uint16 :offset 0 :size 16) ;; Q4 fixed point + (y uint16 :offset 16 :size 16) ;; Q4 fixed point + (z uint32 :offset 32 :size 32) + ) :flag-assert #x900000008 ) +;; the GS's UV register specifies the texel coordinate (UV) values of the vertex. (deftype gs-uv (uint64) - () + ((u uint16 :offset 0 :size 14) ;; Q4 fixed point + (v uint16 :offset 16 :size 14) ;; Q4 fixed point + ) :flag-assert #x900000008 ) +;; the GS's ST register sets the S and T values of the vertex texture coordinates. +;; The value Q is specified by the RGBAQ register. (deftype gs-st (uint64) - () + ((s float :offset 0 :size 32) + (t float :offset 32 :size 32) + ) :flag-assert #x900000008 ) +;; GS XYZF registers (deftype gs-xyzf (uint64) - () + ((x uint16 :offset 0 :size 16) ;; Q4 fixed point + (y uint16 :offset 16 :size 16) ;; Q4 fixed point + (z uint32 :offset 32 :size 24) + (f uint8 :offset 56 :size 8) ;; fog coeff + ) :flag-assert #x900000008 ) +;; the GS's TRXPOS register specifies the position and scanning direction of the rectangular area +;; in each buffer where buffer transmission is performed. (deftype gs-trxpos (uint64) - () + ((ssax uint16 :offset 0 :size 11) + (ssay uint16 :offset 16 :size 11) + (dsax uint16 :offset 32 :size 11) + (dsay uint16 :offset 48 :size 11) + (dir uint8 :offset 59 :size 2) + ) :flag-assert #x900000008 ) +;; the GS's TRXREG register specifies the size of the rectangular area, where the transmission +;; between buffers is implemented, in units of pixels. +;; The pixel mode must be the one set by the BITBLTBUF register. (deftype gs-trxreg (uint64) - () + ((rrw uint16 :offset 0 :size 12) + (rrh uint16 :offset 32 :size 12) + ) :flag-assert #x900000008 ) +;; the GS's TRXDIR register specifies the transmission direction in the transmission between +;; buffers, and activates transmission. +;; Appropriate settings must be made by the BITBLTBUF/TRXPOS/TRXREG before activating +;; the transmission. (deftype gs-trxdir (uint64) - () + ((xdir uint8 :offset 0 :size 2)) :flag-assert #x900000008 ) +;; the GS's BITBLTBUF register stores buffer-related settings for transmission source and +;; destination during transmission between buffers. (deftype gs-bitbltbuf (uint64) - () + ((sbp uint16 :offset 0 :size 14) + (sbw uint8 :offset 16 :size 6) + (spsm uint8 :offset 24 :size 6) + (dbp uint16 :offset 32 :size 14) + (dbw uint8 :offset 48 :size 6) + (dpsm uint8 :offset 56 :size 6) + ) :flag-assert #x900000008 ) +;; the GS's TEX0 registers set various kinds of information regarding the textures to be used. (deftype gs-tex0 (uint64) - () + ((tbp0 uint16 :offset 0 :size 14) + (tbw uint8 :offset 14 :size 6) + (psm uint8 :offset 20 :size 6) + (tw uint8 :offset 26 :size 4) + (th uint8 :offset 30 :size 4) + (tcc uint8 :offset 34 :size 1) + (tfx uint8 :offset 35 :size 2) + (cbp uint16 :offset 37 :size 14) + (cpsm uint8 :offset 51 :size 4) + (csm uint8 :offset 55 :size 1) + (csa uint8 :offset 56 :size 5) + (cld uint8 :offset 61 :size 3) + ) :flag-assert #x900000008 ) +;; the GS's TEX1 registers set information on the sampling method of the textures. (deftype gs-tex1 (uint64) - () + ((lcm uint8 :offset 0 :size 1) + (mxl uint8 :offset 2 :size 3) + (mmag uint8 :offset 5 :size 1) + (mmin uint8 :offset 6 :size 3) + (mtba uint8 :offset 9 :size 1) + (l uint8 :offset 19 :size 2) + (k int16 :offset 32 :size 12) + ) :flag-assert #x900000008 ) +;; the GS's TEXA register sets the Alpha value to be referred to when the Alpha value of the +;; texture is not an 8-bit value. (deftype gs-texa (uint64) - () + ((ta0 uint8 :offset 0 :size 8) + (aem uint8 :offset 15 :size 1) + (ta1 uint8 :offset 32 :size 8) + ) :flag-assert #x900000008 ) +;; the GS's TEXCLUT register specifies the CLUT position in the buffer when the CLUT storage mode +;; is CSM=1 (CSM2 mode). (deftype gs-texclut (uint64) - () + ((cbw uint8 :offset 0 :size 6) + (cou uint8 :offset 6 :size 6) + (cov uint16 :offset 12 :size 10) + ) :flag-assert #x900000008 ) +;; the GS's MIPTBP registers set the buffer pointer and buffer width of textures when performing +;; MIPMAP. +;; MIPTBP1 sets levels 1 to 3, MIPTBP2 sets levels 4 to 6. (deftype gs-miptbp (uint64) - () + ((tbp1 uint16 :offset 0 :size 14) + (tbw1 uint8 :offset 14 :size 6) + (tbp2 uint16 :offset 20 :size 14) + (tbw2 uint8 :offset 34 :size 6) + (tbp3 uint16 :offset 40 :size 14) + (tbw3 uint8 :offset 54 :size 6) + ) :flag-assert #x900000008 ) +;; the GS's ALPHA registers define the blend function of alpha blending (deftype gs-alpha (uint64) - () + ((a uint8 :offset 0 :size 2) + (b uint8 :offset 2 :size 2) + (c uint8 :offset 4 :size 2) + (d uint8 :offset 6 :size 2) + (fix uint8 :offset 32 :size 8) + ) :flag-assert #x900000008 ) + +(deftype gs-clamp (uint64) + ((wms uint8 :offset 0 :size 2) + (wmt uint8 :offset 2 :size 2) + (minu uint16 :offset 4 :size 10) + (maxu uint16 :offset 14 :size 10) + (minv uint16 :offset 24 :size 10) + (maxv uint16 :offset 34 :size 10) + ) + :flag-assert #x900000008 + ) + (deftype gs-fog (uint64) - () + ((f uint8 :offset 56 :size 8)) :flag-assert #x900000008 ) + (deftype gs-fogcol (uint64) - () + ((fcr uint8 :offset 0 :size 8) + (fcg uint8 :offset 8 :size 8) + (fcb uint8 :offset 16 :size 8) + ) :flag-assert #x900000008 ) (deftype gif-ctrl (uint32) - () + ((rst uint8 :offset 0 :size 1) + (pse uint8 :offset 3 :size 1) + ) :flag-assert #x900000004 ) (deftype gif-mode (uint32) - () + ((m3r uint8 :offset 0 :size 1) + (imt uint8 :offset 2 :size 1) + ) :flag-assert #x900000004 ) (deftype gif-stat (uint32) - () + ((m3r uint8 :offset 0 :size 1) + (m3p uint8 :offset 1 :size 1) + (imt uint8 :offset 2 :size 1) + (pse uint8 :offset 3 :size 1) + (ip3 uint8 :offset 5 :size 1) + (p3q uint8 :offset 6 :size 1) + (p2q uint8 :offset 7 :size 1) + (p1q uint8 :offset 8 :size 1) + (oph uint8 :offset 9 :size 1) + (apath uint8 :offset 10 :size 2) + (dir uint8 :offset 12 :size 1) + (fqc uint8 :offset 24 :size 5) + ) :flag-assert #x900000004 ) (deftype gif-cnt (uint32) - () + ((loopcnt uint16 :offset 0 :size 15) + (regcnt uint8 :offset 16 :size 4) + (vuaddr uint16 :offset 20 :size 10) + ) :flag-assert #x900000004 ) (deftype gif-p3cnt (uint32) - () + ((p3cnt uint16 :offset 0 :size 15)) :flag-assert #x900000004 ) (deftype gif-p3tag (uint32) - () + ((loopcnt uint16 :offset 0 :size 15) + (eop uint8 :offset 15 :size 1) + ) :flag-assert #x900000004 ) @@ -2961,7 +3184,30 @@ :flag-assert #x900000008 ) (deftype gif-tag (uint128) - () + ((nloop uint16 :offset 0 :size 15) + (eop uint8 :offset 15 :size 1) + (id uint16 :offset 32 :size 14) + (pre uint8 :offset 46 :size 1) + (prim uint16 :offset 47 :size 11) + (flg uint8 :offset 58 :size 2) + (nreg uint8 :offset 60 :size 4) + (regs0 uint8 :offset 64 :size 4) + (regs1 uint8 :offset 68 :size 4) + (regs2 uint8 :offset 72 :size 4) + (regs3 uint8 :offset 76 :size 4) + (regs4 uint8 :offset 80 :size 4) + (regs5 uint8 :offset 84 :size 4) + (regs6 uint8 :offset 88 :size 4) + (regs7 uint8 :offset 92 :size 4) + (regs8 uint8 :offset 96 :size 4) + (regs9 uint8 :offset 100 :size 4) + (regs10 uint8 :offset 104 :size 4) + (regs11 uint8 :offset 108 :size 4) + (regs12 uint8 :offset 112 :size 4) + (regs13 uint8 :offset 116 :size 4) + (regs14 uint8 :offset 120 :size 4) + (regs15 uint8 :offset 124 :size 4) + ) :flag-assert #x900000010 ) @@ -3113,9 +3359,9 @@ :flag-assert #x900000080 ) -;;(define-extern *post-draw-hook* object) ;; unknown type +(define-extern *post-draw-hook* (function none)) ;; unknown type (define-extern put-draw-env (function dma-packet none)) -;;(define-extern *pre-draw-hook* object) ;; unknown type +(define-extern *pre-draw-hook* (function none)) ;; unknown type (deftype display-frame (basic) diff --git a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc index a144bd9669..ad72e82a8c 100644 --- a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc @@ -758,6 +758,15 @@ "args": ["allocation", "type-to-make", "psm", "w", "h", "ztest", "zpsm"], "vars": { "gp-0": "obj" } }, + + "(method 0 draw-context)": { + "args": ["allocation", "type-to-make", "org-x", "org-y", "width", "height", "color-0"], + "vars": { "v0-0": "obj"} + }, + + "draw-context-set-xy": { + "args": ["ctxt", "x", "y"] + }, "(method 9 __assert-info-private-struct)": { "args": ["obj", "filename", "line-num", "column-num"] diff --git a/goal_src/engine/gfx/hw/display-h.gc b/goal_src/engine/gfx/hw/display-h.gc index dcbce07f97..b1da53dd30 100644 --- a/goal_src/engine/gfx/hw/display-h.gc +++ b/goal_src/engine/gfx/hw/display-h.gc @@ -5,9 +5,6 @@ ;; name in dgo: display-h ;; dgos: GAME, ENGINE -(declare-type display basic) -(define-extern set-display (function display int int int int int display)) - (deftype display-env (structure) ((pmode uint64 :offset-assert 0) (smode2 uint64 :offset-assert 8) @@ -144,6 +141,7 @@ (define-extern *display* display) +(define-extern set-display (function display int int int int int display)) (defmethod new display ((allocation symbol) (type-to-make type) (psm int) (w int) (h int) (ztest int) (zpsm int)) (local-vars (obj display)) (set! obj diff --git a/goal_src/engine/gfx/hw/gs.gc b/goal_src/engine/gfx/hw/gs.gc index 517f69d4e4..565c935d67 100644 --- a/goal_src/engine/gfx/hw/gs.gc +++ b/goal_src/engine/gfx/hw/gs.gc @@ -5,13 +5,25 @@ ;; name in dgo: gs ;; dgos: GAME, ENGINE +;; the GS's PMODE register makes various settings for the PCRTC. (deftype gs-pmode (uint64) - () + ((en1 uint8 :offset 0 :size 1) + (en2 uint8 :offset 1 :size 1) + (crtmd uint8 :offset 2 :size 3) + (mmod uint8 :offset 5 :size 1) + (amod uint8 :offset 6 :size 1) + (slbg uint8 :offset 7 :size 1) + (alp uint8 :offset 8 :size 8) + ) :flag-assert #x900000008 ) +;; the GS's SMODE2 register makes settings related to PCRTC video synchronization. (deftype gs-smode2 (uint64) - () + ((int uint8 :offset 0 :size 1) + (ffmd uint8 :offset 1 :size 1) + (dpms uint8 :offset 2 :size 2) + ) :flag-assert #x900000008 ) @@ -87,26 +99,63 @@ ) ) +;; the GS's DISPFB registers make settings for the frame buffer regarding information on +;; Rectangular Area Read Output Circuit n for the PCRTC. +;; write-only (deftype gs-display-fb (uint64) - () + ((fbp uint16 :offset 0 :size 9) + (fbw uint8 :offset 9 :size 6) + (psm uint8 :offset 15 :size 5) + (dbx uint16 :offset 32 :size 11) + (dby uint16 :offset 43 :size 11) + ) :flag-assert #x900000008 ) - +;; the GS's DISPLAY registers make settings for the display position on the screen regarding +;; information on Rectangular Area Read Output Circuit n for the PCRTC. +;; write-only (deftype gs-display (uint64) - () + ((dx uint16 :offset 0 :size 12) + (dy uint16 :offset 12 :size 11) + (magh uint8 :offset 23 :size 4) + (magv uint8 :offset 27 :size 2) + (dw uint16 :offset 32 :size 12) + (dh uint16 :offset 44 :size 11) + ) :flag-assert #x900000008 ) - +;; the GS's BGCOLOR register sets the background color of the PCRTC with RGB value. +;; write-only (deftype gs-bgcolor (uint64) - () + ((r uint8 :offset 0 :size 8) + (g uint8 :offset 0 :size 8) + (b uint8 :offset 0 :size 8) + ) :flag-assert #x900000008 ) - +;; the GS's CSR register sets and obtains various GS statuses. +;; read-write. the fields have different effects depending on whether they're being read from +;; or written to. +;; bits 5 and 6 (0x20 and 0x40) should be zero (deftype gs-csr (uint64) - () + ((signal uint8 :offset 0 :size 1) + (finish uint8 :offset 1 :size 1) + (hsint uint8 :offset 2 :size 1) + (vsint uint8 :offset 3 :size 1) + (edwint uint8 :offset 4 :size 1) + (flush uint8 :offset 8 :size 1) + (reset uint8 :offset 9 :size 1) + (nfield uint8 :offset 12 :size 1) + (field uint8 :offset 13 :size 1) + (fifo uint8 :offset 14 :size 2) + (rev uint8 :offset 16 :size 8) + (id uint8 :offset 24 :size 8) + ) :flag-assert #x900000008 ) +;; memory layout of the GS's privileged registers +;; it is missing the SIGLBLID/LABELID register at 4224 (useless anyway?) (deftype gs-bank (structure) ((pmode gs-pmode :offset-assert 0) (smode2 gs-smode2 :offset 32) @@ -126,160 +175,317 @@ :size-assert #x1048 :flag-assert #x900001048 ) - +;; the GS's FRAME registers store various settings related to the frame buffer. (deftype gs-frame (uint64) - () + ((fbp uint16 :offset 0 :size 9) + (fbw uint8 :offset 16 :size 6) + (psm uint8 :offset 24 :size 6) + (fbmsk uint32 :offset 32 :size 32) + ) :flag-assert #x900000008 ) +;; the GS's ZBUF registers make various settings regarding Z buffer. (deftype gs-zbuf (uint64) - () + ((zbp uint16 :offset 0 :size 9) + (psm uint8 :offset 24 :size 4) + (zmsk uint8 :offset 32 :size 1) + ) :flag-assert #x900000008 ) +;; the GS's XYOFFSET registers set the offset value for converting from the primitive coordinate +;; system to the window coordinate system. (deftype gs-xy-offset (uint64) - () + ((ofx uint16 :offset 0 :size 16) + (ofy uint16 :offset 32 :size 16) + ) :flag-assert #x900000008 ) +;; the GS's SCISSOR registers specify the scissoring area. The coordinate values for +;; the upper-left/lower-right points of the enabled drawing area are specified by the window +;; coordinate system. (deftype gs-scissor (uint64) - () + ((scax0 uint16 :offset 0 :size 11) + (scax1 uint16 :offset 16 :size 11) + (scay0 uint16 :offset 32 :size 11) + (scay1 uint16 :offset 48 :size 11) + ) :flag-assert #x900000008 ) +;; the GS's PRMODECONT register sets whether to use primitive attributes (IIP, TME, FGE, ABE, +;; AA1, FST, CTXT, FIX) specified by the PRMODE register or the PRIM register. (deftype gs-prmode-cont (uint64) - () + ((ac uint8 :offset 0 :size 1)) :flag-assert #x900000008 ) +;; the GS's COLCLAMP register stores settings as to whether clamping for the RGB value of the +;; pixel is performed. (deftype gs-color-clamp (uint64) - () + ((clamp uint8 :offset 0 :size 1)) :flag-assert #x900000008 ) +;; the GS's DTHE register stores settings for dithering (performed/not performed). (deftype gs-dthe (uint64) - () + ((dthe uint8 :offset 0 :size 1)) :flag-assert #x900000008 ) +;; the GS's TEST register performs settings related to the pixel test. (deftype gs-test (uint64) - () + ((ate uint8 :offset 0 :size 1) ;; alpha test enable + (atst uint8 :offset 1 :size 3) ;; alpha test method + (aref uint8 :offset 4 :size 8) ;; alpha val reference + (afail uint8 :offset 12 :size 2) ;; processing method on alpha test fail + (date uint8 :offset 14 :size 1) ;; dest alpha test enable + (datm uint8 :offset 15 :size 1) ;; dest alpha test mode + (zte uint8 :offset 16 :size 1) ;; depth test enable + (ztst uint8 :offset 17 :size 2) ;; depth test method + ) :flag-assert #x900000008 ) +;; the GS's PRIM register specifies the types of drawing primitives and various attributes, and +;; initializes the contents of the vertex queue. (deftype gs-prim (uint64) - () + (;; type of primitive: + ;; - 0: point + ;; - 1: line + ;; - 2: line strip + ;; - 3: tri + ;; - 4: tri strip + ;; - 5: tri fan + ;; - 6: sprite (what?) + ;; - 7: dark magic? + (prim uint8 :offset 0 :size 3) + (iip uint8 :offset 3 :size 1) + (tme uint8 :offset 4 :size 1) + (fge uint8 :offset 5 :size 1) + (abe uint8 :offset 6 :size 1) + (aa1 uint8 :offset 7 :size 1) + (fst uint8 :offset 8 :size 1) + (ctxt uint8 :offset 9 :size 1) + (fix uint8 :offset 10 :size 1) + ) :flag-assert #x900000008 ) +;; the GS's RGBAQ register sets the RGBA value of the vertex and the Q value of the normalized +;; texture coordinates. (deftype gs-rgbaq (uint64) - () + ((r uint8 :offset 0 :size 8) + (g uint8 :offset 8 :size 8) + (b uint8 :offset 16 :size 8) + (a uint8 :offset 24 :size 8) ;; 0x80 --> 1.0 + (q float :offset 32 :size 32) ;; affects some LOD behavior apparently? + ) :flag-assert #x900000008 ) +;; GS XYZ registers (deftype gs-xyz (uint64) - () + ((x uint16 :offset 0 :size 16) ;; Q4 fixed point + (y uint16 :offset 16 :size 16) ;; Q4 fixed point + (z uint32 :offset 32 :size 32) + ) :flag-assert #x900000008 ) +;; the GS's UV register specifies the texel coordinate (UV) values of the vertex. (deftype gs-uv (uint64) - () + ((u uint16 :offset 0 :size 14) ;; Q4 fixed point + (v uint16 :offset 16 :size 14) ;; Q4 fixed point + ) :flag-assert #x900000008 ) +;; the GS's ST register sets the S and T values of the vertex texture coordinates. +;; The value Q is specified by the RGBAQ register. (deftype gs-st (uint64) - () + ((s float :offset 0 :size 32) + (t float :offset 32 :size 32) + ) :flag-assert #x900000008 ) +;; GS XYZF registers (deftype gs-xyzf (uint64) - () + ((x uint16 :offset 0 :size 16) ;; Q4 fixed point + (y uint16 :offset 16 :size 16) ;; Q4 fixed point + (z uint32 :offset 32 :size 24) + (f uint8 :offset 56 :size 8) ;; fog coeff + ) :flag-assert #x900000008 ) +;; the GS's TRXPOS register specifies the position and scanning direction of the rectangular area +;; in each buffer where buffer transmission is performed. (deftype gs-trxpos (uint64) - () + ((ssax uint16 :offset 0 :size 11) + (ssay uint16 :offset 16 :size 11) + (dsax uint16 :offset 32 :size 11) + (dsay uint16 :offset 48 :size 11) + (dir uint8 :offset 59 :size 2) + ) :flag-assert #x900000008 ) +;; the GS's TRXREG register specifies the size of the rectangular area, where the transmission +;; between buffers is implemented, in units of pixels. +;; The pixel mode must be the one set by the BITBLTBUF register. (deftype gs-trxreg (uint64) - () + ((rrw uint16 :offset 0 :size 12) + (rrh uint16 :offset 32 :size 12) + ) :flag-assert #x900000008 ) +;; the GS's TRXDIR register specifies the transmission direction in the transmission between +;; buffers, and activates transmission. +;; Appropriate settings must be made by the BITBLTBUF/TRXPOS/TRXREG before activating +;; the transmission. (deftype gs-trxdir (uint64) - () + ((xdir uint8 :offset 0 :size 2)) :flag-assert #x900000008 ) +;; the GS's BITBLTBUF register stores buffer-related settings for transmission source and +;; destination during transmission between buffers. (deftype gs-bitbltbuf (uint64) - () + ((sbp uint16 :offset 0 :size 14) + (sbw uint8 :offset 16 :size 6) + (spsm uint8 :offset 24 :size 6) + (dbp uint16 :offset 32 :size 14) + (dbw uint8 :offset 48 :size 6) + (dpsm uint8 :offset 56 :size 6) + ) :flag-assert #x900000008 ) +;; the GS's TEX0 registers set various kinds of information regarding the textures to be used. (deftype gs-tex0 (uint64) - () + ((tbp0 uint16 :offset 0 :size 14) + (tbw uint8 :offset 14 :size 6) + (psm uint8 :offset 20 :size 6) + (tw uint8 :offset 26 :size 4) + (th uint8 :offset 30 :size 4) + (tcc uint8 :offset 34 :size 1) + (tfx uint8 :offset 35 :size 2) + (cbp uint16 :offset 37 :size 14) + (cpsm uint8 :offset 51 :size 4) + (csm uint8 :offset 55 :size 1) + (csa uint8 :offset 56 :size 5) + (cld uint8 :offset 61 :size 3) + ) :flag-assert #x900000008 ) +;; the GS's TEX1 registers set information on the sampling method of the textures. (deftype gs-tex1 (uint64) - () + ((lcm uint8 :offset 0 :size 1) + (mxl uint8 :offset 2 :size 3) + (mmag uint8 :offset 5 :size 1) + (mmin uint8 :offset 6 :size 3) + (mtba uint8 :offset 9 :size 1) + (l uint8 :offset 19 :size 2) + (k int16 :offset 32 :size 12) + ) :flag-assert #x900000008 ) +;; the GS's TEXA register sets the Alpha value to be referred to when the Alpha value of the +;; texture is not an 8-bit value. (deftype gs-texa (uint64) - () + ((ta0 uint8 :offset 0 :size 8) + (aem uint8 :offset 15 :size 1) + (ta1 uint8 :offset 32 :size 8) + ) :flag-assert #x900000008 ) +;; the GS's TEXCLUT register specifies the CLUT position in the buffer when the CLUT storage mode +;; is CSM=1 (CSM2 mode). (deftype gs-texclut (uint64) - () + ((cbw uint8 :offset 0 :size 6) + (cou uint8 :offset 6 :size 6) + (cov uint16 :offset 12 :size 10) + ) :flag-assert #x900000008 ) +;; the GS's MIPTBP registers set the buffer pointer and buffer width of textures when performing +;; MIPMAP. +;; MIPTBP1 sets levels 1 to 3, MIPTBP2 sets levels 4 to 6. (deftype gs-miptbp (uint64) - () + ((tbp1 uint16 :offset 0 :size 14) + (tbw1 uint8 :offset 14 :size 6) + (tbp2 uint16 :offset 20 :size 14) + (tbw2 uint8 :offset 34 :size 6) + (tbp3 uint16 :offset 40 :size 14) + (tbw3 uint8 :offset 54 :size 6) + ) :flag-assert #x900000008 ) +;; the GS's ALPHA registers define the blend function of alpha blending (deftype gs-alpha (uint64) - () + ((a uint8 :offset 0 :size 2) + (b uint8 :offset 2 :size 2) + (c uint8 :offset 4 :size 2) + (d uint8 :offset 6 :size 2) + (fix uint8 :offset 32 :size 8) + ) :flag-assert #x900000008 ) - -(defmethod inspect gs-alpha ((obj gs-alpha)) - (format #t "[~8x] ~A~%" obj 'gs-alpha) - (format #t "~Ta: ~D~%" (shr (shl (the-as int obj) 62) 62)) - (format #t "~Tb: ~D~%" (shr (shl (the-as int obj) 60) 62)) - (format #t "~Tc: ~D~%" (shr (shl (the-as int obj) 58) 62)) - (format #t "~Td: ~D~%" (shr (shl (the-as int obj) 56) 62)) - (format #t "~Tfix: ~D~%" (shr (shl (the-as int obj) 24) 56)) - obj +;; the GS's CLAMP registers set the texture's wrap mode (repeating or clamping) for both S and T. +(deftype gs-clamp (uint64) + ((wms uint8 :offset 0 :size 2) + (wmt uint8 :offset 2 :size 2) + (minu uint16 :offset 4 :size 10) + (maxu uint16 :offset 14 :size 10) + (minv uint16 :offset 24 :size 10) + (maxv uint16 :offset 34 :size 10) + ) + :flag-assert #x900000008 ) (deftype gs-fog (uint64) - () + ((f uint8 :offset 56 :size 8)) :flag-assert #x900000008 ) -(defmethod inspect gs-fog ((obj gs-fog)) - (format #t "[~8x] ~A~%" obj 'gs-fog) - (format #t "~Tf: ~D~%" (shr (the-as int obj) 56)) - obj - ) - (deftype gs-fogcol (uint64) - () + ((fcr uint8 :offset 0 :size 8) + (fcg uint8 :offset 8 :size 8) + (fcb uint8 :offset 16 :size 8) + ) :flag-assert #x900000008 ) -(defmethod inspect gs-fogcol ((obj gs-fogcol)) - (format #t "[~8x] ~A~%" obj 'gs-fogcol) - (format #t "~Tr: ~D~%" (shr (shl (the-as int obj) 56) 56)) - (format #t "~Tg: ~D~%" (shr (shl (the-as int obj) 48) 56)) - (format #t "~Tb: ~D~%" (shr (shl (the-as int obj) 40) 56)) - obj - ) - (deftype gif-ctrl (uint32) - () + ((rst uint8 :offset 0 :size 1) + (pse uint8 :offset 3 :size 1) + ) :flag-assert #x900000004 ) (deftype gif-mode (uint32) - () + ((m3r uint8 :offset 0 :size 1) + (imt uint8 :offset 2 :size 1) + ) :flag-assert #x900000004 ) (deftype gif-stat (uint32) - () + ((m3r uint8 :offset 0 :size 1) + (m3p uint8 :offset 1 :size 1) + (imt uint8 :offset 2 :size 1) + (pse uint8 :offset 3 :size 1) + (ip3 uint8 :offset 5 :size 1) + (p3q uint8 :offset 6 :size 1) + (p2q uint8 :offset 7 :size 1) + (p1q uint8 :offset 8 :size 1) + (oph uint8 :offset 9 :size 1) + (apath uint8 :offset 10 :size 2) + (dir uint8 :offset 12 :size 1) + (fqc uint8 :offset 24 :size 5) + ) :flag-assert #x900000004 ) (deftype gif-cnt (uint32) - () + ((loopcnt uint16 :offset 0 :size 15) + (regcnt uint8 :offset 16 :size 4) + (vuaddr uint16 :offset 20 :size 10) + ) :flag-assert #x900000004 ) (deftype gif-p3cnt (uint32) - () + ((p3cnt uint16 :offset 0 :size 15)) :flag-assert #x900000004 ) (deftype gif-p3tag (uint32) - () + ((loopcnt uint16 :offset 0 :size 15) + (eop uint8 :offset 15 :size 1) + ) :flag-assert #x900000004 ) @@ -313,7 +519,30 @@ :flag-assert #x900000008 ) (deftype gif-tag (uint128) - () + ((nloop uint16 :offset 0 :size 15) + (eop uint8 :offset 15 :size 1) + (id uint16 :offset 32 :size 14) + (pre uint8 :offset 46 :size 1) + (prim uint16 :offset 47 :size 11) + (flg uint8 :offset 58 :size 2) + (nreg uint8 :offset 60 :size 4) + (regs0 uint8 :offset 64 :size 4) + (regs1 uint8 :offset 68 :size 4) + (regs2 uint8 :offset 72 :size 4) + (regs3 uint8 :offset 76 :size 4) + (regs4 uint8 :offset 80 :size 4) + (regs5 uint8 :offset 84 :size 4) + (regs6 uint8 :offset 88 :size 4) + (regs7 uint8 :offset 92 :size 4) + (regs8 uint8 :offset 96 :size 4) + (regs9 uint8 :offset 100 :size 4) + (regs10 uint8 :offset 104 :size 4) + (regs11 uint8 :offset 108 :size 4) + (regs12 uint8 :offset 112 :size 4) + (regs13 uint8 :offset 116 :size 4) + (regs14 uint8 :offset 120 :size 4) + (regs15 uint8 :offset 124 :size 4) + ) :flag-assert #x900000010 ) @@ -331,7 +560,7 @@ ;; Note - there was an inspect method for the uint128-based gif-tag, but it is being left out. -;; no idea what format this is stored in. Looks like a nasty orange? +;; some nice blue. probably the same as the fog color for geyser/sandover/etc. (define *fog-color* #xc88029) ;; set up a DMA buffer. This will hold a message to set the GS state to normal. @@ -356,7 +585,7 @@ (set! (-> tag word 2) #x13000000) (set! (-> tag word 3) #x5000000a) (set! (-> buff base) (&+ (the-as pointer tag) 16)) - + ;; make another tag. (set! tag2 (the gs-gif-tag (-> buff base))) ;; no idea what this is about, it doesn't matter. @@ -365,7 +594,7 @@ (set! (-> tag2 dword 0) #x9000000000008001) (set! (-> tag2 dword 1) #xeeeeeeeeeeeeeeee) (set! (-> buff base) (&+ (the-as pointer tag2) 16)) - + ;; now some payload. (set! data (the (pointer uint64) (-> buff base))) (set! (-> data 0) 68) @@ -472,14 +701,14 @@ (deftype draw-context (basic) - ((orgx int32 :offset-assert 4) - (orgy int32 :offset-assert 8) - (orgz int32 :offset-assert 12) - (width int32 :offset-assert 16) - (height int32 :offset-assert 20) + ((orgx int32 :offset-assert 4) + (orgy int32 :offset-assert 8) + (orgz int32 :offset-assert 12) + (width int32 :offset-assert 16) + (height int32 :offset-assert 20) (color int32 4 :offset-assert 24) ) - (:methods + (:methods (new (symbol type int int int int int) _type_ 0) ) :method-count-assert 9 @@ -496,23 +725,24 @@ (color-0 int) ) "Allocate and initialize a draw-context" - (local-vars (v0-0 draw-context) (v1-3 int) (a0-2 int)) - (set! v0-0 - (object-new allocation type-to-make (the-as int (-> type-to-make size))) - ) - (set! v1-3 - (the int (* (the float org-y) (-> *video-parms* relative-y-scale))) - ) - (set! a0-2 - (the int (* (the float height) (-> *video-parms* relative-y-scale))) - ) - (set! (-> v0-0 orgx) org-x) - (set! (-> v0-0 orgy) v1-3) - (set! (-> v0-0 orgz) #xffffff) - (set! (-> v0-0 width) width) - (set! (-> v0-0 height) a0-2) - (set! (-> v0-0 color 0) color-0) - v0-0 + (let + ((obj + (object-new allocation type-to-make (the-as int (-> type-to-make size))) + ) + ) + (let + ((v1-3 (the int (* (the float org-y) (-> *video-parms* relative-y-scale)))) + (a0-2 (the int (* (the float height) (-> *video-parms* relative-y-scale)))) + ) + (set! (-> obj orgx) org-x) + (set! (-> obj orgy) v1-3) + (set! (-> obj orgz) #xffffff) + (set! (-> obj width) width) + (set! (-> obj height) a0-2) + ) + (set! (-> obj color 0) color-0) + obj + ) ) (defun draw-context-set-xy ((arg0 draw-context) (x int) (y int))