• Please review our updated Terms and Rules here

DOS Screen Handling and UI

Mike Chambers

Veteran Member
Joined
Sep 2, 2006
Messages
2,621
i installed the Turbo C (thanks again) i actually have it up on an old celeron right now. i am going to play with it a bit.

question, in your code does it break up the lines into 3 different vars - or does it just start at 23x1 and do a big long printf of the whole string?

if you are breaking it up, i don't think it'd take any less CPU doing it the way i suggested. otherwise, yes it will. :p
 
Splitting this post to a new thread to avoid polluting the original thread.

I'll prep some code for you when I get a chance, but here is the basic idea. The input buffer is a single long string of about 240 characters. The program keeps track of the cursor location and detects wrapping around the edge. It also handles backspace.

Some key combinations mean 'do something', and when they are detected the calling function is told what happened.

Here is the specific code: (You won't be able to compile it because there is more out there and I need to prep it for you)

Code:
ScBuffer::InputActions ScBuffer::getInput2( void ) {

  uint8_t ch = getch( );

  if ( isprint(ch) ) {

    if ( input_len < (SCBUFFER_MAX_INPUT_LEN-2) ) {

      gotoxy( input_x, input_y );
      putch( ch );

      tmp_input_buffer[input_len] = ch;
      input_len++;

      input_x++;
      if ( input_x > CPL ) {
        input_x = 1;
        input_y++;
      }

      return NoAction;
    }
    else { BEEP( ); }

  }
  else if ( iscntrl(ch) ) {

    if ( ch == 0 ) {
      ch = getch( );
      if ( ch == 73 ) return BackScroll;    // PgUp
      if ( ch == 81 ) return ForwardScroll; // PgDn
      if ( ch == 31 ) return Stats;         // Alt-S
      if ( ch == 45 ) return EndProgram;    // Alt-X
      if ( ch == 48 ) return BeepToggle;    // Alt-B
      if ( ch == 35 ) return Help;          // Alt-H
    }
    else {

      if ( ch == 8 ) {

        if ( input_len ) {

          input_len--;

          input_x--;

          if ( input_x == 0 ) {
            input_x = CPL;
            input_y--;
          }

          gotoxy( input_x, input_y );
          putch( ' ' );
          gotoxy( input_x, input_y );

        }
        else {
          BEEP( );
        }

      }

      else if ( ch == 13 ) {
        tmp_input_buffer[input_len] = '\n';
        tmp_input_buffer[input_len+1] = 0;
        strcpy( userInputBuffer, tmp_input_buffer );
        clearInputArea( );
        return InputReady;
      }

    }

  }

  return NoAction;

}

This code is not even called unless we know the keyboard has been hit. That code is in an inline function, which calls this code if the keyboard has been it. That inline function is used to poll for the keyboard input.

Nothing is returned until the user hits Enter or one of the special keys.

When the user finally hits Enter to signal that input is ready, the buffer is copied to another buffer that the user provides. This allows me to turn around and start accepting new input without having to worry about corrupting the old input.

There are probably places to speed things up here - I haven't scrubbed this part totally clean yet.
 
Back
Top