home *** CD-ROM | disk | FTP | other *** search
-
-
- LISTING ONE
-
-
- 1) copy masm.exe masm.sav (to make a backup)
-
- 2) ren masm.exe masm.fix (debug.com can't wrtie EXE files)
-
- 3) debug masm.fix
- 3a) D 72B8 L 22 (should see 34 bytes of 00)
- 3b) E 72B8
- enter these bytes:
- 8B 1E D6 09 C6 06 C0 01 00 E9 75 02 C4 57 06 FE
- 06 C0 01 E9 74 02 80 7C FF 1A 74 03 39 9D 02 4E
- EB F4
- 3c) U 7535 L 1 (should see "MOV BX,[09D6]" )
- 3d) E 7535
- enter these bytes: E9 80 FD
- 3e) U 753F L 1 (should see "LES DX,[BX+06]" )
- 3f) E 753F
- enter these bytes: E9 82 FD
- 3g) U 756D L 1 (should see "CMP BYTE PTR [SI-01],1A" )
- enter these bytes: E9 5E FD
- 3h) W (to write changes to masm.fix)
- 3i) Q (to exit debug.com)
-
- 4) ren masm.fix masm.exe
-
- 5) Test masm.exe to make sure changes have been made correctly.
- If not, copy masm.sav to mas.exe and try again.
-
- ****************************************************************************
-
-
- LISTING TWO
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;; ;;;;
- ;;;; hpkio Basic I/O functions using handle packing. ;;;;
- ;;;; ;;;;
- ;;;; Written By Paul M. Adams ;;;;
- ;;;; Route 4 Box 23 ;;;;
- ;;;; Shelbyville, KY 40065 ;;;;
- ;;;; ;;;;
- ;;;; ;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- include model.h
- include prologue.h
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; ;;;
- ;;; hcreate(dsn, attr) ;;;
- ;;; unsigned char *dsn; /* Data Set Name */ ;;;
- ;;; int attr; /* file attribute byte */ ;;;
- ;;; ;;;
- ;;; ;;;
- ;;; hold_handle = psp_handle[19] ;;;
- ;;; psp_handle[19] = FF ;;;
- ;;; call dos to create file ;;;
- ;;; if error ;;;
- ;;; retval = -1 ;;;
- ;;; else ;;;
- ;;; retval = psp_handle[dos_handle] ;;;
- ;;; psp_handle[dos_handle] = FF ;;;
- ;;; ;;;
- ;;; psp_handle[19] = hold_handle ;;;
- ;;; ;;;
- ;;; return(retval) - real dos handle ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- hcreate proc
- public hcreate
- push es
- push bp
- mov bp,sp
- sub sp, 2
-
- dsn equ [bp + 6]
- attr equ [bp + 8]
- hold_handle equ [bp - 2]
-
- mov ah, 62h
- int 21h
- mov es, bx
-
- mov al, byte ptr es:[18h + 19]
- xor ah, ah
- mov hold_handle, ax
- mov byte ptr es:[18h + 19], 0ffh
-
- mov ah, 3ch
- mov dx, dsn
- mov cx, attr
- int 21h
- jc hcreate_error
-
- mov bx, ax
- mov al, byte ptr es:[bx + 18h]
- xor ah, ah
- mov byte ptr es:[bx + 18h], 0ffh
- jmp hcreate_done
-
- hcreate_error:
- mov ax, 0ffffh
-
- hcreate_done:
- push ax
- mov ax, hold_handle
- mov byte ptr es:[18h + 19], al
- pop ax
-
- hcreate_exit:
- mov sp, bp
- pop bp
- pop es
- ret
-
- hcreate endp
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; ;;;
- ;;; hopen(dsn, mode) ;;;
- ;;; unsigned char *dsn; /* Data Set Name */ ;;;
- ;;; int mode; /* DOS open mode */ ;;;
- ;;; ;;;
- ;;; hold_handle = psp_handle[19] ;;;
- ;;; psp_handle[19] = FF ;;;
- ;;; call dos to open file ;;;
- ;;; if error ;;;
- ;;; retval = -1 ;;;
- ;;; else ;;;
- ;;; retval = psp_handle[dos_handle] ;;;
- ;;; psp_handle[dos_handle] = FF ;;;
- ;;; ;;;
- ;;; psp_handle[19] = hold_handle ;;;
- ;;; ;;;
- ;;; return(retval) - real dos handle ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- hopen proc
- public hopen
-
- push es
- push bp
- mov bp,sp
- sub sp, 2
-
- dsn equ [bp + 6]
- mode equ [bp + 8]
- hold_handle equ [bp - 2]
-
- mov ah, 62h
- int 21h
- mov es, bx
-
- mov al, byte ptr es:[18h + 19]
- xor ah, ah
- mov hold_handle, ax
- mov byte ptr es:[18h + 19], 0ffh
-
- mov ax, mode
- mov ah, 3dh
- mov dx, dsn
- int 21h
- jc hopen_error
-
- mov bx, ax
- mov al, byte ptr es:[bx + 18h]
- xor ah, ah
- mov byte ptr es:[bx + 18h], 0ffh
- jmp hopen_done
-
- hopen_error:
- mov ax, 0ffffh
-
- hopen_done:
- push ax
- mov ax, hold_handle
- mov byte ptr es:[18h + 19], al
- pop ax
-
- hopen_exit:
- mov sp, bp
- pop bp
- pop es
- ret
- hopen endp
-
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; ;;;
- ;;; hclose(handle) ;;;
- ;;; int handle; /* File handle from hopen */ ;;;
- ;;; ;;;
- ;;; ;;;
- ;;; hold_handle = psp_handle[19] ;;;
- ;;; psp_handle[19] = handle ;;;
- ;;; ;;;
- ;;; call dos to close handle ;;;
- ;;; if error ;;;
- ;;; retval = -1 ;;;
- ;;; else ;;;
- ;;; retval = 0 ;;;
- ;;; ;;;
- ;;; psp_handle[19] = hold_handle ;;;
- ;;; return (retval) ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- hclose proc
- public hclose
-
- push es
- push bp
- mov bp,sp
- sub sp, 2
-
- handle equ [bp + 6]
- hold_handle equ [bp - 2]
-
- mov ah, 62h
- int 21h
- mov es, bx
-
- mov al, byte ptr es:[18h + 19]
- xor ah, ah
- mov hold_handle, ax
- mov ax, handle
- mov byte ptr es:[18h + 19], al
- mov bx, 19
- mov ah, 3eh
- int 21h
- jc hclose_error
-
- xor ax, ax
- jmp hclose_done
-
- hclose_error:
- mov ax, 0ffffh
-
- hclose_done:
- push ax
- mov ax, hold_handle
- mov byte ptr es:[18h + 19], al
- pop ax
-
- hclose_exit:
- mov sp, bp
- pop bp
- pop es
- ret
-
- hclose endp
-
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; ;;;
- ;;; hget(handle, ioarea, len) ;;;
- ;;; int handle; /* File handle from hopen */ ;;;
- ;;; unsigned char *ioarea; /* Input Buffer */ ;;;
- ;;; int len; /* Number of bytes to read */ ;;;
- ;;; ;;;
- ;;; hold_handle = psp_handle[19] ;;;
- ;;; psp_handle[19] = handle ;;;
- ;;; ;;;
- ;;; call dos to read file ;;;
- ;;; if error ;;;
- ;;; retval = -1 ;;;
- ;;; else ;;;
- ;;; retval = number of bytes read ;;;
- ;;; ;;;
- ;;; psp_handle[19] = hold_handle ;;;
- ;;; return (retval) ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- hget proc
- public hget
-
- push es
- push bp
- mov bp,sp
- sub sp, 2
-
- handle equ [bp + 6]
- get_area equ [bp + 8]
- get_len equ [bp + 10]
- hold_handle equ [bp - 2]
-
- mov ah, 62h
- int 21h
- mov es, bx
-
- mov al, byte ptr es:[18h + 19]
- xor ah, ah
- mov hold_handle, ax
-
- mov ax, handle
- mov byte ptr es:[18h + 19], al
- mov dx, get_area
- mov cx, get_len
- mov bx, 19
- mov ah, 3fh
- int 21h
- jc hget_error
- jmp hget_done
-
- hget_error:
- mov ax, 0ffffh
-
- hget_done:
- push ax
- mov ax, hold_handle
- mov byte ptr es:[18h + 19], al
- pop ax
-
- hget_exit:
- mov sp, bp
- pop bp
- pop es
- ret
-
- hget endp
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; ;;;
- ;;; hput(handle, ioarea, len) ;;;
- ;;; int handle; /* File handle from hopen */ ;;;
- ;;; unsigned char *ioarea; /* Output buffer */ ;;;
- ;;; int len; /* Number of bytes to write*/ ;;;
- ;;; ;;;
- ;;; hold_handle = psp_handle[19] ;;;
- ;;; psp_handle[19] = handle ;;;
- ;;; ;;;
- ;;; call dos to write file ;;;
- ;;; if error ;;;
- ;;; retval = -1 ;;;
- ;;; else ;;;
- ;;; retval = number of bytes written ;;;
- ;;; ;;;
- ;;; psp_handle[19] = hold_handle ;;;
- ;;; return (retval) ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- hput proc
- public hput
-
- push es
- push bp
- mov bp,sp
- sub sp, 2
-
- handle equ [bp + 6]
- put_area equ [bp + 8]
- put_len equ [bp + 10]
- hold_handle equ [bp - 2]
-
- mov ah, 62h
- int 21h
- mov es, bx
-
- mov al, byte ptr es:[18h + 19]
- xor ah, ah
- mov hold_handle, ax
-
- mov ax, handle
- mov byte ptr es:[18h + 19], al
- mov dx, put_area
- mov cx, put_len
- mov bx, 19
- mov ah, 40h
- int 21h
- jc hput_error
- jmp hput_done
-
- hput_error:
- mov ax, 0ffffh
-
- hput_done:
- push ax
- mov ax, hold_handle
- mov byte ptr es:[18h + 19], al
- pop ax
-
- hput_exit:
- mov sp, bp
- pop bp
- pop es
- ret
-
- hput endp
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; ;;;
- ;;; long int hseek(handle, rba, method) ;;;
- ;;; int handle; /* File handle from hopen */ ;;;
- ;;; long int rba; /* Relative Byte address */ ;;;
- ;;; int method; /* Seek method */ ;;;
- ;;; ;;;
- ;;; hold_handle = psp_handle[19] ;;;
- ;;; psp_handle[19] = handle ;;;
- ;;; ;;;
- ;;; call dos to seek to rba ;;;
- ;;; if error ;;;
- ;;; retval = -1 ;;;
- ;;; else ;;;
- ;;; retval = seek address ;;;
- ;;; ;;;
- ;;; psp_handle[19] = hold_handle ;;;
- ;;; return (retval) ;;;
- ;;; ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- hseek proc
- public hseek
-
- push es
- push bp
- mov bp,sp
- sub sp, 2
-
- handle equ [bp + 6]
- rba_low equ [bp + 8]
- rba_high equ [bp + 10]
- seek_method equ [bp + 12]
- hold_handle equ [bp - 2]
-
- mov ah, 62h
- int 21h
- mov es, bx
-
- mov al, byte ptr es:[18h + 19]
- xor ah, ah
- mov hold_handle, ax
-
- mov ax, handle
- mov byte ptr es:[18h + 19], al
- mov dx, rba_low
- mov cx, rba_high
- mov ax, seek_method
- mov ah, 42h
- mov bx, 19
- int 21h
- jc hseek_error
- jmp hseek_done
-
- hseek_error:
- mov ax, 0ffffh
- mov dx, ax
-
- hseek_done:
- push ax
- mov ax, hold_handle
- mov byte ptr es:[18h + 19], al
- pop ax
-
- hseek_exit:
- mov sp, bp
- pop bp
- pop es
- ret
- hseek endp
-
- include epilogue.h
- end
-
- *************************************************************************
-
- LISTING THREE
-
-
- #include <stdio.h>
-
- #define MAXF 256
-
- struct { int scs, sss, sds, ses; } sreg;
- struct { int ax, bx, cx, dx, si, di, ds, es; } dreg;
-
- main(argc, argv)
- int argc;
- unsigned char *argv;
- {
- int fid[MAXF];
- int i;
- int j;
- int c;
- long l;
- int lastfile;
- char dsn[30];
- char line[80];
- long int hseek();
-
-
- segread(&sreg);
- dreg.ax = 0x6200;
- sysint21(&dreg, &dreg);
-
- printf("\nCreate files");
-
- for (i = 0; i < MAXF ; i++ ) {
- sprintf(dsn, "\\test\\bt%d.dat", i);
- c = hcreate(dsn, 0);
- fid[i] = c;
- printf("\nCreate dsn = %s, handle = %3d", dsn, c);
-
- if (c == -1) {
- break;
- }
- }
- lastfile = i;
-
- printf("\n");
-
- printf("\nWrite files");
-
- for (i = 0; i < lastfile; i++ ) {
- printf("\nWriting file number %02d", i);
-
- for(j = 0; j < 10; j++ ) {
- sprintf(line, "out file no %03d line no %02d\n\r", i, j);
- c = hput(fid[i], line, 28);
- }
- }
-
- printf("\nClose files");
-
- for (i = 0; i < lastfile; i++ ) {
- c = hclose(fid[i]);
- printf("\nreturn from close %3d = %3d", i, c );
-
- }
-
- printf("\nOpen files");
-
- for (i = 0; i < lastfile; i++ ) {
- sprintf(dsn, "\\test\\bt%d.dat", i);
- c = hopen(dsn, 0);
- fid[i] = c;
- printf("\nOpen dsn = %s, handle = %3d", dsn, c);
-
- }
-
- printf("\nRead files");
-
- for (i = 0; i < lastfile; i++ ) {
- l = 28 * (i % 10);
- l = hseek(fid[i], l, 0);
- c = hget(fid[i], line, 28);
- line[26] = 0;
- printf("\nseek return = %3D, get return = %3d, line = %s", l, c, line);
-
- }
-
- printf("\nClose files");
-
- for (i = 0; i < lastfile; i++ ) {
- c = hclose(fid[i]);
- printf("\nreturn from close %3d = %3d", i, c );
-
- }
- }
-
- [EOF]
-