;;-*-Lisp-*-
(in-package goal)

;; name: hfrag-vu1.gc
;; name in dgo: hfrag-vu1
;; dgos: HGA, WIN, DST

;; DECOMP BEGINS

(define hfrag-vu1-block (new 'static 'vu-function :length #x7ec :qlength #x3f6))

;; ERROR: function was not converted to expressions. Cannot decompile.

;; ERROR: function was not converted to expressions. Cannot decompile.

;; ERROR: function was not converted to expressions. Cannot decompile.

;; ERROR: function was not converted to expressions. Cannot decompile.

;; ERROR: function was not converted to expressions. Cannot decompile.

;; ERROR: function was not converted to expressions. Cannot decompile.

;; ERROR: function was not converted to expressions. Cannot decompile.

;; ERROR: function was not converted to expressions. Cannot decompile.

;; WARN: Return type mismatch vector vs none.
(defun hfrag-setup-constants ((arg0 hfrag-vu1-constants))
  (let ((gp-0 *math-camera*))
    (let ((v1-0 *hfrag-vu1-constants-base*))
      (dotimes (a0-1 81)
        (vector-copy! (-> arg0 base far-verts a0-1) (-> v1-0 far-verts a0-1))
        )
      )
    (case *subdivide-draw-mode*
      (((subdivide-setting textured))
       (set! (-> arg0 drw-strip4 tag)
             (new 'static 'gif-tag64
               :nloop #x4
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip9-0 tag)
             (new 'static 'gif-tag64
               :nloop #x6
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip9-1 tag)
             (new 'static 'gif-tag64
               :nloop #x6
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip25-0 tag)
             (new 'static 'gif-tag64
               :nloop #xa
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip25-1 tag)
             (new 'static 'gif-tag64
               :nloop #xa
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       )
      (((subdivide-setting outline))
       (set! (-> arg0 drw-strip4 tag)
             (new 'static 'gif-tag64
               :nloop #x4
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type line-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip9-0 tag)
             (new 'static 'gif-tag64
               :nloop #x6
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type line-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip9-1 tag)
             (new 'static 'gif-tag64
               :nloop #x6
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type line-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip25-0 tag)
             (new 'static 'gif-tag64
               :nloop #xa
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type line-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip25-1 tag)
             (new 'static 'gif-tag64
               :nloop #xa
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type line-strip) :iip #x1 :tme #x1 :fge #x1)
               :nreg #x3
               )
             )
       )
      (((subdivide-setting gouraud))
       (set! (-> arg0 drw-strip4 tag)
             (new 'static 'gif-tag64
               :nloop #x4
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip9-0 tag)
             (new 'static 'gif-tag64
               :nloop #x6
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip9-1 tag)
             (new 'static 'gif-tag64
               :nloop #x6
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip25-0 tag)
             (new 'static 'gif-tag64
               :nloop #xa
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :fge #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip25-1 tag)
             (new 'static 'gif-tag64
               :nloop #xa
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :fge #x1)
               :nreg #x3
               )
             )
       )
      (((subdivide-setting hack))
       (set! (-> arg0 drw-strip4 tag)
             (new 'static 'gif-tag64
               :nloop #x4
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip9-0 tag)
             (new 'static 'gif-tag64
               :nloop #x6
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip9-1 tag)
             (new 'static 'gif-tag64
               :nloop #x6
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip25-0 tag)
             (new 'static 'gif-tag64
               :nloop #xa
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1)
               :nreg #x3
               )
             )
       (set! (-> arg0 drw-strip25-1 tag)
             (new 'static 'gif-tag64
               :nloop #xa
               :eop #x1
               :pre #x1
               :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1)
               :nreg #x3
               )
             )
       )
      )
    (set! (-> arg0 drw-strip4 regs)
          (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyzf2))
          )
    (set! (-> arg0 drw-strip9-0 regs)
          (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyzf2))
          )
    (set! (-> arg0 drw-strip9-1 regs)
          (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyzf2))
          )
    (set! (-> arg0 drw-strip25-0 regs)
          (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyzf2))
          )
    (set! (-> arg0 drw-strip25-1 regs)
          (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyzf2))
          )
    (mem-copy! (the-as pointer (-> arg0 matrix)) (the-as pointer (-> gp-0 camera-temp)) 64)
    (vector-copy! (-> arg0 hvdf-offset) (-> gp-0 hvdf-off))
    (vector-copy! (-> arg0 hmge-scale) (-> gp-0 hmge-scale))
    (set-vector! (-> arg0 fog) (-> gp-0 pfog0) (-> gp-0 fog-min) (-> gp-0 fog-max) 3072.0)
    )
  (none)
  )

;; WARN: Return type mismatch pointer vs none.
(defun hfrag-add-constants ((arg0 dma-buffer))
  (let* ((a1-0 94)
         (v1-0 arg0)
         (a0-1 (the-as dma-packet (-> v1-0 base)))
         )
    (set! (-> a0-1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc a1-0))
    (set! (-> a0-1 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)))
    (set! (-> a0-1 vif1) (new 'static 'vif-tag :imm #x189 :cmd (vif-cmd unpack-v4-32) :num a1-0))
    (set! (-> v1-0 base) (the-as pointer (&+ a0-1 16)))
    )
  (hfrag-setup-constants (the-as hfrag-vu1-constants (-> arg0 base)))
  (&+! (-> arg0 base) 1504)
  (none)
  )

(defun hfrag-vu1-end-buffer ((arg0 dma-buffer))
  (let* ((v1-0 arg0)
         (a1-0 (the-as dma-packet (-> v1-0 base)))
         )
    (set! (-> a1-0 dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt)))
    (set! (-> a1-0 vif0) (new 'static 'vif-tag :cmd (vif-cmd stmask)))
    (set! (-> a1-0 vif1) (new 'static 'vif-tag))
    (set! (-> v1-0 base) (the-as pointer (&+ a1-0 16)))
    )
  (let* ((v1-1 arg0)
         (a1-2 (the-as (pointer vif-tag) (-> v1-1 base)))
         )
    (set! (-> a1-2 0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1 :imm #x20))
    (set! (-> a1-2 1) (new 'static 'vif-tag :cmd (vif-cmd stmod)))
    (set! (-> a1-2 2) (new 'static 'vif-tag :cmd (vif-cmd flusha) :msk #x1))
    (set! (-> a1-2 3) (new 'static 'vif-tag :cmd (vif-cmd strow) :msk #x1))
    (set! (-> a1-2 4) (new 'static 'vif-tag))
    (set! (-> a1-2 5) (new 'static 'vif-tag))
    (set! (-> a1-2 6) (new 'static 'vif-tag))
    (set! (-> a1-2 7) (new 'static 'vif-tag))
    (set! (-> v1-1 base) (&-> a1-2 8))
    )
  (dma-buffer-add-gs-set arg0 (test-1 (new 'static 'gs-test :zte #x1 :ztst (gs-ztest greater-equal))))
  0
  (none)
  )

(defun hfrag-vu1-init-buf ()
  (let ((v1-0 *display*)
        (a0-5 (+ (* (+ (/ (-> hfrag-vu1-block qlength) 127) 1) 16) 1568))
        )
    (+! (-> v1-0 mem-reserve-size) a0-5)
    (when (not (-> v1-0 dma-buffer-overflow))
      (let ((a2-0 (-> v1-0 frames (-> v1-0 on-screen) global-buf)))
        (if (< (-> a2-0 real-buffer-end) (the-as int (&+ (-> a2-0 base) a0-5)))
            (set! (-> v1-0 dma-buffer-overflow) #t)
            )
        )
      (when (not (-> v1-0 dma-buffer-overflow))
        (let ((gp-0 (-> *display* frames (-> *display* on-screen) bucket-group 8)))
          (when (!= gp-0 (-> gp-0 last))
            (let* ((s4-0 (-> *display* frames (-> *display* on-screen) global-buf))
                   (s5-3 (-> s4-0 base))
                   )
              (dma-buffer-add-vu-function s4-0 hfrag-vu1-block 1)
              (hfrag-add-constants s4-0)
              (let* ((v1-14 s4-0)
                     (a0-13 (the-as dma-packet (-> v1-14 base)))
                     )
                (set! (-> a0-13 dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt)))
                (set! (-> a0-13 vif0) (new 'static 'vif-tag))
                (set! (-> a0-13 vif1) (new 'static 'vif-tag :cmd (vif-cmd strow) :msk #x1))
                (set! (-> v1-14 base) (the-as pointer (&+ a0-13 16)))
                )
              (let* ((v1-15 s4-0)
                     (a0-15 (-> v1-15 base))
                     )
                (set! (-> (the-as (pointer uint32) a0-15) 0) (the-as uint 0))
                (set! (-> (the-as (pointer uint32) a0-15) 1) (the-as uint 0))
                (set! (-> (the-as (pointer uint32) a0-15) 2) (the-as uint 0))
                (set! (-> (the-as (pointer uint32) a0-15) 3) (the-as uint 0))
                (set! (-> (the-as (pointer vif-tag) a0-15) 4) (new 'static 'vif-tag :cmd (vif-cmd base)))
                (set! (-> (the-as (pointer vif-tag) a0-15) 5) (new 'static 'vif-tag :cmd (vif-cmd offset)))
                (set! (-> (the-as (pointer vif-tag) a0-15) 6) (new 'static 'vif-tag :cmd (vif-cmd stmod)))
                (set! (-> (the-as (pointer vif-tag) a0-15) 7) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1 :imm #x22))
                (set! (-> v1-15 base) (&+ a0-15 32))
                )
              (let ((v1-16 (the-as dma-packet (-> s4-0 base))))
                (set! (-> v1-16 dma) (new 'static 'dma-tag :id (dma-tag-id next) :addr (-> gp-0 next)))
                (set! (-> v1-16 vif0) (new 'static 'vif-tag))
                (set! (-> v1-16 vif1) (new 'static 'vif-tag))
                (set! (-> s4-0 base) (the-as pointer (&+ v1-16 16)))
                )
              (set! (-> gp-0 next) (the-as uint s5-3))
              )
            )
          )
        )
      )
    )
  (let ((v1-18 *display*)
        (a0-19 96)
        )
    (+! (-> v1-18 mem-reserve-size) a0-19)
    (when (not (-> v1-18 dma-buffer-overflow))
      (let ((a2-6 (-> v1-18 frames (-> v1-18 on-screen) global-buf)))
        (if (< (-> a2-6 real-buffer-end) (the-as int (&+ (-> a2-6 base) a0-19)))
            (set! (-> v1-18 dma-buffer-overflow) #t)
            )
        )
      (when (not (-> v1-18 dma-buffer-overflow))
        (let ((gp-1 (-> *display* frames (-> *display* on-screen) bucket-group 8)))
          (when (!= gp-1 (-> gp-1 last))
            (let* ((s4-1 (-> *display* frames (-> *display* on-screen) global-buf))
                   (s5-4 (-> s4-1 base))
                   )
              (hfrag-vu1-end-buffer s4-1)
              (let ((a1-31 (-> s4-1 base)))
                (let ((v1-32 (the-as dma-packet (-> s4-1 base))))
                  (set! (-> v1-32 dma) (new 'static 'dma-tag :id (dma-tag-id next)))
                  (set! (-> v1-32 vif0) (new 'static 'vif-tag))
                  (set! (-> v1-32 vif1) (new 'static 'vif-tag))
                  (set! (-> s4-1 base) (the-as pointer (&+ v1-32 16)))
                  )
                (set! (-> (the-as (pointer uint32) (-> gp-1 last)) 1) (the-as uint s5-4))
                (set! (-> gp-1 last) (the-as (pointer dma-tag) a1-31))
                )
              )
            )
          )
        )
      )
    )
  0
  (none)
  )
