#include <cstddef>
#include <string.h>
#include "device.h"
#include "MonochromeScreenPatch.h"
#include "ProgramVector.h"
#include "PatchProcessor.h"
#include "ServiceCall.h"
PatchProcessor* getInitialisingPatchProcessor();
static void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
MonochromeScreenPatch* patch = (MonochromeScreenPatch*)getInitialisingPatchProcessor()->patch;
if(patch != NULL){
MonochromeScreenBuffer screen(width, height);
screen.setBuffer(pixels);
patch->processScreen(screen);
}
}
MonochromeScreenPatch::MonochromeScreenPatch(){
void* drawArgs[] = {(void*)SYSTEM_FUNCTION_DRAW, (void*)&onDrawCallback};
getProgramVector()->serviceCall(OWL_SERVICE_REGISTER_CALLBACK, drawArgs, 2);
}
MonochromeScreenPatch::~MonochromeScreenPatch(){}
template<>
Colour MonochromeScreenBuffer::getPixel(unsigned int x, unsigned int y){
if(x >= width || y >= height)
return 0;
uint8_t ucByteOffset = 0;
uint16_t usiArrayLoc = 0;
usiArrayLoc = (y/8)+(x*8);
ucByteOffset = y-((uint8_t)(y/8)*8);
return pixels[usiArrayLoc] & (1 << ucByteOffset);
}
template<>
void MonochromeScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
if(x < width && y < height){
uint8_t ucByteOffset = 0;
uint16_t usiArrayLoc = 0;
usiArrayLoc = (y/8)+(x*8);
ucByteOffset = y-((uint8_t)(y/8)*8);
if(c == BLACK)
pixels[usiArrayLoc] &= ~(1 << ucByteOffset);
else
pixels[usiArrayLoc] |= (1 << ucByteOffset);
}
}
template<>
void MonochromeScreenBuffer::invertPixel(unsigned int x, unsigned int y){
if(x < width && y < height){
uint8_t ucByteOffset = 0;
uint16_t usiArrayLoc = 0;
usiArrayLoc = (y/8)+(x*8);
ucByteOffset = y-((uint8_t)(y/8)*8);
uint8_t pixel = (1 << ucByteOffset);
if(pixels[usiArrayLoc] & pixel)
pixels[usiArrayLoc] &= ~pixel;
else
pixels[usiArrayLoc] |= pixel;
}
}
template<>
void MonochromeScreenBuffer::fade(uint16_t steps){
}
template<>
void MonochromeScreenBuffer::fill(Colour c) {
memset(pixels, c == WHITE ? 0xff : 0x00, height*width/8);
}