*** EMIL6502lib v0.1 ***


+1.What is Emil6502lib?
+2.Public functions
+3.What should I do?
+4.Contact me


+1.WHAT IS EMIL6502LIB?

Emil6502 is a MOS 6502 emulation library. It is written in pure C and is the same core I'm using in EmilNES emulator. At the moment it doesn't support Decimal Mode (As it's not required in NES emulation). I use GCC to compile so i recomend you doing the same.




+2.PUBLIC FUNCTIONS

-First of all, the types "union tipo_palabra8" and "union tipo_palabra16" can be used as unsigned/signed 8 and 16bits word using .uns (unsigned) and .sig (signed). 

The file you must include is 6502core.h where you will find:

-The basic data srtuct of the Emil6502lib is:

struct cpu6502
 {
  union tipo_palabra16 PC;
  union tipo_palabra8 A;
  union tipo_palabra8 X;
  union tipo_palabra8 Y;
  union tipo_palabra8 P;
  union tipo_palabra8 SP; //Stack Pointer. 
  union tipo_palabra8 IR; //Instruction register.
  union tipo_palabra8* memory_map; 
  
  int nmi;     //0->nothing, 1->nmi
  int reset;   //0->nothing, 1->reset
  int brk_irq; //0->nothing, 1->brk, 2->irq.    
 };    

Pay attention that before doing anything else you MUST give memory_map a valid pointer.

-To reset the 6502 just call:

void reset6502(struct cpu6502* cpu)

-If you want to execute the cpu just call:

int inline ejecutar(int *halt,struct cpu6502* cpu, unsigned long* ciclo)

This function executes ONE instruction and return the number of cycles spent.
halt will be return 1 if an invalid opcode is decoded.
ciclo will return ciclo + spent cycles in execution.

-In order to generate an excepction you should set the nmi, reset or brk_irq to the value desired (0,1 or 2 in brk_irq) and call the ejecutar function. For example if you wish to generate a nmi:

cpu.nmi = 1;
ejecutar(&halt, &cpu, &ciclo);

-You can find an example of using the library in main.c (which is not a library file).



+3.WHAT SHOULD I DO?

In order to make it work you HAVE TO WRITE the functions leer_mp (read memory) and escribir_mp (write memory) just fill the bodys in rw_mp.c.

The parameters means:

-dato: Pointer to the value to be written/read.
-mp: Pointer to memory.
-dir: Address.





+4. CONTACT ME

This library is written by Emilio Garcia Montao.
If you find some bug or are you going to use it please write me to egm_nes@yahoo.com

