📄 console.c
字号:
mov ds, dx
}
/*
screen_ptr += off;
bcol = window->start_col;
for (col=0; col < max_col; col++, bcol++) {
attr = normal;
if (col < len)
c = *text++;
else if (col == len && show_eol)
c = EOL_CHAR;
else
c = ' ';
*screen_ptr++ = c;
*screen_ptr++ = attr;
c_output( c, bcol, line, attr );
}
*/
}
}
/*
* Name: c_output
* Purpose: Output one character on prompt lines
* Date: June 5, 1991
* Passed: c: character to output to screen
* col: col to display character
* line: line number to display character
* attr: attribute of character
* Returns: none
*/
void c_output( int c, int col, int line, int attr )
{
void far *screen_ptr;
int off;
screen_ptr = (void far *)g_display.display_address;
off = line * 160 + col * 2;
ASSEMBLE {
mov bx, WORD PTR screen_ptr /* load OFFSET of screen ptr */
add bx, WORD PTR off /* add offset of line:col */
mov ax, WORD PTR screen_ptr+2 /* load SEGMENT of screen ptr */
mov es, ax
mov cx, WORD PTR attr /* get attribute */
mov ah, cl /* put in ah */
mov cx, WORD PTR c /* get character */
mov al, cl /* put in al */
mov WORD PTR es:[bx], ax /* show char on screen */
}
/*
screen_ptr = g_display.display_address + line * 160 + col * 2;
*screen_ptr++ = c;
*screen_ptr = attr;
*/
}
/*
* Name: s_output
* Purpose: To output a string
* Date: June 5, 1991
* Passed: s: string to output
* line: line to display
* col: column to begin display
* attr: color to display string
* Notes: This function is used to output most strings not part of file text.
*/
void s_output( char far *s, int line, int col, int attr )
{
void far *screen_ptr;
int off;
int max_col;
max_col = g_display.ncols;
screen_ptr = (void far *)g_display.display_address;
off = line * 160 + col * 2;
ASSEMBLE {
push ds /* save ds on stack */
push di /* save di on stack */
push si /* save si on stack */
mov bx, WORD PTR attr /* keep attribute in bx */
mov cx, WORD PTR col /* put cols in cx */
mov dx, WORD PTR max_col /* keep max_col in dx */
mov di, WORD PTR screen_ptr /* load OFFSET of screen ptr */
add di, WORD PTR off /* add offset of line:col */
mov ax, WORD PTR screen_ptr+2 /* load SEGMENT of screen ptr */
mov es, ax
mov si, WORD PTR s /* load offset of string ptr */
or si, si /* is it == NULL? */
je getout /* yes, no output needed */
mov ax, WORD PTR s+2 /* load segment of string ptr */
or ax, ax /* is pointer == NULL? */
je getout /* yes, no output needed */
mov ds, ax /* load segment of text in ds */
mov ah, bl /* put attribute in AH */
}
top:
ASSEMBLE {
cmp cx, dx /* col < max_cols? */
jge getout /* no, thru with line */
lodsb /* get next char in string - put in al */
or al, al /* is it '\0' */
je getout /* yes, end of string */
cmp al, 0x0a /* is it '\n'? */
je getout /* yes, end of string */
stosw /* else show attr + char on screen (ah + al) */
inc cx /* col++ */
jmp SHORT top /* get another character */
}
getout:
ASSEMBLE {
pop si /* get back si */
pop di /* get back di */
pop ds /* get back ds */
}
/*
screen_ptr = g_display.display_address + line * 160 + col * 2;
max_col = g_display.ncols;
while (*s && col < max) {
*screen_ptr++ = *s++;
*screen_ptr++ = attr;
}
*/
}
/*
* Name: eol_clear
* Purpose: To clear the line from col to max columns
* Date: June 5, 1991
* Passed: col: column to begin clear
* line: line to clear
* attr: color to clear
* Notes: Basic assembly
*/
void eol_clear( int col, int line, int attr )
{
int max_col;
void far *screen_ptr;
int off;
max_col = g_display.ncols;
screen_ptr = (void far *)g_display.display_address;
off = line * 160 + col * 2;
ASSEMBLE {
push di /* save di on stack */
mov bx, WORD PTR attr /* keep attribute in bx */
mov dx, WORD PTR col /* put cols in dx */
mov cx, WORD PTR max_col /* put max_col in cx */
cmp dx, cx /* max_cols < cols? */
jge getout /* no, thru with line */
sub cx, dx /* number of column to clear */
mov di, WORD PTR screen_ptr /* load OFFSET of screen ptr */
add di, WORD PTR off /* add offset of line:col */
mov ax, WORD PTR screen_ptr+2 /* load SEGMENT of screen ptr */
mov es, ax
mov ah, bl /* get attribute in ah */
mov al, ' ' /* store ' ' in al */
rep stosw /* clear to end of line */
}
getout:
ASSEMBLE {
pop di /* get back di from stack */
}
/*
for (; col < g_display.ncols; col++) {
*p++ = ' ';
*p++ = attr;
}
*/
}
/*
* Name: window_eol_clear
* Purpose: To clear the line from start_col to end_col
* Date: June 5, 1991
* Passed: col: column to begin clear
* line: line to clear
* attr: color to clear
* Notes: Basic assembly
*/
void window_eol_clear( WINDOW *window, int attr )
{
int max_col;
void far *screen_ptr;
int off;
if (!g_status.screen_display)
return;
screen_ptr = (void far *)g_display.display_address;
off = window->cline * 160 + window->start_col * 2;
max_col = window->end_col + 1 - window->start_col;
ASSEMBLE {
push di /* save di on stack */
mov bx, WORD PTR attr /* keep attribute in bx */
mov cx, WORD PTR max_col /* put max_col in cx */
mov di, WORD PTR screen_ptr /* load OFFSET of screen ptr */
add di, WORD PTR off /* add offset of line:col */
mov ax, WORD PTR screen_ptr+2 /* load SEGMENT of screen ptr */
mov es, ax
mov ah, bl /* get attribute in ah */
mov al, ' ' /* store ' ' in al */
rep stosw /* clear to end of line */
pop di /* get back di from stack */
}
/*
for (; col < g_display.ncols; col++) {
*p++ = ' ';
*p++ = attr;
}
*/
}
/*
* Name: hlight_line
* Date: July 21, 1991
* Passed: x: column to begin hi lite
* y: line to begin hi lite
* lgth: number of characters to hi lite
* attr: attribute color
* Notes: The attribute byte is the hi byte.
*/
void hlight_line( int x, int y, int lgth, int attr )
{
int off;
void far *screen_ptr;
screen_ptr = (void far *)g_display.display_address;
off = y * 160 + 2 * x + 1; /* add one - so it points to attribute byte */
ASSEMBLE {
push di /* save di */
mov cx, lgth /* number of characters to change color */
mov di, WORD PTR screen_ptr /* get destination - video memory */
add di, off /* add offset */
mov ax, WORD PTR screen_ptr+2
mov es, ax
mov ax, attr /* attribute */
}
lite_len:
ASSEMBLE {
stosb /* store a BYTE */
inc di /* skip over character to next attribute */
loop lite_len /* change next attribute */
pop di /* restore di */
}
}
/*
* Name: cls
* Purpose: clear screen
* Date: June 5, 1991
* Notes: Call the video BIOS routine to clear the screen.
*/
void cls( void )
{
int line;
line = g_display.nlines + 1;
ASSEMBLE {
xor ch, ch /* starting row in ch = 0 */
xor cl, cl /* starting column in cl = 0 */
mov ax, WORD PTR line /* get ending row */
mov dh, al /* put it in dh */
mov dl, 79 /* ending column in dl = 79 */
mov bh, 7 /* attribute in bh = 7 (normal) */
mov al, 0 /* get number of lines */
mov ah, 6 /* get function number */
push bp /* some BIOS versions wipe out bp */
int 0x10
pop bp
}
}
/*
* Name: set_cursor_size
* Purpose: To set cursor size according to insert mode.
* Date: June 5, 1991
* Passed: csize: desired cursor size
* Notes: use the global display structures to set the cursor size
*/
void set_cursor_size( int csize )
{
ASSEMBLE {
mov ah, 1 /* function 1 - set cursor size */
mov cx, WORD PTR csize /* get cursor size ch:cl == top:bot */
push bp
int VIDEO_INT /* video interrupt = 10h */
pop bp
}
}
/*
* Name: set_overscan_color
* Purpose: To set overscan color
* Date: April 1, 1993
* Passed: color: overscan color
* Notes: before setting the overscan color, the old overscan color
* needs to be saved so it can be restored.
*/
void set_overscan_color( int color )
{
ASSEMBLE {
mov ah, 0x0b /* function 0x0b */
mov bl, BYTE PTR color /* get new overscan color */
xor bh, bh
push bp
int VIDEO_INT /* video interrupt = 10h */
pop bp
}
}
/*
* Name: save_screen_line
* Purpose: To save the characters and attributes of a line on screen.
* Date: June 5, 1991
* Passed: col: desired column, usually always zero
* line: line on screen to save (0 up to max)
* screen_buffer: buffer for screen contents, must be >= 160 chars
* Notes: Save the contents of the line on screen where prompt is
* to be displayed
*/
void save_screen_line( int col, int line, char *screen_buffer )
{
char far *p;
p = g_display.display_address + line * 160 + col * 2;
_fmemcpy( screen_buffer, p, 160 );
}
/*
* Name: restore_screen_line
* Purpose: To restore the characters and attributes of a line on screen.
* Date: June 5, 1991
* Passed: col: usually always zero
* line: line to restore (0 up to max)
* screen_buffer: buffer for screen contents, must be >= 160 chars
* Notes: Restore the contents of the line on screen where the prompt
* was displayed
*/
void restore_screen_line( int col, int line, char *screen_buffer )
{
char far *p;
p = g_display.display_address + line * 160 + col * 2;
_fmemcpy( p, screen_buffer, 160 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -