allowing emulators to change method flags

This commit is contained in:
2026-04-27 20:14:34 +03:00
parent 72fd316310
commit 21eca5db92
4 changed files with 43 additions and 10 deletions

View File

@@ -19,10 +19,10 @@ to be made more portable.
Not everything OC has (as a few of them are really MC-centered) but most of it. Not everything OC has (as a few of them are really MC-centered) but most of it.
- `data` component (note: maybe add hamming code support?) - `data` component (note: deflate, sha256 and aes impl are callbacks, to keep NN small and simple)
- `modem` component - `modem` component
- `tunnel` component - `tunnel` component
- `internet` component - `internet` component (note: NN does not handle internet requests, those are up to the emulator)
- `relay` component (note: OCDoc still refers to it as `access_point`) - `relay` component (note: OCDoc still refers to it as `access_point`)
- `computer` component - `computer` component
- `geolyzer` component - `geolyzer` component

View File

@@ -480,7 +480,7 @@ int main(int argc, char **argv) {
nn_mountComponent(c, screen, -1, false); nn_mountComponent(c, screen, -1, false);
nn_mountComponent(c, ocelotCard, -1, false); nn_mountComponent(c, ocelotCard, -1, false);
//nn_mountComponent(c, tmpfs, -1, false); //nn_mountComponent(c, tmpfs, -1, false);
nn_mountComponent(c, keyboard, -1, false); nn_mountComponent(c, keyboard, -1, false);
nn_mountComponent(c, eepromCard, 0, false); nn_mountComponent(c, eepromCard, 0, false);
nn_mountComponent(c, managedfs, 1, false); nn_mountComponent(c, managedfs, 1, false);
nn_mountComponent(c, gpuCard, 2, false); nn_mountComponent(c, gpuCard, 2, false);
@@ -619,6 +619,11 @@ skipDrawScreen:;
printf("error: %s\n", nn_getError(c)); printf("error: %s\n", nn_getError(c));
goto cleanup; goto cleanup;
} }
e = nn_tickSynchronized(c);
if(e != NN_OK) {
printf("sync method error: %s\n", nn_getError(c));
goto cleanup;
}
nn_ComputerState state = nn_getComputerState(c); nn_ComputerState state = nn_getComputerState(c);
if(state == NN_POWEROFF) break; if(state == NN_POWEROFF) break;

View File

@@ -1779,6 +1779,34 @@ nn_Exit nn_setComponentTypeID(nn_Component *c, const char *internalTypeID) {
return NN_OK; return NN_OK;
} }
static nn_MethodEntry *nn_getComponentMethodEntry(nn_Component *c, const char *method) {
nn_MethodEntry ent = {
.name = method,
};
return nn_hashGet(&c->methodsMap, &ent);
}
// Sets the method flags
void nn_setComponentMethodFlags(nn_Component *c, const char *method, nn_MethodFlags flags) {
nn_MethodEntry *ent = nn_getComponentMethodEntry(c, method);
if(ent == NULL) return;
ent->flags = flags;
}
// combines method flags
void nn_addComponentMethodFlags(nn_Component *c, const char *method, nn_MethodFlags flags) {
nn_MethodEntry *ent = nn_getComponentMethodEntry(c, method);
if(ent == NULL) return;
ent->flags |= flags;
}
// removes method flags
void nn_removeComponentMethodFlags(nn_Component *c, const char *method, nn_MethodFlags flags) {
nn_MethodEntry *ent = nn_getComponentMethodEntry(c, method);
if(ent == NULL) return;
ent->flags &= ~flags;
}
void *nn_getComponentState(nn_Component *c) { void *nn_getComponentState(nn_Component *c) {
return c->state; return c->state;
} }
@@ -1792,13 +1820,6 @@ size_t nn_countComponentMethods(nn_Component *c) {
return c->methodCount; return c->methodCount;
} }
static nn_MethodEntry *nn_getComponentMethodEntry(nn_Component *c, const char *method) {
nn_MethodEntry ent = {
.name = method,
};
return nn_hashGet(&c->methodsMap, &ent);
}
// will fill the methodnames array with the names of the *enabled* methods. // will fill the methodnames array with the names of the *enabled* methods.
// Will set *len to the amount of methods. // Will set *len to the amount of methods.
void nn_getComponentMethods(nn_Component *c, const char **methodnames, size_t *len) { void nn_getComponentMethods(nn_Component *c, const char **methodnames, size_t *len) {

View File

@@ -678,6 +678,13 @@ nn_Exit nn_setComponentMethodsArray(nn_Component *c, const nn_Method *methods, s
// so the GPU can confirm it is being bound to a screen it knows how to use. // so the GPU can confirm it is being bound to a screen it knows how to use.
nn_Exit nn_setComponentTypeID(nn_Component *c, const char *internalTypeID); nn_Exit nn_setComponentTypeID(nn_Component *c, const char *internalTypeID);
// Sets the method flags
void nn_setComponentMethodFlags(nn_Component *c, const char *method, nn_MethodFlags flags);
// combines method flags
void nn_addComponentMethodFlags(nn_Component *c, const char *method, nn_MethodFlags flags);
// removes method flags
void nn_removeComponentMethodFlags(nn_Component *c, const char *method, nn_MethodFlags flags);
// get component state // get component state
void *nn_getComponentState(nn_Component *c); void *nn_getComponentState(nn_Component *c);
// get component class state // get component class state