home *** CD-ROM | disk | FTP | other *** search
-
- ; TechnoJocks Turbo Toolkit v4.0
- ; Display Routines : included in UNIT FastTTT
- ; Copyright (c) R. D. Ainsbury 1986, 1987
- ;
- ; Credits : Marshall Brain (the Fastwrite inventor)
- ; Brian Foley (the Fastwrite optimizer)
-
- ;****************************************************** Equates
-
- Mono = 0
- CGA = 1
- EGA = 2
- MCGA = 3
- VGA = 4
-
- ;****************************************************** Data
-
- DATA SEGMENT BYTE PUBLIC
-
- EXTRN BaseOfScreen : WORD ;Pascal variables
- EXTRN WaitForRetrace : BYTE
-
- CurrentMode DB ? ;local variables
- Display DB ?
-
- DATA ENDS
-
- ;****************************************************** Code
-
- CODE SEGMENT BYTE PUBLIC
-
- ASSUME CS:CODE,DS:DATA
-
- PUBLIC FastWrite, PlainWrite
- PUBLIC CurrentDisplay, CurrentVideoMode
- ;****************************************************** CalcOffset
-
- ;Calculates offset in video memory corresponding to Row,Column
- ;On entry, CH has Row, BX has Column (both 1-based)
- ;On exit, ES:DI points to proper address in video memory, AX = 0
-
- CalcOffset PROC NEAR
-
- XOR AX,AX ;AX = 0
- MOV CL,AL ;CL = 0
- MOV BH,AL ;BH = 0
- DEC CH ;Row (in CH) to 0..24 range
- SHR CX,1 ;CX = Row * 128
- MOV DI,CX ;Store in DI
- SHR DI,1 ;DI = Row * 64
- SHR DI,1 ;DI = Row * 32
- ADD DI,CX ;DI = (Row * 160)
- DEC BX ;Col (in BX) to 0..79 range
- SHL BX,1 ;Account for attribute bytes
- ADD DI,BX ;DI = (Row * 160) + (Col * 2)
- MOV ES,BaseOfScreen ;ES:DI points to BaseOfScreen:Row,Col
- RET ;Return
-
- CalcOffset ENDP
-
- ;****************************************************** FastWrite
-
- ;procedure FastWrite(Col, Row, Attr:byte; St : String);
- ;Fast write string St to screen in color Attr at coords Col, Row
-
- ;equates for parameters:
- FWSt EQU DWORD PTR [BP+6]
- FWAttr EQU BYTE PTR [BP+10]
- FWRow EQU BYTE PTR [BP+12]
- FWCol EQU BYTE PTR [BP+14]
-
- FastWrite PROC FAR
-
- PUSH BP ;Save BP
- MOV BP,SP ;Set up stack frame
- PUSH DS ;Save DS
- MOV CH,FWRow ;CH = Row
- MOV BL,FWCol ;BL = Column
- CALL CalcOffset ;Call routine to calculate offset
- MOV CL,WaitForRetrace ;Grab this before changing DS
- LDS SI,FWSt ;DS:SI points to St[0]
- CLD ;Set direction to forward
- LODSB ;AX = Length(St); DS:SI -> St[1]
- XCHG AX,CX ;CX = Length; AL = WaitForRetrace
- JCXZ FWExit ;If string empty, exit
- MOV AH,FWAttr ;AH = Attribute
- RCR AL,1 ;If WaitForRetrace is False...
- JNC FWMono ; use "FWMono" routine
- MOV DX,03DAh ;Point DX to CGA status port
- FWGetNext:
- LODSB ;Load next character into AL
- ; AH already has Attr
- MOV BX,AX ;Store video word in BX
- CLI ;No interrupts now
- FWWaitNoH:
- IN AL,DX ;Get 6845 status
- TEST AL,8 ;Vertical retrace in progress?
- JNZ FWStore ;If so, go
- RCR AL,1 ;Else, wait for end of
- JC FWWaitNoH ; horizontal retrace
- FWWaitH:
- IN AL,DX ;Get 6845 status again
- RCR AL,1 ;Wait for horizontal
- JNC FWWaitH ; retrace
- FWStore:
- MOV AX,BX ;Move word back to AX...
- STOSW ; and then to screen
- STI ;Allow interrupts!
- LOOP FWGetNext ;Get next character
- JMP FWExit ;Done
- FWMono:
- LODSB ;Load next character into AL
- ; AH already has Attr
- STOSW ;Move video word into place
- LOOP FWMono ;Get next character
- FWExit:
- POP DS ;Restore DS
- MOV SP,BP ;Restore SP
- POP BP ;Restore BP
- RET 10 ;Remove parameters and return
-
- FastWrite ENDP
-
- ;****************************************************** PlainWrite
-
- ;procedure PlainWrite(Col, Row:byte; St : String);
- ;Megafast write string St to the screen at coords Col,Row
-
- ;equates for parameters:
- PWSt EQU DWORD PTR [BP+6]
- PWRow EQU BYTE PTR [BP+10]
- PWCol EQU BYTE PTR [BP+12]
-
- PlainWrite PROC FAR
-
- PUSH BP ;Save BP
- MOV BP,SP ;Set up stack frame
- PUSH DS ;Save DS
- MOV CH,PWRow ;CH = Row
- MOV BL,PWCol ;BL = Column
- CALL CalcOffset ;Call routine to calculate offset
- MOV CL,WaitForRetrace ;Grab this before changing DS
- LDS SI,PWSt ;DS:SI points to St[0]
- CLD ;Set direction to forward
- LODSB ;AX = Length(St); DS:SI -> St[1]
- XCHG AX,CX ;CX = Length; AL = Wait
- JCXZ PWExit ;If string empty, exit
- RCR AL,1 ;If WaitForRetrace is False...
- JNC PWNoWait ; use PWNoWait routine
- MOV DX,03DAh ;Point DX to CGA status port
- PWGetNext:
- LODSB ;Load next character into AL
- MOV AH,AL ;Store char in AH
- CLI ;No interrupts now
- PWWaitNoH:
- IN AL,DX ;Get 6845 status
- TEST AL,8 ;Check for vertical retrace
- JNZ PWStore ; In progress? go
- RCR AL,1 ;Else, wait for end of
- JC PWWaitNoH ; horizontal retrace
- PWWaitH:
- IN AL,DX ;Get 6845 status again
- RCR AL,1 ;Wait for horizontal
- JNC PWWaitH ; retrace
- PWStore:
- MOV AL,AH ;Move char back to AL...
- STOSB ; and then to screen
- STI ;Allow interrupts
- INC DI ;Skip attribute bytes
- LOOP PWGetNext ;Get next character
- JMP PWExit ;Done
- PWNoWait:
- MOVSB ;Move character to screen
- INC DI ;Skip attribute bytes
- LOOP PWNoWait ;Get next character
- PWExit:
- POP DS ;Restore DS
- MOV SP,BP ;Restore SP
- POP BP ;Restore BP
- RET 8 ;Remove parameters and return
-
- PlainWrite ENDP
-
- ;****************************************************** CurrentModePrim
-
- ;Returns current video mode in AL
-
- CurrentModePrim PROC NEAR
-
- MOV AH,0Fh ;Get video mode function
- INT 10h ;Call BIOS
- MOV CurrentMode,AL ;Save it
- RET ;Return
-
- CurrentModePrim ENDP
-
- ;****************************************************** CurrentDisplay
-
- ;function CurrentDisplay : DisplayType;
- ;Returns type of the currently active display.
-
- JunkValue = 0FFFFh
-
- CurrentDisplay PROC FAR
-
- ;get the current video mode
- CALL CurrentModePrim ;Call primitive routine
-
- ;test for VGA
- MOV Display,VGA ;Assume VGA
- MOV CX,JunkValue ;Load CX with junk value
- MOV AX,1C00h ;Save/Restore video state
- INT 10h
- CMP AL,1Ch ;AL = $1C signals valid call
- JE CDexit ;Adapter type known
-
- ;test for MCGA
- MOV Display,MCGA ;Assume MCGA
- MOV BL,32h ;Choose Enable
- MOV AX,1200h ;Enable/Disable video addressing
- INT 10h
- CMP AL,12h ;AL = $12 signals valid call
- JE CDexit ;Adapter type known
-
- ;test for EGA
- MOV Display,EGA ;Assume EGA
- MOV BX,0FF10h ;Return EGA information
- MOV CX,JunkValue ;Load CX with junk value
- MOV AX,1200h ;Alternate function select
- INT 10h
- XOR AL,AL ;AL = 0
- CMP CX,JunkValue ;CX unchanged?
- JE CDplain ;If so, not an EGA
- CMP BH,1 ;BH should be 0 or 1
- JA CDplain ;Mono or CGA if it isn't
-
- ;See if EGA is the active display
- CMP BH,1 ;mono display?
- JE CDegaMono ;If so, use mono check
- CMP CurrentMode,7 ;In mono mode?
- JE CDplain ;If so, we're not on the EGA
- JMP SHORT CDexit ;else, it's an EGA
-
- CDegaMono:
- CMP CurrentMode,7 ;Current mode = 7?
- JNE CDplain ;Exit if not
-
- CDexit:
- MOV AL,Display ;set return value
- RET ;Return
-
- CDplain:
- MOV Display,CGA ;Assume CGA
- CMP CurrentMode,7 ;Mono mode
- JNE CDexit ;Done if not
- MOV Display,Mono ;Else, Mono
- JMP SHORT CDexit ;Done
-
- CurrentDisplay ENDP
-
- ;****************************************************** CurrentVideoMode
-
- ;function CurrentVideoMode : Byte;
- ;Returns current video mode in AL
-
- CurrentVideoMode PROC FAR
-
- CALL CurrentModePrim ;Call primitive routine
- RET ;Return
-
- CurrentVideoMode ENDP
-
- CODE ENDS
-
- END