this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Baremetal Pi fix (#2763)

* Remove fopen/fclose reference from bytebattle part to fix baremetal pi boot (avoid 4-colour screen)

* Add support for isdir, deldir and delfile in baremetal pi

* Skip tic80.com folder in baremetal pi as there is no network

* Hide .local folder in baremetal pi

* Hide pixel cursor in baremetal pi, as a cursor is already rendered by tic80

* Fix potential buffer overflow in baremetal pi

* Remove unused code

* Add support for USB storage, using SD card as fallback, in baremetal pi

* Add baremetal pi support for ES locale while keeping US as default

* Use mouse raw mode instead of cooked mode to fix missing button-up events in baremetal pi

authored by

josei and committed by
GitHub
123ce61c 286e9c53

+81 -114
+4
build/baremetalpi/toolchain.cmake
··· 51 51 52 52 set(BAREMETALPI TRUE) 53 53 54 + if(NOT DEFINED KEYBOARD_LAYOUT) 55 + set(KEYBOARD_LAYOUT "US" CACHE STRING "Keyboard layout (US, ES, IT, etc.)") 56 + endif() 57 + add_compile_definitions(KEYBOARD_LAYOUT_${KEYBOARD_LAYOUT})
+17 -11
src/studio/fs.c
··· 398 398 399 399 void tic_fs_enum(tic_fs* fs, fs_list_callback onItem, fs_done_callback onDone, void* data) 400 400 { 401 + #ifndef BAREMETALPI 401 402 if (isRoot(fs) && !onItem(PublicDir, NULL, NULL, 0, data, true)) 402 403 { 403 404 onDone(data); ··· 417 418 } 418 419 #endif 419 420 421 + #endif 422 + 420 423 const char* path = tic_fs_path(fs, ""); 421 424 422 425 fs_enum(path, onItem, data); ··· 427 430 bool tic_fs_deldir(tic_fs* fs, const char* name) 428 431 { 429 432 #if defined(BAREMETALPI) 430 - // TODO BAREMETALPI 431 - dbg("tic_fs_deldir %s", name); 432 - return 0; 433 + const char* path = tic_fs_path(fs, name); 434 + const FsString* pathString = utf8ToString(path); 435 + bool result = (f_unlink(pathString) != FR_OK); 436 + freeString(pathString); 437 + 438 + return result; 433 439 #else 434 440 #if defined(__TIC_WINDOWS__) 435 441 const char* path = tic_fs_path(fs, name); ··· 452 458 453 459 bool tic_fs_delfile(tic_fs* fs, const char* name) 454 460 { 455 - #if defined(BAREMETALPI) 456 - dbg("tic_fs_delfile %s", name); 457 - // TODO BAREMETALPI 458 - return false; 459 - #else 460 461 const char* path = tic_fs_path(fs, name); 461 462 462 463 const FsString* pathString = utf8ToString(path); 464 + #if defined(BAREMETALPI) 465 + bool result = (f_unlink(pathString) != FR_OK); 466 + #else 463 467 bool result = tic_remove(pathString); 468 + #endif 464 469 freeString(pathString); 465 470 466 471 #if defined(__EMSCRIPTEN__) ··· 468 473 #endif 469 474 470 475 return result; 471 - #endif 472 476 } 473 477 474 478 void tic_fs_homedir(tic_fs* fs) ··· 548 552 bool fs_isdir(const char* path) 549 553 { 550 554 #if defined(BAREMETALPI) 551 - // This function isn't applicable to baremetal. 552 - return false; 555 + FILINFO s; 556 + FRESULT res = f_stat(path, &s); 557 + if (res != FR_OK) return false; 558 + return s.fattrib & AM_DIR; 553 559 #else 554 560 struct tic_stat_struct s; 555 561 const FsString* pathString = utf8ToString(path);
+20 -5
src/studio/studio.c
··· 413 413 tic_mem* tic = studio->tic; 414 414 tic80_input* input = &tic->ram->input; 415 415 416 + #ifdef KEYBOARD_LAYOUT_ES 417 + // US KEYS: " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./< "; 418 + static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789'!`+cn'o,.-< "; 419 + static const char Shift[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ=!\" $%&/()??^*CN\"a;:_> "; 420 + static const char Alt[] = " |@# []} {\\ "; 421 + #else 416 422 static const char Symbols[] = " abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ "; 417 423 static const char Shift[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}|:\"~<>? "; 424 + static const char Alt[] = " "; 425 + #endif 418 426 419 427 enum{Count = sizeof Symbols}; 420 428 ··· 426 434 { 427 435 bool caps = tic_api_key(tic, tic_key_capslock); 428 436 bool shift = tic_api_key(tic, tic_key_shift); 437 + bool alt = tic_api_key(tic, tic_key_alt); 429 438 430 - return caps 431 - ? key >= tic_key_a && key <= tic_key_z 432 - ? shift ? Symbols[key] : Shift[key] 433 - : shift ? Shift[key] : Symbols[key] 434 - : shift ? Shift[key] : Symbols[key]; 439 + if (caps && key >= tic_key_a && key <= tic_key_z) shift = !shift; 440 + 441 + return shift ? Shift[key] 442 + : alt ? Alt[key] 443 + : Symbols[key]; 435 444 } 436 445 } 437 446 ··· 1827 1836 #if defined(BUILD_EDITORS) 1828 1837 else if(studio->mode != TIC_RUN_MODE && studio->config->data.keyboardLayout != tic_layout_azerty) 1829 1838 { 1839 + #ifndef KEYBOARD_LAYOUT_ES 1830 1840 if(keyWasPressedOnce(studio, tic_key_grave)) setStudioMode(studio, TIC_CONSOLE_MODE); 1831 1841 else if(keyWasPressedOnce(studio, tic_key_1)) 1832 1842 { ··· 1840 1850 else if(keyWasPressedOnce(studio, tic_key_3)) setStudioMode(studio, TIC_MAP_MODE); 1841 1851 else if(keyWasPressedOnce(studio, tic_key_4)) setStudioMode(studio, TIC_SFX_MODE); 1842 1852 else if(keyWasPressedOnce(studio, tic_key_5)) setStudioMode(studio, TIC_MUSIC_MODE); 1853 + #endif 1843 1854 } 1844 1855 #endif 1845 1856 } ··· 2250 2261 #if defined(BUILD_EDITORS) 2251 2262 static void doCodeExport(Studio* studio) 2252 2263 { 2264 + #ifndef BAREMETALPI 2253 2265 char pos[sizeof studio->bytebattle.last.postag]; 2254 2266 { 2255 2267 s32 x = 0, y = 0; ··· 2277 2289 fclose(file); 2278 2290 } 2279 2291 } 2292 + #endif 2280 2293 } 2281 2294 2282 2295 static void doCodeImport(Studio* studio) 2283 2296 { 2297 + #ifndef BAREMETALPI 2284 2298 FILE* file = fopen(studio->bytebattle.imp, "rb"); 2285 2299 2286 2300 if(file) ··· 2326 2340 2327 2341 fclose(file); 2328 2342 } 2343 + #endif 2329 2344 } 2330 2345 #endif 2331 2346
+4
src/studio/studio.h
··· 40 40 #define KEYBOARD_HOLD 20 41 41 #define KEYBOARD_PERIOD 3 42 42 43 + #ifdef BAREMETALPI 44 + #define TIC_LOCAL "../.tic80/" 45 + #else 43 46 #define TIC_LOCAL ".local/" 47 + #endif 44 48 #define TIC_LOCAL_VERSION TIC_LOCAL TIC_VERSION_HASH "/" 45 49 #define TIC_CACHE TIC_LOCAL "cache/" 46 50
+17 -77
src/system/baremetalpi/kernel.cpp
··· 42 42 static char keyboardModifiers; 43 43 44 44 // mouse status 45 - static unsigned mousex; 46 - static unsigned mousey; 47 - static unsigned mousexOld; 48 - static unsigned mouseyOld; 45 + static int mousex; 46 + static int mousey; 49 47 static unsigned mousebuttons; 50 - static unsigned mousebuttonsOld; 51 - static unsigned mouseTime = 600; // starts not visible 52 48 53 49 // gamepad status 54 50 static struct TGamePadState gamepad; ··· 180 176 const u32 *line = ts + ((y+TIC80_OFFSET_TOP)*(TIC80_FULLWIDTH) + TIC80_OFFSET_LEFT); 181 177 memcpy(buf + (pitch * y), line, TIC80_WIDTH * 4); 182 178 } 183 - 184 - // single pixel mouse pointer, disappear after 10 seconds unmoved 185 - if (mouseTime<600) 186 - { 187 - u32 midx = pitch*(mousey)+mousex; 188 - buf[midx]= 0xffffff; 189 - } 190 - 191 - // memcpy(screen->GetBuffer(), tic->screen, TIC80_WIDTH*TIC80_HEIGHT*4); would have been too good 192 179 } 193 - 194 180 195 181 196 182 } //extern C 197 183 198 - void mouseEventHandler (TMouseEvent Event, unsigned nButtons, unsigned nPosX, unsigned nPosY, int nWheelMove) 184 + void mouseStatusHandler (unsigned nButtons, int nDisplacementX, int nDisplacementY, int nWheelMove) 199 185 { 200 186 keyspinlock.Acquire(); 201 - mousex = nPosX/MOUSE_SENS; 202 - mousey = nPosY/MOUSE_SENS; 187 + 188 + mousex += nDisplacementX; 189 + mousey += nDisplacementY; 190 + 191 + if (mousex < 0) mousex = 0; 192 + if (mousex > TIC80_WIDTH*MOUSE_SENS) mousex = TIC80_WIDTH*MOUSE_SENS; 193 + if (mousey < 0) mousey = 0; 194 + if (mousey > TIC80_HEIGHT*MOUSE_SENS) mousey = TIC80_HEIGHT*MOUSE_SENS; 195 + 203 196 mousebuttons = nButtons; 204 197 keyspinlock.Release(); 205 198 } ··· 227 220 if (mousebuttons & 0x01) tic_input->mouse.left = true; else tic_input->mouse.left = false; 228 221 if (mousebuttons & 0x02) tic_input->mouse.right = true; else tic_input->mouse.right = false; 229 222 if (mousebuttons & 0x04) tic_input->mouse.middle = true; else tic_input->mouse.middle = false; 230 - tic_input->mouse.x = mousex + TIC80_OFFSET_LEFT; 231 - tic_input->mouse.y = mousey + TIC80_OFFSET_TOP; 232 - 233 - if( (mousex == mousexOld) && (mousey == mouseyOld) && (mousebuttons == mousebuttonsOld)) 234 - { 235 - mouseTime++; 236 - } 237 - else 238 - { 239 - mouseTime = 0; 240 - } 241 - 242 - mousexOld = mousex; 243 - mouseyOld = mousey; 244 - mousebuttonsOld = mousebuttons; 223 + tic_input->mouse.x = mousex/MOUSE_SENS + TIC80_OFFSET_LEFT; 224 + tic_input->mouse.y = mousey/MOUSE_SENS + TIC80_OFFSET_TOP; 245 225 246 226 // keyboard 247 227 tic_input->gamepads.first.data = 0; ··· 275 255 case 0x4F: tic_input->gamepads.first.right = true; break; 276 256 } 277 257 //dbg(" %02x ", keyboardRawKeys[i]); 278 - 279 258 } 280 259 } 281 260 //dbg("\n"); 282 261 262 + if(keynum >= TIC80_KEY_BUFFER) return; 283 263 284 264 // gamepads 285 265 ··· 339 319 keyspinlock.Release(); 340 320 } 341 321 342 - void testmkdir(const char* name) 343 - { 344 - dbg("creating %s : ", name); 345 - FRESULT res = f_mkdir(name); 346 - if(res == FR_OK) 347 - { 348 - dbg("ok\n"); 349 - } 350 - else 351 - { 352 - dbg("KO %d\n", res); 353 - } 354 - } 355 - 356 - void teststat(const char* name) 357 - { 358 - dbg("K:%s", name); 359 - FILINFO filinfo; 360 - FRESULT res = f_stat (name, &filinfo); 361 - dbg("stat: %d ", res); 362 - dbg("size: %ld ", filinfo.fsize); 363 - dbg("attr: %02x\n", filinfo.fattrib); 364 - } 365 - 366 322 TShutdownMode Run(void) 367 323 { 368 324 initializeCore(); 369 325 mLogger.Write (KN, LogNotice, "TIC80 Port"); 370 326 371 - //teststat("circle.txt"); 372 - //teststat("no.txt"); 373 - //teststat("carts"); 374 - 375 - testmkdir("tic80"); 376 - //CTimer::SimpleMsDelay(5000); 377 - 378 - // ok testmkdir("primo"); 379 - // ko testmkdir("secondo/bis"); 380 - // ok testmkdir(".terzo"); 381 - // ko testmkdir(".quarto/"); 382 - // ko testmkdir("quinto/"); 383 - // ok testmkdir("sesto bis"); 327 + f_mkdir("tic80"); 384 328 385 329 dbg("Calling studio init instance..\n"); 386 330 387 331 if (pKeyboard) 388 332 { 389 333 dbg("With keyboard\n"); 390 - malloc(77); 391 334 char arg0[] = "xxkernel"; 392 335 char* argv[] = { &arg0[0], NULL }; 393 336 int argc = 1; 394 - malloc(88); 395 337 platform.studio = studio_create(argc, argv, 44100, TIC80_PIXEL_COLOR_BGRA8888, "tic80", INT32_MAX, tic_layout_qwerty); 396 - malloc(99); 397 - 398 338 } 399 339 else 400 340 { ··· 422 362 initGamepads(mDeviceNameService, gamePadStatusHandler); 423 363 424 364 if (pMouse) { 425 - pMouse->RegisterEventHandler (mouseEventHandler); 365 + pMouse->RegisterStatusHandler (mouseStatusHandler); 426 366 } 427 367 428 368 const tic80* product = &studio_mem(platform.studio)->product;
+11 -11
src/system/baremetalpi/keycodes.h
··· 49 49 tic_key_backspace, // KeyBackspace, 0x2A 50 50 tic_key_tab, // KeyTabulator, 0x2B 51 51 tic_key_space, // KeySpace, 0x2C 52 - tic_key_apostrophe, // '\'', 0x2D 53 - tic_key_unknown, // C('?'), 0x2E -- ^ 54 - tic_key_leftbracket, // C('?'), 0x2F -- [ 55 - tic_key_rightbracket, // '+', 0x30 -- ] 56 - tic_key_unknown, // C('?'), 0x31 57 - tic_key_unknown, // C('?'), 0x32 58 - tic_key_unknown, // C('?'), 0x33 -- @ 59 - tic_key_unknown, // C('?'), 0x34 -- # 60 - tic_key_backslash, // '\\', 0x35 52 + tic_key_minus, // '-', 0x2D 53 + tic_key_equals, // '=', 0x2E 54 + tic_key_leftbracket, // '[', 0x2F 55 + tic_key_rightbracket, // ']', 0x30 56 + tic_key_backslash, // '\\', 0x31 57 + tic_key_backslash, // '\\', 0x32 58 + tic_key_semicolon, // ';', 0x33 59 + tic_key_apostrophe, // '\'', 0x34 60 + tic_key_grave, // '`', 0x35 61 61 tic_key_comma, // ',', 0x36 62 62 tic_key_period, // '.', 0x37 63 - tic_key_minus, // '-', 0x38 63 + tic_key_slash, // '/', 0x38 64 64 tic_key_capslock, // KeyCapsLock, 0x39 65 65 tic_key_f1, // KeyF1, 0x3A 66 66 tic_key_f2, // KeyF2, 0x3B ··· 104 104 tic_key_numpad9, // KeyPageUp, 0x61 105 105 tic_key_numpad0, // KeyInsert, 0x62 106 106 tic_key_numpadperiod, // KeyDelete, 0x63 107 - tic_key_unknown, // '<', 0x64 107 + tic_key_iso_extra, // '<', 0x64 108 108 tic_key_unknown, // KeyApplication, 0x65 109 109 tic_key_unknown, // KeyNone, 0x66 110 110 tic_key_unknown, // KeyNone, 0x67
+7 -10
src/system/baremetalpi/syscore.h
··· 161 161 // Initialize newlib stdio with a reference to Circle's file system and console 162 162 CGlueStdioInit (mConsole); 163 163 164 - if (f_mount (&mFileSystem, "SD:", 1) != FR_OK) 165 - { 164 + if (f_mount (&mFileSystem, "SD:", 1) != FR_OK) { 166 165 Die("Cannot mount drive"); 166 + } 167 + 168 + if (f_mount (&mFileSystem, "USB:", 1) != FR_OK) { 169 + if (f_mount (&mFileSystem, "SD:", 1) != FR_OK) { 170 + Die("Cannot mount drive"); 171 + } 167 172 } 168 173 169 174 pKeyboard = (CUSBKeyboardDevice *) mDeviceNameService.GetDevice ("ukbd1", FALSE); ··· 178 183 if (pMouse == 0) 179 184 { 180 185 dbg("Mouse not found"); 181 - } 182 - else 183 - { 184 - if (!pMouse->Setup (TIC80_WIDTH*MOUSE_SENS, TIC80_HEIGHT*MOUSE_SENS)) 185 - { 186 - Die("Cannot setup mouse"); 187 - } 188 - 189 186 } 190 187 191 188
+1
src/tic.h
··· 707 707 tic_key_comma, 708 708 tic_key_period, 709 709 tic_key_slash, 710 + tic_key_iso_extra, 710 711 711 712 tic_key_space, 712 713 tic_key_tab,