gs: lmem.lisp

the GS's local memory: pages, blocks, columns, the swizzled pixel layouts.

Other definitions

(defun gs-mem-read8) source
(defun gs-mem-read8 (g a)
  (declare (type gsm g) (type (unsigned-byte 32) a))
  (ldb (byte 8 (* 8 (logand a 3))) (aref (gsm-mem g) (logand (ash a -2) #xFFFFF))))
(defun gs-mem-write8) source
(defun gs-mem-write8 (g a v)
  (declare (type gsm g) (type (unsigned-byte 32) a) (type (unsigned-byte 8) v))
  (let ((i (logand (ash a -2) #xFFFFF)))
    (setf (aref (gsm-mem g) i) (dpb v (byte 8 (* 8 (logand a 3))) (aref (gsm-mem g) i))))
  nil)
(defmacro gs-half) source
(defmacro gs-half (g h)
  `(ldb (byte 16 (* 16 (logand ,h 1))) (aref (gsm-mem ,g) (logand (ash ,h -1) #xFFFFF))))
(defmacro gs-set-half) source
(defmacro gs-set-half (g h v)
  `(let ((i (logand (ash ,h -1) #xFFFFF)))
     (setf (aref (gsm-mem ,g) i) (dpb ,v (byte 16 (* 16 (logand ,h 1))) (aref (gsm-mem ,g) i)))))
(defun gs-psm-bits) source
(defun gs-psm-bits (psm)
  "the bits a pixel of format PSM takes in a transfer: 32, 24, 16, 8 or 4"
  (declare (type (unsigned-byte 8) psm))
  (case psm
    ((#x00 #x30) 32) ((#x01 #x31) 24) ((#x02 #x0A #x32 #x3A) 16)
    ((#x13 #x1B) 8) ((#x14 #x24 #x2C) 4)
    (t 32)))
(defun gs-read-pixel) source
(defun gs-read-pixel (g psm bp bw x y)
  "the stored value of pixel (X, Y) of the buffer: its bits only (24, 16, 8, 4 of them)"
  (declare (type gsm g) (type (unsigned-byte 8) psm) (type (unsigned-byte 32) bp bw x y))
  (let ((m (gsm-mem g)))
    (case psm
      (#x00 (aref m (texfmt-gs-addr32 bp bw x y 0)))
      (#x30 (aref m (texfmt-gs-addr32 bp bw x y 1)))
      (#x01 (logand (aref m (texfmt-gs-addr32 bp bw x y 0)) #xFFFFFF))
      (#x31 (logand (aref m (texfmt-gs-addr32 bp bw x y 1)) #xFFFFFF))
      (#x02 (let ((h (texfmt-gs-addr16 bp bw x y 0 0))) (gs-half g h)))
      (#x0A (let ((h (texfmt-gs-addr16 bp bw x y 1 0))) (gs-half g h)))
      (#x32 (let ((h (texfmt-gs-addr16 bp bw x y 0 1))) (gs-half g h)))
      (#x3A (let ((h (texfmt-gs-addr16 bp bw x y 1 1))) (gs-half g h)))
      (#x13 (gs-mem-read8 g (texfmt-gs-addr8 bp bw x y)))
      (#x14 (let ((n (texfmt-gs-addr4 bp bw x y)))
              (ldb (byte 4 (* 4 (logand n 1))) (gs-mem-read8 g (ash n -1)))))
      (#x1B (ldb (byte 8 24) (aref m (texfmt-gs-addr32 bp bw x y 0))))
      (#x24 (ldb (byte 4 24) (aref m (texfmt-gs-addr32 bp bw x y 0))))
      (#x2C (ldb (byte 4 28) (aref m (texfmt-gs-addr32 bp bw x y 0))))
      (t (aref m (texfmt-gs-addr32 bp bw x y 0))))))
(defun gs-write-pixel) source
(defun gs-write-pixel (g psm bp bw x y v)
  "store V's bits as pixel (X, Y) of the buffer (the other bits of its word kept)"
  (declare (type gsm g) (type (unsigned-byte 8) psm) (type (unsigned-byte 32) bp bw x y v))
  (let ((m (gsm-mem g)))
    (case psm
      (#x00 (setf (aref m (texfmt-gs-addr32 bp bw x y 0)) v))
      (#x30 (setf (aref m (texfmt-gs-addr32 bp bw x y 1)) v))
      ((#x01 #x31)
       (let ((i (texfmt-gs-addr32 bp bw x y (if (= psm #x31) 1 0))))
         (setf (aref m i) (dpb v (byte 24 0) (aref m i)))))
      ((#x02 #x0A #x32 #x3A)
       (let ((h (texfmt-gs-addr16 bp bw x y (if (or (= psm #x0A) (= psm #x3A)) 1 0) (if (>= psm #x30) 1 0))))
         (gs-set-half g h (logand v #xFFFF))))
      (#x13 (gs-mem-write8 g (texfmt-gs-addr8 bp bw x y) (logand v #xFF)))
      (#x14 (let* ((n (texfmt-gs-addr4 bp bw x y)) (b (gs-mem-read8 g (ash n -1))))
              (gs-mem-write8 g (ash n -1) (dpb (logand v 15) (byte 4 (* 4 (logand n 1))) b))))
      (#x1B (let ((i (texfmt-gs-addr32 bp bw x y 0))) (setf (aref m i) (dpb v (byte 8 24) (aref m i)))))
      (#x24 (let ((i (texfmt-gs-addr32 bp bw x y 0))) (setf (aref m i) (dpb v (byte 4 24) (aref m i)))))
      (#x2C (let ((i (texfmt-gs-addr32 bp bw x y 0))) (setf (aref m i) (dpb v (byte 4 28) (aref m i)))))
      (t (setf (aref m (texfmt-gs-addr32 bp bw x y 0)) v))))
  nil)
(defun gs-color32) source
(defun gs-color32 (psm v)
  "a colour of format PSM (32, 24, 16 bits) as A8B8G8R8 (R in the low byte): a 16-bit
   colour's 5-bit channels shifted left 3, its A bit as #x80; 24 bits keep alpha 0"
  (declare (type (unsigned-byte 8) psm) (type (unsigned-byte 32) v))
  (case psm
    ((#x02 #x0A #x32 #x3A)
     (logior (ash (ldb (byte 5 0) v) 3) (ash (ldb (byte 5 5) v) 11) (ash (ldb (byte 5 10) v) 19)
             (if (logbitp 15 v) #x80000000 0)))
    ((#x01 #x31) (logand v #xFFFFFF))
    (t v)))

Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.