-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathColourScreenPatch.cpp
More file actions
67 lines (56 loc) · 1.67 KB
/
ColourScreenPatch.cpp
File metadata and controls
67 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <cstddef>
#include <string.h>
#include "device.h"
#include "ColourScreenPatch.h"
#include "ProgramVector.h"
#include "PatchProcessor.h"
#include "ServiceCall.h"
PatchProcessor* getInitialisingPatchProcessor();
static void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
ColourScreenPatch* patch = (ColourScreenPatch*)getInitialisingPatchProcessor()->patch;
if(patch != NULL){
ColourScreenBuffer screen(width, height);
screen.setBuffer(pixels);
patch->processScreen(screen);
}
}
ColourScreenPatch::ColourScreenPatch(){
void* drawArgs[] = {(void*)SYSTEM_FUNCTION_DRAW, (void*)&onDrawCallback};
getProgramVector()->serviceCall(OWL_SERVICE_REGISTER_CALLBACK, drawArgs, 2);
}
ColourScreenPatch::~ColourScreenPatch(){}
uint16_t ColourScreenPatch::getScreenWidth(){
return 64;
}
uint16_t ColourScreenPatch::getScreenHeight(){
return 64;
}
template<>
Colour ColourScreenBuffer::getPixel(unsigned int x, unsigned int y){
if(x >= width || y >= height)
return 0;
return pixels[y*width+x];
}
template<>
void ColourScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
if(x < width && y < height)
pixels[y*width+x] = c;
}
template<>
void ColourScreenBuffer::invertPixel(unsigned int x, unsigned int y){
if(x < width && y < height)
pixels[y*width+x] ^= WHITE;
}
template<>
void ColourScreenBuffer::fade(uint16_t steps){
for(int i=0; i<height*width; ++i)
pixels[i] =
(((pixels[i] & RED) >> steps) & RED) |
(((pixels[i] & GREEN) >> steps) & GREEN) |
(((pixels[i] & BLUE) >> steps) & BLUE);
}
template<>
void ColourScreenBuffer::fill(Colour c) {
for(int i=0; i<height*width; ++i)
pixels[i] = c;
}