home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1986 / 09 / dunclst.sep < prev    next >
Text File  |  1986-09-30  |  19KB  |  579 lines

  1.  
  2.  
  3. LISTING ONE
  4.  
  5.  
  6.   1) copy masm.exe masm.sav (to make a backup)
  7.  
  8.   2) ren masm.exe masm.fix (debug.com can't wrtie EXE files)
  9.  
  10.   3) debug masm.fix
  11.      3a) D 72B8 L 22  (should see 34 bytes of 00)
  12.      3b) E 72B8
  13.          enter these bytes:
  14.          8B 1E D6 09 C6 06 C0 01 00 E9 75 02 C4 57 06 FE
  15.          06 C0 01 E9 74 02 80 7C FF 1A 74 03 39 9D 02 4E
  16.          EB F4
  17.      3c) U 7535 L 1   (should see "MOV BX,[09D6]" )
  18.      3d) E 7535
  19.          enter these bytes: E9 80 FD
  20.      3e) U 753F L 1   (should see "LES DX,[BX+06]" )
  21.      3f) E 753F
  22.          enter these bytes: E9 82 FD
  23.      3g) U 756D L 1   (should see "CMP BYTE PTR [SI-01],1A" )
  24.          enter these bytes: E9 5E FD
  25.      3h) W   (to write changes to masm.fix)
  26.      3i) Q   (to exit debug.com)
  27.  
  28.   4) ren masm.fix masm.exe
  29.  
  30.   5) Test masm.exe to make sure changes have been made correctly.
  31.      If not, copy masm.sav to mas.exe and try again.
  32.  
  33. ****************************************************************************
  34.  
  35.  
  36. LISTING TWO
  37.  
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ;;;;                                                                    ;;;;
  40. ;;;;    hpkio        Basic I/O functions using handle packing.          ;;;;
  41. ;;;;                                                                    ;;;;
  42. ;;;;            Written By   Paul M. Adams                              ;;;;
  43. ;;;;                         Route 4 Box 23                             ;;;;
  44. ;;;;                         Shelbyville, KY  40065                     ;;;;
  45. ;;;;                                                                    ;;;;
  46. ;;;;                                                                    ;;;;
  47. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  48.  
  49.  
  50.         include model.h
  51.         include prologue.h
  52.  
  53.  
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;;;                                                                     ;;;
  56. ;;;     hcreate(dsn, attr)                                              ;;;
  57. ;;;     unsigned char   *dsn;   /* Data Set Name        */              ;;;
  58. ;;;     int             attr;   /* file attribute byte  */              ;;;
  59. ;;;                                                                     ;;;
  60. ;;;                                                                     ;;;
  61. ;;;     hold_handle = psp_handle[19]                                    ;;;
  62. ;;;     psp_handle[19] = FF                                             ;;;
  63. ;;;     call dos  to create file                                        ;;;
  64. ;;;     if error                                                        ;;;
  65. ;;;             retval = -1                                             ;;;
  66. ;;;     else                                                            ;;;
  67. ;;;             retval =  psp_handle[dos_handle]                        ;;;
  68. ;;;             psp_handle[dos_handle] = FF                             ;;;
  69. ;;;                                                                     ;;;
  70. ;;;     psp_handle[19] = hold_handle                                    ;;;
  71. ;;;                                                                     ;;;
  72. ;;;     return(retval)  - real dos handle                               ;;;
  73. ;;;                                                                     ;;;
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75.  
  76. hcreate proc
  77.         public  hcreate
  78.         push    es
  79.         push    bp
  80.         mov     bp,sp
  81.         sub     sp, 2
  82.  
  83. dsn         equ [bp + 6]
  84. attr        equ [bp + 8]
  85. hold_handle equ [bp - 2]
  86.  
  87.         mov     ah, 62h
  88.         int     21h
  89.         mov     es, bx
  90.  
  91.         mov     al, byte ptr es:[18h + 19]
  92.         xor     ah, ah
  93.         mov     hold_handle, ax
  94.         mov     byte ptr es:[18h + 19], 0ffh
  95.  
  96.         mov     ah, 3ch
  97.         mov     dx, dsn
  98.         mov     cx, attr
  99.         int     21h
  100.         jc      hcreate_error
  101.  
  102.         mov     bx, ax
  103.         mov     al, byte ptr es:[bx + 18h]
  104.         xor     ah, ah
  105.         mov     byte ptr es:[bx + 18h], 0ffh
  106.         jmp     hcreate_done
  107.  
  108. hcreate_error:
  109.         mov     ax, 0ffffh
  110.  
  111. hcreate_done:
  112.         push    ax
  113.         mov     ax, hold_handle
  114.         mov     byte ptr es:[18h + 19], al
  115.         pop     ax
  116.  
  117. hcreate_exit:
  118.         mov     sp, bp
  119.         pop     bp
  120.         pop     es
  121.         ret
  122.  
  123. hcreate endp
  124.  
  125.  
  126. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  127. ;;;                                                                     ;;;
  128. ;;;     hopen(dsn, mode)                                                ;;;
  129. ;;;     unsigned char   *dsn;   /* Data Set Name        */              ;;;
  130. ;;;     int             mode;   /* DOS open mode        */              ;;;
  131. ;;;                                                                     ;;;
  132. ;;;     hold_handle = psp_handle[19]                                    ;;;
  133. ;;;     psp_handle[19] = FF                                             ;;;
  134. ;;;     call dos  to open file                                          ;;;
  135. ;;;     if error                                                        ;;;
  136. ;;;             retval = -1                                             ;;;
  137. ;;;     else                                                            ;;;
  138. ;;;             retval =  psp_handle[dos_handle]                        ;;;
  139. ;;;             psp_handle[dos_handle] = FF                             ;;;
  140. ;;;                                                                     ;;;
  141. ;;;     psp_handle[19] = hold_handle                                    ;;;
  142. ;;;                                                                     ;;;
  143. ;;;     return(retval)  - real dos handle                               ;;;
  144. ;;;                                                                     ;;;
  145. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  146.  
  147. hopen   proc
  148.         public  hopen
  149.  
  150.         push    es
  151.         push    bp
  152.         mov     bp,sp
  153.         sub     sp, 2
  154.  
  155. dsn         equ [bp + 6]
  156. mode        equ [bp + 8]
  157. hold_handle equ [bp - 2]
  158.  
  159.         mov     ah, 62h
  160.         int     21h
  161.         mov     es, bx
  162.  
  163.         mov     al, byte ptr es:[18h + 19]
  164.         xor     ah, ah
  165.         mov     hold_handle, ax
  166.         mov     byte ptr es:[18h + 19], 0ffh
  167.  
  168.         mov     ax, mode
  169.         mov     ah, 3dh
  170.         mov     dx, dsn
  171.         int     21h
  172.         jc      hopen_error
  173.  
  174.         mov     bx, ax
  175.         mov     al, byte ptr es:[bx + 18h]
  176.         xor     ah, ah
  177.         mov     byte ptr es:[bx + 18h], 0ffh
  178.         jmp     hopen_done
  179.  
  180. hopen_error:
  181.         mov     ax, 0ffffh
  182.  
  183. hopen_done:
  184.         push    ax
  185.         mov     ax, hold_handle
  186.         mov     byte ptr es:[18h + 19], al
  187.         pop     ax
  188.  
  189. hopen_exit:
  190.         mov     sp, bp
  191.         pop     bp
  192.         pop     es
  193.         ret
  194. hopen   endp
  195.  
  196.  
  197.  
  198. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  199. ;;;                                                                     ;;;
  200. ;;;     hclose(handle)                                                  ;;;
  201. ;;;     int             handle;         /* File handle from hopen  */   ;;;
  202. ;;;                                                                     ;;;
  203. ;;;                                                                     ;;;
  204. ;;;     hold_handle = psp_handle[19]                                    ;;;
  205. ;;;     psp_handle[19] = handle                                         ;;;
  206. ;;;                                                                     ;;;
  207. ;;;     call dos  to close handle                                       ;;;
  208. ;;;     if error                                                        ;;;
  209. ;;;             retval = -1                                             ;;;
  210. ;;;     else                                                            ;;;
  211. ;;;             retval = 0                                              ;;;
  212. ;;;                                                                     ;;;
  213. ;;;     psp_handle[19] = hold_handle                                    ;;;
  214. ;;;     return (retval)                                                 ;;;
  215. ;;;                                                                     ;;;
  216. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  217.  
  218.  
  219. hclose  proc
  220.         public  hclose
  221.  
  222.         push    es
  223.         push    bp
  224.         mov     bp,sp
  225.         sub     sp, 2
  226.  
  227. handle      equ [bp + 6]
  228. hold_handle equ [bp - 2]
  229.  
  230.         mov     ah, 62h
  231.         int     21h
  232.         mov     es, bx
  233.  
  234.         mov     al, byte ptr es:[18h + 19]
  235.         xor     ah, ah
  236.         mov     hold_handle, ax
  237.         mov     ax, handle
  238.         mov     byte ptr es:[18h + 19], al
  239.         mov     bx, 19
  240.         mov     ah, 3eh
  241.         int     21h
  242.         jc      hclose_error
  243.  
  244.         xor     ax, ax
  245.         jmp     hclose_done
  246.  
  247. hclose_error:
  248.         mov     ax, 0ffffh
  249.  
  250. hclose_done:
  251.         push    ax
  252.         mov     ax, hold_handle
  253.         mov     byte ptr es:[18h + 19], al
  254.         pop     ax
  255.  
  256. hclose_exit:
  257.         mov     sp, bp
  258.         pop     bp
  259.         pop     es
  260.         ret
  261.  
  262. hclose  endp
  263.  
  264.  
  265.  
  266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  267. ;;;                                                                     ;;;
  268. ;;;     hget(handle, ioarea, len)                                       ;;;
  269. ;;;     int             handle;         /* File handle from hopen  */   ;;;
  270. ;;;     unsigned char   *ioarea;        /* Input Buffer            */   ;;;
  271. ;;;     int             len;            /* Number of bytes to read */   ;;;
  272. ;;;                                                                     ;;;
  273. ;;;     hold_handle = psp_handle[19]                                    ;;;
  274. ;;;     psp_handle[19] = handle                                         ;;;
  275. ;;;                                                                     ;;;
  276. ;;;     call dos  to read file                                          ;;;
  277. ;;;     if error                                                        ;;;
  278. ;;;             retval = -1                                             ;;;
  279. ;;;     else                                                            ;;;
  280. ;;;             retval = number of bytes read                           ;;;
  281. ;;;                                                                     ;;;
  282. ;;;     psp_handle[19] = hold_handle                                    ;;;
  283. ;;;     return (retval)                                                 ;;;
  284. ;;;                                                                     ;;;
  285. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  286.  
  287.  
  288. hget    proc
  289.         public  hget
  290.  
  291.         push    es
  292.         push    bp
  293.         mov     bp,sp
  294.         sub     sp, 2
  295.  
  296. handle      equ [bp + 6]
  297. get_area    equ [bp + 8]
  298. get_len     equ [bp + 10]
  299. hold_handle equ [bp - 2]
  300.  
  301.         mov     ah, 62h
  302.         int     21h
  303.         mov     es, bx
  304.  
  305.         mov     al, byte ptr es:[18h + 19]
  306.         xor     ah, ah
  307.         mov     hold_handle, ax
  308.  
  309.         mov     ax, handle
  310.         mov     byte ptr es:[18h + 19], al
  311.         mov     dx, get_area
  312.         mov     cx, get_len
  313.         mov     bx, 19
  314.         mov     ah, 3fh
  315.         int     21h
  316.         jc      hget_error
  317.         jmp     hget_done
  318.  
  319. hget_error:
  320.         mov     ax, 0ffffh
  321.  
  322. hget_done:
  323.         push    ax
  324.         mov     ax, hold_handle
  325.         mov     byte ptr es:[18h + 19], al
  326.         pop     ax
  327.  
  328. hget_exit:
  329.         mov     sp, bp
  330.         pop     bp
  331.         pop     es
  332.         ret
  333.  
  334. hget    endp
  335.  
  336.  
  337. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  338. ;;;                                                                     ;;;
  339. ;;;     hput(handle, ioarea, len)                                       ;;;
  340. ;;;     int             handle;         /* File handle from hopen  */   ;;;
  341. ;;;     unsigned char   *ioarea;        /* Output buffer           */   ;;;
  342. ;;;     int             len;            /* Number of bytes to write*/   ;;;
  343. ;;;                                                                     ;;;
  344. ;;;     hold_handle = psp_handle[19]                                    ;;;
  345. ;;;     psp_handle[19] = handle                                         ;;;
  346. ;;;                                                                     ;;;
  347. ;;;     call dos  to write file                                         ;;;
  348. ;;;     if error                                                        ;;;
  349. ;;;             retval = -1                                             ;;;
  350. ;;;     else                                                            ;;;
  351. ;;;             retval = number of bytes written                        ;;;
  352. ;;;                                                                     ;;;
  353. ;;;     psp_handle[19] = hold_handle                                    ;;;
  354. ;;;     return (retval)                                                 ;;;
  355. ;;;                                                                     ;;;
  356. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  357.  
  358.  
  359. hput    proc
  360.         public  hput
  361.  
  362.         push    es
  363.         push    bp
  364.         mov     bp,sp
  365.         sub     sp, 2
  366.  
  367. handle      equ [bp + 6]
  368. put_area    equ [bp + 8]
  369. put_len     equ [bp + 10]
  370. hold_handle equ [bp - 2]
  371.  
  372.         mov     ah, 62h
  373.         int     21h
  374.         mov     es, bx
  375.  
  376.         mov     al, byte ptr es:[18h + 19]
  377.         xor     ah, ah
  378.         mov     hold_handle, ax
  379.  
  380.         mov     ax, handle
  381.         mov     byte ptr es:[18h + 19], al
  382.         mov     dx, put_area
  383.         mov     cx, put_len
  384.         mov     bx, 19
  385.         mov     ah, 40h
  386.         int     21h
  387.         jc      hput_error
  388.         jmp     hput_done
  389.  
  390. hput_error:
  391.         mov     ax, 0ffffh
  392.  
  393. hput_done:
  394.         push    ax
  395.         mov     ax, hold_handle
  396.         mov     byte ptr es:[18h + 19], al
  397.         pop     ax
  398.  
  399. hput_exit:
  400.         mov     sp, bp
  401.         pop     bp
  402.         pop     es
  403.         ret
  404.  
  405. hput    endp
  406.  
  407. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  408. ;;;                                                                     ;;;
  409. ;;;     long int hseek(handle, rba, method)                             ;;;
  410. ;;;     int             handle;         /* File handle from hopen  */   ;;;
  411. ;;;     long int        rba;            /* Relative Byte address   */   ;;;
  412. ;;;     int             method;         /* Seek method             */   ;;;
  413. ;;;                                                                     ;;;
  414. ;;;     hold_handle = psp_handle[19]                                    ;;;
  415. ;;;     psp_handle[19] = handle                                         ;;;
  416. ;;;                                                                     ;;;
  417. ;;;     call dos  to seek to rba                                        ;;;
  418. ;;;     if error                                                        ;;;
  419. ;;;             retval = -1                                             ;;;
  420. ;;;     else                                                            ;;;
  421. ;;;             retval = seek address                                   ;;;
  422. ;;;                                                                     ;;;
  423. ;;;     psp_handle[19] = hold_handle                                    ;;;
  424. ;;;     return (retval)                                                 ;;;
  425. ;;;                                                                     ;;;
  426. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  427.  
  428.  
  429. hseek   proc
  430.         public  hseek
  431.  
  432.         push    es
  433.         push    bp
  434.         mov     bp,sp
  435.         sub     sp, 2
  436.  
  437. handle      equ [bp + 6]
  438. rba_low     equ [bp + 8]
  439. rba_high    equ [bp + 10]
  440. seek_method equ [bp + 12]
  441. hold_handle equ [bp - 2]
  442.  
  443.         mov     ah, 62h
  444.         int     21h
  445.         mov     es, bx
  446.  
  447.         mov     al, byte ptr es:[18h + 19]
  448.         xor     ah, ah
  449.         mov     hold_handle, ax
  450.  
  451.         mov     ax, handle
  452.         mov     byte ptr es:[18h + 19], al
  453.         mov     dx, rba_low
  454.         mov     cx, rba_high
  455.         mov     ax, seek_method
  456.         mov     ah, 42h
  457.         mov     bx, 19
  458.         int     21h
  459.         jc      hseek_error
  460.         jmp     hseek_done
  461.  
  462. hseek_error:
  463.         mov     ax, 0ffffh
  464.         mov     dx, ax
  465.  
  466. hseek_done:
  467.         push    ax
  468.         mov     ax, hold_handle
  469.         mov     byte ptr es:[18h + 19], al
  470.         pop     ax
  471.  
  472. hseek_exit:
  473.         mov     sp, bp
  474.         pop     bp
  475.         pop     es
  476.         ret
  477. hseek   endp
  478.  
  479.         include epilogue.h
  480.         end
  481.  
  482. *************************************************************************
  483.  
  484. LISTING THREE
  485.  
  486.  
  487. #include <stdio.h>
  488.  
  489. #define MAXF  256
  490.  
  491. struct  { int   scs, sss, sds, ses; }  sreg;
  492. struct  { int   ax, bx, cx, dx, si, di, ds, es; }   dreg;
  493.  
  494. main(argc, argv)
  495. int             argc;
  496. unsigned char   *argv;
  497. {
  498.         int     fid[MAXF];
  499.         int     i;
  500.         int     j;
  501.         int     c;
  502.         long    l;
  503.         int     lastfile;
  504.         char    dsn[30];
  505.         char    line[80];
  506.         long int        hseek();
  507.  
  508.  
  509.         segread(&sreg);
  510.         dreg.ax = 0x6200;
  511.         sysint21(&dreg, &dreg);
  512.  
  513.         printf("\nCreate files");
  514.  
  515.         for (i = 0; i < MAXF ; i++ ) {
  516.                 sprintf(dsn, "\\test\\bt%d.dat", i);
  517.                 c = hcreate(dsn, 0);
  518.                 fid[i] = c;
  519.                 printf("\nCreate dsn = %s, handle = %3d", dsn, c);
  520.  
  521.                 if (c == -1) {
  522.                         break;
  523.                 }
  524.         }
  525.         lastfile = i;
  526.  
  527.         printf("\n");
  528.  
  529.         printf("\nWrite files");
  530.  
  531.         for (i = 0; i < lastfile; i++ ) {
  532.             printf("\nWriting file number %02d", i);
  533.  
  534.             for(j = 0; j < 10; j++ ) {
  535.                 sprintf(line, "out file no %03d line no %02d\n\r", i, j);
  536.                 c = hput(fid[i], line, 28);
  537.             }
  538.         }
  539.  
  540.         printf("\nClose files");
  541.  
  542.         for (i = 0; i < lastfile; i++ ) {
  543.                 c = hclose(fid[i]);
  544.                 printf("\nreturn from close %3d = %3d", i, c );
  545.  
  546.         }
  547.  
  548.         printf("\nOpen files");
  549.  
  550.         for (i = 0; i < lastfile; i++ ) {
  551.                 sprintf(dsn, "\\test\\bt%d.dat", i);
  552.                 c = hopen(dsn, 0);
  553.                 fid[i] = c;
  554.                 printf("\nOpen dsn = %s, handle = %3d", dsn, c);
  555.  
  556.      }
  557.  
  558.      printf("\nRead files");
  559.  
  560.      for (i = 0; i < lastfile; i++ ) {
  561.         l = 28 * (i % 10);
  562.         l = hseek(fid[i], l, 0);
  563.         c = hget(fid[i], line, 28);
  564.         line[26] = 0;
  565.         printf("\nseek return = %3D, get return = %3d, line = %s", l, c, line);
  566.  
  567.         }
  568.  
  569.         printf("\nClose files");
  570.  
  571.         for (i = 0; i < lastfile; i++ ) {
  572.                 c = hclose(fid[i]);
  573.                 printf("\nreturn from close %3d = %3d", i, c );
  574.  
  575.         }
  576. }
  577.  
  578.                                [EOF]
  579.