Well, i earlier post something like "problems with a 256 entries jump table".
Now, im using Visual Studio 2010 professional and i had set up it fine for MASM. I have made a NES emulator which you are welcomed to try if you want at
www.yanese.com.. It's really done in the "C" that C++ has.
I want to emulate 8 BIT NES 6502 cpu in x64. So i have a file called "cpu.asm".
That's why i post the jump table thing, to jmp to and opcode table.
This thing about x64 dev is confusing me and getting me crazy.
I have a C++ func defined:
u8 ReadCpuMem(u16 addr)
{
u8 data;
data = CpuMemMap.pReadMem[addr >> 12](addr);
return data;
}
"CpuMemMap" is structure holding an array of 16 function pointers. You may be asking whay that "addr >> 12", simple the 6502 can address up to 64k, so shifting by 12 gives me the correct number between 0-15 and calls the correct function.
I use it this way becouse it's easier to map memory, since this old consoles had ranges on the CPU address bus that were used in a specially way. And most of all some NES cartridags had "mappers" chips to extend limitations of memory, etc.
Anyway back to my question:
I must call the ReadCpuMem function, so what i did in cpu.asm was:
ReadCpuMem PROTO :word
...
.data
dq BRK_IMPLIED
dq ORA_INDIRECT_X
dq OP_NOTFOUND
...
.code
RunCpu PROC LEAF
mov cx, Cpu.PC ;opcodes jump table
call ReadCpuMem ;this first C++ func call it's fine (read below)
mov Cpu.opcode, al
inc word ptr Cpu.PC ;INC PC
mov rcx, offset opcodes_jump
mov rcx, [rcx + rax * 8]
jmp rcx
;jump labales opcodes
BRK_IMPLIED::
ORA_INDIRECT_X::
;etc...
LDA_INMEDIATE::
call ResolveInmediate ;again: read below please!!
mov Cpu.A, al
jmp return
;etc...
return:
RunCpu ENDP
ResolveInmediate PROC LEAF
movzx rcx, Cpu.PC
call ReadCpuMem ;HERE MY PROBLEM!!!
inc word ptr Cpu.PC
ret
ResolveInmediate ENDP
That ResolveInmediate PROC is the emulated 6502 part. It's like saying "LDA #$05", or "load the Accumulator with inmediate 05h" Same as x86 or x64 architecture that has inmediate addressing... mov al, 05h.
That's not my point the thing i have read that a LEAF PROC can't CALL other procs?? When RunCpu PROC endsthe VS2010 debugger sends me to a full 0x00000000 and of course execution "CRASH".
The first c++ ReadCpuMem it's fine doesn't crash the app, but the second (the one inside ResolveInmediate PROC) is causing the problem.
Please be aware that im a newbie and all i can figure out is that something is going on wrong with the stack.
I have read too that "FRAME" procs can be made in x64, maybe that solves my problem making them FRAME, but i'm still to noob to make a FRAME PROC and MSDN is not the best source...
Btw, im using extern "C" and __cdecl in the functions that my c++ code calls to the .asm code.
help!!