corecpu.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * CoreCPU - The Quick6502 Project
  3. * corecpu.h
  4. *
  5. * Created by Manoel Trapier on 24/02/08
  6. * Copyright 2008 986 Corp. All rights reserved.
  7. *
  8. * $LastChangedDate$
  9. * $Author$
  10. * $HeadURL$
  11. * $Revision$
  12. *
  13. */
  14. #ifndef _QUICK6502_CORECPU_H_
  15. #define _QUICK6502_CORECPU_H_
  16. /* M6502 configuration
  17. *
  18. * Supported DEFINEs :
  19. * Q6502_NO_DECIMAL Quick6502 will not support BDC arithemtic (used for NES)
  20. * Q6502_CMOS Quick6502 will act as a CMOS 6502 (Not actually used)
  21. * Q6502_DEBUGGER Quick6502 will be build with debugguer support. Add some KB to the binary
  22. * and may slowdown a bit the emulation.
  23. *
  24. */
  25. #ifdef Q6502_CMOS
  26. //#warning Quick6502 CMOS support is actually desactivated, desactivate it
  27. #undef Q6502_CMOS
  28. #endif
  29. #ifndef Q6502_NO_DECIMAL
  30. //#warning Quick6502 have actually no BCD support, fallback to no NO_DECIMAL
  31. #define Q6502_NO_DECIMAL
  32. #endif
  33. #include "types.h"
  34. typedef byte (*quick6502_MemoryReadFunction)(unsigned short addr);
  35. typedef void (*quick6502_MemoryWriteFunction)(unsigned short addr, byte value);
  36. typedef struct quick6502_cpu_
  37. {
  38. /* 6502 registers */
  39. byte reg_A, reg_X, reg_Y;
  40. byte reg_P, reg_S;
  41. unsigned short reg_PC;
  42. /* Read/Write memory functions */
  43. quick6502_MemoryReadFunction memory_read;
  44. quick6502_MemoryWriteFunction memory_write;
  45. quick6502_MemoryReadFunction memory_page0_read;
  46. quick6502_MemoryWriteFunction memory_page0_write;
  47. quick6502_MemoryReadFunction memory_stack_read;
  48. quick6502_MemoryWriteFunction memory_stack_write;
  49. quick6502_MemoryReadFunction memory_opcode_read;
  50. /* Timing related */
  51. long cycle_done;
  52. byte exit_loop;
  53. byte int_pending;
  54. /* Other config options */
  55. byte running; /* This field is used to prevent cpu free if this cpu is running */
  56. byte page_crossed;
  57. /* TODO add support for Inst/MemAccess breakpoints */
  58. } quick6502_cpu;
  59. typedef struct quick6502_cpuconfig_
  60. {
  61. /* Read/Write memory functions */
  62. quick6502_MemoryReadFunction memory_read;
  63. quick6502_MemoryWriteFunction memory_write;
  64. quick6502_MemoryReadFunction memory_page0_read;
  65. quick6502_MemoryWriteFunction memory_page0_write;
  66. quick6502_MemoryReadFunction memory_stack_read;
  67. quick6502_MemoryWriteFunction memory_stack_write;
  68. quick6502_MemoryReadFunction memory_opcode_read;
  69. } quick6502_cpuconfig;
  70. /*** Signal that we can send to the CPU ***/
  71. typedef enum
  72. {
  73. Q6502_NO_SIGNAL = 0,
  74. Q6502_IRQ_SIGNAL,
  75. Q6502_NMI_SIGNAL,
  76. Q6502_STOPLOOP_SIGNAL
  77. } quick6502_signal;
  78. /*** Some 6502 related definitions ***/
  79. /*** P register flags ***/
  80. #define Q6502_N_FLAG 0x80 /* Negavite flag */
  81. #define Q6502_V_FLAG 0x40 /* oVerflow flag */
  82. #define Q6502_R_FLAG 0x20 /* Not a real flag, but need to be to 1 on PHP */
  83. #define Q6502_B_FLAG 0x10 /* Break flag */
  84. #define Q6502_D_FLAG 0x08 /* BCD flag */
  85. #define Q6502_I_FLAG 0x04 /* IRQ/BRK flag */
  86. #define Q6502_Z_FLAG 0x02 /* Zero flag */
  87. #define Q6502_C_FLAG 0x01 /* Carry flag */
  88. /*** Interuption Vectors ***/
  89. #define Q6502_NMI_LOW 0xFFFA
  90. #define Q6502_NMI_HIGH 0xFFFB
  91. #define Q6502_RESET_LOW 0xFFFC
  92. #define Q6502_RESET_HIGH 0xFFFD
  93. #define Q6502_IRQ_LOW 0xFFFE
  94. #define Q6502_IRQ_HIGH 0xFFFF
  95. /**
  96. * Initialise the CPU
  97. *
  98. * Inputs:
  99. *
  100. * - CPU Init structure:
  101. * +- Memory Read function pointer
  102. * +- Memory Write function pointer
  103. * +- Fast memory read function pointer (for opcodes read)
  104. * +- Fast page 0 function / Read/Write
  105. * +- Fast page 1 function / Read/Write
  106. *
  107. * Output:
  108. *
  109. * (void *): An opaque pointer to the internal structure of the CPU
  110. *
  111. */
  112. quick6502_cpu *quick6502_init(quick6502_cpuconfig *config);
  113. /* Reset the CPU (must be done after init) */
  114. void quick6502_reset(quick6502_cpu *cpu);
  115. /**
  116. * Run cpu for at least X cycles
  117. *
  118. * Output:
  119. *
  120. * int: (Number of cycle really done) - (Number of cycle asked)
  121. */
  122. int quick6502_run(quick6502_cpu *cpu, int cycles);
  123. /** Loop CPU until explicit quit */
  124. void quick6502_loop(quick6502_cpu *cpu);
  125. /** Run CPU for one instruction */
  126. void quick6502_exec(quick6502_cpu *cpu);
  127. /** Send IRQ/NMI/EXITLOOP signal to CPU */
  128. void quick6502_int(quick6502_cpu *cpu, quick6502_signal signal);
  129. /** Dump CPU State to the given file */
  130. void quick6502_dump(quick6502_cpu *cpu, FILE * fp);
  131. /** Get current instruction name at specified address and put it into buffer */
  132. #define MINE
  133. int quick6502_getinstruction(quick6502_cpu *cpu, char interpret,
  134. unsigned short addr, char *buffer, int *strlength);
  135. /**
  136. * Free the CPU
  137. *
  138. * This function will free the CPU only if it's not currently used, it will
  139. * return !0 if everything goes well and 0 if the free is impossible
  140. */
  141. int quick6502_free(quick6502_cpu *cpu);
  142. #endif /* _QUICK6502_CORECPU_H_ */