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

;; definition of type sprite-header
(deftype sprite-header (structure)
  ((header      qword 1 :inline :offset-assert   0)
   (num-sprites int32           :offset          0)
   )
  :method-count-assert 9
  :size-assert         #x10
  :flag-assert         #x900000010
  )

;; definition for method 3 of type sprite-header
(defmethod inspect sprite-header ((obj sprite-header))
  (format #t "[~8x] ~A~%" obj 'sprite-header)
  (format #t "~Theader[1] @ #x~X~%" (-> obj header))
  (format #t "~Tnum-sprites: ~D~%" (-> obj num-sprites))
  obj
  )

;; definition for function sprite-setup-header
;; INFO: Return type mismatch int vs none.
(defun sprite-setup-header ((hdr sprite-header) (num-sprites int))
  (set! (-> hdr num-sprites) num-sprites)
  (none)
  )

;; definition of type sprite-hvdf-data
(deftype sprite-hvdf-data (structure)
  ((data qword 76 :inline :offset-assert   0)
   )
  :method-count-assert 9
  :size-assert         #x4c0
  :flag-assert         #x9000004c0
  )

;; definition for method 3 of type sprite-hvdf-data
(defmethod inspect sprite-hvdf-data ((obj sprite-hvdf-data))
  (format #t "[~8x] ~A~%" obj 'sprite-hvdf-data)
  (format #t "~Tdata[76] @ #x~X~%" (-> obj data))
  obj
  )

;; definition of type sprite-hvdf-control
(deftype sprite-hvdf-control (structure)
  ((alloc int8 76 :offset-assert   0)
   )
  :method-count-assert 9
  :size-assert         #x4c
  :flag-assert         #x90000004c
  )

;; definition for method 3 of type sprite-hvdf-control
(defmethod inspect sprite-hvdf-control ((obj sprite-hvdf-control))
  (format #t "[~8x] ~A~%" obj 'sprite-hvdf-control)
  (format #t "~Talloc[76] @ #x~X~%" (-> obj alloc))
  obj
  )

;; definition for symbol *sprite-hvdf-data*, type sprite-hvdf-data
(define *sprite-hvdf-data* (new 'global 'sprite-hvdf-data))

;; definition for symbol *sprite-hvdf-control*, type sprite-hvdf-control
(define *sprite-hvdf-control* (new 'global 'sprite-hvdf-control))

;; failed to figure out what this is:
(dotimes (v1-6 76)
  (set! (-> *sprite-hvdf-control* alloc v1-6) 0)
  )

;; failed to figure out what this is:
(set! (-> *sprite-hvdf-control* alloc 0) 1)

;; definition of type sprite-aux-list
(deftype sprite-aux-list (basic)
  ((num-entries int32                :offset-assert   4)
   (entry       int32                :offset-assert   8)
   (data        sprite-vec-data-2d 1 :offset-assert  12)
   )
  :method-count-assert 9
  :size-assert         #x10
  :flag-assert         #x900000010
  (:methods
    (new (symbol type int) _type_ 0)
    )
  )

;; definition for method 3 of type sprite-aux-list
;; INFO: this function exists in multiple non-identical object files
(defmethod inspect sprite-aux-list ((obj sprite-aux-list))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tnum-entries: ~D~%" (-> obj num-entries))
  (format #t "~Tentry: ~D~%" (-> obj entry))
  (format #t "~Tdata[1] @ #x~X~%" (-> obj data))
  obj
  )

;; definition for method 0 of type sprite-aux-list
(defmethod new sprite-aux-list ((allocation symbol) (type-to-make type) (size int))
  (let ((v0-0 (object-new allocation type-to-make (the-as int (+ (-> type-to-make size) (* (+ size -1) 4))))))
    (set! (-> v0-0 num-entries) size)
    (set! (-> v0-0 entry) 0)
    v0-0
    )
  )

;; definition for method 3 of type sprite-aux-list
;; INFO: this function exists in multiple non-identical object files
;; INFO: Return type mismatch symbol vs sprite-aux-list.
(defmethod inspect sprite-aux-list ((obj sprite-aux-list))
  (format #t "[~X] sprite-aux-list:~%" obj)
  (format #t "~Tnum-entries: ~D~%" (-> obj num-entries))
  (format #t "~Tentry: ~D~%" (-> obj entry))
  (dotimes (s5-0 (-> obj entry))
    (format #t "~T~D : ~X~%" s5-0 (-> obj data s5-0))
    )
  (the-as sprite-aux-list #f)
  )

;; definition for symbol *sprite-aux-list*, type sprite-aux-list
(define *sprite-aux-list* (new 'global 'sprite-aux-list 256))

;; definition for function clear-sprite-aux-list
;; INFO: Return type mismatch int vs none.
(defun clear-sprite-aux-list ()
  (set! (-> *sprite-aux-list* entry) 0)
  0
  (none)
  )

;; definition for function add-to-sprite-aux-list
;; INFO: Return type mismatch int vs none.
(defun add-to-sprite-aux-list ((arg0 sparticle-system) (arg1 sparticle-cpuinfo) (arg2 sprite-vec-data-3d))
  (let ((v1-0 *sprite-aux-list*))
    (when (< (-> v1-0 entry) (-> v1-0 num-entries))
      (set! (-> v1-0 data (-> v1-0 entry)) (-> arg1 sprite))
      (+! (-> v1-0 entry) 1)
      )
    )
  (set! (-> arg2 r-g-b-a w) 0.0)
  0
  (none)
  )

;; definition of type sprite-frame-data
(deftype sprite-frame-data (structure)
  ((cdata              vector       16 :inline :offset-assert   0)
   (hmge-scale         vector       :inline    :offset        256)
   (consts             vector       :inline    :offset-assert 272)
   (pfog0              float                   :offset        272)
   (deg-to-rad         float                   :offset        276)
   (min-scale          float                   :offset        280)
   (inv-area           float                   :offset        284)
   (adgif-giftag       gs-gif-tag   :inline    :offset-assert 288)
   (sprite-2d-giftag   gs-gif-tag   :inline    :offset-assert 304)
   (sprite-2d-giftag-2 gs-gif-tag   :inline    :offset-assert 320)
   (sincos-01          vector       :inline    :offset-assert 336)
   (sincos-23          vector       :inline    :offset-assert 352)
   (sincos-45          vector       :inline    :offset-assert 368)
   (sincos-67          vector       :inline    :offset-assert 384)
   (sincos-89          vector       :inline    :offset-assert 400)
   (basis-x            vector       :inline    :offset-assert 416)
   (basis-y            vector       :inline    :offset-assert 432)
   (sprite-3d-giftag   gs-gif-tag   :inline    :offset-assert 448)
   (screen-shader      adgif-shader :inline    :offset-assert 464)
   (clipped-giftag     gs-gif-tag   :inline    :offset-assert 544)
   (inv-hmge-scale     vector       :inline    :offset-assert 560)
   (stq-offset         vector       :inline    :offset-assert 576)
   (stq-scale          vector       :inline    :offset-assert 592)
   (rgba-plain         qword        :inline    :offset-assert 608)
   (warp-giftag        gs-gif-tag   :inline    :offset-assert 624)
   (fog-clamp          vector       :inline    :offset-assert 640)
   (fog-min            float                   :offset        640)
   (fog-max            float                   :offset        644)
   (max-scale          float                   :offset        648)
   )
  :method-count-assert 9
  :size-assert         #x290
  :flag-assert         #x900000290
  )

;; definition for method 3 of type sprite-frame-data
(defmethod inspect sprite-frame-data ((obj sprite-frame-data))
  (format #t "[~8x] ~A~%" obj 'sprite-frame-data)
  (format #t "~Tdata[41] @ #x~X~%" (-> obj cdata))
  (format #t "~Tcdata[16] @ #x~X~%" (-> obj cdata))
  (format #t "~Tfdata[25] @ #x~X~%" (-> obj hmge-scale))
  (format #t "~Txy-array[8] @ #x~X~%" (-> obj cdata))
  (format #t "~Tst-array[4] @ #x~X~%" (-> obj cdata 8))
  (format #t "~Txyz-array[4] @ #x~X~%" (-> obj cdata 12))
  (format #t "~Thmge-scale: #<vector @ #x~X>~%" (-> obj hmge-scale))
  (format #t "~Tconsts: #<vector @ #x~X>~%" (&-> obj pfog0))
  (format #t "~Tpfog0: ~f~%" (-> obj pfog0))
  (format #t "~Tdeg-to-rad: ~f~%" (-> obj deg-to-rad))
  (format #t "~Tmin-scale: ~f~%" (-> obj min-scale))
  (format #t "~Tinv-area: ~f~%" (-> obj inv-area))
  (format #t "~Tadgif-giftag: #<qword @ #x~X>~%" (-> obj adgif-giftag))
  (format #t "~Tsprite-2d-giftag: #<qword @ #x~X>~%" (-> obj sprite-2d-giftag))
  (format #t "~Tsprite-2d-giftag-2: #<qword @ #x~X>~%" (-> obj sprite-2d-giftag-2))
  (format #t "~Tsincos-01: #<vector @ #x~X>~%" (-> obj sincos-01))
  (format #t "~Tsincos-23: #<vector @ #x~X>~%" (-> obj sincos-23))
  (format #t "~Tsincos-45: #<vector @ #x~X>~%" (-> obj sincos-45))
  (format #t "~Tsincos-67: #<vector @ #x~X>~%" (-> obj sincos-67))
  (format #t "~Tsincos-89: #<vector @ #x~X>~%" (-> obj sincos-89))
  (format #t "~Tbasis-x: #<vector @ #x~X>~%" (-> obj basis-x))
  (format #t "~Tbasis-y: #<vector @ #x~X>~%" (-> obj basis-y))
  (format #t "~Tsprite-3d-giftag: #<qword @ #x~X>~%" (-> obj sprite-3d-giftag))
  (format #t "~Tscreen-shader: #<adgif-shader @ #x~X>~%" (-> obj screen-shader))
  (format #t "~Tclipped-giftag: #<qword @ #x~X>~%" (-> obj clipped-giftag))
  (format #t "~Tinv-hmge-scale: #<vector @ #x~X>~%" (-> obj inv-hmge-scale))
  (format #t "~Tstq-offset: #<vector @ #x~X>~%" (-> obj stq-offset))
  (format #t "~Tstq-scale: #<vector @ #x~X>~%" (-> obj stq-scale))
  (format #t "~Trgba-plain: #<qword @ #x~X>~%" (-> obj rgba-plain))
  (format #t "~Twarp-giftag: #<qword @ #x~X>~%" (-> obj warp-giftag))
  (format #t "~Tfog-clamp: #<vector @ #x~X>~%" (-> obj fog-clamp))
  (format #t "~Tfog-min: ~f~%" (-> obj fog-clamp x))
  (format #t "~Tfog-max: ~f~%" (-> obj fog-clamp y))
  (format #t "~Tmax-scale: ~f~%" (-> obj fog-clamp z))
  obj
  )

;; definition for function sprite-setup-frame-data
;; INFO: Used lq/sq
;; INFO: Return type mismatch float vs none.
(defun sprite-setup-frame-data ((data sprite-frame-data) (tbp-offset int))
  (set! (-> data hmge-scale quad) (-> *math-camera* hmge-scale quad))
  (set! (-> data inv-hmge-scale quad) (-> *math-camera* inv-hmge-scale quad))
  (set! (-> data pfog0) (-> *math-camera* pfog0))
  (set! (-> data deg-to-rad) 0.000095873795)
  (set! (-> data adgif-giftag tag) (new 'static 'gif-tag64 :nloop #x1 :nreg #x5))
  (set! (-> data adgif-giftag regs)
        (new 'static 'gif-tag-regs
          :regs0 (gif-reg-id a+d)
          :regs1 (gif-reg-id a+d)
          :regs2 (gif-reg-id a+d)
          :regs3 (gif-reg-id a+d)
          :regs4 (gif-reg-id a+d)
          )
        )
  (set! (-> data sprite-2d-giftag tag)
        (new 'static 'gif-tag64
          :nloop #x1
          :eop #x1
          :pre #x1
          :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1)
          :nreg #x9
          )
        )
  (set! (-> data sprite-2d-giftag regs)
        (new 'static 'gif-tag-regs
          :regs0 (gif-reg-id rgbaq)
          :regs1 (gif-reg-id st)
          :regs2 (gif-reg-id xyzf2)
          :regs3 (gif-reg-id st)
          :regs4 (gif-reg-id xyzf2)
          :regs5 (gif-reg-id st)
          :regs6 (gif-reg-id xyzf2)
          :regs7 (gif-reg-id st)
          :regs8 (gif-reg-id xyzf2)
          )
        )
  (set! (-> data sprite-2d-giftag-2 tag)
        (new 'static 'gif-tag64
          :nloop #x1
          :eop #x1
          :pre #x1
          :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :abe #x1)
          :nreg #x9
          )
        )
  (set! (-> data sprite-2d-giftag-2 regs)
        (new 'static 'gif-tag-regs
          :regs0 (gif-reg-id rgbaq)
          :regs1 (gif-reg-id st)
          :regs2 (gif-reg-id xyzf2)
          :regs3 (gif-reg-id st)
          :regs4 (gif-reg-id xyzf2)
          :regs5 (gif-reg-id st)
          :regs6 (gif-reg-id xyzf2)
          :regs7 (gif-reg-id st)
          :regs8 (gif-reg-id xyzf2)
          )
        )
  (set! (-> data sprite-3d-giftag tag)
        (new 'static 'gif-tag64
          :nloop #x1
          :eop #x1
          :pre #x1
          :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1)
          :nreg #xc
          )
        )
  (set! (-> data sprite-3d-giftag regs)
        (new 'static 'gif-tag-regs
          :regs0 (gif-reg-id st)
          :regs1 (gif-reg-id rgbaq)
          :regs2 (gif-reg-id xyzf2)
          :regs3 (gif-reg-id st)
          :regs4 (gif-reg-id rgbaq)
          :regs5 (gif-reg-id xyzf2)
          :regs6 (gif-reg-id st)
          :regs7 (gif-reg-id rgbaq)
          :regs8 (gif-reg-id xyzf2)
          :regs9 (gif-reg-id st)
          :regs10 (gif-reg-id rgbaq)
          :regs11 (gif-reg-id xyzf2)
          )
        )
  (set! (-> data clipped-giftag tag)
        (new 'static 'gif-tag64
          :nloop #x1
          :eop #x1
          :pre #x1
          :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1)
          :nreg #x3
          )
        )
  (set! (-> data clipped-giftag regs)
        (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyzf2))
        )
  (set! (-> data warp-giftag tag) (new 'static 'gif-tag64
                                    :nloop #x1
                                    :eop #x1
                                    :pre #x1
                                    :prim (new 'static 'gs-prim :prim (gs-prim-type tri) :tme #x1 :abe #x1)
                                    :nreg #xc
                                    )
        )
  (set! (-> data warp-giftag regs) (new 'static 'gif-tag-regs
                                     :regs0 (gif-reg-id st)
                                     :regs1 (gif-reg-id rgbaq)
                                     :regs2 (gif-reg-id xyzf2)
                                     :regs3 (gif-reg-id st)
                                     :regs4 (gif-reg-id rgbaq)
                                     :regs5 (gif-reg-id xyzf2)
                                     :regs6 (gif-reg-id st)
                                     :regs7 (gif-reg-id rgbaq)
                                     :regs8 (gif-reg-id xyzf2)
                                     )
        )
  (set! (-> data screen-shader prims 1) (gs-reg64 tex0-1))
  (set! (-> data screen-shader tex0) (new 'static 'gs-tex0 :tbw #x8 :tw #xa :th #x8 :tbp0 (* tbp-offset 32)))
  (set! (-> data screen-shader prims 3) (gs-reg64 tex1-1))
  (set! (-> data screen-shader tex1) (new 'static 'gs-tex1 :mmag #x1 :mmin #x1))
  (set! (-> data screen-shader prims 5) (gs-reg64 miptbp1-1))
  (set! (-> data screen-shader miptbp1) (new 'static 'gs-miptbp))
  (set! (-> data screen-shader clamp-reg) (gs-reg64 clamp-1))
  (set! (-> data screen-shader clamp) (new 'static 'gs-clamp
                                        :wms (gs-tex-wrap-mode region-clamp)
                                        :wmt (gs-tex-wrap-mode region-clamp)
                                        :maxu #x27f
                                        :maxv #xef
                                        )
        )
  (set! (-> data screen-shader prims 9) (gs-reg64 alpha-1))
  (set! (-> data screen-shader alpha) (new 'static 'gs-alpha :b #x1 :d #x1))
  (set! (-> data sincos-01 z) 0.999998)
  (set! (-> data sincos-23 z) -0.16666014)
  (set! (-> data sincos-45 z) 0.008326521)
  (set! (-> data sincos-67 z) -0.0001956241)
  (set! (-> data sincos-89 z) 0.0000023042373)
  (set! (-> data sincos-01 w) 1.0)
  (set! (-> data sincos-23 w) -0.49998003)
  (set! (-> data sincos-45 w) 0.041620404)
  (set! (-> data sincos-67 w) -0.0013636408)
  (set! (-> data sincos-89 w) 0.000020170546)
  (set! (-> data basis-x quad) (the-as uint128 0))
  (set! (-> data basis-x x) (- (-> *math-camera* perspective vector 0 x)))
  (set! (-> data basis-y quad) (the-as uint128 0))
  (set! (-> data basis-y y) (- (-> *math-camera* perspective vector 1 y)))
  (set! (-> data min-scale) (sqrtf (* (/ 1.0 (-> data basis-x x)) (/ 1.0 (-> data basis-y y)))))
  (set! (-> data inv-area) (/ 1.0 (* (-> data min-scale) (-> data min-scale))))
  (set-vector! (-> data cdata 0) -0.5 -0.5 0.0 0.0)
  (set-vector! (-> data cdata 1) 0.5 -0.5 0.0 0.0)
  (set-vector! (-> data cdata 2) 0.5 0.5 0.0 0.0)
  (set-vector! (-> data cdata 3) -0.5 0.5 0.0 0.0)
  (set-vector! (-> data cdata 4) 0.0 -0.5 0.0 0.0)
  (set-vector! (-> data cdata 5) 1.0 -0.5 0.0 0.0)
  (set-vector! (-> data cdata 6) 1.0 0.5 0.0 0.0)
  (set-vector! (-> data cdata 7) 0.0 0.5 0.0 0.0)
  (set-vector! (-> data cdata 8) 0.0 0.0 1.0 0.0)
  (set-vector! (-> data cdata 9) 1.0 0.0 1.0 0.0)
  (set-vector! (-> data cdata 10) 1.0 1.0 1.0 0.0)
  (set-vector! (-> data cdata 11) 0.0 1.0 1.0 0.0)
  (set-vector! (-> data cdata 12) -0.5 0.0 -0.5 0.0)
  (set-vector! (-> data cdata 13) 0.5 0.0 -0.5 0.0)
  (set-vector! (-> data cdata 14) 0.5 0.0 0.5 0.0)
  (set-vector! (-> data cdata 15) -0.5 0.0 0.5 0.0)
  (set-vector! (-> data stq-offset) -1792.0 (+ -2048.0 (the float (-> *video-parms* screen-hy))) 0.0 0.0)
  (set-vector! (-> data stq-scale) 0.0009765625 0.00390625 1.0 1.0)
  (set! (-> data rgba-plain vector4w x) 128)
  (set! (-> data rgba-plain vector4w y) 128)
  (set! (-> data rgba-plain vector4w z) 128)
  (set! (-> data rgba-plain vector4w w) 64)
  (set! (-> data fog-clamp x) (-> *math-camera* fog-min))
  (set! (-> data fog-clamp y) (-> *math-camera* fog-max))
  (set! (-> data fog-clamp z) 2048.0)
  (none)
  )

;; definition for symbol sprite-vu1-block, type vu-function
(define sprite-vu1-block (new 'static 'vu-function :length #x356 :qlength #x1ab))

;; definition for method 0 of type sprite-array-2d
(defmethod new sprite-array-2d ((allocation symbol) (type-to-make type) (group-0-size int) (group-1-size int))
  (let* ((sprite-count (+ group-0-size group-1-size))
         (vec-data-size (* 3 sprite-count))
         (adgif-data-size (* 5 sprite-count))
         (v0-0 (object-new
                 allocation
                 type-to-make
                 (the-as int (+ (-> type-to-make size) (* (+ adgif-data-size -1 vec-data-size) 16)))
                 )
               )
         )
    (set! (-> v0-0 num-sprites 0) group-0-size)
    (set! (-> v0-0 num-sprites 1) group-1-size)
    (set! (-> v0-0 num-valid 0) 0)
    (set! (-> v0-0 num-valid 1) 0)
    (set! (-> v0-0 vec-data) (-> v0-0 data))
    (set! (-> v0-0 adgif-data) (the-as (inline-array adgif-shader) (&-> v0-0 data vec-data-size)))
    v0-0
    )
  )

;; definition for method 0 of type sprite-array-3d
(defmethod new sprite-array-3d ((allocation symbol) (type-to-make type) (group-0-size int) (group-1-size int))
  (let* ((sprite-count (+ group-0-size group-1-size))
         (vec-data-size (* 3 sprite-count))
         (adgif-data-size (* 5 sprite-count))
         (v0-0 (object-new
                 allocation
                 type-to-make
                 (the-as int (+ (-> type-to-make size) (* (+ adgif-data-size -1 vec-data-size) 16)))
                 )
               )
         )
    (set! (-> v0-0 num-sprites 0) group-0-size)
    (set! (-> v0-0 num-sprites 1) group-1-size)
    (set! (-> v0-0 num-valid 0) 0)
    (set! (-> v0-0 num-valid 1) 0)
    (set! (-> v0-0 vec-data) (-> v0-0 data))
    (set! (-> v0-0 adgif-data) (the-as (inline-array adgif-shader) (&-> v0-0 data vec-data-size)))
    v0-0
    )
  )

;; definition for symbol *sprite-array-2d*, type sprite-array-2d
(define *sprite-array-2d* (new 'global 'sprite-array-2d 1920 128))

;; definition for symbol *sprite-array-3d*, type sprite-array-3d
(define *sprite-array-3d* (new 'global 'sprite-array-3d 256 0))

;; definition for function sprite-set-3d-quaternion!
(defun sprite-set-3d-quaternion! ((arg0 sprite-vec-data-3d) (arg1 quaternion))
  (local-vars (v1-0 float) (v1-1 float))
  (rlet ((vf0 :class vf)
         (vf1 :class vf)
         (vf2 :class vf)
         )
    (init-vf0-vector)
    (cond
      ((< (-> arg1 w) 0.0)
       (.lvf vf1 (&-> arg0 qx-qy-qz-sy quad))
       (.lvf vf2 (&-> arg1 vec quad))
       (.sub.vf vf1 vf0 vf2 :mask #b111)
       (.svf (&-> arg0 qx-qy-qz-sy quad) vf1)
       (.mov v1-0 vf1)
       )
      (else
        (.lvf vf1 (&-> arg0 qx-qy-qz-sy quad))
        (.lvf vf2 (&-> arg1 vec quad))
        (.add.vf vf1 vf0 vf2 :mask #b111)
        (.svf (&-> arg0 qx-qy-qz-sy quad) vf1)
        (.mov v1-1 vf1)
        )
      )
    arg1
    )
  )

;; definition for function sprite-get-3d-quaternion!
(defun sprite-get-3d-quaternion! ((arg0 quaternion) (arg1 sprite-vec-data-3d))
  (let ((f0-0 (-> arg1 qx-qy-qz-sy x))
        (f1-0 (-> arg1 qx-qy-qz-sy y))
        (f3-0 (-> arg1 qx-qy-qz-sy z))
        )
    (set! (-> arg0 x) f0-0)
    (set! (-> arg0 y) f1-0)
    (set! (-> arg0 z) f3-0)
    (set! (-> arg0 w) (sqrtf (- (- (- 1.0 (* f3-0 f3-0)) (* f1-0 f1-0)) (* f0-0 f0-0))))
    )
  arg0
  )

;; definition for function sprite-add-matrix-data
;; INFO: Used lq/sq
;; INFO: Return type mismatch int vs none.
(defun sprite-add-matrix-data ((dma-buff dma-buffer) (matrix-mode uint))
  (let ((count 900))
    (cond
      ((zero? matrix-mode)
       (let* ((a1-1 dma-buff)
              (pkt1 (the-as dma-packet (-> a1-1 base)))
              )
         (set! (-> pkt1 dma) (new 'static 'dma-tag :qwc #x5 :id (dma-tag-id cnt)))
         (set! (-> pkt1 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)))
         (set! (-> pkt1 vif1) (new 'static 'vif-tag :num #x5 :cmd (vif-cmd unpack-v4-32) :imm (shr (shl count 54) 54)))
         (set! (-> a1-1 base) (&+ (the-as pointer pkt1) 16))
         )
       (let* ((mtx (the-as matrix (-> dma-buff base)))
              (t1-0 (-> *math-camera* camera-temp))
              (a2-4 (-> t1-0 vector 0 quad))
              (a3-4 (-> t1-0 vector 1 quad))
              (t0-4 (-> t1-0 vector 2 quad))
              (t1-1 (-> t1-0 vector 3 quad))
              )
         (set! (-> mtx vector 0 quad) a2-4)
         (set! (-> mtx vector 1 quad) a3-4)
         (set! (-> mtx vector 2 quad) t0-4)
         (set! (-> mtx vector 3 quad) t1-1)
         )
       (&+! (-> dma-buff base) 64)
       (let ((v1-1 (+ count 4)))
         (set! (-> (the-as (pointer uint128) (-> dma-buff base))) (-> *math-camera* hvdf-off quad))
         (&+! (-> dma-buff base) 16)
         (+ v1-1 1)
         )
       )
      ((= matrix-mode 1)
       (let* ((a1-10 dma-buff)
              (pkt2 (the-as dma-packet (-> a1-10 base)))
              )
         (set! (-> pkt2 dma) (new 'static 'dma-tag :qwc #x50 :id (dma-tag-id cnt)))
         (set! (-> pkt2 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)))
         (set! (-> pkt2 vif1)
               (new 'static 'vif-tag :num #x50 :cmd (vif-cmd unpack-v4-32) :imm (shr (shl count 54) 54))
               )
         (set! (-> a1-10 base) (&+ (the-as pointer pkt2) 16))
         )
       (let ((mtx2 (the-as matrix (-> dma-buff base)))
             (f1-0 (-> *math-camera* perspective vector 0 x))
             (f2-0 (-> *math-camera* perspective vector 1 y))
             (f0-1 (* -1.9996 (-> *math-camera* perspective vector 0 x)))
             )
         (set-vector! (-> mtx2 vector 0) f0-1 0.0 0.0 0.0)
         (set-vector! (-> mtx2 vector 1) 0.0 (- (* (/ f2-0 f1-0) f0-1)) 0.0 0.0)
         (set-vector! (-> mtx2 vector 2) 0.0 0.0 (- f0-1) 0.0)
         (set-vector! (-> mtx2 vector 3) 0.0 0.0 (* 500000000.0 f0-1) (* 60.0 f0-1 (-> *math-camera* pfog0)))
         )
       (&+! (-> dma-buff base) 64)
       (let ((v1-2 (+ count 4)))
         (let ((a1-16 (the-as vector (-> dma-buff base))))
           (set! (-> a1-16 quad) (-> *math-camera* hvdf-off quad))
           (set! (-> a1-16 x) 2048.0)
           (set! (-> a1-16 y) 2048.0)
           (set! (-> a1-16 z) (-> *math-camera* hvdf-off z))
           )
         (&+! (-> dma-buff base) 16)
         (let ((v1-3 (+ v1-2 1)))
           (dotimes (hvdf-idx 75)
             (set! (-> (the-as (pointer uint128) (-> dma-buff base))) (-> *sprite-hvdf-data* data (+ hvdf-idx 1) quad))
             (&+! (-> dma-buff base) 16)
             (+! v1-3 1)
             )
           )
         )
       )
      )
    )
  0
  (none)
  )

;; definition for function sprite-add-frame-data
;; INFO: Return type mismatch pointer vs none.
(defun sprite-add-frame-data ((dma-buff dma-buffer) (tbp-offset uint))
  (let ((s5-0 41))
    (let* ((v1-0 dma-buff)
           (pkt (the-as dma-packet (-> v1-0 base)))
           )
      (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc s5-0))
      (set! (-> pkt vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)))
      (set! (-> pkt vif1) (new 'static 'vif-tag :imm #x3d4 :cmd (vif-cmd unpack-v4-32) :num s5-0))
      (set! (-> v1-0 base) (&+ (the-as pointer pkt) 16))
      )
    (sprite-setup-frame-data (the-as sprite-frame-data (-> dma-buff base)) (the-as int tbp-offset))
    (&+! (-> dma-buff base) (* s5-0 16))
    )
  (none)
  )

;; definition for function sprite-add-2d-chunk
;; INFO: Return type mismatch pointer vs none.
(defun sprite-add-2d-chunk ((sprites sprite-array-2d) (start-sprite-idx int) (num-sprites int) (dma-buff dma-buffer) (mscal-addr int))
  (let ((qwc-pkt1 1))
    (let* ((v1-0 dma-buff)
           (pkt1 (the-as dma-packet (-> v1-0 base)))
           )
      (set! (-> pkt1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc qwc-pkt1))
      (set! (-> pkt1 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)))
      (set! (-> pkt1 vif1) (new 'static 'vif-tag :imm #x8000 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt1))
      (set! (-> v1-0 base) (&+ (the-as pointer pkt1) 16))
      )
    (sprite-setup-header (the-as sprite-header (-> dma-buff base)) num-sprites)
    (&+! (-> dma-buff base) (* qwc-pkt1 16))
    )
  (let* ((qwc-pkt2 (* 3 num-sprites))
         (v1-4 dma-buff)
         (pkt2 (the-as dma-packet (-> v1-4 base)))
         )
    (set! (-> pkt2 dma) (new 'static 'dma-tag
                          :id (dma-tag-id ref)
                          :addr (the-as int (&+ (-> sprites vec-data) (* 48 start-sprite-idx)))
                          :qwc qwc-pkt2
                          )
          )
    (set! (-> pkt2 vif0) (new 'static 'vif-tag))
    (set! (-> pkt2 vif1) (new 'static 'vif-tag :imm #x8001 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt2))
    (set! (-> v1-4 base) (&+ (the-as pointer pkt2) 16))
    )
  (let* ((qwc-pkt3 (* 5 num-sprites))
         (v1-6 dma-buff)
         (pkt3 (the-as dma-packet (-> v1-6 base)))
         )
    (set! (-> pkt3 dma) (new 'static 'dma-tag
                          :id (dma-tag-id ref)
                          :addr (+ (the-as int (-> sprites adgif-data)) (* 80 start-sprite-idx))
                          :qwc qwc-pkt3
                          )
          )
    (set! (-> pkt3 vif0) (new 'static 'vif-tag))
    (set! (-> pkt3 vif1) (new 'static 'vif-tag :imm #x8091 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt3))
    (set! (-> v1-6 base) (&+ (the-as pointer pkt3) 16))
    )
  (let ((pkt4 (the-as dma-packet (-> dma-buff base))))
    (set! (-> pkt4 dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
    (set! (-> pkt4 vif0) (new 'static 'vif-tag))
    (set! (-> pkt4 vif1) (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm mscal-addr))
    (set! (-> dma-buff base) (&+ (the-as pointer pkt4) 16))
    )
  (none)
  )

;; definition for function sprite-add-2d-all
(defun sprite-add-2d-all ((sprites sprite-array-2d) (dma-buff dma-buffer) (group-idx int))
  (when (> (-> sprites num-valid group-idx) 0)
    (let ((current-sprite-idx 0)
          (mscal-addr 3)
          )
      (when (= group-idx 1)
        (set! current-sprite-idx (-> sprites num-sprites 0))
        (set! mscal-addr 109)
        )
      (let ((remaining-sprites (-> sprites num-valid group-idx)))
        (while (< 48 remaining-sprites)
          (sprite-add-2d-chunk sprites current-sprite-idx 48 dma-buff mscal-addr)
          (+! current-sprite-idx 48)
          (+! remaining-sprites -48)
          )
        (sprite-add-2d-chunk sprites current-sprite-idx remaining-sprites dma-buff mscal-addr)
        )
      )
    )
  (none)
  )

;; definition for function sprite-add-3d-chunk
;; INFO: Return type mismatch pointer vs none.
(defun sprite-add-3d-chunk ((sprites sprite-array-3d) (start-sprite-idx int) (num-sprites int) (dma-buff dma-buffer))
  (let ((qwc-pkt1 1))
    (let* ((v1-0 dma-buff)
           (pkt1 (the-as dma-packet (-> v1-0 base)))
           )
      (set! (-> pkt1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc qwc-pkt1))
      (set! (-> pkt1 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)))
      (set! (-> pkt1 vif1) (new 'static 'vif-tag :imm #x8000 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt1))
      (set! (-> v1-0 base) (&+ (the-as pointer pkt1) 16))
      )
    (sprite-setup-header (the-as sprite-header (-> dma-buff base)) num-sprites)
    (&+! (-> dma-buff base) (* qwc-pkt1 16))
    )
  (let* ((qwc-pkt2 (* 3 num-sprites))
         (v1-4 dma-buff)
         (pkt2 (the-as dma-packet (-> v1-4 base)))
         )
    (set! (-> pkt2 dma) (new 'static 'dma-tag
                          :id (dma-tag-id ref)
                          :addr (the-as int (&+ (-> sprites vec-data) (* 48 start-sprite-idx)))
                          :qwc qwc-pkt2
                          )
          )
    (set! (-> pkt2 vif0) (new 'static 'vif-tag))
    (set! (-> pkt2 vif1) (new 'static 'vif-tag :imm #x8001 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt2))
    (set! (-> v1-4 base) (&+ (the-as pointer pkt2) 16))
    )
  (let* ((qwc-pkt3 (* 5 num-sprites))
         (v1-6 dma-buff)
         (pkt3 (the-as dma-packet (-> v1-6 base)))
         )
    (set! (-> pkt3 dma) (new 'static 'dma-tag
                          :id (dma-tag-id ref)
                          :addr (the-as int (-> sprites adgif-data start-sprite-idx))
                          :qwc qwc-pkt3
                          )
          )
    (set! (-> pkt3 vif0) (new 'static 'vif-tag))
    (set! (-> pkt3 vif1) (new 'static 'vif-tag :imm #x8091 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt3))
    (set! (-> v1-6 base) (&+ (the-as pointer pkt3) 16))
    )
  (let ((pkt4 (the-as dma-packet (-> dma-buff base))))
    (set! (-> pkt4 dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
    (set! (-> pkt4 vif0) (new 'static 'vif-tag))
    (set! (-> pkt4 vif1) (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm #xd3))
    (set! (-> dma-buff base) (&+ (the-as pointer pkt4) 16))
    )
  (none)
  )

;; definition for function sprite-add-3d-all
(defun sprite-add-3d-all ((sprites sprite-array-3d) (dma-buff dma-buffer) (group-idx int))
  (when (> (-> sprites num-valid group-idx) 0)
    (let ((current-sprite-idx (if (zero? group-idx)
                                  0
                                  (-> sprites num-sprites 0)
                                  )
                              )
          (remaining-sprites (-> sprites num-valid group-idx))
          )
      (while (< 48 remaining-sprites)
        (sprite-add-3d-chunk sprites current-sprite-idx 48 dma-buff)
        (+! current-sprite-idx 48)
        (+! remaining-sprites -48)
        )
      (sprite-add-3d-chunk sprites current-sprite-idx remaining-sprites dma-buff)
      )
    )
  (none)
  )

;; definition for function sprite-add-shadow-chunk
;; INFO: Return type mismatch pointer vs none.
(defun sprite-add-shadow-chunk ((shadow-buff fake-shadow-buffer) (start-idx int) (num-sprites int) (dma-buff dma-buffer))
  (let ((qwc-pkt1 1))
    (let* ((v1-0 dma-buff)
           (pkt1 (the-as dma-packet (-> v1-0 base)))
           )
      (set! (-> pkt1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc qwc-pkt1))
      (set! (-> pkt1 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)))
      (set! (-> pkt1 vif1) (new 'static 'vif-tag :imm #x8000 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt1))
      (set! (-> v1-0 base) (&+ (the-as pointer pkt1) 16))
      )
    (sprite-setup-header (the-as sprite-header (-> dma-buff base)) num-sprites)
    (&+! (-> dma-buff base) (* qwc-pkt1 16))
    )
  (let* ((qwc-pkt2 (* 3 num-sprites))
         (v1-4 dma-buff)
         (pkt2 (the-as dma-packet (-> v1-4 base)))
         )
    (set! (-> pkt2 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc qwc-pkt2))
    (set! (-> pkt2 vif0) (new 'static 'vif-tag))
    (set! (-> pkt2 vif1) (new 'static 'vif-tag :imm #x8001 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt2))
    (set! (-> v1-4 base) (&+ (the-as pointer pkt2) 16))
    )
  (dotimes (sprite-idx num-sprites)
    (let ((dma-vec-data (the-as (inline-array vector) (-> dma-buff base))))
      (let ((in-vec-data (-> shadow-buff data (+ start-idx sprite-idx))))
        (set! (-> dma-vec-data 0 x) (-> in-vec-data px))
        (set! (-> dma-vec-data 0 y) (-> in-vec-data py))
        (set! (-> dma-vec-data 0 z) (-> in-vec-data pz))
        (set! (-> dma-vec-data 0 w) (-> in-vec-data scale))
        (set! (-> dma-vec-data 1 x) (-> in-vec-data qx))
        (set! (-> dma-vec-data 1 y) (-> in-vec-data qy))
        (set! (-> dma-vec-data 1 z) (-> in-vec-data qz))
        (set! (-> dma-vec-data 1 w) (-> in-vec-data scale))
        )
      (set! (-> dma-vec-data 2 x) 128.0)
      (set! (-> dma-vec-data 2 y) 128.0)
      (set! (-> dma-vec-data 2 z) 128.0)
      (set! (-> dma-vec-data 2 w) 40.0)
      )
    (&+! (-> dma-buff base) 48)
    )
  (let* ((qwc-pkt3 (* 5 num-sprites))
         (v1-9 dma-buff)
         (pkt3 (the-as dma-packet (-> v1-9 base)))
         )
    (set! (-> pkt3 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc qwc-pkt3))
    (set! (-> pkt3 vif0) (new 'static 'vif-tag))
    (set! (-> pkt3 vif1) (new 'static 'vif-tag :imm #x8091 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt3))
    (set! (-> v1-9 base) (&+ (the-as pointer pkt3) 16))
    )
  (dotimes (si num-sprites)
    (let ((dma-adgif-data (the-as adgif-shader (-> dma-buff base)))
          (in-adgif-data (-> shadow-buff data (+ start-idx si)))
          )
      (adgif-shader<-texture-simple! dma-adgif-data *shadow-middot-texture*)
      (if (logtest? (-> in-adgif-data flags) 1)
          (set! (-> dma-adgif-data alpha) (new 'static 'gs-alpha :b #x2 :d #x1))
          (set! (-> dma-adgif-data alpha) (new 'static 'gs-alpha :a #x2 :d #x1))
          )
      )
    (&+! (-> dma-buff base) 80)
    )
  (let ((pkt4 (the-as dma-packet (-> dma-buff base))))
    (set! (-> pkt4 dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
    (set! (-> pkt4 vif0) (new 'static 'vif-tag))
    (set! (-> pkt4 vif1) (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm #xd3))
    (set! (-> dma-buff base) (&+ (the-as pointer pkt4) 16))
    )
  (none)
  )

;; definition for function sprite-add-shadow-all
(defun sprite-add-shadow-all ((shadow-buff fake-shadow-buffer) (dma-buff dma-buffer))
  (when (> (-> shadow-buff num-shadows) 0)
    (let ((current-shadow 0)
          (remaining-shadows (-> shadow-buff num-shadows))
          )
      (while (< 48 remaining-shadows)
        (sprite-add-shadow-chunk shadow-buff current-shadow 48 dma-buff)
        (+! current-shadow 48)
        (+! remaining-shadows -48)
        )
      (sprite-add-shadow-chunk shadow-buff current-shadow remaining-shadows dma-buff)
      )
    )
  (none)
  )

;; definition for function sprite-draw
;; INFO: Return type mismatch int vs none.
(defun sprite-draw ((disp display))
  (let ((dma-mem-begin (-> *display* frames (-> *display* on-screen) frame global-buf base)))
    (let* ((dma-buff (-> *display* frames (-> *display* on-screen) frame global-buf))
           (dma-bucket-begin (-> dma-buff base))
           )
      (sprite-init-distorter dma-buff (-> disp frames (-> disp on-screen) draw frame1 fbp))
      (sprite-draw-distorters dma-buff)
      (let* ((v1-13 dma-buff)
             (pkt1 (the-as dma-packet (-> v1-13 base)))
             )
        (set! (-> pkt1 dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt)))
        (set! (-> pkt1 vif0) (new 'static 'vif-tag))
        (set! (-> pkt1 vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1))
        (set! (-> v1-13 base) (&+ (the-as pointer pkt1) 16))
        )
      (let* ((v1-14 dma-buff)
             (giftag (the-as gs-gif-tag (-> v1-14 base)))
             )
        (set! (-> giftag tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2))
        (set! (-> giftag regs)
              (new 'static 'gif-tag-regs
                :regs0 (gif-reg-id a+d)
                :regs1 (gif-reg-id a+d)
                :regs2 (gif-reg-id a+d)
                :regs3 (gif-reg-id a+d)
                :regs4 (gif-reg-id a+d)
                :regs5 (gif-reg-id a+d)
                :regs6 (gif-reg-id a+d)
                :regs7 (gif-reg-id a+d)
                :regs8 (gif-reg-id a+d)
                :regs9 (gif-reg-id a+d)
                :regs10 (gif-reg-id a+d)
                :regs11 (gif-reg-id a+d)
                :regs12 (gif-reg-id a+d)
                :regs13 (gif-reg-id a+d)
                :regs14 (gif-reg-id a+d)
                :regs15 (gif-reg-id a+d)
                )
              )
        (set! (-> v1-14 base) (&+ (the-as pointer giftag) 16))
        )
      (let* ((v1-15 dma-buff)
             (a0-13 (-> v1-15 base))
             )
        (set! (-> (the-as (pointer gs-test) a0-13) 0)
              (new 'static 'gs-test
                :ate #x1
                :atst (gs-atest greater-equal)
                :aref #x26
                :afail #x1
                :zte #x1
                :ztst (gs-ztest greater-equal)
                )
              )
        (set! (-> (the-as (pointer gs-reg64) a0-13) 1) (gs-reg64 test-1))
        (set! (-> (the-as (pointer gs-clamp) a0-13) 2)
              (new 'static 'gs-clamp :wms (gs-tex-wrap-mode clamp) :wmt (gs-tex-wrap-mode clamp))
              )
        (set! (-> (the-as (pointer gs-reg64) a0-13) 3) (gs-reg64 clamp-1))
        (set! (-> v1-15 base) (&+ a0-13 32))
        )
      (dma-buffer-add-vu-function dma-buff sprite-vu1-block 1)
      (sprite-add-frame-data dma-buff (-> disp frames (-> disp on-screen) draw frame1 fbp))
      (let* ((v1-22 dma-buff)
             (pkt2 (the-as dma-packet (-> v1-22 base)))
             )
        (set! (-> pkt2 dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
        (set! (-> pkt2 vif0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1 :imm #x0))
        (set! (-> pkt2 vif1) (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1))
        (set! (-> v1-22 base) (&+ (the-as pointer pkt2) 16))
        )
      (let* ((v1-23 dma-buff)
             (pkt3 (the-as dma-packet (-> v1-23 base)))
             )
        (set! (-> pkt3 dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
        (set! (-> pkt3 vif0) (new 'static 'vif-tag :cmd (vif-cmd base)))
        (set! (-> pkt3 vif1) (new 'static 'vif-tag :imm #x190 :cmd (vif-cmd offset)))
        (set! (-> v1-23 base) (&+ (the-as pointer pkt3) 16))
        )
      (sprite-add-matrix-data dma-buff (the-as uint 0))
      (sprite-add-3d-all *sprite-array-3d* dma-buff 0)
      (sprite-add-2d-all *sprite-array-2d* dma-buff 0)
      (sprite-add-shadow-all
        (if (= *fake-shadow-buffer* *fake-shadow-buffer-1*)
            *fake-shadow-buffer-2*
            *fake-shadow-buffer-1*
            )
        dma-buff
        )
      (let* ((v1-25 dma-buff)
             (pkt4 (the-as dma-packet (-> v1-25 base)))
             )
        (set! (-> pkt4 dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
        (set! (-> pkt4 vif0) (new 'static 'vif-tag))
        (set! (-> pkt4 vif1) (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1))
        (set! (-> v1-25 base) (&+ (the-as pointer pkt4) 16))
        )
      (sprite-add-matrix-data dma-buff (the-as uint 1))
      (sprite-add-2d-all *sprite-array-2d* dma-buff 1)
      (let ((a3-0 (-> dma-buff base)))
        (let ((pkt5 (the-as dma-packet (-> dma-buff base))))
          (set! (-> pkt5 dma) (new 'static 'dma-tag :id (dma-tag-id next)))
          (set! (-> pkt5 vif0) (new 'static 'vif-tag))
          (set! (-> pkt5 vif1) (new 'static 'vif-tag))
          (set! (-> dma-buff base) (&+ (the-as pointer pkt5) 16))
          )
        (dma-bucket-insert-tag
          (-> *display* frames (-> *display* on-screen) frame bucket-group)
          (bucket-id sprite)
          dma-bucket-begin
          (the-as (pointer dma-tag) a3-0)
          )
        )
      )
    (let ((mem-use *dma-mem-usage*))
      (when (nonzero? mem-use)
        (set! (-> mem-use length) (max 83 (-> mem-use length)))
        (set! (-> mem-use data 82 name) "sprite")
        (+! (-> mem-use data 82 count) 1)
        (+! (-> mem-use data 82 used)
            (&- (-> *display* frames (-> *display* on-screen) frame global-buf base) (the-as uint dma-mem-begin))
            )
        (set! (-> mem-use data 82 total) (-> mem-use data 82 used))
        )
      )
    )
  0
  (none)
  )

;; definition for function sprite-allocate-user-hvdf
(defun sprite-allocate-user-hvdf ()
  (dotimes (v1-0 76)
    (when (zero? (-> *sprite-hvdf-control* alloc v1-0))
      (set! (-> *sprite-hvdf-control* alloc v1-0) 1)
      (return v1-0)
      )
    )
  0
  )

;; definition for function sprite-release-user-hvdf
;; INFO: Return type mismatch int vs none.
(defun sprite-release-user-hvdf ((arg0 int))
  (when (and (>= arg0 1) (< arg0 76))
    (set! (-> *sprite-hvdf-control* alloc arg0) 0)
    0
    )
  0
  (none)
  )

;; definition for function sprite-get-user-hvdf
;; INFO: Return type mismatch qword vs vector.
(defun sprite-get-user-hvdf ((arg0 int))
  (the-as vector (-> *sprite-hvdf-data* data arg0))
  )
