* Copyright (C) 1999 Jonathan St-André
* Copyright (C) 1999 Hugo Villeneuve <hugo@hugovil.com>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ * This file is released under the GPLv2
*/
+#include "config.h"
+
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+#ifdef HAVE_LIBREADLINE
+#include <readline/readline.h>
+#include <readline/history.h>
+#endif /* HAVE_LIBREADLINE */
#include "common.h"
#include "cpu8051.h"
#include "options.h"
#include "hexfile.h"
#include "keyboard.h"
+#include "scanner.h"
#include "menu.h"
extern struct options_t options;
-void
-menu_prompt(void)
+#define YY_NULL 0
+
+#define MENU_PROMPT "-> "
+
+int
+menu_get_input(char *buf, ssize_t size)
{
- printf("-> ");
+ char *line;
+ int max_len;
+
+ max_len = size - 2;
+
+ if (feof(yyin))
+ return YY_NULL;
+
+#ifdef HAVE_LIBREADLINE
+ /* Get the input line, and if non-empty, place it in the history. */
+ line = readline(MENU_PROMPT);
+ if (!line)
+ return YY_NULL;
+
+ if (line && *line)
+ add_history(line);
+
+ if ((int) strlen(line) > max_len) {
+ printf("input line too long");
+ return YY_NULL;
+ }
+
+ strcpy(buf, line);
+
+ /* Readline never gives you the last '\n', so add it back for Lex. */
+ strcat(buf, "\n");
+
+ free(line);
+#else
+ /* It's okay to print a prompt if we are redirecting stdout,
+ * as long as stdin is still a tty. Otherwise, don't print
+ * a prompt at all if stdin is redirected.
+ */
+ (void) fputs(MENU_PROMPT, stdout);
+ (void) fflush(stdout); /* for svr4 */
+ line = fgets(buf, max_len, stdin);
+ if (!line)
+ return YY_NULL;
+#endif
+
+ return strlen(buf);
}
void
menu_display_usage(void)
{
- printf(" *******************\n"
- " * 8051 Emulator *\n"
- " *******************\n"
- "\n"
- " Available commands, [ ] = options\n"
+ int id;
+
+ printf(" " PACKAGE_NAME " commands, [] = options:\n"
"\n"
- " Set Breakpoint.............. SB [address]\n"
- " Remove Breakpoint........... RB [address]\n"
- " address = all:"
- " clear all breakpoints\n"
- " Display Breakpoint(s)....... DB\n"
- " Dump External Data Memory... DE [address] [size]\n"
- " Dump Internal Data Memory... DI [address] [size]\n"
- " Dump Program Memory......... DP [address] [size]\n"
- " Display Registers........... DR\n"
- " Help........................ H or ?\n"
- " Modify External Data Memory. ME address value\n"
- " Modify Internal Data Memory. MI address value\n"
- " Modify Program Memory....... MP address value\n"
- " Modify Register............. MR register value\n"
- " Quit........................ Q\n"
- " Run......................... R [number of instructions]\n"
- " Step........................ S\n"
- " Unassemble.................. U [address]"
- " [number of instructions]\n"
- " Reset processor............. Z\n"
- " Reset general-purpose timer. ZT\n");
+ " sb [ADDRESS] Set breakpoint at PC or ADDRESS\n"
+ " rb [ADDRESS] Remove breakpoint at PC or ADDRESS\n"
+ " ADDRESS = all: clear all breakpoints\n"
+ " db Display breakpoints\n"
+ " de ADDRESS NUM Dump NUM bytes from ADDRESS in external data"
+ " memory\n"
+ " di ADDRESS NUM Dump NUM bytes from ADDRESS in internal data"
+ " memory\n"
+ " dp ADDRESS NUM Dump NUM bytes from ADDRESS in program"
+ " memory\n"
+ " dr Display registers\n"
+ " h or ? Display this help menu\n"
+ " q Quit\n"
+ " r [NUM] Run until breakpoint or for NUM "
+ "instructions\n"
+ " s Step (execute 1 instruction)\n"
+ " u [ADDRESS] [NUM] Unassemble NUM instructions at ADDRESS\n"
+ " we ADDRESS VAL Write VAL at ADDRESS in external data memory\n"
+ " wi ADDRESS VAL Write VAL at ADDRESS in internal data memory\n"
+ " wp ADDRESS VAL Write VAL at ADDRESS in program memory\n"
+ " wr REGISTER VAL Write VAL at REGISTER (REGISTER is name of"
+ " register)\n"
+ " z Reset processor\n"
+ " zt ID Reset emulator timer ID (");
+
+ for (id = 0; id < GP_TIMERS_COUNT; id++) {
+ printf("%c", 'A' + id);
+ if (id < (GP_TIMERS_COUNT - 1))
+ printf(", ");
+ }
+ printf(")\n");
}
/* Disassemble NumberInst instructions at Address */
static void
console_dump_sfr_registers_compact(void)
{
+ int id;
unsigned char PSW = cpu8051_ReadD(_PSW_);
int BankSelect = (PSW & 0x18);
printf("---------------------------------------------------------------"
"-------\n");
- printf("| General-purpose Timer: %08d |\n", gp_timer_read());
- printf("-----------------------------------\n");
+ for (id = 0; id < GP_TIMERS_COUNT; id++)
+ printf("| Emulator timer %c: %08d |\n", 'A' + id, gp_timer_read(id));
+
+ printf("------------------------------\n");
+
+
}
/* Show CPU registers */