An emulator, assembler, and disassembler for the Sega Game Gear
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

724 lines
16 KiB

  1. # Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. # Released under the terms of the MIT License. See LICENSE for details.
  3. # *** ASM Instruction Description File ***
  4. # This file is used to generate 'instructions.inc.c'.
  5. # `make` should trigger a rebuild when this file is modified; if not, use:
  6. # `python scripts/update_asm_instructions.py`.
  7. ---
  8. adc:
  9. args: yes
  10. cases:
  11. - type: [register, register]
  12. cases:
  13. - if: [a, a|b|c|d|e|h|ih|l|il]
  14. return: [reg(0x88)]
  15. - if: [hl, bc|de|hl|sp]
  16. return: [0xED, reg(0x4A 0x10)]
  17. - type: [register, immediate]
  18. cases:
  19. - if: [a, u8]
  20. return: [0xCE, u8]
  21. - type: [register, indirect_hl_or_indexed]
  22. cases:
  23. - if: [a, _]
  24. return: [0x8E]
  25. add:
  26. args: yes
  27. cases:
  28. - type: [register, register]
  29. cases:
  30. - if: [a, a|b|c|d|e|h|ih|l|il]
  31. return: [reg(0x80)]
  32. - if: [hl|ixy, bc]
  33. return: [0x09]
  34. - if: [hl|ixy, de]
  35. return: [0x19]
  36. - if: [hl|ixy, hl|ixy]
  37. return: [0x29]
  38. - if: [hl|ixy, sp]
  39. return: [0x39]
  40. - type: [register, immediate]
  41. cases:
  42. - if: [a, u8]
  43. return: [0xC6, u8]
  44. - type: [register, indirect_hl_or_indexed]
  45. cases:
  46. - if: [a, _]
  47. return: [0x86]
  48. and:
  49. args: yes
  50. cases:
  51. - type: [register]
  52. cases:
  53. - if: [a|b|c|d|e|h|ih|l|il]
  54. return: [reg(0xA0)]
  55. - type: [immediate]
  56. cases:
  57. - if: [u8]
  58. return: [0xE6, u8]
  59. - type: [indirect_hl_or_indexed]
  60. cases:
  61. - if: [_]
  62. return: [0xA6]
  63. bit:
  64. args: yes
  65. cases:
  66. - type: [immediate, register]
  67. cases:
  68. - if: [bit, a|b|c|d|e|h|l]
  69. return: [0xCB, bit(reg(0x40))]
  70. - type: [immediate, indirect_hl_or_indexed]
  71. cases:
  72. - if: [bit, _]
  73. return: [0xCB, bit(0x46)]
  74. call:
  75. args: yes
  76. cases:
  77. - type: [immediate]
  78. cases:
  79. - if: [u16]
  80. return: [0xCD, u16]
  81. - type: [condition, immediate]
  82. cases:
  83. - if: [nz|z|nc|c|po|pe|p|m, u16]
  84. return: [cond(0xC4 0x08), u16]
  85. ccf:
  86. args: no
  87. return: [0x3F]
  88. cp:
  89. args: yes
  90. cases:
  91. - type: [register]
  92. cases:
  93. - if: [a|b|c|d|e|h|ih|l|il]
  94. return: [reg(0xB8)]
  95. - type: [indirect_hl_or_indexed]
  96. cases:
  97. - if: [_]
  98. return: [0xBE]
  99. - type: [immediate]
  100. cases:
  101. - if: [u8]
  102. return: [0xFE, u8]
  103. cpd:
  104. args: no
  105. return: [0xED, 0xA9]
  106. cpdr:
  107. args: no
  108. return: [0xED, 0xB9]
  109. cpi:
  110. args: no
  111. return: [0xED, 0xA1]
  112. cpir:
  113. args: no
  114. return: [0xED, 0xB1]
  115. cpl:
  116. args: no
  117. return: [0x2F]
  118. daa:
  119. args: no
  120. return: [0x27]
  121. dec:
  122. args: yes
  123. cases:
  124. - type: [register]
  125. cases:
  126. - if: [a|b|c|d|e|h|ih|l|il]
  127. return: [reg(0x05 0x08)]
  128. - if: [bc|de|hl|ixy|sp]
  129. return: [reg(0x0B 0x10)]
  130. - type: [indirect_hl_or_indexed]
  131. cases:
  132. - if: [_]
  133. return: [0x35]
  134. di:
  135. args: no
  136. return: [0xF3]
  137. djnz:
  138. args: yes
  139. cases:
  140. - type: [immediate]
  141. cases:
  142. - if: [rel]
  143. return: [0x10, rel]
  144. ei:
  145. args: no
  146. return: [0xFB]
  147. ex:
  148. args: yes
  149. cases:
  150. - type: [register, register]
  151. cases:
  152. - if: [af, af_]
  153. return: [0x08]
  154. - if: [de, hl]
  155. return: [0xEB]
  156. - type: [indirect, register]
  157. cases:
  158. - if: [reg.sp, hl|ixy]
  159. return: [0xE3]
  160. exx:
  161. args: no
  162. return: [0xD9]
  163. halt:
  164. args: no
  165. return: [0x76]
  166. im:
  167. args: yes
  168. cases:
  169. - type: [immediate]
  170. cases:
  171. - if: [im.0]
  172. return: [0xED, 0x46]
  173. - if: [im.1]
  174. return: [0xED, 0x56]
  175. - if: [im.2]
  176. return: [0xED, 0x5E]
  177. in:
  178. args: yes
  179. cases:
  180. - type: [register, port]
  181. cases:
  182. - if: [a, imm]
  183. return: [0xDB, u8]
  184. - if: [a|b|c|d|e|h|l, reg.c]
  185. return: [0xED, reg(0x40 0x08)]
  186. - type: [port]
  187. cases:
  188. - if: [reg.c]
  189. return: [0xED, 0x70]
  190. inc:
  191. args: yes
  192. cases:
  193. - type: [register]
  194. cases:
  195. - if: [a|b|c|d|e|h|ih|l|il]
  196. return: [reg(0x04 0x08)]
  197. - if: [bc|de|hl|ixy|sp]
  198. return: [reg(0x03 0x10)]
  199. - type: [indirect_hl_or_indexed]
  200. cases:
  201. - if: [_]
  202. return: [0x34]
  203. ind:
  204. args: no
  205. return: [0xED, 0xAA]
  206. indr:
  207. args: no
  208. return: [0xED, 0xBA]
  209. ini:
  210. args: no
  211. return: [0xED, 0xA2]
  212. inir:
  213. args: no
  214. return: [0xED, 0xB2]
  215. jp:
  216. args: yes
  217. cases:
  218. - type: [immediate]
  219. cases:
  220. - if: [u16]
  221. return: [0xC3, u16]
  222. - type: [condition, immediate]
  223. cases:
  224. - if: [nz|z|nc|c|po|pe|p|m, u16]
  225. return: [cond(0xC2 0x08), u16]
  226. - type: [indirect]
  227. cases:
  228. - if: [reg.hl|reg.ixy]
  229. return: [0xE9]
  230. jr:
  231. args: yes
  232. cases:
  233. - type: [immediate]
  234. cases:
  235. - if: [rel]
  236. return: [0x18, rel]
  237. - type: [condition, immediate]
  238. cases:
  239. - if: [nz|z|nc|c, rel]
  240. return: [cond(0x20 0x08), rel]
  241. ld:
  242. args: yes
  243. cases:
  244. - type: [register, register]
  245. cases:
  246. - if: [a, a|b|c|d|e|h|ih|l|il]
  247. return: [reg(0x78)]
  248. - if: [b, a|b|c|d|e|h|ih|l|il]
  249. return: [reg(0x40)]
  250. - if: [c, a|b|c|d|e|h|ih|l|il]
  251. return: [reg(0x48)]
  252. - if: [d, a|b|c|d|e|h|ih|l|il]
  253. return: [reg(0x50)]
  254. - if: [e, a|b|c|d|e|h|ih|l|il]
  255. return: [reg(0x58)]
  256. - if: [h|ih, a]
  257. return: [0x67]
  258. - if: [h|ih, b]
  259. return: [0x60]
  260. - if: [h|ih, c]
  261. return: [0x61]
  262. - if: [h|ih, d]
  263. return: [0x62]
  264. - if: [h|ih, e]
  265. return: [0x63]
  266. - if: [h|ih, h|ih]
  267. return: [0x64]
  268. - if: [h|ih, l|il]
  269. return: [0x65]
  270. - if: [l|il, a]
  271. return: [0x6F]
  272. - if: [l|il, b]
  273. return: [0x68]
  274. - if: [l|il, c]
  275. return: [0x69]
  276. - if: [l|il, d]
  277. return: [0x6A]
  278. - if: [l|il, e]
  279. return: [0x6B]
  280. - if: [l|il, h|ih]
  281. return: [0x6C]
  282. - if: [l|il, l|il]
  283. return: [0x6D]
  284. - if: [a, i]
  285. return: [0xED, 0x57]
  286. - if: [i, a]
  287. return: [0xED, 0x47]
  288. - if: [a, r]
  289. return: [0xED, 0x5F]
  290. - if: [r, a]
  291. return: [0xED, 0x4F]
  292. - if: [sp, hl|ixy]
  293. return: [0xF9]
  294. - type: [register, immediate]
  295. cases:
  296. - if: [a|b|c|d|e|h|ih|l|il, u8]
  297. return: [reg(0x06 0x08), u8]
  298. - if: [bc|de|hl|ixy|sp, u16]
  299. return: [reg(0x01 0x10), u16]
  300. - type: [register, indirect_hl_or_indexed]
  301. cases:
  302. - if: [a|b|c|d|e|h|l, _]
  303. return: [reg(0x46 0x08)]
  304. - type: [register, indirect]
  305. cases:
  306. - if: [a, reg.bc]
  307. return: [0x0A]
  308. - if: [a, reg.de]
  309. return: [0x1A]
  310. - if: [hl|ixy, imm]
  311. return: [0x2A, u16]
  312. - if: [a, imm]
  313. return: [0x3A, u16]
  314. - if: [bc|de|sp, imm]
  315. return: [0xED, reg(0x4B 0x10), u16]
  316. - type: [indirect_hl_or_indexed, register]
  317. cases:
  318. - if: [_, a|b|c|d|e|h|l]
  319. return: [reg(0x70)]
  320. - type: [indirect_hl_or_indexed, immediate]
  321. cases:
  322. - if: [_, u8]
  323. return: [0x36, u8]
  324. - type: [indirect, register]
  325. cases:
  326. - if: [reg.bc, a]
  327. return: [0x02]
  328. - if: [reg.de, a]
  329. return: [0x12]
  330. - if: [imm, hl|ixy]
  331. return: [0x22, u16]
  332. - if: [imm, a]
  333. return: [0x32, u16]
  334. - if: [imm, bc|de|sp]
  335. return: [0xED, reg(0x43 0x10), u16]
  336. ldd:
  337. args: no
  338. return: [0xED, 0xA8]
  339. lddr:
  340. args: no
  341. return: [0xED, 0xB8]
  342. ldi:
  343. args: no
  344. return: [0xED, 0xA0]
  345. ldir:
  346. args: no
  347. return: [0xED, 0xB0]
  348. neg:
  349. args: no
  350. return: [0xED, 0x44]
  351. nop:
  352. args: no
  353. return: [0x00]
  354. or:
  355. args: yes
  356. cases:
  357. - type: [register]
  358. cases:
  359. - if: [a|b|c|d|e|h|ih|l|il]
  360. return: [reg(0xB0)]
  361. - type: [immediate]
  362. cases:
  363. - if: [u8]
  364. return: [0xF6, u8]
  365. - type: [indirect_hl_or_indexed]
  366. cases:
  367. - if: [_]
  368. return: [0xB6]
  369. otdr:
  370. args: no
  371. return: [0xED, 0xBB]
  372. otir:
  373. args: no
  374. return: [0xED, 0xB3]
  375. out:
  376. args: yes
  377. cases:
  378. - type: [port, register]
  379. cases:
  380. - if: [imm, a]
  381. return: [0xD3, u8]
  382. - if: [reg.c, a|b|c|d|e|h|l]
  383. return: [0xED, reg(0x41 0x08)]
  384. - type: [port, immediate]
  385. cases:
  386. - if: [reg.c, u8.0]
  387. return: [0xED, 0x71]
  388. outd:
  389. args: no
  390. return: [0xED, 0xAB]
  391. outi:
  392. args: no
  393. return: [0xED, 0xA3]
  394. pop:
  395. args: yes
  396. cases:
  397. - type: [register]
  398. cases:
  399. - if: [bc|de|hl|ixy|af]
  400. return: [reg(0xC1 0x10)]
  401. push:
  402. args: yes
  403. cases:
  404. - type: [register]
  405. cases:
  406. - if: [bc|de|hl|ixy|af]
  407. return: [reg(0xC5 0x10)]
  408. res:
  409. args: yes
  410. cases:
  411. - type: [immediate, register]
  412. cases:
  413. - if: [bit, a|b|c|d|e|h|l]
  414. return: [0xCB, bit(reg(0x80))]
  415. - type: [immediate, indirect_hl_or_indexed]
  416. cases:
  417. - if: [bit, _]
  418. return: [0xCB, bit(0x86)]
  419. - type: [immediate, indexed, register]
  420. cases:
  421. - if: [bit, _, a|b|c|d|e|h|l]
  422. return: [0xCB, bit(reg(0x80))]
  423. ret:
  424. args: yes
  425. cases:
  426. - type: []
  427. return: [0xC9]
  428. - type: [condition]
  429. cases:
  430. - if: [nz|z|nc|c|po|pe|p|m]
  431. return: [cond(0xC0 0x08)]
  432. reti:
  433. args: no
  434. return: [0xED, 0x4D]
  435. retn:
  436. args: no
  437. return: [0xED, 0x45]
  438. rl:
  439. args: yes
  440. cases:
  441. - type: [register]
  442. cases:
  443. - if: [a|b|c|d|e|h|l]
  444. return: [0xCB, reg(0x10)]
  445. - type: [indirect_hl_or_indexed]
  446. cases:
  447. - if: [_]
  448. return: [0xCB, 0x16]
  449. - type: [indexed, register]
  450. cases:
  451. - if: [_, a|b|c|d|e|h|l]
  452. return: [0xCB, reg(0x10)]
  453. rla:
  454. args: no
  455. return: [0x17]
  456. rlc:
  457. args: yes
  458. cases:
  459. - type: [register]
  460. cases:
  461. - if: [a|b|c|d|e|h|l]
  462. return: [0xCB, reg(0x00)]
  463. - type: [indirect_hl_or_indexed]
  464. cases:
  465. - if: [_]
  466. return: [0xCB, 0x06]
  467. - type: [indexed, register]
  468. cases:
  469. - if: [_, a|b|c|d|e|h|l]
  470. return: [0xCB, reg(0x00)]
  471. rlca:
  472. args: no
  473. return: [0x07]
  474. rld:
  475. args: no
  476. return: [0xED, 0x6F]
  477. rr:
  478. args: yes
  479. cases:
  480. - type: [register]
  481. cases:
  482. - if: [a|b|c|d|e|h|l]
  483. return: [0xCB, reg(0x18)]
  484. - type: [indirect_hl_or_indexed]
  485. cases:
  486. - if: [_]
  487. return: [0xCB, 0x1E]
  488. - type: [indexed, register]
  489. cases:
  490. - if: [_, a|b|c|d|e|h|l]
  491. return: [0xCB, reg(0x18)]
  492. rra:
  493. args: no
  494. return: [0x1F]
  495. rrc:
  496. args: yes
  497. cases:
  498. - type: [register]
  499. cases:
  500. - if: [a|b|c|d|e|h|l]
  501. return: [0xCB, reg(0x08)]
  502. - type: [indirect_hl_or_indexed]
  503. cases:
  504. - if: [_]
  505. return: [0xCB, 0x0E]
  506. - type: [indexed, register]
  507. cases:
  508. - if: [_, a|b|c|d|e|h|l]
  509. return: [0xCB, reg(0x08)]
  510. rrca:
  511. args: no
  512. return: [0x0F]
  513. rrd:
  514. args: no
  515. return: [0xED, 0x67]
  516. rst:
  517. args: yes
  518. cases:
  519. - type: [immediate]
  520. cases:
  521. - if: [rst]
  522. return: [rst(0xC7)]
  523. sbc:
  524. args: yes
  525. cases:
  526. - type: [register, register]
  527. cases:
  528. - if: [a, a|b|c|d|e|h|ih|l|il]
  529. return: [reg(0x98)]
  530. - if: [hl, bc|de|hl|sp]
  531. return: [0xED, reg(0x42 0x10)]
  532. - type: [register, immediate]
  533. cases:
  534. - if: [a, u8]
  535. return: [0xDE, u8]
  536. - type: [register, indirect_hl_or_indexed]
  537. cases:
  538. - if: [a, _]
  539. return: [0x9E]
  540. scf:
  541. args: no
  542. return: [0x37]
  543. set:
  544. args: yes
  545. cases:
  546. - type: [immediate, register]
  547. cases:
  548. - if: [bit, a|b|c|d|e|h|l]
  549. return: [0xCB, bit(reg(0xC0))]
  550. - type: [immediate, indirect_hl_or_indexed]
  551. cases:
  552. - if: [bit, _]
  553. return: [0xCB, bit(0xC6)]
  554. - type: [immediate, indexed, register]
  555. cases:
  556. - if: [bit, _, a|b|c|d|e|h|l]
  557. return: [0xCB, bit(reg(0xC0))]
  558. sl1: &sl1
  559. args: yes
  560. cases:
  561. - type: [register]
  562. cases:
  563. - if: [a|b|c|d|e|h|l]
  564. return: [0xCB, reg(0x30)]
  565. - type: [indirect_hl_or_indexed]
  566. cases:
  567. - if: [_]
  568. return: [0xCB, 0x36]
  569. - type: [indexed, register]
  570. cases:
  571. - if: [_, a|b|c|d|e|h|l]
  572. return: [0xCB, reg(0x30)]
  573. sla:
  574. args: yes
  575. cases:
  576. - type: [register]
  577. cases:
  578. - if: [a|b|c|d|e|h|l]
  579. return: [0xCB, reg(0x20)]
  580. - type: [indirect_hl_or_indexed]
  581. cases:
  582. - if: [_]
  583. return: [0xCB, 0x26]
  584. - type: [indexed, register]
  585. cases:
  586. - if: [_, a|b|c|d|e|h|l]
  587. return: [0xCB, reg(0x20)]
  588. sll: *sl1
  589. sls: *sl1
  590. sra:
  591. args: yes
  592. cases:
  593. - type: [register]
  594. cases:
  595. - if: [a|b|c|d|e|h|l]
  596. return: [0xCB, reg(0x28)]
  597. - type: [indirect_hl_or_indexed]
  598. cases:
  599. - if: [_]
  600. return: [0xCB, 0x2E]
  601. - type: [indexed, register]
  602. cases:
  603. - if: [_, a|b|c|d|e|h|l]
  604. return: [0xCB, reg(0x28)]
  605. srl:
  606. args: yes
  607. cases:
  608. - type: [register]
  609. cases:
  610. - if: [a|b|c|d|e|h|l]
  611. return: [0xCB, reg(0x38)]
  612. - type: [indirect_hl_or_indexed]
  613. cases:
  614. - if: [_]
  615. return: [0xCB, 0x3E]
  616. - type: [indexed, register]
  617. cases:
  618. - if: [_, a|b|c|d|e|h|l]
  619. return: [0xCB, reg(0x38)]
  620. sub:
  621. args: yes
  622. cases:
  623. - type: [register]
  624. cases:
  625. - if: [a|b|c|d|e|h|ih|l|il]
  626. return: [reg(0x90)]
  627. - type: [immediate]
  628. cases:
  629. - if: [u8]
  630. return: [0xD6, u8]
  631. - type: [indirect_hl_or_indexed]
  632. cases:
  633. - if: [_]
  634. return: [0x96]
  635. xor:
  636. args: yes
  637. cases:
  638. - type: [register]
  639. cases:
  640. - if: [a|b|c|d|e|h|ih|l|il]
  641. return: [reg(0xA8)]
  642. - type: [immediate]
  643. cases:
  644. - if: [u8]
  645. return: [0xEE, u8]
  646. - type: [indirect_hl_or_indexed]
  647. cases:
  648. - if: [_]
  649. return: [0xAE]