psxgpu: gp1.lisp

the GP1 commands (display control) as an ISA, and the GPU's reset.

0/1 a fixed bit, name a field,   a bit the decoder ignores

reset source

GP1(00h) Reset GPU

313029282726252423222120191817161514131211109876543210
000000
(defgp1 reset "..000000 ........................"
  (:doc "GP1(00h) Reset GPU")
  (gpu-reset cpu))

reset-buffer source

GP1(01h) Reset Command Buffer

313029282726252423222120191817161514131211109876543210
000001
(defgp1 reset-buffer "..000001 ........................"
  (:doc "GP1(01h) Reset Command Buffer")
  (setf (gpu-count cpu) 0 (gpu-mode cpu) 0))

ack-irq source

GP1(02h) Acknowledge GPU Interrupt (IRQ1)

313029282726252423222120191817161514131211109876543210
000010
(defgp1 ack-irq "..000010 ........................"
  (:doc "GP1(02h) Acknowledge GPU Interrupt (IRQ1)")
  (setf (gpu-irq cpu) 0))

display-enable source

GP1(03h) Display Enable: 0 on, 1 off (GPUSTAT.23)

313029282726252423222120191817161514131211109876543210
000011dmsk
(defgp1 display-enable "..000011 ....................... dmsk:1"
  (:doc "GP1(03h) Display Enable: 0 on, 1 off (GPUSTAT.23)")
  (setf (gpu-stat cpu) (logior (logand (gpu-stat cpu) #xFF7FFFFF) (ash dmsk 23))))

dma-direction source

GP1(04h) DMA Direction / Data Request (GPUSTAT.29-30)

313029282726252423222120191817161514131211109876543210
000100dmd
(defgp1 dma-direction "..000100 ...................... dmd:2"
  (:doc "GP1(04h) DMA Direction / Data Request (GPUSTAT.29-30)")
  (setf (gpu-stat cpu) (logior (logand (gpu-stat cpu) #x9FFFFFFF) (ash dmd 29))))

display-start source

GP1(05h) Start of Display area (in VRAM); a change counts as a flip

313029282726252423222120191817161514131211109876543210
000101yx
(defgp1 display-start "..000101 ..... y:9 x:10"
  (:doc "GP1(05h) Start of Display area (in VRAM); a change counts as a flip")
  (unless (and (= x (gpu-disp-x cpu)) (= y (gpu-disp-y cpu)))
    (setf (gpu-flips cpu) (wrap 64 (+ (gpu-flips cpu) 1))))
  (setf (gpu-disp-x cpu) x (gpu-disp-y cpu) y))

hrange source

GP1(06h) Horizontal Display range (on Screen), video clocks

313029282726252423222120191817161514131211109876543210
000110x2x1
(defgp1 hrange "..000110 x2:12 x1:12"
  (:doc "GP1(06h) Horizontal Display range (on Screen), video clocks")
  (setf (gpu-hr1 cpu) x1 (gpu-hr2 cpu) x2))

vrange source

GP1(07h) Vertical Display range (on Screen), scanlines

313029282726252423222120191817161514131211109876543210
000111y2y1
(defgp1 vrange "..000111 .... y2:10 y1:10"
  (:doc "GP1(07h) Vertical Display range (on Screen), scanlines")
  (setf (gpu-vr1 cpu) y1 (gpu-vr2 cpu) y2))

display-mode source

GP1(08h) Display mode: resolution, PAL, 24-bit, interlace (GPUSTAT.14, 16-22)

313029282726252423222120191817161514131211109876543210
001000revhr2irslbsnpbvdshds
(defgp1 display-mode "..001000 ................ rev:1 hr2:1 irs:1 lbs:1 npb:1 vds:1 hds:2"
  (:doc "GP1(08h) Display mode: resolution, PAL, 24-bit, interlace (GPUSTAT.14, 16-22)")
  (setf (gpu-dmode cpu) (logand insn #xFF)
        (gpu-stat cpu) (logior (logand (gpu-stat cpu) #xFF80BFFF)
                               (ash hds 17) (ash vds 19) (ash npb 20) (ash lbs 21) (ash irs 22)
                               (ash hr2 16) (ash rev 14))))

texture-disable source

GP1(09h) New Texture Disable: allows GP0(E1h).11 (not modelled further)

313029282726252423222120191817161514131211109876543210
001001allow
(defgp1 texture-disable "..001001 ....................... allow:1"
  (:doc "GP1(09h) New Texture Disable: allows GP0(E1h).11 (not modelled further)")
  nil)

info source

GP1(10h-1Fh) Read GPU internal register into GPUREAD (v2 GPU: 7 the version, 2)

313029282726252423222120191817161514131211109876543210
01
(defgp1 info "..01.... ........................"
  (:doc "GP1(10h-1Fh) Read GPU internal register into GPUREAD (v2 GPU: 7 the version, 2)")
  (case (logand insn 15)
    (2 (setf (gpu-latch cpu) (gpu-window cpu)))
    (3 (setf (gpu-latch cpu) (logior (gpu-ax1 cpu) (ash (gpu-ay1 cpu) 10))))
    (4 (setf (gpu-latch cpu) (logior (gpu-ax2 cpu) (ash (gpu-ay2 cpu) 10))))
    (5 (setf (gpu-latch cpu) (logior (wrap 11 (gs coordinates offset-x)) (ash (wrap 11 (gs coordinates offset-y)) 11))))
    (7 (setf (gpu-latch cpu) 2))
    (8 (setf (gpu-latch cpu) 0))))

Other definitions

(defisa gp1) source
(defisa gp1 :width 32 :endian :little :state gpu
  :doc "the PS1 GPU's GP1 commands, [PSXSPX] \"GPU Display Control Commands (GP1)\"")
(defmacro defgp1) source
(defmacro defgp1 (name encoding &body body)
  `(definsn gp1 ,name ,encoding
     ,@(loop for b in body while (and (consp b) (keywordp (car b))) collect b)
     (let ((gfx (gpu-gfx cpu)))
       (declare (ignorable gfx))
       ,@(loop for b on body unless (and (consp (car b)) (keywordp (caar b))) return b))))
(defun gpu-reset) source
(defun gpu-reset (gpu)
  "GP1(00h): \"GP1(01h) ;clear fifo, GP1(02h) ;ack irq (0), GP1(03h) ;display
   off (1), GP1(04h) ;dma off (0), GP1(05h) ;display address (0), GP1(06h)
   ;display x1,x2 (x1=200h, x2=200h+256*10), GP1(07h) ;display y1,y2
   (y1=010h, y2=010h+240), GP1(08h) ;display mode 320x200 NTSC (0),
   GP0(E1h..E6h) ;rendering attributes (0)\"; GPUSTAT 14802000h"
  (declare (type gpu gpu))
  (setf (gpu-count gpu) 0 (gpu-mode gpu) 0 (gpu-irq gpu) 0 (gpu-rd-n gpu) 0 (gpu-rd-i gpu) 0
        (gpu-disp-x gpu) 0 (gpu-disp-y gpu) 0
        (gpu-hr1 gpu) #x200 (gpu-hr2 gpu) (+ #x200 2560) (gpu-vr1 gpu) #x10 (gpu-vr2 gpu) (+ #x10 240)
        (gpu-dmode gpu) 0 (gpu-stat gpu) #x14802000
        (gpu-ax1 gpu) 0 (gpu-ay1 gpu) 0 (gpu-ax2 gpu) 0 (gpu-ay2 gpu) 0)
  (gpu-init-gfx gpu)
  (gp0-execute gpu #xE1000000) (gp0-execute gpu #xE2000000) (gp0-execute gpu #xE3000000)
  (gp0-execute gpu #xE4000000) (gp0-execute gpu #xE5000000) (gp0-execute gpu #xE6000000)
  ;; GP0(E1h) wrote GPUSTAT's low bits: the reset value stands
  (setf (gpu-stat gpu) #x14802000)
  nil)
(defun gp1-nop) source
(defun gp1-nop (cpu insn)
  (declare (type gpu cpu) (type u32 insn) (ignore cpu insn))
  nil)
(define-executor gp1-execute) source
(define-executor gp1-execute gp1 :illegal gp1-nop)
(defun gp1-write) source
(defun gp1-write (gpu w)
  "a word written to GP1 (1F801814h)"
  (declare (type gpu gpu) (type u32 w))
  (gp1-execute gpu w)
  nil)

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