aboutsummaryrefslogtreecommitdiff
path: root/bda.h
diff options
context:
space:
mode:
Diffstat (limited to 'bda.h')
-rw-r--r--bda.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/bda.h b/bda.h
new file mode 100644
index 0000000..29b842a
--- /dev/null
+++ b/bda.h
@@ -0,0 +1,48 @@
+#ifndef BDA_H
+#define BDA_H
+
+#include "utils.h"
+
+#define BIOS_DATA_AREA_SEGMENT 0x40
+
+static inline uint32_t bda_get_dword(unsigned int offset) {
+ uint32_t __far *p = MK_FP(BIOS_DATA_AREA_SEGMENT, offset);
+ return *p;
+}
+
+static inline uint16_t bda_get_word(unsigned int offset) {
+ uint16_t __far *p = MK_FP(BIOS_DATA_AREA_SEGMENT, offset);
+ return *p;
+}
+
+static inline uint8_t bda_get_byte(unsigned int offset) {
+ uint8_t __far *p = MK_FP(BIOS_DATA_AREA_SEGMENT, offset);
+ return *p;
+}
+
+#define bda_get_ebda_segment() bda_get_word(0x0e)
+
+#define bda_get_video_mode() bda_get_byte(0x49)
+#define bda_get_num_columns() bda_get_word(0x4a)
+#define bda_get_video_page_size() bda_get_word(0x4c)
+#define bda_get_cur_video_page() bda_get_word(0x62)
+#define bda_get_last_row() bda_get_byte(0x84)
+#define bda_get_char_height() bda_get_word(0x85)
+
+#define bda_get_tick_count() bda_get_dword(0x6c)
+#define bda_get_tick_count_lo() bda_get_word(0x6c)
+
+static inline void bda_wait_tick() {
+ uint16_t cur_ticks = bda_get_tick_count_lo();
+ do {
+ pause();
+ } while (cur_ticks == bda_get_tick_count_lo());
+}
+
+static inline void bda_wait_ticks(unsigned int ticks) {
+ for (; ticks > 0; ticks--) {
+ bda_wait_tick();
+ }
+}
+
+#endif // BDA_H