PrintInstrToString.cpp
上传用户:luhy168
上传日期:2022-01-10
资源大小:240k
文件大小:60k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. //------------------------------------------------------------------------------
  2. // Name: PrintInstrToString.cpp
  3. // Desc: Holds the functions involved in printing an instruction
  4. //       from the 6502 into a string.
  5. //------------------------------------------------------------------------------
  6. // Includes
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include "PrintInstrToString.h"
  10. //------------------------------------------------------------------------------
  11. // Name: PrintAddrMode_Absolute()
  12. // Desc: Prints the the instruction with the absolute addressing mode
  13. //       and returns the number of bytes this addressing mode uses.
  14. //------------------------------------------------------------------------------
  15. BYTE PrintAddrMode_Absolute(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  16. {
  17. // Print the memory byte.
  18. sprintf(strDest, " %02X %02X", GetMemoryByte(wPC+1), GetMemoryByte(wPC+2));
  19. // Print the instruction name to the instruction string.
  20. memcpy(&strDest[7], strInstrName, 3);
  21. // Print the operand for the instruction.
  22. sprintf(&strDest[10], " $%02X%02X", GetMemoryByte(wPC+2), GetMemoryByte(wPC+1));
  23. // Return the number of bytes for this addressing mode.
  24. return 2;
  25. } // end PrintAddrMode_Absolute()
  26. //------------------------------------------------------------------------------
  27. // Name: PrintAddrMode_AbsoluteX()
  28. // Desc: Prints the the instruction with the absolute X addressing mode
  29. //       and returns the number of bytes this addressing mode uses.
  30. //------------------------------------------------------------------------------
  31. BYTE PrintAddrMode_AbsoluteX(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  32. {
  33. // Print the memory byte.
  34. sprintf(strDest, " %02X %02X", GetMemoryByte(wPC+1), GetMemoryByte(wPC+2));
  35. // Print the instruction name to the instruction string.
  36. memcpy(&strDest[7], strInstrName, 3);
  37. // Print the operand for the instruction.
  38. sprintf(&strDest[10], " $%02X%02X, X", GetMemoryByte(wPC+2), GetMemoryByte(wPC+1));
  39. // Return the number of bytes for this addressing mode.
  40. return 2;
  41. } // end PrintAddrMode_AbsoluteX()
  42. //------------------------------------------------------------------------------
  43. // Name: PrintAddrMode_AbsoluteY()
  44. // Desc: Prints the the instruction with the absolute Y addressing mode
  45. //       and returns the number of bytes this addressing mode uses.
  46. //------------------------------------------------------------------------------
  47. BYTE PrintAddrMode_AbsoluteY(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  48. {
  49. // Print the memory byte.
  50. sprintf(strDest, " %02X %02X", GetMemoryByte(wPC+1), GetMemoryByte(wPC+2));
  51. // Print the instruction name to the instruction string.
  52. memcpy(&strDest[7], strInstrName, 3);
  53. // Print the operand for the instruction.
  54. sprintf(&strDest[10], " $%02X%02X, Y", GetMemoryByte(wPC+2), GetMemoryByte(wPC+1));
  55. // Return the number of bytes for this addressing mode.
  56. return 2;
  57. } // end PrintAddrMode_AbsoluteY()
  58. //------------------------------------------------------------------------------
  59. // Name: PrintAddrMode_Accumulator()
  60. // Desc: Prints the the instruction with the accumulator addressing mode
  61. //       and returns the number of bytes this addressing mode uses.
  62. //------------------------------------------------------------------------------
  63. BYTE PrintAddrMode_Accumulator(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  64. {
  65. // Print the memory byte.
  66. sprintf(strDest, " %02X", GetMemoryByte(wPC+1));
  67. // Print the instruction name to the instruction string.
  68. memcpy(&strDest[7], strInstrName, 3);
  69. // Print the operand for the instruction.
  70. sprintf(&strDest[10], " A");
  71. // Return the number of bytes for this addressing mode.
  72. return 0;
  73. } // end PrintAddrMode_Accumulator()
  74. //------------------------------------------------------------------------------
  75. // Name: PrintAddrMode_Immediate()
  76. // Desc: Prints the the instruction with the immediate addressing mode
  77. //       and returns the number of bytes this addressing mode uses.
  78. //------------------------------------------------------------------------------
  79. BYTE PrintAddrMode_Immediate(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  80. {
  81. // Print the memory byte.
  82. sprintf(strDest, " %02X", GetMemoryByte(wPC+1));
  83. // Print the instruction name to the instruction string.
  84. memcpy(&strDest[7], strInstrName, 3);
  85. // Print the operand for the instruction.
  86. sprintf(&strDest[10], " #$%02X", GetMemoryByte(wPC+1));
  87. // Return the number of bytes for this addressing mode.
  88. return 1;
  89. } // end PrintAddrMode_Immediate()
  90. //------------------------------------------------------------------------------
  91. // Name: PrintAddrMode_Implied()
  92. // Desc: Prints the the instruction with the implied addressing mode
  93. //       and returns the number of bytes this addressing mode uses.
  94. //------------------------------------------------------------------------------
  95. BYTE PrintAddrMode_Implied(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  96. {
  97. // Print the memory byte.
  98. sprintf(strDest, "   ");
  99. // Print the instruction name to the instruction string.
  100. memcpy(&strDest[7], strInstrName, 3);
  101. // Print the operand for the instruction.
  102. sprintf(&strDest[10], " ");
  103. // Return the number of bytes for this addressing mode.
  104. return 0;
  105. } // end PrintAddrMode_Implied()
  106. //------------------------------------------------------------------------------
  107. // Name: PrintAddrMode_PostIndexedIndirect()
  108. // Desc: Prints the the instruction with the post indexed indirect addressing mode
  109. //       and returns the number of bytes this addressing mode uses.
  110. //------------------------------------------------------------------------------
  111. BYTE PrintAddrMode_PostIndexedIndirect(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  112. {
  113. // Print the memory byte.
  114. sprintf(strDest, " %02X", GetMemoryByte(wPC+1));
  115. // Print the instruction name to the instruction string.
  116. memcpy(&strDest[7], strInstrName, 3);
  117. // Print the operand for the instruction.
  118. sprintf(&strDest[10], " ($%02X), Y", GetMemoryByte(wPC+1));
  119. // Return the number of bytes for this addressing mode.
  120. return 1;
  121. } // end PrintAddrMode_PostIndexedIndirect()
  122. //------------------------------------------------------------------------------
  123. // Name: PrintAddrMode_PreIndexedIndirect()
  124. // Desc: Prints the the instruction with the pre indexed indirect addressing mode
  125. //       and returns the number of bytes this addressing mode uses.
  126. //------------------------------------------------------------------------------
  127. BYTE PrintAddrMode_PreIndexedIndirect(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  128. {
  129. // Print the memory byte.
  130. sprintf(strDest, " %02X", GetMemoryByte(wPC+1));
  131. // Print the instruction name to the instruction string.
  132. memcpy(&strDest[7], strInstrName, 3);
  133. // Print the operand for the instruction.
  134. sprintf(&strDest[10], " ($%02X, X)", GetMemoryByte(wPC+1));
  135. // Return the number of bytes for this addressing mode.
  136. return 1;
  137. } // end PrintAddrMode_PreIndexedIndirect()
  138. //------------------------------------------------------------------------------
  139. // Name: PrintAddrMode_Indirect()
  140. // Desc: Prints the the instruction with the indirect addressing mode
  141. //       and returns the number of bytes this addressing mode uses.
  142. //------------------------------------------------------------------------------
  143. BYTE PrintAddrMode_Indirect(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  144. {
  145. // Print the memory byte.
  146. sprintf(strDest, " %02X %02X", GetMemoryByte(wPC+1), GetMemoryByte(wPC+2));
  147. // Print the instruction name to the instruction string.
  148. memcpy(&strDest[7], strInstrName, 3);
  149. // Print the operand for the instruction.
  150. sprintf(&strDest[10], " ($%02X%02X)", GetMemoryByte(wPC+2), GetMemoryByte(wPC+1));
  151. // Return the number of bytes for this addressing mode.
  152. return 2;
  153. } // end PrintAddrMode_Indirect()
  154. //------------------------------------------------------------------------------
  155. // Name: PrintAddrMode_Relative()
  156. // Desc: Prints the the instruction with the relative addressing mode
  157. //       and returns the number of bytes this addressing mode uses.
  158. //------------------------------------------------------------------------------
  159. BYTE PrintAddrMode_Relative(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  160. {
  161. // Print the memory byte.
  162. sprintf(strDest, " %02X", GetMemoryByte(wPC+1));
  163. // Print the instruction name to the instruction string.
  164. memcpy(&strDest[7], strInstrName, 3);
  165. // Print the operand for the instruction.
  166. sprintf(&strDest[10], " $%02X", GetMemoryByte(wPC+1));
  167. // Return the number of bytes for this addressing mode.
  168. return 1;
  169. } // end PrintAddrMode_Relative()
  170. //------------------------------------------------------------------------------
  171. // Name: PrintAddrMode_ZeroPage()
  172. // Desc: Prints the the instruction with the zero page addressing mode
  173. //       and returns the number of bytes this addressing mode uses.
  174. //------------------------------------------------------------------------------
  175. BYTE PrintAddrMode_ZeroPage(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  176. {
  177. // Print the memory byte.
  178. sprintf(strDest, " %02X", GetMemoryByte(wPC+1));
  179. // Print the instruction name to the instruction string.
  180. memcpy(&strDest[7], strInstrName, 3);
  181. // Print the operand for the instruction.
  182. sprintf(&strDest[10], " $%02X", GetMemoryByte(wPC+1));
  183. // Return the number of bytes for this addressing mode.
  184. return 1;
  185. } // end PrintAddrMode_ZeroPage()
  186. //------------------------------------------------------------------------------
  187. // Name: PrintAddrMode_ZeroPageX()
  188. // Desc: Prints the the instruction with the zero page X addressing mode
  189. //       and returns the number of bytes this addressing mode uses.
  190. //------------------------------------------------------------------------------
  191. BYTE PrintAddrMode_ZeroPageX(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  192. {
  193. // Print the memory byte.
  194. sprintf(strDest, " %02X", GetMemoryByte(wPC+1));
  195. // Print the instruction name to the instruction string.
  196. memcpy(&strDest[7], strInstrName, 3);
  197. // Print the operand for the instruction.
  198. sprintf(&strDest[10], " $%02X, X", GetMemoryByte(wPC+1));
  199. // Return the number of bytes for this addressing mode.
  200. return 1;
  201. } // end PrintAddrMode_ZeroPageX()
  202. //------------------------------------------------------------------------------
  203. // Name: PrintAddrMode_ZeroPageY()
  204. // Desc: Prints the the instruction with the zero page Y addressing mode
  205. //       and returns the number of bytes this addressing mode uses.
  206. //------------------------------------------------------------------------------
  207. BYTE PrintAddrMode_ZeroPageY(LPSTR strDest, LPSTR strInstrName, WORD wPC)
  208. {
  209. // Print the memory byte.
  210. sprintf(strDest, " %02X", GetMemoryByte(wPC+1));
  211. // Print the instruction name to the instruction string.
  212. memcpy(&strDest[7], strInstrName, 3);
  213. // Print the operand for the instruction.
  214. sprintf(&strDest[10], " $%02X, Y", GetMemoryByte(wPC+1));
  215. // Return the number of bytes for this addressing mode.
  216. return 1;
  217. } // end PrintAddrMode_ZeroPageY()
  218. //------------------------------------------------------------------------------
  219. // Name: PrintADC()
  220. // Desc: Prints the ADC instruction to a string and returns the number
  221. //       of bytes for the entire instruction.
  222. //------------------------------------------------------------------------------
  223. BYTE PrintADC(LPSTR strDest, WORD wPC, BYTE byOpcode)
  224. {
  225. LPSTR strInstrName = "ADC"; // Name of the instruction being printed.
  226. // Depending on the opcode of the instruction, different addressing
  227. // modes apply. This means that different strings must be printed
  228. // depending on the addressing mode.
  229. switch (byOpcode)
  230. {
  231. case 0x61:
  232. return (1 + PrintAddrMode_PreIndexedIndirect(strDest, strInstrName, wPC));
  233. case 0x65:
  234. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  235. case 0x69:
  236. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  237. case 0x6D:
  238. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  239. case 0x71:
  240. return (1 + PrintAddrMode_PostIndexedIndirect(strDest, strInstrName, wPC));
  241. case 0x75:
  242. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  243. case 0x79:
  244. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  245. case 0x7D:
  246. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  247. default:
  248. return 0;
  249. }
  250. } // end PrintADC()
  251. //------------------------------------------------------------------------------
  252. // Name: PrintAND()
  253. // Desc: Prints the AND instruction to a string and returns the number
  254. //       of bytes for the entire instruction.
  255. //------------------------------------------------------------------------------
  256. BYTE PrintAND(LPSTR strDest, WORD wPC, BYTE byOpcode)
  257. {
  258. LPSTR strInstrName = "AND"; // Name of the instruction being printed.
  259. // Depending on the opcode of the instruction, different addressing
  260. // modes apply. This means that different strings must be printed
  261. // depending on the addressing mode.
  262. switch (byOpcode)
  263. {
  264. case 0x21:
  265. return (1 + PrintAddrMode_PreIndexedIndirect(strDest, strInstrName, wPC));
  266. case 0x25:
  267. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  268. case 0x29:
  269. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  270. case 0x2D:
  271. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  272. case 0x31:
  273. return (1 + PrintAddrMode_PostIndexedIndirect(strDest, strInstrName, wPC));
  274. case 0x35:
  275. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  276. case 0x39:
  277. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  278. case 0x3D:
  279. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  280. default:
  281. return 0;
  282. }
  283. } // end PrintAND()
  284. //------------------------------------------------------------------------------
  285. // Name: PrintASL()
  286. // Desc: Prints the ASL instruction to a string and returns the number
  287. //       of bytes for the entire instruction.
  288. //------------------------------------------------------------------------------
  289. BYTE PrintASL(LPSTR strDest, WORD wPC, BYTE byOpcode)
  290. {
  291. LPSTR strInstrName = "ASL"; // Name of the instruction being printed.
  292. // Depending on the opcode of the instruction, different addressing
  293. // modes apply. This means that different strings must be printed
  294. // depending on the addressing mode.
  295. switch (byOpcode)
  296. {
  297. case 0x06:
  298. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  299. case 0x0A:
  300. return (1 + PrintAddrMode_Accumulator(strDest, strInstrName, wPC));
  301. case 0x0E:
  302. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  303. case 0x16:
  304. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  305. case 0x1E:
  306. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  307. default:
  308. return 0;
  309. }
  310. } // end PrintASL()
  311. //------------------------------------------------------------------------------
  312. // Name: PrintBCC()
  313. // Desc: Prints the BCC instruction to a string and returns the number
  314. //       of bytes for the entire instruction.
  315. //------------------------------------------------------------------------------
  316. BYTE PrintBCC(LPSTR strDest, WORD wPC, BYTE byOpcode)
  317. {
  318. LPSTR strInstrName = "BCC"; // Name of the instruction being printed.
  319. return (1 + PrintAddrMode_Relative(strDest, strInstrName, wPC));
  320. } // end PrintBCC()
  321.   
  322. //------------------------------------------------------------------------------
  323. // Name: PrintBCS()
  324. // Desc: Prints the BCS instruction to a string and returns the number
  325. //       of bytes for the entire instruction.
  326. //------------------------------------------------------------------------------
  327. BYTE PrintBCS(LPSTR strDest, WORD wPC, BYTE byOpcode)
  328. {
  329. LPSTR strInstrName = "BCS"; // Name of the instruction being printed.
  330. return (1 + PrintAddrMode_Relative(strDest, strInstrName, wPC));
  331. } // end PrintBCS()
  332. //------------------------------------------------------------------------------
  333. // Name: PrintBEQ()
  334. // Desc: Prints the BEQ instruction to a string and returns the number
  335. //       of bytes for the entire instruction.
  336. //------------------------------------------------------------------------------
  337. BYTE PrintBEQ(LPSTR strDest, WORD wPC, BYTE byOpcode)
  338. {
  339. LPSTR strInstrName = "BEQ"; // Name of the instruction being printed.
  340. return (1 + PrintAddrMode_Relative(strDest, strInstrName, wPC));
  341. } // end PrintBEQ()
  342. //------------------------------------------------------------------------------
  343. // Name: PrintBIT()
  344. // Desc: Prints the BIT instruction to a string and returns the number
  345. //       of bytes for the entire instruction.
  346. //------------------------------------------------------------------------------
  347. BYTE PrintBIT(LPSTR strDest, WORD wPC, BYTE byOpcode)
  348. {
  349. LPSTR strInstrName = "BIT"; // Name of the instruction being printed.
  350. // Depending on the opcode of the instruction, different addressing
  351. // modes apply. This means that different strings must be printed
  352. // depending on the addressing mode.
  353. switch (byOpcode)
  354. {
  355. case 0x24:
  356. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  357. case 0x2C:
  358. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  359. default:
  360. return 0;
  361. }
  362. } // end PrintBIT()
  363. //------------------------------------------------------------------------------
  364. // Name: PrintBMI()
  365. // Desc: Prints the BMI instruction to a string and returns the number
  366. //       of bytes for the entire instruction.
  367. //------------------------------------------------------------------------------
  368. BYTE PrintBMI(LPSTR strDest, WORD wPC, BYTE byOpcode)
  369. {
  370. LPSTR strInstrName = "BMI"; // Name of the instruction being printed.
  371. return (1 + PrintAddrMode_Relative(strDest, strInstrName, wPC));
  372. } // end PrintBMI()
  373. //------------------------------------------------------------------------------
  374. // Name: PrintBNE()
  375. // Desc: Prints the BNE instruction to a string and returns the number
  376. //       of bytes for the entire instruction.
  377. //------------------------------------------------------------------------------
  378. BYTE PrintBNE(LPSTR strDest, WORD wPC, BYTE byOpcode)
  379. {
  380. LPSTR strInstrName = "BNE"; // Name of the instruction being printed.
  381. return (1 + PrintAddrMode_Relative(strDest, strInstrName, wPC));
  382. } // end PrintBNE()
  383. //------------------------------------------------------------------------------
  384. // Name: PrintBPL()
  385. // Desc: Prints the BPL instruction to a string and returns the number
  386. //       of bytes for the entire instruction.
  387. //------------------------------------------------------------------------------
  388. BYTE PrintBPL(LPSTR strDest, WORD wPC, BYTE byOpcode)
  389. {
  390. LPSTR strInstrName = "BPL"; // Name of the instruction being printed.
  391. return (1 + PrintAddrMode_Relative(strDest, strInstrName, wPC));
  392. } // end PrintBPL()
  393. //------------------------------------------------------------------------------
  394. // Name: PrintBRK()
  395. // Desc: Prints the BRK instruction to a string and returns the number
  396. //       of bytes for the entire instruction.
  397. //------------------------------------------------------------------------------
  398. BYTE PrintBRK(LPSTR strDest, WORD wPC, BYTE byOpcode)
  399. {
  400. LPSTR strInstrName = "BRK"; // Name of the instruction being printed.
  401. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  402. } // end PrintBRK()
  403. //------------------------------------------------------------------------------
  404. // Name: PrintBVC()
  405. // Desc: Prints the BVC instruction to a string and returns the number
  406. //       of bytes for the entire instruction.
  407. //------------------------------------------------------------------------------
  408. BYTE PrintBVC(LPSTR strDest, WORD wPC, BYTE byOpcode)
  409. {
  410. LPSTR strInstrName = "BVC"; // Name of the instruction being printed.
  411. return (1 + PrintAddrMode_Relative(strDest, strInstrName, wPC));
  412. } // end PrintBVC()
  413. //------------------------------------------------------------------------------
  414. // Name: PrintBVS()
  415. // Desc: Prints the BVS instruction to a string and returns the number
  416. //       of bytes for the entire instruction.
  417. //------------------------------------------------------------------------------
  418. BYTE PrintBVS(LPSTR strDest, WORD wPC, BYTE byOpcode)
  419. {
  420. LPSTR strInstrName = "BVS"; // Name of the instruction being printed.
  421. return (1 + PrintAddrMode_Relative(strDest, strInstrName, wPC));
  422. } // end PrintBVS()
  423. //------------------------------------------------------------------------------
  424. // Name: PrintCLC()
  425. // Desc: Prints the CLC instruction to a string and returns the number
  426. //       of bytes for the entire instruction.
  427. //------------------------------------------------------------------------------
  428. BYTE PrintCLC(LPSTR strDest, WORD wPC, BYTE byOpcode)
  429. {
  430. LPSTR strInstrName = "CLC"; // Name of the instruction being printed.
  431. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  432. } // end PrintCLC()
  433. //------------------------------------------------------------------------------
  434. // Name: PrintCLD()
  435. // Desc: Prints the CLD instruction to a string and returns the number
  436. //       of bytes for the entire instruction.
  437. //------------------------------------------------------------------------------
  438. BYTE PrintCLD(LPSTR strDest, WORD wPC, BYTE byOpcode)
  439. {
  440. LPSTR strInstrName = "CLD"; // Name of the instruction being printed.
  441. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  442. } // end PrintCLD()
  443. //------------------------------------------------------------------------------
  444. // Name: PrintCLI()
  445. // Desc: Prints the CLI instruction to a string and returns the number
  446. //       of bytes for the entire instruction.
  447. //------------------------------------------------------------------------------
  448. BYTE PrintCLI(LPSTR strDest, WORD wPC, BYTE byOpcode)
  449. {
  450. LPSTR strInstrName = "CLI"; // Name of the instruction being printed.
  451. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  452. } // end PrintCLI()
  453. //------------------------------------------------------------------------------
  454. // Name: PrintCLV()
  455. // Desc: Prints the CLV instruction to a string and returns the number
  456. //       of bytes for the entire instruction.
  457. //------------------------------------------------------------------------------
  458. BYTE PrintCLV(LPSTR strDest, WORD wPC, BYTE byOpcode)
  459. {
  460. LPSTR strInstrName = "CLV"; // Name of the instruction being printed.
  461. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  462. } // end PrintCLV()
  463. //------------------------------------------------------------------------------
  464. // Name: PrintCMP()
  465. // Desc: Prints the CMP instruction to a string and returns the number
  466. //       of bytes for the entire instruction.
  467. //------------------------------------------------------------------------------
  468. BYTE PrintCMP(LPSTR strDest, WORD wPC, BYTE byOpcode)
  469. {
  470. LPSTR strInstrName = "CMP"; // Name of the instruction being printed.
  471. // Depending on the opcode of the instruction, different addressing
  472. // modes apply. This means that different strings must be printed
  473. // depending on the addressing mode.
  474. switch (byOpcode)
  475. {
  476. case 0xC1:
  477. return (1 + PrintAddrMode_PreIndexedIndirect(strDest, strInstrName, wPC));
  478. case 0xC5:
  479. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  480. case 0xC9:
  481. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  482. case 0xCD:
  483. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  484. case 0xD1:
  485. return (1 + PrintAddrMode_PostIndexedIndirect(strDest, strInstrName, wPC));
  486. case 0xD5:
  487. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  488. case 0xD9:
  489. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  490. case 0xDD:
  491. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  492. default:
  493. return 0;
  494. }
  495. } // end PrintCMP()
  496. //------------------------------------------------------------------------------
  497. // Name: PrintCPX()
  498. // Desc: Prints the CPX instruction to a string and returns the number
  499. //       of bytes for the entire instruction.
  500. //------------------------------------------------------------------------------
  501. BYTE PrintCPX(LPSTR strDest, WORD wPC, BYTE byOpcode)
  502. {
  503. LPSTR strInstrName = "CPX"; // Name of the instruction being printed.
  504. // Depending on the opcode of the instruction, different addressing
  505. // modes apply. This means that different strings must be printed
  506. // depending on the addressing mode.
  507. switch (byOpcode)
  508. {
  509. case 0xE0:
  510. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  511. case 0xE4:
  512. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  513. case 0xEC:
  514. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  515. default:
  516. return 0;
  517. }
  518. } // end PrintCPX()
  519. //------------------------------------------------------------------------------
  520. // Name: PrintCPY()
  521. // Desc: Prints the CPY instruction to a string and returns the number
  522. //       of bytes for the entire instruction.
  523. //------------------------------------------------------------------------------
  524. BYTE PrintCPY(LPSTR strDest, WORD wPC, BYTE byOpcode)
  525. {
  526. LPSTR strInstrName = "CPY"; // Name of the instruction being printed.
  527. // Depending on the opcode of the instruction, different addressing
  528. // modes apply. This means that different strings must be printed
  529. // depending on the addressing mode.
  530. switch (byOpcode)
  531. {
  532. case 0xC0:
  533. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  534. case 0xC4:
  535. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  536. case 0xCC:
  537. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  538. default:
  539. return 0;
  540. }
  541. } // end PrintCPY()
  542. //------------------------------------------------------------------------------
  543. // Name: PrintDEC()
  544. // Desc: Prints the DEC instruction to a string and returns the number
  545. //       of bytes for the entire instruction.
  546. //------------------------------------------------------------------------------
  547. BYTE PrintDEC(LPSTR strDest, WORD wPC, BYTE byOpcode)
  548. {
  549. LPSTR strInstrName = "DEC"; // Name of the instruction being printed.
  550. // Depending on the opcode of the instruction, different addressing
  551. // modes apply. This means that different strings must be printed
  552. // depending on the addressing mode.
  553. switch (byOpcode)
  554. {
  555. case 0xC6:
  556. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  557. case 0xCE:
  558. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  559. case 0xD6:
  560. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  561. case 0xDE:
  562. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  563. default:
  564. return 0;
  565. }
  566. } // end PrintDEC()
  567. //------------------------------------------------------------------------------
  568. // Name: PrintDEX()
  569. // Desc: Prints the DEX instruction to a string and returns the number
  570. //       of bytes for the entire instruction.
  571. //------------------------------------------------------------------------------
  572. BYTE PrintDEX(LPSTR strDest, WORD wPC, BYTE byOpcode)
  573. {
  574. LPSTR strInstrName = "DEX"; // Name of the instruction being printed.
  575. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  576. } // end PrintDEX()
  577. //------------------------------------------------------------------------------
  578. // Name: PrintDEY()
  579. // Desc: Prints the DEY instruction to a string and returns the number
  580. //       of bytes for the entire instruction.
  581. //------------------------------------------------------------------------------
  582. BYTE PrintDEY(LPSTR strDest, WORD wPC, BYTE byOpcode)
  583. {
  584. LPSTR strInstrName = "DEY"; // Name of the instruction being printed.
  585. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  586. } // end PrintDEY()
  587. //------------------------------------------------------------------------------
  588. // Name: PrintEOR()
  589. // Desc: Prints the EOR instruction to a string and returns the number
  590. //       of bytes for the entire instruction.
  591. //------------------------------------------------------------------------------
  592. BYTE PrintEOR(LPSTR strDest, WORD wPC, BYTE byOpcode)
  593. {
  594. LPSTR strInstrName = "EOR"; // Name of the instruction being printed.
  595. // Depending on the opcode of the instruction, different addressing
  596. // modes apply. This means that different strings must be printed
  597. // depending on the addressing mode.
  598. switch (byOpcode)
  599. {
  600. case 0x41:
  601. return (1 + PrintAddrMode_PreIndexedIndirect(strDest, strInstrName, wPC));
  602. case 0x45:
  603. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  604. case 0x49:
  605. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  606. case 0x4D:
  607. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  608. case 0x51:
  609. return (1 + PrintAddrMode_PostIndexedIndirect(strDest, strInstrName, wPC));
  610. case 0x55:
  611. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  612. case 0x59:
  613. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  614. case 0x5D:
  615. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  616. default:
  617. return 0;
  618. }
  619. } // end PrintEOR()
  620. //------------------------------------------------------------------------------
  621. // Name: PrintINC()
  622. // Desc: Prints the INC instruction to a string and returns the number
  623. //       of bytes for the entire instruction.
  624. //------------------------------------------------------------------------------
  625. BYTE PrintINC(LPSTR strDest, WORD wPC, BYTE byOpcode)
  626. {
  627. LPSTR strInstrName = "INC"; // Name of the instruction being printed.
  628. // Depending on the opcode of the instruction, different addressing
  629. // modes apply. This means that different strings must be printed
  630. // depending on the addressing mode.
  631. switch (byOpcode)
  632. {
  633. case 0xE6:
  634. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  635. case 0xEE:
  636. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  637. case 0xF6:
  638. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  639. case 0xFE:
  640. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  641. default:
  642. return 0;
  643. }
  644. } // end PrintINC()
  645. //------------------------------------------------------------------------------
  646. // Name: PrintINX()
  647. // Desc: Prints the INX instruction to a string and returns the number
  648. //       of bytes for the entire instruction.
  649. //------------------------------------------------------------------------------
  650. BYTE PrintINX(LPSTR strDest, WORD wPC, BYTE byOpcode)
  651. {
  652. LPSTR strInstrName = "INX"; // Name of the instruction being printed.
  653. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  654. } // end PrintINX()
  655. //------------------------------------------------------------------------------
  656. // Name: PrintINY()
  657. // Desc: Prints the INY instruction to a string and returns the number
  658. //       of bytes for the entire instruction.
  659. //------------------------------------------------------------------------------
  660. BYTE PrintINY(LPSTR strDest, WORD wPC, BYTE byOpcode)
  661. {
  662. LPSTR strInstrName = "INY"; // Name of the instruction being printed.
  663. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  664. } // end PrintINY()
  665. //------------------------------------------------------------------------------
  666. // Name: PrintJMP()
  667. // Desc: Prints the JMP instruction to a string and returns the number
  668. //       of bytes for the entire instruction.
  669. //------------------------------------------------------------------------------
  670. BYTE PrintJMP(LPSTR strDest, WORD wPC, BYTE byOpcode)
  671. {
  672. LPSTR strInstrName = "JMP"; // Name of the instruction being printed.
  673. // Depending on the opcode of the instruction, different addressing
  674. // modes apply. This means that different strings must be printed
  675. // depending on the addressing mode.
  676. switch (byOpcode)
  677. {
  678. case 0x4C:
  679. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  680. case 0x6C:
  681. return (1 + PrintAddrMode_Indirect(strDest, strInstrName, wPC));
  682. default:
  683. return 0;
  684. }
  685. } // end PrintJMP()
  686. //------------------------------------------------------------------------------
  687. // Name: PrintJSR()
  688. // Desc: Prints the JSR instruction to a string and returns the number
  689. //       of bytes for the entire instruction.
  690. //------------------------------------------------------------------------------
  691. BYTE PrintJSR(LPSTR strDest, WORD wPC, BYTE byOpcode)
  692. {
  693. LPSTR strInstrName = "JSR"; // Name of the instruction being printed.
  694. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  695. } // end PrintJSR()
  696. //------------------------------------------------------------------------------
  697. // Name: PrintLDA()
  698. // Desc: Prints the LDA instruction to a string and returns the number
  699. //       of bytes for the entire instruction.
  700. //------------------------------------------------------------------------------
  701. BYTE PrintLDA(LPSTR strDest, WORD wPC, BYTE byOpcode)
  702. {
  703. LPSTR strInstrName = "LDA"; // Name of the instruction being printed.
  704. // Depending on the opcode of the instruction, different addressing
  705. // modes apply. This means that different strings must be printed
  706. // depending on the addressing mode.
  707. switch (byOpcode)
  708. {
  709. case 0xA1:
  710. return (1 + PrintAddrMode_PreIndexedIndirect(strDest, strInstrName, wPC));
  711. case 0xA5:
  712. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  713. case 0xA9:
  714. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  715. case 0xAD:
  716. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  717. case 0xB1:
  718. return (1 + PrintAddrMode_PostIndexedIndirect(strDest, strInstrName, wPC));
  719. case 0xB5:
  720. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  721. case 0xB9:
  722. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  723. case 0xBD:
  724. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  725. default:
  726. return 0;
  727. }
  728. } // end PrintLDA()
  729. //------------------------------------------------------------------------------
  730. // Name: PrintLDX()
  731. // Desc: Prints the LDX instruction to a string and returns the number
  732. //       of bytes for the entire instruction.
  733. //------------------------------------------------------------------------------
  734. BYTE PrintLDX(LPSTR strDest, WORD wPC, BYTE byOpcode)
  735. {
  736. LPSTR strInstrName = "LDX"; // Name of the instruction being printed.
  737. // Depending on the opcode of the instruction, different addressing
  738. // modes apply. This means that different strings must be printed
  739. // depending on the addressing mode.
  740. switch (byOpcode)
  741. {
  742. case 0xA6:
  743. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  744. case 0xA2:
  745. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  746. case 0xAE:
  747. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  748. case 0xB6:
  749. return (1 + PrintAddrMode_ZeroPageY(strDest, strInstrName, wPC));
  750. case 0xBE:
  751. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  752. default:
  753. return 0;
  754. }
  755. } // end PrintLDX()
  756. //------------------------------------------------------------------------------
  757. // Name: PrintLDY()
  758. // Desc: Prints the LDY instruction to a string and returns the number
  759. //       of bytes for the entire instruction.
  760. //------------------------------------------------------------------------------
  761. BYTE PrintLDY(LPSTR strDest, WORD wPC, BYTE byOpcode)
  762. {
  763. LPSTR strInstrName = "LDY"; // Name of the instruction being printed.
  764. // Depending on the opcode of the instruction, different addressing
  765. // modes apply. This means that different strings must be printed
  766. // depending on the addressing mode.
  767. switch (byOpcode)
  768. {
  769. case 0xA4:
  770. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  771. case 0xA0:
  772. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  773. case 0xAC:
  774. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  775. case 0xB4:
  776. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  777. case 0xBC:
  778. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  779. default:
  780. return 0;
  781. }
  782. } // end PrintLDY()
  783. //------------------------------------------------------------------------------
  784. // Name: PrintLSR()
  785. // Desc: Prints the LSR instruction to a string and returns the number
  786. //       of bytes for the entire instruction.
  787. //------------------------------------------------------------------------------
  788. BYTE PrintLSR(LPSTR strDest, WORD wPC, BYTE byOpcode)
  789. {
  790. LPSTR strInstrName = "LSR"; // Name of the instruction being printed.
  791. // Depending on the opcode of the instruction, different addressing
  792. // modes apply. This means that different strings must be printed
  793. // depending on the addressing mode.
  794. switch (byOpcode)
  795. {
  796. case 0x46:
  797. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  798. case 0x4A:
  799. return (1 + PrintAddrMode_Accumulator(strDest, strInstrName, wPC));
  800. case 0x4E:
  801. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  802. case 0x56:
  803. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  804. case 0x5E:
  805. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  806. default:
  807. return 0;
  808. }
  809. } // end PrintLSR()
  810. //------------------------------------------------------------------------------
  811. // Name: PrintNOP()
  812. // Desc: Prints the NOP instruction to a string and returns the number
  813. //       of bytes for the entire instruction.
  814. //------------------------------------------------------------------------------
  815. BYTE PrintNOP(LPSTR strDest, WORD wPC, BYTE byOpcode)
  816. {
  817. LPSTR strInstrName = "NOP"; // Name of the instruction being printed.
  818. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  819. } // end PrintNOP()
  820. //------------------------------------------------------------------------------
  821. // Name: PrintORA()
  822. // Desc: Prints the ORA instruction to a string and returns the number
  823. //       of bytes for the entire instruction.
  824. //------------------------------------------------------------------------------
  825. BYTE PrintORA(LPSTR strDest, WORD wPC, BYTE byOpcode)
  826. {
  827. LPSTR strInstrName = "ORA"; // Name of the instruction being printed.
  828. // Depending on the opcode of the instruction, different addressing
  829. // modes apply. This means that different strings must be printed
  830. // depending on the addressing mode.
  831. switch (byOpcode)
  832. {
  833. case 0x01:
  834. return (1 + PrintAddrMode_PreIndexedIndirect(strDest, strInstrName, wPC));
  835. case 0x05:
  836. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  837. case 0x09:
  838. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  839. case 0x0D:
  840. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  841. case 0x11:
  842. return (1 + PrintAddrMode_PostIndexedIndirect(strDest, strInstrName, wPC));
  843. case 0x15:
  844. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  845. case 0x19:
  846. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  847. case 0x1D:
  848. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  849. default:
  850. return 0;
  851. }
  852. } // end PrintORA()
  853. //------------------------------------------------------------------------------
  854. // Name: PrintPHA()
  855. // Desc: Prints the PHA instruction to a string and returns the number
  856. //       of bytes for the entire instruction.
  857. //------------------------------------------------------------------------------
  858. BYTE PrintPHA(LPSTR strDest, WORD wPC, BYTE byOpcode)
  859. {
  860. LPSTR strInstrName = "PHA"; // Name of the instruction being printed.
  861. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  862. } // end PrintPHA()
  863. //------------------------------------------------------------------------------
  864. // Name: PrintPHP()
  865. // Desc: Prints the PHP instruction to a string and returns the number
  866. //       of bytes for the entire instruction.
  867. //------------------------------------------------------------------------------
  868. BYTE PrintPHP(LPSTR strDest, WORD wPC, BYTE byOpcode)
  869. {
  870. LPSTR strInstrName = "PHP"; // Name of the instruction being printed.
  871. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  872. } // end PrintPHP()
  873. //------------------------------------------------------------------------------
  874. // Name: PrintPLA()
  875. // Desc: Prints the PLA instruction to a string and returns the number
  876. //       of bytes for the entire instruction.
  877. //------------------------------------------------------------------------------
  878. BYTE PrintPLA(LPSTR strDest, WORD wPC, BYTE byOpcode)
  879. {
  880. LPSTR strInstrName = "PLA"; // Name of the instruction being printed.
  881. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  882. } // end PrintPLA()
  883. //------------------------------------------------------------------------------
  884. // Name: PrintPHP()
  885. // Desc: Prints the PHP instruction to a string and returns the number
  886. //       of bytes for the entire instruction.
  887. //------------------------------------------------------------------------------
  888. BYTE PrintPLP(LPSTR strDest, WORD wPC, BYTE byOpcode)
  889. {
  890. LPSTR strInstrName = "PHP"; // Name of the instruction being printed.
  891. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  892. } // end PrintPHP()
  893. //------------------------------------------------------------------------------
  894. // Name: PrintROL()
  895. // Desc: Prints the ROL instruction to a string and returns the number
  896. //       of bytes for the entire instruction.
  897. //------------------------------------------------------------------------------
  898. BYTE PrintROL(LPSTR strDest, WORD wPC, BYTE byOpcode)
  899. {
  900. LPSTR strInstrName = "ROL"; // Name of the instruction being printed.
  901. // Depending on the opcode of the instruction, different addressing
  902. // modes apply. This means that different strings must be printed
  903. // depending on the addressing mode.
  904. switch (byOpcode)
  905. {
  906. case 0x26:
  907. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  908. case 0x2A:
  909. return (1 + PrintAddrMode_Accumulator(strDest, strInstrName, wPC));
  910. case 0x2E:
  911. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  912. case 0x36:
  913. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  914. case 0x3E:
  915. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  916. default:
  917. return 0;
  918. }
  919. } // end PrintROL()
  920. //------------------------------------------------------------------------------
  921. // Name: PrintROR()
  922. // Desc: Prints the ROR instruction to a string and returns the number
  923. //       of bytes for the entire instruction.
  924. //------------------------------------------------------------------------------
  925. BYTE PrintROR(LPSTR strDest, WORD wPC, BYTE byOpcode)
  926. {
  927. LPSTR strInstrName = "ROR"; // Name of the instruction being printed.
  928. // Depending on the opcode of the instruction, different addressing
  929. // modes apply. This means that different strings must be printed
  930. // depending on the addressing mode.
  931. switch (byOpcode)
  932. {
  933. case 0x66:
  934. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  935. case 0x6A:
  936. return (1 + PrintAddrMode_Accumulator(strDest, strInstrName, wPC));
  937. case 0x6E:
  938. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  939. case 0x76:
  940. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  941. case 0x7E:
  942. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  943. default:
  944. return 0;
  945. }
  946. } // end PrintROR()
  947. //------------------------------------------------------------------------------
  948. // Name: PrintRTI()
  949. // Desc: Prints the RTI instruction to a string and returns the number
  950. //       of bytes for the entire instruction.
  951. //------------------------------------------------------------------------------
  952. BYTE PrintRTI(LPSTR strDest, WORD wPC, BYTE byOpcode)
  953. {
  954. LPSTR strInstrName = "RTI"; // Name of the instruction being printed.
  955. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  956. } // end PrintRTI()
  957. //------------------------------------------------------------------------------
  958. // Name: PrintRTS()
  959. // Desc: Prints the RTS instruction to a string and returns the number
  960. //       of bytes for the entire instruction.
  961. //------------------------------------------------------------------------------
  962. BYTE PrintRTS(LPSTR strDest, WORD wPC, BYTE byOpcode)
  963. {
  964. LPSTR strInstrName = "RTS"; // Name of the instruction being printed.
  965. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  966. } // end PrintRTS()
  967. //------------------------------------------------------------------------------
  968. // Name: PrintSBC()
  969. // Desc: Prints the SBC instruction to a string and returns the number
  970. //       of bytes for the entire instruction.
  971. //------------------------------------------------------------------------------
  972. BYTE PrintSBC(LPSTR strDest, WORD wPC, BYTE byOpcode)
  973. {
  974. LPSTR strInstrName = "SBC"; // Name of the instruction being printed.
  975. // Depending on the opcode of the instruction, different addressing
  976. // modes apply. This means that different strings must be printed
  977. // depending on the addressing mode.
  978. switch (byOpcode)
  979. {
  980. case 0xE1:
  981. return (1 + PrintAddrMode_PreIndexedIndirect(strDest, strInstrName, wPC));
  982. case 0xE5:
  983. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  984. case 0xE9:
  985. return (1 + PrintAddrMode_Immediate(strDest, strInstrName, wPC));
  986. case 0xED:
  987. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  988. case 0xF1:
  989. return (1 + PrintAddrMode_PostIndexedIndirect(strDest, strInstrName, wPC));
  990. case 0xF5:
  991. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  992. case 0xF9:
  993. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  994. case 0xFD:
  995. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  996. default:
  997. return 0;
  998. }
  999. } // end PrintSBC()
  1000. //------------------------------------------------------------------------------
  1001. // Name: PrintSEC()
  1002. // Desc: Prints the SEC instruction to a string and returns the number
  1003. //       of bytes for the entire instruction.
  1004. //------------------------------------------------------------------------------
  1005. BYTE PrintSEC(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1006. {
  1007. LPSTR strInstrName = "SEC"; // Name of the instruction being printed.
  1008. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1009. } // end PrintSEC()
  1010. //------------------------------------------------------------------------------
  1011. // Name: PrintSED()
  1012. // Desc: Prints the SED instruction to a string and returns the number
  1013. //       of bytes for the entire instruction.
  1014. //------------------------------------------------------------------------------
  1015. BYTE PrintSED(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1016. {
  1017. LPSTR strInstrName = "SED"; // Name of the instruction being printed.
  1018. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1019. } // end PrintSED()
  1020. //------------------------------------------------------------------------------
  1021. // Name: PrintSEI()
  1022. // Desc: Prints the SEI instruction to a string and returns the number
  1023. //       of bytes for the entire instruction.
  1024. //------------------------------------------------------------------------------
  1025. BYTE PrintSEI(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1026. {
  1027. LPSTR strInstrName = "SEI"; // Name of the instruction being printed.
  1028. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1029. } // end PrintSEI()
  1030. //------------------------------------------------------------------------------
  1031. // Name: PrintSTA()
  1032. // Desc: Prints the STA instruction to a string and returns the number
  1033. //       of bytes for the entire instruction.
  1034. //------------------------------------------------------------------------------
  1035. BYTE PrintSTA(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1036. {
  1037. LPSTR strInstrName = "STA"; // Name of the instruction being printed.
  1038. // Depending on the opcode of the instruction, different addressing
  1039. // modes apply. This means that different strings must be printed
  1040. // depending on the addressing mode.
  1041. switch (byOpcode)
  1042. {
  1043. case 0x81:
  1044. return (1 + PrintAddrMode_PreIndexedIndirect(strDest, strInstrName, wPC));
  1045. case 0x85:
  1046. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  1047. case 0x8D:
  1048. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  1049. case 0x91:
  1050. return (1 + PrintAddrMode_PostIndexedIndirect(strDest, strInstrName, wPC));
  1051. case 0x95:
  1052. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  1053. case 0x99:
  1054. return (1 + PrintAddrMode_AbsoluteY(strDest, strInstrName, wPC));
  1055. case 0x9D:
  1056. return (1 + PrintAddrMode_AbsoluteX(strDest, strInstrName, wPC));
  1057. default:
  1058. return 0;
  1059. }
  1060. } // end PrintSTA()
  1061. //------------------------------------------------------------------------------
  1062. // Name: PrintSTX()
  1063. // Desc: Prints the STX instruction to a string and returns the number
  1064. //       of bytes for the entire instruction.
  1065. //------------------------------------------------------------------------------
  1066. BYTE PrintSTX(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1067. {
  1068. LPSTR strInstrName = "STX"; // Name of the instruction being printed.
  1069. // Depending on the opcode of the instruction, different addressing
  1070. // modes apply. This means that different strings must be printed
  1071. // depending on the addressing mode.
  1072. switch (byOpcode)
  1073. {
  1074. case 0x86:
  1075. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  1076. case 0x8E:
  1077. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  1078. case 0x96:
  1079. return (1 + PrintAddrMode_ZeroPageY(strDest, strInstrName, wPC));
  1080. default:
  1081. return 0;
  1082. }
  1083. } // end PrintSTX()
  1084. //------------------------------------------------------------------------------
  1085. // Name: PrintSTY()
  1086. // Desc: Prints the STY instruction to a string and returns the number
  1087. //       of bytes for the entire instruction.
  1088. //------------------------------------------------------------------------------
  1089. BYTE PrintSTY(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1090. {
  1091. LPSTR strInstrName = "STY"; // Name of the instruction being printed.
  1092. // Depending on the opcode of the instruction, different addressing
  1093. // modes apply. This means that different strings must be printed
  1094. // depending on the addressing mode.
  1095. switch (byOpcode)
  1096. {
  1097. case 0x84:
  1098. return (1 + PrintAddrMode_ZeroPage(strDest, strInstrName, wPC));
  1099. case 0x8C:
  1100. return (1 + PrintAddrMode_Absolute(strDest, strInstrName, wPC));
  1101. case 0x94:
  1102. return (1 + PrintAddrMode_ZeroPageX(strDest, strInstrName, wPC));
  1103. default:
  1104. return 0;
  1105. }
  1106. } // end PrintSTY()
  1107. //------------------------------------------------------------------------------
  1108. // Name: PrintTAX()
  1109. // Desc: Prints the TAX instruction to a string and returns the number
  1110. //       of bytes for the entire instruction.
  1111. //------------------------------------------------------------------------------
  1112. BYTE PrintTAX(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1113. {
  1114. LPSTR strInstrName = "TAX"; // Name of the instruction being printed.
  1115. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1116. } // end PrintTAX()
  1117. //------------------------------------------------------------------------------
  1118. // Name: PrintTAY()
  1119. // Desc: Prints the SEI instruction to a string and returns the number
  1120. //       of bytes for the entire instruction.
  1121. //------------------------------------------------------------------------------
  1122. BYTE PrintTAY(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1123. {
  1124. LPSTR strInstrName = "TAY"; // Name of the instruction being printed.
  1125. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1126. } // end PrintTAY()
  1127. //------------------------------------------------------------------------------
  1128. // Name: PrintTSX()
  1129. // Desc: Prints the TSX instruction to a string and returns the number
  1130. //       of bytes for the entire instruction.
  1131. //------------------------------------------------------------------------------
  1132. BYTE PrintTSX(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1133. {
  1134. LPSTR strInstrName = "TSX"; // Name of the instruction being printed.
  1135. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1136. } // end PrintTSX()
  1137. //------------------------------------------------------------------------------
  1138. // Name: PrintTXA()
  1139. // Desc: Prints the TXA instruction to a string and returns the number
  1140. //       of bytes for the entire instruction.
  1141. //------------------------------------------------------------------------------
  1142. BYTE PrintTXA(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1143. {
  1144. LPSTR strInstrName = "TXA"; // Name of the instruction being printed.
  1145. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1146. } // end PrintTXA()
  1147. //------------------------------------------------------------------------------
  1148. // Name: PrintTXS()
  1149. // Desc: Prints the TXS instruction to a string and returns the number
  1150. //       of bytes for the entire instruction.
  1151. //------------------------------------------------------------------------------
  1152. BYTE PrintTXS(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1153. {
  1154. LPSTR strInstrName = "TXS"; // Name of the instruction being printed.
  1155. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1156. } // end PrintTXS()
  1157. //------------------------------------------------------------------------------
  1158. // Name: PrintTYA()
  1159. // Desc: Prints the TYA instruction to a string and returns the number
  1160. //       of bytes for the entire instruction.
  1161. //------------------------------------------------------------------------------
  1162. BYTE PrintTYA(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1163. {
  1164. LPSTR strInstrName = "TYA"; // Name of the instruction being printed.
  1165. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1166. } // end PrintTYA()
  1167. //------------------------------------------------------------------------------
  1168. // Name: PrintUNDEF()
  1169. // Desc: Prints the UNDEF instruction to a string and returns the number
  1170. //       of bytes for the entire instruction.
  1171. //------------------------------------------------------------------------------
  1172. BYTE PrintUNDEF(LPSTR strDest, WORD wPC, BYTE byOpcode)
  1173. {
  1174. LPSTR strInstrName = "???"; // Name of the instruction being printed.
  1175. return (1 + PrintAddrMode_Implied(strDest, strInstrName, wPC));
  1176. } // end PrintUNDEF()
  1177. //------------------------------------------------------------------------------
  1178. // Name: PrintInstrToString()
  1179. // Desc: Gets the opcode of the instruction from memory and prints the
  1180. //       appropirate instruction to the string passed to the function.
  1181. //       This function returns the number of bytes the entire instruction
  1182. //       occupies. The string format is:
  1183. //       "PCMachineCodeInstructionMemoryContents"
  1184. //
  1185. //       Each individual part can be accessed by their associated constants
  1186. //       in PrintInstreToString.h
  1187. //
  1188. //       This way the strings can be easily printed separately 
  1189. //       becuase of the null terminating characters.
  1190. //------------------------------------------------------------------------------
  1191. BYTE PrintInstrToString(LPSTR strInstr, WORD wPC)
  1192. {
  1193. BYTE byOpcode = GetMemoryByte(wPC); // The opcode of our instruction.
  1194. // Print the beginning of the string.
  1195. // This is the same for every instruction.
  1196. sprintf(strInstr, "%04X: %02X", wPC, byOpcode);
  1197. strInstr[5] = '';
  1198. // Whatever the instruction is, print it to the string.
  1199. switch (byOpcode)
  1200. {
  1201. case 0x69: 
  1202. case 0x65: 
  1203. case 0x75: 
  1204. case 0x6D: 
  1205. case 0x7D: 
  1206. case 0x79:
  1207. case 0x61: 
  1208. case 0x71:
  1209. return PrintADC(&strInstr[8], wPC, byOpcode);
  1210. case 0x21:
  1211. case 0x25:
  1212. case 0x29:
  1213. case 0x2D:
  1214. case 0x31:
  1215. case 0x35:
  1216. case 0x39:
  1217. case 0x3D:
  1218. return PrintAND(&strInstr[8], wPC, byOpcode);
  1219. case 0x06:
  1220. case 0x0A:
  1221. case 0x0E:
  1222. case 0x16:
  1223. case 0x1E:
  1224. return PrintASL(&strInstr[8], wPC, byOpcode);
  1225. case 0x90:
  1226. return PrintBCC(&strInstr[8], wPC, byOpcode);
  1227. case 0xB0:
  1228. return PrintBCS(&strInstr[8], wPC, byOpcode);
  1229. case 0xF0:
  1230. return PrintBEQ(&strInstr[8], wPC, byOpcode);
  1231. case 0x24:
  1232. case 0x2C:
  1233. return PrintBIT(&strInstr[8], wPC, byOpcode);
  1234. case 0x30:
  1235. return PrintBMI(&strInstr[8], wPC, byOpcode);
  1236. case 0xD0:
  1237. return PrintBNE(&strInstr[8], wPC, byOpcode);
  1238. case 0x10:
  1239. return PrintBPL(&strInstr[8], wPC, byOpcode);
  1240. case 0x00:
  1241. return PrintBRK(&strInstr[8], wPC, byOpcode);
  1242. case 0x50:
  1243. return PrintBVC(&strInstr[8], wPC, byOpcode);
  1244. case 0x70:
  1245. return PrintBVS(&strInstr[8], wPC, byOpcode);
  1246. case 0x18:
  1247. return PrintCLC(&strInstr[8], wPC, byOpcode);
  1248. case 0xD8:
  1249. return PrintCLD(&strInstr[8], wPC, byOpcode);
  1250. case 0x58:
  1251. return PrintCLI(&strInstr[8], wPC, byOpcode);
  1252. case 0xB8:
  1253. return PrintCLV(&strInstr[8], wPC, byOpcode);
  1254. case 0xC9:
  1255. case 0xC5:
  1256. case 0xD5:
  1257. case 0xCD:
  1258. case 0xDD:
  1259. case 0xD9:
  1260. case 0xC1:
  1261. case 0xD1:
  1262. return PrintCMP(&strInstr[8], wPC, byOpcode);
  1263. case 0xE0:
  1264. case 0xE4:
  1265. case 0xEC:
  1266. return PrintCPX(&strInstr[8], wPC, byOpcode);
  1267. case 0xC0:
  1268. case 0xC4:
  1269. case 0xCC:
  1270. return PrintCPY(&strInstr[8], wPC, byOpcode);
  1271. case 0xC6:
  1272. case 0xD6:
  1273. case 0xCE:
  1274. case 0xDE:
  1275. return PrintDEC(&strInstr[8], wPC, byOpcode);
  1276. case 0xCA:
  1277. return PrintDEX(&strInstr[8], wPC, byOpcode);
  1278. case 0x88:
  1279. return PrintDEY(&strInstr[8], wPC, byOpcode);
  1280. case 0x49:
  1281. case 0x45:
  1282. case 0x55:
  1283. case 0x4D:
  1284. case 0x5D:
  1285. case 0x59:
  1286. case 0x41:
  1287. case 0x51:
  1288. return PrintEOR(&strInstr[8], wPC, byOpcode);
  1289. case 0xE6:
  1290. case 0xF6:
  1291. case 0xEE:
  1292. case 0xFE:
  1293. return PrintINC(&strInstr[8], wPC, byOpcode);
  1294. case 0xE8:
  1295. return PrintINX(&strInstr[8], wPC, byOpcode);
  1296. case 0xC8:
  1297. return PrintINY(&strInstr[8], wPC, byOpcode);
  1298. case 0x4C:
  1299. case 0x6C:
  1300. return PrintJMP(&strInstr[8], wPC, byOpcode);
  1301. case 0x20:
  1302. return PrintJSR(&strInstr[8], wPC, byOpcode);
  1303. case 0xA9:
  1304. case 0xA5:
  1305. case 0xB5:
  1306. case 0xAD:
  1307. case 0xBD:
  1308. case 0xB9:
  1309. case 0xA1:
  1310. case 0xB1:
  1311. return PrintLDA(&strInstr[8], wPC, byOpcode);
  1312. case 0xA2:
  1313. case 0xA6:
  1314. case 0xB6:
  1315. case 0xAE:
  1316. case 0xBE:
  1317. return PrintLDX(&strInstr[8], wPC, byOpcode);
  1318. case 0xA0:
  1319. case 0xA4:
  1320. case 0xB4:
  1321. case 0xAC:
  1322. case 0xBC:
  1323. return PrintLDY(&strInstr[8], wPC, byOpcode);
  1324. case 0x4A:
  1325. case 0x46:
  1326. case 0x56:
  1327. case 0x4E:
  1328. case 0x5E:
  1329. return PrintLSR(&strInstr[8], wPC, byOpcode);
  1330. case 0xEA:
  1331. return PrintNOP(&strInstr[8], wPC, byOpcode);
  1332. case 0x09:
  1333. case 0x05:
  1334. case 0x15:
  1335. case 0x0D:
  1336. case 0x1D:
  1337. case 0x19:
  1338. case 0x01:
  1339. case 0x11:
  1340. return PrintORA(&strInstr[8], wPC, byOpcode);
  1341. case 0x48:
  1342. return PrintPHA(&strInstr[8], wPC, byOpcode);
  1343. case 0x08:
  1344. return PrintPHP(&strInstr[8], wPC, byOpcode);
  1345. case 0x68:
  1346. return PrintPLA(&strInstr[8], wPC, byOpcode);
  1347. case 0x28:
  1348. return PrintPLP(&strInstr[8], wPC, byOpcode);
  1349. case 0x2A:
  1350. case 0x26:
  1351. case 0x36:
  1352. case 0x2E:
  1353. case 0x3E:
  1354. return PrintROL(&strInstr[8], wPC, byOpcode);
  1355. case 0x6A:
  1356. case 0x66:
  1357. case 0x76:
  1358. case 0x6E:
  1359. case 0x7E:
  1360. return PrintROR(&strInstr[8], wPC, byOpcode);
  1361. case 0x40:
  1362. return PrintRTI(&strInstr[8], wPC, byOpcode);
  1363. case 0x60:
  1364. return PrintRTS(&strInstr[8], wPC, byOpcode);
  1365. case 0xE9:
  1366. case 0xE5:
  1367. case 0xF5:
  1368. case 0xED:
  1369. case 0xFD:
  1370. case 0xF9:
  1371. case 0xE1:
  1372. case 0xF1:
  1373. return PrintSBC(&strInstr[8], wPC, byOpcode);
  1374. case 0x38:
  1375. return PrintSEC(&strInstr[8], wPC, byOpcode);
  1376. case 0xF8:
  1377. return PrintSED(&strInstr[8], wPC, byOpcode);
  1378. case 0x78:
  1379. return PrintSEI(&strInstr[8], wPC, byOpcode);
  1380. case 0x85:
  1381. case 0x95:
  1382. case 0x8D:
  1383. case 0x9D:
  1384. case 0x99:
  1385. case 0x81:
  1386. case 0x91:
  1387. return PrintSTA(&strInstr[8], wPC, byOpcode);
  1388. case 0x86:
  1389. case 0x96:
  1390. case 0x8E:
  1391. return PrintSTX(&strInstr[8], wPC, byOpcode);
  1392. case 0x84:
  1393. case 0x94:
  1394. case 0x8C:
  1395. return PrintSTY(&strInstr[8], wPC, byOpcode);
  1396. case 0xAA:
  1397. return PrintTAX(&strInstr[8], wPC, byOpcode);
  1398. case 0xA8:
  1399. return PrintTAY(&strInstr[8], wPC, byOpcode);
  1400. case 0xBA:
  1401. return PrintTSX(&strInstr[8], wPC, byOpcode);
  1402. case 0x8A:
  1403. return PrintTXA(&strInstr[8], wPC, byOpcode);
  1404. case 0x9A:
  1405. return PrintTXS(&strInstr[8], wPC, byOpcode);
  1406. case 0x98:
  1407. return PrintTYA(&strInstr[8], wPC, byOpcode);
  1408. default:
  1409. return PrintUNDEF(&strInstr[8], wPC, byOpcode);
  1410. }
  1411. } // end PrintInstrToString()