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

;; definition of type display-env
(deftype display-env (structure)
  ((pmode   gs-pmode       :offset-assert   0)
   (smode2  gs-smode2      :offset-assert   8)
   (dspfb   gs-display-fb  :offset-assert  16)
   (display gs-display     :offset-assert  24)
   (bgcolor gs-bgcolor     :offset-assert  32)
   )
  :pack-me
  :method-count-assert 9
  :size-assert         #x28
  :flag-assert         #x900000028
  )

;; definition for method 3 of type display-env
(defmethod inspect display-env ((obj display-env))
  (format #t "[~8x] ~A~%" obj 'display-env)
  (format #t "~Tpmode: #x~X~%" (-> obj pmode))
  (format #t "~Tsmode2: #x~X~%" (-> obj smode2))
  (format #t "~Tdspfb: #x~X~%" (-> obj dspfb))
  (format #t "~Tdisplay: #x~X~%" (-> obj display))
  (format #t "~Tbgcolor: #x~X~%" (-> obj bgcolor))
  obj
  )

;; definition of type draw-env
(deftype draw-env (structure)
  ((frame1         gs-frame        :offset-assert   0)
   (frame1addr     gs-reg64        :offset-assert   8)
   (zbuf1          gs-zbuf         :offset-assert  16)
   (zbuf1addr      gs-reg64        :offset-assert  24)
   (xyoffset1      gs-xy-offset    :offset-assert  32)
   (xyoffset1addr  gs-reg64        :offset-assert  40)
   (scissor1       gs-scissor      :offset-assert  48)
   (scissor1addr   gs-reg64        :offset-assert  56)
   (prmodecont     gs-prmode-cont  :offset-assert  64)
   (prmodecontaddr gs-reg64        :offset-assert  72)
   (colclamp       gs-color-clamp  :offset-assert  80)
   (colclampaddr   gs-reg64        :offset-assert  88)
   (dthe           gs-dthe         :offset-assert  96)
   (dtheaddr       gs-reg64        :offset-assert 104)
   (test1          gs-test         :offset-assert 112)
   (test1addr      gs-reg64        :offset-assert 120)
   )
  :method-count-assert 9
  :size-assert         #x80
  :flag-assert         #x900000080
  )

;; definition for method 3 of type draw-env
(defmethod inspect draw-env ((obj draw-env))
  (format #t "[~8x] ~A~%" obj 'draw-env)
  (format #t "~Tframe1: #x~X~%" (-> obj frame1))
  (format #t "~Tframe1addr: #x~X~%" (-> obj frame1addr))
  (format #t "~Tzbuf1: #x~X~%" (-> obj zbuf1))
  (format #t "~Tzbuf1addr: #x~X~%" (-> obj zbuf1addr))
  (format #t "~Txyoffset1: #x~X~%" (-> obj xyoffset1))
  (format #t "~Txyoffset1addr: #x~X~%" (-> obj xyoffset1addr))
  (format #t "~Tscissor1: #x~X~%" (-> obj scissor1))
  (format #t "~Tscissor1addr: #x~X~%" (-> obj scissor1addr))
  (format #t "~Tprmodecont: #x~X~%" (-> obj prmodecont))
  (format #t "~Tprmodecontaddr: #x~X~%" (-> obj prmodecontaddr))
  (format #t "~Tcolclamp: #x~X~%" (-> obj colclamp))
  (format #t "~Tcolclampaddr: #x~X~%" (-> obj colclampaddr))
  (format #t "~Tdthe: #x~X~%" (-> obj dthe))
  (format #t "~Tdtheaddr: #x~X~%" (-> obj dtheaddr))
  (format #t "~Ttest1: #x~X~%" (-> obj test1))
  (format #t "~Ttest1addr: #x~X~%" (-> obj test1addr))
  obj
  )

;; definition for function put-draw-env
;; Used lq/sq
(defun put-draw-env ((arg0 (pointer gif-tag)))
  (dma-send (the-as dma-bank #x1000a000) (the-as uint arg0) (+ (-> arg0 0 nloop) 1))
  (none)
  )

;; definition of type display-frame
(deftype display-frame (basic)
  ((calc-buf     dma-buffer                   :offset   8)
   (vu1-buf      dma-buffer                   :offset   8)
   (debug-buf    dma-buffer                   :offset  36)
   (global-buf   dma-buffer                   :offset  40)
   (bucket-group (inline-array dma-bucket)    :offset  44)
   (buffer       dma-buffer                11 :offset   4)
   (profile-bar  profile-bar               2  :offset  48)
   (run-time     int64                        :offset  56)
   )
  :method-count-assert 9
  :size-assert         #x40
  :flag-assert         #x900000040
  (:methods
    (new (symbol type) _type_ 0)
    )
  )

;; definition for method 3 of type display-frame
(defmethod inspect display-frame ((obj display-frame))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tbuffer[11] @ #x~X~%" (-> obj buffer))
  (format #t "~Tcalc-buf: ~A~%" (-> obj calc-buf))
  (format #t "~Tvu1-buf: ~A~%" (-> obj calc-buf))
  (format #t "~Tdebug-buf: ~A~%" (-> obj debug-buf))
  (format #t "~Tglobal-buf: ~A~%" (-> obj global-buf))
  (format #t "~Tbucket-group: #<dma-bucket @ #x~X>~%" (-> obj bucket-group))
  (format #t "~Tprofile-bar[2] @ #x~X~%" (-> obj profile-bar))
  (format #t "~Trun-time: ~D~%" (-> obj run-time))
  obj
  )

;; definition for method 0 of type display-frame
(defmethod new display-frame ((allocation symbol) (type-to-make type))
  (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
    (set! (-> obj calc-buf) (the-as dma-buffer 0))
    (set! (-> obj global-buf) (the-as dma-buffer 0))
    (set! (-> obj debug-buf) (the-as dma-buffer 0))
    (when *debug-segment*
      (set! (-> obj profile-bar 0) (new 'debug 'profile-bar))
      (set! (-> obj profile-bar 1) (new 'debug 'profile-bar))
      )
    obj
    )
  )

;; definition of type virtual-frame
(deftype virtual-frame (structure)
  ((display      display-env    :offset-assert   0)
   (display-last display-env    :offset-assert   4)
   (gif          pointer        :offset-assert   8)
   (draw         draw-env       :offset-assert  12)
   (frame        display-frame  :offset-assert  16)
   )
  :allow-misaligned
  :method-count-assert 9
  :size-assert         #x14
  :flag-assert         #x900000014
  )

;; definition for method 3 of type virtual-frame
(defmethod inspect virtual-frame ((obj virtual-frame))
  (format #t "[~8x] ~A~%" obj 'virtual-frame)
  (format #t "~Tdisplay: #<display-env @ #x~X>~%" (-> obj display))
  (format #t "~Tdisplay-last: #<display-env @ #x~X>~%" (-> obj display-last))
  (format #t "~Tgif: #x~X~%" (-> obj gif))
  (format #t "~Tdraw: #<draw-env @ #x~X>~%" (-> obj draw))
  (format #t "~Tframe: ~A~%" (-> obj frame))
  obj
  )

;; definition of type display
(deftype display (basic)
  ((display-env0                    display-env   :inline   :offset-assert   8)
   (display-env1                    display-env   :inline   :offset-assert  48)
   (display-env2                    display-env   :inline   :offset-assert  88)
   (gif-tag0                        gs-gif-tag    :inline   :offset-assert 128)
   (draw0                           draw-env      :inline   :offset-assert 144)
   (gif-tag1                        gs-gif-tag    :inline   :offset-assert 272)
   (draw1                           draw-env      :inline   :offset-assert 288)
   (gif-tag2                        gs-gif-tag    :inline   :offset-assert 416)
   (draw2                           draw-env      :inline   :offset-assert 432)
   (on-screen                       int32                   :offset-assert 560)
   (last-screen                     int32                   :offset-assert 564)
   (frames                          virtual-frame 6 :inline :offset-assert 568)
   (bg-clear-color                  rgba          4         :offset-assert 760)
   (real-frame-counter              time-frame              :offset-assert 776)
   (base-frame-counter              time-frame              :offset-assert 784)
   (game-frame-counter              time-frame              :offset-assert 792)
   (integral-frame-counter          time-frame              :offset-assert 800)
   (real-integral-frame-counter     time-frame              :offset-assert 808)
   (actual-frame-counter            time-frame              :offset-assert 816)
   (real-actual-frame-counter       time-frame              :offset-assert 824)
   (part-frame-counter              time-frame              :offset-assert 832)
   (old-real-frame-counter          time-frame              :offset-assert 840)
   (old-base-frame-counter          time-frame              :offset-assert 848)
   (old-game-frame-counter          time-frame              :offset-assert 856)
   (old-integral-frame-counter      time-frame              :offset-assert 864)
   (old-real-integral-frame-counter time-frame              :offset-assert 872)
   (old-actual-frame-counter        time-frame              :offset-assert 880)
   (old-real-actual-frame-counter   time-frame              :offset-assert 888)
   (old-part-frame-counter          time-frame              :offset-assert 896)
   (time-ratio                      float                   :offset-assert 904)
   (seconds-per-frame               float                   :offset-assert 908)
   (frames-per-second               float                   :offset-assert 912)
   (time-factor                     float                   :offset-assert 916)
   (time-adjust-ratio               float                   :offset-assert 920)
   )
  :method-count-assert 10
  :size-assert         #x39c
  :flag-assert         #xa0000039c
  (:methods
    (new (symbol type int int int int int) _type_ 0)
    (set-time-ratios (_type_ float) float 9)
    )
  )

;; definition for method 3 of type display
;; Used lq/sq
(defmethod inspect display ((obj display))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tdisplay-env0: #<display-env @ #x~X>~%" (-> obj display-env0))
  (format #t "~Tdisplay-env1: #<display-env @ #x~X>~%" (-> obj display-env1))
  (format #t "~Tdisplay-env2: #<display-env @ #x~X>~%" (-> obj display-env2))
  (format #t "~Tgif-tag0: #x~X~%" (-> obj gif-tag0 qword))
  (format #t "~Tdraw0: #<draw-env @ #x~X>~%" (-> obj draw0))
  (format #t "~Tgif-tag1: #x~X~%" (-> obj gif-tag1 qword))
  (format #t "~Tdraw1: #<draw-env @ #x~X>~%" (-> obj draw1))
  (format #t "~Tgif-tag2: #x~X~%" (-> obj gif-tag2 qword))
  (format #t "~Tdraw2: #<draw-env @ #x~X>~%" (-> obj draw2))
  (format #t "~Ton-screen: ~D~%" (-> obj on-screen))
  (format #t "~Tlast-screen: ~D~%" (-> obj last-screen))
  (format #t "~Tframes[6] @ #x~X~%" (-> obj frames))
  (format #t "~Tbg-clear-color[4] @ #x~X~%" (-> obj bg-clear-color))
  (format #t "~Treal-frame-counter: ~D~%" (-> obj real-frame-counter))
  (format #t "~Tbase-frame-counter: ~D~%" (-> obj base-frame-counter))
  (format #t "~Tgame-frame-counter: ~D~%" (-> obj game-frame-counter))
  (format #t "~Tintegral-frame-counter: ~D~%" (-> obj integral-frame-counter))
  (format #t "~Treal-integral-frame-counter: ~D~%" (-> obj real-integral-frame-counter))
  (format #t "~Tactual-frame-counter: ~D~%" (-> obj actual-frame-counter))
  (format #t "~Treal-actual-frame-counter: ~D~%" (-> obj real-actual-frame-counter))
  (format #t "~Tpart-frame-counter: ~D~%" (-> obj part-frame-counter))
  (format #t "~Told-real-frame-counter: ~D~%" (-> obj old-real-frame-counter))
  (format #t "~Told-base-frame-counter: ~D~%" (-> obj old-base-frame-counter))
  (format #t "~Told-game-frame-counter: ~D~%" (-> obj old-game-frame-counter))
  (format #t "~Told-integral-frame-counter: ~D~%" (-> obj old-integral-frame-counter))
  (format #t "~Told-real-integral-frame-counter: ~D~%" (-> obj old-real-integral-frame-counter))
  (format #t "~Told-actual-frame-counter: ~D~%" (-> obj old-actual-frame-counter))
  (format #t "~Told-real-actual-frame-counter: ~D~%" (-> obj old-real-actual-frame-counter))
  (format #t "~Told-part-frame-counter: ~D~%" (-> obj old-part-frame-counter))
  (format #t "~Ttime-ratio: ~f~%" (-> obj time-ratio))
  (format #t "~Tseconds-per-frame: ~f~%" (-> obj seconds-per-frame))
  (format #t "~Tframes-per-second: ~f~%" (-> obj frames-per-second))
  (format #t "~Ttime-factor: ~f~%" (-> obj time-factor))
  (format #t "~Ttime-adjust-ratio: ~f~%" (-> obj time-adjust-ratio))
  obj
  )

;; definition for method 0 of type display
(defmethod new display ((allocation symbol) (type-to-make type) (psm int) (w int) (h int) (ztest int) (zpsm int))
  (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
    (set-display obj psm w h ztest zpsm)
    (set! (-> obj frames 0 display) (-> obj display-env0))
    (set! (-> obj frames 1 display) (-> obj display-env1))
    (set! (-> obj frames 2 display) (-> obj display-env2))
    (set! (-> obj frames 3 display) (-> obj display-env0))
    (set! (-> obj frames 4 display) (-> obj display-env1))
    (set! (-> obj frames 5 display) (-> obj display-env2))
    (set! (-> obj frames 0 display-last) (-> obj display-env2))
    (set! (-> obj frames 1 display-last) (-> obj display-env0))
    (set! (-> obj frames 2 display-last) (-> obj display-env1))
    (set! (-> obj frames 3 display-last) (-> obj display-env2))
    (set! (-> obj frames 4 display-last) (-> obj display-env0))
    (set! (-> obj frames 5 display-last) (-> obj display-env1))
    (set! (-> obj frames 0 gif) (the-as pointer (-> obj gif-tag0)))
    (set! (-> obj frames 1 gif) (the-as pointer (-> obj gif-tag1)))
    (set! (-> obj frames 2 gif) (the-as pointer (-> obj gif-tag2)))
    (set! (-> obj frames 3 gif) (the-as pointer (-> obj gif-tag0)))
    (set! (-> obj frames 4 gif) (the-as pointer (-> obj gif-tag1)))
    (set! (-> obj frames 5 gif) (the-as pointer (-> obj gif-tag2)))
    (set! (-> obj frames 0 draw) (-> obj draw0))
    (set! (-> obj frames 1 draw) (-> obj draw1))
    (set! (-> obj frames 2 draw) (-> obj draw2))
    (set! (-> obj frames 3 draw) (-> obj draw0))
    (set! (-> obj frames 4 draw) (-> obj draw1))
    (set! (-> obj frames 5 draw) (-> obj draw2))
    (set! (-> obj frames 0 frame) (new 'global 'display-frame))
    (set! (-> obj frames 1 frame) (new 'global 'display-frame))
    (set! (-> obj frames 2 frame) (-> obj frames 0 frame))
    (set! (-> obj frames 3 frame) (-> obj frames 1 frame))
    (set! (-> obj frames 4 frame) (-> obj frames 0 frame))
    (set! (-> obj frames 5 frame) (-> obj frames 1 frame))
    (default-buffer-init *default-regs-buffer*)
    (set! (-> obj bg-clear-color 0) (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80))
    (set! (-> obj bg-clear-color 1) (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80))
    (set! (-> obj bg-clear-color 2) (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80))
    (set! (-> obj bg-clear-color 3) (new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80))
    obj
    )
  )

;; definition for symbol *pre-draw-hook*, type (function object none)
(define *pre-draw-hook* (the-as (function object none) nothing))

;; definition for symbol *post-draw-hook*, type (function dma-buffer none)
(define *post-draw-hook* (the-as (function dma-buffer none) nothing))

;; failed to figure out what this is:
0
