home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / PEN / PENTKT / PENBASE / INC / STRUC.INC < prev   
Text File  |  1995-04-14  |  16KB  |  537 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  4. ;
  5. ;    The following IBM OS/2 WARP source code is provided to you solely for
  6. ;    the purpose of assisting you in your development of OS/2 WARP device
  7. ;    drivers. You may use this code in accordance with the IBM License
  8. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  9. ;    Copyright statement may not be removed.;
  10. ;*****************************************************************************/
  11. ;/*************************************************************************/
  12. ;/*                                                                       */
  13. ;/*                                                                       */
  14. ;/*************************************************************************/
  15. ;;STRUC.INC--Stucture Macro Library
  16.  
  17. if1
  18. $noconj equ     0
  19. $and            equ     1
  20. $or             equ     2
  21. $short          equ     3
  22. $near           equ     4
  23. $andor          =       0
  24. $temp           =       0
  25. $temp2          =       0
  26. $dist           =       0
  27.  
  28. $notype         equ     10
  29. $conjif         equ     11
  30. $iftype         equ     12
  31. $elsetype       equ     13
  32. $whiletype      equ     14
  33. $conjwhile      equ     15
  34. $repeattype     equ     16
  35. $conjuntil      equ     17
  36. $fortype        equ     18
  37. $conjleave      equ     19
  38.  
  39. $StrucErr macro text
  40.                                         Structure error -- text
  41. endm
  42.  
  43. j       macro
  44. endm
  45. jn      macro
  46. endm
  47.  
  48. jbuild  macro   j1,j2
  49.         j1      macro   mod,tgt
  50.                 .xcref  j1
  51.                                         j2 mod tgt
  52.         endm
  53. endm
  54.  
  55. irp     x,<<jeq,je>,<jlt,jl>,<jgt,jg>,<jneq,jne>,<jnlt,jnl>,<jngt,jng>,<jnpe,jpo>,<jnpo,jpe>>
  56.         jbuild  x
  57. endm
  58. irp     x,<<jzero,jz>,<jnzero,jnz>,<jnonzero,jnz>,<jnnonzero,jz>,<jand,jnz>,<jnand,jz>,<jnnand,jnz>>
  59.         jbuild  x
  60. endm
  61. irp     x,<a,ae,b,be,c,e,g,ge,l,le,o,p,s,z,cxz,ecxz>
  62.         jbuild  jnn&x,j&x
  63. endm
  64.  
  65. jncxz   macro   mod,tgt
  66.         local   skip
  67.                                         jcxz skip
  68.                                         jmp mod tgt
  69. skip:
  70. endm
  71.  
  72. jnecxz  macro   mod,tgt
  73.         local   skip
  74.                                         jecxz skip
  75.                                         jmp mod tgt
  76. skip:
  77. endm
  78.  
  79. purge   jbuild
  80.  
  81. $getconj macro  p1,p2
  82.         $andor  = $noconj
  83.         irp     parm,<p1,p2>
  84.                 ifnb    <&parm>
  85.                         irp     x,<and,or>
  86.                                 ifidni  <parm>,<x>
  87.                                         $andor = $&&&x
  88.                                         exitm
  89.                                 endif
  90.                         endm
  91.                 endif
  92.         endm
  93. endm
  94.  
  95. $getdist macro  p1,p2
  96.         irp     parm,<p1,p2>
  97.                 ifnb    <parm>
  98.                         irp     x,<short,near>
  99.                                 ifidni  <parm>,<x>
  100.                                         $dist = $&&&x
  101.                                         exitm
  102.                                 endif
  103.                         endm
  104.                 endif
  105.         endm
  106. endm
  107.  
  108.  
  109. $poke   macro   num,value
  110.         $st&num = value
  111. .xcref  $st&num
  112. endm
  113.  
  114. $peek   macro   sym,num
  115.         sym     = $st&num
  116. endm
  117.  
  118. $push   macro   value
  119.         $st     = $st+1
  120.         $poke   %$st,value
  121. endm
  122.  
  123. $pop    macro   sym
  124.         $peek   sym,%$st
  125.         $st     = $st-1
  126. endm
  127.  
  128. $labl   macro   num
  129. $l&num:
  130. endm
  131.  
  132. $cjump  macro   lnum,tf,cond
  133.         local   skip
  134.         if      $dist eq $short
  135.                 ifb     <cond>
  136.                                         jmp short $l&lnum
  137.                 else
  138.                         ifidn <tf>,<f>
  139.                                         jn&cond short $l&lnum
  140.                         else
  141.                                         j&cond short $l&lnum
  142.                         endif
  143.                 endif
  144.         else
  145.                 ifnb    <cond>
  146.                     if  (@Cpu and 8) ne 0
  147.                     ifdifi <cond>,<cxz>
  148.                     ifdifi <cond>,<ncxz>
  149.                         ifidn <tf>,<f>
  150.                                         jn&cond $l&lnum
  151.                         else
  152.                                         j&cond $l&lnum
  153.                         endif
  154.                         exitm
  155.                     endif
  156.                     endif
  157.                     endif
  158.                     ifidn <tf>,<f>
  159.                                         j&cond skip
  160.                     else
  161.                                         jn&cond skip
  162.                     endif
  163.                 endif
  164.                                         jmp $l&lnum
  165.                 ifnb            <cond>
  166. skip:
  167.                 endif
  168.         endif
  169. endm
  170.  
  171.  
  172. $cloop  macro   lnum,cond
  173.                                         loop&cond $l&lnum
  174. endm
  175.  
  176. $test   macro   tgt,a1,a2,a3,a4,x1
  177.         ifb     <a1>
  178.                 $StrucErr <invalid condition>
  179.         elseifb <a2>
  180.                 $cjump  %&tgt,a1
  181.         elseifb <a3>
  182.                 ifdifi  <a1>,<zero>
  183.                 ifdifi  <a1>,<nonzero>
  184.                         $StrucErr       <invalid condition>
  185.                         exitm
  186.                 endif
  187.                 endif
  188.                 if      $dist eq $short
  189.                 ifidni  <a1>,<nonzero>
  190.                 ifidni  <a2>,<cx>
  191.                 $cjump  %&tgt,ncxz
  192.                 exitm
  193.                 endif
  194.                 ifidni  <a2>,<ecx>
  195.                 $cjump  %&tgt,necxz
  196.                 exitm
  197.                 endif
  198.                 endif
  199.                 endif
  200.                                         or a2,a2
  201.                 $cjump  %&tgt,a1
  202.         elseifb <a4>
  203.                                         cmp a1,a3
  204.                 $cjump  %&tgt,a2
  205.         elseifb <x1>
  206.                 ifdifi  <a1>,<bit>
  207.                         $StrucErr       <invalid condition>
  208.                         exitm
  209.                 endif
  210.                                         test a2,a4
  211.                 $cjump  %&tgt,a3
  212.         else
  213.                 $StrucErr       <invalid condition>
  214.         endif
  215. endm
  216.  
  217. $toptest macro  args,ntype,ctype,p4,p5
  218.         $getconj p4,p5
  219.         $dist = $defdist
  220.         $getdist p4,p5
  221.         if      $andor eq $noconj
  222.                 $test   <$sn-1,f>,args
  223.                 $pop    $temp
  224.                 if       $orfound
  225.                         $labl  %$temp
  226.                 endif
  227.                 $push   ntype
  228.         else
  229.                 if      $andor eq $and
  230.                         $test   <$sn-1,f>,args
  231.                 else
  232.                         $orfound = 1
  233.                         $test   <$sn,t>,args
  234.                 endif
  235.                 $push   ctype
  236.         endif
  237. endm
  238. ;;*****************************************************************************
  239. .if     macro   tst,p2,p3
  240.         $peek   $temp,%$st
  241.         if      $temp eq $conjif
  242.                 $pop    $temp
  243.         else
  244.                 $push   $elseiffound
  245.                 $elseiffound = 0
  246.                 $orfound = 0
  247.                 $sn     = $sn+1
  248.                 $push   $sn
  249.                 $sn     = $sn+1
  250.                 $push   $sn
  251.                 $sn     = $sn+1
  252.                 $push   $sn
  253.         endif
  254.         $toptest <tst>,$iftype,$conjif,p2,p3
  255. endm
  256. ;;*****************************************************************************
  257. .then   macro
  258.         $peek   $temp,%$st
  259.         if      $temp ne $iftype
  260.                 $StrucErr <then without if>
  261.         endif
  262. endm
  263. ;;*****************************************************************************
  264. .elseif macro   tst,p2,p3
  265.         $pop    $temp
  266.         if      $temp ne $iftype
  267.                 $StrucErr <elseif without if>
  268.                 exitm
  269.         endif
  270.         $elseiffound = 1
  271.         $orfound = 0
  272.         $pop    $temp
  273.         $peek   $temp2,%$st
  274.         $dist   = $near
  275.         $cjump  %$temp2
  276.         $labl   %$temp
  277.         $sn     = $sn+1
  278.         $push   $sn
  279.         $sn     = $sn+1
  280.         $push   $sn
  281.         $toptest <tst>,$iftype,$conjif,p2,p3
  282. endm
  283. ;;*****************************************************************************
  284. .else   macro   dist
  285.         $pop    $temp
  286.         if      $temp ne $iftype
  287.                 $StrucErr <else without if>
  288.                 exitm
  289.         endif
  290.         $sn     = $sn+1
  291.         $dist   = $defdist
  292.         $getdist dist
  293.         $cjump  %$sn
  294.         $pop    $temp
  295.         $labl   %$temp
  296.         $push   $sn
  297.         $push   $elsetype
  298. endm
  299. ;;*****************************************************************************
  300. .endif  macro
  301.         $pop    $temp
  302.         if      $temp ne $iftype
  303.                 if      $temp ne $elsetype
  304.                         $StrucErr <endif without if>
  305.                         exitm
  306.                 endif
  307.         endif
  308.         $pop    $temp
  309.         $labl   %$temp
  310.         $pop    $temp
  311.         if      $elseiffound
  312.                 $labl    %$temp
  313.         endif
  314.         $pop    $elseiffound
  315. endm
  316. ;;*****************************************************************************
  317. .while  macro   tst,p2,p3
  318.         $peek   $temp,%$st
  319.         if      $temp eq $conjwhile
  320.                 $pop            $temp
  321.         else
  322.                 $push $endloop
  323.                 $orfound = 0
  324.                 $sn = $sn + 1
  325.                 $push $sn
  326.                 $labl %$sn
  327.                 $sn = $sn + 2
  328.                 $push $sn
  329.                 $endloop = $sn - 1
  330.         endif
  331.         $toptest <tst>,$whiletype,$conjwhile,p2,p3
  332. endm
  333. ;;*****************************************************************************
  334. .endwhile macro
  335.         $pop    $temp
  336.         if      $temp ne $whiletype
  337.                 $StrucErr <endwhile without while>
  338.                 exitm
  339.         endif
  340.         $pop    $temp
  341.         $dist   = $near
  342.         $cjump  %$temp
  343.         $labl   %$temp+1
  344.         $pop    $endloop
  345. endm
  346. ;;*****************************************************************************
  347. .repeat macro
  348.         $push   $endloop
  349.         $push   $leavefound
  350.         $sn     = $sn+1
  351.         $labl   %$sn
  352.         $push   $sn
  353.         $push   $repeattype
  354.         $sn     = $sn+1
  355.         $endloop = $sn
  356.         $leavefound = 0
  357. endm
  358. ;;*****************************************************************************
  359. .until  macro   tst,p2,p3
  360.         $until_2 p2,p3,tst
  361. endm
  362. $until_2 macro  p2,p3,a1,a2,a3,a4,x1
  363.         $pop    $temp
  364.         if      $temp ne $repeattype
  365.                 if      $temp ne $conjuntil
  366.                         $StrucErr <until without repeat>
  367.                         exitm
  368.                 endif
  369.         else
  370.                 $orfound = 0
  371.         endif
  372.         $dist   = $defdist
  373.         $getdist p2,p3
  374.         $getconj p2,p3
  375.  
  376.         if      $andor eq $noconj
  377.                 $pop    $temp
  378.                 ifb     <a1>
  379.                         $dist   = $near
  380.                         $cjump  %$temp,f
  381.                 else
  382.                         $test   <$temp,f>,<a1>,<a2>,<a3>,<a4>,<x1>
  383.                 endif
  384.                 if      $orfound or $leavefound
  385.                         $labl %$temp+1
  386.                 endif
  387.                 $pop    $leavefound
  388.                 $pop    $endloop
  389.         else
  390.                 $peek $temp,%$st
  391.                 if      $andor eq $and
  392.                         $test <$temp,f>,<a1>,<a2>,<a3>,<a4>,<x1>
  393.                 else
  394.                         $orfound = 1
  395.                         $test <$temp+1,t>,<a1>,<a2>,<a3>,<a4>,<x1>
  396.                 endif
  397.                 $push $conjuntil
  398.         endif
  399. endm
  400. ;;*****************************************************************************
  401. .loop   macro   cond
  402.         $pop    $temp
  403.         if      $temp ne $repeattype
  404.                 $StrucErr <loop without repeat>
  405.                 exitm
  406.         endif
  407.         $pop    $temp
  408.         $cloop  %$temp,cond
  409.         if      $leavefound
  410.                 $labl %$temp+1
  411.         endif
  412.         $pop    $leavefound
  413.         $pop    $endloop
  414. endm
  415. ;;*****************************************************************************
  416. .for    macro   index,equals,start,to,stop,by,step,dist
  417.                                         mov index,start
  418.         $push   $endloop
  419.         $sn     = $sn+1
  420.         $push   $sn
  421.         $labl   %$sn
  422.         $sn     = $sn+1
  423.         $endloop = $sn
  424.                                         cmp index,stop
  425.         $dist   = $defdist
  426.         ifb     <step>
  427.                 $push 1
  428.                 $getdist by
  429.                 $cjump %$sn,t,gt
  430.         else
  431.                 $getdist dist
  432.                 $push %(step)
  433.                 if      step lt 0
  434.                         $cjump %$sn,t,lt
  435.                 else
  436.                         $cjump %$sn,t,gt
  437.                 endif
  438.         endif
  439.         $push   $fortype
  440. endm
  441. ;;*****************************************************************************
  442. .next   macro   index
  443.         $pop    $temp
  444.         if      $temp ne $fortype
  445.                 $StrucErr <next without for>
  446.                 exitm
  447.         endif
  448.         $pop    $temp
  449.         if      $temp eq 1
  450.                                         inc index
  451.         else
  452.                 if      $temp eq -1
  453.                                         dec index
  454.                 else
  455.                                         add index,$temp
  456.                 endif
  457.         endif
  458.         $pop    $temp
  459.         $dist   = $near
  460.         $cjump  %$temp
  461.         $labl   %$temp+1
  462.         $pop    $endloop
  463. endm
  464. ;;*****************************************************************************
  465. .leave  macro   tst,p2,p3
  466.         $leave_2 p2,p3,tst
  467. endm
  468. $leave_2 macro  p2,p3,a1,a2,a3,a4,x1
  469.         ife     $endloop
  470.                 $StrucErr <leave outside a loop>
  471.                 exitm
  472.         endif
  473.         $leavefound = 1
  474.         $peek   $temp,%$st
  475.         if      $temp eq $conjleave
  476.                 $pop            $temp
  477.         else
  478.                 $orfound = 0
  479.                 $sn = $sn + 1
  480.         endif
  481.         $dist   = 0
  482.         $getdist <a1>
  483.         if      $dist
  484.                 $cjump %$endloop
  485.                 if      $orfound
  486.                         $labl %$sn
  487.                 endif
  488.         else
  489.                 $dist   = $defdist
  490.                 $getdist p2,p3
  491.                 $getconj p2,p3
  492.  
  493.                 if      $andor eq $noconj
  494.                         ifb     <a1>
  495.                                 $cjump  %$endloop,t
  496.                         else
  497.                                 $test <$endloop,t>,<a1>,<a2>,<a3>,<a4>,<x1>
  498.                         endif
  499.                         if      $orfound
  500.                                 $labl %$sn
  501.                         endif
  502.                 else
  503.                         if      $andor eq $and
  504.                                 $orfound = 1
  505.                                 $test  <$sn,f>,<a1>,<a2>,<a3>,<a4>,<x1>
  506.                         else
  507.                                 $test  <$endloop,t>,<a1>,<a2>,<a3>,<a4>,<x1>
  508.                         endif
  509.                         $push $conjleave
  510.                 endif
  511.         endif
  512. endm
  513. ;;*****************************************************************************
  514. else
  515.         $pop     $temp
  516.         if       $temp ne $notype
  517.                  $StrucErr <open structure(s)>
  518.         endif
  519. .xcref $noconj,$and,$or,$short,$near,$andor,$temp,$temp2,$dist
  520. .xcref $notype,$conjif,$iftype,$elsetype,$whiletype,$conjwhile
  521. .xcref $repeattype,$conjuntil,$fortype,$conjleave,jncxz,jnecxz
  522. .xcref jeq,jgt,jlt,jneq,jngt,jnlt,jnna,jnnae,jnnb,jnnbe,jnnc,jnncxz,jnnecxz
  523. .xcref jnne,jnng,jnnge,jnnl,jnnle,jnno,jnnp,jnns,jnnz,jnpe,jnpo,jbuild
  524. .xcref $getconj,$getdist,$poke,$peek,$push,$pop,$labl,$cjump,$cloop,$test
  525. .xcref $toptest,$leave_2,$until_2,$StrucErr,j,jn,jand,jnand,jnnand
  526. .xcref jnnonzero,jnonzero,jnzero,jzero
  527. .xcref $st,$sn,$orfound,$elseiffound,$endloop,$leavefound,$defdist
  528. endif
  529. $st             = 0
  530. $sn             = 0
  531. $orfound        = 0
  532. $elseiffound    = 0
  533. $endloop        = 0
  534. $leavefound     = 0
  535. $defdist        = $short
  536. $push   %$notype
  537.