forked from Omega-Numworks/Omega-External
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmain.cpp
More file actions
209 lines (171 loc) · 4.28 KB
/
Copy pathmain.cpp
File metadata and controls
209 lines (171 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include <extapp_api.h>
#include <cstring>
#ifdef SIMULATOR
#include <FL/Fl.H>
#endif
#ifndef SIMULATOR
namespace Ion {
namespace Timing {
uint64_t millis() {
return extapp_millis();
}
}
}
extern "C" const char * mp_hal_input(const char * prompt) {
return 0;
}
#endif
extern "C" {
int ext_main();
void extapp_main(int argc, char * argv[]) {
ext_main();
}
uint64_t millis() {
return extapp_millis();
}
int os_file_browser(const char ** filenames, int maxrecords, const char * extension,int storage) {
int n = extapp_fileListWithExtension(filenames, maxrecords, extension, storage);
filenames[n] = 0;
return n;
}
bool file_exists(const char * filename) {
return extapp_fileExists(filename, EXTAPP_BOTH_FILE_SYSTEM);
}
bool erase_file(const char * filename){
return extapp_fileErase(filename, EXTAPP_RAM_FILE_SYSTEM);
}
void console_output(const char * s,int l);
const char * read_file(const char * filename){
const char * ptr = extapp_fileRead(filename, NULL, EXTAPP_RAM_FILE_SYSTEM);
if (0 && ptr && ( (unsigned char) *ptr<0x20) ) {
// extapp_fileRead in scriptstore now always skips 1st byte
// console_output("scriptstore\n",12); console_output(ptr,8);
// script from scriptstore
return ptr + 1;
}
//if (ptr){ console_output("scriptstore ",12); console_output(ptr,8); console_output("\n",1); return ptr;}
if (!ptr)
ptr=extapp_fileRead(filename, NULL, EXTAPP_FLASH_FILE_SYSTEM);
//if (ptr){ console_output("flash ",6); console_output(ptr,8); console_output("\n",1); }
return ptr;
}
bool write_file(const char * filename, const char * content, size_t len) {
if(len) {
return extapp_fileWrite(filename, content, len, EXTAPP_RAM_FILE_SYSTEM);
} else {
return extapp_fileWrite(filename, content, strlen(content) + 1, EXTAPP_RAM_FILE_SYSTEM);
}
}
int numworks_draw_string(int x, int y, int c, int bg, const char * text, bool fake) {
return extapp_drawTextLarge(text, x, y + 18, c, bg, fake);
}
int numworks_draw_string_small(int x, int y, int c, int bg, const char * text, bool fake) {
return extapp_drawTextSmall(text, x, y + 18, c, bg, fake);
}
bool waitforvblank() {
return extapp_waitForVBlank();
}
void numworks_set_pixel(int x, int y, int color) {
if (x<0 || x>=LCD_WIDTH || y<0 || y>=LCD_HEIGHT-18)
return;
extapp_pushRectUniform(x, y + 18, 1, 1, color);
}
void numworks_fill_rect(int x, int y, int w, int h, int c) {
if (x<0) {
w += x;
x=0;
}
if (y<0) {
h += y;
y=0;
}
if (h+y>=LCD_HEIGHT-18)
h=LCD_HEIGHT-18-y;
if (x+w>=LCD_WIDTH)
w=LCD_WIDTH-x;
if (h<=0 || w<=0)
return;
extapp_pushRectUniform(x, y + 18, w, h, c);
}
int numworks_get_pixel(int x, int y) {
uint16_t color;
extapp_pullRect(x, y, 1, 1, &color);
return color;
}
void numworks_wait_1ms(int ms) {
for (int i=0; i<ms/128; ++i) {
#ifdef SIMULATOR
extapp_msleep(0);
#endif
uint64_t scan = extapp_scanKeyboard();
if (scan & SCANCODE_Back) {
return;
}
extapp_msleep(128);
}
extapp_msleep(ms % 128);
}
static bool interruptible = true;
bool back_key_pressed() {
static int c = 0;
++c;
if (!interruptible || c%1024 != 0) {
return false;
} else {
#ifdef SIMULATOR
extapp_msleep(0);
#endif
return extapp_scanKeyboard() & SCANCODE_Back;
}
}
void enable_back_interrupt() {
interruptible = true;
}
void disable_back_interrupt() {
interruptible = false;
}
bool os_set_angle_unit(int mode) {
return false;
}
int os_get_angle_unit() {
return 0;
}
void numworks_hide_graph() {
}
void numworks_show_graph() {
}
void statuslinemsg(const char * msg) {
uint16_t c;
extapp_pullRect(0, 0, 1, 1, &c);
extapp_pushRectUniform(0, 0, 280, 18, c);
if(strlen(msg) > 25) {
extapp_drawTextSmall(msg, 0, 0, 65535, c, false);
} else {
extapp_drawTextLarge(msg, 0, 0, 65535, c, false);
}
}
void statusline(int mode, size_t heap) {
}
void lock_alpha() {
extapp_lockAlpha();
}
void reset_kbd() {
extapp_resetKeyboard();
}
static bool alphawasactive_ = false;
bool alphawasactive () {
return alphawasactive_;
}
int getkey(int allow_suspend) {
return extapp_getKey(allow_suspend, &alphawasactive_);
}
bool iskeydown(int key) {
return extapp_isKeydown(key);
}
void GetKey(int * key) {
*key = getkey(true);
}
bool inexammode(){
return extapp_inExamMode();
}
} // end extern "C"