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