aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2022-12-28 14:27:34 +0100
committerspicyjpeg <thatspicyjpeg@gmail.com>2022-12-28 14:27:34 +0100
commit50faf92a8cb099420aa956dcac3a8105067e117c (patch)
treefa817a7419bc06aee432fa9e608b173d628c3b5d
parent7e350980d5c09bbc81a0de01bf016a87ecfc4feb (diff)
Re-enable MoveImage(), add tagless primitive structs
-rw-r--r--libpsn00b/include/psxgpu.h212
-rw-r--r--libpsn00b/psxgpu/common.c31
-rw-r--r--libpsn00b/psxgpu/env.c27
-rw-r--r--libpsn00b/psxgpu/image.c12
4 files changed, 151 insertions, 131 deletions
diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h
index 26e560f..4dbcc6c 100644
--- a/libpsn00b/include/psxgpu.h
+++ b/libpsn00b/include/psxgpu.h
@@ -101,9 +101,12 @@ typedef enum _GPU_VideoMode {
#define setlen(p, _len) (((P_TAG *) (p))->len = (uint8_t) (_len))
#define setaddr(p, _addr) (((P_TAG *) (p))->addr = (uint32_t) (_addr))
#define setcode(p, _code) (((P_TAG *) (p))->code = (uint8_t) (_code))
+#define setcode_T(p, _code) (((P_TAG_T *) (p))->code = (uint8_t) (_code))
+
#define getlen(p) (((P_TAG *) (p))->len)
#define getaddr(p) (((P_TAG *) (p))->addr)
#define getcode(p) (((P_TAG *) (p))->code)
+#define getcode_T(p) (((P_TAG_T *) (p))->code)
#define nextPrim(p) (void *) (0x80000000 | (((P_TAG *) (p))->addr))
#define isendprim(p) ((((P_TAG *) (p))->addr) == 0xffffff)
@@ -147,16 +150,41 @@ typedef enum _GPU_VideoMode {
#define setTile(p) setlen(p, 3), setcode(p, 0x60)
#define setLineF2(p) setlen(p, 3), setcode(p, 0x40)
#define setLineG2(p) setlen(p, 4), setcode(p, 0x50)
-#define setLineF3(p) setlen(p, 5), setcode(p, 0x48), \
- (p)->pad = 0x55555555
-#define setLineG3(p) setlen(p, 7), setcode(p, 0x58), \
- (p)->pad = 0x55555555, (p)->p1 = 0, (p)->p2 = 0
-#define setLineF4(p) setlen(p, 6), setcode(p, 0x4c), \
- (p)->pad = 0x55555555
-#define setLineG4(p) setlen(p, 9), setcode(p, 0x5c), \
- (p)->pad = 0x55555555, (p)->p1 = 0, (p)->p2 = 0, (p)->p3 = 0
-#define setFill(p) setlen(p, 3), setcode(p, 0x02)
-#define setVram2Vram(p) setlen(p, 8), setcode(p, 0x80), \
+#define setLineF3(p) setlen(p, 5), setcode(p, 0x48), (p)->pad = 0x55555555
+#define setLineG3(p) setlen(p, 7), setcode(p, 0x58), (p)->pad = 0x55555555, \
+ (p)->p1 = 0, (p)->p2 = 0
+#define setLineF4(p) setlen(p, 6), setcode(p, 0x4c), (p)->pad = 0x55555555
+#define setLineG4(p) setlen(p, 9), setcode(p, 0x5c), (p)->pad = 0x55555555, \
+ (p)->p1 = 0, (p)->p2 = 0, (p)->p3 = 0
+#define setFill(p) setlen(p, 3), setcode(p, 0x02)
+#define setBlit(p) setlen(p, 8), setcode(p, 0x80), \
+ (p)->pad[0] = 0, (p)->pad[1] = 0, (p)->pad[2] = 0, (p)->pad[3] = 0
+
+#define setPolyF3_T(p) setcode_T(p, 0x20)
+#define setPolyFT3_T(p) setcode_T(p, 0x24)
+#define setPolyG3_T(p) setcode_T(p, 0x30)
+#define setPolyGT3_T(p) setcode_T(p, 0x34)
+#define setPolyF4_T(p) setcode_T(p, 0x28)
+#define setPolyFT4_T(p) setcode_T(p, 0x2c)
+#define setPolyG4_T(p) setcode_T(p, 0x38)
+#define setPolyGT4_T(p) setcode_T(p, 0x3c)
+#define setSprt8_T(p) setcode_T(p, 0x74)
+#define setSprt16_T(p) setcode_T(p, 0x7c)
+#define setSprt_T(p) setcode_T(p, 0x64)
+#define setTile1_T(p) setcode_T(p, 0x68)
+#define setTile8_T(p) setcode_T(p, 0x70)
+#define setTile16_T(p) setcode_T(p, 0x78)
+#define setTile_T(p) setcode_T(p, 0x60)
+#define setLineF2_T(p) setcode_T(p, 0x40)
+#define setLineG2_T(p) setcode_T(p, 0x50)
+#define setLineF3_T(p) setcode_T(p, 0x48), (p)->pad = 0x55555555
+#define setLineG3_T(p) setcode_T(p, 0x58), (p)->pad = 0x55555555, \
+ (p)->p1 = 0, (p)->p2 = 0
+#define setLineF4_T(p) setcode_T(p, 0x4c), (p)->pad = 0x55555555
+#define setLineG4_T(p) setcode_T(p, 0x5c), (p)->pad = 0x55555555, \
+ (p)->p1 = 0, (p)->p2 = 0, (p)->p3 = 0
+#define setFill_T(p) setcode_T(p, 0x02)
+#define setBlit_T(p) setcode_T(p, 0x80), \
(p)->pad[0] = 0, (p)->pad[1] = 0, (p)->pad[2] = 0, (p)->pad[3] = 0
#define setDrawTPage(p, dfe, dtd, tpage) \
@@ -200,6 +228,11 @@ typedef enum _GPU_VideoMode {
/* Primitive structure definitions */
+typedef struct _P_TAG_T {
+ uint32_t color:24;
+ uint32_t code:8;
+} P_TAG_T;
+
typedef struct _P_TAG {
uint32_t addr:24;
uint32_t len:8;
@@ -212,25 +245,31 @@ typedef struct _P_COLOR {
uint32_t pad:8;
} P_COLOR;
-typedef struct _POLY_F3 {
- uint32_t tag;
+// These macros are used to define two variants of each primitive, a regular one
+// and a "tagless" one (_T suffix) without the OT/display list header.
+#define _DEF_PRIM(name, ...) \
+ typedef struct _##name##_T { __VA_ARGS__ } name##_T; \
+ typedef struct _##name { uint32_t tag; __VA_ARGS__ } name;
+#define _DEF_ALIAS(name, target) \
+ typedef struct _##target##_T name##_T; \
+ typedef struct _##target name;
+
+_DEF_PRIM(POLY_F3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
int16_t x2, y2;
-} POLY_F3;
+)
-typedef struct _POLY_F4 {
- uint32_t tag;
+_DEF_PRIM(POLY_F4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
int16_t x2, y2;
int16_t x3, y3;
-} POLY_F4;
+)
-typedef struct _POLY_FT3 {
- uint32_t tag;
+_DEF_PRIM(POLY_FT3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
@@ -241,10 +280,9 @@ typedef struct _POLY_FT3 {
int16_t x2, y2;
uint8_t u2, v2;
uint16_t pad;
-} POLY_FT3;
+)
-typedef struct _POLY_FT4 {
- uint32_t tag;
+_DEF_PRIM(POLY_FT4,
uint8_t r0, g0, b0, code;
uint16_t x0, y0;
uint8_t u0, v0;
@@ -258,20 +296,18 @@ typedef struct _POLY_FT4 {
int16_t x3, y3;
uint8_t u3, v3;
uint16_t pad1;
-} POLY_FT4;
+)
-typedef struct _POLY_G3 {
- uint32_t tag;
+_DEF_PRIM(POLY_G3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, pad0;
int16_t x1, y1;
uint8_t r2, g2, b2, pad1;
int16_t x2, y2;
-} POLY_G3;
+)
-typedef struct _POLY_G4 {
- uint32_t tag;
+_DEF_PRIM(POLY_G4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, pad0;
@@ -280,10 +316,9 @@ typedef struct _POLY_G4 {
int16_t x2, y2;
uint8_t r3, g3, b3, pad2;
int16_t x3, y3;
-} POLY_G4;
+)
-typedef struct _POLY_GT3 {
- uint32_t tag;
+_DEF_PRIM(POLY_GT3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
@@ -296,10 +331,9 @@ typedef struct _POLY_GT3 {
int16_t x2, y2;
uint8_t u2, v2;
uint16_t pad2;
-} POLY_GT3;
+)
-typedef struct _POLY_GT4 {
- uint32_t tag;
+_DEF_PRIM(POLY_GT4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
@@ -316,34 +350,30 @@ typedef struct _POLY_GT4 {
int16_t x3, y3;
uint8_t u3, v3;
uint16_t pad4;
-} POLY_GT4;
+)
-typedef struct _LINE_F2 {
- uint32_t tag;
+_DEF_PRIM(LINE_F2,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
-} LINE_F2;
+)
-typedef struct _LINE_G2 {
- uint32_t tag;
+_DEF_PRIM(LINE_G2,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, p1;
int16_t x1, y1;
-} LINE_G2;
+)
-typedef struct _LINE_F3 {
- uint32_t tag;
+_DEF_PRIM(LINE_F3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
int16_t x2, y2;
uint32_t pad;
-} LINE_F3;
+)
-typedef struct _LINE_G3 {
- uint32_t tag;
+_DEF_PRIM(LINE_G3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, p1;
@@ -351,20 +381,18 @@ typedef struct _LINE_G3 {
uint8_t r2, g2, b2, p2;
int16_t x2, y2;
uint32_t pad;
-} LINE_G3;
+)
-typedef struct _LINE_F4 {
- uint32_t tag;
+_DEF_PRIM(LINE_F4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
int16_t x2, y2;
int16_t x3, y3;
uint32_t pad;
-} LINE_F4;
+)
-typedef struct _LINE_G4 {
- uint32_t tag;
+_DEF_PRIM(LINE_G4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, p1;
@@ -374,88 +402,70 @@ typedef struct _LINE_G4 {
uint8_t r3, g3, b3, p3;
int16_t x3, y3;
uint32_t pad;
-} LINE_G4;
+)
-typedef struct _TILE {
- uint32_t tag;
+_DEF_PRIM(TILE,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t w, h;
-} TILE;
+)
-struct _TILE_FIXED {
- uint32_t tag;
+_DEF_PRIM(TILE_1,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
-};
-typedef struct _TILE_FIXED TILE_1;
-typedef struct _TILE_FIXED TILE_8;
-typedef struct _TILE_FIXED TILE_16;
+)
+_DEF_ALIAS(TILE_8, TILE_1)
+_DEF_ALIAS(TILE_16, TILE_1)
-typedef struct _SPRT {
- uint32_t tag;
+_DEF_PRIM(SPRT,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
uint16_t clut;
uint16_t w, h;
-} SPRT;
+)
-struct _SPRT_FIXED {
- uint32_t tag;
+_DEF_PRIM(SPRT_1,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
uint16_t clut;
-};
-typedef struct _SPRT_FIXED SPRT_8;
-typedef struct _SPRT_FIXED SPRT_16;
+)
+_DEF_ALIAS(SPRT_8, SPRT_1)
+_DEF_ALIAS(SPRT_16, SPRT_1)
-typedef struct _DR_ENV {
- uint32_t tag;
+_DEF_PRIM(DR_ENV,
uint32_t code[8];
-} DR_ENV;
-
-typedef struct _DR_AREA {
- uint32_t tag;
+)
+_DEF_PRIM(DR_AREA,
uint32_t code[2];
-} DR_AREA;
-
-typedef struct _DR_OFFSET {
- uint32_t tag;
+)
+_DEF_PRIM(DR_OFFSET,
uint32_t code[1];
-} DR_OFFSET;
-
-typedef struct _DR_TWIN {
- uint32_t tag;
+)
+_DEF_PRIM(DR_TWIN,
uint32_t code[2];
-} DR_TWIN;
-
-typedef struct _DR_TPAGE {
- uint32_t tag;
+)
+_DEF_PRIM(DR_TPAGE,
uint32_t code[1];
-} DR_TPAGE;
-
-typedef struct _DR_MASK {
- uint32_t tag;
+)
+_DEF_PRIM(DR_MASK,
uint32_t code[1];
-} DR_MASK;
+)
-typedef struct _FILL {
- uint32_t tag;
+_DEF_PRIM(FILL,
uint8_t r0, g0, b0, code;
- uint16_t x0, y0; // Note: coordinates must be in 16 pixel steps
+ uint16_t x0, y0;
uint16_t w, h;
-} FILL;
+)
-typedef struct _VRAM2VRAM {
- uint32_t tag;
+_DEF_PRIM(BLIT,
uint8_t p0, p1, p2, code;
uint16_t x0, y0;
uint16_t x1, y1;
uint16_t w, h;
uint32_t pad[4];
-} VRAM2VRAM;
+)
/* Structure definitions */
@@ -536,10 +546,10 @@ void *DrawSyncCallback(void (*func)(void));
int LoadImage(const RECT *rect, const uint32_t *data);
int StoreImage(const RECT *rect, uint32_t *data);
-//int MoveImage(const RECT *rect, int x, int y);
+int MoveImage(const RECT *rect, int x, int y);
void LoadImage2(const RECT *rect, const uint32_t *data);
void StoreImage2(const RECT *rect, uint32_t *data);
-//void MoveImage2(const RECT *rect, int x, int y);
+void MoveImage2(const RECT *rect, int x, int y);
void ClearOTagR(uint32_t *ot, size_t length);
void ClearOTag(uint32_t *ot, size_t length);
diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c
index e66e46c..8d2119b 100644
--- a/libpsn00b/psxgpu/common.c
+++ b/libpsn00b/psxgpu/common.c
@@ -46,7 +46,8 @@ static void _vblank_handler(void) {
}
static void _gpu_dma_handler(void) {
- //while (!(GPU_GP1 & (1 << 26)) || (DMA_CHCR(DMA_GPU) & (1 << 24)))
+ if (GPU_GP1 & (1 << 24))
+ GPU_GP1 = 0x02000000;
while (!(GPU_GP1 & (1 << 26)))
__asm__ volatile("");
@@ -72,6 +73,7 @@ void ResetGraph(int mode) {
if (!ResetCallback()) {
EnterCriticalSection();
InterruptCallback(IRQ_VBLANK, &_vblank_handler);
+ InterruptCallback(IRQ_GPU, &_gpu_dma_handler);
DMACallback(DMA_GPU, &_gpu_dma_handler);
_gpu_video_mode = (GPU_GP1 >> 20) & 1;
@@ -308,30 +310,3 @@ void DrawOTag2(const uint32_t *ot) {
DMA_BCR(DMA_GPU) = 0;
DMA_CHCR(DMA_GPU) = 0x01000401;
}
-
-/* Misc. functions */
-
-GPU_VideoMode GetVideoMode(void) {
- return _gpu_video_mode;
-}
-
-void SetVideoMode(GPU_VideoMode mode) {
- uint32_t _mode, stat = GPU_GP1;
-
- _gpu_video_mode = mode & 1;
-
- _mode = (mode & 1) << 3;
- _mode |= (stat >> 17) & 0x37; // GPUSTAT 17-22 -> cmd bits 0-5
- _mode |= (stat >> 10) & 0x40; // GPUSTAT bit 16 -> cmd bit 6
- _mode |= (stat >> 7) & 0x80; // GPUSTAT bit 14 -> cmd bit 7
-
- GPU_GP1 = 0x08000000 | mode;
-}
-
-int GetODE(void) {
- return (GPU_GP1 >> 31);
-}
-
-void SetDispMask(int mask) {
- GPU_GP1 = 0x03000000 | (mask ? 0 : 1);
-}
diff --git a/libpsn00b/psxgpu/env.c b/libpsn00b/psxgpu/env.c
index 8784947..96e065e 100644
--- a/libpsn00b/psxgpu/env.c
+++ b/libpsn00b/psxgpu/env.c
@@ -233,3 +233,30 @@ void PutDispEnvRaw(const DISPENV_RAW *env) {
GPU_GP1 = 0x08000000 | env->vid_mode; // Set video mode
GPU_GP1 = 0x05000000 | fb_pos; // Set VRAM location to display
}
+
+/* Misc. display functions */
+
+GPU_VideoMode GetVideoMode(void) {
+ return _gpu_video_mode;
+}
+
+void SetVideoMode(GPU_VideoMode mode) {
+ uint32_t _mode, stat = GPU_GP1;
+
+ _gpu_video_mode = mode & 1;
+
+ _mode = (mode & 1) << 3;
+ _mode |= (stat >> 17) & 0x37; // GPUSTAT bits 17-22 -> command bits 0-5
+ _mode |= (stat >> 10) & 0x40; // GPUSTAT bit 16 -> command bit 6
+ _mode |= (stat >> 7) & 0x80; // GPUSTAT bit 14 -> command bit 7
+
+ GPU_GP1 = 0x08000000 | _mode;
+}
+
+int GetODE(void) {
+ return (GPU_GP1 >> 31);
+}
+
+void SetDispMask(int mask) {
+ GPU_GP1 = 0x03000000 | (mask ? 0 : 1);
+}
diff --git a/libpsn00b/psxgpu/image.c b/libpsn00b/psxgpu/image.c
index 96f5366..09c7ab9 100644
--- a/libpsn00b/psxgpu/image.c
+++ b/libpsn00b/psxgpu/image.c
@@ -90,6 +90,10 @@ int StoreImage(const RECT *rect, uint32_t *data) {
);
}
+int MoveImage(const RECT *rect, int x, int y) {
+ return EnqueueDrawOp((void *) &MoveImage2, (uint32_t) rect, x, y);
+}
+
void LoadImage2(const RECT *rect, const uint32_t *data) {
_dma_transfer(rect, (uint32_t *) data, 1);
}
@@ -98,14 +102,18 @@ void StoreImage2(const RECT *rect, uint32_t *data) {
_dma_transfer(rect, data, 0);
}
-/*void MoveImage2(const RECT *rect, int x, int y) {
+void MoveImage2(const RECT *rect, int x, int y) {
GPU_GP0 = 0x80000000;
//GPU_GP0 = rect->x | (rect->y << 16);
GPU_GP0 = *((const uint32_t *) &(rect->x));
GPU_GP0 = (x & 0xffff) | (y << 16);
//GPU_GP0 = rect->w | (rect->h << 16);
GPU_GP0 = *((const uint32_t *) &(rect->w));
-}*/
+
+ // As no DMA transfer is performed by this command, the GPU IRQ is used
+ // instead of the DMA IRQ to trigger the draw queue callback.
+ GPU_GP0 = 0x1f000000;
+}
/* .TIM image parsers */