Error in C++ / NES emulator programm - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Error in C++ / NES emulator programm

ehguachoehguacho Posts: 2Member
hi! i'm trying to programm a Nintendo NES emulator. i've coded some opcodes (NES uses a 6502 processor) and them worked perfectly. but now i'm trying to allocate a piece of memory and i get this error.


after the error, a blue line appears on the line "switch(memory[pc])" and i can't figure out why does it happen, i can't find the error. is it inside of the "switch" instruccion or is it in the "pc" (program counter) variable!? what i'm trying to do is to copy a piece of memory from the NES game rom file to the memory (a piece of memory wich should start at 0x8000). please somebody help me! :(

this is the full source code of my programm.
you can download it from here: [link=][/link]


#define ADDR ((memory[pc + 2] << 8) | memory[pc + 1])
#define PUSH(a) memory[SP + 0x100] = (a); SP--
#define PULL() memory[(++SP) + 0x100]

void main(void)
FILE *fp;
unsigned char *memory; // Vector de memoria ROM (PRG Rom)
int i = 0;
unsigned int pc; // Contador de programa
int AR = 0; // Registro A
int XR = 0; // Registro X
int YR = 0; // Registro Y
int C_FLAG = 0; // Carry flag
int S_FLAG = 0; // Sign flag
int Z_FLAG = 0; // Zero flag
int SP = 0xFF; // Puntero a pila
int mirroring; // 0 = Horizontal 1 = Vertical
int trainer, battery;


// Carga del archivo

fp = fopen("jumpy.nes","rb");
printf("No se encontro el archivo
else printf("Archivo encontrado

// Cantidad de bancos de ROM y VROM y tama


  • LundinLundin Posts: 3,711Member
    Are you running that compiler for a 16 bit or 32 bit program?

    If 16 bit, then the "int" type is probably not large enough to hold a value of x*16*1024. The max value of an "int" is 32767 or 65535, it depends on the compiler setting. In that case, change PRGROM_SIZE to unsigned int.

  • ehguachoehguacho Posts: 2Member
    variable "pc" is already an unsigned int
  • LundinLundin Posts: 3,711Member
    The possible problem would be with malloc(), in case the amount of memory is large enough to overflow the int.

    Since you don't tell whether this is 16 or 32 bit, I can't help you further.
Sign In or Register to comment.