#include "mem.h" #include unsigned char memory[4096]; extern unsigned char DEFAULT_FONT[]; void MemInit(){ MemSet(0,0,4096); MemStore(DEFAULT_FONT,16*5,ADDR_FONT); } void MemSet(int addr, unsigned char value, int size){ for(int i=0;i4096){ printf("Illegal memory access (store): addr=%d\n",addr+i); return; } memory[addr+i]=data[i]; } } void MemLoad(unsigned char *data, int size, int addr){ int location=addr; for(int i=0;i4096){ printf("Illegal memory access (load): addr=%d\n",addr+i); return; } data[i]=memory[addr+i]; } } void MemLoadROM(char *path){ char byte; FILE *ptr; ptr=fopen(path,"rb"); int location=ADDR_ROM; while(fread(&byte,1,1,ptr)==1){ if(location >= 4096) break; MemSet(location,byte,1); location++; } fclose(ptr); } void MemDump(){ MemDumpRange(0,4096); } void MemDumpRange(int from, int size){ for(int addr=from;addr