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

;; definition of type mc-handle
(deftype mc-handle (int32)
  ()
  :method-count-assert 9
  :size-assert         #x4
  :flag-assert         #x900000004
  )

;; definition of type mc-file-info
(deftype mc-file-info (structure)
  ((present               int32    :offset-assert   0)
   (blind-data            float 16 :offset-assert   4)
   (blind-data-int8       int8  64 :offset          4)
   (level-index           int32    :offset          4)
   (fuel-cell-count       float    :offset          8)
   (money-count           float    :offset         12)
   (buzzer-count          float    :offset         16)
   (completion-percentage float    :offset         20)
   (minute                uint8    :offset         24)
   (hour                  uint8    :offset         25)
   (week                  uint8    :offset         26)
   (day                   uint8    :offset         27)
   (month                 uint8    :offset         28)
   (year                  uint8    :offset         29)
   )
  :pack-me
  :method-count-assert 9
  :size-assert         #x44
  :flag-assert         #x900000044
  )

;; definition for method 3 of type mc-file-info
(defmethod inspect mc-file-info ((obj mc-file-info))
  (format #t "[~8x] ~A~%" obj 'mc-file-info)
  (format #t "~Tpresent: ~D~%" (-> obj present))
  (format #t "~Tblind-data[16] @ #x~X~%" (-> obj blind-data))
  (format #t "~Tblind-data-int8[64] @ #x~X~%" (-> obj blind-data))
  (format #t "~Tlevel-index: ~D~%" (-> obj level-index))
  (format #t "~Tfuel-cell-count: ~f~%" (-> obj fuel-cell-count))
  (format #t "~Tmoney-count: ~f~%" (-> obj money-count))
  (format #t "~Tbuzzer-count: ~f~%" (-> obj buzzer-count))
  (format #t "~Tcompletion-percentage: ~f~%" (-> obj completion-percentage))
  (format #t "~Tminute: #x~X~%" (-> obj minute))
  (format #t "~Thour: #x~X~%" (-> obj hour))
  (format #t "~Tweek: #x~X~%" (-> obj week))
  (format #t "~Tday: #x~X~%" (-> obj day))
  (format #t "~Tmonth: #x~X~%" (-> obj month))
  (format #t "~Tyear: #x~X~%" (-> obj year))
  obj
  )

;; definition of type mc-slot-info
(deftype mc-slot-info (structure)
  ((handle       int32                  :offset-assert   0)
   (known        int32                  :offset-assert   4)
   (formatted    int32                  :offset-assert   8)
   (inited       int32                  :offset-assert  12)
   (last-file    int32                  :offset-assert  16)
   (mem-required int32                  :offset-assert  20)
   (mem-actual   int32                  :offset-assert  24)
   (file         mc-file-info 4 :inline :offset-assert  28)
   )
  :pack-me
  :method-count-assert 9
  :size-assert         #x12c
  :flag-assert         #x90000012c
  )

;; definition for method 3 of type mc-slot-info
(defmethod inspect mc-slot-info ((obj mc-slot-info))
  (format #t "[~8x] ~A~%" obj 'mc-slot-info)
  (format #t "~Thandle: ~D~%" (-> obj handle))
  (format #t "~Tknown: ~D~%" (-> obj known))
  (format #t "~Tformatted: ~D~%" (-> obj formatted))
  (format #t "~Tinited: ~D~%" (-> obj inited))
  (format #t "~Tlast-file: ~D~%" (-> obj last-file))
  (format #t "~Tmem-required: ~D~%" (-> obj mem-required))
  (format #t "~Tmem-actual: ~D~%" (-> obj mem-actual))
  (format #t "~Tfile[4] @ #x~X~%" (-> obj file))
  obj
  )

;; definition for function mc-sync
(defun mc-sync ()
  (let ((v0-0 0))
    (while (zero? v0-0)
      (mc-run)
      (set! v0-0 (mc-check-result))
      )
    v0-0
    )
  )

;; definition for function show-mc-info
;; INFO: Return type mismatch int vs none.
(defun show-mc-info ((dma-buf dma-buffer))
  (let ((info (new 'stack-no-clear 'mc-slot-info)))
    (dotimes (slot-idx 2)
      (mc-get-slot-info slot-idx info)
      (cond
        ((zero? (-> info known))
         (format (clear *temp-string*) "SLOT ~D: EXAMINING SLOT~%" slot-idx)
         *temp-string*
         )
        ((zero? (-> info handle))
         (format (clear *temp-string*) "SLOT ~D: NO CARD~%" slot-idx)
         *temp-string*
         )
        ((zero? (-> info formatted))
         (format (clear *temp-string*) "SLOT ~D: CARD [~D] : NOT FORMATTED~%" slot-idx (-> info handle))
         *temp-string*
         )
        ((zero? (-> info inited))
         (format
           (clear *temp-string*)
           "SLOT ~D: CARD [~D] : NO FILE [~D/~D]~%"
           slot-idx
           (-> info handle)
           (-> info mem-required)
           (-> info mem-actual)
           )
         *temp-string*
         )
        (else
          (format (clear *temp-string*) "SLOT ~D: CARD [~D] : " slot-idx (-> info handle))
          *temp-string*
          (format
            *temp-string*
            "SAVES ~D ~D ~D ~D : LAST ~D~%"
            (-> info file 0 present)
            (-> info file 1 present)
            (-> info file 2 present)
            (-> info file 3 present)
            (-> info last-file)
            )
          )
        )
      (draw-string-xy *temp-string* dma-buf 32 (+ (* 12 slot-idx) 8) (font-color orange-red) (font-flags shadow))
      )
    )
  0
  (none)
  )

;; failed to figure out what this is:
0
