mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 17:13:31 +02:00
small tweak
This commit is contained in:
parent
4a28c8943e
commit
84ada3c62a
@ -154,24 +154,31 @@ void nn_eeprom_makeReadonly(nn_eeprom *eeprom, void *_, nn_component *component,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nn_eeprom_getChecksum(nn_eeprom *eeprom, void *_, nn_component *component, nn_computer *computer) {
|
void nn_eeprom_getChecksum(nn_eeprom *eeprom, void *_, nn_component *component, nn_computer *computer) {
|
||||||
size_t cap = eeprom->getDataSize(component, eeprom->userdata);
|
size_t dataCap = eeprom->getDataSize(component, eeprom->userdata);
|
||||||
|
size_t codeCap = eeprom->getSize(component, eeprom->userdata);
|
||||||
nn_Alloc *alloc = nn_getAllocator(nn_getUniverse(computer));
|
nn_Alloc *alloc = nn_getAllocator(nn_getUniverse(computer));
|
||||||
char *buf = nn_alloc(alloc, cap);
|
char *buf = nn_alloc(alloc, dataCap + codeCap);
|
||||||
if(buf == NULL) {
|
if(buf == NULL) {
|
||||||
nn_setCError(computer, "out of memory");
|
nn_setCError(computer, "out of memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int len = eeprom->getData(component, eeprom->userdata, buf);
|
int dataLen = eeprom->getData(component, eeprom->userdata, buf);
|
||||||
if(len < 0) {
|
if(dataLen < 0) {
|
||||||
|
nn_dealloc(alloc, buf, dataCap + codeCap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char hash[4] = {1, 0, 0, 1};
|
int codeLen = eeprom->get(component, eeprom->userdata, buf + dataLen);
|
||||||
nn_data_crc32(buf, len, hash);
|
if(codeLen < 0) {
|
||||||
nn_dealloc(alloc, buf, cap);
|
nn_dealloc(alloc, buf, dataCap + codeCap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
char hash[4];
|
||||||
|
nn_data_crc32(buf, dataLen + codeLen, hash);
|
||||||
|
nn_dealloc(alloc, buf, dataCap + codeCap);
|
||||||
|
|
||||||
nn_return_string(computer, hash, sizeof(hash));
|
nn_return_string(computer, hash, sizeof(hash));
|
||||||
|
|
||||||
nn_eeprom_readCost(component, len);
|
nn_eeprom_readCost(component, dataLen + codeLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nn_loadEepromTable(nn_universe *universe) {
|
void nn_loadEepromTable(nn_universe *universe) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user