home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / 9900asm.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  2.9 KB  |  236 lines

  1.  
  2. #include "centry.h"
  3.  
  4.  
  5. u16 INLINE swpb(u16 val)
  6. {
  7.     union swapstruc
  8.     {
  9.         struct
  10.         {
  11.             u8 hi,lo;
  12.         }    b;
  13.         u16    val;
  14.     }    v;
  15.     u8 tmp;
  16.     
  17.     v.val = val;
  18.     tmp=v.b.hi;
  19.     v.b.hi=v.b.lo;
  20.     v.b.lo=tmp;
  21.     return v.val;
  22. }
  23.  
  24. /*
  25.     Meat of SRA
  26. */
  27. u16 INLINE setst_sra_laec(s16 a,u16 c)
  28. {
  29. #ifdef GNU_X86_ASM
  30.     register u16 ans asm ("ax")=a;
  31.     register u8 cnt asm ("cl");
  32.     
  33.     cnt=c;
  34.     status&=~ST_C;
  35.     asm(
  36.         "\t sarw %1,%0\n"
  37.         "\t jnc 2f\n"
  38.         "\t orb $0x10,status+1\n"
  39.         "\t2:\n"
  40.         : "=r" (ans)
  41.         : "r" (cnt), "r" (ans)
  42.         : "cc", "ax"
  43.     );
  44.     lastval=ans;
  45.     lastcmp=0;
  46.     
  47.     return setst_lae(ans);
  48.  
  49. #else
  50.  
  51.     u16 mask= c ? (1 << (c-1)) : 0;
  52.     
  53. #if defined(FAST_X86_STATUS) || defined(GNU_X86_ASM)
  54.     if (a & mask)
  55.         status |= ST_C;
  56.     else
  57.         status &= ~ST_C;
  58. #else
  59.     st_c = (a & mask) != 0;
  60. #endif
  61.     
  62.     a >>= c;
  63.  
  64.     lastval=a;
  65.     lastcmp=0;
  66.     
  67.     return setst_lae(a);
  68. #endif
  69. }
  70.  
  71.  
  72. /*
  73.     Meat of SRL
  74. */
  75. u16 INLINE setst_srl_laec(u16 a,u16 c)
  76. {
  77. #ifdef GNU_X86_ASM
  78.     register u16 ans asm ("ax")=a;
  79.     register u8 cnt asm ("cl");
  80.     
  81.     cnt=c;
  82.     status&=~ST_C;
  83.     asm(
  84.         "\t shrw %1,%0\n"
  85.         "\t jnc 2f\n"
  86.         "\t orb $0x10,status+1\n"
  87.         "\t2:\n"
  88.         : "=r" (ans)
  89.         : "r" (cnt), "r" (ans)
  90.         : "cc", "ax"
  91.     );
  92.     lastval=ans;
  93.     lastcmp=0;
  94.     
  95.     return setst_lae(ans);
  96.  
  97. #else
  98.  
  99.     u16 mask = c ? (1 << (c-1)) : 0;
  100.  
  101. #if defined(FAST_X86_STATUS) || defined(GNU_X86_ASM)
  102.     if (a & mask)
  103.         status |= ST_C;
  104.     else
  105.         status &= ~ST_C;
  106. #else
  107.     st_c = (a & mask) != 0;
  108. #endif    
  109.         
  110.     a >>= c;
  111.  
  112.     lastval=a;
  113.     lastcmp=0;
  114.     
  115.     return setst_lae(a);
  116.  
  117. #endif
  118. }
  119.  
  120.  
  121. /*
  122.     Meat of SRC
  123. */
  124. u16 INLINE setst_src_laec(u16 a,u16 c)
  125. {
  126. #ifdef GNU_X86_ASM
  127.     register u16 ans asm ("ax")=a;
  128.     register u8 cnt asm ("cl");
  129.     
  130.     cnt=c;
  131.     status&=~ST_C;
  132.     asm(
  133.         "\t rorw %1,%0\n"
  134.         "\t jnc 2f\n"
  135.         "\t orb $0x10,status+1\n"
  136.         "\t2:\n"
  137.         : "=r" (ans)
  138.         : "r" (cnt), "r" (ans)
  139.         : "cc", "ax"
  140.     );
  141.     lastval=ans;
  142.     lastcmp=0;
  143.     
  144.     return setst_lae(ans);
  145.     
  146. #else
  147.  
  148.     u16 mask = c ? (1 << (c-1)) : 0;
  149.  
  150. #if defined(FAST_X86_STATUS) || defined(GNU_X86_ASM)
  151.     if (a & mask)
  152.         status |= ST_C;
  153.     else    
  154.         status &= ~ST_C;
  155. #else
  156.     st_c = (a & mask) != 0;
  157. #endif
  158.         
  159.     a = (a >> c) | (a << (16-c));
  160.  
  161.     lastval=a;
  162.     lastcmp=0;
  163.     
  164.     return setst_lae(a);
  165.  
  166. #endif
  167. }
  168.  
  169.  
  170. /*
  171.     Meat of SLA
  172. */
  173. u16 INLINE setst_sla_laeco(u16 a,u16 c)
  174. {
  175. #ifdef GNU_X86_ASM
  176.     register u16 ans asm ("ax")=a;
  177.     register u8 cnt asm ("cl");
  178.     
  179.     cnt=c;
  180.     status&=~(ST_C|ST_O);
  181.     asm(
  182.         "\t salw %1,%0\n"
  183.         "\t pushf\n"
  184.         "\t jno 1f\n"
  185.         "\t orb $0x8,status+1\n"
  186.         "\t1: popf\n"
  187.         "\t jnc 2f\n"
  188.         "\t orb $0x10,status+1\n"
  189.         "\t2:\n"
  190.         : "=r" (ans)
  191.         : "r" (cnt), "r" (ans)
  192.         : "cc", "ax"
  193.     );
  194.     lastval=ans;
  195.     lastcmp=0;
  196.     
  197.     return setst_lae(ans);
  198.  
  199. #else
  200.  
  201.     u16 mask = 0x10000 >> c;
  202.     u16 oa;
  203.  
  204. #if defined(FAST_X86_STATUS) || defined(GNU_X86_ASM)    
  205.     if (a & mask)
  206.         status |= ST_C;
  207.     else
  208.         status &= ~ST_C;
  209. #else
  210.     st_c = (a & mask) != 0;
  211. #endif
  212.  
  213.     oa = a;
  214.     a <<= c;
  215.  
  216. #if defined(FAST_X86_STATUS) || defined(GNU_X86_ASM)
  217.     if ((oa ^ a) & 0x8000)
  218.         status |= ST_O;
  219.     else
  220.         status &= ~ST_O;
  221. #else
  222.     st_o = ((oa ^ a) & 0x8000) != 0;
  223. #endif
  224.         
  225.     lastval=a;
  226.     lastcmp=0;
  227.     
  228.     return setst_lae(a);
  229.  
  230. #endif
  231. }
  232.  
  233. #include "cexit.h"
  234.  
  235.  
  236.