Make ROM const

This commit is contained in:
Toby Jaffey 2025-12-09 22:08:53 +00:00
parent 76fba39a21
commit ac554865a6
6 changed files with 11 additions and 7 deletions

View file

@ -1,2 +1,2 @@
// Arduino cannot do -DUVM32_MEMORY_SIZE, so set this explicitly
#define UVM32_MEMORY_SIZE 600
#define UVM32_MEMORY_SIZE 16*1024

View file

@ -2,7 +2,8 @@
#include "uvm32.h"
#include "common/uvm32_common_custom.h"
uint8_t rom[] = {
#if 0
uint8_t rom[] = { // mandel.bin
0x23, 0x26, 0x11, 0x00, 0xef, 0x00, 0xc0, 0x00, 0xb7, 0x08, 0x00, 0x01,
0x73, 0x00, 0x00, 0x00, 0x13, 0x01, 0x01, 0xff, 0x23, 0x26, 0x81, 0x00,
0x37, 0xf5, 0xff, 0xff, 0xb7, 0x15, 0x00, 0x00, 0x37, 0xe6, 0xff, 0xff,
@ -27,6 +28,9 @@ uint8_t rom[] = {
0x67, 0x80, 0x00, 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f,
0x72, 0x6c, 0x64, 0x00
};
#else
#include "zigtris.h"
#endif
uvm32_state_t vmst;
uvm32_evt_t evt;
@ -49,7 +53,7 @@ void loop(void) {
}
if (isrunning) {
uvm32_run(&vmst, &evt, 100); // num instructions before vm considered hung
uvm32_run(&vmst, &evt, 10000000); // num instructions before vm considered hung
switch(evt.typ) {
case UVM32_EVT_END:

View file

@ -78,7 +78,7 @@ void uvm32_init(uvm32_state_t *vmst) {
vmst->core.extraflags |= 3; // Machine-mode.
}
bool uvm32_load(uvm32_state_t *vmst, uint8_t *rom, int len) {
bool uvm32_load(uvm32_state_t *vmst, const uint8_t *rom, int len) {
if (len > UVM32_MEMORY_SIZE) {
// too big
return false;

View file

@ -72,7 +72,7 @@ typedef struct {
} uvm32_state_t;
void uvm32_init(uvm32_state_t *vmst);
bool uvm32_load(uvm32_state_t *vmst, uint8_t *rom, int len);
bool uvm32_load(uvm32_state_t *vmst, const uint8_t *rom, int len);
bool uvm32_hasEnded(const uvm32_state_t *vmst);
uint32_t uvm32_run(uvm32_state_t *vmst, uvm32_evt_t *evt, uint32_t instr_meter);