Merge pull request #8 from speedy-lex/main

fix stuff
This commit is contained in:
Quantum Tomato 2025-07-02 00:02:46 +02:00 committed by GitHub
commit 5c3ec01a5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -60,7 +60,7 @@ void nn_drive_writeSector(nn_drive *drive, void *_, nn_component *component, nn_
int sector = nn_toInt(sectorValue); int sector = nn_toInt(sectorValue);
size_t sector_size = drive->getSectorSize(component, drive->userdata); size_t sector_size = drive->getSectorSize(component, drive->userdata);
nn_value bufValue = nn_getArgument(computer, 1); nn_value bufValue = nn_getArgument(computer, 1);
char *buf = nn_toString(bufValue, &sector_size); const char *buf = nn_toString(bufValue, &sector_size);
drive->writeSector(component, drive->userdata, sector, buf); drive->writeSector(component, drive->userdata, sector, buf);
} }
void nn_drive_readByte(nn_drive *drive, void *_, nn_component *component, nn_computer *computer) { void nn_drive_readByte(nn_drive *drive, void *_, nn_component *component, nn_computer *computer) {
@ -71,7 +71,7 @@ void nn_drive_readByte(nn_drive *drive, void *_, nn_component *component, nn_com
size_t sector_offset = disk_offset % sector_size; size_t sector_offset = disk_offset % sector_size;
char buf[sector_size]; char buf[sector_size];
drive->readSector(component, drive->userdata, sector, &buf); drive->readSector(component, drive->userdata, sector, buf);
nn_return(computer, nn_values_integer(buf[sector_offset])); nn_return(computer, nn_values_integer(buf[sector_offset]));
} }
@ -85,7 +85,7 @@ void nn_drive_writeByte(nn_drive *drive, void *_, nn_component *component, nn_co
size_t sector_offset = disk_offset % sector_size; size_t sector_offset = disk_offset % sector_size;
char buf[sector_size]; char buf[sector_size];
drive->readSector(component, drive->userdata, sector, &buf); drive->readSector(component, drive->userdata, sector, buf);
buf[sector_offset] = write; buf[sector_offset] = write;

View File

@ -51,6 +51,10 @@ const char *ne_location(nn_address address) {
size_t ne_eeprom_get(nn_component *component, void *_, char *buf) { size_t ne_eeprom_get(nn_component *component, void *_, char *buf) {
FILE *f = fopen(ne_location(nn_getComponentAddress(component)), "rb"); FILE *f = fopen(ne_location(nn_getComponentAddress(component)), "rb");
if (f == NULL) {
printf("couldn't read eeprom");
exit(1);
}
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
size_t len = ftell(f); size_t len = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
@ -61,6 +65,10 @@ size_t ne_eeprom_get(nn_component *component, void *_, char *buf) {
void ne_eeprom_set(nn_component *component, void *_, const char *buf, size_t len) { void ne_eeprom_set(nn_component *component, void *_, const char *buf, size_t len) {
FILE *f = fopen(ne_location(nn_getComponentAddress(component)), "wb"); FILE *f = fopen(ne_location(nn_getComponentAddress(component)), "wb");
if (f == NULL) {
printf("couldn't write eeprom");
exit(1);
}
fwrite(buf, sizeof(char), len, f); fwrite(buf, sizeof(char), len, f);
fclose(f); fclose(f);
} }