⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtinit.asm

📁 [随书类]Dos6.0源代码
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;	None.
;Exceptions:
;	None.
;****
cProc	B$Init,<PUBLIC,FAR>,<ES,SI>
cBegin
	MOV	SI,b$pBC_SAB		;get offset to beginning of table
	LES	SI,[SI] 		;ES:SI = module header ptr
	MOV	b$ucodeoff,SI
	MOV	b$ucodeseg,ES
	CALL	B$RTRUNINI		;clear user vars
	OR	b$CtrlFlags,NoInitBcVars ;We have already inited BcVars,
					;B$RtRunini doesn't need to.

cEnd

GenericError:

BADLLI: 				
	JMP	B$ERR_LLI		; Low level initialization error
BADDOS: 				
	JMP	B$ERR_DOS		; Invalid dos version error

	SUBTTL	Runtime Core "ONE" time initialization
	PAGE
;***
;B$RTINI - One time Initializion routine for the runtime core.
;PLM B$RTINI()
;
;Purpose:
;	This is the routine responsible for initializing the runtime
;	core.  This routine checks to make sure that the runtime is
;	running under a reasonable version of DOS.  It also checks
;	to make sure that each object module was compiled with the
;	correct version of the compiler, and that each module was
;	linked with the correct library.  For DOS 3 RTM module versions,
;	this routine causes the runtime module to get loaded.
;	We will also determine if IO has been redirected.
;	We will set up the signal/interrupt handlers for divide by 0,
;	overflow, and HARD disk errors.  For OS/2 versions,
;	if we have been chained to we will get the data that was
;	passed across shared memory.
;	This routine move from INIT_CODE to RT_TEXT with [88].
;
;
; BC3	- void pascal B$RTINI()
; ---
;	This entry point is called B$RTINI.  It has no parameters and
;	performs initialization that is only needed once.  This initialization
;	includes:
;		Checking for reasonable versions of DOS
;		Checking each user module for proper linkage
;			and compiler version
;	  DOS 3 specific:
;		Get/Save machine ID (low level)
;		Set /0, overflow, and int24 handlers
;		Have low level save runtime DS in LL CS (chain/shell/ints)
;	  RTM module specific:
;		Load and fixup RTM module
;		Init RTM module interrupt vectors
;	  OS/2 specific:
;		Set /0, and overflow signal handlers
;		set ignore int24 signal to return an error code
;
; QB4	- void pascal B$RTINI()
; ---
;	The interpreter entry point will also be B$RTINI for "ONE time" init.
;	The interpreter runtime will not need as much "ONE time" initialization
;	as the compiler.  It will still be sensitive to differences in DOS 3 vs
;	OS/2.
;		Checking for reasonable versions of DOS
;	  DOS 3 specific:
;		Get/Save machine ID (low level)
;		Set /0, overflow, and int24 handlers
;		Have low level save runtime DS in LL CS (ints)
;	  OS/2 specific:
;		Set /0, and overflow signal handlers
;		set ignore int24 signal and return an error code
;
;Entry:
;	None.
;
;Exit:
;	None.
;
;Uses:
;	None.
;
;Exceptions:
;	Doesn't return in following conditions:
;		Wrong version of DOS.
;		Wrong runtime module.(BC3)
;		Linked with wrong library. (BC3)
;		Bad runtime module. (BC3)
;		Not enough memory to load runtime module. (BC3)
;****
cProc	B$RTINI,<NEAR>,<SI>	
cBegin
	PUSH	ES			;ensure ES is preserved.

;	Install the RTM interrupt vector.  This is placed first to
;	to ensure that the vector is always installed and deinstalled
;	once under all circumstances.

; RTM already installed for DOS3.  Couldn't have reached here if not.
	cCall	B$RTMInstall	;install the RTM interrupt vector

;
;	Check for the correct version of DOS.  BASIC .EXEs created for
;	DOS 3 can run in greater than or equal to DOS 2.10.  BASIC .EXEs
;	created for OS/2 can run in only OS/2.	The DOS or OS/2 program
;	loader will ensure that the user can't run a DOS 3 exe in OS/2 or
;	vice versa, so all we have to check here is that we aren't trying
;	to execute a DOS3 .EXE in a DOS less than 2.10.  The current dos
;	version is defined in the C startup in a variable called __osversion.
;	The high byte of this variable contains the decimal value for the
;	minor version number.  The low byte of this variable contains the
;	decimal value for the major version number of dos.  For example
;	2.10 is represented as 0A02H.
;

	MOV	AX,__osversion		; get dos version
	XCHG	AH,AL			; AH = major #, AL = minor #
	CMP	AX,020Ah		; all versions run on >= 2.10
	JB	BADDOS			; brif bad dos version

;
;	Each user module that gets linked into the executable file
;	contains a header which is ~30 bytes.  This header contains
;	information about the module.  The module code begins after
;	the header.  The header is described in addr.inc.  We need
;	to check each module to ensure that it was compiled with
;	the correct version of the compiler, and linked with the
;	appropriate runtime libraries.	A table of module start
;	addresses is emitted by the compiler into the BC_SA segment.
;
	MOV	BX,b$pBC_SAB		;offset from DS of BC_SAB seg
	MOV	AX,[BX+2]		;get user code segment
	MOV	b$ucodeseg,AX		;save user code segment
	MOV	SI,[BX] 		;get user code offset
	MOV	b$ucodeoff,SI		;save user code offset
CHECK_MODULE:
	PUSH	AX			;save segment
	OR	AX,SI			;at end of zero terminated list?
	POP	AX			;recover segment
	JZ	CHECK_MODULE_DONE	;finished if so
	ADD	BX,4			;point to next entry in module table
	MOV	ES,AX			;mov segment to seg reg (AFTER CHECK
					;so no segmentation fault will occur
	MOV	AX,ES:[SI].U_FLAG	;get compile switches
	OR	b$userflags,AX 		;update user flags

NEXT_MODULE:				; label used to save code for RTM
	MOV	SI,[BX] 		;get offset of users module
	MOV	AX,[BX+2]		;get segment of users module
	JMP	SHORT CHECK_MODULE	;check all modules in link

CHECK_MODULE_DONE:


	cCall	B$IOINI			; Init /0, OVF, 24H interrupts


	cCall	B$RTLLINI		;do low level init
	OR	AX,AX			;check for low level error
	JNZ	GenericError		;error out if LL init failed

	cCall	B$GWINI			;do low level init
	JC	BADLLI			;low level error


LLSkip: 				
	POP	ES			;recover ES
cEnd

	PAGE	
;***
;B$CHNINI - CHAIN initialization for QB interpreter.
;void pascal B$CHNINI(*sd)
;
;Purpose:
;	Added with revision [40].
;	This routine provides QBI specific CHAIN support.
;	It will call user library reinitialization, stop
;	any currently playing music, clear any arrays or
;	strings that are not in blank COMMON, reset rt
;	state variables, and reinitialize the EVENT queues.
;Entry:
;	psdCommon - non-zero indicates an sd describing the
;	QBI blank COMMON value table.
;Exit:
;	None.
;Uses:
;	Per convention.
;Exceptions:
;	None.
;****
cProc	B$CHNINI,<PUBLIC,FAR>
parmW	psdCommon
cBegin
	PUSH	b$commonfirst	;save start of compiled common block
	PUSH	b$commonlast	;save end of compiled common block
	INC	b$chaining	;we are chaining, not running
	MOV	BX,psdCommon	;get ptr to common block descriptor
	OR	BX,BX		;should we use interpreters COMMON?
	JZ	UseCompiledCommon ;brif not, use Compiled COMMON

	MOV	CX,[BX+2]	;get ptr to start of QBI common block
	MOV	b$commonfirst,CX ;save it
	ADD	CX,[BX] 	;get ptr to end of QBI common block
	MOV	b$commonlast,CX ;save it

UseCompiledCommon:
	MOV	AL,STPSND	;flag to turn off noise
	cCall	B$DONOTE	;turn off any pending music
	cCall	B$FHClear	;clear non-COMMON huge arrays
	cCall	B$NHCLR	;clear non-COMMON arrays and strings
	cCall	B$CLEAR	;clear rt state variables
	cCall	B$?EVT 	;reset event queue
	cCall	B$ULInit	;reinit user library
	MOV	b$Chaining,0	;clear chaining flag
	POP	b$commonlast	;recover end of compiled common
	POP	b$commonfirst	;recover start of compiled common
cEnd
	PAGE
;***
;B$RUNINI - "RUN time" initialization for QB4 Interpreter.
;void pascal B$RUNINI()
;
;Purpose:
;	This routine is a common runtime entry point for the interpreter.
;	It is responsible for providing the necessary initialization to
;	support the interpreter concept of restartability.  The interpreter
;	will call this routine whenever a RUN or NEW statement is executed.
;	This routine will cause all components needing initialization
;	to be re-initialized.
;
;Entry:
;	None.
;
;Exit:
;	None.
;
;Uses:
;	None.
;
;Exceptions:
;	None.
;****
cProc	B$RUNINI,<PUBLIC,FAR,FORCEFRAME>
cBegin
	PUSH	SI
	MOV	SI,OFFSET DGROUP:b$run_disp ;get "run" time dispatch table
	CALL	FAR PTR B$COMP_DISP	     ;do "RUN" time initialization
	POP	SI		
	CALL	B$ULInit	;reinitialize user library.

	MOV	AH,7Fh		; request 7Fxx7Fxx bytes more in order
	cCall	B$SETM,<AX,AX>	; to get back the maximum space for BASIC
cEnd
	SUBTTL	Component generalized dispatcher
	PAGE
;***
;B$COMP_DISP - Indirect component dispatch routine.
;void pascal B$COMP_DISP()
;
;Purpose:
;	This routine will indirectly call each routine which
;	is in the dispatch table which is passed into this
;	routine.  The first word in the dispatch table should
;	contain the number of routines to be called in the table.
;
;Entry:
;	SI	- points to first word of dispatch table.
;
;Exit:
;	None.
;
;Uses:
;	SI
;
;Exceptions:
;	None.
;****
cProc	B$COMP_DISP,<PUBLIC,FAR>
cBegin
	MOV	CX,[SI] 		;number of entries in dispatch table
	JCXZ	DISP_EXIT		;no entries, don't go into loop
DISP_LOOP:				
	LODSW				;point to first routine in table.
	PUSH	CX			;preserve count of routines to check
	CALL	WORD PTR [SI]		;dispatch to init routine (ret if
					;component is not present).
	POP	CX			;restore routine counter
	LOOP	DISP_LOOP		;continue until all routines called
DISP_EXIT:				
cEnd
	SUBTTL	RT Component "RUN" time Initilization
	PAGE
;***
;B$RTRUNINI -	RT Core component "RUN" time initialization.
;void pascal B$RTRUNINI()
;
;Purpose:
;   BC3
;   ---
;	This routine performs the runtime core component initialization that is
;	necessary whenever the runtime system is initialized, a CHAIN statement
;	is executed in the DOS 3 /O environment, or a RUN "filename" statement
;	is executed in the DOS 3 environment.  B$RTRUNINI does the following:
;		Clear user variables (share with CLEAR by calling B$RTCLR)
;		Reset b$traceon and LPR_ECHO flag. [43]
;   QB4
;   ---
;	Same as BC3.
;
;Entry:
;	None.
;
;Exit:
;	b$CtrlFlags & traceon = 0 [61]
;	User variables and runtime state variables cleared.
;
;Uses:
;	None.
;
;Exceptions:
;	None.
;****
cProc	B$RTRUNINI,<NEAR>	
cBegin
	CALL	B$RTCLR 		;Clear all user variables
	AND	b$CtrlFlags,NOT(traceon OR NoInitBcVars) ;reset trace on
					; tracking, and init BC_VARS all
					; subsequent times called.
	cCall	__fpreset		;reset numeric stack
cEnd

	SUBTTL	Interpreter helper
	PAGE
;***
;B$IRTCLR -	B$RTCLR for the interpreter
;
;Purpose:
;	Added with revision [97] to clear QuickLib variables.
;	clear items in blank common, BC_DATA, named common (except NMALLOC).
;	Re-written with revision [98].
;
;	This should not be called if chaining.  B$CHNINI will do the
;	work in that case.
;
;	This should also not be called unless common is shared between
;	the interpreter and the QuickLib.
;
;Entry:
;	None.
;Exit:
;	Variables deallocated, and owners in common or BC_VARS cleared.
;Uses:
;	Per convention.
;
;Exceptions:
;	None.
;****
cProc	B$IRTCLR,<FAR,PUBLIC>,<ES,DI>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -