Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion src/mos.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ static t_mosCommand mosCommands[] = {
{ "CLS", &mos_cmdCLS, NULL, HELP_CLS, NULL },
{ "MOUNT", &mos_cmdMOUNT, NULL, HELP_MOUNT, NULL },
{ "HELP", &mos_cmdHELP, HELP_HELP_ARGS, HELP_HELP, NULL },
{ "KEY", &mos_cmdKEY, HELP_KEY_ARGS, HELP_KEY, NULL },
};

#define mosCommands_count (sizeof(mosCommands)/sizeof(t_mosCommand))
Expand Down Expand Up @@ -336,7 +337,7 @@ int mos_exec(char * buffer) {
char path[256];
UINT8 mode;

ptr = mos_trim(buffer);
ptr = mos_trim(buffer);
ptr = mos_strtok(ptr, " ");
if(ptr != NULL) {
func = mos_getCommand(ptr);
Expand Down Expand Up @@ -408,6 +409,67 @@ int mos_cmdDIR(char * ptr) {
return mos_DIR(path);
}

// KEY command
// Parameters:
// - ptr: Pointer to the argument string in the line edit buffer
// Returns:
// - MOS error code
//
int mos_cmdKEY(char *ptr) {

UINT24 fn_number = 0;
char *hotkey_string;

if (!mos_parseNumber(NULL, &fn_number)) {

UINT8 key;
printf("Hotkey assignments:\r\n\r\n");

for (key = 0; key < 12; key++) {
printf("F%d: %s\r\n", key+1, hotkey_strings[key] == NULL ? "N/A" : hotkey_strings[key]);
}

printf("\r\n");
return 0;

}

if (fn_number < 1 || fn_number > 12) {
printf("Invalid FN-key number.\r\n");
return 0;
}

if (strlen(mos_strtok_ptr) < 1) {

if (hotkey_strings[fn_number - 1] != NULL) {
free(hotkey_strings[fn_number - 1]);
hotkey_strings[fn_number - 1] = NULL;
printf("F%u cleared.\r\n", fn_number);
} else printf("F%u already clear, no hotkey command provided.\r\n", fn_number);

return 0;

}


if (mos_strtok_ptr[0] == '\"' && mos_strtok_ptr[strlen(mos_strtok_ptr) - 1] == '\"') {

mos_strtok_ptr[strlen(mos_strtok_ptr) - 1] = '\0';
mos_strtok_ptr++;

}

if (hotkey_strings[fn_number - 1] != NULL) free(hotkey_strings[fn_number - 1]);

hotkey_strings[fn_number - 1] = malloc((strlen(mos_strtok_ptr) + 1) * sizeof(char));

strncpy(hotkey_strings[fn_number - 1], mos_strtok_ptr, strlen(mos_strtok_ptr));

hotkey_strings[fn_number - 1][strlen(mos_strtok_ptr)] = '\0';

return 0;
}

// LOAD <filename> <addr> command
// Parameters:
// - ptr: Pointer to the argument string in the line edit buffer
Expand Down
9 changes: 9 additions & 0 deletions src/mos.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ int mos_cmdTYPE(char *ptr);
int mos_cmdCLS(char *ptr);
int mos_cmdMOUNT(char *ptr);
int mos_cmdHELP(char *ptr);
int mos_cmdKEY(char *ptr);

UINT24 mos_LOAD(char * filename, UINT24 address, UINT24 size);
UINT24 mos_SAVE(char * filename, UINT24 address, UINT24 size);
Expand Down Expand Up @@ -193,6 +194,14 @@ UINT8 fat_EOF(FIL * fp);
#define HELP_TYPE "Display the contents of a file on the screen\r\n"
#define HELP_TYPE_ARGS "<filename>"

#define HELP_KEY "Store a command in one of 12 hotkey slots assigned to F1-F12\r\n\r\n" \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-tiny gotcha in this file is that the help command response contents (help help) currently does not compose the list of commands, so you should explicitly add in KEY into HELP_HELP

"Optionally, the command string can include \"%s\" as a marker\r\n" \
"in which case the hotkey command will be built either side.\r\n\r\n" \
"KEY without any arguments will list the currently assigned\r\n" \
"command strings.\r\n"

#define HELP_KEY_ARGS "<key number> <command string>\r\n"

#define HELP_CLS "Clear the screen\r\n"

#define HELP_MOUNT "(Re-)mount the MicroSD card\r\n"
Expand Down
62 changes: 62 additions & 0 deletions src/mos_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern BYTE scrcols;
//
static char cmd_history[cmd_historyDepth][cmd_historyWidth + 1];

char *hotkey_strings[12] = NULL;

// Get the current cursor position from the VPD
//
void getCursorPos() {
Expand Down Expand Up @@ -240,6 +242,66 @@ UINT24 mos_EDITLINE(char * buffer, int bufferLength, UINT8 clear) {
case 0x87: { // END
insertPos = gotoEditLineEnd(insertPos, len);
} break;

case 0x9F: //F1
case 0xA0: //F2
case 0xA1: //F3
case 0xA2: //F4
case 0xA3: //F5
case 0xA4: //F6
case 0xA5: //F7
case 0xA6: //F8
case 0xA7: //F9
case 0xA8: //F10
case 0xA9: //F11
case 0xAA: //F12
{
if (hotkey_strings[keyc - 159] != NULL) {

char *wildcardPos = strstr(hotkey_strings[keyc - 159], "%s");

if (wildcardPos == NULL) { //No wildcard in the hotkey string

removeEditLine(buffer, insertPos, len);
strcpy(buffer, hotkey_strings[keyc - 159]);
printf("%s", buffer);
len = strlen(buffer);
insertPos = len;
keya = 0x0D;
} else {

UINT8 prefixLength = wildcardPos - hotkey_strings[keyc - 159];
UINT8 replacementLength = strlen(buffer);
UINT8 suffixLength = strlen(wildcardPos + 2);
char *result;

if (prefixLength + replacementLength + suffixLength + 1 >= bufferLength) {
break; // Exceeds max command length (256 chars)
}

result = malloc(prefixLength + replacementLength + suffixLength + 1); // +1 for null terminator

strncpy(result, hotkey_strings[keyc - 159], prefixLength); //Copy the portion preceding the wildcard to the buffer
result[prefixLength] = '\0'; //Terminate

strcat(result, buffer);
strcat(result, wildcardPos + 2);

removeEditLine(buffer, insertPos, len);
strcpy(buffer, result);
printf("%s", buffer);
len = strlen(buffer);
insertPos = len;

keya = 0x0D;

free(result);

}

} else break;
Comment thread
HeathenUK marked this conversation as resolved.
}

//
// Now the ASCII keys
//
Expand Down
2 changes: 2 additions & 0 deletions src/mos_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@

UINT24 mos_EDITLINE(char * filename, int bufferLength, UINT8 clear);

extern char *hotkey_strings[12];

#endif MOS_EDITOR_H