hollyhock
calc.hpp
1 #pragma once
2 #include <stdint.h>
3 
4 #include <sdk/os/lcd.hpp> //needed for getVramAddress and
5 
6 
7 //Graphics stuff
8 
9 extern uint16_t *vram; //The vram pointer (this is used by routines like setPixel and has to be initialized by getVramAddress() or calc_init();
10 extern int width; //width of the screen
11 extern int height; //height of the screen
12 
13 void line(int x1, int y1, int x2, int y2, uint16_t color);
14 void triangle(int x0, int y0, int x1, int y1, int x2, int y2, uint16_t colorFill, uint16_t colorLine);
15 void fillScreen(uint16_t color);
16 
17 inline uint16_t color(uint8_t R, uint8_t G, uint8_t B){
18  return (((R<<8) & 0b1111100000000000) |
19  ((G<<3) & 0b0000011111100000) |
20  ((B>>3) & 0b0000000000011111));
21 }
22 
23 inline void setPixel(int x,int y, uint32_t color) {
24  if(x>=0 && x < width && y>=0 && y < height)
25  vram[width*y + x] = color;
26 }
27 
28 //Stuff for Initialisation and stuff
29 
30 inline void calcInit(){
31  vram = LCD_GetVRAMAddress();
32  LCD_GetSize(&width, &height);
34 }
35 inline void calcEnd(){
37  LCD_Refresh();
38 }
39 
40 //Stuff for the keyboard
41 
42 extern "C" void getKey(uint32_t *key1, uint32_t *key2);
43 
44 enum Keys1 {
45  KEY_SHIFT = 0x80000000,
46  KEY_CLEAR = 0x00020000, //The Power key
47  KEY_BACKSPACE = 0x00000080,
48  KEY_LEFT = 0x00004000,
49  KEY_RIGHT = 0x00008000,
50  KEY_Z = 0x00002000,
51  KEY_POWER = 0x00000040, //The exponent key
52  KEY_DIVIDE = 0x40000000,
53  KEY_MULTIPLY = 0x20000000,
54  KEY_SUBTRACT = 0x10000000,
55  KEY_ADD = 0x08000000,
56  KEY_EXE = 0x04000000,
57  KEY_EXP = 0x00000004,
58  KEY_3 = 0x00000008,
59  KEY_6 = 0x00000010,
60  KEY_9 = 0x00000020,
61 };
62 
63 enum Keys2 {
64  KEY_KEYBOARD = 0x80000000,
65  KEY_UP = 0x00800000,
66  KEY_DOWN = 0x00400000,
67  KEY_EQUALS = 0x00000080,
68  KEY_X = 0x00000040,
69  KEY_Y = 0x40000000,
70  KEY_LEFT_BRACKET = 0x00000020,
71  KEY_RIGHT_BRACKET = 0x00000010,
72  KEY_COMMA = 0x00000008,
73  KEY_NEGATIVE = 0x00000004,
74  KEY_0 = 0x04000000,
75  KEY_DOT = 0x00040000,
76  KEY_1 = 0x08000000,
77  KEY_2 = 0x00080000,
78  KEY_4 = 0x10000000,
79  KEY_5 = 0x00100000,
80  KEY_7 = 0x20000000,
81  KEY_8 = 0x00200000,
82 };
83 
84 inline bool testKey(uint32_t key1, uint32_t key2, Keys1 key){
85  (void) key2;
86  if (key1 & key) return true;
87  else return false;
88 }
89 
90 inline bool testKey(uint32_t key1, uint32_t key2, Keys2 key){
91  (void) key1;
92  if (key2 & key) return true;
93  else return false;
94 }
Functions for interacting with the LCD and VRAM.
void LCD_VRAMRestore()
void LCD_VRAMBackup()
uint16_t * LCD_GetVRAMAddress()
void LCD_GetSize(int *width, int *height)
void LCD_Refresh()