summaryrefslogtreecommitdiff
path: root/src/gfx/ps1/src/sort.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gfx/ps1/src/sort.c')
-rw-r--r--src/gfx/ps1/src/sort.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/gfx/ps1/src/sort.c b/src/gfx/ps1/src/sort.c
new file mode 100644
index 0000000..5c1c278
--- /dev/null
+++ b/src/gfx/ps1/src/sort.c
@@ -0,0 +1,73 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <gfx/gfx.h>
+#include <gfx/private.h>
+#include <drv/ps1/bios.h>
+#include <stddef.h>
+#include <stdint.h>
+
+static union gfx_sznext *first, *last;
+
+static void add_to_list(union gfx_sznext *const p)
+{
+ if (!first)
+ first = p;
+ else if (last)
+ last->f.next = (uint32_t)p;
+
+ last = p;
+}
+
+void sprite_sort(struct gfx_sprite *const s)
+{
+ add_to_list(&s->sznext);
+}
+
+void quad_sort(struct quad *const q)
+{
+ add_to_list(&q->sznext);
+}
+
+void gfx_rect_sort(struct gfx_rect *const r)
+{
+ add_to_list(&r->sznext);
+}
+
+void stp_4line_sort(struct stp_4line *const l)
+{
+ add_to_list(&l->sznext);
+}
+
+int gfx_draw(void)
+{
+ static union gfx_sznext term = {.cmd_next = 0xffffff};
+
+ add_to_list(&term);
+
+ void gpu_ctrl(unsigned int command, unsigned int param);
+
+ gfx_swapbuffers();
+ gfx_swapheap();
+ gpu_ctrl(4, 2);
+ D2_MADR = (uint32_t)first;
+ D2_BCR = 0;
+ D2_CHCR = (1 << 0xa) | 1 | (1 << 0x18);
+ first = NULL;
+ return 0;
+}