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

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

;; The font system draws all of the text strings.

;; +++font-color
(defenum font-color
  :type uint32
  (default 0)
  (white 1)
  (transparent 2)
  (red 3)
  (orange 4)
  (yellow 5)
  (green 6)
  (blue 7)
  (cyan 8)
  (pink 9)
  (menu-selected 10)
  (menu-selected-parent 11)
  (menu 12)
  (menu-parent 13)
  (menu-func-bad 14)
  (menu-flag-on 15)
  (menu-flag-on-parent 16)
  (menu-flag-off 17)
  (menu-flag-off-parent 18)
  (menu-invalid 19)
  (flat-yellow 20)
  (font-color-21 21)
  (pad-back 22)
  (pad-shine 23)
  (pad-square 24)
  (pad-circle 25)
  (pad-triangle 26)
  (pad-x 27)
  (progress-old-blue 28)
  (progress-old-yellow 29)
  (progress-old-selected 30)
  (progress-old-percent 31)
  (progress 32)
  (progress-selected 33)
  (progress-force-selected 34)
  (progress-option-off 35)
  (font-color-36 36)
  (credits-staff-title1 37)
  (credits-staff-title2 38)
  (font-color-39 39)
  )
;; ---font-color

;; copied from jak1, not completely confirmed.
(defenum font-flags
  :type uint32
  :bitfield #t
  (shadow 0)
  (kerning 1)
  (middle 2)
  (middle-vert 3)
  (right 4)
  (large 5)
  (pc-hack 6)
  )

;; added type
(deftype draw-string-result (uint64)
  ((length float :offset 0)
   (b float :offset 32))
  )

(define-extern draw-string-xy (function string dma-buffer int int font-color font-flags draw-string-result))

;; DECOMP BEGINS

(deftype char-verts (structure)
  ((pos    vector 4 :inline :offset-assert   0)
   (color  vector 4 :inline :offset-assert  64)
   (tex-st vector 4 :inline :offset-assert 128)
   )
  :method-count-assert 9
  :size-assert         #xc0
  :flag-assert         #x9000000c0
  )


(deftype char-color (structure)
  ((color rgba 4 :offset-assert   0)
   )
  :method-count-assert 9
  :size-assert         #x10
  :flag-assert         #x900000010
  )


(define *font-default-matrix*
  (new 'static 'matrix :vector (new 'static 'inline-array vector 4
                                 (new 'static 'vector :x 1.0)
                                 (new 'static 'vector :y 1.0)
                                 (new 'static 'vector :z 1.0)
                                 (new 'static 'vector :x -256.0 :y -208.0 :w 1.0)
                                 )
                       )
  )

;; font settings that can be passed to draw-string
(deftype font-context (basic)
  ((origin     vector     :inline :offset-assert  16)
   (strip-gif  vector     :inline :offset-assert  32)
   (width      float              :offset-assert  48)
   (height     float              :offset-assert  52)
   (projection float              :offset-assert  56)
   (scale      float              :offset-assert  60)
   (color      font-color         :offset-assert  64)
   (flags      font-flags         :offset-assert  68)
   (mat        matrix             :offset-assert  72)
   (start-line uint32             :offset-assert  76)
   (alpha      float              :offset-assert  80)
   )
  :method-count-assert 21
  :size-assert         #x54
  :flag-assert         #x1500000054
  (:methods
    (new (symbol type matrix int int float font-color font-flags) _type_)
    (set-mat! (font-context matrix) font-context)
    (set-origin! (font-context int int) font-context)
    (set-depth! (font-context int) font-context)
    (set-w! (font-context float) font-context)
    (set-width! (font-context int) font-context)
    (set-height! (font-context int) font-context)
    (set-projection! (font-context float) font-context)
    (set-color! (font-context font-color) font-context)
    (set-flags! (font-context font-flags) font-context)
    (set-start-line! (font-context uint) font-context)
    (set-scale! (font-context float) font-context)
    (set-alpha! (font-context float) font-context)
    )
  )


(defmethod set-mat! font-context ((obj font-context) (arg0 matrix))
  (set! (-> obj mat) arg0)
  obj
  )

(defmethod set-origin! font-context ((obj font-context) (arg0 int) (arg1 int))
  (set! (-> obj origin x) (the float arg0))
  (set! (-> obj origin y) (the float arg1))
  obj
  )

(defmethod set-depth! font-context ((obj font-context) (arg0 int))
  (set! (-> obj origin z) (the float arg0))
  obj
  )

(defmethod set-w! font-context ((obj font-context) (arg0 float))
  (set! (-> obj origin w) arg0)
  obj
  )

(defmethod set-width! font-context ((obj font-context) (arg0 int))
  (set! (-> obj width) (the float arg0))
  obj
  )

(defmethod set-height! font-context ((obj font-context) (arg0 int))
  (set! (-> obj height) (the float arg0))
  obj
  )

(defmethod set-projection! font-context ((obj font-context) (arg0 float))
  (set! (-> obj projection) arg0)
  obj
  )

(defmethod set-color! font-context ((obj font-context) (arg0 font-color))
  (set! (-> obj color) arg0)
  obj
  )

(defmethod set-flags! font-context ((obj font-context) (arg0 font-flags))
  (set! (-> obj flags) arg0)
  obj
  )

(defmethod set-start-line! font-context ((obj font-context) (arg0 uint))
  (set! (-> obj start-line) arg0)
  obj
  )

(defmethod set-scale! font-context ((obj font-context) (arg0 float))
  (set! (-> obj scale) arg0)
  obj
  )

(defmethod set-alpha! font-context ((obj font-context) (arg0 float))
  (set! (-> obj alpha) arg0)
  obj
  )

(defmethod new font-context ((allocation symbol)
                           (type-to-make type)
                           (arg0 matrix)
                           (arg1 int)
                           (arg2 int)
                           (arg3 float)
                           (arg4 font-color)
                           (arg5 font-flags)
                           )
  (let ((v0-0 (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
    (set! (-> v0-0 mat) arg0)
    (let ((v1-3 v0-0))
      (set! (-> v1-3 origin x) (the float arg1))
      (set! (-> v1-3 origin y) (the float arg2))
      )
    (cond
      ((= arg3 0.0)
       (let ((v1-4 v0-0))
         (set! (-> v1-4 origin z) (-> *math-camera* isometric trans z))
         )
       )
      (else
        (let ((v1-5 v0-0))
          (set! (-> v1-5 origin z) arg3)
          )
        )
      )
    (let ((v1-6 v0-0))
      (set! (-> v1-6 origin w) 1.0)
      )
    (let ((v1-7 v0-0))
      (set! (-> v1-7 width) (the float 512))
      )
    (let ((v1-8 v0-0))
      (set! (-> v1-8 height) (the float 416))
      )
    (let ((v1-9 v0-0))
      (set! (-> v1-9 projection) 1.0)
      )
    (set! (-> v0-0 color) arg4)
    (set! (-> v0-0 flags) arg5)
    (let ((a0-6 v0-0))
      (set! (-> a0-6 start-line) (the-as uint 0))
      )
    (let ((v1-13 v0-0))
      (set! (-> v1-13 scale) 1.0)
      )
    (let ((v1-14 v0-0))
      (set! (-> v1-14 alpha) 1.0)
      )
    v0-0
    )
  )

(deftype font-work (structure)
  ((font-tmpl           dma-gif-packet :inline    :offset-assert   0)
   (char-tmpl           dma-gif-packet :inline    :offset-assert  32)
   (tex1-tmpl           uint64         2          :offset-assert  64)
   (small-font-0-tmpl   uint64         2          :offset-assert  80)
   (small-font-1-tmpl   uint64         2          :offset-assert  96)
   (small-font-2-tmpl   uint64         2          :offset-assert 112)
   (small-font-3-tmpl   uint64         2          :offset-assert 128)
   (large-font-0-tmpl   uint64         2          :offset-assert 144)
   (large-font-1-tmpl   uint64         2          :offset-assert 160)
   (large-font-2-tmpl   uint64         2          :offset-assert 176)
   (large-font-3-tmpl   uint64         2          :offset-assert 192)
   (size1-small         vector         :inline    :offset-assert 208)
   (size2-small         vector         :inline    :offset-assert 224)
   (size3-small         vector         :inline    :offset-assert 240)
   (size1-large         vector         :inline    :offset-assert 256)
   (size2-large-0       vector         :inline    :offset-assert 272)
   (size2-large-1       vector         :inline    :offset-assert 288)
   (size2-large-2       vector         :inline    :offset-assert 304)
   (size2-large-3       vector         :inline    :offset-assert 320)
   (size3-large         vector         :inline    :offset-assert 336)
   (size2-0             vector         :inline    :offset-assert 352)
   (size2-1             vector         :inline    :offset-assert 368)
   (size2-2             vector         :inline    :offset-assert 384)
   (size2-3             vector         :inline    :offset-assert 400)
   (size-st1            vector         :inline    :offset-assert 416)
   (size-st2            vector         :inline    :offset-assert 432)
   (size-st3            vector         :inline    :offset-assert 448)
   (save                vector         :inline    :offset-assert 464)
   (save-color          vector         4 :inline  :offset-assert 480)
   (current-verts       char-verts     :inline    :offset-assert 544)
   (src-verts           char-verts     :inline    :offset-assert 736)
   (dest-verts          char-verts     :inline    :offset-assert 928)
   (justify             vector         64 :inline :offset-assert 1120)
   (color-shadow        vector4w       :inline    :offset-assert 2144)
   (color-table         char-color     40 :inline :offset-assert 2160)
   (current-font-0-tmpl uint64         2          :offset-assert 2800)
   (current-font-1-tmpl uint64         2          :offset-assert 2816)
   (current-font-2-tmpl uint64         2          :offset-assert 2832)
   (current-font-3-tmpl uint64         2          :offset-assert 2848)
   (last-color          font-color                :offset-assert 2864)
   (save-last-color     font-color                :offset-assert 2868)
   (buf                 basic                     :offset-assert 2872)
   (str-ptr             uint32                    :offset-assert 2876)
   (flags               font-flags                :offset-assert 2880)
   (reg-save            uint32         5          :offset-assert 2884)
   )
  :method-count-assert 9
  :size-assert         #xb58
  :flag-assert         #x900000b58
  )


(define *font-work*
  (new 'static 'font-work
    :font-tmpl (new 'static 'dma-gif-packet
      :dma-vif (new 'static 'dma-packet
        :dma (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))
        :vif1 (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)
        )
      :gif0 (new 'static 'gif-tag64
        :nloop #x1
        :eop #x1
        :pre #x1
        :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :abe #x1)
        :nreg #x1
        )
      :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d))
      )
    :char-tmpl (new 'static 'dma-gif-packet
      :dma-vif (new 'static 'dma-packet
        :dma (new 'static 'dma-tag :qwc #xe :id (dma-tag-id cnt))
        :vif1 (new 'static 'vif-tag :imm #xe :cmd (vif-cmd direct) :msk #x1)
        )
      :gif0 (new 'static 'gif-tag64
        :nloop #x1
        :eop #x1
        :pre #x1
        :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :abe #x1)
        :nreg #xd
        )
      :gif1 (new 'static 'gif-tag-regs
        :regs0 (gif-reg-id a+d)
        :regs1 (gif-reg-id st)
        :regs2 (gif-reg-id rgbaq)
        :regs3 (gif-reg-id xyzf2)
        :regs4 (gif-reg-id st)
        :regs5 (gif-reg-id rgbaq)
        :regs6 (gif-reg-id xyzf2)
        :regs7 (gif-reg-id st)
        :regs8 (gif-reg-id rgbaq)
        :regs9 (gif-reg-id xyzf2)
        :regs10 (gif-reg-id st)
        :regs11 (gif-reg-id rgbaq)
        :regs12 (gif-reg-id xyzf2)
        )
      )
    :tex1-tmpl (new 'static 'array uint64 2 #x60 #x14)
    :small-font-0-tmpl (new 'static 'array uint64 2 #x0 #x6)
    :small-font-1-tmpl (new 'static 'array uint64 2 #x0 #x6)
    :small-font-2-tmpl (new 'static 'array uint64 2 #x0 #x6)
    :small-font-3-tmpl (new 'static 'array uint64 2 #x0 #x6)
    :large-font-0-tmpl (new 'static 'array uint64 2 #x0 #x6)
    :large-font-1-tmpl (new 'static 'array uint64 2 #x0 #x6)
    :large-font-2-tmpl (new 'static 'array uint64 2 #x0 #x6)
    :large-font-3-tmpl (new 'static 'array uint64 2 #x0 #x6)
    :size1-small (new 'static 'vector :x 12.0 :w 0.5)
    :size2-small (new 'static 'vector :y 14.857 :w 8.0)
    :size3-small (new 'static 'vector :x 12.0 :y 14.857 :w 14.857)
    :size1-large (new 'static 'vector :x 24.0 :w 1.0)
    :size2-large-0 (new 'static 'vector :y 29.714 :w 24.0)
    :size2-large-1 (new 'static 'vector :y 29.714 :w 24.0)
    :size2-large-2 (new 'static 'vector :y 29.714 :w 24.0)
    :size2-large-3 (new 'static 'vector :y 29.714 :w 24.0)
    :size3-large (new 'static 'vector :x 24.0 :y 29.714 :w 29.714)
    :size-st1 (new 'static 'vector :x 0.08985 :w 0.5)
    :size-st2 (new 'static 'vector :y 0.031007752 :w 0.5)
    :size-st3 (new 'static 'vector :x 0.08985 :y 0.031007752 :w 0.5)
    :current-verts (new 'static 'char-verts
      :pos (new 'static 'inline-array vector 4
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        )
      :tex-st (new 'static 'inline-array vector 4
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        )
      )
    :src-verts (new 'static 'char-verts
      :pos (new 'static 'inline-array vector 4
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        )
      :tex-st (new 'static 'inline-array vector 4
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        )
      )
    :dest-verts (new 'static 'char-verts
      :pos (new 'static 'inline-array vector 4
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        (new 'static 'vector :w 1.0)
        )
      :tex-st (new 'static 'inline-array vector 4
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        (new 'static 'vector :z 1.0)
        )
      )
    :color-shadow (new 'static 'vector4w :w #x80)
    :color-table (new 'static 'inline-array char-color 40
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x70 :g #x78 :b #x70 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x78 :b #x70 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x78 :b #x70 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x78 :b #x70 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x40)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x40)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x40)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x40)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x20 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x20 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x20 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x20 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x64 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x64 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x64 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x64 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x20 :g #x80 :b #x20 :a #x80)
                                        (new 'static 'rgba :r #x20 :g #x80 :b #x20 :a #x80)
                                        (new 'static 'rgba :r #x20 :g #x80 :b #x20 :a #x80)
                                        (new 'static 'rgba :r #x20 :g #x80 :b #x20 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :g #x20 :b #x80 :a #x80)
                                        (new 'static 'rgba :g #x20 :b #x80 :a #x80)
                                        (new 'static 'rgba :g #x20 :b #x80 :a #x80)
                                        (new 'static 'rgba :g #x20 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :g #x80 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x40 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x40 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x40 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x40 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x60 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x60 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x60 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x60 :g #x80 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x40 :g #x60 :b #x60 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x60 :b #x60 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x60 :b #x60 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x60 :b #x60 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x50 :g #x50 :b #x50 :a #x80)
                                        (new 'static 'rgba :r #x50 :g #x50 :b #x50 :a #x80)
                                        (new 'static 'rgba :r #x50 :g #x50 :b #x50 :a #x80)
                                        (new 'static 'rgba :r #x50 :g #x50 :b #x50 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x54 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x54 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x54 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x54 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x70 :g #x80 :b #x30 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x80 :b #x30 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x80 :b #x30 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x80 :b #x30 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x48 :g #x58 :b #x10 :a #x80)
                                        (new 'static 'rgba :r #x48 :g #x58 :b #x10 :a #x80)
                                        (new 'static 'rgba :r #x48 :g #x58 :b #x10 :a #x80)
                                        (new 'static 'rgba :r #x48 :g #x58 :b #x10 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x58 :g #x60 :b #x58 :a #x80)
                                        (new 'static 'rgba :r #x58 :g #x60 :b #x58 :a #x80)
                                        (new 'static 'rgba :r #x58 :g #x60 :b #x58 :a #x80)
                                        (new 'static 'rgba :r #x58 :g #x60 :b #x58 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x40 :g #x48 :b #x40 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x48 :b #x40 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x48 :b #x40 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x48 :b #x40 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x30 :g #x20 :b #x30 :a #x80)
                                        (new 'static 'rgba :r #x30 :g #x20 :b #x30 :a #x80)
                                        (new 'static 'rgba :r #x30 :g #x20 :b #x30 :a #x80)
                                        (new 'static 'rgba :r #x30 :g #x20 :b #x30 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x79 :b #x48 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x79 :b #x48 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x79 :b #x48 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x79 :b #x48 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x20 :g #x5e :b #x78 :a #x80)
                                        (new 'static 'rgba :r #x20 :g #x5e :b #x78 :a #x80)
                                        (new 'static 'rgba :r #x20 :g #x5e :b #x78 :a #x80)
                                        (new 'static 'rgba :r #x20 :g #x5e :b #x78 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x1d :g #x1d :b #x1d :a #x80)
                                        (new 'static 'rgba :r #x1d :g #x1d :b #x1d :a #x80)
                                        (new 'static 'rgba :r #x1d :g #x1d :b #x1d :a #x80)
                                        (new 'static 'rgba :r #x1d :g #x1d :b #x1d :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x40 :g #x40 :b #x40 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x40 :b #x40 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x40 :b #x40 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x40 :b #x40 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x7a :g #x4d :b #x65 :a #x80)
                                        (new 'static 'rgba :r #x7a :g #x4d :b #x65 :a #x80)
                                        (new 'static 'rgba :r #x7a :g #x4d :b #x65 :a #x80)
                                        (new 'static 'rgba :r #x7a :g #x4d :b #x65 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x7a :g #x34 :b #x34 :a #x80)
                                        (new 'static 'rgba :r #x7a :g #x34 :b #x34 :a #x80)
                                        (new 'static 'rgba :r #x7a :g #x34 :b #x34 :a #x80)
                                        (new 'static 'rgba :r #x7a :g #x34 :b #x34 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x10 :g #x65 :b #x4c :a #x80)
                                        (new 'static 'rgba :r #x10 :g #x65 :b #x4c :a #x80)
                                        (new 'static 'rgba :r #x10 :g #x65 :b #x4c :a #x80)
                                        (new 'static 'rgba :r #x10 :g #x65 :b #x4c :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x46 :g #x4a :b #x78 :a #x80)
                                        (new 'static 'rgba :r #x46 :g #x4a :b #x78 :a #x80)
                                        (new 'static 'rgba :r #x46 :g #x4a :b #x78 :a #x80)
                                        (new 'static 'rgba :r #x46 :g #x4a :b #x78 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x57 :g #x7e :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x57 :g #x7e :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x57 :g #x7e :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x57 :g #x7e :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x7f :g #x7b :b #x33 :a #x80)
                                        (new 'static 'rgba :r #x7f :g #x7b :b #x33 :a #x80)
                                        (new 'static 'rgba :r #x7f :g #x7b :b #x33 :a #x80)
                                        (new 'static 'rgba :r #x7f :g #x7b :b #x33 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x79 :g #x79 :b #x2 :a #x80)
                                        (new 'static 'rgba :r #x79 :g #x79 :b #x2 :a #x80)
                                        (new 'static 'rgba :r #x79 :g #x79 :b #x2 :a #x80)
                                        (new 'static 'rgba :r #x79 :g #x79 :b #x2 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x47 :g #x68 :b #x7a :a #x80)
                                        (new 'static 'rgba :r #x47 :g #x68 :b #x7a :a #x80)
                                        (new 'static 'rgba :r #x47 :g #x68 :b #x7a :a #x80)
                                        (new 'static 'rgba :r #x47 :g #x68 :b #x7a :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x40 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x80 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x40 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x40 :g #x80 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x20 :g #x40 :b #x40 :a #x60)
                                        (new 'static 'rgba :r #x20 :g #x40 :b #x40 :a #x60)
                                        (new 'static 'rgba :r #x20 :g #x40 :b #x40 :a #x60)
                                        (new 'static 'rgba :r #x20 :g #x40 :b #x40 :a #x60)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x70 :g #x78 :b #x70 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x78 :b #x70 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x78 :b #x70 :a #x80)
                                        (new 'static 'rgba :r #x70 :g #x78 :b #x70 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x60 :a #x80)
                                        (new 'static 'rgba :r #x60 :a #x80)
                                        (new 'static 'rgba :r #x60 :a #x80)
                                        (new 'static 'rgba :r #x60 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :r #x80 :g #x60 :b #x20 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x60 :b #x20 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x60 :b #x20 :a #x80)
                                        (new 'static 'rgba :r #x80 :g #x60 :b #x20 :a #x80)
                                        )
                               )
      (new 'static 'char-color :color (new 'static 'array rgba 4
                                        (new 'static 'rgba :b #x1 :a #x80)
                                        (new 'static 'rgba :b #x1 :a #x80)
                                        (new 'static 'rgba :b #x1 :a #x80)
                                        (new 'static 'rgba :b #x1 :a #x80)
                                        )
                               )
      )
    )
  )

(defun font-set-tex0 ((arg0 (pointer gs-tex0)) (arg1 texture) (arg2 int) (arg3 int) (arg4 int))
  "Write the TEX0 parameters for a font"
  (set! (-> arg0 0) (new 'static 'gs-tex0
                      :tcc #x1
                      :cld #x1
                      :cbp arg4
                      :th (+ (log2 (+ (-> arg1 h) -1)) 1)
                      :tw (log2 (-> arg1 w))
                      :tbw (-> arg1 width 0)
                      :tbp0 (/ arg2 64)
                      :psm arg3
                      )
        )
  (none)
  )

(defun set-font-color ((color font-color) (vert int) (rgba-red rgba) (rgba-green rgba) (rgba-blue rgba))
  (set! (-> *font-work* color-table color color (* vert 2) r) (-> rgba-red r))
  (set! (-> *font-work* color-table color color (* vert 2) g) (-> rgba-green r))
  (set! (-> *font-work* color-table color color (* vert 2) b) (-> rgba-blue r))
  ;; NOTE : this line was missing in the original code
  (set! (-> *font-work* color-table color color (1+ (* vert 2)) r) (-> rgba-red r))
  (set! (-> *font-work* color-table color color (1+ (* vert 2)) g) (-> rgba-green r))
  (set! (-> *font-work* color-table color color (1+ (* vert 2)) b) (-> rgba-blue r))
  0
  )
