home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1996 December / PC_Shareware-1996-12.iso / windows / spectrum / sources / z80 / rotate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-11  |  29.6 KB  |  979 lines

  1.  
  2. /* Rotate.c: Z80 rotate and displacement instructions.
  3.  *
  4.  * Copyright 1996 Rui Fernando Ferreira Ribeiro.
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include "env.h"
  22.  
  23. /*=========================================================================*
  24.  *                            rlca                                         *
  25.  *=========================================================================*/
  26. /*                        ----------------
  27.              |  ----------    |
  28.              CY <- | 7  <-  0 |<--
  29.                 ----------
  30.                 A
  31.  */
  32. void rlca()
  33. {
  34.    T(4);
  35.    flags._H = flags._N = 0;
  36.    A =(A<<1)| (UCHAR)(flags._C =(A>>7));
  37.    flags._X = A & (UCHAR)BIT_5;
  38.    flags._Y = A & (UCHAR)BIT_3;
  39. }
  40.  
  41. /*=========================================================================*
  42.  *                            rla                                          *
  43.  *=========================================================================*/
  44. /*               -------------------------
  45.         |           ----------    |
  46.          --- CY <- | 7  <-  0 |<--
  47.                 ----------
  48.                 A
  49.  */
  50. void rla()
  51. {
  52.    LOCAL UCHAR flagCcopy;
  53.  
  54.    T(4);
  55.    flagCcopy = (flags._C != 0);
  56.    flags._C = A & (UCHAR)BIT_7;
  57.    A=((A<<1)|(flagCcopy));
  58.    flags._H = flags._N = 0;
  59.    flags._X = A & (UCHAR)BIT_5;
  60.    flags._Y = A & (UCHAR)BIT_3;
  61. }
  62.  
  63. /*=========================================================================*
  64.  *                            rrca                                         *
  65.  *=========================================================================*/
  66. /*                     -----------------
  67.               |     ---------   |
  68.               --> | 7  ->  0 | ---> CY
  69.                 ---------
  70.                 A
  71.  */
  72. void rrca()
  73. {
  74.    T(4);
  75.    flags._C = A & BIT_0;
  76.    A = (A>>1) | (A<<7);
  77.    flags._H = flags._N = 0;
  78.    flags._X = A & (UCHAR)BIT_5;
  79.    flags._Y = A & (UCHAR)BIT_3;
  80. }
  81.  
  82. /*=========================================================================*
  83.  *                            rra                                          *
  84.  *=========================================================================*/
  85. /*                     ---------------------
  86.               |    ---------       |
  87.               --> | 7  ->  0 | ---> CY
  88.                ---------
  89.                                           A
  90.  */
  91. void rra()
  92. {
  93.    LOCAL UCHAR flagCcopy;
  94.  
  95.    T(4);
  96.    flagCcopy = flags._C?(UCHAR)BIT_7:0;
  97.    flags._C = A & BIT_0;
  98.    A=(A>>1)|flagCcopy;
  99.    flags._H = flags._N = 0;
  100.    flags._X = A & (UCHAR)BIT_5;
  101.    flags._Y = A & (UCHAR)BIT_3;
  102. }
  103.  
  104. /*=========================================================================*
  105.  *                            rlc_r                                        *
  106.  *=========================================================================*/
  107. /*                         ----------------
  108.               |    ----------    |
  109.             CY <- | 7  <-  0 |<--
  110.                    ----------
  111.                                           r
  112.  */
  113. #define rlc_r(r, TS) { \
  114.    T(TS); \
  115.    flags._H = flags._N = 0; \
  116.    flags._Z = !((r)=((r)<<1)|(UCHAR)(flags._C=((r)>>7))); \
  117.    flags._S = ((r) & (UCHAR)BIT_7); \
  118.    flags._P = parity(r); \
  119.    flags._X = (r) & (UCHAR)BIT_5; \
  120.    flags._Y = (r) & (UCHAR)BIT_3; \
  121. }
  122.  
  123. void rlc_b()  rlc_r(B,   8);
  124. void rlc_c()  rlc_r(C,   8);
  125. void rlc_d()  rlc_r(D,   8);
  126. void rlc_e()  rlc_r(E,   8);
  127. void rlc_h()  rlc_r(H,   8);
  128. void rlc_Ix() rlc_r(HX, 15);
  129. void rlc_Iy() rlc_r(HY, 15);
  130. void rlc_l()  rlc_r(L,   8);
  131. void rlc_iX() rlc_r(LX, 15);
  132. void rlc_iY() rlc_r(LY, 15);
  133. void rlc_a()  rlc_r(A,   8);
  134.  
  135. #undef rlc_r
  136.  
  137. /*=========================================================================*
  138.  *                            rlc_phl                                      *
  139.  *=========================================================================*/
  140. /*                        ----------------
  141.              |  ----------    |
  142.              CY <- | 7  <-  0 |<--
  143.                 ----------
  144.                 (HL),(IX+d),(IY+d)
  145.  */
  146. #define rlc_pss(ss, TS) \
  147. { \
  148.    LOCAL USHORT tmp; \
  149.    LOCAL UCHAR n; \
  150.    \
  151.    T(TS); \
  152.    n = readbyte(tmp = ss); \
  153.    flags._H = flags._N = 0; \
  154.    flags._Z = !((n)=((n)<<1)|(UCHAR)(flags._C=((n)>>7))); \
  155.    flags._S = (n & (UCHAR)BIT_7); \
  156.    flags._P = parity(n); \
  157.    writebyte(tmp, n); \
  158.    flags._X = n & (UCHAR)BIT_5; \
  159.    flags._Y = n & (UCHAR)BIT_3; \
  160. }
  161.  
  162. void rlc_phl() rlc_pss(HL,    15);
  163. void rlc_pix() rlc_pss(pCBIX, 23);
  164. void rlc_piy() rlc_pss(pCBIY, 23);
  165.  
  166. #undef rlc_pss
  167.  
  168. /*=========================================================================*
  169.  *                            rl_r                                         *
  170.  *=========================================================================*/
  171. /*               -------------------------
  172.         |           ----------    |
  173.          --- CY <- | 7  <-  0 |<--
  174.                 ----------
  175.                 r
  176.  */
  177. #define rl_r(r, TS) { \
  178.    LOCAL UCHAR flagCcopy; \
  179.    \
  180.    T(TS); \
  181.    flags._H = flags._N = 0; \
  182.    flagCcopy = (flags._C != 0); \
  183.    flags._C = ((r) & (UCHAR)BIT_7); \
  184.    flags._S = (((r) = (((r) << (UCHAR)1) | flagCcopy)) & (UCHAR)BIT_7); \
  185.    flags._Z = !(r); \
  186.    flags._P = parity(r); \
  187.    flags._X = (r) & (UCHAR)BIT_5; \
  188.    flags._Y = (r) & (UCHAR)BIT_3; \
  189. }
  190.  
  191.  
  192. void rl_b()  rl_r(B,   8);
  193. void rl_c()  rl_r(C,   8);
  194. void rl_d()  rl_r(D,   8);
  195. void rl_e()  rl_r(E,   8);
  196. void rl_h()  rl_r(H,   8);
  197. void rl_Ix() rl_r(HX, 15);
  198. void rl_Iy() rl_r(HY, 15);
  199. void rl_l()  rl_r(L,   8);
  200. void rl_iX() rl_r(LX, 15);
  201. void rl_iY() rl_r(LY, 15);
  202. void rl_a()  rl_r(A,   8);
  203.  
  204. #undef rl_r
  205.  
  206. /*=========================================================================*
  207.  *                            rl_phl                                       *
  208.  *=========================================================================*/
  209. /*               -------------------------
  210.         |           ----------    |
  211.          --- CY <- | 7  <-  0 |<--
  212.                 ----------
  213.                 (HL),(IX+d),(IY+d)
  214.  */
  215.  
  216. #define rl_pss(ss, TS) \
  217. { \
  218.    LOCAL UCHAR flagCcopy; \
  219.    LOCAL USHORT tmp; \
  220.    LOCAL UCHAR n; \
  221.    \
  222.    T(TS); \
  223.    flags._H = flags._N = 0; \
  224.    flagCcopy = (flags._C != 0); \
  225.    flags._C = ((n = readbyte(tmp = ss)) & (UCHAR)BIT_7); \
  226.    flags._S = ((n = (n << (UCHAR)1) | flagCcopy) & (UCHAR)BIT_7); \
  227.    flags._Z = !n; \
  228.    flags._P = parity(n); \
  229.    writebyte(tmp, n); \
  230.    flags._X = n & (UCHAR)BIT_5; \
  231.    flags._Y = n & (UCHAR)BIT_3; \
  232. }
  233.  
  234. void rl_phl() rl_pss(HL   , 15);
  235. void rl_pix() rl_pss(pCBIX, 23);
  236. void rl_piy() rl_pss(pCBIY, 23);
  237.  
  238. #undef rl_pss
  239.  
  240. /*=========================================================================*
  241.  *                            rrc_r                                        *
  242.  *=========================================================================*/
  243. /*                     -----------------
  244.               |     ---------   |
  245.               --> | 7  ->   0| ---> CY
  246.                 ---------
  247.                 r
  248.  */
  249. #define rrc_r(r, TS) { \
  250.    T(TS); \
  251.    flags._H = flags._N = 0; \
  252.    flags._S = flags._C = (r&1)?(USHORT)0x0080:0; \
  253.    r = (r>>1) | flags._C; \
  254.    flags._Z = !r; \
  255.    flags._P = parity(r); \
  256.    flags._X = (r) & (UCHAR)BIT_5; \
  257.    flags._Y = (r) & (UCHAR)BIT_3; \
  258. }
  259.  
  260.  
  261. void rrc_b()  rrc_r(B,   8);
  262. void rrc_c()  rrc_r(C,   8);
  263. void rrc_d()  rrc_r(D,   8);
  264. void rrc_e()  rrc_r(E,   8);
  265. void rrc_h()  rrc_r(H,   8);
  266. void rrc_Ix() rrc_r(HX, 15);
  267. void rrc_Iy() rrc_r(HY, 15);
  268. void rrc_l()  rrc_r(L,   8);
  269. void rrc_iX() rrc_r(LX, 15);
  270. void rrc_iY() rrc_r(LY, 15);
  271. void rrc_a()  rrc_r(A,   8);
  272.  
  273. #undef rrc_r
  274.  
  275. /*=========================================================================*
  276.  *                            rrc_phl                                      *
  277.  *=========================================================================*/
  278. /*                     -----------------
  279.               |     ---------   |
  280.               --> | 7  ->   0| ---> CY
  281.                 ---------
  282.             (HL),(IX+d),(IY+d)
  283.  */
  284. #define rrc_pss(ss, TS) \
  285. { \
  286.    LOCAL USHORT tmp; \
  287.    LOCAL UCHAR n; \
  288.    \
  289.    T(TS); \
  290.    flags._H = flags._N = 0; \
  291.    n = readbyte(tmp = ss); \
  292.    flags._S = flags._C = (n&1)?(USHORT)0x0080:0; \
  293.    n = (n>>1) | flags._C; \
  294.    flags._Z = !n; \
  295.    flags._P = parity(n); \
  296.    writebyte(tmp, n); \
  297.    flags._X = n & (UCHAR)BIT_5; \
  298.    flags._Y = n & (UCHAR)BIT_3; \
  299. }
  300.  
  301. void rrc_phl() rrc_pss(HL,    15);
  302. void rrc_pix() rrc_pss(pCBIX, 23);
  303. void rrc_piy() rrc_pss(pCBIY, 23);
  304.  
  305. #undef rrc_pss
  306.  
  307. /*=========================================================================*
  308.  *                            rr_r                                         *
  309.  *=========================================================================*/
  310. /*                     ---------------------
  311.               |     ---------       |
  312.               --> | 7  ->  0 | ---> CY
  313.                 ---------
  314.                 r
  315.  */
  316. #define rr_r(r, TS) { \
  317.    LOCAL UCHAR flagCcopy; \
  318.    \
  319.    T(TS); \
  320.    flags._H = flags._N = 0; \
  321.    flagCcopy = flags._C?(UCHAR)BIT_7:0; \
  322.    flags._C = ((r) & (UCHAR)1); \
  323.    flags._Z = !(r = (r >> 1) | flagCcopy); \
  324.    flags._S = ((r) & (UCHAR)BIT_7); \
  325.    flags._P = parity(r); \
  326.    flags._X = (r) & (UCHAR)BIT_5; \
  327.    flags._Y = (r) & (UCHAR)BIT_3; \
  328. }
  329.  
  330. void rr_b()  rr_r(B,   8);
  331. void rr_c()  rr_r(C,   8);
  332. void rr_d()  rr_r(D,   8);
  333. void rr_e()  rr_r(E,   8);
  334. void rr_h()  rr_r(H,   8);
  335. void rr_Ix() rr_r(HX, 15);
  336. void rr_Iy() rr_r(HY, 15);
  337. void rr_l()  rr_r(L,   8);
  338. void rr_iX() rr_r(LX, 15);
  339. void rr_iY() rr_r(LY, 15);
  340. void rr_a()  rr_r(A,   8);
  341.  
  342. #undef rr_r
  343.  
  344. /*=========================================================================*
  345.  *                            rr_phl                                       *
  346.  *=========================================================================*/
  347. /*                     ---------------------
  348.               |     ----------      |
  349.               --> | 7  ->   0 | ---> CY
  350.                 ----------
  351.                 (HL),(IX+d),(IY+d)
  352.  */
  353. #define rr_pss(ss, TS) \
  354. { \
  355.    LOCAL UCHAR flagCcopy; \
  356.    LOCAL USHORT tmp; \
  357.    LOCAL UCHAR n; \
  358.    \
  359.    T(TS); \
  360.    flags._H = flags._N = 0; \
  361.    flagCcopy = flags._C?(UCHAR)BIT_7:0; \
  362.    flags._C = ((n = readbyte(tmp = ss)) & (UCHAR)1); \
  363.    flags._Z = !(n = (n >> (UCHAR)1) | flagCcopy); \
  364.    flags._S = (n & (UCHAR)BIT_7); \
  365.    flags._P = parity(n); \
  366.    writebyte(tmp, n); \
  367.    flags._X = n & (UCHAR)BIT_5; \
  368.    flags._Y = n & (UCHAR)BIT_3; \
  369. }
  370.  
  371. void rr_phl() rr_pss(HL,    15);
  372. void rr_pix() rr_pss(pCBIX, 23);
  373. void rr_piy() rr_pss(pCBIY, 23);
  374.  
  375. #undef rr_pss
  376.  
  377. /*=========================================================================*
  378.  *                            sla_r                                        *
  379.  *=========================================================================*/
  380. /*
  381.                 ----------
  382.              CY <- | 7  <-  0 |<-- 0
  383.                 ----------
  384.                 A
  385.  */
  386.  
  387. #define sla_r(r, TS) { \
  388.    T(TS); \
  389.    flags._H = flags._N = 0; \
  390.    flags._C = ((r) & (UCHAR)BIT_7); \
  391.    flags._Z = !((r) = ((r) << (UCHAR)1) ); \
  392.    flags._S = ((r) & (UCHAR)BIT_7); \
  393.    flags._P = parity(r); \
  394.    flags._X = (r) & (UCHAR)BIT_5; \
  395.    flags._Y = (r) & (UCHAR)BIT_3; \
  396. }
  397.  
  398. void sla_b()  sla_r(B,   8);
  399. void sla_c()  sla_r(C,   8);
  400. void sla_d()  sla_r(D,   8);
  401. void sla_e()  sla_r(E,   8);
  402. void sla_h()  sla_r(H,   8);
  403. void sla_Ix() sla_r(HX, 15);
  404. void sla_Iy() sla_r(HY, 15);
  405. void sla_l()  sla_r(L,   8);
  406. void sla_iX() sla_r(LX, 15);
  407. void sla_iY() sla_r(LY, 15);
  408. void sla_a()  sla_r(A,   8);
  409.  
  410. #undef sla_r
  411.  
  412. /*=========================================================================*
  413.  *                            sla_phl                                      *
  414.  *=========================================================================*/
  415. /*
  416.                 ----------
  417.              CY <- | 7  <-  0 |<-- 0
  418.                 ----------
  419.             (HL),(IX+d),(IY+d)
  420.  */
  421. #define sla_pss(ss, TS) \
  422. { \
  423.    LOCAL USHORT tmp; \
  424.    LOCAL UCHAR n; \
  425.    \
  426.    T(TS); \
  427.    flags._H = flags._N = 0; \
  428.    flags._C = ((n = readbyte(tmp = ss)) & (UCHAR)BIT_7); \
  429.    flags._Z = !(n <<= (UCHAR)1); \
  430.    flags._S = (n & (UCHAR)BIT_7); \
  431.    flags._P = parity(n); \
  432.    writebyte(tmp, n); \
  433.    flags._X = n & (UCHAR)BIT_5; \
  434.    flags._Y = n & (UCHAR)BIT_3; \
  435. }
  436.  
  437. void sla_phl() sla_pss(HL,    15);
  438. void sla_pix() sla_pss(pCBIX, 23);
  439. void sla_piy() sla_pss(pCBIY, 23);
  440.  
  441. #undef sla_pss
  442.  
  443. /*=========================================================================*
  444.  *                            sll_r                                        *
  445.  *=========================================================================*/
  446. /*
  447.                 ----------
  448.              CY <- | 7  <-  0 |<-- 1
  449.                 ----------
  450.                 A
  451.  */
  452.  
  453. #define sll_r(r, TS) { \
  454.    T(TS); \
  455.    flags._H = flags._N = 0; \
  456.    flags._C = ((r) & (UCHAR)BIT_7); \
  457.    flags._Z = !((r) = (((r) << (UCHAR)1) | (UCHAR)1) ); \
  458.    flags._S = ((r) & (UCHAR)BIT_7); \
  459.    flags._P = parity(r); \
  460.    flags._X = (r) & (UCHAR)BIT_5; \
  461.    flags._Y = (r) & (UCHAR)BIT_3; \
  462. }
  463.  
  464. void sll_b()  sll_r(B,   8);
  465. void sll_c()  sll_r(C,   8);
  466. void sll_d()  sll_r(D,   8);
  467. void sll_e()  sll_r(E,   8);
  468. void sll_h()  sll_r(H,   8);
  469. void sll_Ix() sll_r(HX, 15);
  470. void sll_Iy() sll_r(HY, 15);
  471. void sll_l()  sll_r(L,   8);
  472. void sll_iX() sll_r(LX, 15);
  473. void sll_iY() sll_r(LY, 15);
  474. void sll_a()  sll_r(A,   8);
  475.  
  476. #undef sll_r
  477.  
  478. /*=========================================================================*
  479.  *                            sll_phl                                      *
  480.  *=========================================================================*/
  481. /*
  482.                 ----------
  483.              CY <- | 7  <-  0 |<-- 1
  484.                 ----------
  485.             (HL),(IX+d),(IY+d)
  486.  */
  487. #define sll_pss(ss, TS) \
  488. { \
  489.    LOCAL USHORT tmp; \
  490.    LOCAL UCHAR n; \
  491.    \
  492.    T(TS); \
  493.    flags._H = flags._N = 0; \
  494.    flags._C = ((n = readbyte(tmp = ss)) & (UCHAR)BIT_7); \
  495.    flags._Z = !(n = ((n << (UCHAR)1) | 1)); \
  496.    flags._S = (n & (UCHAR)BIT_7); \
  497.    flags._P = parity(n); \
  498.    writebyte(tmp, n); \
  499.    flags._X = n & (UCHAR)BIT_5; \
  500.    flags._Y = n & (UCHAR)BIT_3; \
  501. }
  502.  
  503. void sll_phl() sll_pss(HL,    15);
  504. void sll_pix() sll_pss(pCBIX, 23);
  505. void sll_piy() sll_pss(pCBIY, 23);
  506.  
  507. #undef sll_pss
  508.  
  509. /*=========================================================================*
  510.  *                            sra_r                                        *
  511.  *=========================================================================*/
  512. /*
  513.                 ----------
  514.                --  | 7  ->  0 | ---> CY
  515.               |     ----------
  516.               |     |  r
  517.                ->---
  518. */
  519. #define sra_r(r, TS) { \
  520.    T(TS); \
  521.    flags._H = flags._N = 0; \
  522.    flags._C = (r) & (UCHAR)1; \
  523.    flags._Z = !((r) = ((r) & (UCHAR)BIT_7) | ((r) >> (UCHAR)1)); \
  524.    flags._S = ((r) & (UCHAR)BIT_7); \
  525.    flags._P = parity(r); \
  526.    flags._X = (r) & (UCHAR)BIT_5; \
  527.    flags._Y = (r) & (UCHAR)BIT_3; \
  528. }
  529.  
  530.  
  531. void sra_b()  sra_r(B,   8);
  532. void sra_c()  sra_r(C,   8);
  533. void sra_d()  sra_r(D,   8);
  534. void sra_e()  sra_r(E,   8);
  535. void sra_h()  sra_r(H,   8);
  536. void sra_Ix() sra_r(HX, 15);
  537. void sra_Iy() sra_r(HY, 15);
  538. void sra_l()  sra_r(L,   8);
  539. void sra_iX() sra_r(LX, 15);
  540. void sra_iY() sra_r(LY, 15);
  541. void sra_a()  sra_r(A,   8);
  542.  
  543. #undef sra_r
  544.  
  545. /*=========================================================================*
  546.  *                            sra_phl                                      *
  547.  *=========================================================================*/
  548. /*
  549.                 ----------
  550.                --  | 7  ->  0 | ---> CY
  551.               |     ----------
  552.               |     ^  (HL),(IX+d),(IY+d)
  553.               |     |
  554.                ->---
  555. */
  556. #define sra_pss(ss, TS) \
  557. { \
  558.    LOCAL USHORT tmp; \
  559.    LOCAL UCHAR n; \
  560.    \
  561.    T(TS); \
  562.    flags._H = flags._N = 0; \
  563.    flags._C = (n = readbyte(tmp = ss)) & (UCHAR)1; \
  564.    flags._Z = !(n = (n & (UCHAR)BIT_7) | (n >> (UCHAR)1)); \
  565.    flags._S = (n & (UCHAR)BIT_7); \
  566.    flags._P = parity(n); \
  567.    writebyte(tmp, n); \
  568.    flags._X = n & (UCHAR)BIT_5; \
  569.    flags._Y = n & (UCHAR)BIT_3; \
  570. }
  571.  
  572. void sra_phl() sra_pss(HL,    15);
  573. void sra_pix() sra_pss(pCBIX, 23);
  574. void sra_piy() sra_pss(pCBIY, 23);
  575.  
  576. #undef sra_pss
  577.  
  578. /*=========================================================================*
  579.  *                            srl_r                                        *
  580.  *=========================================================================*/
  581. /*
  582.                 ----------
  583.              0 --> | 7  ->  0 | ---> CY
  584.                 ----------
  585.                 r
  586.  
  587. */
  588. #define srl_r(r, TS) { \
  589.    T(TS); \
  590.    flags._H = flags._N = 0; \
  591.    flags._C = (r) & (UCHAR)1; \
  592.    flags._Z = !((r) >>= (UCHAR)1); \
  593.    flags._S = ((r) & (UCHAR)BIT_7); \
  594.    flags._P = parity(r); \
  595.    flags._X = (r) & (UCHAR)BIT_5; \
  596.    flags._Y = (r) & (UCHAR)BIT_3; \
  597. }
  598.  
  599. void srl_b()  srl_r(B, 8);
  600. void srl_c()  srl_r(C, 8);
  601. void srl_d()  srl_r(D, 8);
  602. void srl_e()  srl_r(E, 8);
  603. void srl_h()  srl_r(H, 8);
  604. void srl_Ix() srl_r(HX, 15);
  605. void srl_Iy() srl_r(HY, 15);
  606. void srl_l()  srl_r(L, 8);
  607. void srl_iX() srl_r(LX, 15);
  608. void srl_iY() srl_r(LY, 15);
  609. void srl_a()  srl_r(A, 8);
  610.  
  611. #undef srl_r
  612.  
  613. /*=========================================================================*
  614.  *                            srl_phl                                      *
  615.  *=========================================================================*/
  616. /*
  617.                 ----------
  618.              0 --> | 7  ->  0 | ---> CY
  619.                 ----------
  620.             (HL),(IX+d),(IY+d)
  621.  
  622. */
  623. #define srl_pss(ss, TS) \
  624. { \
  625.    LOCAL USHORT tmp; \
  626.    LOCAL UCHAR n; \
  627.    \
  628.    T(TS); \
  629.    flags._H = flags._N = 0; \
  630.    flags._C = (n = readbyte(tmp = ss)) & (UCHAR)1; \
  631.    flags._Z = !(n >>= (UCHAR)1); \
  632.    flags._S = (n & (UCHAR)BIT_7); \
  633.    flags._P = parity(n); \
  634.    writebyte(tmp, n); \
  635.    flags._X = n & (UCHAR)BIT_5; \
  636.    flags._Y = n & (UCHAR)BIT_3; \
  637. }
  638.  
  639. void srl_phl() srl_pss(HL,    15);
  640. void srl_pix() srl_pss(pCBIX, 23);
  641. void srl_piy() srl_pss(pCBIY, 23);
  642.  
  643. #undef srl_pss
  644.  
  645. /*=========================================================================*
  646.  *                            rld                                          *
  647.  *=========================================================================*/
  648. /******  RLD:            ____________________
  649.             ^                    |
  650.         [A]  1111 1111     [(HL)]  1111 1111
  651.             ^              |  ^    |
  652.             ----------------  ------
  653. **/
  654. void rld()
  655. {
  656.    LOCAL UCHAR n;
  657.  
  658.    T(18);
  659.    writebyte(HL, (A & (UCHAR)0x0F) | ((n=readbyte(HL))<<4) );
  660.    A = (A & (UCHAR)0xF0) | (n>>4);
  661.    flags._H = flags._N = 0;
  662.    flags._Z = !A;
  663.    flags._S = (A & (UCHAR)BIT_7);
  664.    flags._P = parity(A);
  665.    flags._X = A & (UCHAR)BIT_5;
  666.    flags._Y = A & (UCHAR)BIT_3;
  667. };
  668.  
  669. /*=========================================================================*
  670.  *                            rrd                                          *
  671.  *=========================================================================*/
  672. /******  RRD:            ______________   ____
  673.             ^              | ^    |
  674.         [A]  1111 1111     [(HL)]  1111 1111
  675.             ^                     |
  676.             -----------------------
  677. **/
  678. void rrd()
  679. {
  680.    LOCAL UCHAR n;
  681.  
  682.    T(18);
  683.    writebyte(HL, (A<<4) | ((n = readbyte(HL))>>4));
  684.    A = (A & (UCHAR)0xF0) | (n & (UCHAR)0x0F);
  685.    flags._Z = !A;
  686.    flags._H = flags._N = 0;
  687.    flags._S = (A & (UCHAR)BIT_7);
  688.    flags._P = parity(A);
  689.    flags._X = A & (UCHAR)BIT_5;
  690.    flags._Y = A & (UCHAR)BIT_3;
  691. }
  692.  
  693. /* =================================== */
  694. #define rlc_CB(r) { T(23); rlc_pix(); r=readbyte(pCBIX); }
  695. void rlc_pixb() rlc_CB(B);
  696. void rlc_pixc() rlc_CB(C);
  697. void rlc_pixd() rlc_CB(D);
  698. void rlc_pixe() rlc_CB(E);
  699. void rlc_pixa() rlc_CB(A);
  700. #undef rlc_CB
  701. #define rlc_CB(r) { T(23); rlc_piy(); r=readbyte(pCBIY); }
  702. void rlc_piyb() rlc_CB(B);
  703. void rlc_piyc() rlc_CB(C);
  704. void rlc_piyd() rlc_CB(D);
  705. void rlc_piye() rlc_CB(E);
  706. void rlc_piya() rlc_CB(A);
  707. #undef rlc_CB
  708. #define rrc_CB(r) { T(23); rrc_pix(); r=readbyte(pCBIX); }
  709. void rrc_pixb() rrc_CB(B);
  710. void rrc_pixc() rrc_CB(C);
  711. void rrc_pixd() rrc_CB(D);
  712. void rrc_pixe() rrc_CB(E);
  713. void rrc_pixa() rrc_CB(A);
  714. #undef rrc_CB
  715. #define rrc_CB(r) { T(23); rrc_piy(); r=readbyte(pCBIY); }
  716. void rrc_piyb() rrc_CB(B);
  717. void rrc_piyc() rrc_CB(C);
  718. void rrc_piyd() rrc_CB(D);
  719. void rrc_piye() rrc_CB(E);
  720. void rrc_piya() rrc_CB(A);
  721. #undef rrc_CB
  722. #define rl_CB(r) { T(23); rl_pix(); r=readbyte(pCBIX); }
  723. void rl_pixb() rl_CB(B);
  724. void rl_pixc() rl_CB(C);
  725. void rl_pixd() rl_CB(D);
  726. void rl_pixe() rl_CB(E);
  727. void rl_pixa() rl_CB(A);
  728. #undef rl_CB
  729. #define rl_CB(r) { T(23); rl_piy(); r=readbyte(pCBIY); }
  730. void rl_piyb() rl_CB(B);
  731. void rl_piyc() rl_CB(C);
  732. void rl_piyd() rl_CB(D);
  733. void rl_piye() rl_CB(E);
  734. void rl_piya() rl_CB(A);
  735. #undef rl_CB
  736. #define rr_CB(r) { T(23); rr_pix(); r=readbyte(pCBIX); }
  737. void rr_pixb() rr_CB(B);
  738. void rr_pixc() rr_CB(C);
  739. void rr_pixd() rr_CB(D);
  740. void rr_pixe() rr_CB(E);
  741. void rr_pixa() rr_CB(A);
  742. #undef rr_CB
  743. #define rr_CB(r) { T(23); rr_piy(); r=readbyte(pCBIY); }
  744. void rr_piyb() rr_CB(B);
  745. void rr_piyc() rr_CB(C);
  746. void rr_piyd() rr_CB(D);
  747. void rr_piye() rr_CB(E);
  748. void rr_piya() rr_CB(A);
  749. #undef rr_CB
  750. #define sla_CB(r) { T(23); sla_pix(); r=readbyte(pCBIX); }
  751. void sla_pixb() sla_CB(B);
  752. void sla_pixc() sla_CB(C);
  753. void sla_pixd() sla_CB(D);
  754. void sla_pixe() sla_CB(E);
  755. void sla_pixa() sla_CB(A);
  756. #undef sla_CB
  757. #define sla_CB(r) { T(23); sla_piy(); r=readbyte(pCBIY); }
  758. void sla_piyb() sla_CB(B);
  759. void sla_piyc() sla_CB(C);
  760. void sla_piyd() sla_CB(D);
  761. void sla_piye() sla_CB(E);
  762. void sla_piya() sla_CB(A);
  763. #undef sla_CB
  764. #define sra_CB(r) { T(23); sra_pix(); r=readbyte(pCBIX); }
  765. void sra_pixb() sra_CB(B);
  766. void sra_pixc() sra_CB(C);
  767. void sra_pixd() sra_CB(D);
  768. void sra_pixe() sra_CB(E);
  769. void sra_pixa() sra_CB(A);
  770. #undef sra_CB
  771. #define sra_CB(r) { T(23); sra_piy(); r=readbyte(pCBIY); }
  772. void sra_piyb() sra_CB(B);
  773. void sra_piyc() sra_CB(C);
  774. void sra_piyd() sra_CB(D);
  775. void sra_piye() sra_CB(E);
  776. void sra_piya() sra_CB(A);
  777. #undef sra_CB
  778. #define sll_CB(r) { T(23); sll_pix(); r=readbyte(pCBIX); }
  779. void sll_pixb() sll_CB(B);
  780. void sll_pixc() sll_CB(C);
  781. void sll_pixd() sll_CB(D);
  782. void sll_pixe() sll_CB(E);
  783. void sll_pixa() sll_CB(A);
  784. #undef sll_CB
  785. #define sll_CB(r) { T(23); sll_piy(); r=readbyte(pCBIY); }
  786. void sll_piyb() sll_CB(B);
  787. void sll_piyc() sll_CB(C);
  788. void sll_piyd() sll_CB(D);
  789. void sll_piye() sll_CB(E);
  790. void sll_piya() sll_CB(A);
  791. #undef sll_CB
  792. #define srl_CB(r) { T(23); srl_pix(); r=readbyte(pCBIX); }
  793. void srl_pixb() srl_CB(B);
  794. void srl_pixc() srl_CB(C);
  795. void srl_pixd() srl_CB(D);
  796. void srl_pixe() srl_CB(E);
  797. void srl_pixa() srl_CB(A);
  798. #undef srl_CB
  799. #define srl_CB(r) { T(23); srl_piy(); r=readbyte(pCBIY); }
  800. void srl_piyb() srl_CB(B);
  801. void srl_piyc() srl_CB(C);
  802. void srl_piyd() srl_CB(D);
  803. void srl_piye() srl_CB(E);
  804. void srl_piya() srl_CB(A);
  805. #undef srl_CB
  806.  
  807. #define res_CB(r, expr) { T(23); expr(); r=readbyte(pCBIX); }
  808. void res_0_pixb() res_CB(B, res_0_pix);
  809. void res_0_pixc() res_CB(C, res_0_pix);
  810. void res_0_pixd() res_CB(D, res_0_pix);
  811. void res_0_pixe() res_CB(E, res_0_pix);
  812. void res_0_pixa() res_CB(A, res_0_pix);
  813. void res_1_pixb() res_CB(B, res_1_pix);
  814. void res_1_pixc() res_CB(C, res_1_pix);
  815. void res_1_pixd() res_CB(D, res_1_pix);
  816. void res_1_pixe() res_CB(E, res_1_pix);
  817. void res_1_pixa() res_CB(A, res_1_pix);
  818. void res_2_pixb() res_CB(B, res_2_pix);
  819. void res_2_pixc() res_CB(C, res_2_pix);
  820. void res_2_pixd() res_CB(D, res_2_pix);
  821. void res_2_pixe() res_CB(E, res_2_pix);
  822. void res_2_pixa() res_CB(A, res_2_pix);
  823. void res_3_pixb() res_CB(B, res_3_pix);
  824. void res_3_pixc() res_CB(C, res_3_pix);
  825. void res_3_pixd() res_CB(D, res_3_pix);
  826. void res_3_pixe() res_CB(E, res_3_pix);
  827. void res_3_pixa() res_CB(A, res_3_pix);
  828. void res_4_pixb() res_CB(B, res_4_pix);
  829. void res_4_pixc() res_CB(C, res_4_pix);
  830. void res_4_pixd() res_CB(D, res_4_pix);
  831. void res_4_pixe() res_CB(E, res_4_pix);
  832. void res_4_pixa() res_CB(A, res_4_pix);
  833. void res_5_pixb() res_CB(B, res_5_pix);
  834. void res_5_pixc() res_CB(C, res_5_pix);
  835. void res_5_pixd() res_CB(D, res_5_pix);
  836. void res_5_pixe() res_CB(E, res_5_pix);
  837. void res_5_pixa() res_CB(A, res_5_pix);
  838. void res_6_pixb() res_CB(B, res_6_pix);
  839. void res_6_pixc() res_CB(C, res_6_pix);
  840. void res_6_pixd() res_CB(D, res_6_pix);
  841. void res_6_pixe() res_CB(E, res_6_pix);
  842. void res_6_pixa() res_CB(A, res_6_pix);
  843. void res_7_pixb() res_CB(B, res_7_pix);
  844. void res_7_pixc() res_CB(C, res_7_pix);
  845. void res_7_pixd() res_CB(D, res_7_pix);
  846. void res_7_pixe() res_CB(E, res_7_pix);
  847. void res_7_pixa() res_CB(A, res_7_pix);
  848. #undef res_CB
  849. #define res_CB(r, expr) { T(23); expr(); r=readbyte(pCBIY); }
  850. void res_0_piyb() res_CB(B, res_0_piy);
  851. void res_0_piyc() res_CB(C, res_0_piy);
  852. void res_0_piyd() res_CB(D, res_0_piy);
  853. void res_0_piye() res_CB(E, res_0_piy);
  854. void res_0_piya() res_CB(A, res_0_piy);
  855. void res_1_piyb() res_CB(B, res_1_piy);
  856. void res_1_piyc() res_CB(C, res_1_piy);
  857. void res_1_piyd() res_CB(D, res_1_piy);
  858. void res_1_piye() res_CB(E, res_1_piy);
  859. void res_1_piya() res_CB(A, res_1_piy);
  860. void res_2_piyb() res_CB(B, res_2_piy);
  861. void res_2_piyc() res_CB(C, res_2_piy);
  862. void res_2_piyd() res_CB(D, res_2_piy);
  863. void res_2_piye() res_CB(E, res_2_piy);
  864. void res_2_piya() res_CB(A, res_2_piy);
  865. void res_3_piyb() res_CB(B, res_3_piy);
  866. void res_3_piyc() res_CB(C, res_3_piy);
  867. void res_3_piyd() res_CB(D, res_3_piy);
  868. void res_3_piye() res_CB(E, res_3_piy);
  869. void res_3_piya() res_CB(A, res_3_piy);
  870. void res_4_piyb() res_CB(B, res_4_piy);
  871. void res_4_piyc() res_CB(C, res_4_piy);
  872. void res_4_piyd() res_CB(D, res_4_piy);
  873. void res_4_piye() res_CB(E, res_4_piy);
  874. void res_4_piya() res_CB(A, res_4_piy);
  875. void res_5_piyb() res_CB(B, res_5_piy);
  876. void res_5_piyc() res_CB(C, res_5_piy);
  877. void res_5_piyd() res_CB(D, res_5_piy);
  878. void res_5_piye() res_CB(E, res_5_piy);
  879. void res_5_piya() res_CB(A, res_5_piy);
  880. void res_6_piyb() res_CB(B, res_6_piy);
  881. void res_6_piyc() res_CB(C, res_6_piy);
  882. void res_6_piyd() res_CB(D, res_6_piy);
  883. void res_6_piye() res_CB(E, res_6_piy);
  884. void res_6_piya() res_CB(A, res_6_piy);
  885. void res_7_piyb() res_CB(B, res_7_piy);
  886. void res_7_piyc() res_CB(C, res_7_piy);
  887. void res_7_piyd() res_CB(D, res_7_piy);
  888. void res_7_piye() res_CB(E, res_7_piy);
  889. void res_7_piya() res_CB(A, res_7_piy);
  890. #undef res_CB
  891.  
  892. /* ++++++++ */
  893. #define set_CB(r, expr) { T(23); expr(); r=readbyte(pCBIX); }
  894. void set_0_pixb() set_CB(B, set_0_pix);
  895. void set_0_pixc() set_CB(C, set_0_pix);
  896. void set_0_pixd() set_CB(D, set_0_pix);
  897. void set_0_pixe() set_CB(E, set_0_pix);
  898. void set_0_pixa() set_CB(A, set_0_pix);
  899. void set_1_pixb() set_CB(B, set_1_pix);
  900. void set_1_pixc() set_CB(C, set_1_pix);
  901. void set_1_pixd() set_CB(D, set_1_pix);
  902. void set_1_pixe() set_CB(E, set_1_pix);
  903. void set_1_pixa() set_CB(A, set_1_pix);
  904. void set_2_pixb() set_CB(B, set_2_pix);
  905. void set_2_pixc() set_CB(C, set_2_pix);
  906. void set_2_pixd() set_CB(D, set_2_pix);
  907. void set_2_pixe() set_CB(E, set_2_pix);
  908. void set_2_pixa() set_CB(A, set_2_pix);
  909. void set_3_pixb() set_CB(B, set_3_pix);
  910. void set_3_pixc() set_CB(C, set_3_pix);
  911. void set_3_pixd() set_CB(D, set_3_pix);
  912. void set_3_pixe() set_CB(E, set_3_pix);
  913. void set_3_pixa() set_CB(A, set_3_pix);
  914. void set_4_pixb() set_CB(B, set_4_pix);
  915. void set_4_pixc() set_CB(C, set_4_pix);
  916. void set_4_pixd() set_CB(D, set_4_pix);
  917. void set_4_pixe() set_CB(E, set_4_pix);
  918. void set_4_pixa() set_CB(A, set_4_pix);
  919. void set_5_pixb() set_CB(B, set_5_pix);
  920. void set_5_pixc() set_CB(C, set_5_pix);
  921. void set_5_pixd() set_CB(D, set_5_pix);
  922. void set_5_pixe() set_CB(E, set_5_pix);
  923. void set_5_pixa() set_CB(A, set_5_pix);
  924. void set_6_pixb() set_CB(B, set_6_pix);
  925. void set_6_pixc() set_CB(C, set_6_pix);
  926. void set_6_pixd() set_CB(D, set_6_pix);
  927. void set_6_pixe() set_CB(E, set_6_pix);
  928. void set_6_pixa() set_CB(A, set_6_pix);
  929. void set_7_pixb() set_CB(B, set_7_pix);
  930. void set_7_pixc() set_CB(C, set_7_pix);
  931. void set_7_pixd() set_CB(D, set_7_pix);
  932. void set_7_pixe() set_CB(E, set_7_pix);
  933. void set_7_pixa() set_CB(A, set_7_pix);
  934. #undef set_CB
  935. #define set_CB(r, expr) { T(23); expr(); r=readbyte(pCBIY); }
  936. void set_0_piyb() set_CB(B, set_0_piy);
  937. void set_0_piyc() set_CB(C, set_0_piy);
  938. void set_0_piyd() set_CB(D, set_0_piy);
  939. void set_0_piye() set_CB(E, set_0_piy);
  940. void set_0_piya() set_CB(A, set_0_piy);
  941. void set_1_piyb() set_CB(B, set_1_piy);
  942. void set_1_piyc() set_CB(C, set_1_piy);
  943. void set_1_piyd() set_CB(D, set_1_piy);
  944. void set_1_piye() set_CB(E, set_1_piy);
  945. void set_1_piya() set_CB(A, set_1_piy);
  946. void set_2_piyb() set_CB(B, set_2_piy);
  947. void set_2_piyc() set_CB(C, set_2_piy);
  948. void set_2_piyd() set_CB(D, set_2_piy);
  949. void set_2_piye() set_CB(E, set_2_piy);
  950. void set_2_piya() set_CB(A, set_2_piy);
  951. void set_3_piyb() set_CB(B, set_3_piy);
  952. void set_3_piyc() set_CB(C, set_3_piy);
  953. void set_3_piyd() set_CB(D, set_3_piy);
  954. void set_3_piye() set_CB(E, set_3_piy);
  955. void set_3_piya() set_CB(A, set_3_piy);
  956. void set_4_piyb() set_CB(B, set_4_piy);
  957. void set_4_piyc() set_CB(C, set_4_piy);
  958. void set_4_piyd() set_CB(D, set_4_piy);
  959. void set_4_piye() set_CB(E, set_4_piy);
  960. void set_4_piya() set_CB(A, set_4_piy);
  961. void set_5_piyb() set_CB(B, set_5_piy);
  962. void set_5_piyc() set_CB(C, set_5_piy);
  963. void set_5_piyd() set_CB(D, set_5_piy);
  964. void set_5_piye() set_CB(E, set_5_piy);
  965. void set_5_piya() set_CB(A, set_5_piy);
  966. void set_6_piyb() set_CB(B, set_6_piy);
  967. void set_6_piyc() set_CB(C, set_6_piy);
  968. void set_6_piyd() set_CB(D, set_6_piy);
  969. void set_6_piye() set_CB(E, set_6_piy);
  970. void set_6_piya() set_CB(A, set_6_piy);
  971. void set_7_piyb() set_CB(B, set_7_piy);
  972. void set_7_piyc() set_CB(C, set_7_piy);
  973. void set_7_piyd() set_CB(D, set_7_piy);
  974. void set_7_piye() set_CB(E, set_7_piy);
  975. void set_7_piya() set_CB(A, set_7_piy);
  976. #undef set_CB
  977.  
  978. /* EOF: Rotate.c */
  979.