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