Skip to content

Commit 3716c9b

Browse files
committed
Run program directly from ROM
1 parent ac0b81e commit 3716c9b

2 files changed

Lines changed: 39 additions & 15 deletions

File tree

src/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,31 @@ target_compile_options(pawn PRIVATE
916916
-DAMX_ANSIONLY
917917
-DAMX_NODYNALOAD
918918
-DAMX_DONT_RELOCATE
919+
920+
# -DAMX_ALIGN
921+
# -DAMX_ALLOT
922+
# -DAMX_DEFCALLBACK
923+
-DAMX_CLEANUP
924+
# -DAMX_CLONE
925+
-DAMX_EXEC
926+
# -DAMX_FLAGS
927+
-DAMX_INIT
928+
# -DAMX_MEMINFO
929+
# -DAMX_NAMELENGTH
930+
# -DAMX_NATIVEINFO
931+
-DAMX_PUSHXXX
932+
-DAMX_RAISEERROR
933+
# -DAMX_REGISTER
934+
-DAMX_SETCALLBACK
935+
# -DAMX_SETDEBUGHOOK
936+
# -DAMX_UTF8XXX
937+
# -DAMX_XXXNATIVES
938+
-DAMX_XXXPUBLICS
939+
-DAMX_XXXPUBVARS
940+
-DAMX_XXXSTRING
941+
# -DAMX_XXXTAGS
942+
# -DAMX_XXXUSERDATA
943+
# -DAMX_VERIFYADDR
919944
$<$<CONFIG:DEBUG>: ${DEBUG_FLAGS}>
920945
$<$<CONFIG:RELEASE>: ${RELEASE_FLAGS}>
921946
$<$<COMPILE_LANGUAGE:CXX>: ${CXX_FLAGS}>

src/displayapp/screens/Pawn.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ static cell AMX_NATIVE_CALL F_raise_error(AMX* amx, const cell* params) {
357357
return 0;
358358
}
359359

360-
static const uintptr_t natives[] = { // Indices start at -1000
360+
static const uintptr_t natives[] = {
361+
// Indices start at -1000
361362
(uintptr_t) lv_label_create,
362363
(uintptr_t) lv_btn_create,
363364
(uintptr_t) lv_obj_set_pos,
@@ -366,7 +367,8 @@ static const uintptr_t natives[] = { // Indices start at -1000
366367
(uintptr_t) lv_obj_realign,
367368
};
368369

369-
static const AMX_NATIVE lvgl_proxys[] = { // Indices start at -3000
370+
static const AMX_NATIVE lvgl_proxys[] = {
371+
// Indices start at -3000
370372
F_lv_label_create,
371373
F_lv_obj_set_event_cb,
372374
F_lv_label_set_text,
@@ -376,7 +378,8 @@ static const AMX_NATIVE lvgl_proxys[] = { // Indices start at -3000
376378
F_lv_obj_set_style_local_ptr,
377379
};
378380

379-
static const AMX_NATIVE pawn_proxys[] = { // Indices start at -2000
381+
static const AMX_NATIVE pawn_proxys[] = {
382+
// Indices start at -2000
380383
F_sprintf,
381384
F_read_datetime,
382385
F_read_datetime_short_str,
@@ -501,21 +504,21 @@ int Pawn::LoadProgram() {
501504

502505
memcpy(header, file, hdr.cod);
503506

504-
if (hdr.flags & AMX_FLAG_OVERLAY) {
505-
datablock = malloc(hdr.stp - hdr.dat); // This block contains data, heap and stack
506-
if (datablock == NULL)
507-
return AMX_ERR_MEMORY;
507+
datablock = malloc(hdr.stp - hdr.dat); // This block contains data, heap and stack
508+
if (datablock == NULL)
509+
return AMX_ERR_MEMORY;
508510

509-
memcpy(datablock, file + hdr.dat, hdr.hea - hdr.dat);
511+
memcpy(datablock, file + hdr.dat, hdr.hea - hdr.dat);
512+
amx.data = (unsigned char*) datablock;
510513

514+
if (hdr.flags & AMX_FLAG_OVERLAY) {
511515
constexpr int overlaypool_overhead = 8;
512516
overlaypool = malloc(max_overlay_size + overlaypool_overhead);
513517
if (overlaypool == NULL)
514518
return AMX_ERR_MEMORY;
515519

516520
amx_poolinit(&amx_pool, overlaypool, max_overlay_size + overlaypool_overhead);
517521

518-
amx.data = (unsigned char*) datablock;
519522
amx.overlay = prun_Overlay;
520523

521524
result = amx_Init(&amx, header);
@@ -528,13 +531,9 @@ int Pawn::LoadProgram() {
528531
overlaypool = NULL;
529532
}
530533
} else {
531-
datablock = malloc(hdr.stp); // This block contains code, data, heap and stack
532-
if (datablock == NULL)
533-
return AMX_ERR_MEMORY;
534-
535-
memcpy(datablock, file, hdr.size);
534+
amx.flags |= AMX_FLAG_DSEG_INIT;
536535

537-
result = amx_Init(&amx, datablock);
536+
result = amx_Init(&amx, (void*) file);
538537
if (result != AMX_ERR_NONE) {
539538
free(header);
540539
header = NULL;

0 commit comments

Comments
 (0)