hollyhock
Loading...
Searching...
No Matches
calc.h
1#pragma once
2
3#ifdef __cplusplus
4extern "C" {
5#else
6#define constexpr
7#endif
8
9#include <stdint.h>
10
11//Graphics stuff
12
13static uint16_t * const vram = (uint16_t *)0x8c000000; //address of the vram
14static const constexpr unsigned int width = 320; //width of the screen
15static const constexpr unsigned int height = 528; //height of the screen
16
17void line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, uint16_t color);
18void vline(unsigned int x, unsigned int y1, unsigned int y2, uint16_t color);
19void triangle(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, uint16_t colorFill, uint16_t colorLine);
20void fillScreen(uint16_t color);
21
22static inline __attribute__((pure)) uint16_t constexpr color(uint8_t R, uint8_t G, uint8_t B) {
23 return (((R<<8) & 0xF800) |
24 ((G<<3) & 0x07E0) |
25 ((B>>3) & 0x001A));
26}
27
28static inline void setPixel(unsigned int x, unsigned int y, uint32_t color) {
29 if(x < width && y < height)
30 vram[width*y + x] = color;
31}
32
33//Stuff for Initialisation and stuff
34
35// they are implmented weak
36#pragma GCC diagnostic push
37#ifndef __clang__
38#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
39#endif
40__attribute__((constructor(99), used)) void calcInit(void);
41__attribute__((destructor(99), used)) void calcExit(void);
42#pragma GCC diagnostic pop
43
44//Stuff for the keyboard
45
46#ifndef __clang__
47__attribute__((access(write_only, 1), access(write_only, 2)))
48#endif
49void getKey(uint32_t *key1, uint32_t *key2);
50
51enum Keys1 {
52 KEY_SHIFT = (int)0x80000000,
53 KEY_CLEAR = 0x00020000, //The Power key
54 KEY_BACKSPACE = 0x00000080,
55 KEY_LEFT = 0x00004000,
56 KEY_RIGHT = 0x00008000,
57 KEY_Z = 0x00002000,
58 KEY_POWER = 0x00000040, //The exponent key
59 KEY_DIVIDE = 0x40000000,
60 KEY_MULTIPLY = 0x20000000,
61 KEY_SUBTRACT = 0x10000000,
62 KEY_ADD = 0x08000000,
63 KEY_EXE = 0x04000000,
64 KEY_EXP = 0x00000004,
65 KEY_3 = 0x00000008,
66 KEY_6 = 0x00000010,
67 KEY_9 = 0x00000020,
68};
69
70enum Keys2 {
71 KEY_KEYBOARD = (int)0x80000000,
72 KEY_UP = 0x00800000,
73 KEY_DOWN = 0x00400000,
74 KEY_EQUALS = 0x00000080,
75 KEY_X = 0x00000040,
76 KEY_Y = 0x40000000,
77 KEY_LEFT_BRACKET = 0x00000020,
78 KEY_RIGHT_BRACKET = 0x00000010,
79 KEY_COMMA = 0x00000008,
80 KEY_NEGATIVE = 0x00000004,
81 KEY_0 = 0x04000000,
82 KEY_DOT = 0x00040000,
83 KEY_1 = 0x08000000,
84 KEY_2 = 0x00080000,
85 KEY_4 = 0x10000000,
86 KEY_5 = 0x00100000,
87 KEY_7 = 0x20000000,
88 KEY_8 = 0x00200000,
89};
90
91#ifdef __cplusplus
92}
93
94static inline
95#ifndef __clang__
96__attribute__((access(write_only, 1), access(write_only, 2)))
97#endif
98void getKey(Keys1 *key1, Keys2 *key2) {
99 uint32_t k1, k2;
100 getKey(&k1, &k2);
101 *key1 = static_cast<Keys1>(k1);
102 *key2 = static_cast<Keys2>(k2);
103}
104
105static inline __attribute__((pure)) bool constexpr testKey(uint32_t key1, uint32_t, Keys1 key) {
106 return key1 & key;
107}
108
109static inline __attribute__((pure)) bool constexpr testKey(uint32_t, uint32_t key2, Keys2 key) {
110 return key2 & key;
111}
112#else
113#undef constexpr
114#endif