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