got print working, new keyboard control converts keycode to char. all chars conv to charcodes using shiftMap and charMap. added temp cp/m logo cause fuck it

This commit is contained in:
luke zeller
2020-05-05 14:15:34 -04:00
parent 84dcb2bd50
commit cb809b8ce3
2 changed files with 171 additions and 37 deletions

BIN
program

Binary file not shown.

View File

@@ -771,7 +771,106 @@ bool chars[69][8][8] {
},
};
map<SDL_Keycode, int> charMap{ {SDLK_SPACE, 0},
map<char, int> charMap = { {' ', 0},
{'a', 1},
{'b', 2},
{'c', 3},
{'d', 4},
{'e', 5},
{'f', 6},
{'g', 7},
{'h', 8},
{'i', 9},
{'j', 10},
{'k', 11},
{'l', 12},
{'m', 13},
{'n', 14},
{'o', 15},
{'p', 16},
{'q', 17},
{'r', 18},
{'s', 19},
{'t', 20},
{'u', 21},
{'v', 22},
{'w', 23},
{'x', 24},
{'y', 25},
{'z', 26},
{'1', 27},
{'2', 28},
{'3', 29},
{'4', 30},
{'5', 31},
{'6', 32},
{'7', 33},
{'8', 34},
{'9', 35},
{'0', 36},
{'`', 37},
{'-', 38},
{'=', 39},
{'\\', 40},
{'/', 41},
{'[', 42},
{']', 44},
{';', 45},
{'\'', 47},
{',', 48},
{'.', 49}
};
map<char, int> shiftMap = { {'!', 52},
{'@', 62},
{'#', 54},
{'$', 55},
{'%', 56},
{'^', 63},
{'&', 57},
{'*', 50},
{'(', 58},
{')', 59},
{'~', 67},
{'_', 64},
{'+', 51},
{'|', 43},
{'?', 53},
{'{', 66},
{'}', 65},
{':', 46},
{'\"', 68},
{'<', 60},
{'>', 61}
};
map<char, char> shiftConv = { {'1', '!'},
{'2', '@'},
{'3', '#'},
{'4', '$'},
{'5', '%'},
{'6', '^'},
{'7', '&'},
{'8', '*'},
{'9', '('},
{'0', ')'},
{'`', '~'},
{'-', '_'},
{'=', '+'},
{'\\', '|'},
{'/', '?'},
{'[', '{'},
{']', '}'},
{';', ':'},
{'\'', '\"'},
{',', '<'},
{'.', '>'}
};
/*map<SDL_Keycode, int> charMap{ {SDLK_SPACE, 0},
{SDLK_a, 1},
{SDLK_b, 2},
{SDLK_c, 3},
@@ -871,8 +970,10 @@ map<SDL_Keycode, int> shiftMap{ {SDLK_SPACE, 0},
{SDLK_COMMA, 60},
{SDLK_PERIOD, 61},
};
};*/
string shiftChars = R"(!@#$%^&*()~_+|?{}:"<>)";
//int screen[40][25]; but in vector
vector< vector<int> > screen(40, vector<int>(25));
@@ -881,6 +982,9 @@ const char* ver = "0.1.0-prerelease";
bool cursor = false;
int a = 0;
int b = 0;
void drawChar(SDL_Renderer *renderer, int scale, int x, int y, int charToDraw) {
@@ -931,12 +1035,6 @@ void drawScreen(SDL_Renderer *renderer, int scale, int x, int y) {
}
void clearScreen() {
/*for(int c=0;c<40;c++) {
for(int d=0;d<25;d++) {
screen[c][d] = 0;
}
}*/
screen.clear();
@@ -958,6 +1056,52 @@ void scrollScreen() {
}
void printCharFromCode(int charCode) {
screen[a][b] = charCode;
if (a < 39) { a++; } else { a = 0; b++; }
if (b < 25) {} else { b = 24; scrollScreen(); }
}
void printChar(char charToDraw) {
if (shiftChars.find(charToDraw) != string::npos) {
printCharFromCode(shiftMap[charToDraw]);
} else {
printCharFromCode(charMap[charToDraw]);
}
}
void print(string stringToPrint) {
for(int f=0; f < stringToPrint.length(); f++) {
printChar(stringToPrint[f]);
}
}
void println(string stringToPrint) {
for(int f=0; f < stringToPrint.length(); f++) {
printChar(stringToPrint[f]);
}
a = 0;
b++;
}
int main(int argc, char* argv[]) {
//setup
@@ -1000,9 +1144,9 @@ int main(int argc, char* argv[]) {
"Z80 SCREENTEST", //window title
SDL_WINDOWPOS_UNDEFINED, //initial x position
SDL_WINDOWPOS_UNDEFINED, //initial y position
320 * scale, //width, in pixels
200 * scale, //height, in pixels
SDL_WINDOW_OPENGL //flags - see below
320 * scale, //width, in pixels
200 * scale, //height, in pixels
SDL_WINDOW_OPENGL //flags
);
// Check that the window was successfully created
@@ -1024,23 +1168,16 @@ int main(int argc, char* argv[]) {
//clear screen to black
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
//test drawing section (will be removed once program loop is implemented
/*
SDL_RenderSetScale(renderer, scale, scale);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderDrawPoint(renderer, 0, 0);
drawChar(renderer, scale, 0, 0, 0);
SDL_RenderPresent(renderer);
*/
println("cp/m 2.2");
println("copyright 1979 digital research");
println("");
print("a>");
int a = 0;
int b = 0;
Uint32 time = SDL_GetTicks();
@@ -1051,16 +1188,11 @@ int main(int argc, char* argv[]) {
drawScreen(renderer, scale, a, b);
SDL_RenderPresent(renderer);
if (SDL_TICKS_PASSED(SDL_GetTicks(), time + 500)) {
if (SDL_GetTicks() > time + 500) {
cursor = !cursor;
time = SDL_GetTicks();
}
//handle events
SDL_Event event;
while (SDL_PollEvent(&event)) {
@@ -1104,23 +1236,25 @@ int main(int argc, char* argv[]) {
break;
default:
cout << shiftMap[event.key.keysym.sym];
if (charMap.count(event.key.keysym.sym) == 0) { break; }
cursor = true;
if (event.key.keysym.mod == 4097) {
//char shiftSym =
screen[a][b] = shiftMap[event.key.keysym.sym];
printCharFromCode(shiftMap[shiftConv[event.key.keysym.sym]]);
} else {
screen[a][b] = charMap[event.key.keysym.sym];
printCharFromCode(charMap[event.key.keysym.sym]);
}
if (a < 39) { a++; } else { a = 0; b++; }
if (b < 25) {} else { b = 24; scrollScreen(); }
time = SDL_GetTicks();