📄 osstmt.asm
字号:
TITLE OSSTMT - OS Unique features for BASCOM-86
;***
; OSSTMT - OS Unique features for BASCOM-86
;
; Copyright <C> 1986, Microsoft Corporation
;
;Purpose:
; This module contains Operating system-unique features for supporting
; BASIC-callable DOS functions.
;
; BASIC Syntax mapping to the included runtime entry points:
;
; - ENVIRON Statement:
;
; ENVIRON string
; |
; B$SENV
;
; - ENVIRON$ Function:
;
; Two types of arguments produce unique runtime calls:
;
; stringvar = ENVIRON$(num) stringvar = ENVIRON$(string)
; | |
; B$FEVI B$FEVS
;
; - ERDEV Variable:
;
; v = ERDEV
; |
; B$ERDV
;
; - ERDEV$ Variable:
;
; v = B$ERDEV
; |
; B$ERDS
;
; - IOCTL$ Function:
;
; IOCTL$ ([#]filenumber)
; |
; B$FICT
;
; - IOCTL Statement:
;
; IOCTL [#]filenumber, string
; |
; B$SICT
;
; - SHELL Statement:
;
; SHELL [commandstring]
; |
; B$SSHL
;
; - SHELL Function:
; x = SHELL(commandstring)
; |
; B$FSHL
;
;******************************************************************************
INCLUDE switch.inc
INCLUDE rmacros.inc ; Runtime Macro Defintions
USESEG <LOADRTM>
USESEG <OS_TEXT>
USESEG <ER_TEXT>
USESEG <RT_TEXT>
USESEG <ST_TEXT>
USESEG <NH_TEXT>
USESEG <FH_TEXT>
USESEG <_DATA>
USESEG <_BSS>
INCLUDE seg.inc
INCLUDE oscalls.inc
INCLUDE baslibma.inc
INCLUDE files.inc
INCLUDE devdef.inc
INCLUDE addr.inc
INCLUDE ascii.inc
INCLUDE rtps.inc ; constants shared with QBI
INCLUDE string.inc
INCLUDE idmac.inc
INCLUDE const.inc
ExecParamStruc STRUC
ExecEnvSeg DW ? ;environment segment
CmdLineOff DW ? ;offset of command line tail
CmdLineSeg DW ? ;segment of command line tail
FileBlock1Off DW ? ;offset of first FCB (offset 5CH in PSP)
FileBlock1Seg DW ? ;segment of first FCB
FileBlock2Off DW ? ;offset of second FCB (offset 6CH in PSP)
FileBlock2Seg DW ? ;segment of second FCB
ExecParamStruc ENDS
externFP UiReInit ;hooks interrupts for UI
externFP UiPause ;unhooks UI interrupts
; Operating System Equates and Macros
sBegin _DATA
externW b$pCommSave ;conditional vector to B$CommSave
externW b$pCommRestore ;conditional vector to B$CommRestore
externW b$nuldes
externW b$shli_disp ;SHELL initialization dispatch vectors
externW b$shlt_disp ;SHELL termination dispatch vectors
externW b$CURSOR ; current cursor position
externB b$WDOBOT ; text window bottom
sEnd _DATA
sBegin _BSS
externB b$PATHNAM
externW b$ERDEV
externW b$ERDEVP
externW b$env_len
externB b$Buf2 ; overlaid with EXEC parameter blocks
Fcb1Blk EQU b$Buf2 ;block for first FCB
Fcb2Blk EQU b$Buf2+10H ;block for second FCB
ExecBlk EQU b$Buf2+20H ;parameter block for EXEC call
IF (20H + SIZE ExecParamStruc) GT FILNAML
ERROR -- b$Buf2 not big enough for EXEC parameter blocks
ENDIF
sEnd _BSS
externFP __ctermsub ; C math termination (returns)
externFP B$cinitsub ; C math initialion (returns)
sBegin ER_TEXT
externNP B$FrameAFE
externNP B$ERR_FC
externNP B$ERR_OM
externNP B$ERR_IOE
externNP B$ERR_IFN
sEnd ER_TEXT
sBegin NH_TEXT
externNP B$STDALCTMP
externNP B$STALCTMP
sEnd NH_TEXT
sBegin FH_TEXT
externNP B$FHShlTerm ; trick to drag in fhchn.asm!
sEnd FH_TEXT
externFP B$COMP_DISP ;generalized dispatcher
externFP B$RTMInstall ;routine to install RTM dispatch vector
externFP B$RTMDeinstall ;routine to deinstall RTM vector
sBegin RT_TEXT
externNP B$$TCR ; do a CR/LF
externNP B$GETCSRDATA ; get current cursor position and type.
externNP B$SCNLOC ; update cursor position
externNP B$OVWCSR ; turn on overwrite cursor
externNP B$OFFCSR ; turn off cursor
externNP B$GRMODE ; test for graphics mode
sEnd RT_TEXT
SUBTTL SHELL support shared with QBI RTM loader
PAGE
assumes CS,LOADRTM
sBegin LOADRTM
;***
; B$SHELL - SHELL the specified process.
;
;Purpose:
; Added with revision [21].
; SHELL the requested process and return an error code.
;Entry:
; AX = environment seg to use
; CX:DX = ptr to program pathname to be execed.
; BX = DGROUP ptr to argument list.
; SI = DGROUP ptr to argrments to be parsed into FCB blocks.
;Exit:
; AX = 0 if no error occurred.
;Uses:
; Per Convention.
;Exceptions:
; None.
;******************************************************************************
assumes ES,DGROUP
cProc B$Shell,<PUBLIC,FAR>,<SI,DI,ES>
cBegin
; Perform the DOS 3 shell operation.
PUSH DS ;set ES to DS
POP ES
; Fill the EXEC parameter block.
MOV WORD PTR ExecBlk.ExecEnvSeg,AX ;use specified ENV block
MOV WORD PTR ExecBlk.CmdLineOff,BX ;set command line offset
MOV WORD PTR ExecBlk.CmdLineSeg,DS ;set cmdline far ptr
MOV WORD PTR ExecBlk.FileBlock1Off,OFFSET DGROUP:Fcb1Blk
MOV WORD PTR ExecBlk.FileBlock1Seg,DS ;set first FCB far ptr
MOV WORD PTR ExecBlk.FileBlock2Off,OFFSET DGROUP:Fcb2Blk
MOV WORD PTR ExecBlk.FileBlock2Seg,DS ;set second FCB far ptr
; Parse the program name to point to first parameter.
; Parse the first two parameters to the default FCB blocks.
MOV DI,OFFSET DGROUP:Fcb1Blk ;point to first FCB block
MOV AX,2901H ;function to parse - strip leading blanks
INT 21H ;dummy FCB fill - SI points to first param
INT 21H ;fill first FCB - SI points to second param
MOV DI,OFFSET DGROUP:Fcb2Blk ;point to second FCB block
INT 21H ;fill second FCB - (unused params null)
; Set up the registers for the EXEC, save SS:SP in CS, and
; perform the EXEC call.
PUSH DS ;save DGROUP segment on stack
PUSH BP ;save frame pointer on stack
MOV DS,CX ;set COMSPEC segment in data segment
assumes DS,NOTHING
MOV BX,OFFSET DGROUP:ExecBlk ;ES:BX has pointer to param block
MOV AX,4B00H ;DOS function to EXEC program
MOV CS:SavedSSinCS,SS ;save the stack segment in CS
MOV CS:SavedSPinCS,SP ;save the stack pointer in CS
INT 21H ;EXEC - all regs changed except CS:IP
; After EXEC return, restore the stack and save any error code.
CLI ;turn off interrupts
MOV SS,CS:SavedSSinCS ;restore the stack segment
MOV SP,CS:SavedSPinCS ;restore the stack pointer
STI ;turn interrupts back on
POP BP ;restore frame pointer from stack
POP DS ;restore the data segment
assumes DS,DGROUP
JC ExecError ;jump if error, AX has error code
XOR AX,AX ;if no error, then no error code
ExecError:
cEnd
; Stack segment and offset pointer must be saved in the
; current code segment for restoration after the EXEC call.
SavedSPinCS DW ? ;saved stack pointer before EXEC
SavedSSinCS DW ? ;saved stack segment before EXEC
assumes ES,NOTHING
sEnd LOADRTM
PAGE
assumes CS,OS_TEXT
sBegin OS_TEXT
externNP B$LHFDBLOC
externNP B$SHLSAV
externNP B$SHLRST
externNP B$SEGINI
externNP B$BldExecCmdLine ;parse and build command line for exec
externNP B$FIRST_ENV
externNP B$NEXT_ENV
;***
; B$ShellSetup - Set up runtime for a SHELL.
;
;Purpose:
; Added with revision [21].
; Prepares runtime for a SHELL by getting off of interrupts,
; and compressing near and far heaps as much as possible.
;Entry:
; None.
;Exit:
; None.
;Uses:
; Per Convention.
;Exceptions:
; None.
;******************************************************************************
cProc B$ShellSetup,<PUBLIC,FAR>,<SI>
cBegin
; For QBI, let User Interface off of it's interrupts.
PUSH ES
CALL UiPause ; Let UI Get it's BUTT out of the way.
POP ES
; Disable and preserve the runtime state.
MOV SI,OFFSET DGROUP:b$shlt_disp ;SHELL term disp vector
cCall B$COMP_DISP ;do SHELL termination
CALL B$SHLSAV ;perform low-level SHELL save routine
CALL [b$pCommSave]
CALL __ctermsub ; terminate math
; give the shelled program a cursor
MOV AX,OFFSET CS:B$OVWCSR ; assume to turn on cursor
call B$GRMODE ; graphics mode?
JZ DSPL_CURSOR ; brif not -- display overwrite cursor
MOV AX,OFFSET CS:B$OFFCSR ; turn off the cursor
DSPL_CURSOR:
MOV DX,b$CURSOR ; at current position
CALL AX ; display appropriate cursor
NoCursor:
; For DOS 3 RTM and QBI UL, deinstall the RTM dispatch interrupt
CALL B$RTMDeinstall ;remove the vector
cEnd
PAGE
;***
; B$ShellRecover - Restore runtime after a SHELL.
;
;Purpose:
; Added with revision [21].
; Restores runtime to the pre-SHELL state by reinstalling interrupts,
; and expanding near and far heaps as much as possible.
;Entry:
; None.
;Exit:
; None.
;Uses:
; Per Convention.
;Exceptions:
; None.
;******************************************************************************
cProc B$ShellRecover,<PUBLIC,FAR>,<SI>
cBegin
; For DOS 3 RTM, reinstall the RTM dispatch interrupt
CALL B$RTMInstall ;relink the interrupt vector
; Restore the runtime state.
CALL B$cinitsub ; re-init math
CALL B$SEGINI ;establish the new DGROUP value
CALL B$SHLRST ;perform low-level initialize after SHELL
CALL B$GETCSRDATA ; DX,CX = current cursor position,type
CALL B$SCNLOC ; update cursor position variables, since
; the SHELL might have modified it, and
; display user cursor.
CMP DL,b$WDOBOT ; outside of current text window now?
JBE NoCursorRestore ; brif not -- don't scroll
CALL B$$TCR ; do a CR/LF to scroll the screen and
; (possibly) bring cursor position back
; into current text window range
NoCursorRestore:
MOV SI,OFFSET DGROUP:b$shli_disp ;SHELL init disp vector
cCall B$COMP_DISP ;do SHELL reinitialization
CALL [b$pCommRestore] ;restore the communication device state
; For QBI, let User Interface off of it's interrupts.
CALL UiReInit ;Let UI Get it's BUTT back in the way.
cEnd
PAGE
;***
; B$FSHL - asynchronous SHELL function runtime routine (DOS 5)
; Purpose:
; B$FSHL performs an asynchronous SHELL function and
; returns the process ID of the executing task.
;
; Inputs:
; BX - string descriptor of EXEC command string
; Outputs:
; AX - Process ID of spawned process.
; Modfies:
; None.
; Uses:
; None.
; Exceptions:
; Advanced feature error if not OS/2
;******************************************************************************
cProc B$FSHL,<PUBLIC,FAR>,<SI,DI,ES>
cBegin
JMP B$FrameAFE ; advanced feature error + frame setup
cEnd <nogen>
;***
; B$SSHL - SHELL command runtime routine
; Purpose:
; B$SSHL saves its current environment and
; performs an EXEC call with the string argument given. The
; saved environment is then restored.
;
; Inputs:
; sdExec/psdExec - sd or psd of EXEC command string
; Outputs:
; None.
; Modifies:
; None.
; Uses:
; None.
;*****************************************************************************
cProc B$SSHL,<PUBLIC,FAR>,<SI,DI,ES>
parmSD sdExec
cBegin
PUSH DS ;get DGROUP on stack...
POP ES ;...and set ES to DGROUP
assumes ES,DGROUP
GetpSD BX,sdExec ; [BX] = psdExec
cCall B$BldExecCmdLine ;parse command line into b$PATHNAM
PUSH AX ;save COMSPEC far ptr offset
PUSH DX ;save COMSPEC far ptr segment
cCall B$ShellSetup ;prepare for SHELL operation
; Perform the DOS 5 shell operation.
; Perform the DOS 3 shell operation.
POP CX ;get COMSPEC segment (saved as DX)
POP DX ;get COMSPEC offset (saved as AX)
MOV SI,OFFSET DGROUP:b$PATHNAM ;get pointer to cmdline byte count
MOV BX,SI ;get ptr to command tail.
CMP BYTE PTR [SI],0 ;test if null string given
JZ ExecNullCmd ;if so, process to get null FCB's
MOV SI,OFFSET DGROUP:b$PATHNAM+4 ;point to program name (past /C)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -