📄 csup.asm
字号:
;
; HEAP_GET(WORD) allocates memory from the C HEAP if at any stage
; the heap grows to within STACKSLOP of the base of the stack this
; function executes a LONGJUMP using the BREAK_ENV buffer. This will
; terminate any internal function.
;
PUBLIC _heap_get
_heap_get:
push bp
mov bp,sp
mov ax,heap_top
add ax,04[bp] ; Add in the requested value
jc heap_error ; Exit with error if Carry
sub bp,STACKSLOP ; now check that the stack
cmp bp,ax ; is still well above the
jc heap_error ; heap.
mov stack_min,ax ; Update the Stack Minimum Variable
add stack_min,STACKSLOP ; for the CHKSTK routine
xchg ax,heap_top ; Return the existing heap top
pop bp ; and update the local variable
ret ; with the new value.
heap_error:
mov dx,3 ; Return the Heap Overflow error
push dx
mov ax,dataOFFSET _break_env ; using the JMP_BUF
push ax
call LONGJUMP ; We are never coming back
;
; HEAP_SIZE returns the size remaining on the C HEAP
;
PUBLIC _heap_size
_heap_size:
push bp
mov bp,sp
mov ax,heap_top
add ax,STACKSLOP
sub bp,ax
jnc noprobs
xor bp,bp
noprobs:
mov ax,sp
pop bp
ret
;
; HEAP() can only return a pointer to the top of the C Heap
; and is identical in function to HEAP_GET(0) except that no
; overflow checking is required and the calling overhead is
; minimal.
;
PUBLIC _heap
_heap:
mov ax,heap_top
ifndef FINAL
ifdef WATCOMC
add ax,STACKSLOP ; we'd better do some stack checking
cmp ax,sp ; 'cause the C isn't doing it now
jae heap_error
sub ax,STACKSLOP
endif
endif
ret
;
; VOID HEAP_SET(BYTE *) forces the heap to a specified value
;
PUBLIC _heap_set
_heap_set:
push bp
mov bp,sp
mov ax,04[bp] ; Get the new value for the HEAP
cmp ax,dataOFFSET _end ; base and check against the
jnb heap_s10 ; absolute base. If below then force
mov ax,dataOFFSET _end ; the heap to the absolute base
heap_s10:
mov heap_top,ax
mov stack_min,ax
add stack_min,STACKSLOP
pop bp
ret
page
ifdef MSC
;
; This is our own Stack Check routine which is called on
; entry to every C routine. AX contains the number of bytes
; to be reseved on the stack.
;
PUBLIC __chkstk
__chkstk:
pop cx ; Get the Return Address
mov bx,sp ; Calculate the new SP value
sub bx,ax ; AX contains the number of bytes
jc OVERFLOW@ ; to reserve.
cmp bx,stack_min ; Check we are still above the heap
jc OVERFLOW@ ; No !!! Help
mov sp,bx ; Update the Stack pointer
jmp cx ; Its Ok lets go back
endif
ifdef WATCOMC
Public __STK
__STK:
cmp ax,sp
jnb OVERFLOW@
sub ax,sp
neg ax
cmp ax,stack_min
jbe OVERFLOW@
ret
endif
ifdef TURBOC
Public OVERFLOW@ ; Public TURBOC Stack Error Handler
endif
OVERFLOW@:
mov dx,2 ; Return the STACK Overflow error
push dx
mov ax,dataOFFSET _break_env ; using the JMP_BUF
push ax
call LONGJUMP ; We are never coming back
; MLOCAL UWORD CDECL findeof(s, count) /* find ^Z in buffer */
; BYTE FAR *s; /* buffer to search */
; UWORD count; /* # of bytes in buffer */
; {
; REG UWORD i;
;
; i = count;
; while(i) { /* Scan through the data */
; if(*s++ == (BYTE) 0x1A) /* looking for a Control-Z */
; break;
; i--;
; }
;
; return (count - i);
; }
PUBLIC _findeof
_findeof:
push bp ; establish a stack frame
mov bp,sp ; s dword 04[bp]
push es ; count word 08[bp]
push di ; save important registers
cld
les di,4[bp] ; load up the pointer
mov cx,8[bp] ; and the count
mov al,26 ; looking for EOF mark in the buffer
repne scasb ; scan until we find one
jne findeof10 ; if we do find one
inc cx ; then include it in the count
findeof10:
mov ax,8[bp] ; we wanted this many
sub ax,cx ; subtract any past EOF
pop di
pop es
pop bp
ret
ifdef DLS
public _my_dls_init
; void my_dls_init()
;extrn _dls_init:near
;extrn _dls_get_table:near
_my_dls_init proc far
push ds
push cs
pop ds
call _dls_init
mov ax,1
push ax
call _dls_get_table
pop ax
pop ds
ret
_my_dls_init endp
public _copy_crit_msgs
_copy_crit_msgs proc near
extrn _crit_msgs:word
extrn _crit_text:byte
push ds
push es
push di
push si
push ds
pop es
push cs
pop ds
mov si,_dls_table
add si,msg0
mov si,[si]
mov di,offset DGROUP:_crit_text
add di,2
mov bx,offset DGROUP:_crit_msgs
add bx,2
mov cx,24
ccm_loop1:
mov es:[bx],di
add bx,2
ccm_loop2:
lodsb
stosb
cmp al,'$'
jne ccm_loop2
loop ccm_loop1
pop si
pop di
pop es
pop ds
ret
_copy_crit_msgs endp
public _copy_rld_msgs
_copy_rld_msgs proc near
extrn _rld_msgs:word
extrn _rld_text:byte
push ds
push es
push di
push si
push ds
pop es
push cs
pop ds
mov si,_dls_table
add si,reload_msgs
mov si,[si]
mov di,offset DGROUP:_rld_text
add di,2
mov bx,offset DGROUP:_rld_msgs
add bx,2
mov cx,3
crm_loop1:
mov es:[bx],di
add bx,2
crm_loop2:
lodsb
stosb
cmp al,0
jne crm_loop2
loop crm_loop1
pop si
pop di
pop es
pop ds
ret
_copy_rld_msgs endp
public _dls_msg1
; char *dls_msg1(int)
_dls_msg1:
push bp
mov bp,sp
push bx
mov ax,4[bp]
shl ax,1
mov bx,cs:_dls_table
add bx,ax
mov ax,cs:[bx]
pop bx
pop bp
ret
endif ; ifdef DLS
public _dos_parse_filename
_dos_parse_filename proc near
push bp
mov bp,sp
sub sp,30h
push es
push ds
pop es
lea di,-30h[bp]
mov si,4[bp]
mov ax,2901h
int 21h
mov ah,0
pop es
add sp,30h
pop bp
ret
_dos_parse_filename endp
public _flush_cache
_flush_cache proc near
push si
push di
push bp
mov ax,4a10h
mov bx,0
mov cx,0edch
int 2fh
cmp ax,6756h ; NWCACHE
je do_flush
cmp ax,0BABEh ; SmartDrive
jne skip_flush
do_flush:
mov ax,4a10h
mov bx,1
mov cx,0edch
int 2fh
skip_flush:
pop bp
pop di
pop si
ret
_flush_cache endp
_TEXT ENDS
page
_DATA SEGMENT byte public 'DATA'
extrn __psp:word
extrn _end:byte
extrn _break_env:word
extrn low_seg:word
public stack_min
public heap_top
ifdef TURBOC
public ___brklvl ; Turbo C does an inline check against
___brklvl label word ; ___brklvl and id SP < ___brklvl then
endif ; it calls OVERFLOW@
stack_min dw dataOFFSET _end + STACKSLOP
heap_top dw dataOFFSET _end ; Current Top of Heap
_DATA ENDS
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -