(from my TTY driver)
Code: Select all
/**
* \brief Opens a new TTY and returns a TTY object
* \return A pointer to a TTY object, or NULL if none could be allocated
* \warning You should pass the object to ttyclose() when you are finished with
* it
*/
TTY* ttyopen();
/**
* \brief Frees a TTY object allocated by ttyopen()
* \param t TTY object to de-allocate/free
*/
void ttyclose(TTY* t);
/**
* \brief Get a character from the input stream
* \param t Pointer to a TTY object
* \return The last character typed by the user
*/
char ttygetc(TTY* t);
/**
* \brief Get a string from the input stream. Strings end when a newline or EOF
* is encountered, or when s is full
* \param t Pointer to a TTY object
* \param s Buffer to store input data
* \param sz Size of s in bytes
* \return Number of bytes actually read
*/
uint32 ttygets(TTY* t, char* s, uint32 sz);
/**
* \brief Read data from a TTY's input buffer
* \param buf Data buffer
* \param elemsz Size, in bytes, of each element buffer
* \param nelem Number of elements
* \param t Pointer to a TTY object
* \return Number of elements written
*/
uint32 ttyread(void* buf, uint32 elemsz, uint32 nelem, TTY* t);
/**
* \brief Put a character in the stream's buffer
* \param t Pointer to a TTY object
* \param c character to write
*/
void ttyputc(TTY* t, char c);
/**
* \brief Put a string in the stream's buffer
* \param t Pointer to a TTY object
* \param s String to write
* \return Number of characters written (should == length of string)
*/
uint32 ttyputs(TTY* t, const char* s);
/**
* \brief Write data to a TTY's output buffer
* \param buf Data buffer
* \param elemsz Size, in bytes, of each element in buffer
* \param nelem Number of elements
* \param t Pointer to a TTY object
* \return Number of elements written
*/
uint32 ttywrite(void* buf, uint32 elemsz, uint32 nelem, TTY* t);
/**
* \brief Draw the TTY's output buffer on the screen
* \param t Pointer to a TTY object
* \note The buffer is flushed every time a newline is printed, or when
* t->obuffer is full
*/
void ttyflush(TTY* t);
/**
* \brief Clear the TTY's output buffer
* \param t Pointer to a TTY object
*/
void ttyclear(TTY* t);
/**
* \brief Scroll the TTY's output buffer up by one line
* \param t Pointer to a TTY object
*/
void ttyscroll(TTY* t);
Note: I'm thinking about rewriting much of it and redesigning it, because the way it works now is that you can either make your own TTY object and use ttyflush() to write it to video memory or you can use "stdout" (a default TTY object) but I think I need to rethink how this will work for things such as a memory manager (my plan is to make everything a driver and leave the kernel really small; sort of like a microkernel except for now, the drivers run in kernel space (I will move them once I'm done, though).