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

;; name: generic-merc-h.gc
;; name in dgo: generic-merc-h
;; dgos: ENGINE, GAME

;; DECOMP BEGINS

(deftype merc-matrix (structure)
  ((quad    uint128  8)
   (vector  vector   8 :inline :overlay-at (-> quad 0))
   (tag     uint64             :overlay-at (-> quad 0))
   )
  )


(deftype generic-merc-tag (dma-packet)
  ((next-ptr  uint32  :overlay-at vif1)
   (size      uint32  :overlay-at vif0)
   )
  )


(deftype generic-merc-ctrl (structure)
  ((tag     generic-merc-tag  :inline)
   (lights  vu-lights         :inline)
   (header  merc-ctrl-header  :inline)
   (effect  merc-effect       :inline)
   )
  )


(deftype generic-merc-ctrl-with-sfx (generic-merc-ctrl)
  ((sfx-data  uint128  11)
   )
  )


(deftype generic-merc-input (structure)
  ((geo-tag      generic-merc-tag            :inline)
   (geo-block    uint8                       1296)
   (byte-header  merc-byte-header            :inline :overlay-at (-> geo-block 0))
   (matrix       merc-matrix                 9 :inline)
   (control      generic-merc-ctrl-with-sfx  :inline)
   (end-tag      generic-merc-tag            :inline)
   (shader       adgif-shader                :inline)
   )
  )


(deftype generic-merc-output (structure)
  ((info              gsf-info    :inline)
   (header            gsf-header  :inline)
   (index-kick-table  uint16      80)
   (index-table       uint8       160 :overlay-at (-> index-kick-table 0))
   (inverse-table     uint8       256)
   (vertex-table      gsf-vertex  72 :inline)
   )
  )


(deftype generic-merc-dcache (structure)
  ((output-a     generic-merc-output  :inline)
   (output-b     generic-merc-output  :inline)
   (inv-table-1  uint8                544)
   (inv-table-7  uint8                544)
   (inv-safety   uint8                16)
   (effect-data  uint8                1584)
   )
  )


(deftype gm-shadow (structure)
  ((perspective                 matrix        :inline)
   (isometric                   matrix        :inline)
   (inv-camera-rot              matrix        :inline)
   (envmap-shader               adgif-shader  :inline)
   (current-chain               uint32)
   (next-chain                  uint32)
   (buf-index                   uint32)
   (fragment-count              uint32)
   (write-limit                 int32)
   (indexed-input-base          generic-merc-input)
   (other-input-base            generic-merc-input)
   (indexed-output-base         generic-merc-output)
   (other-output-base           generic-merc-output)
   (p-input                     uint32)
   (gsf-buf                     generic-merc-dcache)
   (p-fheader                   merc-fp-header)
   (curr-chain                  basic)
   (mercneric-convert           basic)
   (generic-prepare-dma-single  basic)
   (generic-prepare-dma-double  basic)
   (generic-light-proc          basic)
   (generic-envmap-proc         basic)
   (high-speed-reject           basic)
   (dummy-0                     uint32)
   (hsr-xmult                   vector        :inline)
   (hsr-ymult                   vector        :inline)
   (warp-consts                 vector        :inline)
   )
  )


(deftype generic-merc-work (structure)
  ((input-a  generic-merc-input          :inline)
   (input-b  generic-merc-input          :inline)
   (ctrl     generic-merc-ctrl-with-sfx  :inline)
   (shadow   gm-shadow                   :inline)
   (stack    uint128                     16)
   )
  )
