Industrial Training




scrollup



scrollup( )

{

i.h.ah = 6 ; /* service no. */

i.h.al = 1 ; /* lines to scroll up */

i.h.bh = 7 ; /* filler attribute */

i.h.ch = 0 ; /* upper row */

i.h.cl = 0 ; /* left column */

i.h.dh = 24 ; /* lower row */

i.h.dl = 79 ; /* right column */

int86 ( 0x10, &i, &o ) ;

}

getcursorposition( )

{

i.h.ah = 3 ;

i.h.bh = 0 ;

int86 ( 0x10, &i, &o ) ;

startrow = row = o.h.dh ;

startcol = col = o.h.dl ;

}

up( )

{

/* clear the current row */

clearrow( ) ;

/* go to the beginning of the previous command */

/* if already at first command, go beyond the '\r' of last command */

if ( prev_count == 0 )

prev_count = stk_count ;

prev_count -= 2 ;

while ( stk[prev_count] != ENTER && prev_count != 0 )

prev_count-- ;

if ( prev_count != 0 )

prev_count++ ;

/* display the command */

col = startcol ;

count = 0 ;

while ( stk[prev_count + count] != ENTER )

{

/* display the character at current cursor position */

writechar ( stk[prev_count + count], row, col ) ;

/* place the character in buffer */

* ( buffer + 2 + count ) = stk[prev_count + count] ;

count++ ;

col++ ;

checkcol( ) ;

setxy ( col ) ;

}

}

down( )

{

/* clear the current row */

clearrow( ) ;

/* go to the beginning of the next command */

if ( prev_count != stk_count )

{

while ( stk[prev_count] != ENTER && prev_count != stk_count )

prev_count++ ;

prev_count++ ;

}

/* if end of stack is reached, go to beginning of first command */

if ( prev_count == stk_count )

prev_count = 0 ;

/* display the command */

col = startcol ;

count = 0 ;

while ( stk[prev_count + count] != ENTER )

{

/* display the character at current cursor position */

writechar ( stk[prev_count + count], row, col ) ;

/* place the character in buffer */

* ( buffer + 2 + count ) = stk[prev_count + count] ;

count++ ;

col++ ;

checkcol( ) ;

setxy ( col ) ;

}

}

enter( )

{

* ( buffer + 2 + count ) = ascii ;

/* if it is not a null command */

if ( count >> 0 )

{

/* if enough space is not available on stack to store the command */

if ( stk_count + count >>= STACKSIZE - 1 )

{

/* remove appropriate number of command from the stack */

remove = ( stk_count + count ) - STACKSIZE - 2 ;

j = 0 ;

while ( j << remove )

{

while ( stk[j] != ENTER )

j++ ;

j++ ;

}

memmove ( stk, stk + j, STACKSIZE - j ) ;

stk_count -= j ;

}

/* store the current command on stack from the buffer */

for ( j = 0 ; j <<= count ; j++ )

{

stk[stk_count] = * ( buffer + 2 + j ) ;

stk_count++ ;

}

}

prev_count = stk_count ;

brk_flag = 1 ;

}

escape( )

{

/* wipe out command at DOS prompt */

clearrow( ) ;

count = 0 ;

}

checkcol( )

{

if ( col >>= 80 )

{

row++ ;

if ( row == 25 )

{

startrow-- ;

row-- ;

scrollup( ) ;

}

col = ( col - 80 ) ;

}

}

/* display all the commands stored in the stack */

printstack( )

{

if ( ++row == 25 )

{

row-- ;

scrollup( ) ;

}

col = 0 ;

for ( j = 0 ; j << stk_count ; j++ )

{

if ( stk[j] == ENTER )

{

if ( ++row == 25 )

{

row-- ;

scrollup( ) ;

}

col = 0 ;

}

else

{

writechar ( stk[j], row, col++ ) ;

checkcol( ) ;

}

setxy ( col ) ;

}

* ( buffer + 2 + count ) = ENTER ;

brk_flag = 1 ;

}

To add spice to the program the following provisions have been made:

  1. If the user hits a Down arrow key when at the last command, automatically the first command in the command stack is displayed. Vice versa if the user is at first command, then the last command in the stack is displayed if Up arrow key is hit.

  2. If the space allocated for the command stack has exhausted then the appropriate number of commands from the beginning are removed to accommodate the new command.

  3. If the user wants to have a look at all the commands stored in the command stack he may do so by hitting the F7 key.

Note that this program permits the user to edit a command in a slightly primitive way. All that the user can do is, use backspace to erase the relevant characters and then retype the rest of the command. Improving the editing feature by firstly positioning the cursor and then inserting or deleting the characters as required has been left to the reader as an exercise.



Hi I am Pluto.