aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-08-28 15:16:12 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-08-28 15:30:25 +0100
commite35cff6d299a07d9b34f303717083a9299a37e82 (patch)
tree7204099ad4978dfc67e04bc11df29d0f366af851 /include
downloaduboxlib-dos-e35cff6d299a07d9b34f303717083a9299a37e82.tar.gz
uboxlib-dos-e35cff6d299a07d9b34f303717083a9299a37e82.zip
Initial import
Diffstat (limited to 'include')
-rw-r--r--include/ubox.h14
-rw-r--r--include/ubox_assets.h17
-rw-r--r--include/ubox_control.h15
-rw-r--r--include/ubox_debug.h12
-rw-r--r--include/ubox_joy.h10
-rw-r--r--include/ubox_keyb.h38
-rw-r--r--include/ubox_sound.h32
-rw-r--r--include/ubox_timer.h19
-rw-r--r--include/ubox_vga.h44
9 files changed, 201 insertions, 0 deletions
diff --git a/include/ubox.h b/include/ubox.h
new file mode 100644
index 0000000..cbf8d98
--- /dev/null
+++ b/include/ubox.h
@@ -0,0 +1,14 @@
+#ifndef _UBOX_H
+#define _UBOX_H
+
+#include <stdint.h>
+
+#include "ubox_vga.h"
+#include "ubox_timer.h"
+#include "ubox_keyb.h"
+#include "ubox_joy.h"
+#include "ubox_control.h"
+#include "ubox_sound.h"
+#include "ubox_assets.h"
+
+#endif /* _UBOX_H */
diff --git a/include/ubox_assets.h b/include/ubox_assets.h
new file mode 100644
index 0000000..c2dcf65
--- /dev/null
+++ b/include/ubox_assets.h
@@ -0,0 +1,17 @@
+#ifndef _UBOX_ASSETS_H
+#define _UBOX_ASSETS_H
+
+/* Simple asset manager supporting pak file (a ZIP file).
+ *
+ * 1. call ubox_assets_init using a directory name DIR
+ * If a "DIR.pak" file exists, it will be opened and any call to read will
+ * check on the pak file (unless the file exists in DIR, in which case it takes
+ * priority).
+ * 2. call ubox_assets_read to read assets; allocated memory MUST be freed with free.
+ * 3. call ubox_assets_free to discard the DIR (and pak file if exists).
+ */
+uint8_t ubox_assets_init(const char *dirname);
+uint8_t ubox_assets_read(const char *name, char **data, size_t *data_size);
+void ubox_assets_free();
+
+#endif /* _UBOX_ASSETS_H */
diff --git a/include/ubox_control.h b/include/ubox_control.h
new file mode 100644
index 0000000..47fff33
--- /dev/null
+++ b/include/ubox_control.h
@@ -0,0 +1,15 @@
+#ifndef _UBOX_CONTROL_H
+#define _UBOX_CONTROL_H
+
+#define UBOX_CTL_NONE 0
+#define UBOX_CTL_UP 1
+#define UBOX_CTL_DOWN 2
+#define UBOX_CTL_RIGHT 4
+#define UBOX_CTL_LEFT 8
+#define UBOX_CTL_FIRE1 16
+#define UBOX_CTL_FIRE2 32
+
+void ubox_control_init();
+uint8_t ubox_control_read();
+
+#endif /* _UBOX_CONTROL_H */
diff --git a/include/ubox_debug.h b/include/ubox_debug.h
new file mode 100644
index 0000000..686671e
--- /dev/null
+++ b/include/ubox_debug.h
@@ -0,0 +1,12 @@
+#ifndef _UBOX_DEBUG_H
+#define _UBOX_DEBUG_H
+
+#ifdef DEBUG
+#define UBOX_DEBUG_LOG(...) \
+ do { fprintf(stderr, "DEBUG:%s:%d: ",__FILE__, __LINE__);\
+ fprintf(stderr, __VA_ARGS__); } while (0)
+#else
+#define UBOX_DEBUG_LOG(fmt, args...) /* release */
+#endif
+
+#endif /* _UBOX_DEBUG_H */
diff --git a/include/ubox_joy.h b/include/ubox_joy.h
new file mode 100644
index 0000000..002b58e
--- /dev/null
+++ b/include/ubox_joy.h
@@ -0,0 +1,10 @@
+#ifndef _UBOX_JOY_H
+#define _UBOX_JOY_H
+
+/* it also calibrates */
+uint8_t ubox_joy_detect();
+
+/* returns the bits specified in ubox_control.h */
+uint8_t ubox_joy_read();
+
+#endif /* _UBOX_JOY_H */
diff --git a/include/ubox_keyb.h b/include/ubox_keyb.h
new file mode 100644
index 0000000..6c3a95b
--- /dev/null
+++ b/include/ubox_keyb.h
@@ -0,0 +1,38 @@
+#ifndef _UBOX_KEYB_H
+#define _UBOX_KEYB_H
+
+extern volatile uint8_t ubox_keys[0xff];
+
+void ubox_keyb_init();
+void ubox_keyb_free();
+
+#define UBOX_KEY_ESC 1
+#define UBOX_KEY_TAB 15
+#define UBOX_KEY_ENTER 28
+#define UBOX_KEY_SPACE 57
+
+#define UBOX_KEY_A 30
+#define UBOX_KEY_S 31
+#define UBOX_KEY_Z 44
+#define UBOX_KEY_X 45
+#define UBOX_KEY_P 25
+
+#define UBOX_KEY_UP 72
+#define UBOX_KEY_LEFT 75
+#define UBOX_KEY_RIGHT 77
+#define UBOX_KEY_DOWN 80
+
+#define UBOX_KEY_F1 59
+#define UBOX_KEY_F2 60
+#define UBOX_KEY_F3 61
+#define UBOX_KEY_F4 62
+#define UBOX_KEY_F5 63
+#define UBOX_KEY_F6 64
+#define UBOX_KEY_F7 65
+#define UBOX_KEY_F8 66
+#define UBOX_KEY_F9 67
+#define UBOX_KEY_F10 68
+#define UBOX_KEY_F11 87
+#define UBOX_KEY_F12 88
+
+#endif /* _UBOX_KEYB_H */
diff --git a/include/ubox_sound.h b/include/ubox_sound.h
new file mode 100644
index 0000000..d52962b
--- /dev/null
+++ b/include/ubox_sound.h
@@ -0,0 +1,32 @@
+#ifndef _UBOX_SOUND_H
+#define _UBOX_SOUND_H
+
+#ifndef UBOX_SOUND_DIVIDER
+/* ubox_sound_update will be called from the timer int, so we update every
+ * 1080ms approx by using a counter and updating 1 in 20 interrupts */
+#define UBOX_SOUND_DIVIDER 20
+#endif
+
+typedef struct
+{
+ const char *data;
+ size_t len;
+} ubox_sound_data;
+
+/* mus is expected to be a IT module, efx are samples */
+uint8_t ubox_sound_init(const ubox_sound_data *mus, const ubox_sound_data *efx, uint8_t efx_cnt);
+void ubox_sound_free();
+void ubox_sound_update();
+
+void ubox_sound_music_pattern(uint16_t pat);
+
+/* priority based efx player using order:
+ * The effects plays if nothing is playing or if the effect playing has equal
+ * or less priority.
+ */
+void ubox_sound_play_efx(uint8_t efxno);
+
+void ubox_sound_mute();
+void ubox_sound_unmute();
+
+#endif /* _UBOX_SOUND_H */
diff --git a/include/ubox_timer.h b/include/ubox_timer.h
new file mode 100644
index 0000000..e2caaaf
--- /dev/null
+++ b/include/ubox_timer.h
@@ -0,0 +1,19 @@
+#ifndef _UBOX_TIMER_H
+#define _UBOX_TIMER_H
+
+/* updates 18.2 times per second */
+extern volatile uint32_t ubox_ticks;
+
+void ubox_timer_init();
+void ubox_timer_free();
+
+/* to be called 18.2 times per second */
+void ubox_timer_user_fn(void (*fn)(void));
+
+/* countdown clock updating by seconds */
+void ubox_timer_start(uint8_t secs, volatile uint8_t *updated);
+uint8_t ubox_timer_value();
+void ubox_timer_stop();
+void ubox_timer_resume();
+
+#endif /* _UBOX_TIMER_H */
diff --git a/include/ubox_vga.h b/include/ubox_vga.h
new file mode 100644
index 0000000..7aee782
--- /dev/null
+++ b/include/ubox_vga.h
@@ -0,0 +1,44 @@
+#ifndef _UBOX_VGA_H
+#define _UBOX_VGA_H
+
+/* palette index to be used as transparent color */
+#ifndef UBOX_TRANSPARENT
+#define UBOX_TRANSPARENT 255
+#endif
+
+typedef struct {
+ uint16_t x;
+ uint16_t y;
+ uint16_t w;
+ uint16_t h;
+} ubox_rect;
+
+uint8_t ubox_open_framebuffer();
+void ubox_close_framebuffer();
+
+uint8_t ubox_set_mode(uint8_t mode);
+void ubox_wait_vsync();
+void ubox_wait_frames(uint16_t frames);
+
+/* the palette is expected to be 8 bit per color, and will be converted to VGA's 6 bit per color */
+void ubox_set_palette(const uint8_t *palette);
+
+#define TARGET_SCREEN 0
+#define TARGET_BUFFER 1
+
+void ubox_blit_target(uint8_t t);
+
+void ubox_blit(const uint8_t *sprite, const ubox_rect *dst);
+/* used for text: skip transparent, ignore 0, replace any other color by c */
+void ubox_blit_c(const uint8_t *sprite, const ubox_rect *dst, uint8_t c);
+/* in src w is sprite width, h is sprite height */
+void ubox_blitrc(const uint8_t *sprite, const ubox_rect *src, const ubox_rect *dst);
+void ubox_blit_erase(uint8_t c);
+
+/* copy from back buffer to screen */
+void ubox_blit_copy_all();
+void ubox_blit_copy(const ubox_rect *dst);
+/* only for 16 width, w is ignored */
+void ubox_blit_copy16(const ubox_rect *dst);
+
+#endif /* _UBOX_VGA_H */