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

📄 vidcode.inc

📁 MMURTL(tm) Computer Operating System Ver x0.8, source code.
💻 INC
📖 第 1 页 / 共 2 页
字号:
		INC EDI					;Pass the char value
		STOSB					;Move Color in
		LOOP pcAMore
		XOR EAX, EAX			;No Error!
pcADone:
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 16
_PutVidAttrs  ENDP

;=============================================================================
; PutVidChars:
; This Places characters on the VGA Character Screen in the XY Coords
;  Params
;  1) DD X (Column 0-79)
;  2) DD Y (Line 0-24)
;  3) DD Near Ptr (relative to DS) of string
;  4) DD Size of String
;  5) DD (of which the low order byte is the Color)
;
; Start Position in screen memory is (Line * 80 + (Column*2))
; Put Char, then Color, then char, then color etc... DO NOT EXCEED 2000!
; Needs to be fixed to tell if ECX + sDDChars will go off screen...
;
;=============================================================================

oDDX		EQU DWORD PTR [EBP+28] ;Param 1 COLUMN
oDDY		EQU DWORD PTR [EBP+24] ;Param 2 LINE
pDDChars	EQU DWORD PTR [EBP+20] ;Param 3 pChars
sDDChars	EQU DWORD PTR [EBP+16] ;Param 4 sChars
sDDColor	EQU DWORD PTR [EBP+12] ;Param 5 Attr

PUBLIC _PutVidChars
_PutVidChars	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,oDDx
		SHL EBX,1				;Times 2
		MOV EAX,oDDy
		MOV ECX,0A0h			;Times 160
		MUL ECX					;Times nColumns
		ADD EAX,EBX
		CMP EAX,0F9Eh			;Last legal posn on screen
		JBE PutChars00
		MOV EAX, ErcVidParam
		JMP PcDone
PutChars00:
		MOV ECX,sDDChars
		OR ECX, ECX
		JZ PcDone
		MOV ESI,pDDChars
		ADD EDI,EAX
		MOV EAX,sDDColor
		CLD
pcMore:
		MOVSB					;Move Char in
		STOSB					;Move Color in
		LOOP pcMore
		XOR EAX, EAX			;No Error!
pcDone:
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 20
_PutVidChars  ENDP

;=============================================================================
;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
;

oGDDX		EQU DWORD PTR [EBP+24] ;Param 1 COLUMN
oGDDY		EQU DWORD PTR [EBP+20] ;Param 2 LINE
pGDDCRet	EQU DWORD PTR [EBP+16] ;Param 3 pCharRet
pGDDARet	EQU DWORD PTR [EBP+12] ;Param 4 pAttrRet

_GetVidChar	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,oGDDx
		SHL EBX,1				;Times 2
		MOV EAX,oGDDy
		MOV ECX,0A0h			;Times 160
		MUL ECX					;Times nColumns
		ADD EAX,EBX
		CMP EAX,0F9Eh			;Last legal posn on screen
		JBE GetChar00
		MOV EAX, ErcVidParam
		JMP PcGDone
GetChar00:
		ADD EDI,EAX				;EDI now points to char
		MOV ESI,pGDDCRet
		MOV AL, [EDI]
		MOV [ESI], AL			;Give them the char
		INC EDI					;Move to Attr
		MOV ESI,pGDDARet
		MOV AL, [EDI]
		MOV [ESI], AL			;Give them the Attr
		XOR EAX, EAX			;No Error!
pcGDone:
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 20
_GetVidChar  ENDP
;=============================================================================
; ScrollVid:
; This scrolls the defined area up or down one line.
;  Params
;  1) Upper Left column X (Column 0-79)
;  2) Upper Left line Y (Line 0-24)
;  3) nCols to scroll
;  4) nLines to scroll
;  5) TRUE for up (any NON zero QUAD)
;
;  We check all params for validity. ErcVidParam is returned if one is
;  invalid.
;=============================================================================

oULX		EQU DWORD PTR [EBP+28] ;Param 1 COLUMN
oULY		EQU DWORD PTR [EBP+24] ;Param 2 LINE
nddCols 	EQU DWORD PTR [EBP+20] ;Param 3 pChars
nddLines	EQU DWORD PTR [EBP+16] ;Param 4 sChars
ddfUP		EQU DWORD PTR [EBP+12] ;Param 5 Attr

_ScrollVid	PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		CALL GetpCrntJCB		;Leaves ptr to current JCB in EAX
		MOV EBX, EAX			;Save pJCB & use in EBX
		MOV EAX, oULX
		CMP EAX, 79
		JA svErcExit
		ADD EAX, nddCols
		CMP EAX, 80
		JA svErcExit
		MOV EAX, oULY
		CMP EAX, 24
		JA svErcExit
		ADD EAX, nddLines
		CMP EAX, 25
		JA svErcExit

		CMP ddfUP, 0		;Scroll UP?
		JNE svUP0			;Yes... Scroll UP!

;Scroll DOWN begins

		MOV EAX, oULY		;First line
		ADD EAX, nddLines	;Last line
		MOV ECX, 160
		MUL ECX 				;times nBytes per line
		MOV EDI, [EBX.pVidMem]	;EDI points to video memory 0,0
		MOV	EDX, EBX			;Save pJCB
		ADD EDI, EAX			;EDI is ptr to 1st dest line
		ADD EDI, oULX		;offset into line
		ADD EDI, oULX		;add again for attributes
		MOV ESI, EDI		;
		SUB ESI, 160		;ESI is 1st source line
		MOV EBX, ESI		;Save in EBX for reload
		MOV EAX, nDDLines	;How many lines to move
		DEC EAX 			;one less than window height
svDOWN1:
		MOV ECX, nddCols	;How many WORDS per line to move
		REP MOVSW			;Move a line (of WORDS!)
		MOV EDI, EBX		;Reload Dest to next line
		MOV ESI, EDI
		SUB ESI, 160
		MOV EBX, ESI		;Save again
		DEC EAX
		JNZ svDOWN1
		MOV EAX, [EDX.NormAttr]	;Normal video attributes!!!
		SHL EAX, 8
		MOV AL, 20h				;Space
		MOV EDI, EBX			;Put the last line into EDI
		MOV ECX, nddCols
		CLD
		REP STOSW
		XOR EAX, EAX		;No error
		JMP svDone
							;No... scroll down begins
svUP0:
		MOV EAX, oULY		;First line
		MOV ECX, 160
		MUL ECX 				;times nBytes per line
		MOV EDI, [EBX.pVidMem]	;EDI points to video memory 0,0
		MOV EDX, EBX			;Save pJCB
		ADD EDI, EAX			;EDI is ptr to 1st dest line
		ADD EDI, oULX		;offset into line
		ADD EDI, oULX		;add again for attributes
		MOV ESI, EDI		;
		ADD ESI, 160		;ESI is 1st source line
		MOV EBX, ESI		;Save in EBX for reload
		MOV EAX, nDDLines	;How many lines to move
		DEC EAX 			;two less than window height
svUP1:
		MOV ECX, nddCols	;How many WORDS per line to move
		REP MOVSW			;Move a line (of WORDS!)
		MOV EDI, EBX		;Reload Dest to next line
		MOV ESI, EDI
		ADD ESI, 160
		MOV EBX, ESI		;Save again
		DEC EAX
		JNZ svUP1
		MOV EAX, [EDX.NormAttr]	;Normal video attributes!!!
		SHL EAX, 8
		MOV AL, 20h				;Space
		MOV EDI, EBX		;Put the last line into EDI
		SUB EDI, 160
		MOV ECX, nddCols
		CLD
		REP STOSW
		XOR EAX, EAX		;No error
		JMP svDone
svErcExit:					;Error exits will jump here
		MOV EAX, ErcVidParam
svDone:
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 20
_ScrollVid	ENDP
;
;=============================================================
; HardXY - Intenal  Internal to support SetXY and SetVidOwner
;			This sets the hardware cursor position
; Input:
;	EAX : New Y position
;	EBX : New X position
; Used:
;	EAX, EBX, EDX, Flags
; Output:
;	None

HardXY:
		MOV ECX,80
		MUL ECX					; Line * 80
		ADD EAX,EBX				; Line plus column
		MOV DX,CRTCPort1		; Index register
		PUSH EAX
		MOV AL,CRTCCurLo
		OUT DX,AL				; Index 0Fh for low byte
		POP EAX
		MOV DX,CRTCPort2		; Data register
		OUT DX,AL				; Send Low byte out
		SHR EAX,08				; shift hi byte into AL
		PUSH EAX
		MOV DX,CRTCPort1
		MOV AL,CRTCCurHi
		OUT DX,AL				; Index for High byte
		POP EAX
		MOV DX,CRTCPort2
		OUT DX,AL				; Send High byte out
		RETN
;
;=============================================================================
; SetXY:
; Position VGA cursor (Text mode) to the X & Y position.
; Also sets hardware CrntX and CrntY cursor position if
; crnt job is assigned the real screen
;=============================================================================

NewX		EQU DWORD PTR [EBP+16]
NewY		EQU DWORD PTR [EBP+12]

_SetXY	PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		CALL GetpCrntJCB		;Leaves ptr to current JCB in EAX
		MOV EBX, EAX

		MOV ECX,NewX			; Column
		MOV EDX,NewY			; Line
		MOV [EBX.CrntX],ECX		; This saves it in the VCB
		MOV [EBX.CrntY],EDX		;

		CALL GetCrntJobNum		;Leaves ptr to current JCB in EAX
		CMP EAX, ddVidOwner
		JNE GotoXYDone			;If not on Active screen, skip it

		MOV EAX,NewY			;Setup to call HardXY
		MOV EBX,NewX
		CALL HardXY
GotoXYDone:
		XOR EAX,EAX				;No Error
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 8
_SetXY	ENDP

;=============================================================================
; GetXY:
; Returns position of VGA cursor (Text mode X & Y position).
; This appliies to the values for the caller's VCB
;=============================================================================

pXret		EQU DWORD PTR [EBP+16]
pYret		EQU DWORD PTR [EBP+12]

_GetXY	PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		CALL GetpCrntJCB		;Leaves ptr to current JCB in EAX
		MOV EBX, EAX

		MOV EAX,[EBX.CrntX]		; Column
		MOV ESI,pXret
		MOV [ESI], EAX
		MOV EAX,[EBX.CrntY]		; Line
		MOV ESI,pYret
		MOV [ESI], EAX
		XOR EAX,EAX
QXYDone:
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 8
_GetXY	ENDP


;=============================================================================
; EditLine
; Reads a line of text from the keyboard and puts it into the
; specified string with full line editing features.
;
; EditLine(pStr, dCrntLen, dMaxLen, pdLenRet, pbExitChar): dError
;
; Param 1 is a NEAR Ptr to string to be edited
; Param 2 is current length of string to edit (80 Max)
; Param 3 is the max length the string can be (80 Max)
; Param 4 is a NEAR Ptr to a DD where the length of the string is returned
; Param 5 is a pointer to a Byte where the exit key from the edit
;        operation is returned.
; Param 6 is the editing attribute to use.
;
; Display and keyboard are handled entirely inside EditLine.
; The following keys are recognized and handled inside, any other key
; causes Editline to exit returning the string in it's current condition
; and returning the key that caused the exit to pKeyRet:
;
; 08 (Backspace) move cursor to left replacing char with 20h
;     which is a destructive backspace
; 20-7E Hex places character in current position and advances position

; Any other keystroke causes the edit line routine to be exited 
; with that keystroke returned to pExitKeyRet
;
;
;=============================================================================

pEdString       EQU DWORD PTR [EBP+32]
ddSzCrnt        EQU DWORD PTR [EBP+28]
ddSzMax         EQU DWORD PTR [EBP+24]
pddSzRet        EQU DWORD PTR [EBP+20]
pExitKeyRet     EQU DWORD PTR [EBP+16]
dEditAttr		EQU DWORD PTR [EBP+12]

;Local vars EditX and EditY hold position of first char of text
;CrntX is the cursor postion
;
PosnX           EQU DWORD PTR [EBP-04]
EditX           EQU DWORD PTR [EBP-08]
EditY           EQU DWORD PTR [EBP-12]
KeyCode			EQU DWORD PTR [EBP-16]

PUBLIC _EditLine
_EditLine  PROC FAR
		PUSH EBP                ;
		MOV EBP,ESP             ;
		SUB ESP, 16

		CMP ddSzCrnt, 80     ;Is it currently too long?
		JA BadEdit
		CMP ddSzMax, 80      ;Is Max len to long?
		JA BadEdit
		MOV EAX, ddSzCrnt
		CMP EAX, ddSzMax     ;Is Crnt len > Max???
		JA BadEdit

		LEA EAX, EditX			;Get current cursor posns in local vars
		PUSH EAX
		LEA EAX, EditY
		PUSH EAX
		CALL FAR PTR _GetXY
		CMP EAX, 0
		JNE EditDone         ;Bad Erc from call

		MOV EAX, EditX
		ADD EAX, ddSzCrnt
		MOV PosnX, EAX       ;make PosnX end of string

		MOV ECX, ddSzMax
		SUB ECX, ddSzCrnt    ;ECX  how many bytes to zero
		JZ  EdLn01           ;None to zero out
		MOV ESI, pEdString   ;Initialize currrent string
		ADD ESI, ddSzCrnt    ;ESI ptr to 1st empty byte
		MOV AL, 20h          ;fill with spaces
Edln00:
		MOV [ESI], AL
		INC ESI
		LOOP Edln00

EdLn01:
		PUSH PosnX
		PUSH EditY
		CALL FAR PTR _SetXY
		CMP EAX, 0
		JNE EditDone

EdLn02:
		PUSH EditX      		;Display current string
		PUSH EditY
		PUSH pEdString
		PUSH ddSzMax
		PUSH dEditAttr			;Attribute they selected
		CALL FAR PTR _PutVidChars
		CMP EAX, 0
		JNE EditDone
EdLn03:
		LEA EAX, KeyCode
		PUSH EAX
		CMP ddVidOwner, 2		;Debugger???
		JE EdLn035
		PUSH 1					;Wait for a key
		CALL FAR PTR _ReadKbd	;Get a key
		JMP SHORT EdLn036
EdLn035:
		CALL ReadDbgKbd
EdLn036:
		MOV EAX, KeyCode
		AND EAX, 07Fh
		OR  EAX, EAX
		JZ  EdLn03
		CMP EAX, 08h            ;BackSpace?
		JNE EdLn04              ;No - Next test
EdLn037:
		CMP ddSzCrnt, 0
		JE EdLn01
		DEC PosnX
		DEC ddSzCrnt
		MOV ESI, pEdString
		MOV ECX, ddSzCrnt
		MOV BYTE PTR [ESI+ECX], 20h
		JMP Edln01
EdLn04: CMP EAX, 03h            ;Left?
		JNE EdLn045             ;No - Next test
		JMP EdLn037
EdLn045:
		CMP EAX, 83h            ;Num-Left?
		JNE EdLn046             ;No - Next test
		JMP EdLn037
EdLn046:
		CMP EAX, 0Dh            ;CR?
		JNE EdLn05              ;No - Next test
		JMP EdLn07
EdLn05: CMP EAX, 1Bh            ;Escape?
		JNE EdLn06              ;No - Next test
		JMP EdLn07
EdLn06:
		CMP EAX, 7Eh            ;Is it above text?
		JA  EdLn07				;Yes, Exit!
		CMP EAX, 20h            ;Is it below text??
		JB  EdLn07				;Yes, Exit
		MOV ESI, pEdString      ;It's really a char!
		MOV ECX, ddSzCrnt
		MOV BYTE PTR [ESI+ECX], AL
		MOV ECX, ddSzMax
		CMP ddSzCrnt, ECX
		JAE EdLn01
		INC PosnX
		INC ddSzCrnt
		JMP EdLn01
EdLn07:
		MOV ESI,pExitKeyRet
		MOV [ESI], AL
		MOV ESI,pddSzRet
		MOV EAX, ddSzCrnt
		MOV [ESI], EAX

		PUSH EditX  		   	;Display current string w/Norm Attrs
		PUSH EditY
		PUSH pEdString
		PUSH ddSzMax
		CALL GetpCrntJCB		;Leaves ptr to current JCB in EAX
		MOV EBX, [EAX.NormAttr]
		PUSH EBX				;Normal Attribute from JCB
		CALL FAR PTR _PutVidChars	;Ignore error (we are leaving anyway)
		XOR EAX, EAX
		JMP EditDone
BadEdit:
        MOV EAX, ErcEditParam
EditDone:
		MOV ESP,EBP             ;
		POP EBP                 ;
		RETF 24
_EditLine   ENDP

;===================== END OF MODULE ================

⌨️ 快捷键说明

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