我尝试使用fseek
和fread
将二进制文件(Game Boy ROM)的字节0x0100-0x3FFF复制到我模拟的addressSpace的字节0x0100-0x3FFF;但我不知道如何使用fread
开始写入addressSpace中的特定字节。这是受影响的代码;它按预期开始读取ROM的0x0100,但它写入了addressSpace的0x0000-0x3EFF,我的问题是,如何让fread开始写入0x0100呢?
#include <stdio.h>
#include <stdint.h>
uint8_t addressSpace[0x10000];
int main()
{
FILE* gameROM = fopen("rom.gb", "rb");
if (gameROM == NULL || sizeof(addressSpace[0]) != 1)
{
printf("Error");
getchar();
fclose(gameROM);
return 1;
}
fseek(gameROM, 0x100, SEEK_SET);
fread(addressSpace, sizeof(addressSpace[0]), 0x3EFF, gameROM);
printf("\n%X\n", addressSpace[0x100]);
getchar();
return 0;
}
答案 0 :(得分:4)
// v-- here
fread(addressSpace + 0x100, sizeof(addressSpace[0]), 0x3EFF, gameROM);
答案 1 :(得分:2)
fread(addressSpace+loc, sizeof(addressSpace[0]), 0x3EFF, gameROM);
loc
是您要写入addressspace
loc = 0x0100