2014-09-03 12:02:14 +00:00
|
|
|
; int __cdecl setvbuf(FILE *fp, char *buf, int type, size_t size)
|
2014-11-05 17:20:02 +00:00
|
|
|
_setvbuf proc
|
2014-09-03 12:02:14 +00:00
|
|
|
@@fp = DPTR_ dPtrSize + 2
|
|
|
|
@@buf = DPTR_ dPtrSize + 2 + dPtrSize
|
|
|
|
@@type = word ptr dPtrSize + 2 + (dPtrSize * 2)
|
|
|
|
@@size = word ptr dPtrSize + 2 + (dPtrSize * 2) + 2
|
|
|
|
|
|
|
|
push bp
|
|
|
|
mov bp, sp
|
|
|
|
push si
|
|
|
|
push di
|
|
|
|
LES_ bx, [bp+@@fp]
|
|
|
|
mov ax, ES_[bx+FILE.token]
|
|
|
|
cmp ax, word ptr [bp+@@fp]
|
|
|
|
jz short @@validType?
|
|
|
|
jmp @@retEOF
|
|
|
|
|
|
|
|
@@validType?:
|
|
|
|
cmp [bp+@@type], 2
|
|
|
|
jle short @@tooLarge?
|
|
|
|
jmp @@retEOF
|
|
|
|
|
|
|
|
@@tooLarge?:
|
|
|
|
cmp [bp+@@size], 7FFFh
|
|
|
|
jbe short @@stdoutStart?
|
|
|
|
jmp @@retEOF
|
|
|
|
|
|
|
|
@@stdoutStart?:
|
|
|
|
cmp _stdoutStarted, 0
|
|
|
|
jnz short @@stdinStart?
|
|
|
|
cmp word ptr [bp+@@fp], offset stdout
|
|
|
|
jnz short @@stdinStart?
|
|
|
|
mov _stdoutStarted, 1
|
|
|
|
jmp short @@reposition?
|
|
|
|
|
|
|
|
@@stdinStart?:
|
|
|
|
cmp _stdinStarted, 0
|
|
|
|
jnz short @@reposition?
|
|
|
|
cmp word ptr [bp+@@fp], offset stdin
|
|
|
|
jnz short @@reposition?
|
|
|
|
mov _stdinStarted, 1
|
|
|
|
|
|
|
|
@@reposition?:
|
|
|
|
LES_ bx, [bp+@@fp]
|
|
|
|
cmp ES_[bx+FILE.level], 0
|
|
|
|
jz short @@freeBuffer?
|
|
|
|
mov ax, 1
|
|
|
|
push ax
|
|
|
|
xor ax, ax
|
|
|
|
push ax
|
|
|
|
push ax
|
|
|
|
if LDATA
|
|
|
|
push word ptr [bp+@@fp+2]
|
|
|
|
endif
|
|
|
|
push bx
|
|
|
|
nopcall _fseek
|
|
|
|
add sp, 6 + dPtrSize
|
|
|
|
|
|
|
|
@@freeBuffer?:
|
|
|
|
LES_ bx, [bp+@@fp]
|
|
|
|
test byte ptr ES_[bx+FILE.flags], 4
|
|
|
|
jz short @@resetBuffer
|
|
|
|
if LDATA
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
push word ptr ES_[bx+FILE.buffer+2]
|
2014-09-03 12:02:14 +00:00
|
|
|
endif
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
push word ptr ES_[bx+FILE.buffer]
|
2014-09-03 12:02:14 +00:00
|
|
|
nopcall _free
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
popCX_
|
2014-09-03 12:02:14 +00:00
|
|
|
pop cx
|
|
|
|
|
|
|
|
@@resetBuffer:
|
|
|
|
LES_ bx, [bp+@@fp]
|
|
|
|
and ES_[bx+FILE.flags], 0FFF3h
|
|
|
|
mov ES_[bx+FILE._bsize], 0
|
|
|
|
if LDATA
|
|
|
|
mov dx, word ptr [bp+@@fp+2]
|
|
|
|
endif
|
|
|
|
mov ax, word ptr [bp+@@fp]
|
|
|
|
add ax, FILE.hold
|
|
|
|
if LDATA
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
mov word ptr ES_[bx+FILE.buffer+2], dx
|
|
|
|
mov word ptr ES_[bx+FILE.buffer], ax
|
|
|
|
mov word ptr ES_[bx+FILE.curp+2], dx
|
2014-09-03 12:02:14 +00:00
|
|
|
else
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
mov word ptr ES_[bx+FILE.buffer], ax
|
2014-09-03 12:02:14 +00:00
|
|
|
endif
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
mov word ptr ES_[bx+FILE.curp], ax
|
2014-09-03 12:02:14 +00:00
|
|
|
cmp [bp+@@type], 2
|
|
|
|
jz short @@ret0
|
|
|
|
cmp [bp+@@size], 0
|
|
|
|
jbe short @@ret0
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
if LDATA
|
|
|
|
setfarfp _exitbuf, __xfflush
|
2014-09-03 12:02:14 +00:00
|
|
|
mov ax, word ptr [bp+@@buf]
|
|
|
|
or ax, word ptr [bp+@@buf+2]
|
|
|
|
else
|
|
|
|
mov word ptr _exitbuf, offset __xfflush
|
|
|
|
cmp word ptr [bp+@@buf], 0
|
|
|
|
endif
|
|
|
|
jnz short @@setBuffer
|
|
|
|
push [bp+@@size]
|
|
|
|
nopcall _malloc
|
|
|
|
pop cx
|
|
|
|
if LDATA
|
|
|
|
mov word ptr [bp+@@buf+2], dx
|
|
|
|
mov word ptr [bp+@@buf], ax
|
|
|
|
or ax, dx
|
|
|
|
else
|
|
|
|
mov word ptr [bp+@@buf], ax
|
|
|
|
or ax, ax
|
|
|
|
endif
|
|
|
|
jz short @@retEOF
|
|
|
|
LES_ bx, [bp+@@fp]
|
|
|
|
or ES_[bx+FILE.flags], 4
|
|
|
|
jmp short @@setBuffer
|
|
|
|
|
|
|
|
@@retEOF:
|
|
|
|
mov ax, 0FFFFh
|
|
|
|
jmp short @@ret
|
|
|
|
|
|
|
|
@@setBuffer:
|
|
|
|
LES_ bx, [bp+@@fp]
|
|
|
|
if LDATA
|
|
|
|
mov dx, word ptr [bp+@@buf+2]
|
|
|
|
mov ax, word ptr [bp+@@buf]
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
mov word ptr ES_[bx+FILE.curp+2], dx
|
|
|
|
mov word ptr ES_[bx+FILE.curp], ax
|
|
|
|
mov word ptr ES_[bx+FILE.buffer+2], dx
|
|
|
|
mov word ptr ES_[bx+FILE.buffer], ax
|
2014-09-03 12:02:14 +00:00
|
|
|
else
|
|
|
|
mov ax, word ptr [bp+@@buf]
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
mov word ptr ES_[bx+FILE.curp], ax
|
|
|
|
mov word ptr ES_[bx+FILE.buffer], ax
|
2014-09-03 12:02:14 +00:00
|
|
|
endif
|
|
|
|
mov ax, [bp+@@size]
|
|
|
|
mov ES_[bx+FILE._bsize], ax
|
|
|
|
cmp [bp+@@type], 1
|
|
|
|
jnz short @@ret0
|
|
|
|
or ES_[bx+FILE.flags], 8
|
|
|
|
|
|
|
|
@@ret0:
|
|
|
|
xor ax, ax
|
|
|
|
|
|
|
|
@@ret:
|
|
|
|
pop di
|
|
|
|
pop si
|
|
|
|
pop bp
|
|
|
|
ret
|
|
|
|
_setvbuf endp
|