From a779b848439279ebae2c1236c83cf7f251ea535f Mon Sep 17 00:00:00 2001 From: nmlgc Date: Thu, 28 Aug 2014 05:13:35 +0200 Subject: [PATCH] [Reduction] #245: dos_filesize --- libs/master.lib/dos_filesize.asm | 78 ++++++++++++++++++++++++++++++++ th02_main.asm | 33 +------------- th02_maine.asm | 45 +----------------- th03_mainl.asm | 45 +----------------- th04_main.asm | 45 +----------------- th04_maine.asm | 45 +----------------- th05_maine.asm | 45 +----------------- 7 files changed, 90 insertions(+), 246 deletions(-) create mode 100644 libs/master.lib/dos_filesize.asm diff --git a/libs/master.lib/dos_filesize.asm b/libs/master.lib/dos_filesize.asm new file mode 100644 index 00000000..7fd4e8b6 --- /dev/null +++ b/libs/master.lib/dos_filesize.asm @@ -0,0 +1,78 @@ +; master library - DOS - file - size +; +; Description: +; ファイルの大きさを得る +; +; Function/Procedures: +; long dos_filesize( int fh ) ; +; +; Parameters: +; fh ファイルハンドル +; +; Returns: +; InvalidHandle (cy=1) ハンドルが無効 +; 0〜 (cy=0) ファイルの大きさ +; +; Binding Target: +; Microsoft-C / Turbo-C / Turbo Pascal +; +; Running Target: +; MS-DOS +; +; Requiring Resources: +; CPU: 8086 +; +; Notes: +; +; +; Assembly Language Note: +; +; +; Compiler/Assembler: +; TASM 3.0 +; OPTASM 1.6 +; +; Author: +; 恋塚昭彦 +; +; Revision History: +; 94/ 2/14 Initial: dosfsize.asm/master.lib 0.22a +; 95/ 1/21 [M0.23] BUGFIX + +func DOS_FILESIZE ; dos_filesize() { + mov BX,SP + @@filehandle = (RETSIZE+0)*2 + mov BX,SS:[BX+@@filehandle] + + mov AX,4201h ; 現在位置を得る + xor CX,CX + mov DX,CX + int 21h + jc short @@FAULT + + push SI + push DI + + push AX ; 現在位置をpush + push DX + xor DX,DX + mov AX,4202h ; 末尾へ (CX,DXは既に 0) + int 21h + mov SI,AX ; 末尾位置を DI,SIに保存 + mov DI,DX + + pop CX + pop DX + mov AX,4200h ; 元の位置へ戻る + int 21h + + mov AX,SI + mov DX,DI + pop DI + pop SI + ret 2 +@@FAULT: + neg AX ; InvalidHandle + sbb DX,DX ; 必ず-1, cy=1 + ret 2 +endfunc ; } diff --git a/th02_main.asm b/th02_main.asm index 4fbfaa1e..754da63d 100644 --- a/th02_main.asm +++ b/th02_main.asm @@ -42,35 +42,7 @@ include libs/master.lib/bseek.asm include libs/master.lib/bseek_.asm include libs/master.lib/cutline.asm include libs/master.lib/dos_axdx.asm - -loc_6F6: - mov bx, sp - mov bx, ss:[bx+4] - mov ax, 4201h - xor cx, cx - mov dx, cx - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from present location - jb short loc_726 - push si - push di - push ax - push dx - xor dx, dx - mov ax, 4202h -; --------------------------------------------------------------------------- - db 0CDh -byte_711 db 21h -byte_712 db 8Bh - db 0F0h, 8Bh, 0FAh, 59h, 5Ah, 0B8h, 0, 42h, 0CDh, 21h - db 8Bh, 0C6h, 8Bh, 0D7h, 5Fh, 5Eh, 0CAh, 2, 0 -; --------------------------------------------------------------------------- - -loc_726: - neg ax - sbb dx, dx - retf 2 - +include libs/master.lib/dos_filesize.asm include libs/master.lib/dos_setvect.asm include libs/master.lib/egc.asm @@ -400,8 +372,7 @@ sub_98C endp sub_9CE proc far push word_1DF80 - push cs - call loc_6F6 + call dos_filesize jb short loc_9D9 retf ; --------------------------------------------------------------------------- diff --git a/th02_maine.asm b/th02_maine.asm index 5f223172..fff6a0e2 100644 --- a/th02_maine.asm +++ b/th02_maine.asm @@ -43,47 +43,7 @@ include libs/master.lib/bseek.asm include libs/master.lib/bseek_.asm include libs/master.lib/cutline.asm include libs/master.lib/dos_axdx.asm - -; =============== S U B R O U T I N E ======================================= - - -sub_73A proc far - mov bx, sp - mov bx, ss:[bx+4] - mov ax, 4201h - xor cx, cx - mov dx, cx - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from present location - jb short loc_76A - push si - push di - push ax - push dx - xor dx, dx - mov ax, 4202h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from end of file - mov si, ax - mov di, dx - pop cx - pop dx - mov ax, 4200h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from beginning of file - mov ax, si - mov dx, di - pop di - pop si - retf 2 -; --------------------------------------------------------------------------- - -loc_76A: - neg ax - sbb dx, dx - retf 2 -sub_73A endp - +include libs/master.lib/dos_filesize.asm include libs/master.lib/dos_setvect.asm include libs/master.lib/egc.asm include libs/master.lib/egc_shift_down.asm @@ -416,8 +376,7 @@ sub_BD8 endp sub_C1A proc far push word_D396 - push cs - call near ptr sub_73A + call dos_filesize jb short loc_C25 retf ; --------------------------------------------------------------------------- diff --git a/th03_mainl.asm b/th03_mainl.asm index 66a06bb2..9b1c5bf2 100644 --- a/th03_mainl.asm +++ b/th03_mainl.asm @@ -42,47 +42,7 @@ include libs/master.lib/bread.asm include libs/master.lib/bseek.asm include libs/master.lib/bseek_.asm include libs/master.lib/dos_axdx.asm - -; =============== S U B R O U T I N E ======================================= - - -sub_6C6 proc far - mov bx, sp - mov bx, ss:[bx+4] - mov ax, 4201h - xor cx, cx - mov dx, cx - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from present location - jb short loc_6F6 - push si - push di - push ax - push dx - xor dx, dx - mov ax, 4202h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from end of file - mov si, ax - mov di, dx - pop cx - pop dx - mov ax, 4200h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from beginning of file - mov ax, si - mov dx, di - pop di - pop si - retf 2 -; --------------------------------------------------------------------------- - -loc_6F6: - neg ax - sbb dx, dx - retf 2 -sub_6C6 endp - +include libs/master.lib/dos_filesize.asm include libs/master.lib/dos_keyclear.asm include libs/master.lib/dos_setvect.asm include libs/master.lib/egc.asm @@ -452,8 +412,7 @@ sub_9A2 endp sub_9E4 proc far push word_E946 - push cs - call near ptr sub_6C6 + call dos_filesize jb short loc_9EF retf ; --------------------------------------------------------------------------- diff --git a/th04_main.asm b/th04_main.asm index 341cd334..d19944b6 100644 --- a/th04_main.asm +++ b/th04_main.asm @@ -44,47 +44,7 @@ include libs/master.lib/bseek.asm include libs/master.lib/bseek_.asm include libs/master.lib/cutline.asm include libs/master.lib/dos_axdx.asm - -; =============== S U B R O U T I N E ======================================= - - -sub_826 proc far - mov bx, sp - mov bx, ss:[bx+4] - mov ax, 4201h - xor cx, cx - mov dx, cx - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from present location - jb short loc_856 - push si - push di - push ax - push dx - xor dx, dx - mov ax, 4202h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from end of file - mov si, ax - mov di, dx - pop cx - pop dx - mov ax, 4200h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from beginning of file - mov ax, si - mov dx, di - pop di - pop si - retf 2 -; --------------------------------------------------------------------------- - -loc_856: - neg ax - sbb dx, dx - retf 2 -sub_826 endp - +include libs/master.lib/dos_filesize.asm include libs/master.lib/dos_keyclear.asm include libs/master.lib/dos_read.asm include libs/master.lib/dos_seek.asm @@ -463,8 +423,7 @@ sub_F50 endp sub_F92 proc far push word_216A0 - push cs - call near ptr sub_826 + call dos_filesize jb short loc_F9D retf ; --------------------------------------------------------------------------- diff --git a/th04_maine.asm b/th04_maine.asm index cebd3f90..1a724589 100644 --- a/th04_maine.asm +++ b/th04_maine.asm @@ -43,47 +43,7 @@ include libs/master.lib/bread.asm include libs/master.lib/bseek.asm include libs/master.lib/bseek_.asm include libs/master.lib/dos_axdx.asm - -; =============== S U B R O U T I N E ======================================= - - -sub_7B2 proc far - mov bx, sp - mov bx, ss:[bx+4] - mov ax, 4201h - xor cx, cx - mov dx, cx - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from present location - jb short loc_7E2 - push si - push di - push ax - push dx - xor dx, dx - mov ax, 4202h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from end of file - mov si, ax - mov di, dx - pop cx - pop dx - mov ax, 4200h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from beginning of file - mov ax, si - mov dx, di - pop di - pop si - retf 2 -; --------------------------------------------------------------------------- - -loc_7E2: - neg ax - sbb dx, dx - retf 2 -sub_7B2 endp - +include libs/master.lib/dos_filesize.asm include libs/master.lib/dos_keyclear.asm include libs/master.lib/dos_read.asm include libs/master.lib/dos_seek.asm @@ -456,8 +416,7 @@ sub_AC4 endp sub_B06 proc far push word_E61E - push cs - call near ptr sub_7B2 + call dos_filesize jb short loc_B11 retf ; --------------------------------------------------------------------------- diff --git a/th05_maine.asm b/th05_maine.asm index 0db2dca1..d18f0efc 100644 --- a/th05_maine.asm +++ b/th05_maine.asm @@ -42,47 +42,7 @@ include libs/master.lib/bread.asm include libs/master.lib/bseek.asm include libs/master.lib/bseek_.asm include libs/master.lib/dos_axdx.asm - -; =============== S U B R O U T I N E ======================================= - - -sub_790 proc far - mov bx, sp - mov bx, ss:[bx+4] - mov ax, 4201h - xor cx, cx - mov dx, cx - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from present location - jb short loc_7C0 - push si - push di - push ax - push dx - xor dx, dx - mov ax, 4202h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from end of file - mov si, ax - mov di, dx - pop cx - pop dx - mov ax, 4200h - int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) - ; AL = method: offset from beginning of file - mov ax, si - mov dx, di - pop di - pop si - retf 2 -; --------------------------------------------------------------------------- - -loc_7C0: - neg ax - sbb dx, dx - retf 2 -sub_790 endp - +include libs/master.lib/dos_filesize.asm include libs/master.lib/dos_keyclear.asm include libs/master.lib/dos_read.asm include libs/master.lib/dos_seek.asm @@ -454,8 +414,7 @@ sub_AA2 endp sub_AE4 proc far push word_102FE - push cs - call near ptr sub_790 + call dos_filesize jb short loc_AEF retf ; ---------------------------------------------------------------------------