Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
0.22.5
Browse files Browse the repository at this point in the history
Fixed a bug in PRINT
Disabled line numbers when typing in the shell
Improve Windows speed problem slightly by reducing the number of times _kbhit() is called
Added truecolor to 16-color conversion for non-VT Windows
  • Loading branch information
PQCraft authored Sep 26, 2021
1 parent 3db3a0f commit a2e2d3f
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 66 deletions.
99 changes: 47 additions & 52 deletions clibasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

// Base defines

char VER[] = "0.22.4.1";
char VER[] = "0.22.5";

#if defined(__linux__)
char OSVER[] = "Linux";
Expand Down Expand Up @@ -367,8 +367,10 @@ char** rl_tab(const char* text, int start, int end) {
#ifdef _WIN32
#define hConsole GetStdHandle(STD_OUTPUT_HANDLE)
char* rlptr;
char kbinbuf[256];
bool inrl = false;
void cleanExit();
void cmdIntHndl();
void setcsr() {
COORD coord;
coord.X = 0;
Expand Down Expand Up @@ -400,13 +402,32 @@ void enablevt() {
}
}
#endif
void updatechars() {
char kbc;
int i = strlen(kbinbuf) - 1;
while (_kbhit()) {
kbc = _getch();
if (!((GetKeyState(VK_LCONTROL) | GetKeyState(VK_RCONTROL)) & 0x80)) {
if (kbc == 13) kbc = 10;
else if (kbc == 10) kbc = 13;
}
kbinbuf[++i] = kbc;
if (!textlock) putchar(kbc);
if (kbc == 3) {
//cmdint = true;
cmdIntHndl();
}
}
kbinbuf[++i] = 0;
fflush(stdout);
}
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 4
#endif
#ifndef WEXITSTATUS
#define WEXITSTATUS(x) ((uint8_t)(x))
#endif
char kbinbuf[256];

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
bool winArgNeedsQuotes(char* str) {
Expand Down Expand Up @@ -982,20 +1003,6 @@ int main(int argc, char** argv) {
progLine = 1;
bool comment = false;
while (1) {
#ifdef _WIN32
char kbc;
int kbh = kbhit();
for (int i = 0; i < kbh; ++i) {
kbc = _getch();
kbinbuf[i] = kbc;
if (!textlock) putchar(kbc);
if (kbc == 3) {
if (inProg) {goto brkproccmd;}
else {cmdIntHndl();}
}
}
fflush(stdout);
#endif
rechk:;
if (progindex < 0) {inProg = false;}
else if (inProg == false) {progindex = - 1;}
Expand Down Expand Up @@ -1080,18 +1087,7 @@ static inline void cb_wait(uint64_t d) {
#else
uint64_t t = d + usTime();
while (t > usTime() && !cmdint) {
char kbc;
int kbh = kbhit();
for (int i = 0; i < kbh; ++i) {
kbc = _getch();
kbinbuf[i] = kbc;
if (!textlock) putchar(kbc);
if (kbc == 3) {
cmdint = true;
return;
}
}
fflush(stdout);
updatechars();
}
#endif
}
Expand Down Expand Up @@ -1544,30 +1540,29 @@ void updateTxtAttrib() {
if (txt_reverse) fputs("\e[7m", stdout);
if (txt_underlncolor) printf("\e[58:5:%um", txt_underlncolor);
#else
uint8_t tfgc, tbgc;
switch (fgc % 16) {
case 1: tfgc = 4; break;
case 3: tfgc = 6; break;
case 4: tfgc = 1; break;
case 6: tfgc = 3; break;
case 9: tfgc = 12; break;
case 11: tfgc = 14; break;
case 12: tfgc = 9; break;
case 14: tfgc = 11; break;
default: tfgc = fgc; break;
}
switch (bgc % 16) {
case 1: tbgc = 4; break;
case 3: tbgc = 6; break;
case 4: tbgc = 1; break;
case 6: tbgc = 3; break;
case 9: tbgc = 12; break;
case 11: tbgc = 14; break;
case 12: tbgc = 9; break;
case 14: tbgc = 11; break;
default: tbgc = bgc; break;
}
SetConsoleTextAttribute(hConsole, (tfgc % 16) + (tbgc % 16) * 16);
uint8_t tmpfgc, tmpbgc;
if (txt_truecolor) {
uint8_t a;
tmpfgc = (((truefgc >> 23) & 1) << 2) | (((truefgc >> 15) & 1) << 1) | ((truefgc >> 7) & 1);
tmpfgc |= ((((truefgc >> 22) & 1) & ((truefgc >> 21) & 1)) << 2)\
| ((((truefgc >> 14) & 1) & ((truefgc >> 13) & 1)) << 1)\
| (((truefgc >> 6) & 1) & ((truefgc >> 5) & 1));
a = ((((truefgc >> 16) & 0xFF) + ((truefgc >> 8) & 0xFF) + (truefgc & 0xFF)) / 3);
tmpfgc |= (8 * (a > 84));
tmpbgc = (((truebgc >> 23) & 1) << 2) | (((truebgc >> 15) & 1) << 1) | ((truebgc >> 7) & 1);
tmpbgc |= ((((truebgc >> 22) & 1) & ((truebgc >> 21) & 1)) << 2)\
| ((((truebgc >> 14) & 1) & ((truebgc >> 13) & 1)) << 1)\
| (((truebgc >> 6) & 1) & ((truebgc >> 5) & 1));
a = ((((truebgc >> 16) & 0xFF) + ((truebgc >> 8) & 0xFF) + (truebgc & 0xFF)) / 3);
tmpbgc |= (8 * (a > 84));
} else {
uint8_t b1 = 0, b2 = 0;
b1 = fgc & 1; b2 = (fgc >> 2) & 1; tmpfgc = (b1 ^ b2);
tmpfgc = (tmpfgc) | (tmpfgc << 2); tmpfgc = fgc ^ tmpfgc;
b1 = bgc & 1; b2 = (bgc >> 2) & 1; tmpbgc = (b1 ^ b2);
tmpbgc = (tmpbgc) | (tmpbgc << 2); tmpbgc = bgc ^ tmpbgc;
}
SetConsoleTextAttribute(hConsole, (tmpfgc % 16) + ((tmpbgc % 16) << 4));
#endif
fflush(stdout);
}
Expand Down
3 changes: 3 additions & 0 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ if (chkCmd(3, "@", "LABEL", "LBL")) {
gotodata[i].dlsp = dlstackp;
gotodata[i].fnsp = fnstackp;
gotodata[i].itsp = itstackp;
#ifdef _WIN32
updatechars();
#endif
goto noerr;
}
if (chkCmd(3, "%", "GOTO", "GO")) {
Expand Down
Binary file modified docs/manual.odt
Binary file not shown.
Binary file modified docs/manual.pdf
Binary file not shown.
4 changes: 3 additions & 1 deletion examples/hello.bas
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ IF CINT(RAND(1)) = 1: X = X * -1: ENDIF
IF CINT(RAND(1)) = 1: Y = Y * -1: ENDIF
IF CINT(RAND(1)) = 1: Z = Z * -1: ENDIF
@ LOOP
RESETTIMER
COLOR RGB(LIMIT(R, 0, 255), LIMIT(G, 0, 255), LIMIT(B, 0, 255))
PRINT "Hello, World!",, PAD$(CINT(R), 3), PAD$(CINT(G), 3), PAD$(CINT(B), 3),, PAD$(X, 9, " "), PAD$(Y, 9, " "), PAD$(Z, 9, " ");
COLOR OC
Expand All @@ -20,7 +21,8 @@ IF G > 255: Y = Y * -1: ENDIF
IF G < 0: Y = Y * -1: ENDIF
IF B > 255: Z = Z * -1: ENDIF
IF B < 0: Z = Z * -1: ENDIF
WAIT 0.005
WAITMS LIMIT(10 - TIMERMS(), 0, 10)
RESETTIMER
PUT "\r"
LOCATE , CURY() - 1
GOTO LOOP
8 changes: 6 additions & 2 deletions examples/input.bas
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ DO
L = LEN(K$)
IF ASC(K$) <> 0
P = 0
'LOCATE 1
IF _OS$ = "Windows"
LOCATE 16
ELSE
PUT "\r\t\t"
ENDIF
IF ASC(K$, LEN(K$) - 1) = 10: LOCATE , CURY() - 1: ENDIF
PUT "\r\t\t [", LEN(K$), "]"
PUT " [", LEN(K$), "]"
DOWHILE P < L
PUT ", ", ASC(K$, P)
P = P + 1
Expand Down
13 changes: 3 additions & 10 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,9 @@ if (chkCmd(1, "INKEY$")) {
}
outbuf[obp] = 0;
#else
int tmp = 1;
int obp = 0;
while (obp < tmp) {
outbuf[obp] = 0;
outbuf[obp] = kbinbuf[obp];
kbinbuf[obp] = 0;
if (outbuf[obp] == 0) {break;}
obp++;
}
outbuf[obp] = 0;
updatechars();
copyStr(kbinbuf, outbuf);
kbinbuf[0] = 0;
#endif
goto fexit;
}
Expand Down
11 changes: 10 additions & 1 deletion logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (chkCmd(2, "?", "PRINT")) {
if (!(tmpt = getVal(ltmp[1], ltmp[1]))) return true;
newline = false;
if (cmd[j] == ',') {
if (tmpt == 255 && !cmd[j + 1]) {newline = false;}
if (tmpt == 255 && !cmd[j + 1]) {newline = true;}
putchar('\t');
}
fputs(ltmp[1], stdout);
Expand Down Expand Up @@ -83,6 +83,9 @@ if (chkCmd(1, "DO")) {
dlstack[dlstackp].pl = progLine;
dlstack[dlstackp].fnsp = fnstackp;
dlstack[dlstackp].itsp = itstackp;
#ifdef _WIN32
updatechars();
#endif
return true;
}
if (chkCmd(2, "WHILE", "DOWHILE")) {
Expand All @@ -105,6 +108,9 @@ if (chkCmd(2, "WHILE", "DOWHILE")) {
dlstack[dlstackp].cp = cmdpos;
dlstack[dlstackp].fnsp = fnstackp;
dlstack[dlstackp].itsp = itstackp;
#ifdef _WIN32
updatechars();
#endif
}
dldcmd[dlstackp] = (bool)testval;
dldcmd[dlstackp] = !dldcmd[dlstackp];
Expand Down Expand Up @@ -278,6 +284,9 @@ if (chkCmd(1, "FOR")) {
fnstack[fnstackp].dlsp = dlstackp;
fnstack[fnstackp].itsp = itstackp;
cerr = 0;
#ifdef _WIN32
updatechars();
#endif
return true;
}
if (chkCmd(1, "NEXT")) {
Expand Down

0 comments on commit a2e2d3f

Please sign in to comment.