Console developement question
Posted: Mon Sep 17, 2007 6:38 pm
What I'm trying to do is create a console (think DOS, for simplicity sake). I have a kernel set up, monitor code to print code and such, really basic filesystem set up (using the Skelix OS tutorials), and some other stuff...I don't have much memory management created yet (yet, I kind of think I should do this before working on console stuff). I don't have paging set up (important?...never saw the point in this for a mono-kernel).
Anywho...enough with the rundown, the issue I'm posting about.
If I do a comparison of what was entered character-by-character, I get the "command" to run. However, if I do anything else, such as storing the valid commands in an char array (like commands[] or commands[COMMANDS+1] (where COMMANDS is how many valid commands there are)), it either doesn't work (at all), or compiles with errors. Below is the current source for this information.
tty.h
tty.c
What happens is I pass a converted scancode (that is a char by the time the function is called) in my keyboard setup...and if the user hit enter I do the command, and reset the buffer and index...otherwise I store the character in the buffer, increment the index, and print the character. I know "index += 1;" isn't the best way to do it, and I could do "index++;", but ++ wouldn't work for me either...
(I know the files are named wrong, since I doubt this is a TTY setup by any means...but, I'm more focused on the issue right now.)
The code isn't commented for now because I'm just debugging the stuff, and it's pretty self explanatory with what's there...(not to mention I was in a rush while typing it up).
Most of the time, when I compile this portion of the system, I get an error saying that the commands array has an excess of entries...no matter how I declare it.
Example:
And, the system specs if that helps:
GCC v4.1, latest version of NASM
Using Linux (Ubuntu)
Anywho...enough with the rundown, the issue I'm posting about.
If I do a comparison of what was entered character-by-character, I get the "command" to run. However, if I do anything else, such as storing the valid commands in an char array (like commands[] or commands[COMMANDS+1] (where COMMANDS is how many valid commands there are)), it either doesn't work (at all), or compiles with errors. Below is the current source for this information.
tty.h
Code: Select all
#ifndef __TTY_H
#define __TTY_H
#include "common.h"
#define COMMANDS 1 // How many commands are available to be called?
typedef struct tty{
int index; // Current position in in[] array
char in[]; // Input buffer
} tty_t;
tty_t teletype;
void handle_key(char key);
void do_command();
#endif
Code: Select all
#include "include/tty.h"
#include "include/strings.h"
static char commands[] = {"hi"};
void handle_key(char key){
if(key == '\n'){
do_command(); // enter-key was pressed
int i = 0;
while(i < teletype.index){
teletype.in[i] = 0x00;
i++;
}
teletype.index = 0;
} else{
teletype.in[teletype.index] = key;
teletype.index += 1;
printf("%c", key);
}
}
void do_command(){
teletype.in[teletype.index] = 0x00;
int i = 0;
while(i < COMMANDS){
if(teletype.in == commands[i])
printf("\nWe hit a command!\n");
i++;
}
printf("\nTeletype buffer: %s\nIndex: %d\n\n", teletype.in, teletype.index);
}
(I know the files are named wrong, since I doubt this is a TTY setup by any means...but, I'm more focused on the issue right now.)
The code isn't commented for now because I'm just debugging the stuff, and it's pretty self explanatory with what's there...(not to mention I was in a rush while typing it up).
Most of the time, when I compile this portion of the system, I get an error saying that the commands array has an excess of entries...no matter how I declare it.
Example:
Code: Select all
#define COMMANDS 3
static char commands[] = {"hi", "bob", "senior"};
GCC v4.1, latest version of NASM
Using Linux (Ubuntu)