home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / tools / pcmac / z80.mac < prev   
Text File  |  1991-05-22  |  8KB  |  605 lines

  1.  
  2. ;*******************************************************
  3. ;*                                                     *
  4. ;*             Z80 MACRO DEFINITION                    *
  5. ;*             ====================                    *
  6. ;*                                                     *
  7. ;*  Defined by Peter Verhas                            *
  8. ;*                                                     *
  9. ;*                                                     *
  10. ;*******************************************************
  11.  
  12. ;
  13. ;Register constants
  14. ;
  15. const    _SS    :=    (B,C,D,E,H,L,(HL\),A)
  16. const    _SDD    :=    (BC,DE,HL,SP)
  17. const    _SQQ    :=    (BC,DE,HL,AF)
  18. const    _SPP    :=    (BC,DE,IX,SP)
  19. const    _SRR    :=    (BC,DE,IY,SP)
  20. const    _SII    :=    (HL,IX,IY)
  21. const    _SXX    :=    (IX,IY)
  22. const    _SDB    :=    (BC,DE)
  23. const    _SIR    :=    (I,R)
  24.  
  25. ;
  26. ;Condition constants
  27. ;
  28.  
  29. const    _SCE    :=    (NZ,Z,NC,C,PO,PE,P,M)
  30. const    _SCC    :=    (NZ,Z,NC,C)
  31.  
  32. ;
  33. ;Instruction constants
  34. ;
  35.  
  36. const    _SAR    :=    (ADD,ADC,SUB,SBC,AND,XOR,OR,CP)
  37. const    _SROT    :=    (RLC,RRC,RL,RR,SLA,SRA,SLI,SRL)
  38. const    _SROTA    :=    (RLCA,RRCA,RLA,RRA)
  39. const    _SBIT    :=    (BIT,RES,SET)
  40. const    _SID    :=    (INC,DEC)
  41. const    _SGC    :=    (DAA,CPL,SCF,CCF)
  42. const    _SADS    :=    (ADD,ADC,__GAP__,SBC)
  43.  
  44. ;
  45. ;
  46. ;Pseudo op macro definitions
  47.  
  48. macro("ORG\  *",NUMERIC)
  49. $    :=doreloc(#0)
  50. endm
  51.  
  52. macro("DS\  *",NUMERIC)
  53. $    :=    doreloc($+#0)
  54. endm
  55.  
  56.  
  57. ;
  58. ;
  59. ;Standard Z80 instruction set
  60. ;============================
  61. ;
  62. ;1) 8 Bit load group
  63. ;===================
  64.  
  65. macro("LD\  *,*",_SS,_SS)
  66. #if    #0 == 6 && #1 == 6
  67. #error    "LD (HL),(HL) is invalid."
  68. #endif
  69.     DB    40h+(#0<<3)+#1
  70. endm
  71.  
  72. macro("LD\  *,*",_SS,NUMERIC)
  73.     DB    6h+(#0<<3),#1
  74. endm
  75.  
  76. macro("LD\  *,(**)",_SS,_SXX,NUMERIC)
  77.     db    0ddh+(#1<<5),46h+(#0<<3),#2
  78. endm
  79.  
  80. macro("LD\  (**),*",_SXX,NUMERIC,_SS)
  81.     db    0ddh+(#0<<5),70h+#2,#1
  82. endm
  83.  
  84. macro("LD\  (**),*",_SXX,NUMERIC,NUMERIC)
  85.     db    0ddh+(#0<<5),36h,#1,#2
  86. endm
  87.  
  88. macro("LD\  A,(*)",_SDB)
  89.     db    0ah + (#0<<4)
  90. endm
  91.  
  92. macro("LD\  (*),A",_SDB)
  93.     db    02h + (#0<<4)
  94. endm
  95.  
  96. macro("LD\  A,*",_SIR)
  97.     db    0edh,57h + (#0<<3)
  98. endm
  99.  
  100. macro("LD\  *,A",_SIR)
  101.     db    0edh,047h + (#0<<3)
  102. endm
  103.  
  104. macro("LD\  A,(*)",LABEL)
  105.     db    3ah
  106.     dw    #0
  107. endm
  108.  
  109. macro("LD\  A,(*)",NUMERIC)
  110.     db    3ah
  111.     dw    #0
  112. endm
  113.  
  114. macro("LD\  (*),A",LABEL)
  115.     db    32h
  116.     dw    #0
  117. endm
  118.  
  119. macro("LD\  (*),A",NUMERIC)
  120.     db    32h
  121.     dw    #0
  122. endm
  123.  
  124. macro("LDI")
  125.     db    0edh,0a0h
  126. endm
  127.  
  128. macro("LDIR")
  129.     db    0edh,0b0h
  130. endm
  131.  
  132. macro("LDD")
  133.     db    0edh,0a8h
  134. endm
  135.  
  136. macro("LDDR")
  137.     db    0edh,0b8h
  138. endm
  139.  
  140. ;
  141. ;
  142. ; 2) 16 Bit load group
  143. ; ====================
  144. ;
  145.  
  146. macro("LD\  *,*",_SDD,LABEL)
  147.     db    1 + (#0<<4)
  148.     dw    #1
  149. endm
  150.  
  151. macro("LD\  *,*",_SDD,NUMERIC)
  152.     db    1 + (#0<<4)
  153.     dw    #1
  154. endm
  155.  
  156. macro("LD\  *,*",_SXX,LABEL)
  157.     db    0ddh + (#0<<5),21h
  158.     dw    #1
  159. endm
  160.  
  161. macro("LD\  *,*",_SXX,NUMERIC)
  162.     db    0ddh + (#0<<5),21h
  163.     dw    #1
  164. endm
  165.  
  166. macro("LD\  *,(*)",_SDD,LABEL)
  167. #if    #0 == 2
  168.     db    2ah    ;HL is a special case
  169. #else
  170.     db    0edh,4bh + (#0<<4)
  171. #endif
  172.     dw    #1
  173. endm
  174.  
  175. macro("LD\  *,(*)",_SDD,NUMERIC)
  176. #if    #0 == 2
  177.     db    2ah    ;HL is a special case
  178. #else
  179.     db    0edh,4bh + (#0<<4)
  180. #endif
  181.     dw    #1
  182. endm
  183.  
  184. macro("LD\  (*),*",LABEL,_SDD)
  185. #if    #1 == 2
  186.     db    22h    ;HL is a special case
  187. #else
  188.     db    0edh,43h + (#1<<4)
  189. #endif
  190.     dw    #0
  191. endm
  192. macro("LD\  (*),*",NUMERIC,_SDD)
  193. #if    #1 == 2
  194.     db    22h    ;HL is a special case
  195. #else
  196.     db    0edh,43h + (#1<<4)
  197. #endif
  198.     dw    #0
  199. endm
  200.  
  201. macro("LD\  *,(*)",_SXX,LABEL)
  202.     db    0ddh + (#0<<5),2ah
  203.     dw    #1
  204. endm
  205.  
  206. macro("LD\  *,(*)",_SXX,NUMERIC)
  207.     db    0ddh + (#0<<5),2ah
  208.     dw    #1
  209. endm
  210.  
  211. macro("LD\  (*),*",LABEL,_SXX)
  212.     db    0ddh + (#1<<5),22h
  213.     dw    #0
  214. endm
  215.  
  216. macro("LD\  (*),*",NUMERIC,_SXX)
  217.     db    0ddh + (#1<<5),22h
  218.     dw    #0
  219. endm
  220.  
  221. macro("LD\  SP,*",_SII)
  222. #if    #0
  223.     db    0bdh + (#0<<5)
  224. #endif
  225.     db    0f9h
  226. endm
  227.  
  228. macro("PUSH\  *",_SQQ)
  229.     db    0c5h + (#0<<4)
  230. endm
  231.  
  232. macro("POP\  *",_SQQ)
  233.     db    0c1h + (#0<<4)
  234. endm
  235.  
  236. macro("PUSH\  *",_SXX)
  237.     db    0ddh + (#0<<5),0e5h
  238. endm
  239.  
  240. macro("POP\  *",_SXX)
  241.     db    0ddh + (#0<<5),0e1h
  242. endm
  243.  
  244. macro("EX\  DE,HL")
  245.     db    0ebh
  246. endm
  247.  
  248. macro("EX\  AF,AF")
  249.     db    08h
  250. endm
  251.  
  252. macro("EX\  (SP),*",_SII)
  253. #if    #0
  254.     db    0bdh + (#0<<5)
  255. #endif
  256.     db    0e3h
  257. endm
  258.  
  259. macro("EXX")
  260.     db    0d9h
  261. endm
  262.  
  263.  
  264. ;
  265. ;
  266. ; 3) 16 Bit arithmetic group
  267. ; ==========================
  268. ;
  269.  
  270. macro("ADD\  HL,*",_SDD)
  271.     db    9 + (#0<<4)
  272. endm
  273.  
  274. macro("ADD\  IX,*",_SPP)
  275.     db    0ddh,9 + (#0<<4)
  276. endm
  277.  
  278. macro("ADD\  IY,*",_SRR)
  279.     db    0fdh,9 + (#0<<4)
  280. endm
  281.  
  282. macro("ADC\  HL,*",_SDD)
  283.     db    0edh,4ah + (#0<<4)
  284. endm
  285.  
  286. macro("SBC\  HL,*",_SDD)
  287.     db    0edh,42H + (#0<<4)
  288. endm
  289.  
  290. macro("*\  *",_SID,_SDD)
  291.     db    3 + (#0<<3) + (#1<<4)
  292. endm
  293. ;
  294. ;
  295. ; 4) 8 Bit arithmetic group
  296. ; =========================
  297. ;
  298.  
  299. macro("*\  *",_SAR,_SS)
  300.     db    80h + (#0<<3) + #1
  301. endm
  302.  
  303. macro("*\  A,*",_SADS,_SS)
  304.     db    80h + (#0<<3) + #1
  305. endm
  306.  
  307. macro("*\  *",_SAR,NUMERIC)
  308.     db    0c6h + (#0<<3),#1
  309. endm
  310.  
  311. macro("*\  A,*",_SADS,NUMERIC)
  312.     db    0c6h + (#0<<3),#1
  313. endm
  314.  
  315. macro("*\  (**)",_SAR,_SXX,NUMERIC)
  316.     db     0ddh + (#1<<5),86h + (#0<<3),#2
  317. endm
  318.  
  319. macro("*\  A,(**)",_SADS,_SXX,NUMERIC)
  320.     db    0ddh + (#1<<5),86h + (#0<<3),#2
  321. endm
  322.  
  323. macro("*\  *",_SID,_SS)
  324.     db    4 + #0 + (#1<<3)
  325. endm
  326.  
  327. ;macro("*\  (HL)",_SID)
  328. ;    db    34h + #0
  329. ;endm
  330.  
  331. macro("*\  (**)",_SID,_SXX,NUMERIC)
  332.     db     0ddh + (#1<<5),34h + #0,#2
  333. endm
  334.  
  335. macro("CPI")
  336.     db     0edh,0a1h
  337. endm
  338.  
  339. macro("CPIR")
  340.     db    0edh,0b1h
  341. endm
  342.  
  343. macro("CPD")
  344.     db    0edh,0a9h
  345. endm
  346.  
  347. macro("CPDR")
  348.     db     0edh,0b9h
  349. endm
  350.  
  351. ;
  352. ;
  353. ; 5)General purpose arithmetic and CPU control
  354. ;
  355.  
  356. macro("*",_SGC)
  357.     db    27h+(#0<<3)
  358. endm
  359.  
  360. macro("NOP")
  361.     db    0
  362. endm
  363.  
  364. macro("NEG")
  365.     db    0edh,44h
  366. endm
  367.  
  368. macro("HALT")
  369.     db    76h
  370. endm
  371.  
  372. macro("DI")
  373.     db    0f3h
  374. endm
  375.  
  376. macro("EI")
  377.     db    0fbh
  378. endm
  379.  
  380. macro("IM\  *",NUMERIC)
  381. #if #0<0 || #0>2
  382. #error     "Invalid interrupt mode."
  383. #endif
  384.     db    0edh
  385. #if    #0
  386.     db    4eh + (#0<<3)
  387. #else
  388.     db    46h
  389. #endif
  390. endm
  391.  
  392.  
  393. ;
  394. ;
  395. ; 6) Rotate and shift group
  396. ; =========================
  397. ;
  398.  
  399. macro("*",_SROTA)
  400.     db    7 + (#0<<3)
  401. endm
  402.  
  403. macro("*\  *",_SROT,_SS)
  404.     db    0cbh,#1 + (#0<<3)
  405. endm
  406.  
  407. macro("*\  (**)",_SROT,_SXX,NUMERIC)
  408.     db    0ddh + (#1<<5),0cbh,#2,6 + (#0<<3)
  409. endm
  410.  
  411. macro("RLD")
  412.     db    0edh,6fh
  413. endm
  414.  
  415. macro("RRD")
  416.     db    0edh,067h
  417. endm
  418.  
  419. ;
  420. ;
  421. ; 7) Bit test and set group
  422. ; =========================
  423. ;
  424.  
  425. macro("*\  *,*",_SBIT,NUMERIC,_SS)
  426. #if #1<0 || #1>7
  427. #error    "Invalid bit number!"
  428. #endif
  429.     db    0cbh,40h + (#0<<6) + (#1<<3) + #2
  430. endm
  431.  
  432. macro("*\  *,(**)",_SBIT,NUMERIC,_SXX,NUMERIC)
  433. #if #1<0 || #1>7
  434. #error    "Invalid bit number!"
  435. #endif
  436.     db    0ddh + (#2<<5),0cbh,#3,46h + (#0<<6) + (#1<<3)
  437. endm
  438.  
  439. ;
  440. ;
  441. ; 8) Jump and call group
  442. ; ======================
  443. ;
  444.  
  445. macro("JP\  *,*",_SCE,LABEL)
  446.     db    0c2h + (#0<<3)
  447.     dw    #1
  448. endm
  449.  
  450. macro("JP\  *,*",_SCE,NUMERIC)
  451.     db    0c2h + (#0<<3)
  452.     dw    #1
  453. endm
  454.  
  455. macro("CALL\  *,*",_SCE,LABEL)
  456.     db    0c4h + (#0<<3)
  457.     dw    #1
  458. endm
  459.  
  460. macro("CALL\  *,*",_SCE,NUMERIC)
  461.     db    0c4h + (#0<<3)
  462.     dw    #1
  463. endm
  464.  
  465. macro("RST\  *",NUMERIC)
  466. #if #0<0 || #0>56
  467. #error    "Invalid restart address"
  468. #elsif #0<8
  469.     db    0c7h + (#0<<3)
  470. #elsif #0 % 8 
  471. #error    "Invalid restart address"
  472. #else
  473.     db    0c7h + #0
  474. #endif
  475. endm
  476.  
  477. macro("JP\  *",LABEL)
  478.     db    0c3h
  479.     dw    #0
  480. endm
  481.  
  482. macro("JP\  *",NUMERIC)
  483.     db    0c3h
  484.     dw    #0
  485. endm
  486.  
  487. macro("CALL\  *",LABEL)
  488.     db    0cdh
  489.     dw    #0
  490. endm
  491.  
  492. macro("CALL\  *",NUMERIC)
  493.     db    0cdh
  494.     dw    #0
  495. endm
  496.  
  497. macro("JR\  *,*",_SCC,LABEL)
  498.     db    20h + (#0<<3)
  499.     drb    doreloc(#1)
  500. endm
  501.  
  502. macro("JR\  *,*",_SCC,NUMERIC)
  503.     db    20h + (#0<<3)
  504.     drb    doreloc(#1)
  505. endm
  506.  
  507. macro("JR\  *",LABEL)
  508.     db    18h
  509.     drb    doreloc(#0)
  510. endm
  511. macro("JR\  *",NUMERIC)
  512.     db    18h
  513.     drb    doreloc(#0)
  514. endm
  515.  
  516. macro("JP\  (*)",_SII)
  517. #if    #0
  518.     db    0ddh + (#0<<5)
  519. #endif
  520.     db    0e9h
  521. endm
  522.  
  523. macro("DJNZ\  *",NUMERIC)
  524.     db    10h
  525.     db    #0-($+1)
  526. endm
  527.  
  528. ;
  529. ;
  530. ; 9) Return group
  531. ; ===============
  532. ;
  533.  
  534. macro("RET")
  535.     db    0c9h
  536. endm
  537.  
  538. macro("RET\  *",_SCE)
  539.     db    0c0h + (#0<<3)
  540. endm
  541.  
  542. macro("RET I")
  543.     db    0edh,4dh
  544. endm
  545.  
  546. macro("RET N")
  547.     db    0edh,45h
  548. endm
  549.  
  550. ;
  551. ;
  552. ; 10) Input / Output group
  553. ; ========================
  554. ;
  555. macro("IN\  A,(*)",NUMERIC)
  556.     db    0dbh,#0
  557. endm
  558.  
  559. macro("OUT\  (*),A",NUMERIC)
  560.     db    0d3h,#0
  561. endm
  562.  
  563. macro("IN\  *,(C)",_SS)
  564.     db    0edh,40h + (#0<<3)
  565. endm
  566.  
  567. macro("OUT\  (C),*",_SS)
  568.     db    0edh,41h + (#0<<3)
  569. endm
  570.  
  571. macro("INI")
  572.     db    0edh,0a2h
  573. endm
  574.  
  575. macro("INIR")
  576.     db    0edh,0b2h
  577. endm
  578.  
  579. macro("OUTI")
  580.     db    0edh,0a3h
  581. endm
  582.  
  583. macro("OTIR")
  584.     db    0edh,0b3h
  585. endm
  586.  
  587. macro("IND")
  588.     db    0edh,0aah
  589. endm
  590.  
  591. macro("INDR")
  592.     db    0edh,0bah
  593. endm
  594.  
  595. macro("OUTD")
  596.     db    0edh,0abh
  597. endm
  598.  
  599. macro("OTDR")
  600.     db    0edh,0bbh
  601. endm
  602.  
  603. ;    END
  604.  
  605.