annotate vbe.h @ 0:cbded07e50d8 default tip

*: initial commit here's a simple VBE thing. It's intended to be able to work pretty much anywhere, but I don't really have anything to test VBE 1.0 with (and i'm not entirely sure if this code works in the first place) it's balls simple, no BS, and ONLY works with DJGPP.
author Paper <paper@tflc.us>
date Sat, 02 Aug 2025 12:55:21 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
1 /**
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
2 * VBE.C -- interface into VESA BIOS extensions from DJGPP-compiled
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
3 * MS-DOS programs.
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
4 *
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
5 * Copyright (c) 2025 Paper
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
6 *
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
13 *
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in all
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
15 * copies or substantial portions of the Software.
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
16 *
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
23 * SOFTWARE.
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
24 **/
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
25
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
26 #include <stdint.h>
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
27
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
28 enum {
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
29 VBE_BLIT_UNINITIALIZED = 0,
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
30 VBE_BLIT_FRAMEBUFFER,
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
31 VBE_BLIT_BANKS,
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
32 };
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
33
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
34 struct vbe {
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
35 /* ---- PUBLIC MEMBERS ---- */
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
36
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
37 uint16_t width, height, pitch;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
38 uint8_t bpp; /* BYTES per pixel */
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
39
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
40 /* (width * height * bpp) */
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
41 uint32_t size;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
42
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
43 uint8_t r_size;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
44 uint8_t r_pos;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
45 uint8_t g_size;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
46 uint8_t g_pos;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
47 uint8_t b_size;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
48 uint8_t b_pos;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
49
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
50 /* --- INTERNAL MEMBERS --- */
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
51
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
52 int blit_type;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
53 union {
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
54 struct {
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
55 uint32_t address;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
56 int selector;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
57 } fb;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
58 struct {
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
59 uint32_t size;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
60 uint32_t granularity;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
61 } banks;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
62 } blit;
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
63 };
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
64
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
65 #ifdef __GNUC__
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
66 # define VBE_INLINE static inline __attribute__((__always_inline__))
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
67 #else
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
68 # define VBE_INLINE static inline
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
69 #endif
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
70
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
71 /* VBE has a theoretical maximum resolution of 65535x65535. */
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
72 int vbe_init(struct vbe *vbe, uint16_t width, uint16_t height);
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
73 void vbe_blit(struct vbe *vbe, const void *ptr);
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
74 void vbe_quit(struct vbe *vbe);
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
75
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
76 /* this is a convenience macro for converting 8-bit RGB values into
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
77 * a full RGB value for use in a framebuffer. */
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
78 #define VBE_RGB(/* struct vbe */vbe, /*uint8_t */r, /*uint8_t */g, /*uint8_t */b) \
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
79 ( \
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
80 ((((uint32_t)(r) & 0xFF) << (vbe).r_size >> 8) << (vbe).r_pos) \
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
81 | ((((uint32_t)(g) & 0xFF) << (vbe).g_size >> 8) << (vbe).g_pos) \
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
82 | ((((uint32_t)(b) & 0xFF) << (vbe).b_size >> 8) << (vbe).b_pos) \
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
83 ) \
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
84
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
85 /* function variation of the above. */
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
86 VBE_INLINE uint32_t vbe_rgb(struct vbe *vbe, uint8_t r, uint8_t g, uint8_t b)
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
87 {
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
88 return VBE_RGB(*vbe, r, g, b);
cbded07e50d8 *: initial commit
Paper <paper@tflc.us>
parents:
diff changeset
89 }