OpenWareLaboratory
MonochromeScreenPatch.cpp
Go to the documentation of this file.
1 #include <cstddef>
2 #include <string.h>
3 #include "device.h"
5 #include "ProgramVector.h"
6 #include "PatchProcessor.h"
7 #include "ServiceCall.h"
8 
9 PatchProcessor* getInitialisingPatchProcessor();
10 
11 static void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
13  if(patch != NULL){
14  MonochromeScreenBuffer screen(width, height);
15  screen.setBuffer(pixels);
16  patch->processScreen(screen);
17  }
18 }
19 
21  void* drawArgs[] = {(void*)SYSTEM_FUNCTION_DRAW, (void*)&onDrawCallback};
22  getProgramVector()->serviceCall(OWL_SERVICE_REGISTER_CALLBACK, drawArgs, 2);
23 }
24 
26 
28  return 128;
29 }
31  return 64;
32 }
33 
34 template<>
35 Colour MonochromeScreenBuffer::getPixel(unsigned int x, unsigned int y){
36  if(x >= width || y >= height)
37  return 0;
38  uint8_t ucByteOffset = 0;
39  uint16_t usiArrayLoc = 0;
40  // Determine array location
41  usiArrayLoc = (y/8)+(x*8);
42  // Determine byte offset
43  ucByteOffset = y-((uint8_t)(y/8)*8);
44  // Return bit state from buffer
45  return pixels[usiArrayLoc] & (1 << ucByteOffset);
46  // return pixels[y*width+x];
47 }
48 
49 template<>
50 void MonochromeScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
51  if(x < width && y < height){
52  uint8_t ucByteOffset = 0;
53  uint16_t usiArrayLoc = 0;
54  // Determine array location
55  usiArrayLoc = (y/8)+(x*8);
56  // Determine byte offset
57  ucByteOffset = y-((uint8_t)(y/8)*8);
58  // Set pixel in buffer
59  if(c == BLACK)
60  pixels[usiArrayLoc] &= ~(1 << ucByteOffset);
61  else
62  pixels[usiArrayLoc] |= (1 << ucByteOffset);
63  }
64 }
65 
66 template<>
67 void MonochromeScreenBuffer::invertPixel(unsigned int x, unsigned int y){
68  if(x < width && y < height){
69  uint8_t ucByteOffset = 0;
70  uint16_t usiArrayLoc = 0;
71  // Determine array location
72  usiArrayLoc = (y/8)+(x*8);
73  // Determine byte offset
74  ucByteOffset = y-((uint8_t)(y/8)*8);
75  uint8_t pixel = (1 << ucByteOffset);
76  // Set pixel in buffer
77  if(pixels[usiArrayLoc] & pixel)
78  pixels[usiArrayLoc] &= ~pixel;
79  else
80  pixels[usiArrayLoc] |= pixel;
81  }
82 }
83 
84 template<>
85 void MonochromeScreenBuffer::fade(uint16_t steps){
86  // for(unsigned int i=0; i<height*width; ++i)
87  // pixels[i] =
88  // (((pixels[i] & RED) >> steps) & RED) |
89  // (((pixels[i] & GREEN) >> steps) & GREEN) |
90  // (((pixels[i] & BLUE) >> steps) & BLUE);
91  // todo!
92 
93  // todo: update contrast setting
94 }
95 
96 template<>
98  memset(pixels, c == WHITE ? 0xff : 0x00, height*width/8);
99  // for(unsigned int i=0; i<height*width; ++i)
100  // pixels[i] = c;
101 }
uint16_t Colour
#define BLACK
#define WHITE
static void onDrawCallback(uint8_t *pixels, uint16_t width, uint16_t height)
PatchProcessor * getInitialisingPatchProcessor()
Abstract base class for patches that use a monochrome screen.
virtual void processScreen(MonochromeScreenBuffer &screen)=0
void setPixel(unsigned int x, unsigned int y, Colour c)
Colour getPixel(unsigned int x, unsigned int y)
void invertPixel(unsigned int x, unsigned int y)
void fade(uint16_t steps)
void fill(Colour c)
void setBuffer(uint8_t *buffer)
Definition: ScreenBuffer.h:36