changeset 216:cd66e13eccf3

fc-simtool pnn-erase command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 18:03:55 +0000
parents 3a2f43460582
children 52c0da56e979
files simtool/dispatch.c simtool/pnnprog.c
diffstat 2 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simtool/dispatch.c	Sun Mar 07 08:35:57 2021 +0000
+++ b/simtool/dispatch.c	Sun Mar 07 18:03:55 2021 +0000
@@ -62,6 +62,7 @@
 extern int cmd_plmnsel_write();
 extern int cmd_plmnsel_write_list();
 extern int cmd_pnn_dump();
+extern int cmd_pnn_erase();
 extern int cmd_pnn_write();
 extern int cmd_readbin();
 extern int cmd_readef();
@@ -191,6 +192,7 @@
 	{"plmnsel-write", 2, 2, 0, cmd_plmnsel_write},
 	{"plmnsel-write-list", 1, 1, 0, cmd_plmnsel_write_list},
 	{"pnn-dump", 0, 0, 1, cmd_pnn_dump},
+	{"pnn-erase", 1, 2, 0, cmd_pnn_erase},
 	{"pnn-write", 2, 3, 0, cmd_pnn_write},
 	{"quit", 0, 0, 0, good_exit},
 	{"readbin", 2, 2, 1, cmd_readbin},
--- a/simtool/pnnprog.c	Sun Mar 07 08:35:57 2021 +0000
+++ b/simtool/pnnprog.c	Sun Mar 07 18:03:55 2021 +0000
@@ -5,6 +5,8 @@
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <strings.h>
 #include "curfile.h"
 
 static u_char *
@@ -65,3 +67,45 @@
 		*dp++ = 0xFF;
 	return update_rec_op(recno, 0x04, record, curfile_record_len);
 }
+
+cmd_pnn_erase(argc, argv)
+	char **argv;
+{
+	int rc;
+	unsigned recno, startrec, endrec;
+	u_char record[255];
+
+	rc = select_ef_pnn();
+	if (rc < 0)
+		return(rc);
+	startrec = strtoul(argv[1], 0, 0);
+	if (startrec < 1 || startrec > curfile_record_count) {
+		fprintf(stderr,
+			"error: specified starting record number is invalid\n");
+		return(-1);
+	}
+	if (!argv[2])
+		endrec = startrec;
+	else if (!strcmp(argv[2], "end"))
+		endrec = curfile_record_count;
+	else {
+		endrec = strtoul(argv[2], 0, 0);
+		if (endrec < 1 || endrec > curfile_record_count) {
+			fprintf(stderr,
+			"error: specified final record number is invalid\n");
+			return(-1);
+		}
+		if (startrec > endrec) {
+			fprintf(stderr,
+				"error: reverse record range specified\n");
+			return(-1);
+		}
+	}
+	memset(record, 0xFF, curfile_record_len);
+	for (recno = startrec; recno <= endrec; recno++) {
+		rc = update_rec_op(recno, 0x04, record, curfile_record_len);
+		if (rc < 0)
+			return(rc);
+	}
+	return(0);
+}