📄 console.c
字号:
les di, screen_ptr mov ah, BYTE PTR attr mov al, BYTE PTR c jmp short done }repeater: ASSEMBLE { mov es:[di], ax add di, bx }done: ASSEMBLE { dec cx /* is count more than zero? */ jns repeater pop di }}/* * 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. * * jmh 991023: Possibly output an extra space before and after. * jmh 991027: don't bother testing (s == NULL) or (*s == '\n'). */void s_output( const char *s, int line, int col, int attr ){char *screen_ptr = SCREEN_PTR( line, col );int max_col = g_display.ncols;int space = g_display.output_space; ASSEMBLE { push ds /* save ds on stack */ push di /* save di on stack */ push si /* save si on stack */ les di, screen_ptr /* load SEGMENT+OFFSET of screen ptr */ lds si, s /* load segment+offset of string ptr */ mov dx, WORD PTR col /* put cols in dx */ mov cx, WORD PTR max_col /* keep max_col in cx */ mov ah, BYTE PTR attr /* keep attribute in ah */ cmp BYTE PTR space, 0 /* outputting a space? */ je begin /* no, skip it */ test dx, dx /* already on left edge? */ je begin /* yep, skip it */ mov al, ' ' mov es:[di-2], ax }begin: ASSEMBLE { sub cx, dx /* max_col -= col */ jle getout }top: ASSEMBLE { lodsb /* get next char in string - put in al */ test al, al /* is it '\0' */ jz end /* yes, end of string */ stosw /* else show attr + char on screen (ah + al) */ loop SHORT top /* get another character */ }end: ASSEMBLE { cmp BYTE PTR space, 0 je getout jcxz getout mov al, ' ' stosw }getout: ASSEMBLE { pop si /* get back si */ pop di /* get back di */ pop ds /* get back ds */ }}/* * 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 ){char *screen_ptr = SCREEN_PTR( y, x ); ASSEMBLE { push di /* save di */ mov cx, lgth /* number of characters to change color */ les di, screen_ptr /* get destination - video memory */ mov al, BYTE PTR attr /* attribute */ }lite_len: ASSEMBLE { inc di /* skip over character to attribute */ stosb /* store a BYTE */ 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;unsigned char column;unsigned char attr; line = g_display.nlines - 1; column = (unsigned char)(g_display.ncols - 1); attr = (unsigned char)Color( Text ); ASSEMBLE { xor cx, cx /* starting row in ch = 0 */ /* starting column in cl = 0 */ mov ax, WORD PTR line /* get ending row */ mov dh, al /* put it in dh */ mov dl, Byte Ptr column /* ending column in dl = 79 */ mov bh, Byte Ptr attr /* attribute in bh (jmh 990414) */ mov al, cl /* get number of lines */ mov ah, 6 /* get function number */ push bp /* some BIOS versions wipe out bp */ int VIDEO_INT 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 * jmh 991028: may as well write it in assembly. */void save_screen_line( int col, int line, Char *screen_buffer ){char *p = SCREEN_PTR( line, col );int max_cols = g_display.ncols; ASSEMBLE { push ds push si push di les di, screen_buffer lds si, p mov cx, max_cols rep movsw pop di pop si pop ds }}/* * 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 * jmh 991028: may as well write it in assembly. */void restore_screen_line( int col, int line, Char *screen_buffer ){char *p = SCREEN_PTR( line, col );int max_cols = g_display.ncols; ASSEMBLE { push ds push si push di les di, p lds si, screen_buffer mov cx, max_cols rep movsw pop di pop si pop ds }}/* * Name: save_area * Purpose: save text and attribute * Date: November 13, 1993 * Passed: buffer: storage for text and attribute * wid: width to save * len: length to save * row: starting row of save * col: starting column of save * * jmh 991022: Rewrote in assembly. * I should point out that the buffer should be (at least) * (wid + 4) * (len + 1) * sizeof(Char) bytes. */void save_area( Char *buffer, int wid, int len, int row, int col ){char *pointer;int cols = g_display.ncols; adjust_area( &wid, &len, &row, &col, NULL ); pointer = SCREEN_PTR( row, col ); ASSEMBLE { push ds push si push di lds si, pointer les di, buffer mov bx, cols /* BX = (cols - wid) * 2 */ sub bx, wid /* It is used to point to */ shl bx, 1 /* the next screen row */ mov ax, len } line_loop: ASSEMBLE { mov cx, wid rep movsw /* buffer = screen */ add si, bx /* next row */ dec ax /* any more? */ jnz line_loop /* yep (assumes len > 0) */ pop di pop si pop ds }}/* * Name: restore_area * Purpose: restore text and attribute * Date: November 13, 1993 * Passed: buffer: storage for text and attribute * wid: width to restore * len: length to restore * row: starting row for restore * col: starting column for restore * * jmh 991022: Rewrote in assembly. * I should point out that these parameters should be identical * to those used in the corresponding save_area(). */void restore_area( Char *buffer, int wid, int len, int row, int col ){char *pointer;int cols = g_display.ncols; adjust_area( &wid, &len, &row, &col, NULL ); pointer = SCREEN_PTR( row, col ); ASSEMBLE { push ds push si push di les di, pointer lds si, buffer mov bx, cols /* BX = (cols - wid) * 2 */ sub bx, wid /* It is used to point to */ shl bx, 1 /* the next screen row */ mov ax, len } line_loop: ASSEMBLE { mov cx, wid rep movsw /* screen = buffer */ add di, bx /* next row */ dec ax /* any more? */ jnz line_loop /* yep (assumes len > 0) */ pop di pop si pop ds }}/* * Name: shadow_area * Purpose: draw a shadow around an area * Author: Jason Hood * Date: October 20, 1999 * Passed: wid: width of area * len: length of area * row: starting row of area * col: starting column of area * Notes: the characters being shadowed are not saved. * Use attribute 8 (dark grey on black) as the shadow. */void shadow_area( int wid, int len, int row, int col ){char *pointer;int w;int cols = g_display.ncols * 2;int alen; if (g_display.shadow) { alen = len; adjust_area( &wid, &len, &row, &col, &w ); if (w > 0) { pointer = display_address + (row + 1) * cols + (col + wid) * 2; ASSEMBLE { push di les di, pointer mov dx, cols mov ax, w shl ax, 1 add dx, ax /* dx is offset to next line */ mov al, 8 /* attribute */ mov cx, len dec cx /* skip the first line */ std /* going backwards */ } shadow_line: ASSEMBLE { mov bx, w /* number of characters to shadow */ } shadow_char: ASSEMBLE { dec di /* point to attribute */ stosb /* store a BYTE */ dec bx jnz shadow_char add di, dx /* next line */ loop shadow_line cld pop di } } if (alen < len) { col += g_display.shadow_width; wid -= g_display.shadow_width + w; /* hlight_line( col, row + len - 1, wid, 8 ); */ pointer = display_address + (row + len - 1) * cols + col * 2; ASSEMBLE { push di mov cx, wid les di, pointer mov al, 8 } shadow_len: ASSEMBLE { inc di /* skip over character to attribute */ stosb /* store a BYTE */ loop shadow_len /* change next attribute */ pop di } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -