Code: Select all
RAM = (byte *)malloc( 0x10000 );why does it happen? how i solve this?
this is the code i get so far (please don't laugh XD):
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
void main(void)
{
FILE *fp;
char gamename[50];
int i,RomBanks16kb,VRomBanks8kb,RamBanks8kb;
unsigned char *mem,*RAM,*ROM,*VRAM,*VROM,*SRAM;
unsigned long int kbromsize,pc;
clrscr();
strcpy(gamename,"demo.nes");
for(i = 0;i <= strlen(gamename) - 1;i++)
{
gamename[i] = toupper(gamename[i]);
}
fp = fopen(gamename,"rb");
if(!fp)
{
printf("Error abriendo el archivo %s. Saliendo...",gamename);
getch();
exit(1);
}
printf("Archivo %s abierto correctamente",gamename);
rewind(fp);
fseek(fp,0L,2);
kbromsize = ftell(fp);
printf("\nTamano de la rom: %d kb",kbromsize);
mem = (unsigned char *)malloc(kbromsize);
rewind(fp);
fread(mem,1,kbromsize,fp);
if(!mem)
{
printf("\nError alojando la memoria principal. Saliendo...");
getch();
exit(1);
}
printf("\nArchivo cargado en memoria correctamente");
if((mem[0] == 'N') && (mem[1] == 'E') && (mem[2] == 'S'))
{
printf("\niNes header encontrado");
}
else printf("\nEl archivo %s no es una rom de NES. Saliendo...",gamename);
RomBanks16kb = mem[4];
VRomBanks8kb = mem[5];
printf("\n%d banco(s) de memoria ROM",RomBanks16kb);
printf("\n%d banco(s) de memoria VROM",VRomBanks8kb);
RAM = (unsigned char *)malloc(0x10000);
/*ROM = (unsigned char *)malloc(RomBanks16kb * 16 * 1024);
VRAM = (unsigned char *)malloc(0x4000);
VROM = (unsigned char *)malloc(VRomBanks8kb * 8 * 1024);
SRAM = (unsigned char *)malloc(0x100);*/
if(!RAM)
{
printf("\nError alojando la memoria principal. Saliendo...");
getch();
exit(1);
}
printf("\n\n");
pc = 0;
while(pc <= 139)
{
if((pc != 0) && (pc % 20 == 0)) printf("\n");
printf("%2X ",mem[pc]);
pc++;
}
printf("\n\nSaliendo...");
getch();
return;
}any suggestion will be apreciated!