You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.2 KiB
C

#include "conio.h"
#include <string.h>
//Slow, find how str function does it and apply to whole string at once?
//Technically could be void, but with returning string allows you to use it easy.
char * strinv(char str[]) {
int i;
for(i = 0; i < strlen(str); i++){
str[i] = inv(str[i]);
}
return str;
}
//This is currently unable to screenwrap. Improve in the future.
void conprint(char * str, int x, int y){
rb_map_device(conid);
con->line = y % 50;
memcpy(con->display + x, str, strlen(str));
}
void set_conid(int id){
conid = id;
}
int get_conid(){
return conid;
}
struct cursor_pos {
int x;
int y;
};
void set_cursor_pos(int x, int y) {
rb_map_device(conid);
con->cursor_x = x;
con->cursor_y = y;
}
struct cursor_pos get_cursor_pos() {
struct cursor_pos cursor;
rb_map_device(conid);
cursor.x = con->cursor_x;
cursor.y = con->cursor_y;
return cursor;
}
void set_cursor_mode(int mode) {
rb_map_device(conid);
con->cursor_mode = mode;
}
int get_cursor_mode() {
rb_map_device(conid);
return con->cursor_mode;
}
void conclear(){
rb_map_device(conid);
blit(1, ' ', (char)0xBD, 0, 0, 80, 50);
set_cursor_pos(0,0);
}
void blit(char command, char x, char y, char xo, char yo, char w, char h) {
con->blit_start_x = x;
con->blit_start_y = y;
con->blit_offset_x = xo;
con->blit_offset_y = yo;
con->blit_width = w;
con->blit_height = h;
con->blit_mode = command;
while(con->blit_mode != 0) ; //WAI
}
#define LF 13
#define BSP 8
char * read_keyboard() {
int pos = 0;
char buf[128];
int breakpoint = 1;
int cursorp;
rb_map_device(conid);
memset(buf, 0, 128);
cursorp = con->cursor_x;
con->line = con->cursor_y;
while(breakpoint) {
while(con->kb_pos != con->kb_start && breakpoint) {
switch(con->kb_key) {
case LF :
fill(' ', cursorp, con->cursor_y, con->cursor_x, 1);
con->cursor_x = cursorp;
breakpoint = 0;
con->kb_start++;
break;
case BSP :
con->kb_pos--;
con->cursor_x--;
pos--;
buf[pos] = ' ';
con->display[con->cursor_x] = ' ';
break;
default :
buf[pos] = con->kb_key;
con->display[con->cursor_x] = con->kb_key;
con->cursor_x++;
con->kb_start++;
pos++;
break;
}
}
}
return buf;
}