64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
#ifndef VIDEO_H
|
|
#define VIDEO_H
|
|
|
|
#ifdef BUILD_SDL
|
|
#include <SDL.h>
|
|
#include <chrono>
|
|
#else
|
|
#include <cstdint>
|
|
#endif
|
|
|
|
#include "../graphics/Rect.h"
|
|
|
|
#define SCREEN_WIDTH 320
|
|
#define SCREEN_HEIGHT 200
|
|
#define MAX_UPDATE_RECT_INDEX 255
|
|
|
|
class Video {
|
|
public:
|
|
struct PaletteEntry {
|
|
uint8_t r{0}, g{0}, b{0};
|
|
};
|
|
|
|
Video();
|
|
~Video();
|
|
|
|
void Enter();
|
|
void Exit();
|
|
|
|
void SetPaletteEntry(uint8_t index, PaletteEntry entry);
|
|
PaletteEntry GetPaletteEntry(uint8_t index);
|
|
|
|
void SetPaletteEntry(uint8_t index, PaletteEntry *entry);
|
|
void GetPaletteEntry(uint8_t index, PaletteEntry *entry);
|
|
|
|
void *GetFB();
|
|
|
|
void WaitForVerticalSync();
|
|
|
|
void UpdateRect(const Rect &rect);
|
|
void Flip();
|
|
private:
|
|
uint8_t _oldMode{0};
|
|
PaletteEntry _oldPalette[256]{};
|
|
#ifdef BUILD_SDL
|
|
SDL_Window *_window;
|
|
SDL_Surface *_windowSurface;
|
|
SDL_Surface *_fb;
|
|
PaletteEntry _palette[256]{};
|
|
std::chrono::steady_clock::time_point _lastUpdate{std::chrono::steady_clock::now()};
|
|
#else
|
|
uint8_t *_fb{nullptr};
|
|
#endif
|
|
uint8_t _renderBuffer[SCREEN_WIDTH*SCREEN_HEIGHT]{};
|
|
Rect _updatedRects[MAX_UPDATE_RECT_INDEX+1];
|
|
unsigned _updateRectIndex{0};
|
|
|
|
void SetMode(uint8_t mode);
|
|
uint8_t GetMode();
|
|
};
|
|
|
|
extern Video video;
|
|
|
|
#endif
|