Skip to content

Commit 5fbbe07

Browse files
menu: INST/DEL deletes the highlighted file on SD or USB
There was no way to remove a file from the C64 side: a stray download, a failed copy or a test image stayed on the card until it went back to a PC. INST/DEL on a file in an SD or USB listing now shows its path and asks "Delete this file? y/n"; y removes it, the folder reloads and the cursor stays on the same row, or the last one if the file was the end of the list. Any other key returns to the listing with no message. The Teensy does the checking and the messaging, in two steps like the NFC tag pair: rCtlDeleteFileCheckWAIT (61, rsDeleteFileCheck 0x23) names the file and says in rwRegScratch whether it can go, the menu asks, and rCtlDeleteFileWAIT (62, rsDeleteFile 0x24) removes it and reports the same way. Refused, with the reason on screen: Teensy Memory, a folder or the .. entry, <Empty>, and an entry inside a mounted disk image. Folders are not deleted. A failed remove, such as a write-protected card, says so and waits for a key. The menu side is 57 bytes and still ends in page $71 ($71BB), so the SID memory-conflict range is unchanged. The header text comes from the Teensy rather than a menu string, as the REU header does, and all seven of the feature's messages are PSTR(): a bare literal lands in .rodata, which the linker script places in DTCM, and these stay in flash (+196 bytes of flash data, RAM1 variables unchanged; the two dispatch cases add 64 bytes of ITCM on TR+ and 128 on TR, absorbed by padding). Help page 2 lists the key, and General_Usage.md documents it as of FW 0.9.1. Tested on a TR and a TR+: SD and USB deletes, cancel, each refusal except on <Empty>, the last item on a page, a write-protected card, the help page, and with the background SID playing. Not yet tried: deleting the only file in a folder, DEL on <Empty>, and removing a /VMS package on the TR+.
1 parent 9a25262 commit 5fbbe07

10 files changed

Lines changed: 494 additions & 367 deletions

File tree

‎Source/C64/MainMenuCRT/source/MainMenu.asm‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,30 @@ DirectRunFromTeensyMenu:
578578
jmp CtlWriteWaitDotsAnyKeyListMenuHighlightCur
579579

580580

581+
+ cmp #ChrDelete ;Delete highlighted file
582+
bne +
583+
jsr PrintBanner ;SourcesColor
584+
lda TblEscC+EscSourcesColor
585+
sta $0286 ;set text color
586+
;header message comes from DeleteFileCheck()
587+
lda #rCtlDeleteFileCheckWAIT ;shows the file, or why it can't go
588+
sta wRegControl+IO1Port
589+
jsr WaitForTRDots
590+
lda rwRegScratch+IO1Port ;non-zero: it can, and the y/n prompt is up
591+
beq ++
592+
- jsr CheckForIRQGetIn
593+
beq -
594+
cmp #'y'
595+
bne +++ ;anything else cancels, straight back to the list
596+
lda #rCtlDeleteFileWAIT
597+
sta wRegControl+IO1Port
598+
jsr WaitForTRDots
599+
lda rwRegScratch+IO1Port ;non-zero: deleted, listing reloaded
600+
bne +++
601+
++ jsr AnyKeyMsgWait ;refused or failed, leave the message up
602+
+++ jsr ListMenuItems ; reprint menu
603+
jmp HighlightCurrent
604+
581605
+ jmp WaitForJSorKey
582606

583607
; ******************************* Subroutines *******************************

‎Source/C64/MainMenuCRT/source/Menu_Regs.i‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,10 @@
284284
rsMakeExtHostStr = 0x20
285285
rsUninstallExtHost = 0x21
286286
rsShowExtPackages = 0x22
287+
rsDeleteFileCheck = 0x23 ;the highlighted SD/USB file: show it, and in rwRegScratch whether it can go
288+
rsDeleteFile = 0x24 ;remove it and reload the listing; rwRegScratch reports success
287289

288-
rsNumStatusTypes = 0x23
290+
rsNumStatusTypes = 0x25
289291

290292
rsReady = 0x5a ;FW->64 (Rd) update finished (done, abort, or otherwise)
291293
rsC64Message = 0xa5 ;FW->64 (Rd) message for the C64, set to continue when finished
@@ -369,6 +371,8 @@
369371
rCtlBootComplete = 58 ; menu finished booting: sets BootComplete, reported by the version command
370372
rCtlBootInProgress = 59 ; clears BootComplete: a remote launch on reset returned and the menu is finishing its boot
371373
rCtlShowExtPackagesWAIT = 60 ; the /VMS packages on SD, sent as one message per row
374+
rCtlDeleteFileCheckWAIT = 61 ; show the highlighted SD/USB file and, in rwRegScratch, whether it can be deleted
375+
rCtlDeleteFileWAIT = 62 ; delete it and reload the listing; rwRegScratch reports success
372376

373377

374378

‎Source/C64/MainMenuCRT/source/c64defs.i‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
ChrUpArrow = 94
107107
ChrLeftArrow= 95
108108
ChrHome = 19
109+
ChrDelete = 20
109110
ChrFillLeft = 181
110111
ChrFillRight= 182
111112
ChrRun = 131

‎Source/C64/TRHelpScreens/source/Pg_HelpInfo2.asm‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ MsgHelpMenu2:
4040
!tx EscC,EscArgSpaces+1, EscC,EscOptionColor, "<Sh>M", EscC,EscNameColor, " *", EscC,EscSourcesColor, "Meatloaf: Mount/Launch Dxx", ChrReturn
4141
!tx EscC,EscArgSpaces+1, EscC,EscOptionColor, "<Sh>K", EscC,EscNameColor, " +", EscC,EscSourcesColor, "Set as Kernal Replace File", ChrReturn
4242
!tx EscC,EscArgSpaces+1, EscC,EscOptionColor, "<Sh>R", EscC,EscNameColor, " +", EscC,EscSourcesColor, "Set as REU Pre-load/save File", ChrReturn
43+
!tx EscC,EscArgSpaces+1, EscC,EscOptionColor, "<Del>", EscC,EscSourcesColor, " Delete file (SD/USB)", ChrReturn
4344
!tx ChrReturn
4445
!tx EscC,EscNameColor, " *:", EscC,EscSourcesColor, " External HW Required", ChrReturn
4546
!tx EscC,EscNameColor, " +:", EscC,EscSourcesColor, " TeensyROM+ Only", ChrReturn

‎Source/Teensy/MinimalBoot/Common/IO_Handlers/IOH_TeensyROM.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ extern void MenuChange();
214214
extern void HandleExecution();
215215
extern bool PathIsRoot();
216216
extern void LoadDirectory(FS *sourceFS);
217+
extern void FullPathToSelected(char *Path, size_t Size, const char *Name);
217218
extern void FreeDriveDirMenu();
218219
extern void RedirectEmptyDriveDirMenu();
219220
extern void IOHandlerSelectInit();
@@ -977,6 +978,12 @@ void IO1Hndlr_TeensyROM(uint8_t Address, bool R_Wn)
977978
case rCtlShowExtPackagesWAIT:
978979
IO1[rwRegStatus] = rsShowExtPackages; //work this in the main code
979980
break;
981+
case rCtlDeleteFileCheckWAIT:
982+
IO1[rwRegStatus] = rsDeleteFileCheck; //work this in the main code
983+
break;
984+
case rCtlDeleteFileWAIT:
985+
IO1[rwRegStatus] = rsDeleteFile; //work this in the main code
986+
break;
980987
case rCtlMakeStrWAIT_First ... rCtlMakeStrWAIT_Last:
981988
IO1[wRegControl] = Data; //preserve for later use
982989
IO1[rwRegStatus] = rsMakeFilenameStr; //work this in the main code

‎Source/Teensy/MinimalBoot/Common/IO_Handlers/StatusFunctions.c‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,81 @@ FLASHMEM void ShowExtPackages()
13841384
#endif
13851385
}
13861386

1387+
// Delete the highlighted file, from the main menu's INST/DEL key. Two steps, like the NFC
1388+
// tag pair: the check shows the file and answers in rwRegScratch whether it can go, the
1389+
// C64 asks the user, and the delete runs only on a yes. rwRegScratch stays zero on a
1390+
// refusal or a failure, and the message says which.
1391+
// Every message here is PSTR(): a bare literal lands in .rodata, which the linker
1392+
// script places in DTCM, and the menu's own messages already fill enough of it.
1393+
FLASHMEM static bool DeletableSelection()
1394+
{
1395+
if (IO1[rWRegCurrMenuWAIT] == rmtTeensy)
1396+
{
1397+
SendMsgPrintfln(PSTR("Select file from SD or USB only\r"));
1398+
return false;
1399+
}
1400+
1401+
const size_t PathLen = strlen(DriveDirPath);
1402+
if (PathLen && DriveDirPath[PathLen-1] == '*') //a disk image's entries, not files on the drive
1403+
{
1404+
SendMsgPrintfln(PSTR("Can't delete from inside a disk image\r"));
1405+
return false;
1406+
}
1407+
1408+
const uint8_t Type = MenuSource[SelItemFullIdx].ItemType;
1409+
if (Type == rtDirectory || Type == rtNone)
1410+
{
1411+
SendMsgPrintfln(PSTR("Only files can be deleted\r"));
1412+
return false;
1413+
}
1414+
return true;
1415+
}
1416+
1417+
FLASHMEM void DeleteFileCheck()
1418+
{
1419+
char PathMsg[MaxPathLength];
1420+
1421+
SelItemFullIdx = MenuIdxFromRegs(IO1[rwRegCursorItemOnPg]);
1422+
IO1[rwRegScratch] = 0; //needed for GetCurrentFilePathName, and the answer until proven deletable
1423+
const bool PathFits = GetCurrentFilePathName(PathMsg, sizeof PathMsg);
1424+
SendMsgPrintfln(PSTR("Delete File:\r%s\r"), PathMsg);
1425+
1426+
if (!DeletableSelection()) return;
1427+
1428+
if (!PathFits)
1429+
{
1430+
SendMsgPrintfln(PSTR("Path incomplete or too long\r"));
1431+
return;
1432+
}
1433+
1434+
SendMsgPrintfln(PSTR("Delete this file? y/n"));
1435+
IO1[rwRegScratch] = 1;
1436+
}
1437+
1438+
FLASHMEM void DeleteSelectedFile()
1439+
{
1440+
SelItemFullIdx = MenuIdxFromRegs(IO1[rwRegCursorItemOnPg]);
1441+
IO1[rwRegScratch] = 0;
1442+
if (!DeletableSelection()) return; //the cursor hasn't moved since the check, but it's cheap
1443+
1444+
FS *sourceFS = &firstPartition;
1445+
if (IO1[rWRegCurrMenuWAIT] == rmtSD) sourceFS = &SD;
1446+
char FullFilePath[MaxNamePathLength];
1447+
1448+
FullPathToSelected(FullFilePath, sizeof FullFilePath, MenuSource[SelItemFullIdx].Name);
1449+
if (!sourceFS->remove(FullFilePath))
1450+
{
1451+
SendMsgPrintfln(PSTR("Delete failed\r"));
1452+
return;
1453+
}
1454+
1455+
//LoadDirectory's SetMenu starts the page over; put the cursor back where the file was
1456+
const uint16_t Idx = SelItemFullIdx;
1457+
LoadDirectory(sourceFS);
1458+
SetCursorToItemNum(Idx < NumItemsFull ? Idx : NumItemsFull-1);
1459+
IO1[rwRegScratch] = 1;
1460+
}
1461+
13871462
//Unsized so the static_assert below can compare its length against rsNumStatusTypes
13881463
void (*StatusFunction[])() = //match RegStatusTypes order
13891464
{
@@ -1422,6 +1497,8 @@ void (*StatusFunction[])() = //match RegStatusTypes order
14221497
&MakeExtHostStr, // rsMakeExtHostStr
14231498
&UninstallExtHost, // rsUninstallExtHost
14241499
&ShowExtPackages, // rsShowExtPackages
1500+
&DeleteFileCheck, // rsDeleteFileCheck
1501+
&DeleteSelectedFile, // rsDeleteFile
14251502
};
14261503
static_assert(sizeof(StatusFunction) / sizeof(StatusFunction[0]) == rsNumStatusTypes,
14271504
"StatusFunction[] / RegStatusTypes count mismatch");

‎Source/Teensy/MinimalBoot/Common/Menu_Regs.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,10 @@ enum RegStatusTypes //rwRegStatus, match StatusFunction order
290290
rsMakeExtHostStr = 0x20,
291291
rsUninstallExtHost = 0x21,
292292
rsShowExtPackages = 0x22,
293+
rsDeleteFileCheck = 0x23, //the highlighted SD/USB file: show it, and in rwRegScratch whether it can go
294+
rsDeleteFile = 0x24, //remove it and reload the listing; rwRegScratch reports success
293295

294-
rsNumStatusTypes = 0x23,
296+
rsNumStatusTypes = 0x25,
295297

296298
rsReady = 0x5a, //FW->64 (Rd) update finished (done, abort, or otherwise)
297299
rsC64Message = 0xa5, //FW->64 (Rd) message for the C64, set to continue when finished
@@ -377,6 +379,8 @@ enum RegCtlCommands
377379
rCtlBootComplete = 58, // menu finished booting: sets BootComplete, reported by the version command
378380
rCtlBootInProgress = 59, // clears BootComplete: a remote launch on reset returned and the menu is finishing its boot
379381
rCtlShowExtPackagesWAIT = 60, // the /VMS packages on SD, sent as one message per row
382+
rCtlDeleteFileCheckWAIT = 61, // show the highlighted SD/USB file and, in rwRegScratch, whether it can be deleted
383+
rCtlDeleteFileWAIT = 62, // delete it and reload the listing; rwRegScratch reports success
380384

381385
};
382386

‎Source/Teensy/TRMenuFiles/ROMs/TRHelpScreens.prg.h‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,21 @@ PROGMEM static const unsigned char TRHelpScreens_prg[] = {
153153
0x45, 0x0d, 0x01, 0x81, 0x01, 0x04, 0x3c, 0xd3, 0x48, 0x3e, 0xd2, 0x01,
154154
0x06, 0x20, 0x2b, 0x01, 0x05, 0xd3, 0x45, 0x54, 0x20, 0x41, 0x53, 0x20,
155155
0xd2, 0xc5, 0xd5, 0x20, 0xd0, 0x52, 0x45, 0x2d, 0x4c, 0x4f, 0x41, 0x44,
156-
0x2f, 0x53, 0x41, 0x56, 0x45, 0x20, 0xc6, 0x49, 0x4c, 0x45, 0x0d, 0x0d,
157-
0x01, 0x06, 0x20, 0x20, 0x20, 0x2a, 0x3a, 0x01, 0x05, 0x20, 0xc5, 0x58,
158-
0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x20, 0xc8, 0xd7, 0x20, 0xd2, 0x45,
159-
0x51, 0x55, 0x49, 0x52, 0x45, 0x44, 0x0d, 0x01, 0x06, 0x20, 0x20, 0x20,
160-
0x2b, 0x3a, 0x01, 0x05, 0x20, 0xd4, 0x45, 0x45, 0x4e, 0x53, 0x59, 0xd2,
161-
0xcf, 0xcd, 0x2b, 0x20, 0xcf, 0x4e, 0x4c, 0x59, 0x0d, 0x0d, 0x01, 0x03,
162-
0x20, 0xc6, 0x4f, 0x52, 0x20, 0x41, 0x44, 0x44, 0x49, 0x54, 0x49, 0x4f,
163-
0x4e, 0x41, 0x4c, 0x20, 0x48, 0x45, 0x4c, 0x50, 0x2c, 0x20, 0x53, 0x45,
164-
0x45, 0x3a, 0x0d, 0x01, 0x05, 0x20, 0x47, 0x49, 0x54, 0x48, 0x55, 0x42,
165-
0x2e, 0x43, 0x4f, 0x4d, 0x2f, 0xd3, 0x45, 0x4e, 0x53, 0x4f, 0x52, 0x49,
166-
0x55, 0x4d, 0xc5, 0x4d, 0x42, 0x45, 0x44, 0x44, 0x45, 0x44, 0x2f, 0xd4,
167-
0x45, 0x45, 0x4e, 0x53, 0x59, 0xd2, 0xcf, 0xcd, 0x00, 0x00
156+
0x2f, 0x53, 0x41, 0x56, 0x45, 0x20, 0xc6, 0x49, 0x4c, 0x45, 0x0d, 0x01,
157+
0x81, 0x01, 0x04, 0x3c, 0xc4, 0x45, 0x4c, 0x3e, 0x01, 0x05, 0x20, 0x20,
158+
0xc4, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x20, 0x46, 0x49, 0x4c, 0x45, 0x20,
159+
0x28, 0xd3, 0xc4, 0x2f, 0xd5, 0xd3, 0xc2, 0x29, 0x0d, 0x0d, 0x01, 0x06,
160+
0x20, 0x20, 0x20, 0x2a, 0x3a, 0x01, 0x05, 0x20, 0xc5, 0x58, 0x54, 0x45,
161+
0x52, 0x4e, 0x41, 0x4c, 0x20, 0xc8, 0xd7, 0x20, 0xd2, 0x45, 0x51, 0x55,
162+
0x49, 0x52, 0x45, 0x44, 0x0d, 0x01, 0x06, 0x20, 0x20, 0x20, 0x2b, 0x3a,
163+
0x01, 0x05, 0x20, 0xd4, 0x45, 0x45, 0x4e, 0x53, 0x59, 0xd2, 0xcf, 0xcd,
164+
0x2b, 0x20, 0xcf, 0x4e, 0x4c, 0x59, 0x0d, 0x0d, 0x01, 0x03, 0x20, 0xc6,
165+
0x4f, 0x52, 0x20, 0x41, 0x44, 0x44, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x41,
166+
0x4c, 0x20, 0x48, 0x45, 0x4c, 0x50, 0x2c, 0x20, 0x53, 0x45, 0x45, 0x3a,
167+
0x0d, 0x01, 0x05, 0x20, 0x47, 0x49, 0x54, 0x48, 0x55, 0x42, 0x2e, 0x43,
168+
0x4f, 0x4d, 0x2f, 0xd3, 0x45, 0x4e, 0x53, 0x4f, 0x52, 0x49, 0x55, 0x4d,
169+
0xc5, 0x4d, 0x42, 0x45, 0x44, 0x44, 0x45, 0x44, 0x2f, 0xd4, 0x45, 0x45,
170+
0x4e, 0x53, 0x59, 0xd2, 0xcf, 0xcd, 0x00, 0x00
168171
};
169172

170173
#endif /* TRHELPSCREENS_PRG_H */

0 commit comments

Comments
 (0)