2021-11-09 12:40:13 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-04-01 15:38:11 +00:00
|
|
|
Copyright (C) 2018-23 divingkatae and maximum
|
2021-11-09 12:40:13 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Video Conroller base class definitions. */
|
|
|
|
|
|
|
|
#ifndef VIDEO_CTRL_H
|
|
|
|
#define VIDEO_CTRL_H
|
|
|
|
|
2023-09-18 23:48:36 +00:00
|
|
|
#include <devices/common/hwinterrupt.h>
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
#include <devices/video/display.h>
|
2021-11-09 12:40:13 +00:00
|
|
|
|
|
|
|
#include <cinttypes>
|
2021-12-07 21:47:25 +00:00
|
|
|
#include <functional>
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-11-03 07:21:33 +00:00
|
|
|
class WindowEvent;
|
|
|
|
|
2021-11-09 12:40:13 +00:00
|
|
|
class VideoCtrlBase {
|
|
|
|
public:
|
2021-12-07 21:47:25 +00:00
|
|
|
VideoCtrlBase(int width = 640, int height = 480);
|
2021-11-09 12:40:13 +00:00
|
|
|
~VideoCtrlBase();
|
|
|
|
|
2023-07-27 00:40:32 +00:00
|
|
|
void handle_events(const WindowEvent& wnd_event);
|
2023-04-01 15:38:11 +00:00
|
|
|
void create_display_window(int width, int height);
|
|
|
|
void blank_display();
|
2021-11-09 12:40:13 +00:00
|
|
|
void update_screen(void);
|
|
|
|
|
2023-07-31 01:34:02 +00:00
|
|
|
void start_refresh_task();
|
|
|
|
void stop_refresh_task();
|
|
|
|
|
2024-02-18 10:20:25 +00:00
|
|
|
void get_palette_color(uint8_t index, uint8_t& r, uint8_t& g, uint8_t& b,
|
|
|
|
uint8_t& a);
|
2023-04-01 10:08:25 +00:00
|
|
|
void set_palette_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
|
|
|
|
2023-04-01 23:56:24 +00:00
|
|
|
// HW cursor support
|
|
|
|
void setup_hw_cursor(int cursor_width=64, int cur_height=64);
|
|
|
|
virtual void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {};
|
|
|
|
virtual void get_cursor_position(int& x, int& y) { x = 0; y = 0; };
|
|
|
|
|
2021-12-07 21:47:25 +00:00
|
|
|
// converters for various framebuffer pixel depths
|
2023-09-19 00:34:23 +00:00
|
|
|
virtual void convert_frame_1bpp_indexed(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
virtual void convert_frame_2bpp_indexed(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
virtual void convert_frame_4bpp_indexed(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
virtual void convert_frame_8bpp_indexed(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
#if 0
|
|
|
|
virtual void convert_frame_8bpp_32LE_indexed(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
#endif
|
2021-12-07 21:47:25 +00:00
|
|
|
virtual void convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch);
|
2023-09-19 00:34:23 +00:00
|
|
|
virtual void convert_frame_15bpp(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
virtual void convert_frame_15bpp_BE(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
virtual void convert_frame_16bpp(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
virtual void convert_frame_24bpp(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
virtual void convert_frame_32bpp(uint8_t *dst_buf, int dst_pitch);
|
|
|
|
virtual void convert_frame_32bpp_BE(uint8_t *dst_buf, int dst_pitch);
|
2021-11-09 12:40:13 +00:00
|
|
|
|
|
|
|
protected:
|
2023-04-01 15:38:11 +00:00
|
|
|
// CRT controller parameters
|
2021-11-09 12:40:13 +00:00
|
|
|
bool crtc_on = false;
|
2023-04-01 15:38:11 +00:00
|
|
|
bool blank_on = true;
|
2023-04-01 23:56:24 +00:00
|
|
|
bool cursor_on = false;
|
2024-03-20 11:38:01 +00:00
|
|
|
bool cursor_dirty = false;
|
2021-11-09 12:40:13 +00:00
|
|
|
int active_width; // width of the visible display area
|
|
|
|
int active_height; // height of the visible display area
|
2023-04-01 17:05:34 +00:00
|
|
|
int hori_total = 0;
|
|
|
|
int vert_total = 0;
|
2023-08-01 15:37:50 +00:00
|
|
|
int hori_blank = 0;
|
|
|
|
int vert_blank = 0;
|
2022-04-13 21:14:37 +00:00
|
|
|
int pixel_depth;
|
2023-09-19 03:38:28 +00:00
|
|
|
int pixel_format;
|
2021-11-09 12:40:13 +00:00
|
|
|
float pixel_clock;
|
|
|
|
float refresh_rate;
|
2024-01-26 07:41:34 +00:00
|
|
|
bool draw_fb = true;
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-04-01 10:08:25 +00:00
|
|
|
uint32_t palette[256]; // internal DAC palette in RGBA format
|
2021-11-09 12:40:13 +00:00
|
|
|
|
|
|
|
// Framebuffer parameters
|
2023-09-19 00:34:23 +00:00
|
|
|
uint8_t* fb_ptr = nullptr;
|
|
|
|
int fb_pitch = 0;
|
2023-04-01 15:38:11 +00:00
|
|
|
uint32_t refresh_task_id = 0;
|
2023-08-01 15:37:50 +00:00
|
|
|
uint32_t vbl_end_task_id = 0;
|
|
|
|
|
|
|
|
// interrupt suff
|
|
|
|
InterruptCtrl* int_ctrl = nullptr;
|
|
|
|
uint32_t irq_id = 0;
|
2023-09-18 23:48:36 +00:00
|
|
|
std::function<void(uint8_t irq_line_state)> vbl_cb = [this](uint8_t irq_line_state) {
|
|
|
|
if (this->int_ctrl)
|
|
|
|
this->int_ctrl->ack_int(this->irq_id, irq_line_state);
|
|
|
|
};
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2024-01-19 22:41:10 +00:00
|
|
|
std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb = nullptr;
|
|
|
|
std::function<void(uint8_t *dst_buf, int dst_pitch)> cursor_ovl_cb = nullptr;
|
2021-12-07 21:47:25 +00:00
|
|
|
|
2021-11-09 12:40:13 +00:00
|
|
|
private:
|
Make Emscripten build not depend on SDL2 or cubeb
While Emscripten has an SDL compabtility layer, it assumes that the
code is executing in the main browser process (and thus has access to
them DOM). The Infinite Mac project runs emulators in a worker thread
(for better performance) and has a custom API for the display, sound,
input, etc. Similarly, it does not need the cross-platform sound support
from cubeb, there there is a sound API as well.
This commit makes SDL (*_sdl.cpp) and cubeb-based (*_cubeb.cpp) code be
skipped when targeting Emscripten, and instead *_js.cpp files are used
instead (this is the cross-platform convention used by Chromium[^1], and
could be extended for other targets).
For hostevents.cpp and soundserver.cpp the entire file was replaced,
whereas for videoctrl.cpp there was enough shared logic that it was
kept, and the platform-specific bits were moved behind a Display class
that can have per-platform implementations. For cases where we need
additional private fields in the platform-specific classes, we use
a PIMPL pattern.
The *_js.cpp files with implementations are not included in this
commit, since they are closely tied to the Infinite Mac project, and
will live in its fork of DingusPPC.
[^1]: https://www.chromium.org/developers/design-documents/conventions-and-patterns-for-multi-platform-development/
2023-09-04 00:59:35 +00:00
|
|
|
Display display;
|
2021-11-09 12:40:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VIDEO_CTRL_H
|