summaryrefslogtreecommitdiff
path: root/agbx/source/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'agbx/source/gfx')
-rw-r--r--agbx/source/gfx/clrscrn.c24
-rw-r--r--agbx/source/gfx/clrscrn.cc23
-rw-r--r--agbx/source/gfx/plot.c29
-rw-r--r--agbx/source/gfx/plottex.c36
-rw-r--r--agbx/source/gfx/plottex.cc29
-rw-r--r--agbx/source/gfx/rd.c24
-rw-r--r--agbx/source/gfx/rd.s (renamed from agbx/source/gfx/getpx.s)8
-rw-r--r--agbx/source/gfx/setpx.c31
8 files changed, 74 insertions, 130 deletions
diff --git a/agbx/source/gfx/clrscrn.c b/agbx/source/gfx/clrscrn.c
deleted file mode 100644
index cd9a7b3..0000000
--- a/agbx/source/gfx/clrscrn.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- Copyright 2022 Gabriel Jensen.
- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
- If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
-*/
-
-#include <ax/priv.h>
-
-#include <ax/gfx.h>
-
-void ax_clrscrn3(ax_i01 const _col) {
- ax_i02 const val = (ax_i02)_col | (ax_i02)_col << 0x10u;
- for (ax_i02 addr = 0x600'0000u;addr != 0x601'2C00u;addr += 0x4u) {__ax_set20(addr,val);}
-}
-
-void ax_clrscrn4(ax_i02 const _vaddr,ax_i8 const _col) {
- ax_i02 const val = (ax_i02)_col | (ax_i02)_col << 0x8u | (ax_i02)_col << 0x10u | (ax_i02)_col << 0x18u;
- for (ax_i02 addr = _vaddr;addr != _vaddr + 0x9600u;addr += 0x4u) {__ax_set20(addr,val);}
-}
-
-void ax_clrscrn5(ax_i02 const _vaddr,ax_i01 const _col) {
- ax_i02 const val = (ax_i02)_col | (ax_i02)_col << 0x10u;
- for (ax_i02 addr = _vaddr;addr != _vaddr + 0xA000u;addr += 0x4u) {__ax_set20(addr,val);}
-}
diff --git a/agbx/source/gfx/clrscrn.cc b/agbx/source/gfx/clrscrn.cc
new file mode 100644
index 0000000..8f27268
--- /dev/null
+++ b/agbx/source/gfx/clrscrn.cc
@@ -0,0 +1,23 @@
+/*
+ Copyright 2022 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+*/
+
+#include <ax/priv.h>
+
+#include <ax/gfx.h>
+
+template<typename _pxtyp> [[gnu::always_inline]] inline static auto __ax_clrscrn(::ax_i02 const _vaddr,_pxtyp const _col) noexcept -> void {
+ static_assert(::__ax_typeq<_pxtyp,::ax_i8> || ::__ax_typeq<_pxtyp,::ax_i01>);
+ ::ax_i02 const val = [&_col] {
+ if constexpr (::__ax_typeq<_pxtyp,::ax_i01>) {
+ return (ax_i02)_col | (ax_i02)_col << 0x10u;
+ }
+ return (ax_i02)_col | (ax_i02)_col << 0x8u | (ax_i02)_col << 0x10u | (ax_i02)_col << 0x18u;
+ }();
+ for (::ax_i02 addr = _vaddr;addr != _vaddr + 0x9600u;addr += 0x4u) {__ax_set20(addr,val);}
+}
+
+extern "C" auto ax_clrscrn1(::ax_i02 const _vaddr,::ax_i8 const _col) -> void {::__ax_clrscrn(_vaddr,_col);}
+extern "C" auto ax_clrscrn2(::ax_i02 const _vaddr,::ax_i01 const _col) -> void {::__ax_clrscrn(_vaddr,_col);}
diff --git a/agbx/source/gfx/plot.c b/agbx/source/gfx/plot.c
index a100208..066b97e 100644
--- a/agbx/source/gfx/plot.c
+++ b/agbx/source/gfx/plot.c
@@ -8,17 +8,24 @@
#include <ax/gfx.h>
-void ax_plot3(ax_i8 const _x,ax_i8 const _y,ax_i01 const _col) {
- ax_i01 const px = _y * 0xF0u + _x;
- __ax_setpx2(0x600'0000u,px,_col)
+void ax_plot1(ax_i02 const _vaddr,ax_i01 const _px,ax_i8 const _col) {
+ /* We can only write halfwords to VRAM, so we need to load the adjacent pixel value and combine it into a halfword. */
+ bool const odd = _px & 0x1u;
+ ax_i02 addr = _vaddr + _px - odd;
+ ax_i01 precol = __ax_get10(addr);
+ ax_i01 col = _col;
+ if (odd) {
+ precol &= 0b11111111u;
+ col <<= 0x8u;
+ }
+ else {
+ precol &= 0b1111111100000000u;
+ }
+ ax_i01 const newcol = precol | col;
+ __ax_set10(addr,newcol);
}
-void ax_plot4(ax_i02 const _vaddr,ax_i8 const _x,ax_i8 const _y,ax_i8 const _col) {
- ax_i01 const px = _y * 0xF0u + _x;
- ax_setpx1(_vaddr,px,_col);
-}
-
-void ax_plot5(ax_i02 const _vaddr,ax_i8 const _x,ax_i8 const _y,ax_i01 const _col) {
- ax_i01 const px = _y * 0xA0u + _x;
- __ax_setpx2(_vaddr,px,_col)
+void ax_plot2(ax_i02 const _vaddr,ax_i01 const _px,ax_i01 const _col) {
+ ax_i02 const addr = _vaddr + _px;
+ __ax_set10(addr,_col);
}
diff --git a/agbx/source/gfx/plottex.c b/agbx/source/gfx/plottex.c
deleted file mode 100644
index 2165c52..0000000
--- a/agbx/source/gfx/plottex.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- Copyright 2022 Gabriel Jensen.
- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
- If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
-*/
-
-#include <ax/priv.h>
-
-#include <ax/gfx.h>
-
-void ax_plottex3(ax_i01 const * const _tex,ax_i8 const _x,ax_i8 const _y,ax_i8 const _w,ax_i8 const _h) {
- ax_i01 const * texpos = _tex;
- for (ax_i8 y = _y;y != _y + _h;++y) {
- for (ax_i8 x = _x;x != _x + _w;++x) {
- ax_plot3(x,y,*(texpos++));
- }
- }
-}
-
-void ax_plottex4(ax_i02 const _vaddr,ax_i8 const * const _tex,ax_i8 const _x,ax_i8 const _y,ax_i8 const _w,ax_i8 const _h) {
- ax_i8 const * texpos = _tex;
- for (ax_i8 y = _y;y != _y + _h;++y) {
- for (ax_i8 x = _x;x != _x + _w;++x) {
- ax_plot4(_vaddr,x,y,*(texpos++));
- }
- }
-}
-
-void ax_plottex5(ax_i02 const _vaddr,ax_i01 const * const _tex,ax_i8 const _x,ax_i8 const _y,ax_i8 const _w,ax_i8 const _h) {
- ax_i01 const * texpos = _tex;
- for (ax_i8 y = _y;y != _y + _h;++y) {
- for (ax_i8 x = _x;x != _x + _w;++x) {
- ax_plot5(_vaddr,x,y,*(texpos++));
- }
- }
-}
diff --git a/agbx/source/gfx/plottex.cc b/agbx/source/gfx/plottex.cc
new file mode 100644
index 0000000..836a6ff
--- /dev/null
+++ b/agbx/source/gfx/plottex.cc
@@ -0,0 +1,29 @@
+/*
+ Copyright 2022 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+*/
+
+#include <ax/priv.h>
+
+#include <ax/gfx.h>
+
+template<typename _pxtyp> [[gnu::always_inline]] inline static auto __ax_plottex(::ax_i02 const _vaddr,::ax_i8 const _scrnw,_pxtyp const * const _tex,::ax_i01 const _px,::ax_i8 const _w,::ax_i8 const _h) noexcept -> void {
+ static_assert(::__ax_typeq<_pxtyp,::ax_i8> || ::__ax_typeq<_pxtyp,::ax_i01>);
+ _pxtyp const * texpos = _tex;
+ for (::ax_i01 px = _px;px != _px + _h * _scrnw;) {
+ ::ax_i01 const rowstart = px;
+ for (;px != rowstart + _w;++px) {
+ if constexpr (::__ax_typeq<_pxtyp,::ax_i01>) {
+ ax_plot2(_vaddr,px,*(texpos++));
+ }
+ else {
+ ax_plot1(_vaddr,px,*(texpos++));
+ }
+ }
+ px = rowstart + _scrnw;
+ }
+}
+
+extern "C" auto ax_plottex1(::ax_i02 const _vaddr,::ax_i8 const _scrnw,::ax_i8 const * const _tex,::ax_i01 const _px,::ax_i8 const _w,::ax_i8 const _h) -> void {::__ax_plottex(_vaddr,_scrnw,_tex,_px,_w,_h);}
+extern "C" auto ax_plottex2(::ax_i02 const _vaddr,::ax_i8 const _scrnw,::ax_i01 const * const _tex,::ax_i01 const _px,::ax_i8 const _w,::ax_i8 const _h) -> void {::__ax_plottex(_vaddr,_scrnw,_tex,_px,_w,_h);}
diff --git a/agbx/source/gfx/rd.c b/agbx/source/gfx/rd.c
deleted file mode 100644
index aba36b1..0000000
--- a/agbx/source/gfx/rd.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- Copyright 2022 Gabriel Jensen.
- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
- If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
-*/
-
-#include <ax/priv.h>
-
-#include <ax/gfx.h>
-
-ax_i01 ax_rd3(ax_i8 const _x,ax_i8 const _y) {
- ax_i01 const px = _y * 0xF0u + _x;
- return ax_getpx2(0x600'0000u,px);
-}
-
-ax_i8 ax_rd4(ax_i02 const _vaddr,ax_i8 const _x,ax_i8 const _y) {
- ax_i01 const px = _y * 0xF0u + _x;
- return ax_getpx1(_vaddr,px);
-}
-
-ax_i01 ax_rd5(ax_i02 const _vaddr,ax_i8 const _x,ax_i8 const _y) {
- ax_i01 const px = _y * 0xA0u + _x;
- return ax_getpx2(_vaddr,px);
-}
diff --git a/agbx/source/gfx/getpx.s b/agbx/source/gfx/rd.s
index 1db82a8..6662848 100644
--- a/agbx/source/gfx/getpx.s
+++ b/agbx/source/gfx/rd.s
@@ -7,13 +7,13 @@
.cpu arm7tdmi
.thumb
-.globl ax_getpx1
-.globl ax_getpx2
+.globl ax_rd1
+.globl ax_rd2
.func
.thumb_func
-ax_getpx1:
+ax_rd1:
adds r0,r1 @ Get the address of the pixel by adding the offset to the video address.
ldrh r0,[r0]
bx lr
@@ -23,7 +23,7 @@ ax_getpx1:
.func
.thumb_func
-ax_getpx2:
+ax_rd2:
adds r0,r1 @ Get the address of the pixel by adding the offset to the video address.
adds r0,r1 @ Add the offset twice as each pixel takes up two bytes.
ldrh r0,[r0]
diff --git a/agbx/source/gfx/setpx.c b/agbx/source/gfx/setpx.c
deleted file mode 100644
index 7110d02..0000000
--- a/agbx/source/gfx/setpx.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- Copyright 2022 Gabriel Jensen.
- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
- If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
-*/
-
-#include <ax/priv.h>
-
-#include <ax/gfx.h>
-
-void ax_setpx1(ax_i02 const _vaddr,ax_i01 const _px,ax_i8 const _col) {
- /* We can only write halfwords to VRAM, so we need to load the adjacent pixel value and combine it into a halfword. */
- bool const odd = _px & 0x1u;
- ax_i02 addr = _vaddr + _px - odd;
- ax_i01 precol = __ax_get10(addr);
- ax_i01 col = _col;
- if (odd) {
- precol &= 0b11111111u;
- col <<= 0x8u;
- }
- else {
- precol &= 0b1111111100000000u;
- }
- ax_i01 const newcol = precol | col;
- __ax_set10(addr,newcol);
-}
-
-void ax_setpx2(ax_i02 const _vaddr,ax_i01 const _px,ax_i01 const _col) {
- ax_i02 const addr = _vaddr + _px;
- __ax_set10(addr,_col);
-}