From 5aad47cb087366f28268b1566208aad01f0f592a Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sun, 21 Sep 2014 13:37:38 +0200 Subject: [PATCH] [Reduction] #508: fclose --- libs/BorlandC/fclose.asm | 89 ++++++++++++++++++++++++++++++ th01_fuuin.asm | 112 ++------------------------------------ th01_op.asm | 112 ++------------------------------------ th01_reiiden.asm | 114 ++------------------------------------- 4 files changed, 98 insertions(+), 329 deletions(-) create mode 100644 libs/BorlandC/fclose.asm diff --git a/libs/BorlandC/fclose.asm b/libs/BorlandC/fclose.asm new file mode 100644 index 00000000..39e16566 --- /dev/null +++ b/libs/BorlandC/fclose.asm @@ -0,0 +1,89 @@ +; int __cdecl fclose(FILE *fp) +_fclose proc DIST +@@res = word ptr -2 +@@fp = dword ptr 6 + + push bp + mov bp, sp + sub sp, 2 + push si + push di + mov [bp+@@res], 0FFFFh + mov ax, word ptr [bp+@@fp] + or ax, word ptr [bp+@@fp+2] + jnz short @@verifyToken + jmp @@ret + +@@verifyToken: + les bx, [bp+@@fp] + mov ax, es:[bx+FILE.token] + cmp ax, word ptr [bp+@@fp] + jz short @@buffered? + jmp @@ret + +@@buffered?: + les bx, [bp+@@fp] + cmp es:[bx+FILE._bsize], 0 + jz short @@close? + cmp es:[bx+FILE.level], 0 + jge short @@free? + push word ptr [bp+@@fp+2] + push bx + nopcall _fflush + pop cx + pop cx + or ax, ax + jnz short @@ret + +@@free?: + les bx, [bp+@@fp] + test byte ptr es:[bx+FILE.flags], 4 + jz short @@close? + push word ptr es:[bx+FILE._buffer+2] + push word ptr es:[bx+FILE._buffer] + nopcall _farfree + pop cx + pop cx + +@@close?: + les bx, [bp+@@fp] + cmp es:[bx+FILE.fd], 0 + jl short @@reset + mov al, es:[bx+FILE.fd] + cbw + push ax + nopcall _close + pop cx + mov [bp+@@res], ax + +@@reset: + les bx, [bp+@@fp] + mov es:[bx+FILE.flags], 0 + mov es:[bx+FILE._bsize], 0 + mov es:[bx+FILE.level], 0 + mov es:[bx+FILE.fd], -1 + cmp es:[bx+FILE.istemp], 0 + jz short @@ret + xor ax, ax + push ax + push ax + push ax + push ax + push es:[bx+FILE.istemp] + call __MKNAME + push dx + push ax + nopcall _unlink + pop cx + pop cx + les bx, [bp+@@fp] + mov es:[bx+FILE.istemp], 0 + +@@ret: + mov ax, [bp+@@res] + pop di + pop si + mov sp, bp + pop bp + ret +_fclose endp diff --git a/th01_fuuin.asm b/th01_fuuin.asm index 6208f64a..3229b1c5 100644 --- a/th01_fuuin.asm +++ b/th01_fuuin.asm @@ -4824,109 +4824,7 @@ loc_3C4C: retf _eof endp - -; =============== S U B R O U T I N E ======================================= - -; Attributes: library function bp-based frame - -; int __cdecl fclose(FILE *stream) -_fclose proc far - -var_2 = word ptr -2 -stream = dword ptr 6 - - push bp - mov bp, sp - sub sp, 2 - push si - push di - mov [bp+var_2], 0FFFFh - mov ax, word ptr [bp+stream] - or ax, word ptr [bp+stream+2] - jnz short loc_3C6A - jmp loc_3D09 -; --------------------------------------------------------------------------- - -loc_3C6A: - les bx, [bp+stream] - mov ax, es:[bx+12h] - cmp ax, word ptr [bp+stream] - jz short loc_3C79 - jmp loc_3D09 -; --------------------------------------------------------------------------- - -loc_3C79: - les bx, [bp+stream] - cmp word ptr es:[bx+6], 0 - jz short loc_3CB1 - cmp word ptr es:[bx], 0 - jge short loc_3C98 - push word ptr [bp+stream+2] - push bx ; stream - nop - call _fflush - pop cx - pop cx - or ax, ax - jnz short loc_3D09 - -loc_3C98: - les bx, [bp+stream] - test byte ptr es:[bx+2], 4 - jz short loc_3CB1 - push word ptr es:[bx+0Ah] - push word ptr es:[bx+8] - nop - push cs - call near ptr _farfree - pop cx - pop cx - -loc_3CB1: - les bx, [bp+stream] - cmp byte ptr es:[bx+4], 0 - jl short loc_3CCA - mov al, es:[bx+4] - cbw - push ax ; handle - nop - push cs - call near ptr _close - pop cx - mov [bp+var_2], ax - -loc_3CCA: - les bx, [bp+stream] - mov word ptr es:[bx+2], 0 - mov word ptr es:[bx+6], 0 - mov word ptr es:[bx], 0 - mov byte ptr es:[bx+4], 0FFh - cmp word ptr es:[bx+10h], 0 - jz short loc_3D09 - xor ax, ax - push ax - push ax ; dest - push ax ; int - push ax ; int - push word ptr es:[bx+10h] ; int - call __MKNAME - push dx - push ax ; path - nopcall _unlink - pop cx - pop cx - les bx, [bp+stream] - mov word ptr es:[bx+10h], 0 - -loc_3D09: - mov ax, [bp+var_2] - pop di - pop si - mov sp, bp - pop bp - retf -_fclose endp - +include libs/BorlandC/fclose.asm include libs/BorlandC/fflush.asm include libs/BorlandC/flength.asm include libs/BorlandC/flushall.asm @@ -5150,9 +5048,7 @@ loc_3FD9: jz short loc_4003 push word ptr [bp+stream+2] push word ptr [bp+stream] ; stream - nop - push cs - call near ptr _fclose + nopcall _fclose pop cx pop cx @@ -6286,9 +6182,7 @@ loc_579E: jz short loc_57B3 push word ptr [bp+stream+2] push bx ; stream - nop - push cs - call near ptr _fclose + nopcall _fclose pop cx pop cx diff --git a/th01_op.asm b/th01_op.asm index 3e3c7aad..3fb2c570 100644 --- a/th01_op.asm +++ b/th01_op.asm @@ -4604,109 +4604,7 @@ loc_3D24: retf _eof endp - -; =============== S U B R O U T I N E ======================================= - -; Attributes: library function bp-based frame - -; int __cdecl fclose(FILE *stream) -_fclose proc far - -var_2 = word ptr -2 -stream = dword ptr 6 - - push bp - mov bp, sp - sub sp, 2 - push si - push di - mov [bp+var_2], 0FFFFh - mov ax, word ptr [bp+stream] - or ax, word ptr [bp+stream+2] - jnz short loc_3D42 - jmp loc_3DE1 -; --------------------------------------------------------------------------- - -loc_3D42: - les bx, [bp+stream] - mov ax, es:[bx+12h] - cmp ax, word ptr [bp+stream] - jz short loc_3D51 - jmp loc_3DE1 -; --------------------------------------------------------------------------- - -loc_3D51: - les bx, [bp+stream] - cmp word ptr es:[bx+6], 0 - jz short loc_3D89 - cmp word ptr es:[bx], 0 - jge short loc_3D70 - push word ptr [bp+stream+2] - push bx ; stream - nop - call _fflush - pop cx - pop cx - or ax, ax - jnz short loc_3DE1 - -loc_3D70: - les bx, [bp+stream] - test byte ptr es:[bx+2], 4 - jz short loc_3D89 - push word ptr es:[bx+0Ah] - push word ptr es:[bx+8] - nop - push cs - call near ptr _farfree - pop cx - pop cx - -loc_3D89: - les bx, [bp+stream] - cmp byte ptr es:[bx+4], 0 - jl short loc_3DA2 - mov al, es:[bx+4] - cbw - push ax ; handle - nop - push cs - call near ptr _close - pop cx - mov [bp+var_2], ax - -loc_3DA2: - les bx, [bp+stream] - mov word ptr es:[bx+2], 0 - mov word ptr es:[bx+6], 0 - mov word ptr es:[bx], 0 - mov byte ptr es:[bx+4], 0FFh - cmp word ptr es:[bx+10h], 0 - jz short loc_3DE1 - xor ax, ax - push ax - push ax ; dest - push ax ; int - push ax ; int - push word ptr es:[bx+10h] ; int - call __MKNAME - push dx - push ax ; path - nopcall _unlink - pop cx - pop cx - les bx, [bp+stream] - mov word ptr es:[bx+10h], 0 - -loc_3DE1: - mov ax, [bp+var_2] - pop di - pop si - mov sp, bp - pop bp - retf -_fclose endp - +include libs/BorlandC/fclose.asm include libs/BorlandC/fflush.asm include libs/BorlandC/flength.asm include libs/BorlandC/flushall.asm @@ -4930,9 +4828,7 @@ loc_40B1: jz short loc_40DB push word ptr [bp+buf+2] push word ptr [bp+buf] ; stream - nop - push cs - call near ptr _fclose + nopcall _fclose pop cx pop cx @@ -5947,9 +5843,7 @@ loc_5A19: jz short loc_5A2E push word ptr [bp+stream+2] push bx ; stream - nop - push cs - call near ptr _fclose + nopcall _fclose pop cx pop cx diff --git a/th01_reiiden.asm b/th01_reiiden.asm index 1c0c1b7b..11d87d9c 100644 --- a/th01_reiiden.asm +++ b/th01_reiiden.asm @@ -7852,111 +7852,7 @@ loc_52A4: retf _eof endp - -; =============== S U B R O U T I N E ======================================= - -; Attributes: library function bp-based frame - -; int __cdecl fclose(FILE *stream) -_fclose proc far - -var_2 = word ptr -2 -stream = dword ptr 6 - - push bp - mov bp, sp - sub sp, 2 - push si - push di - mov [bp+var_2], 0FFFFh - mov ax, word ptr [bp+stream] - or ax, word ptr [bp+stream+2] - jnz short loc_52C2 - jmp loc_5361 -; --------------------------------------------------------------------------- - -loc_52C2: - les bx, [bp+stream] - mov ax, es:[bx+12h] - cmp ax, word ptr [bp+stream] - jz short loc_52D1 - jmp loc_5361 -; --------------------------------------------------------------------------- - -loc_52D1: - les bx, [bp+stream] - cmp word ptr es:[bx+6], 0 - jz short loc_5309 - cmp word ptr es:[bx], 0 - jge short loc_52F0 - push word ptr [bp+stream+2] - push bx ; stream - nop - call _fflush - pop cx - pop cx - or ax, ax - jnz short loc_5361 - -loc_52F0: - les bx, [bp+stream] - test byte ptr es:[bx+2], 4 - jz short loc_5309 - push word ptr es:[bx+0Ah] - push word ptr es:[bx+8] - nop - push cs - call near ptr _farfree - pop cx - pop cx - -loc_5309: - les bx, [bp+stream] - cmp byte ptr es:[bx+4], 0 - jl short loc_5322 - mov al, es:[bx+4] - cbw - push ax ; handle - nop - push cs - call near ptr _close - pop cx - mov [bp+var_2], ax - -loc_5322: - les bx, [bp+stream] - mov word ptr es:[bx+2], 0 - mov word ptr es:[bx+6], 0 - mov word ptr es:[bx], 0 - mov byte ptr es:[bx+4], 0FFh - cmp word ptr es:[bx+10h], 0 - jz short loc_5361 - xor ax, ax - push ax - push ax ; dest - push ax ; int - push ax ; int - push word ptr es:[bx+10h] ; int - call __MKNAME - push dx - push ax ; path - nopcall _unlink - pop cx - -loc_5357: - pop cx - les bx, [bp+stream] - mov word ptr es:[bx+10h], 0 - -loc_5361: - mov ax, [bp+var_2] - pop di - pop si - mov sp, bp - pop bp - retf -_fclose endp - +include libs/BorlandC/fclose.asm include libs/BorlandC/fflush.asm include libs/BorlandC/flength.asm include libs/BorlandC/flushall.asm @@ -8186,9 +8082,7 @@ loc_5631: jz short loc_565B push word ptr [bp+stream+2] push word ptr [bp+stream] ; stream - nop - push cs - call near ptr _fclose + nopcall _fclose pop cx pop cx @@ -9407,9 +9301,7 @@ loc_6E8C: jz short loc_6EA1 push word ptr [bp+stream+2] push bx ; stream - nop - push cs - call near ptr _fclose + nopcall _fclose pop cx pop cx