ok this is my problem: i'm using a Turbo C++ Windows-based compiler to develop a Nintendo NES emulator. i have to reserve memory space for the RAM memory. as I saw in the XNES emulator source code it did like this:
...but when I do that on my compiler it return an error. it's seems like there's no enough memory on my computer, but i know it's a compiler error. this error always comes out when trying to reserve a block a memory higher than 65535 (no that 0x10000 = 65536).
why does it happen? how i solve this?
this is the code i get so far (please don't laugh XD):
i know i can solve this using the "allegro.h" library, but had a few problems using it in all the compilers but Dev-C++ and I refuse to programm in Dev-C++ because it really sucks hard.
any suggestion will be apreciated!
Code:
RAM = (byte *)malloc( 0x10000 );
...but when I do that on my compiler it return an error. it's seems like there's no enough memory on my computer, but i know it's a compiler error. this error always comes out when trying to reserve a block a memory higher than 65535 (no that 0x10000 = 65536).
why does it happen? how i solve this?
this is the code i get so far (please don't laugh XD):
Code:
#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;
}
#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;
}
i know i can solve this using the "allegro.h" library, but had a few problems using it in all the compilers but Dev-C++ and I refuse to programm in Dev-C++ because it really sucks hard.
any suggestion will be apreciated!