2018-09-24 10:43:20 +02:00
|
|
|
|
|
|
|
#include "screen.h"
|
2022-07-26 19:29:41 +02:00
|
|
|
#include "logger.h"
|
|
|
|
#include <coreinit/debug.h>
|
|
|
|
#include <gx2/state.h>
|
2018-09-24 10:43:20 +02:00
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
#include <memory/mappedmemory.h>
|
|
|
|
|
2022-07-26 19:29:41 +02:00
|
|
|
Screen::Screen() : screenBuffer(nullptr) {
|
|
|
|
init();
|
|
|
|
}
|
2018-09-24 10:43:20 +02:00
|
|
|
Screen::~Screen() {
|
2022-07-26 19:29:41 +02:00
|
|
|
destroyBuffer();
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::init() {
|
2022-02-08 14:44:53 +01:00
|
|
|
OSScreenInit();
|
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
uint32_t bufferSize0 = OSScreenGetBufferSizeEx(SCREEN_TV);
|
|
|
|
uint32_t bufferSize1 = OSScreenGetBufferSizeEx(SCREEN_DRC);
|
|
|
|
screenBuffer = MEMAllocFromMappedMemoryForGX2Ex(bufferSize0 + bufferSize1, 0x100);
|
2022-07-26 19:29:41 +02:00
|
|
|
if (screenBuffer == nullptr) {
|
|
|
|
OSFatal("Failed to allocate screenbuffer");
|
|
|
|
}
|
2022-02-08 14:48:41 +01:00
|
|
|
OSScreenSetBufferEx(SCREEN_TV, screenBuffer);
|
|
|
|
OSScreenSetBufferEx(SCREEN_DRC, (char *) screenBuffer + bufferSize0);
|
|
|
|
|
|
|
|
OSScreenEnableEx(SCREEN_TV, 1);
|
|
|
|
OSScreenEnableEx(SCREEN_DRC, 1);
|
|
|
|
OSScreenClearBufferEx(SCREEN_TV, 0);
|
|
|
|
OSScreenClearBufferEx(SCREEN_DRC, 0);
|
|
|
|
OSScreenFlipBuffersEx(SCREEN_TV);
|
|
|
|
OSScreenFlipBuffersEx(SCREEN_DRC);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
void Screen::clear(OSScreenID screen, uint32_t color) {
|
2022-02-08 14:44:53 +01:00
|
|
|
OSScreenClearBufferEx(screen, color);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
void Screen::drawRect(OSScreenID screen, int x1, int y1, int x2, int y2, uint32_t color) {
|
2022-02-08 14:44:53 +01:00
|
|
|
for (int x = x1; x < x2; x++) {
|
|
|
|
OSScreenPutPixelEx(screen, x, y1, color);
|
|
|
|
OSScreenPutPixelEx(screen, x, y2, color);
|
|
|
|
}
|
|
|
|
for (int y = y1; y < y2; y++) {
|
|
|
|
OSScreenPutPixelEx(screen, x1, y, color);
|
|
|
|
OSScreenPutPixelEx(screen, x2, y, color);
|
|
|
|
}
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
void Screen::fillRect(OSScreenID screen, int x1, int y1, int x2, int y2, uint32_t color) {
|
2022-02-08 14:44:53 +01:00
|
|
|
for (int x = x1; x < x2; x++) {
|
|
|
|
for (int y = y1; y < y2; y++) {
|
|
|
|
OSScreenPutPixelEx(screen, x, y, color);
|
|
|
|
}
|
|
|
|
}
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
void Screen::drawText(OSScreenID screen, int x, int y, const char *text) {
|
2022-02-08 14:44:53 +01:00
|
|
|
OSScreenPutFontEx(screen, x, y, text);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
void Screen::flip(OSScreenID screen) {
|
2022-02-08 14:44:53 +01:00
|
|
|
OSScreenFlipBuffersEx(screen);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Screen::convx(int x) { return x * 854 / 1280; }
|
|
|
|
int Screen::convy(int y) { return y * 480 / 720; }
|
|
|
|
|
|
|
|
void Screen::clear(uint32_t color) {
|
2022-02-08 14:48:41 +01:00
|
|
|
clear(SCREEN_TV, color);
|
|
|
|
clear(SCREEN_DRC, color);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::drawRect(int x1, int y1, int x2, int y2, uint32_t color) {
|
2022-02-08 14:48:41 +01:00
|
|
|
drawRect(SCREEN_TV, x1, y1, x2, y2, color);
|
|
|
|
drawRect(SCREEN_DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::fillRect(int x1, int y1, int x2, int y2, uint32_t color) {
|
2022-02-08 14:48:41 +01:00
|
|
|
fillRect(SCREEN_TV, x1, y1, x2, y2, color);
|
|
|
|
fillRect(SCREEN_DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::drawText(int x, int y, const char *text) {
|
2022-02-08 14:48:41 +01:00
|
|
|
drawText(SCREEN_TV, x, y, text);
|
|
|
|
drawText(SCREEN_DRC, x, y, text);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::flip() {
|
2022-02-08 14:48:41 +01:00
|
|
|
flip(SCREEN_TV);
|
|
|
|
flip(SCREEN_DRC);
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
2022-07-26 19:29:41 +02:00
|
|
|
void Screen::destroyBuffer() {
|
|
|
|
if (screenBuffer) {
|
|
|
|
MEMFreeToMappedMemory(screenBuffer);
|
|
|
|
screenBuffer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GX2Init(nullptr);
|
|
|
|
}
|