jak-project/goal_src/engine/gfx/hw/display-h.gc
ManDude 7cb04c6cd5
[decomp] font-h, fix a vector type, minor decompiler fixes (#411)
* Make `:do-not-decompile` work on field lookup as well

* decompile `font-h` and update a vector type + minor fixes

* fix some types

* fix font-h

* fix font-h (again)

* update a script

* fixes

* Fix segfault

* Fix `PROT_NONE` page protection on windows
2021-05-01 21:09:48 -04:00

284 lines
10 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: display-h.gc
;; name in dgo: display-h
;; dgos: GAME, ENGINE
;; display-env stores the GS settings for displaying a framebuffer on screen.
;; this is identical to the Sony sceGsDispEnv struct.
;; you can set one of these up with set-display-env, then use it with
;; put-display-env, which is implemented in the kernel and is a wrapper
;; around a Sony function.
(deftype display-env (structure)
((pmode gs-pmode :offset-assert 0)
(smode2 gs-smode2 :offset-assert 8)
(dspfb gs-display-fb :offset-assert 16)
(display gs-display :offset-assert 24)
(bgcolor gs-bgcolor :offset-assert 32)
)
:pack-me
:method-count-assert 9
:size-assert #x28
:flag-assert #x900000028
)
(defenum gs-reg
:type uint8
(prim 0)
(rgbaq 1)
(st 2)
(uv 3)
(xyzf2 4)
(xyz2 5)
(tex0-1 6)
(tex0-2 7)
(clamp-1 8)
(clamp-2 9)
(fog 10)
(xyzf3 12)
(xyz3 13)
(tex1-1 20)
(tex1-2 21)
(tex2-1 22)
(tex2-2 23)
(xyoffset-1 24)
(xyoffset-2 25)
(prmodecont 26)
(prmode 27)
(texclut 28)
(scanmsk 34)
(miptbp1-1 52)
(miptbp1-2 53)
(miptbp2-1 54)
(miptbp2-2 55)
(texa 59)
(fogcol 61)
(texflush 63)
(scissor-1 64)
(scissor-2 65)
(alpha-1 66)
(alpha-2 67)
(dimx 68)
(dthe 69)
(colclamp 70)
(test-1 71)
(test-2 72)
(pabe 73)
(fba-1 74)
(fba-2 75)
(frame-1 76)
(frame-2 77)
(zbuf-1 78)
(zbuf-2 79)
(bitbltbuf 80)
(trxpos 81)
(trxreg 82)
(trxdir 83)
(hwreg 84)
(signal 96)
(finish 97)
(label 98)
)
(defenum gs-reg64
:type uint64
:copy-entries gs-reg
)
;; draw-env stores the GS settings for drawing to somewhere in VRAM.
;; the "addr" fields represent GS register addresses
;; this is identical to the Sony sceGsDrawEnv1/2 structs
;; Internally, this is register + address GIF data.
(deftype draw-env (structure)
((frame1 gs-frame :offset-assert 0)
(frame1addr gs-reg64 :offset-assert 8)
(zbuf1 gs-zbuf :offset-assert 16)
(zbuf1addr gs-reg64 :offset-assert 24)
(xyoffset1 gs-xy-offset :offset-assert 32)
(xyoffset1addr gs-reg64 :offset-assert 40)
(scissor1 gs-scissor :offset-assert 48)
(scissor1addr gs-reg64 :offset-assert 56)
(prmodecont gs-prmode-cont :offset-assert 64)
(prmodecontaddr gs-reg64 :offset-assert 72)
(colclamp gs-color-clamp :offset-assert 80)
(colclampaddr gs-reg64 :offset-assert 88)
(dthe gs-dthe :offset-assert 96)
(dtheaddr gs-reg64 :offset-assert 104)
(test1 gs-test :offset-assert 112)
(test1addr gs-reg64 :offset-assert 120)
)
:method-count-assert 9
:size-assert #x80
:flag-assert #x900000080
)
(defun put-draw-env ((packet (pointer gif-tag)))
"Begin DMA transfer to the GIF/GS to send a draw env packet.
The length of the transfer is taken from the nloop field of the tag."
;; this is a workaround for OpenGOAL not supporting 128-bitfield access yet.
(let ((packet64 (the-as (pointer gif-tag64) packet)))
(dma-send GIF_DMA_BANK
(the-as uint packet)
(the-as uint (+ (the-as uint (-> packet64 0 nloop)) (the-as uint 1)))
)
)
(none)
)
(deftype display-frame (basic)
((calc-buf dma-buffer :offset 8)
(vu1-buf dma-buffer :offset 8)
(debug-buf dma-buffer :offset 36)
(global-buf dma-buffer :offset 40)
(buffer uint32 11 :offset 4) ;; for debugging?
(bucket-group dma-bucket :offset 44)
(profile-bar profile-bar 2 :offset 48)
(run-time uint64 :offset 56)
)
(:methods
(new (symbol type) _type_ 0)
)
:method-count-assert 9
:size-assert #x40
:flag-assert #x900000040
)
(defmethod new display-frame ((allocation symbol) (type-to-make type))
"Allocate a new display frame"
(let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> obj calc-buf) (the-as dma-buffer 0))
(set! (-> obj global-buf) (the-as dma-buffer 0))
(set! (-> obj debug-buf) (the-as dma-buffer 0))
;; allocate profile-bars in the debug heap, if we're debugging.
(when *debug-segment*
(set! (-> obj profile-bar 0) (new 'debug 'profile-bar))
(set! (-> obj profile-bar 1) (new 'debug 'profile-bar))
)
obj
)
)
(deftype virtual-frame (structure)
((display display-env :offset-assert 0)
(display-last display-env :offset-assert 4)
(gif pointer :offset-assert 8)
(draw draw-env :offset-assert 12)
(frame display-frame :offset-assert 16)
)
:allow-misaligned
:method-count-assert 9
:size-assert #x14
:flag-assert #x900000014
)
(deftype display (basic)
((display-env0 display-env :inline :offset-assert 8)
(display-env1 display-env :inline :offset-assert 48)
(display-env2 display-env :inline :offset-assert 88)
;; the gif-tag + draw is a gif-packet to setting the draw-env.
;; the draw-env is actually just a+d data.
(gif-tag0 gs-gif-tag :inline :offset-assert 128)
(draw0 draw-env :inline :offset-assert 144)
(gif-tag1 gs-gif-tag :inline :offset-assert 272)
(draw1 draw-env :inline :offset-assert 288)
(gif-tag2 gs-gif-tag :inline :offset-assert 416)
(draw2 draw-env :inline :offset-assert 432)
(on-screen int32 :offset-assert 560)
(last-screen int32 :offset-assert 564)
(frames virtual-frame 6 :inline :offset-assert 568)
(bg-clear-color rgba 4 :offset-assert 760)
(real-frame-counter uint64 :offset-assert 776)
(base-frame-counter uint64 :offset-assert 784)
(game-frame-counter uint64 :offset-assert 792)
(integral-frame-counter uint64 :offset-assert 800)
(real-integral-frame-counter uint64 :offset-assert 808)
(actual-frame-counter uint64 :offset-assert 816)
(real-actual-frame-counter uint64 :offset-assert 824)
(part-frame-counter uint64 :offset-assert 832)
(old-real-frame-counter uint64 :offset-assert 840)
(old-base-frame-counter uint64 :offset-assert 848)
(old-game-frame-counter uint64 :offset-assert 856)
(old-integral-frame-counter uint64 :offset-assert 864)
(old-real-integral-frame-counter uint64 :offset-assert 872)
(old-actual-frame-counter uint64 :offset-assert 880)
(old-real-actual-frame-counter uint64 :offset-assert 888)
(old-part-frame-counter uint64 :offset-assert 896)
(time-ratio float :offset-assert 904)
(seconds-per-frame float :offset-assert 908)
(frames-per-second float :offset-assert 912)
(time-factor float :offset-assert 916)
(time-adjust-ratio float :offset-assert 920)
)
:method-count-assert 10
:size-assert #x39c
:flag-assert #xa0000039c
(:methods
(new (symbol type int int int int int) _type_ 0)
(set-time-ratios (_type_ float) float 9)
)
)
(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))
(let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
;; set the display size, texture format, zbuffer format, etc.
(set-display obj psm w h ztest zpsm)
;; set up frames.
(set! (-> obj frames 0 display) (-> obj display-env0))
(set! (-> obj frames 1 display) (-> obj display-env1))
(set! (-> obj frames 2 display) (-> obj display-env2))
(set! (-> obj frames 3 display) (-> obj display-env0))
(set! (-> obj frames 4 display) (-> obj display-env1))
(set! (-> obj frames 5 display) (-> obj display-env2))
(set! (-> obj frames 0 display-last) (-> obj display-env2))
(set! (-> obj frames 1 display-last) (-> obj display-env0))
(set! (-> obj frames 2 display-last) (-> obj display-env1))
(set! (-> obj frames 3 display-last) (-> obj display-env2))
(set! (-> obj frames 4 display-last) (-> obj display-env0))
(set! (-> obj frames 5 display-last) (-> obj display-env1))
(set! (-> obj frames 0 gif) (&-> obj gif-tag0 qword))
(set! (-> obj frames 1 gif) (&-> obj gif-tag1 qword))
(set! (-> obj frames 2 gif) (&-> obj gif-tag2 qword))
(set! (-> obj frames 3 gif) (&-> obj gif-tag0 qword))
(set! (-> obj frames 4 gif) (&-> obj gif-tag1 qword))
(set! (-> obj frames 5 gif) (&-> obj gif-tag2 qword))
(set! (-> obj frames 0 draw) (-> obj draw0))
(set! (-> obj frames 1 draw) (-> obj draw1))
(set! (-> obj frames 2 draw) (-> obj draw2))
(set! (-> obj frames 3 draw) (-> obj draw0))
(set! (-> obj frames 4 draw) (-> obj draw1))
(set! (-> obj frames 5 draw) (-> obj draw2))
(set! (-> obj frames 0 frame) (new 'global 'display-frame))
(set! (-> obj frames 1 frame) (new 'global 'display-frame))
(set! (-> obj frames 2 frame) (-> obj frames 0 frame))
(set! (-> obj frames 3 frame) (-> obj frames 1 frame))
(set! (-> obj frames 4 frame) (-> obj frames 0 frame))
(set! (-> obj frames 5 frame) (-> obj frames 1 frame))
;; do this again. just in case.
(default-buffer-init *default-regs-buffer*)
;; set the default gray color.
(set! (-> obj bg-clear-color 0)
(new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
)
(set! (-> obj bg-clear-color 1)
(new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
)
(set! (-> obj bg-clear-color 2)
(new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
)
(set! (-> obj bg-clear-color 3)
(new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
)
obj
)
)
(define *pre-draw-hook* nothing)
(define *post-draw-hook* nothing)