aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/psxgpu/image.c
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2022-10-19 17:57:06 +0800
committerGitHub <noreply@github.com>2022-10-19 17:57:06 +0800
commite08a3d9366f8ca14a76b3dd569dac1fb9f569748 (patch)
tree33654513b0b184c27f8035dbc405640fcbeb44ab /libpsn00b/psxgpu/image.c
parentc4a2533d21dfd05cde841ea48c67b05e0e6a853f (diff)
parent9b2ffc6078a850b7d354855cca7622090b41f30c (diff)
downloadpsn00bsdk-e08a3d9366f8ca14a76b3dd569dac1fb9f569748.tar.gz
Merge pull request #59 from spicyjpeg/psxmdec
IRQ handler fix, .STR playback example, multiple library builds (v0.21)
Diffstat (limited to 'libpsn00b/psxgpu/image.c')
-rw-r--r--libpsn00b/psxgpu/image.c57
1 files changed, 39 insertions, 18 deletions
diff --git a/libpsn00b/psxgpu/image.c b/libpsn00b/psxgpu/image.c
index da51e7d..968dde5 100644
--- a/libpsn00b/psxgpu/image.c
+++ b/libpsn00b/psxgpu/image.c
@@ -4,42 +4,36 @@
*/
#include <stdint.h>
-#include <stdio.h>
+#include <psxetc.h>
#include <psxgpu.h>
#include <hwregs_c.h>
#define DMA_CHUNK_LENGTH 8
-/* VRAM transfer API */
+/* Private utilities */
-static void _load_store_image(
- uint32_t command,
- int mode,
- const RECT *rect,
- uint32_t *data
-) {
+static void _dma_transfer(const RECT *rect, uint32_t *data, int write) {
size_t length = rect->w * rect->h;
if (length % 2)
- printf("psxgpu: can't transfer an odd number of pixels\n");
+ _sdk_log("psxgpu: can't transfer an odd number of pixels\n");
length /= 2;
if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) {
- printf("psxgpu: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
+ _sdk_log("psxgpu: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
length += DMA_CHUNK_LENGTH - 1;
}
- DrawSync(0);
GPU_GP1 = 0x04000000; // Disable DMA request
GPU_GP0 = 0x01000000; // Flush cache
- GPU_GP0 = command;
+ GPU_GP0 = write ? 0xa0000000 : 0xc0000000;
//GPU_GP0 = rect->x | (rect->y << 16);
GPU_GP0 = *((const uint32_t *) &(rect->x));
//GPU_GP0 = rect->w | (rect->h << 16);
GPU_GP0 = *((const uint32_t *) &(rect->w));
// Enable DMA request, route to GP0 (2) or from GPU_READ (3)
- GPU_GP1 = 0x04000000 | mode;
+ GPU_GP1 = 0x04000002 | (write ^ 1);
DMA_MADR(2) = (uint32_t) data;
if (length < DMA_CHUNK_LENGTH)
@@ -47,15 +41,42 @@ static void _load_store_image(
else
DMA_BCR(2) = DMA_CHUNK_LENGTH | ((length / DMA_CHUNK_LENGTH) << 16);
- DMA_CHCR(2) = 0x01000200 | ((mode & 1) ^ 1);
+ DMA_CHCR(2) = 0x01000200 | write;
+}
+
+/* VRAM transfer API */
+
+int LoadImage(const RECT *rect, const uint32_t *data) {
+ return EnqueueDrawOp(
+ (void *) &_dma_transfer, (uint32_t) rect, (uint32_t) data, 1
+ );
+}
+
+int StoreImage(const RECT *rect, uint32_t *data) {
+ return EnqueueDrawOp(
+ (void *) &_dma_transfer, (uint32_t) rect, (uint32_t) data, 0
+ );
}
-void LoadImage(const RECT *rect, const uint32_t *data) {
- _load_store_image(0xa0000000, 2, rect, (uint32_t *) data);
+int MoveImage(const RECT *rect, int x, int y) {
+ return EnqueueDrawOp((void *) &MoveImage2, (uint32_t) rect, x, y);
}
-void StoreImage(const RECT *rect, uint32_t *data) {
- _load_store_image(0xc0000000, 3, rect, data);
+void LoadImage2(const RECT *rect, const uint32_t *data) {
+ _dma_transfer(rect, (uint32_t *) data, 1);
+}
+
+void StoreImage2(const RECT *rect, uint32_t *data) {
+ _dma_transfer(rect, data, 0);
+}
+
+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));
}
/* .TIM image parsers */