(require 'lua-mode)
(require 'thingatpt)
(require 'dash)
+(require 'calc-bin)
(defgroup pico8 nil
(col (current-column)))
(+ (* 128 row) (/ col 2)))))
+(defun pico8-gff-eldoc ()
+ "Show information about the flag under the point."
+ (save-excursion
+ (when (cl-oddp (current-column))
+ (backward-char))
+ (when (looking-at "..")
+ (let* ((hex (substring-no-properties (match-string 0)))
+ (int (string-to-number hex 16)))
+ (format "%08d %3d %02x"
+ (let ((calc-number-radix 2))
+ (string-to-number (math-format-radix int)))
+ int int)))))
+
+(defconst pico8-gff-font-lock-keywords
+ '(("..\n?" 0
+ (prog1 nil
+ ;; TODO: Lots of work to do here…
+ (let ((pdl (or (car (overlays-at (match-beginning 0)))
+ (make-overlay (match-beginning 0) (match-end 0)))))
+ (overlay-put pdl 'after-string " "))))))
+
+
(define-derived-mode pico8-gff-mode pico8-data-mode
'(:eval (format "Flag[%d]" (pico8-gff-lighter)))
- "Major mode for editing flags in PICO-8 cartridges.")
+ "Major mode for editing flags in PICO-8 cartridges."
+ (font-lock-add-keywords nil pico8-gff-font-lock-keywords)
+ (setq-local eldoc-documentation-function #'pico8-gff-eldoc))
(defun pico8-gff-offset-of-flag (flag)
"Calculate the offset of of flag number FLAG."
(unless (<= 0 flag 255)
(error "Valid flag numbers are 0 to 255, inclusive"))
(+ (* 2 flag) (if (> flag 128) 1 0)))
+
\f
(defface pico8-pixel
'((t (:inherit pico8-data :height 100)))