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

📄 vidcode.inc

📁 MMURTL(tm) Computer Operating System Ver x0.8, source code.
💻 INC
📖 第 1 页 / 共 2 页
字号:
;   MMURTL Operating System Source Code
;   Copyright 1991,1992,1993, Richard A. Burgess
;   ALL RIGHTS RESERVED
;   Version x0.8

;This module contains ALL Video code
;    (along with EdLine for lack of a better place)
;
;This module supports MMURTL's Virtual Text Video.
;All video calls are based on the video information in the job's
;Job Control Block.
;
;Virtual video buffers allow a job to output data even when it is
;not assigned to the real video display buffer.
;
;The call SetVidOwner is the key. It swaps virtual buffers for the real one
;and changes the current pointer in that job's JCB.  It also updates
;the cursor in the correct place on entry.
;
; The following calls are currently implemented:
;
;------------------------------
;GetVidOwner(pdJobNumRet)
;
; Desc: This returns the Job Number that currently has active video
; screen.
;
;------------------------------
;SetVidOwner(ddJobNum)
;
; Desc: This selects the screen that you see.  This call is used
; by the monitor in conjunction with the SetKbdOwner call to change
; who gets the keystrokes and video (should be the same app).
; The internal debugger is the only code that will use this call
; and not move the keyboard also.  It has it's own keyboard code
; (else how could it debug the real keyboard code??)
;
; Params:
;	ddJobNum is the new Job to get the active screen
;   (the one to be displayed)
;------------------------------
;SetNormVid(dAttr)
;
; Desc: This selects the normal background attribute and fill char
; used by ClrScr and ScrollVid on the screen.
;
; Params:
;	dCharAttr is the Character and aAttr values used in
;	standard video operation on the current screen
;
;------------------------------
;GetNormVid(pVidRet)
;
; Desc: This returns the value the normal screen attribute
; used by ClrScr and ScrollVid on the screen.
;
; Params:
;	pVidRet points to the character where you want the NormVid
;	attribute returned.
;
;------------------------------
;ClrScr ();
;
; Desc:
;	This clears the screen for the executing job. It may or may not
;	be the one you are viewing...
;
;------------------------------
;TTYOut (pTextOut, ddTextOut, ddAttrib)
;
;   Desc: This places characters on the screen in a TTY fashion at the
;   X & Y coordinates that are in effect for that screen.
;   The following characters in the stream are interpreted as follows:
;   Hex   Action
;   0A	  Line Feed
;	  The cursor (next active character placement) will be on the
;	  following line at column 0.  If this line is below the bottom
;	  of the screen, the entire screen will be scrolled up on line,
;	  the bottom line will be blanked, and the cursor will be placed
;	  on the last line in the first column.
;   0D	  Carriage Return
;	  The Cursor will be moved to column zero on the current line.
;   08	  BackSpace - The cursor will be moved one column to the left.
;	  If already at column 0, Backspace will have no effect.
;	  The backspace is non-destructive (no chars are changed)
;   7F	  Delete
;	  The character under the cursor will be deleted (blanked). The
;	  Cursor position will not change.
;   0C	  Form Feed
;	  The screen will be blanked and the cursor will be placed at
;	  position 0,0.
;   07	  Bell
;	  The speaker will produce a short tone.
;   1B	  Escape character
;	  Currently ignored, but will eventually lead into video
;	  escape sequences.
;
;   pTextOut is a NEAR Ptr to the text.
;   ddTextOut is the number of chars of text.
;   ddAttrib is the attribute/Color you want.
;
;------------------------------
;PutVidChars(ddCol,ddLine,pChars,sChars,ddAttrib)
;
; Desc: This places characters on the screen without affecting
;   the current TTY coordinates or the TTY data.  It is independent
;   of the current video "Stream."
;
; Params:
;   ddCol is the column to start on (0-79)
;   ddLine is the line (0-24)
;   pChars is a pointer the text to be displayed
;   sChars is the number of chars
;   ddAtrib is the color/attribute to use during display
;    which applies to all of the characters on this
;    call to PutVidChars.
;------------------------------
;GetVidChar(ddCol,ddLine,pCharRet,pAttrRet)
;
; Desc: This returns the current character and attribute
;	from the screen coordinates you specify.
;
; Params:
;   ddCol is the column to start on (0-79)
;   ddLine is the line (0-24)
;   pCharRet is a pointer where you want the character returned
;   pAttrRet is a pointer where you want the attribute returned
;------------------------------
;PutVidAttrs(ddCol,ddLine,sChars,dAttr)
;
; Desc: This sets screen colors (attrs) for the without affecting
;   the current TTY coordinates or the character data. It is independent
;   of the current video "Stream."
;
; Params:
;   ddCol is the column to start on (0-79)
;   ddLine is the line (0-24)
;   sChars is the number of char spaces to place dAttr
;   dAttr is the color/attribute to fill the character spaces with
;
;------------------------------
;ScrollVid(ddULCol,ddULline,nddCols,nddLines, ddfUp)
;
; Desc: This scrolls the described square area on the screen either
;   UP or DOWN one line.  If ddfUp is NON-ZERO the scroll will be UP.
;   The line left blank is filled with NormAttr from JCB.
; Parms:
;   ddULCol is the UPERR LEFT column to start on (0-79)
;   ddULLine is the UPPER LEFT line (0-24)
;   nddCols is the number of columns to be scrolled.
;   nddLines is the count of lines to be scrolled.
;   ddfUp is NON-ZERO to cause the scroll to be up (vise down).
;
;   If you want to scroll the entire screen UP one line, the
;   params would be  ScrollVid(VidNum, 0,0,80,25,1).
;   In this case the top line is lost (not really scrolled),
;   and the bottom line would be blanked. Infact, if you specified
;   (Vidnum, 0,1,80,24,1) you would get the same results.
;
;------------------------------
;SetXY(NewX,NewY)
; Desc: Position VGA cursor (Text mode) to the X & Y position.
;
; Params:
;   NewX is the new horizontal cursor postion
;   NewY is the new vertical cursor position
;
;------------------------------
;GetXY(pXRet,pYRet)
; Desc: Returns the current X & Y position for your job.
;
; Params:
;   pXRet is a ptr where you want the current horizontal cursor postion
;   pYRet is a ptr where you want the current vertical cursor position

;============================================================================
; BEGIN INTERNAL CODE FOR VIDEO
;============================================================================
;
;InitVideo makes Video Screen 0 the default screen. That
;makes the VGATextBase address 0B8000h
;
InitVideo:
		MOV AL, CRTCAddHi	 	;Index of hi byte
		MOV DX, CRTCPort1	 	;Index Port
		OUT DX, AL
		MOV AL, CRTC0C			;hi byte value to send
		MOV DX, CRTCPort2	 	;Data Port
		OUT DX, AL
		;
		MOV AL, CRTCAddLo	 	;Index of lo byte
		MOV DX, CRTCPort1	 	;Index Port
		OUT DX, AL
		MOV AL, CRTC0D			;lo byte value to send
		MOV DX, CRTCPort2	 	;Data Port
		OUT DX, AL
		RETN
;
;============================================================================
; BEGIN PUBLIC CODE FOR VIDEO
;============================================================================
;
;============================================================================
; SetVidOwner - Make a new a screen actively displayed.
; EAX Returns NON-Zero if JOB number is invalid

ddJobVidCV	EQU DWORD PTR [EBP+12]

_SetVidOwner PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		MOV EAX, ddJobVidCV     ;
		CMP EAX, ddVidOwner		;Already own it?
		JNE ChgVid01			;No
		XOR EAX, EAX			;Yes
		JMP ChgVidDone
ChgVid01:
		CALL GetpJCB			;Leaves ptr to new vid JCB in EAX
		CMP [EAX.pVidMem] ,0	;Got valid video memory???
		JNE ChgVid02			;Yes
		MOV EAX, ErcVidNum		;NO! Give em an error!
		JMP ChgVidDone
ChgVid02:
		;Save data on screen to CURRENT job's pVirtVid
		MOV EAX, ddVidOwner
		CALL GetpJCB
		PUSH VGATextBase		;Source
		MOV EBX, [EAX.pVirtVid]	;Destination
		PUSH EBX
		PUSH 4000				;Size of video
		CALL FAR PTR _CopyData	;Do it!

		;Make pVidMem same as pVirtVid for CURRENT OWNER
		MOV EAX, ddVidOwner
		CALL GetpJCB			;Leaves ptr to new vid JCB in EAX
		MOV EBX, [EAX.pVirtVid]
		MOV [EAX.pVidMem], EBX

		;Update current video owner to NEW owner

		MOV EAX, ddJobVidCV     ;
		MOV ddVidOwner, EAX

		;Copy in Data from new pVirtVid

		MOV EAX, ddVidOwner
		CALL GetpJCB
		MOV EBX, [EAX.pVirtVid]	;Source
		PUSH EBX
		PUSH VGATextBase		;Destination
		PUSH 4000				;Size of video
		CALL FAR PTR _CopyData	;Do it!

		;Make new pVidMem real video screen for new owner

		MOV EAX, ddVidOwner
		CALL GetpJCB
		MOV EBX, VGATextBase
		MOV [EAX.pVidMem], EBX

		;Set Cursor position

		MOV EAX, ddVidOwner
		CALL GetpJCB
		MOV ECX, EAX
		MOV EBX, [ECX.CrntX]	;Get current X for new screen
		MOV EAX, [EBX.CrntY]	;Current Y
		CALL HardXY				;Set it up
		XOR EAX, EAX			;No Error
ChgVidDone:
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 4
_SetVidOwner ENDP

;============================================================================
; SetNormVid - Sets the normal video attribute (color) used in
; ClrScr, EditLine, and ScrollVid.
; EAX Returns Zero (No Error)

ddNormVid	EQU DWORD PTR [EBP+12]

_SetNormVid PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		CALL GetpCrntJCB		;pJCB -> EAX
		MOV EBX, ddNormVid      ;
		MOV [EAX.NormAttr], EBX	;
		XOR EAX, EAX
		POP EBP                 ;
		RETF 4
_SetNormVid ENDP

;============================================================================
; GetNormVid - Returns the normal video attribute (color) used in
; ClrScr, EditLine, and ScrollVid.
; EAX Returns Zero (No Error)

pdNormVidRet EQU DWORD PTR [EBP+12]

_GetNormVid PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		CALL GetpCrntJCB		;pJCB -> EAX
		MOV EBX, [EAX.NormAttr]	;
		MOV ESI, pdNormVidRet	;
		MOV [ESI], BL		    ;
		XOR EAX, EAX
		POP EBP                 ;
		RETF 4
_GetNormVid ENDP

;============================================================================
; GetVidOwner - Returns the Job number of current active video
;  number to the caller.
;=============================================================================

pVidNumRet	EQU DWORD PTR [EBP+12]

_GetVidOwner PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		MOV ESI, pVidNumRet		;
		MOV EAX, ddVidOwner		;
		MOV [ESI], EAX			;
		XOR EAX, EAX			; no error obviously
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 4
_GetVidOwner ENDP

;=============================================================================
; Clear caller's video screen (Use Space and Attr from JCB NormAttr)
;=============================================================================
;
_ClrScr	PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		CALL GetpCrntJCB		;Leaves ptr to current JCB in EAX
		MOV EBX, EAX
		MOV EDI,[EBX.pVidMem]	;EDI points to his video memory
		MOV EAX, [EBX.NormAttr]	;Attr
		SHL EAX, 8				;
		MOV AL, 20h				;
		MOV DX, AX
		SHL EAX, 16
		MOV AX, DX				;Fill Char & Attr
		MOV ECX,0400h
		CLD
		REP STOSD
		PUSH 0
		PUSH 0
		CALL FAR PTR _SetXY	;Erc in EAX on Return
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF
_ClrScr		ENDP

;=============================================================================
; TTYOut:
;=============================================================================

pTextOut	EQU DWORD PTR [EBP+20]
sTextOut	EQU DWORD PTR [EBP+16]
dAttrText	EQU DWORD PTR [EBP+12]

DataByte	EQU BYTE PTR [ECX]

_TTYOut	PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		CALL GetpCrntJCB		;Leaves ptr to current JCB in EAX
		MOV EBX, EAX
		MOV EAX, sTextOut		;make sure count isn't null
		OR EAX, EAX
		JZ TTYDone

TTY00:
		MOV EAX,[EBX.CrntX]		; EAX has CrntX (col)
		MOV EDX,[EBX.CrntY]		; EDX has CrntY (line)
		MOV ECX,pTextOut

		CMP DataByte,0Ah		; LF?
		JNE TTY02
		INC EDX
		CMP EDX,[EBX.nLines]	; Equal to or past the bottom?
		JB  TTY06				; No
		JMP TTYScr				; Yes, goto scroll
TTY02:
		CMP DataByte,0Dh		; CR?
		JNE TTY03
		MOV EAX,0
		JMP TTY06
TTY03:
		CMP DataByte,08h		; BackSpace?
		JNE TTY04
		CMP EAX,0
		JE  TTY04
		DEC EAX
		JMP TTY06
TTY04:
		PUSH EBX				;Save pointer to VCB

		PUSH EAX				;X (Param 1)
		PUSH EDX				;Y (Param 2)
		PUSH ECX				;pointer to text char (Param3)
		PUSH 1					;Param 4 (nchars)
		MOV ECX,dAttrText		;
		PUSH ECX				;Param 5
		CALL FAR PTR _PutVidChars	;
		POP EBX 				;restore ptr to VCB
		CMP EAX, 0
		JNE TTYDone
		MOV EAX, [EBX.CrntX]
		MOV EDX, [EBX.CrntY]
		INC EAX 				;Next column
		CMP EAX,[EBX.nCols]
		JNE TTY06				;Make cursor follow
		MOV EAX,0
		INC EDX
		CMP EDX,[EBX.nLines]	; past the bottom?
		JNE TTY06				; No - goto 06 else fall thru

TTYScr:
	 	DEC EDX 				; back up one line
		PUSH EAX				;Save registers (scroll eats em)
		PUSH EBX
		PUSH ECX
		PUSH EDX

		PUSH 0
		PUSH 0
		PUSH 80
		PUSH 25
		PUSH 1					;fUP (non zero)
		CALL FAR PTR _ScrollVid	;Ignore error
		POP EDX 				;restore registers
		POP ECX
		POP EBX
		POP EAX 				;Fall thru to

TTY06:
		PUSH EBX				;save ptr to pJCB

		PUSH EAX
		PUSH EDX
		CALL FAR PTR _SetXY

		POP EBX 				;Restore ptr to VCB
		CMP EAX, 0
		JNE TTYDone
		DEC sTextOut
		JZ TTYDone
		INC pTextOut
		JMP TTY00				; Go back for next char
TTYDone:
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 12
_TTYOut	ENDP



;=============================================================================
; PutVidAttrs:
; Desc: This sets screen colors (attrs) for the without affecting
;   the current TTY coordinates or the character data. It is independent
;   of the current video "Stream."
;
; Params:
;   ddCol is the column to start on (0-79)
;   ddLine is the line (0-24)
;   sChars is the number of char spaces to place dAttr
;   dAttr is the color/attribute to fill the character spaces with
;
; Start Position in screen memory is (Line * 80 + (Column*2))
; pass Char, then Color, pass char, then color etc... DO NOT EXCEED 2000!
; Needs to be fixed to tell if ECX + sDDChars will go off screen...
;
;=============================================================================

oADDX		EQU DWORD PTR [EBP+24] ;Param 1 COLUMN
oADDY		EQU DWORD PTR [EBP+20] ;Param 2 LINE
sADDChars	EQU DWORD PTR [EBP+16] ;Param 3 sChars
sADDColor	EQU DWORD PTR [EBP+12] ;Param 4 Attr

_PutVidAttrs	PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;

		CALL GetpCrntJCB		;Leaves ptr to current JCB in EAX
		MOV EBX, EAX

		MOV EDI, [EBX.pVidMem]	;point to this VCBs video memory
		MOV EBX,oADDx			;x Position
		SHL EBX,1				;Times 2
		MOV EAX,oADDy			;y Position
		MOV ECX,0A0h			;Times 160 (char/attrs per line)
		MUL ECX					;Times nColumns
		ADD EAX,EBX
		CMP EAX,0F9Eh			;Last legal posn on screen
		JBE PutAttrs00
		MOV EAX, ErcVidParam
		JMP PcADone
PutAttrs00:
		MOV ECX,sADDChars
		OR ECX, ECX
		JZ PcADone
		ADD EDI,EAX
		MOV EAX,sADDColor
		CLD
pcAMore:

⌨️ 快捷键说明

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