home *** CD-ROM | disk | FTP | other *** search
/ Emulator Universe CD / emulatoruniversecd1998.iso / Speccy / Emulators / winemu / SOURCES / Z80 / MATH8BIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  19.3 KB  |  625 lines

  1. /* Math8Bit.c: Z80's 8 bit arithmetic and logic instructions.
  2.  *
  3.  * Copyright 1996 Rui Fernando Ferreira Ribeiro.
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include "env.h"
  21.  
  22. /*=========================================================================*
  23.  *                            add_a_r                                      *
  24.  *=========================================================================*/
  25.  
  26. #define add_a_r(r, TS) { \
  27.    LOCAL UCHAR tmp; \
  28.    \
  29.    T(TS); \
  30.    flags._H = ( ((A & (UCHAR)0xF) + ((r) & (UCHAR)0xF) ) > (UCHAR)0xF ); \
  31.    flags._N = 0; \
  32.    flags._C = ((tmp = (UCHAR)(A + (r)))<A); \
  33.    flags._P = (~A^(r)) & (UCHAR)BIT_7 & (tmp ^  A); \
  34.    flags._S = ((A = tmp) & (UCHAR)BIT_7); \
  35.    flags._Z = !A; \
  36.    flags._X = A & (UCHAR)BIT_5; \
  37.    flags._Y = A & (UCHAR)BIT_3; \
  38. }
  39.  
  40.  
  41. void add_a_b()  add_a_r(B, 4);
  42. void add_a_c()  add_a_r(C, 4);
  43. void add_a_d()  add_a_r(D, 4);
  44. void add_a_e()  add_a_r(E, 4);
  45. void add_a_h()  add_a_r(H, 4);
  46. void add_a_Ix() add_a_r(HX, 8);
  47. void add_a_Iy() add_a_r(HY, 8);
  48. void add_a_l()  add_a_r(L, 4);
  49. void add_a_iX() add_a_r(LX, 8);
  50. void add_a_iY() add_a_r(LY, 8);
  51. void add_a_a()  add_a_r(A, 4);
  52.  
  53. #undef add_a_r
  54.  
  55. /*=========================================================================*
  56.  *                            add_a_r                                      *
  57.  *=========================================================================*/
  58. #define add_a_pss(ss, TS) \
  59. { \
  60.    LOCAL UCHAR tmp, n; \
  61.    \
  62.    T(TS); \
  63.    flags._H = ( ((A & (UCHAR)0xF) + ((n = ss) & (UCHAR)0xF) ) > \
  64.         (UCHAR)0xF ); \
  65.    flags._N = 0; \
  66.    flags._C = ((tmp = (UCHAR)(A + (UCHAR)n))<A); \
  67.    flags._P = (~A^n) & (UCHAR)BIT_7 & (tmp^A); \
  68.    flags._S = ((A = tmp) & (UCHAR)BIT_7); \
  69.    flags._Z = !A; \
  70.    flags._X = A & (UCHAR)BIT_5; \
  71.    flags._Y = A & (UCHAR)BIT_3; \
  72. }
  73.  
  74. void add_a_n() add_a_pss(Getnextbyte(), 7);
  75.  
  76. /*=========================================================================*
  77.  *                            add_a_phl                                    *
  78.  *=========================================================================*/
  79. void add_a_phl() add_a_pss(readbyte(HL),  7);
  80. void add_a_pix() add_a_pss(readbyte(pIX), 19);
  81. void add_a_piy() add_a_pss(readbyte(pIY), 19);
  82.  
  83. #undef add_a_pss
  84.  
  85. /*=========================================================================*
  86.  *                            adc_a_r                                      *
  87.  *=========================================================================*/
  88.  
  89. #define adc_a_r(r, TS) { \
  90.    LOCAL UCHAR tmp; \
  91.    \
  92.    T(TS); \
  93.    flags._H = ( ((A & (UCHAR)0xF) + ((r) & (UCHAR)0xF) ) > (UCHAR)0xF ); \
  94.    flags._N = 0; \
  95.    flags._C = ((tmp = (UCHAR)(A + (r) + (UCHAR)(flags._C != 0)))< A) \
  96.          || ((tmp==A)&& (r) ); \
  97.    flags._P = (~A^(r)) & (UCHAR)BIT_7 & (tmp^A); \
  98.    flags._S = ((A = tmp) & (UCHAR)BIT_7); \
  99.    flags._Z = !A; \
  100.    flags._X = A & (UCHAR)BIT_5; \
  101.    flags._Y = A & (UCHAR)BIT_3; \
  102. }
  103.  
  104. void adc_a_b()  adc_a_r(B,  4);
  105. void adc_a_c()  adc_a_r(C,  4);
  106. void adc_a_d()  adc_a_r(D,  4);
  107. void adc_a_e()  adc_a_r(E,  4);
  108. void adc_a_h()  adc_a_r(H,  4);
  109. void adc_a_Ix() adc_a_r(HX, 8);
  110. void adc_a_Iy() adc_a_r(HY, 8);
  111. void adc_a_l()  adc_a_r(L,  4);
  112. void adc_a_iX() adc_a_r(LX, 8);
  113. void adc_a_iY() adc_a_r(LY, 8);
  114. void adc_a_a()  adc_a_r(A,  4);
  115.  
  116. #undef adc_a_r
  117.  
  118. /*=========================================================================*
  119.  *                            adc_a_n                                      *
  120.  *=========================================================================*/
  121. #define adc_a_pss(ss, TS) \
  122. { \
  123.    LOCAL UCHAR tmp, n; \
  124.    \
  125.    T(TS); \
  126.    flags._H = ( ((A & (UCHAR)0xF) + ((n = (ss)) & (UCHAR)0xF) ) > \
  127.         (UCHAR)0xF ); \
  128.    flags._N = 0; \
  129.    flags._C = ((tmp = (UCHAR)(A + n + (UCHAR)(flags._C != 0)))< A) \
  130.              || ((tmp==A) && n); \
  131.    flags._P = (~A^n) & (UCHAR)BIT_7 & (tmp^A); \
  132.    flags._S = ((A = tmp) & (UCHAR)BIT_7); \
  133.    flags._Z = !A; \
  134.    flags._X = A & (UCHAR)BIT_5; \
  135.    flags._Y = A & (UCHAR)BIT_3; \
  136. }
  137.  
  138. void adc_a_n() adc_a_pss(Getnextbyte(), 7);
  139.  
  140. /*=========================================================================*
  141.  *                            adc_a_phl                                    *
  142.  *=========================================================================*/
  143. void adc_a_phl() adc_a_pss(readbyte(HL),   7);
  144. void adc_a_pix() adc_a_pss(readbyte(pIX), 19);
  145. void adc_a_piy() adc_a_pss(readbyte(pIY), 19);
  146.  
  147. #undef add_a_pss
  148.  
  149. /*=========================================================================*
  150.  *                            sub_r                                        *
  151.  *=========================================================================*/
  152.  
  153. #define sub_r(r, TS) { \
  154.    LOCAL UCHAR tmp; \
  155.    \
  156.    T(TS); \
  157.    flags._N = 1; \
  158.    flags._H = (((r) & (UCHAR)0xF) > (A & (UCHAR)0xF) ); \
  159.    flags._Z = !(tmp = (UCHAR)(A - (r))); \
  160.    flags._C = ((r) > A); \
  161.    flags._P = (A^(r)) & (UCHAR)BIT_7 & (tmp^A); \
  162.    flags._S = ((A = tmp) & (UCHAR)BIT_7); \
  163.    flags._X = A & (UCHAR)BIT_5; \
  164.    flags._Y = A & (UCHAR)BIT_3; \
  165. }
  166.  
  167.  
  168. void sub_b()  sub_r(B,  4);
  169. void sub_c()  sub_r(C,  4);
  170. void sub_d()  sub_r(D,  4);
  171. void sub_e()  sub_r(E,  4);
  172. void sub_h()  sub_r(H,  4);
  173. void sub_Ix() sub_r(HX, 8);
  174. void sub_Iy() sub_r(HY, 8);
  175. void sub_l()  sub_r(L,  4);
  176. void sub_iX() sub_r(LX, 8);
  177. void sub_iY() sub_r(LY, 8);
  178. void sub_a()  sub_r(A,  4);
  179. /*
  180. void sub_a()
  181. {
  182.    flags._Z = flags._N = 1;
  183.    A = flags._X = flags._Y = flags._H = flags._C = flags._P = flags._S = 0;
  184. }
  185. */
  186.  
  187. #undef sub_r
  188.  
  189. /*=========================================================================*
  190.  *                            sub_n                                        *
  191.  *=========================================================================*/
  192. #define sub_pss(ss, TS) \
  193. { \
  194.    LOCAL UCHAR tmp, n; \
  195.    \
  196.    T(7); \
  197.    flags._N = 1; \
  198.    flags._H = (((n = ss) & (UCHAR)0xF) > (A & (UCHAR)0xF) ); \
  199.    flags._Z = !(tmp = (UCHAR)(A - n)); \
  200.    flags._C = (n > A); \
  201.    flags._P = (A^n) & (UCHAR)BIT_7 & (tmp^A); \
  202.    flags._S = ((A = tmp) & (UCHAR)BIT_7); \
  203.    flags._X = A & (UCHAR)BIT_5; \
  204.    flags._Y = A & (UCHAR)BIT_3; \
  205. }
  206.  
  207. void sub_n() sub_pss(Getnextbyte(), 7);
  208.  
  209. /*=========================================================================*
  210.  *                            sub_phl                                      *
  211.  *=========================================================================*/
  212. void sub_phl() sub_pss(readbyte(HL),   7);
  213. void sub_pix() sub_pss(readbyte(pIX), 19);
  214. void sub_piy() sub_pss(readbyte(pIY), 19);
  215.  
  216. #undef sub_pss
  217.  
  218. /*=========================================================================*
  219.  *                            sbc_a_r                                      *
  220.  *=========================================================================*/
  221.  
  222. #define sbc_a_r(r, TS) { \
  223.    LOCAL UCHAR tmp; \
  224.    \
  225.    T(TS); \
  226.    flags._N = 1; \
  227.    flags._H = (((r) & (UCHAR)0xF) > (A & (UCHAR)0xF) ); \
  228.    flags._Z = !(tmp = (UCHAR)(A - (r) - (UCHAR)(flags._C != 0))); \
  229.    flags._C = ((r) > A) || (tmp > A); \
  230.    flags._P = (A^(r)) & (UCHAR)BIT_7 & (tmp^A); \
  231.    flags._S = ((A = tmp) & (UCHAR)BIT_7); \
  232.    flags._X = A & (UCHAR)BIT_5; \
  233.    flags._Y = A & (UCHAR)BIT_3; \
  234. }
  235.  
  236. void sbc_a_b()  sbc_a_r(B,  4);
  237. void sbc_a_c()  sbc_a_r(C,  4);
  238. void sbc_a_d()  sbc_a_r(D,  4);
  239. void sbc_a_e()  sbc_a_r(E,  4);
  240. void sbc_a_h()  sbc_a_r(H,  4);
  241. void sbc_a_Ix() sbc_a_r(HX, 8);
  242. void sbc_a_Iy() sbc_a_r(HY, 8);
  243. void sbc_a_l()  sbc_a_r(L,  4);
  244. void sbc_a_iX() sbc_a_r(LX, 8);
  245. void sbc_a_iY() sbc_a_r(LY, 8);
  246. void sbc_a_a()  sbc_a_r(A,  4);
  247. /*
  248. void sbc_a_a()
  249. {
  250.    T(4);
  251.    flags._N = 1;
  252.    flags._P = 0;
  253.    A = (flags._Z = !(flags._X = flags._Y = flags._H = flags._C) ) ?
  254.        0 : (UCHAR)0xFF;
  255. }
  256. */
  257.  
  258. #undef sbc_a_r
  259. /*=========================================================================*
  260.  *                            sbc_a_n                                      *
  261.  *=========================================================================*/
  262. #define sbc_a_pss(ss, TS) \
  263. { \
  264.    LOCAL UCHAR tmp, n; \
  265.    \
  266.    T(TS); \
  267.    flags._N = 1; \
  268.    flags._H = (((n = ss) & (UCHAR)0xF) > (A & (UCHAR)0xF) ); \
  269.    flags._Z = !(tmp = (UCHAR)(A - n - (UCHAR)(flags._C != 0))); \
  270.    flags._C = (n > A)||(tmp>A); \
  271.    flags._P = (A^(n)) & (UCHAR)BIT_7 & (tmp^A); \
  272.    flags._S = ((A = tmp) & (UCHAR)BIT_7); \
  273.    flags._X = A & (UCHAR)BIT_5; \
  274.    flags._Y = A & (UCHAR)BIT_3; \
  275. }
  276.  
  277. void sbc_a_n() sbc_a_pss(Getnextbyte(), 7);
  278.  
  279. /*=========================================================================*
  280.  *                            sbc_a_phl                                    *
  281.  *=========================================================================*/
  282. void sbc_a_phl() sbc_a_pss(readbyte(HL),  7);
  283. void sbc_a_pix() sbc_a_pss(readbyte(pIX), 19);
  284. void sbc_a_piy() sbc_a_pss(readbyte(pIY), 19);
  285.  
  286. #undef sbc_a_pss
  287.  
  288. /*=========================================================================*
  289.  *                            and_r                                        *
  290.  *=========================================================================*/
  291.  
  292. #define and_r(r, TS) { \
  293.    T(TS); \
  294.    flags._H = 1; \
  295.    flags._N = flags._C = 0; \
  296.    flags._Z = !(A=A & (r)); \
  297.    flags._P = parity(A); \
  298.    flags._S = A & (UCHAR)BIT_7; \
  299.    flags._X = A & (UCHAR)BIT_5; \
  300.    flags._Y = A & (UCHAR)BIT_3; \
  301. }
  302.  
  303. void and_b()  and_r(B,  4);
  304. void and_c()  and_r(C,  4);
  305. void and_d()  and_r(D,  4);
  306. void and_e()  and_r(E,  4);
  307. void and_h()  and_r(H,  4);
  308. void and_Ix() and_r(HX, 8);
  309. void and_Iy() and_r(HY, 8);
  310. void and_l()  and_r(L,  4);
  311. void and_iX() and_r(LX, 8);
  312. void and_iY() and_r(LY, 8);
  313. void and_a()  and_r(A,  4);
  314.  
  315. /*
  316. void and_a()
  317. {
  318.     T(4);
  319.     flags._H = 1;
  320.     flags._N = flags._C = 0;
  321.     flags._S = A & (UCHAR)BIT_7;
  322.     flags._Z = !A;
  323.     flags._P = parity(A);
  324.     flags._X = A & (UCHAR)BIT_5;
  325.     flags._Y = A & (UCHAR)BIT_3;
  326. }
  327. */
  328.  
  329. /*=========================================================================*
  330.  *                            and_n                                        *
  331.  *=========================================================================*/
  332. void and_n() and_r(Getnextbyte(), 7);
  333.  
  334. /*=========================================================================*
  335.  *                            and_phl                                      *
  336.  *=========================================================================*/
  337. void and_phl() and_r(readbyte(HL), 7);
  338. void and_pix() and_r(readbyte(pIX), 19);
  339. void and_piy() and_r(readbyte(pIY), 19);
  340.  
  341. #undef and_r
  342.  
  343. /*=========================================================================*
  344.  *                            or_r                                         *
  345.  *=========================================================================*/
  346.  
  347. #define or_r(r,TS) { \
  348.     T(TS); \
  349.     flags._N = flags._C = flags._H = 0; \
  350.     flags._Z = !(A = A | (r)); \
  351.     flags._P = parity(A); \
  352.     flags._S = A & (UCHAR)BIT_7; \
  353.     flags._X = A & (UCHAR)BIT_5; \
  354.     flags._Y = A & (UCHAR)BIT_3; \
  355. }
  356.  
  357.  
  358. void or_b() or_r(B, 4);
  359. void or_c() or_r(C, 4);
  360. void or_d() or_r(D, 4);
  361. void or_e() or_r(E, 4);
  362. void or_h() or_r(H, 4);
  363. void or_Ix() or_r(HX, 8);
  364. void or_Iy() or_r(HY, 8);
  365. void or_l() or_r(L, 4);
  366. void or_iX() or_r(LX, 8);
  367. void or_iY() or_r(LY, 8);
  368. void or_a() or_r(A, 4);
  369. /*
  370. void or_a()
  371. {
  372.     T(4);
  373.     flags._N = flags._C = flags._H = 0;
  374.     flags._S = (A & (UCHAR)BIT_7);
  375.     flags._Z = !A;
  376.     flags._P = parity(A);
  377.     flags._X = A & (UCHAR)BIT_5;
  378.     flags._Y = (UCHAR)BIT_3;
  379. }
  380. */
  381.  
  382. /*=========================================================================*
  383.  *                            or_n                                         *
  384.  *=========================================================================*/
  385. void or_n() or_r(Getnextbyte(), 7);
  386.  
  387. /*=========================================================================*
  388.  *                            or_phl                                       *
  389.  *=========================================================================*/
  390. void or_phl() or_r(readbyte(HL), 7);
  391. void or_pix() or_r(readbyte(pIX), 19);
  392. void or_piy() or_r(readbyte(pIY), 19);
  393.  
  394. #undef or_r
  395.  
  396. /*=========================================================================*
  397.  *                            xor_r                                        *
  398.  *=========================================================================*/
  399.  
  400. #define xor_r(r, TS) { \
  401.     T(TS); \
  402.     flags._N = flags._C = flags._H = 0; \
  403.     flags._Z = !(A = A ^ (r)); \
  404.     flags._P = parity(A); \
  405.     flags._S = A & (UCHAR)BIT_7; \
  406.     flags._X = A & (UCHAR)BIT_5; \
  407.     flags._Y = A & (UCHAR)BIT_3; \
  408. }
  409.  
  410. void xor_b() xor_r(B, 4);
  411. void xor_c() xor_r(C, 4);
  412. void xor_d() xor_r(D, 4);
  413. void xor_e() xor_r(E, 4);
  414. void xor_h() xor_r(H, 4);
  415. void xor_Ix() xor_r(HX, 8);
  416. void xor_Iy() xor_r(HY, 8);
  417. void xor_l() xor_r(L, 4);
  418. void xor_iX() xor_r(LX, 8);
  419. void xor_iY() xor_r(LY, 8);
  420. void xor_a() xor_r(A, 4);
  421. /*
  422. void xor_a()
  423. {
  424.     T(4);
  425.     A = flags._X = flags._Y = flags._N = flags._C = flags._H = flags._S = 0;
  426.     flags._P = flags._Z = 1;
  427. }
  428. */
  429.  
  430. /*=========================================================================*
  431.  *                            xor_n                                        *
  432.  *=========================================================================*/
  433. void xor_n() xor_r(Getnextbyte(), 7);
  434.  
  435. /*=========================================================================*
  436.  *                            xor_phl                                      *
  437.  *=========================================================================*/
  438. void xor_phl() xor_r(readbyte(HL), 7);
  439. void xor_pix() xor_r(readbyte(pIX), 19);
  440. void xor_piy() xor_r(readbyte(pIY), 19);
  441.  
  442. #undef xor_r
  443.  
  444. /*=========================================================================*
  445.  *                            cp_r                                         *
  446.  *=========================================================================*/
  447.  
  448. #define cp_r(r, TS) { \
  449.     LOCAL UCHAR tmp; \
  450.     \
  451.     T(TS); \
  452.     flags._N = 1; \
  453.     flags._H = (((r) & (UCHAR)0xF) > (A & (UCHAR)0xF) ); \
  454.     flags._Z = !(tmp = (UCHAR)(A - (r))); \
  455.     flags._C = ((r) > A); \
  456.     flags._P = (A^(r)) & (UCHAR)BIT_7 & (tmp^A); \
  457.     flags._S = (tmp & (UCHAR)BIT_7); \
  458.     flags._X = tmp & (UCHAR)BIT_5; \
  459.     flags._Y = tmp & (UCHAR)BIT_3; \
  460. }
  461.  
  462.  
  463. void cp_b() cp_r(B, 4);
  464. void cp_c() cp_r(C, 4);
  465. void cp_d() cp_r(D, 4);
  466. void cp_e() cp_r(E, 4);
  467. void cp_h() cp_r(H, 4);
  468. void cp_Ix() cp_r(HX, 8);
  469. void cp_Iy() cp_r(HY, 8);
  470. void cp_l() cp_r(L, 4);
  471. void cp_iX() cp_r(LX, 8);
  472. void cp_iY() cp_r(LY, 8);
  473. void cp_a() cp_r(A, 4);
  474. /*
  475. void cp_a()
  476. {
  477.     T(4);
  478.     flags._Z = flags._N = 1;
  479.     flags._X = flags._Y = flags._H = flags._C = flags._P = flags._S = 0;
  480. }
  481. */
  482.  
  483. #undef cp_r
  484.  
  485. /*=========================================================================*
  486.  *                            cp_n                                         *
  487.  *=========================================================================*/
  488. #define cp_pss(ss, TS) \
  489. { \
  490.     LOCAL UCHAR tmp, n; \
  491.     \
  492.     T(TS); \
  493.     flags._N = 1; \
  494.     flags._H = (((n = (ss)) & (UCHAR)0xF) > (A & (UCHAR)0xF) ); \
  495.     flags._Z = !(tmp = (UCHAR)(A - n)); \
  496.     flags._C = (n > A); \
  497.     flags._P = (A^(n)) & (UCHAR)BIT_7 & (tmp^A); \
  498.     flags._S = (tmp & (UCHAR)BIT_7); \
  499.     flags._X = tmp & (UCHAR)BIT_5; \
  500.     flags._Y = tmp & (UCHAR)BIT_3; \
  501. }
  502.  
  503. void cp_n() cp_pss(Getnextbyte(), 7);
  504.  
  505. /*=========================================================================*
  506.  *                            cp_phl                                       *
  507.  *=========================================================================*/
  508. void cp_phl() cp_pss(readbyte(HL), 7);
  509. void cp_pix() cp_pss(readbyte(pIX), 19);
  510. void cp_piy() cp_pss(readbyte(pIY), 19);
  511.  
  512. #undef cp_pss
  513.  
  514. /*=========================================================================*
  515.  *                            inc_r                                        *
  516.  *=========================================================================*/
  517.  
  518. #define inc_r(r, TS) { \
  519.     T(TS); \
  520.     flags._P = ((r) == 0x7F); \
  521.     flags._N = 0; \
  522.     flags._S = (++(r) & (UCHAR)BIT_7); \
  523.     flags._Z = !(r); \
  524.     flags._H = !((r) & (UCHAR)0xF); \
  525.     flags._X = (r) & (UCHAR)BIT_5; \
  526.     flags._Y = (r) & (UCHAR)BIT_3; \
  527. }
  528.  
  529.  
  530. void inc_b() inc_r(B, 4);
  531. void inc_c() inc_r(C, 4);
  532. void inc_d() inc_r(D, 4);
  533. void inc_e() inc_r(E, 4);
  534. void inc_h() inc_r(H, 4);
  535. void inc_Ix() inc_r(HX, 8);
  536. void inc_Iy() inc_r(HY, 8);
  537. void inc_l() inc_r(L, 4);
  538. void inc_iX() inc_r(LX, 8);
  539. void inc_iY() inc_r(LY, 8);
  540. void inc_a() inc_r(A, 4);
  541.  
  542. #undef inc_r
  543.  
  544. /*=========================================================================*
  545.  *                            inc_phl                                      *
  546.  *=========================================================================*/
  547. #define inc_pss(ss, TS) \
  548. { \
  549.     LOCAL UCHAR n; \
  550.     LOCAL USHORT tmp; \
  551.     \
  552.     T(TS); \
  553.     flags._P = ((n = readbyte(tmp = (ss))) == 0x7F); \
  554.     flags._N = 0; \
  555.     flags._S = (++n & (UCHAR)BIT_7); \
  556.     writebyte(tmp, n); \
  557.     flags._Z = !n; \
  558.     flags._H = !(n & (UCHAR)0xF); \
  559.     flags._X = n & (UCHAR)BIT_5; \
  560.     flags._Y = n & (UCHAR)BIT_3; \
  561. }
  562.  
  563. void inc_phl() inc_pss(HL, 11);
  564. void inc_pix() inc_pss(pIX, 23);
  565. void inc_piy() inc_pss(pIY, 23);
  566.  
  567. #undef inc_pss
  568.  
  569. /*=========================================================================*
  570.  *                            dec_r                                        *
  571.  *=========================================================================*/
  572.  
  573. #define dec_r(r,TS) { \
  574.     T(TS); \
  575.     flags._H = !((r) & (UCHAR)0xF); \
  576.     flags._P = ((r) == (UCHAR)BIT_7); \
  577.     flags._N = 1; \
  578.     flags._S = ((--(r)) & (UCHAR)BIT_7); \
  579.     flags._Z = !(r); \
  580.     flags._X = (r) & (UCHAR)BIT_5; \
  581.     flags._Y = (r) & (UCHAR)BIT_3; \
  582. }
  583.  
  584.  
  585. void dec_b() dec_r(B,4);
  586. void dec_c() dec_r(C,4);
  587. void dec_d() dec_r(D,4);
  588. void dec_e() dec_r(E,4);
  589. void dec_h() dec_r(H,4);
  590. void dec_Ix() dec_r(HX,8);
  591. void dec_Iy() dec_r(HY,8);
  592. void dec_l() dec_r(L,4);
  593. void dec_iX() dec_r(LX,8);
  594. void dec_iY() dec_r(LY,8);
  595. void dec_a() dec_r(A,4);
  596.  
  597. #undef dec_r
  598.  
  599. /*=========================================================================*
  600.  *                            dec_phl                                      *
  601.  *=========================================================================*/
  602. #define dec_pss(ss,TS) \
  603. { \
  604.     LOCAL UCHAR n; \
  605.     LOCAL USHORT tmp; \
  606.           \
  607.     T(TS);    \
  608.     flags._H = !((n = readbyte(tmp = (ss))) & (UCHAR)0xF); \
  609.     flags._P = (n == (UCHAR)BIT_7); \
  610.     flags._N = 1; \
  611.     flags._S = ((--n) & (UCHAR)BIT_7); \
  612.     writebyte(tmp, n); \
  613.     flags._Z = !n;     \
  614.     flags._X = n & (UCHAR)BIT_5; \
  615.     flags._Y = n & (UCHAR)BIT_3;  \
  616. }
  617.  
  618. void dec_phl() dec_pss(HL, 11);
  619. void dec_pix() dec_pss(pIX, 23);
  620. void dec_piy() dec_pss(pIY, 23);
  621.  
  622. #undef dec_pss
  623.  
  624. /* EOF: Math8Bit.c */
  625.