Skip to content

Commit

Permalink
Make the edit line sane and useful. Also, improve saving and loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
TediusTimmy committed May 6, 2023
1 parent f79e34f commit b3e008a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 35 deletions.
18 changes: 12 additions & 6 deletions machina.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ byte platformGetch (void)
case KEY_END:
ch = 148;
break;
case KEY_DC:
ch = 25;
break;
}
return ch;
}
Expand Down Expand Up @@ -183,24 +186,27 @@ byte platformGetch (void)
{
switch (getch())
{
case 72:
case 72: // Cursor Up
ch = 145;
break;
case 80:
case 80: // Cursor Down
ch = 17;
break;
case 75:
case 75: // Cursor Left
ch = 157;
break;
case 77:
case 77: // Cursor Right
ch = 29;
break;
case 71:
case 71: // Home Key
ch = 19;
break;
case 79:
case 79: // End Key
ch = 148;
break;
case 83: // Delete Key
ch = 25;
break;
}
}
return ch;
Expand Down
89 changes: 60 additions & 29 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,51 +319,55 @@ byte interpretCommand (byte command)
(('A' <= command) && ('Z' >= command)))
#endif
{
// A normal character to be inserted into the cell.
if (totLen != 120U)
{
if (inLoc == totLen)
{
string[inLoc] = command;
++inLoc;
string[inLoc] = '\0';
++totLen;

if (inLoc > (x - 5U + lChar))
{
++lChar;
}
string[inLoc + 1U] = '\0';
}
else
{
memmove(&string[inLoc + 1], &string[inLoc], totLen - inLoc + 1U);
string[inLoc] = command;
}
++inLoc;
++totLen;

if (inLoc > (x - 5U + lChar))
{
++lChar;
}
}
}
else if (('\b' == command) || (0177 == command))
else if (('\b' == command) || (0177 == command)) // Backspace
{
if (inLoc == totLen)
if (0U != inLoc)
{
if (0U != inLoc)
if (inLoc == totLen)
{
string[inLoc - 1U] = '\0';
}
else
{
--inLoc;
--totLen;
memmove(&string[inLoc - 1], &string[inLoc], totLen - inLoc + 1U);
}
--inLoc;
--totLen;

if ((inLoc + lChar) > totLen)
{
--lChar;
}
if ((inLoc + lChar) > totLen)
{
--lChar;
}
string[inLoc] = '\0';
}
else
{
}
}
else if ((command == '\n') || (command == '\r'))
else if ((command == '\n') || (command == '\r')) // Enter
{
inputMode = 0;
recalculate(c_major, top_down, left_right);
}
else if (command == 157)
else if (command == 157) // Cursor Left
{
if (0U != inLoc)
{
Expand All @@ -375,7 +379,7 @@ byte interpretCommand (byte command)
}
}
}
else if (command == 29)
else if (command == 29) // Cursor Right
{
if (inLoc != totLen)
{
Expand All @@ -387,13 +391,13 @@ byte interpretCommand (byte command)
}
}
}
else if (command == 19)
else if (command == 19) // Home
{
inLoc = 0U;
lChar = 0U;
}
else if (command == 148)
{
else if ((command == 4) || (command == 148)) // Insert / End
{ // Insert on Commodore because the C64 keyboard doesn't have End
inLoc = totLen;
if (inLoc > (x - 5U))
{
Expand All @@ -404,6 +408,19 @@ byte interpretCommand (byte command)
lChar = 0U;
}
}
else if (command == 25) // Delete
{
if (inLoc != totLen)
{
memmove(&string[inLoc], &string[inLoc + 1], totLen - inLoc + 1U);
--totLen;

if ((inLoc + lChar) > totLen)
{
--lChar;
}
}
}
return 0;
}

Expand Down Expand Up @@ -558,15 +575,21 @@ byte interpretCommand (byte command)
strcpy(working, string);
doSave();
string = getCellString(c_col, c_row);
strcpy(string, working);
if ('\0' != *working)
{
strcpy(string, working);
}
break;
case 'm':
case 'M':
string = getCellString(c_col, c_row);
strcpy(working, string);
doLoad();
string = getCellString(c_col, c_row);
strcpy(string, working);
if ('\0' != *working)
{
strcpy(string, working);
}
break;
}
return 0;
Expand Down Expand Up @@ -636,6 +659,10 @@ void doSave (void)
{
strcpy(working, "Error during file load.");
}
else
{
*working = '\0';
}
fclose(sl_file);
}

Expand All @@ -658,5 +685,9 @@ void doLoad (void)
{
strcpy(working, "Error during file load.");
}
else
{
*working = '\0';
}
fclose(sl_file);
}

0 comments on commit b3e008a

Please sign in to comment.