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 implementation. */
|
|
|
|
|
2023-07-31 01:34:02 +00:00
|
|
|
#include <core/timermanager.h>
|
2023-11-03 07:21:33 +00:00
|
|
|
#include <devices/common/hwinterrupt.h>
|
2023-04-01 15:38:11 +00:00
|
|
|
#include <devices/video/videoctrl.h>
|
|
|
|
#include <memaccess.h>
|
2021-11-09 12:40:13 +00:00
|
|
|
|
|
|
|
#include <cinttypes>
|
|
|
|
|
2021-12-07 21:47:25 +00:00
|
|
|
VideoCtrlBase::VideoCtrlBase(int width, int height)
|
2021-11-09 12:40:13 +00:00
|
|
|
{
|
2023-07-27 00:40:32 +00:00
|
|
|
EventManager::get_instance()->add_window_handler(this, &VideoCtrlBase::handle_events);
|
2023-04-01 15:38:11 +00:00
|
|
|
|
|
|
|
this->create_display_window(width, height);
|
|
|
|
}
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-04-01 15:38:11 +00:00
|
|
|
VideoCtrlBase::~VideoCtrlBase()
|
|
|
|
{
|
|
|
|
}
|
2021-11-09 12:40:13 +00:00
|
|
|
|
2023-07-27 00:40:32 +00:00
|
|
|
void VideoCtrlBase::handle_events(const WindowEvent& wnd_event) {
|
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
|
|
|
this->display.handle_events(wnd_event);
|
2023-07-27 00:40:32 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
// TODO: consider renaming, since it's not always a window
|
2023-04-01 15:38:11 +00:00
|
|
|
void VideoCtrlBase::create_display_window(int width, int height)
|
|
|
|
{
|
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
|
|
|
bool is_initialization = this->display.configure(width, height);
|
|
|
|
if (is_initialization) {
|
2023-04-01 15:38:11 +00:00
|
|
|
this->blank_on = true; // TODO: should be true!
|
|
|
|
this->blank_display();
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-04-01 15:38:11 +00:00
|
|
|
this->active_width = width;
|
|
|
|
this->active_height = height;
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-04-01 15:38:11 +00:00
|
|
|
void VideoCtrlBase::blank_display() {
|
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
|
|
|
this->display.blank();
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::update_screen()
|
|
|
|
{
|
2023-04-01 15:38:11 +00:00
|
|
|
if (this->blank_on) {
|
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
|
|
|
this->display.blank();
|
2023-04-01 15:38:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
int cursor_x = 0;
|
|
|
|
int cursor_y = 0;
|
2023-04-01 23:56:24 +00:00
|
|
|
if (this->cursor_on) {
|
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
|
|
|
this->get_cursor_position(cursor_x, cursor_y);
|
2023-04-01 23:56:24 +00:00
|
|
|
}
|
2021-11-09 12:40:13 +00:00
|
|
|
|
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
|
|
|
this->display.update(
|
|
|
|
this->convert_fb_cb,
|
|
|
|
this->cursor_on, cursor_x, cursor_y);
|
2021-11-09 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 01:34:02 +00:00
|
|
|
void VideoCtrlBase::start_refresh_task() {
|
|
|
|
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate * NS_PER_SEC + 0.5);
|
|
|
|
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
|
|
|
refresh_interval,
|
|
|
|
[this]() {
|
2023-08-01 15:37:50 +00:00
|
|
|
// assert VBL interrupt
|
|
|
|
if (this->int_ctrl)
|
|
|
|
this->int_ctrl->ack_int(this->irq_id, 1);
|
2023-07-31 01:34:02 +00:00
|
|
|
this->update_screen();
|
|
|
|
}
|
|
|
|
);
|
2023-08-01 15:37:50 +00:00
|
|
|
|
|
|
|
uint64_t vbl_duration = static_cast<uint64_t>(1.0f / ((double)(this->pixel_clock) /
|
|
|
|
hori_total / vert_blank) * NS_PER_SEC + 0.5);
|
|
|
|
this->vbl_end_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
|
|
|
refresh_interval,
|
|
|
|
refresh_interval + vbl_duration,
|
|
|
|
[this]() {
|
|
|
|
// deassert VBL interrupt
|
|
|
|
if (this->int_ctrl)
|
|
|
|
this->int_ctrl->ack_int(this->irq_id, 0);
|
|
|
|
}
|
|
|
|
);
|
2023-07-31 01:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::stop_refresh_task() {
|
|
|
|
if (this->refresh_task_id) {
|
|
|
|
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
|
|
|
}
|
2023-08-01 15:37:50 +00:00
|
|
|
if (this->vbl_end_task_id) {
|
|
|
|
TimerManager::get_instance()->cancel_timer(this->vbl_end_task_id);
|
|
|
|
}
|
2023-07-31 01:34:02 +00:00
|
|
|
}
|
|
|
|
|
2023-04-01 10:08:25 +00:00
|
|
|
void VideoCtrlBase::get_palette_colors(uint8_t index, uint8_t& r, uint8_t& g,
|
|
|
|
uint8_t& b, uint8_t& a)
|
|
|
|
{
|
|
|
|
b = this->palette[index] & 0xFFU;
|
|
|
|
g = (this->palette[index] >> 8) & 0xFFU;
|
|
|
|
r = (this->palette[index] >> 16) & 0xFFU;
|
|
|
|
a = (this->palette[index] >> 24) & 0xFFU;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoCtrlBase::set_palette_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
|
|
|
|
{
|
|
|
|
this->palette[index] = (a << 24) | (r << 16) | (g << 8) | b;
|
|
|
|
}
|
|
|
|
|
2023-04-01 23:56:24 +00:00
|
|
|
void VideoCtrlBase::setup_hw_cursor(int cursor_width, int cursor_height)
|
|
|
|
{
|
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
|
|
|
this->display.setup_hw_cursor(
|
|
|
|
[this](uint8_t *dst_buf, int dst_pitch) {
|
|
|
|
this->draw_hw_cursor(dst_buf, dst_pitch);
|
|
|
|
},
|
|
|
|
cursor_width, cursor_height);
|
2023-04-01 23:56:24 +00:00
|
|
|
this->cursor_on = true;
|
|
|
|
}
|
|
|
|
|
2021-12-07 21:47:25 +00:00
|
|
|
void VideoCtrlBase::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
|
|
|
// TODO: implement me!
|
|
|
|
}
|
|
|
|
|
2021-11-09 12:40:13 +00:00
|
|
|
void VideoCtrlBase::convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch)
|
|
|
|
{
|
2023-04-01 10:08:25 +00:00
|
|
|
uint8_t *src_buf, *src_row, *dst_row;
|
2021-11-09 12:40:13 +00:00
|
|
|
int src_pitch;
|
|
|
|
|
|
|
|
src_buf = this->fb_ptr;
|
|
|
|
src_pitch = this->fb_pitch;
|
|
|
|
|
|
|
|
for (int h = 0; h < this->active_height; h++) {
|
|
|
|
src_row = &src_buf[h * src_pitch];
|
|
|
|
dst_row = &dst_buf[h * dst_pitch];
|
|
|
|
|
|
|
|
for (int x = 0; x < this->active_width; x++) {
|
2023-04-01 10:08:25 +00:00
|
|
|
WRITE_DWORD_LE_A(dst_row, this->palette[src_row[x]]);
|
2021-11-09 12:40:13 +00:00
|
|
|
dst_row += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|