📄 xlib.doc
字号:
XOR EDX,EDX
MOV AX,WORD PTR SEGADR[0]
MOV DX,WORD PTR SEGADR[2]
SHL EDX,4 ;Calculate linear address
ADD EDX,EAX
MOV AX,DX
SHR EDX,16 ;Return linear address in DX:AX
RET
LINADR ENDP
;Structure defining control block for SUMARRAY.
ARRAYDATA STRUCT
CONDCODE DWORD 0 ;Condition code
N DWORD 0 ;Number of elements to sum
ADDRESS DWORD 0 ;Address of first element
SUM DWORD 0 ;Sum of array elements
ARRAYDATA ENDS
;Real-mode interface to SUMARRAY32. Segment address of control block having
;structure ARRAYDATA should be on the stack.
SUMARRAY PROC FAR PUBLIC,
CBSEGADR:DWORD ;Control block segment address
PUSH DS
PUSHW DSEG
POP DS
XOR EAX,EAX ;Clear high words
XOR EDX,EDX
MOV AX,WORD PTR CBSEGADR[2]
MOV DX,WORD PTR CBSEGADR[0]
SHL EAX,4 ;Calculate linear address
ADD EAX,EDX
MOV CCODEPTR,EAX ;Reset condition code address
POP DS ;Pop calling DS
PUSHD OFFSET SUMARRAY32
CALL ENTERPM ;Execute SUMARRAY32 in protected
RET
SUMARRAY ENDP
CSEG ENDS
TSEG SEGMENT PARA PUBLIC USE32 'CODE'
ASSUME CS:TSEG, SS:TSEG, DS:TSEG, ES:TSEG, FS:DSEG, GS:DGROUP
14
;Sum the elements of a single precision array. Array parameters are stored
;in a control block having structure of ARRAYDATA. The linear address of the
;control block is stored at CCODEPTR. An error code of -1 is returned in the
;condition code of the control block if the number of array elements is zero
;XLIB places an error code in the control block if an FPU exception occurs
;while calculating the sum. This error code will have the FPU status word in
;the high word and the XLIB FPU error code in the low word. Observe that this
;routine will be called with DS = FLATDSEL (flat-model data descriptor) and
;FS = DSEGSEL (DSEG data descriptor).
SUMARRAY32 PROC NEAR
MOV EBX,FS:CCODEPTR ;Get control block
MOV EDX,ARRAYDATA.ADDRESS[EBX] ;Get array address
MOV ESI,ARRAYDATA.N[EBX] ;Get N
SUB ESI,1
JB NODATA ;Error: N = 0
FLDZ ;Initialize sum
SUMLOOP: FADD DWORD PTR [EDX+4*ESI]
SUB ESI,1
JAE SUMLOOP
FSTP ARRAYDATA.SUM[EBX] ;Save sum
RET
NODATA: MOV ARRAYDATA.CONDCODE[EBX],-1 ;Record error code
RET
SUMARRAY32 ENDP
TSEG ENDS
END
+++++++++++++++++++++
+ BASIC MAIN MODULE +
+++++++++++++++++++++
'The following Microsoft BASIC 7.0 program should be linked with the above
'library. The BASIC program first initializes XLIB. Next, it creates a
'single precision array. A control block for SUMARRAY is then constructed
'and the call to SUMARRAY is executed. Finally, the condition code in the
'control block is inspected and results are printed.
DEFINT A-Z
'Declare XLIB procedures
DECLARE FUNCTION XLIBMEMREQ& ()
DECLARE FUNCTION INITXLIB& ()
DECLARE FUNCTION XLIBCONFIG% ()
'Declare procedures in the library linked with XLIB
DECLARE FUNCTION LINADR& (SEG VARIABLE AS ANY)
DECLARE SUB SUMARRAY (SEG VARIABLE AS ANY)
15
'Structure for the control block
TYPE ARRAYDATA
CONDCODE AS LONG 'Location to receive any error codes
N AS LONG 'Number of elements to be summed
ADDRESS AS LONG 'Linear address of the array
SUM AS SINGLE 'Location for array sum
END TYPE
'Check XLIBCONFIG to see if XLIB has already been initialized. If not then
'call XLIBMEMREQ to find amount of conventional memory needed by XLIB and
'release at least this amount with the BASIC SETMEM function. XLIBMEMREQ
'returns with sign bit of DX set if an error occurred. The error is then
'identified by AX. XLIB will not be terminated upon completion of this
'program in the Microsoft QBX environment; therefore, initialization is
'required only once within the environment.
IF XLIBCONFIG = 0 THEN
TEMP& = XLIBMEMREQ
IF TEMP& >= 0& THEN
IF TEMP& > 0 THEN TEMP& = SETMEM(-TEMP& - 16&)
TEMP& = INITXLIB 'INITXLIB error code returned in TEMP&
ELSE
TEMP& = TEMP& AND &H7FFFFFFF 'Mask sign bit to leave error code only
END IF
IF TEMP& THEN
PRINT "Library initialization error: "; HEX$(TEMP&)
END
END IF
END IF
DIM A(100) AS SINGLE
DIM AD AS ARRAYDATA
FOR I = 0 TO 100 'Assign numbers to array
A(I) = I
NEXT I
AD.CONDCODE = 0& 'Clear the error code
AD.N = 50& 'Sum first 50 elements
AD.ADDRESS = LINADR(A(0)) 'Calculate and record linear address of A(0)
CALL SUMARRAY(AD)
IF AD.CONDCODE THEN
PRINT "Error: ";HEX$(AD.CONDCODE)
ELSE
PRINT "Sum: ";AD.SUM 'Should equal 1225
ENDIF
END
-----------------------------------------------------------------------------
16
Appendix A: Summary of XLIB Public Data
The following is a summary of most public symbols located in the XLIB
data segment DSEG. This summary excludes the symbols presented in tables one
through three. All XLIB symbols conform to the Pascal naming convention.
Symbols: CSEGVAL, TSEGVAL, DSEGVAL, DGROUPVAL (Segment Values)
Symbol Types: WORD
Default Settings: CSEG, TSEG, DSEG, DGROUP
Descriptions: These are memory locations initialized to the respective
segment values. Code in TSEG should not contain segment constants since DOS
may not be able to handle them in relocation fixups. Read these locations to
get segment values. User segments should be handled the same way.
Symbols: CCODEPTR/CCODE (Condition Code Pointer/Condition Code)
Symbol Types: DWORD/DWORD
Default Settings: CCODEPTR = linear address of CCODE. CCODE = 0.
Descriptions: XLIB interrupt handlers will place flags in the condition code
to signal the occurrence of the interrupt. CCODEPTR initially contains the
linear address of CCODE. CCODEPTR may be changed by the user, but must point
to a DWORD in conventional memory.
Symbol: FPUCW (Floating Point Unit Control Word)
Symbol Type: WORD
Default Setting: 0332H
Description: FPUCW is optionally loaded to the FPU control word by CALLPM and
ENTERPM. The default sets rounding control to nearest, precision control to
64 bits, and unmasks exceptions for: overflow, zero divide, and invalid
operations. Exceptions for underflow, precision, and denormalized operations
are masked, and are therefore handled internally by the FPU. Set bit 2 of
OFLAGS to enable FPU save/restore and load of FPUCW.
Symbol: HOTKEY (Hot Key)
Symbol Type: WORD
Default Setting: 022EH
Description: HOTKEY specifies the hot key for the keyboard interrupt handler.
The low byte of HOTKEY specifies the scan code for the key. The upper byte
specifies the state of the shift keys. Bit 8 specifies SHIFT; bit 9 specifies
CTLR, and bit 10 specifies ALT. Set bits mean that the designated key must be
pressed. All other bits are ignored. The default hot key is CTRL C. Bypass
hot key detection by setting HOTKEY = 0.
Symbol: IFLAGS (Initialization Flags)
Symbol Type: WORD
Default Setting: 0
Description: IFLAGS is used by INITXLIB to control the initialization
process. Bit 0 of IFLAGS determines DPMI/VCPI priority in the event that both
interfaces are present. If this bit is clear then DPMI will be installed in
such cases. The other bits are reserved.
17
Symbols: IRQ0INTNO/IRQ8INTNO (IRQ X Interrupt Number)
Symbol Types: BYTE/BYTE
Default Settings: 08H/70H
Descriptions: Specifies the interrupt number assigned to IRQ X. IRQs 0
through 7 and IRQs 8 through 15 are assigned to contiguous interrupt numbers.
These locations are valid only after call to INITXLIB.
Symbol: OFLAGS (Operation Flags)
Symbol Type: WORD
Default Setting: 0
Description: OFLAGS controls post-initialization operation of XLIB.
Setting bit 0 disables XLIB interrupt handlers. XLIB sets this bit only at
calls to CALLPM and ENTERPM and then clears the bit upon return.
Setting bit 1 causes all FPU interrupts to be cascaded to the inherited
real-mode interrupt handler. This bit is automatically set if no FPU is
present.
Setting bit 2 enables FPU save/restore in CALLPM and ENTERPM. Setting this
bit also causes load of FPUCW to the FPU control word.
18
Appendix B: Summary of XLIB Public Procedures
The following is a summary of all XLIB public procedures. All procedures
entered from real mode are in CSEG and have far returns. All protected-mode
procedures are in TSEG and have 32-bit near returns. All procedures conform
to the Pascal naming and calling convention. All XLIB procedures may be
called with interrupts enabled and will return with interrupts enabled
provided that they were enabled upon call.
Initialization Routines
XLIBMEMREQ (XLIB Memory Requirements)
Purpose: Find XLIB conventional memory requirements.
CPU Mode: Real
Registers at Call: None
Return Registers:
Sign bit of DX clear if successful. Memory requirements in bytes returned
in DX:AX. DX:AX is upward adjusted to an integer multiple of 16.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -