SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
Core/display.h
1 #pragma once
2
3 #include "gb.h"
4 #include <stdbool.h>
5 #include <stdint.h>
6
7 typedef struct {
8 struct GB_color_s {
9 uint8_t r, g, b;
10 } colors[5];
11 } GB_palette_t;
12
13 extern const GB_palette_t GB_PALETTE_GREY;
14 extern const GB_palette_t GB_PALETTE_DMG;
15 extern const GB_palette_t GB_PALETTE_MGB;
16 extern const GB_palette_t GB_PALETTE_GBL;
17
18 typedef enum {
19 GB_VBLANK_TYPE_NORMAL_FRAME, // An actual Vblank-triggered frame
20 GB_VBLANK_TYPE_LCD_OFF, // An artificial frame pushed while the LCD was off
21 GB_VBLANK_TYPE_ARTIFICIAL, // An artificial frame pushed for some other reason
22 GB_VBLANK_TYPE_REPEAT, // A frame that would not render on actual hardware, but the screen should retain the previous frame
23 GB_VBLANK_TYPE_SKIPPED_FRAME, // If enabled via GB_set_enable_skipped_frame_vblank_callbacks, called on skipped frames during turbo mode
24 } GB_vblank_type_t;
25
26 typedef void (*GB_vblank_callback_t)(GB_gameboy_t *gb, GB_vblank_type_t type);
27 typedef uint32_t (*GB_rgb_encode_callback_t)(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b);
28
29 typedef struct {
30 uint8_t pixel; // Color, 0-3
31 uint8_t palette; // Palette, 0 - 7 (CGB); 0-1 in DMG (or just 0 for BG)
32 uint8_t priority; // Object priority – 0 in DMG, OAM index in CGB
33 bool bg_priority; // For object FIFO – the BG priority bit. For the BG FIFO – the CGB attributes priority bit
34 } GB_fifo_item_t;
35
36 #define GB_FIFO_LENGTH 8
37 typedef struct {
38 GB_fifo_item_t fifo[GB_FIFO_LENGTH];
39 uint8_t read_end;
40 uint8_t size;
41 } GB_fifo_t;
42
43 #ifdef GB_INTERNAL
44 internal void GB_display_run(GB_gameboy_t *gb, unsigned cycles, bool force);
45 internal void GB_palette_changed(GB_gameboy_t *gb, bool background_palette, uint8_t index);
46 internal void GB_STAT_update(GB_gameboy_t *gb);
47 internal void GB_lcd_off(GB_gameboy_t *gb);
48 internal void GB_display_vblank(GB_gameboy_t *gb, GB_vblank_type_t type);
49 internal void GB_update_wx_glitch(GB_gameboy_t *gb);
50 internal void GB_update_dmg_palette(GB_gameboy_t *gb);
51 #define GB_display_sync(gb) GB_display_run(gb, 0, true)
52
53 enum {
54 GB_OBJECT_PRIORITY_X,
55 GB_OBJECT_PRIORITY_INDEX,
56 };
57 #endif
58
59 typedef enum {
60 GB_PALETTE_NONE,
61 GB_PALETTE_BACKGROUND,
62 GB_PALETTE_OAM,
63 GB_PALETTE_AUTO,
64 } GB_palette_type_t;
65
66 typedef enum {
67 GB_MAP_AUTO,
68 GB_MAP_9800,
69 GB_MAP_9C00,
70 } GB_map_type_t;
71
72 typedef enum {
73 GB_TILESET_AUTO,
74 GB_TILESET_8800,
75 GB_TILESET_8000,
76 } GB_tileset_type_t;
77
78 typedef struct {
79 uint32_t image[128];
80 uint8_t x, y, tile, flags;
81 uint16_t oam_addr;
82 bool obscured_by_line_limit;
83 } GB_oam_info_t;
84
85 typedef enum {
86 GB_COLOR_CORRECTION_DISABLED,
87 GB_COLOR_CORRECTION_CORRECT_CURVES,
88 GB_COLOR_CORRECTION_MODERN_BALANCED,
89 GB_COLOR_CORRECTION_MODERN_BOOST_CONTRAST,
90 GB_COLOR_CORRECTION_REDUCE_CONTRAST,
91 GB_COLOR_CORRECTION_LOW_CONTRAST,
92 GB_COLOR_CORRECTION_MODERN_ACCURATE,
93 } GB_color_correction_mode_t;
94
95 static const GB_color_correction_mode_t __attribute__((deprecated("Use GB_COLOR_CORRECTION_MODERN_BALANCED instead"))) GB_COLOR_CORRECTION_EMULATE_HARDWARE = GB_COLOR_CORRECTION_MODERN_BALANCED;
96 static const GB_color_correction_mode_t __attribute__((deprecated("Use GB_COLOR_CORRECTION_MODERN_BOOST_CONTRAST instead"))) GB_COLOR_CORRECTION_PRESERVE_BRIGHTNESS = GB_COLOR_CORRECTION_MODERN_BOOST_CONTRAST;
97
98 void GB_set_vblank_callback(GB_gameboy_t *gb, GB_vblank_callback_t callback);
99 void GB_set_enable_skipped_frame_vblank_callbacks(GB_gameboy_t *gb, bool enable);
100 void GB_set_rgb_encode_callback(GB_gameboy_t *gb, GB_rgb_encode_callback_t callback);
101 void GB_set_palette(GB_gameboy_t *gb, const GB_palette_t *palette);
102 const GB_palette_t *GB_get_palette(GB_gameboy_t *gb);
103 void GB_set_color_correction_mode(GB_gameboy_t *gb, GB_color_correction_mode_t mode);
104 void GB_set_light_temperature(GB_gameboy_t *gb, double temperature);
105 void GB_set_pixels_output(GB_gameboy_t *gb, uint32_t *output);
106
107 unsigned GB_get_screen_width(GB_gameboy_t *gb);
108 unsigned GB_get_screen_height(GB_gameboy_t *gb);
109 double GB_get_usual_frame_rate(GB_gameboy_t *gb);
110
111 bool GB_is_odd_frame(GB_gameboy_t *gb);
112 uint32_t GB_convert_rgb15(GB_gameboy_t *gb, uint16_t color, bool for_border);
113
114 void GB_draw_tileset(GB_gameboy_t *gb, uint32_t *dest, GB_palette_type_t palette_type, uint8_t palette_index);
115 void GB_draw_tilemap(GB_gameboy_t *gb, uint32_t *dest, GB_palette_type_t palette_type, uint8_t palette_index, GB_map_type_t map_type, GB_tileset_type_t tileset_type);
116 uint8_t GB_get_oam_info(GB_gameboy_t *gb, GB_oam_info_t *dest, uint8_t *object_height);
117
118 void GB_set_object_rendering_disabled(GB_gameboy_t *gb, bool disabled);
119 void GB_set_background_rendering_disabled(GB_gameboy_t *gb, bool disabled);
120 bool GB_is_object_rendering_disabled(GB_gameboy_t *gb);
121 bool GB_is_background_rendering_disabled(GB_gameboy_t *gb);
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.