summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--avr/cli_readline.c412
-rw-r--r--avr/con-utils.c1
-rw-r--r--avr/mmc.c106
-rw-r--r--include/config.h13
-rw-r--r--z180/config.inc11
-rw-r--r--z180/ddtz.1806
6 files changed, 343 insertions, 206 deletions
diff --git a/avr/cli_readline.c b/avr/cli_readline.c
index 93a0355..49ceee7 100644
--- a/avr/cli_readline.c
+++ b/avr/cli_readline.c
@@ -14,18 +14,187 @@
#include "common.h"
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <ctype.h>
#include "config.h"
#include "con-utils.h"
+#include "print-utils.h"
#include "command.h"
#include "cli_readline.h"
+
+
+/************************************************************************************************/
+/* TODO:
+ *
+ */
+
+#define ESC 0x1b
+
+#define KEY_TAB '\t' // TAB key
+#define KEY_CR '\r' // RETURN key
+#define KEY_BACKSPACE '\b' // Backspace key
+#define KEY_ESCAPE 0x1B // ESCAPE (pressed twice)
+
+#define KEY_DOWN 0x80 // Down arrow key
+#define KEY_UP 0x81 // Up arrow key
+#define KEY_LEFT 0x82 // Left arrow key
+#define KEY_RIGHT 0x83 // Right arrow key
+#define KEY_HOME 0x84 // Home key
+#define KEY_DC 0x85 // Delete character key
+#define KEY_IC 0x86 // Ins char/toggle ins mode key
+#define KEY_NPAGE 0x87 // Next-page key
+#define KEY_PPAGE 0x88 // Previous-page key
+#define KEY_END 0x89 // End key
+#define KEY_BTAB 0x8A // Back tab key
+#define KEY_F1 0x8B // Function key F1
+#define KEY_F(n) (KEY_F1+(n)-1) // Space for additional 12 function keys
+
+
+struct fkey_tbl_s {
+ const FLASH char *sequence; /* ESC Sequence */
+ int code; /* Keycode */
+};
+
+//typedef const FLASH struct fkey_tbl_s fkey_tbl_t;
+
+#define FKEY_TBL_ITEM(_seq, _code) { FSTR(#_seq), _code }
+
+
+
+static const FLASH struct fkey_tbl_s fkey_table[] = {
+
+FKEY_TBL_ITEM(B, KEY_DOWN), // Down arrow key
+FKEY_TBL_ITEM(A, KEY_UP), // Up arrow key
+FKEY_TBL_ITEM(D, KEY_LEFT), // Left arrow key
+FKEY_TBL_ITEM(C, KEY_RIGHT), // Right arrow key
+FKEY_TBL_ITEM(1~, KEY_HOME), // Home key
+FKEY_TBL_ITEM(3~, KEY_DC), // Delete character key
+FKEY_TBL_ITEM(2~, KEY_IC), // Ins char/toggle ins mode key
+FKEY_TBL_ITEM(6~, KEY_NPAGE), // Next-page key
+FKEY_TBL_ITEM(5~, KEY_PPAGE), // Previous-page key
+FKEY_TBL_ITEM(4~, KEY_END), // End key
+FKEY_TBL_ITEM(Z, KEY_BTAB), // Back tab key
+/* VT400: */
+FKEY_TBL_ITEM(11~, KEY_F(1)), // Function key F1
+FKEY_TBL_ITEM(12~, KEY_F(2)), // Function key F2
+FKEY_TBL_ITEM(13~, KEY_F(3)), // Function key F3
+FKEY_TBL_ITEM(14~, KEY_F(4)), // Function key F4
+FKEY_TBL_ITEM(15~, KEY_F(5)), // Function key F5
+/* Linux consoe */
+FKEY_TBL_ITEM([A, KEY_F(1)), // Function key F1
+FKEY_TBL_ITEM([B, KEY_F(2)), // Function key F2
+FKEY_TBL_ITEM([C, KEY_F(3)), // Function key F3
+FKEY_TBL_ITEM([D, KEY_F(4)), // Function key F4
+FKEY_TBL_ITEM([E, KEY_F(5)), // Function key F5
+
+FKEY_TBL_ITEM(17~, KEY_F(6)), // Function key F6
+FKEY_TBL_ITEM(18~, KEY_F(7)), // Function key F7
+FKEY_TBL_ITEM(19~, KEY_F(8)), // Function key F8
+FKEY_TBL_ITEM(20~, KEY_F(9)), // Function key F9
+FKEY_TBL_ITEM(21~, KEY_F(10)), // Function key F10
+FKEY_TBL_ITEM(23~, KEY_F(11)), // Function key F11
+FKEY_TBL_ITEM(24~, KEY_F(12)), // Function key F12
+{ NULL } /* Mark end of table */
+};
+
+
+
+typedef enum {
+ STATE_GROUND,
+ STATE_ESCAPE,
+ STATE_CSI_ENTRY
+} vtparse_state_t;
+
+#define CHB_SIZE 15
+
+static
+int vt_parse (void)
+{
+ static vtparse_state_t state = STATE_GROUND;
+ char buf[CHB_SIZE+1];
+ uint8_t param[2];
+ uint8_t i_buf;
+ uint8_t i_param;
+ int ch;
+
+
+ while (1) {
+ ch = my_getchar(1);
+// debug_getch(state, ch);
+
+ switch (state) {
+ case STATE_GROUND:
+ if (ch == ESC) {
+ state = STATE_ESCAPE;
+ continue;
+ }
+ if (ch == 0x7F) // BACKSPACE on VT200 sends DEL char
+ ch = KEY_BACKSPACE; // map it to '\b'
+ break;
+ case STATE_ESCAPE:
+ if (ch < 0)
+ continue;
+
+ if (ch == '[') {
+ state = STATE_CSI_ENTRY;
+ param[0] = param[1] = 0;
+ i_buf = 0;
+ i_param = 0;
+ continue;
+ }
+ state = STATE_GROUND;
+ break;
+ case STATE_CSI_ENTRY:
+ if (ch < 0)
+ continue;
+
+ buf[i_buf] = ch;
+ if (i_buf < CHB_SIZE)
+ i_buf++;
+ if (ch == ';') {
+ i_param++;
+ continue;
+ }
+ if (isdigit(ch)) {
+ if (i_param < 2)
+ param[i_param] = param[i_param] * 10 + ch - '0';
+ continue;
+ }
+ if (ch >= '@' && ch <= '~' && ch != '[') {
+ buf[i_buf] = '\0';
+ int_fast8_t i = 0;
+ while (fkey_table[i].sequence) {
+ if (! strcmp_P (buf, fkey_table[i].sequence)) {
+ ch = fkey_table[i].code;
+ break;
+ }
+ i++;
+ }
+ if (fkey_table[i].sequence == NULL) {
+ ch = '$'; /* KEY_ESCAPE; */
+ }
+ }
+ state = STATE_GROUND;
+ break;
+ }
+ break; /* while */
+ }
+
+ return ch;
+}
+
+/************************************************************************************************/
+
+
char console_buffer[CONFIG_SYS_CBSIZE + 1]; /* console I/O buffer */
+#ifndef CONFIG_CMDLINE_EDITING
static const FLASH char erase_seq[] = "\b \b"; /* erase sequence */
static const FLASH char tab_seq[] = " "; /* used to expand TABs */
-#ifndef CONFIG_CMDLINE_EDITING
static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen)
{
char *s;
@@ -65,63 +234,72 @@ static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen)
* Author: Janghoon Lyu <nandy@mizi.com>
*/
-#define putnstr(str, n) printf_P(PSTR("%.*s"), (int)n, str)
+static void putnstr(char *str, int n)
+{
+ /* printf_P(PSTR("%.*s"), (int)n, str) */
+ while (n-- && *str)
+ putchar(*str++);
+}
-#define CTL_CH(c) ((c) - 'a' + 1)
+
+#define CTL_CH(c) ((c) - 'a' + 1)
#define CTL_BACKSPACE ('\b')
-#define DEL ((char)255)
-#define DEL7 ((char)127)
-#define CREAD_HIST_CHAR ('!')
+#define DEL ((char)255)
+#define DEL7 ((char)127)
#define getcmd_putch(ch) putchar(ch)
-#define getcmd_getch() my_getchar(1)
+#define getcmd_getch() vt_parse()
#define getcmd_cbeep() getcmd_putch('\a')
-#define HIST_MAX 5
-#define HIST_SIZE CONFIG_SYS_CBSIZE
+#define HIST_MAX 20
-static int hist_max;
-static int hist_add_idx;
-static int hist_cur = -1;
-static unsigned hist_num;
+static int_fast8_t hist_max;
+static int_fast8_t hist_add_idx;
+static int_fast8_t hist_cur = -1;
static char *hist_list[HIST_MAX];
-static char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */
-
-#define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
static void hist_init(void)
{
- int i;
+ int_fast8_t i;
hist_max = 0;
hist_add_idx = 0;
hist_cur = -1;
- hist_num = 0;
for (i = 0; i < HIST_MAX; i++) {
- hist_list[i] = hist_lines[i];
- hist_list[i][0] = '\0';
+ hist_list[i] = NULL;
}
}
static void cread_add_to_hist(char *line)
{
- strcpy(hist_list[hist_add_idx], line);
+ if (hist_max) {
+ int_fast8_t last = hist_add_idx;
+ if (--last < 0)
+ last = hist_max;
+
+ if (!strcmp(line, hist_list[last]))
+ return;
+ }
- if (++hist_add_idx >= HIST_MAX)
- hist_add_idx = 0;
+ char *p = strdup(line);
+ if (p) {
+ free(hist_list[hist_add_idx]);
+ hist_list[hist_add_idx] = p;
- if (hist_add_idx > hist_max)
- hist_max = hist_add_idx;
+ if (++hist_add_idx >= HIST_MAX)
+ hist_add_idx = 0;
- hist_num++;
+ if (hist_add_idx > hist_max)
+ hist_max = hist_add_idx;
+ }
}
static char *hist_prev(void)
{
char *ret;
- int old_cur;
+ int_fast8_t old_cur;
if (hist_cur < 0)
return NULL;
@@ -161,55 +339,36 @@ static char *hist_next(void)
return ret;
}
-#ifndef CONFIG_CMDLINE_EDITING
-static void cread_print_hist_list(void)
-{
- int i;
- unsigned n;
-
- n = hist_num - hist_max;
- i = hist_add_idx + 1;
- while (1) {
- if (i > hist_max)
- i = 0;
- if (i == hist_add_idx)
- break;
- printf_P(PSTR("%s\n"), hist_list[i]);
- n++;
- i++;
- }
+#define BEGINNING_OF_LINE() { \
+ while (num) { \
+ getcmd_putch(CTL_BACKSPACE); \
+ num--; \
+ } \
}
-#endif /* CONFIG_CMDLINE_EDITING */
-#define BEGINNING_OF_LINE() { \
- while (num) { \
- getcmd_putch(CTL_BACKSPACE); \
- num--; \
- } \
+#define ERASE_TO_EOL() { \
+ if (num < eol_num) { \
+ /* printf_P(PSTR("%*S"), (int)(eol_num - num), PSTR("")); */ \
+ print_blanks(eol_num - num); \
+ do { \
+ getcmd_putch(CTL_BACKSPACE); \
+ } while (--eol_num > num); \
+ } \
}
-#define ERASE_TO_EOL() { \
- if (num < eol_num) { \
- printf_P(PSTR("%*S"), (int)(eol_num - num), PSTR("")); \
- do { \
- getcmd_putch(CTL_BACKSPACE); \
- } while (--eol_num > num); \
- } \
+#define REFRESH_TO_EOL() { \
+ if (num < eol_num) { \
+ wlen = eol_num - num; \
+ putnstr(buf + num, wlen); \
+ num = eol_num; \
+ } \
}
-#define REFRESH_TO_EOL() { \
- if (num < eol_num) { \
- wlen = eol_num - num; \
- putnstr(buf + num, wlen); \
- num = eol_num; \
- } \
-}
-
-static void cread_add_char(char ichar, int insert, unsigned long *num,
- unsigned long *eol_num, char *buf, unsigned long len)
+static void cread_add_char(char ichar, bool insert, uint_fast8_t *num,
+ uint_fast8_t *eol_num, char *buf, uint_fast8_t len)
{
- unsigned long wlen;
+ uint_fast8_t wlen;
/* room ??? */
if (insert || *num == *eol_num) {
@@ -239,9 +398,9 @@ static void cread_add_char(char ichar, int insert, unsigned long *num,
}
}
-static void cread_add_str(char *str, int strsize, int insert,
- unsigned long *num, unsigned long *eol_num,
- char *buf, unsigned long len)
+static void cread_add_str(char *str, int strsize, bool insert,
+ uint_fast8_t *num, uint_fast8_t *eol_num,
+ char *buf, uint_fast8_t len)
{
while (strsize--) {
cread_add_char(*str, insert, num, eol_num, buf, len);
@@ -249,15 +408,13 @@ static void cread_add_str(char *str, int strsize, int insert,
}
}
-static int cread_line(const FLASH char *const prompt, char *buf, unsigned int *len)
+static int cread_line(const FLASH char *const prompt, char *buf, uint_fast8_t *len)
{
- unsigned long num = 0;
- unsigned long eol_num = 0;
- unsigned long wlen;
- char ichar;
- int insert = 1;
- int esc_len = 0;
- char esc_save[8];
+ uint_fast8_t num = 0;
+ uint_fast8_t eol_num = 0;
+ uint_fast8_t wlen;
+ int ichar;
+ bool insert = 1;
int init_len = strlen(buf);
(void) prompt;
@@ -273,83 +430,32 @@ static int cread_line(const FLASH char *const prompt, char *buf, unsigned int *l
break;
}
- /*
- * handle standard linux xterm esc sequences for arrow key, etc.
- */
- if (esc_len != 0) {
- if (esc_len == 1) {
- if (ichar == '[') {
- esc_save[esc_len] = ichar;
- esc_len = 2;
- } else {
- cread_add_str(esc_save, esc_len,
- insert, &num, &eol_num,
- buf, *len);
- esc_len = 0;
- }
- continue;
- }
-
- switch (ichar) {
- case 'D': /* <- key */
- ichar = CTL_CH('b');
- esc_len = 0;
- break;
- case 'C': /* -> key */
- ichar = CTL_CH('f');
- esc_len = 0;
- break; /* pass off to ^F handler */
- case 'H': /* Home key */
- ichar = CTL_CH('a');
- esc_len = 0;
- break; /* pass off to ^A handler */
- case 'A': /* up arrow */
- ichar = CTL_CH('p');
- esc_len = 0;
- break; /* pass off to ^P handler */
- case 'B': /* down arrow */
- ichar = CTL_CH('n');
- esc_len = 0;
- break; /* pass off to ^N handler */
- default:
- esc_save[esc_len++] = ichar;
- cread_add_str(esc_save, esc_len, insert,
- &num, &eol_num, buf, *len);
- esc_len = 0;
- continue;
- }
- }
switch (ichar) {
- case 0x1b:
- if (esc_len == 0) {
- esc_save[esc_len] = ichar;
- esc_len = 1;
- } else {
- my_puts_P(PSTR("impossible condition #876\n"));
- esc_len = 0;
- }
- break;
+ case KEY_HOME:
case CTL_CH('a'):
BEGINNING_OF_LINE();
break;
- case CTL_CH('c'): /* ^C - break */
- *buf = '\0'; /* discard input */
+ case CTL_CH('c'): /* ^C - break */
+ *buf = '\0'; /* discard input */
return -1;
- case CTL_CH('f'):
+ case KEY_RIGHT:
+ case CTL_CH('f'): /* forward-char */
if (num < eol_num) {
getcmd_putch(buf[num]);
num++;
}
break;
- case CTL_CH('b'):
+ case KEY_LEFT:
+ case CTL_CH('b'): /* backward-char */
if (num) {
getcmd_putch(CTL_BACKSPACE);
num--;
}
break;
- case CTL_CH('d'):
+ case KEY_DC:
+ case CTL_CH('d'): /* delete-char */
if (num < eol_num) {
wlen = eol_num - num - 1;
if (wlen) {
@@ -364,23 +470,24 @@ static int cread_line(const FLASH char *const prompt, char *buf, unsigned int *l
eol_num--;
}
break;
- case CTL_CH('k'):
+ case CTL_CH('k'): /* kill-line */
ERASE_TO_EOL();
break;
case CTL_CH('e'):
REFRESH_TO_EOL();
break;
+ case KEY_IC:
case CTL_CH('o'):
insert = !insert;
break;
case CTL_CH('x'):
- case CTL_CH('u'):
+ case CTL_CH('u'): /* kill-whole-line */
BEGINNING_OF_LINE();
ERASE_TO_EOL();
break;
case DEL:
case DEL7:
- case 8:
+ case 8: /* backward-delete-char */
if (num) {
wlen = eol_num - num;
num--;
@@ -394,14 +501,14 @@ static int cread_line(const FLASH char *const prompt, char *buf, unsigned int *l
eol_num--;
}
break;
- case CTL_CH('p'):
- case CTL_CH('n'):
+ case KEY_UP:
+ case CTL_CH('p'): /* previous-history */
+ case KEY_DOWN:
+ case CTL_CH('n'): /* next-history */
{
char *hline;
- esc_len = 0;
-
- if (ichar == CTL_CH('p'))
+ if (ichar == CTL_CH('p') || ichar == KEY_UP)
hline = hist_prev();
else
hline = hist_next();
@@ -446,15 +553,16 @@ static int cread_line(const FLASH char *const prompt, char *buf, unsigned int *l
}
#endif
default:
- cread_add_char(ichar, insert, &num, &eol_num, buf,
- *len);
+ if (isprint(ichar))
+ cread_add_char(ichar, insert, &num, &eol_num, buf,
+ *len);
break;
}
}
*len = eol_num;
buf[eol_num] = '\0'; /* lose the newline */
- if (buf[0] && buf[0] != CREAD_HIST_CHAR)
+ if (buf[0] /* && buf[0] != CREAD_HIST_CHAR */)
cread_add_to_hist(buf);
hist_cur = hist_add_idx;
@@ -469,9 +577,9 @@ static int cli_readline_into_buffer(const FLASH char *const prompt, char *buffer
{
char *p = buffer;
#ifdef CONFIG_CMDLINE_EDITING
- unsigned int len = CONFIG_SYS_CBSIZE;
+ uint_fast8_t len = CONFIG_SYS_CBSIZE;
int rc;
- static int initted;
+ static bool initted;
if (!initted) {
hist_init();
diff --git a/avr/con-utils.c b/avr/con-utils.c
index 5ee1ff1..4a96771 100644
--- a/avr/con-utils.c
+++ b/avr/con-utils.c
@@ -64,6 +64,7 @@ static uint_fast8_t ctrlc_was_pressed;
uint_fast8_t ctrlc(void)
{
+ bg_shed();
if (!ctrlc_disabled) {
switch (serial_getc()) {
case 0x03: /* ^C - Control C */
diff --git a/avr/mmc.c b/avr/mmc.c
index 7c4da24..d45cdf5 100644
--- a/avr/mmc.c
+++ b/avr/mmc.c
@@ -7,6 +7,7 @@
#include "common.h"
#include <stdbool.h>
+#include <util/atomic.h>
#include "timer.h"
#include "spi.h"
#include "diskio.h"
@@ -19,29 +20,29 @@
/* TODO: config.h cofig macros */
-//#define SD_CD_0 SBIT(PORT,) /* Card detect switch */
+//#define SD_CD_0 SBIT(PORT,) /* Card detect switch */
//#define SD_CD_0_IN SBIT(PIN,)
//#define SD_CD_0_DDR SBIT(DDR,)
-//#define SD_WP_0 SBIT(PORT,) /* Write protect switch */
+//#define SD_WP_0 SBIT(PORT,) /* Write protect switch */
//#define SD_WP_0_IN SBIT(PIN,)
//#define SD_WP_0_DDR SBIT(DDR,)
-#define SD_CS_0 SBIT(PORTB,0) /* Chip select pin */
-#define SD_CS_0_IN SBIT(PINB,0)
+#define SD_CS_0 SBIT(PORTB,0) /* Chip select/Card sense pin */
+//#define SD_CS_0_IN SBIT(PINB,0)
#define SD_CS_0_DDR SBIT(DDRB,0)
-//#define SD_CD_1 SBIT(PORTG,3) /* Card detect switch */
-//#define SD_CD_1_IN SBIT(PING,3)
-//#define SD_CD_1_DDR SBIT(DDRG,3)
+#define SD_CD_1 SBIT(PORTG,3) /* Card detect switch */
+#define SD_CD_1_IN SBIT(PING,3)
+#define SD_CD_1_DDR SBIT(DDRG,3)
-//#define SD_WP_1 SBIT(PORTG,5) /* Write protect switch */
+//#define SD_WP_1 SBIT(PORTG,5) /* Write protect switch */
//#define SD_WP_1_IN SBIT(PING,5)
//#define SD_WP_1_DDR SBIT(DDRG,5)
-#define SD_CS_1 SBIT(PORTG,4) /* Chip select pin */
-#define SD_CS_1_IN SBIT(PING,4)
+#define SD_CS_1 SBIT(PORTG,4) /* Chip select/Card sense pin */
+//#define SD_CS_1_IN SBIT(PING,4)
#define SD_CS_1_DDR SBIT(DDRG,4)
@@ -115,7 +116,7 @@ int wait_ready (void) /* 1:OK, 0:Timeout */
static
void deselect(BYTE drv)
{
- //debug("*** enter deselect()\n");
+ //debug("*** enter deselect(%.2x)\n", drv);
if (drv == 0)
SD_CS_0 = 1;
else {
@@ -132,8 +133,8 @@ void deselect(BYTE drv)
if (drv == 0) {
#ifdef SD_CS_0_IN
- SD_CS_0_DDR = 0;
- SD_CS_0 = 0;
+ SD_CS_0_DDR = 0; /* Input */
+ SD_CS_0 = 0; /* No Pullup */
#endif
} else {
#ifdef SD_CS_1_IN
@@ -141,7 +142,7 @@ void deselect(BYTE drv)
SD_CS_1 = 0;
#endif
}
- //debug("*** exit deselect()\n");
+ //debug("*** exit deselect(%.2x)\n", drv);
}
/*-----------------------------------------------------------------------*/
@@ -151,7 +152,7 @@ void deselect(BYTE drv)
static
int select(BYTE drv) /* 1:Successful, 0:Timeout */
{
- //debug("*** enter select()\n");
+ //debug("*** enter select(%.2x)\n", drv);
if (drv == 0) {
#ifdef SD_CS_0_IN
SD_CS_0 = 1;
@@ -193,7 +194,7 @@ int select(BYTE drv) /* 1:Successful, 0:Timeout */
static
void power_on(BYTE drv)
{
- //debug("*** enter power_on()\n");
+ //debug("*** enter power_on(%.2x)\n", drv);
if (drv == 0) {
#ifdef SD_PWR_0
@@ -209,13 +210,13 @@ void power_on(BYTE drv)
for (uint32_t to = get_timer(0); get_timer(to) < 30;)
; /* Wait for 30ms */
#endif
- //debug("*** exit power_on()\n");
+ //debug("*** exit power_on(%.2x)\n", drv);
}
static
void power_off(BYTE drv)
{
- //debug("*** enter power_off()\n");
+ //debug("*** enter power_off(%.2x)\n", drv);
select(drv); /* Wait for card ready */
deselect(drv);
@@ -228,8 +229,10 @@ void power_off(BYTE drv)
SD_PWR_1 = 1; /* Socket power OFF */
#endif
}
- socket[drv].stat |= STA_NOINIT;
- //debug("*** exit power_off()\n");
+ ATOMIC_BLOCK(ATOMIC_FORCEON) {
+ socket[drv].stat |= STA_NOINIT;
+ }
+ //debug("*** exit power_off(%.2x)\n", drv);
}
#if 0
@@ -338,8 +341,6 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */
} argtmp;
BYTE n, res;
- //debug("*** send_cmd( %.2x )\n", cmd);
-
if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */
cmd &= 0x7F;
res = send_cmd(drv, CMD55, 0);
@@ -347,11 +348,15 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */
return res;
}
+ //debug("*** send_cmd( %.2x )", cmd);
+
/* Select the card and wait for ready except to stop multiple block read */
if (cmd != CMD12) {
deselect(drv);
- if (!select(drv))
+ if (!select(drv)) {
+ //debug(" == %.2x\n", 0xff);
return 0xFF;
+ }
}
/* Send command packet */
@@ -377,6 +382,7 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */
res = spi_rcvr();
while ((res & 0x80) && --n);
+ //debug(" == %.2x\n", res);
return res; /* Return with the response value */
}
@@ -414,24 +420,26 @@ void setup_mmc(void)
#if defined SD_CD_0
SD_CD_0_DDR = 0;
- SD_CD_0 = 1;
+ SD_CD_0 = 1; /* Pullup */
#elif defined SD_CS_0_IN
SD_CS_0_DDR = 0;
SD_CS_0 = 0;
-#else
- SD_CS_0_DDR = 1;
+#endif
+#if defined SD_CD_0 || !defined SD_CS_0_IN
SD_CS_0 = 1;
+ SD_CS_0_DDR = 1;
#endif
#if defined SD_CD_1
SD_CD_1_DDR = 0;
- SD_CD_1 = 1;
+ SD_CD_1 = 1; /* Pullup */
#elif defined SD_CS_1_IN
SD_CS_1_DDR = 0;
- SD_CS_1 = 0;
-#else
+ SD_CS_1 = 0; /* No Pullup */
+#endif
+#if defined SD_CD_1 || !defined SD_CS_1_IN
+ SD_CS_1 = 1; /* Set High */
SD_CS_1_DDR = 1;
- SD_CS_1 = 1;
#endif
}
@@ -446,14 +454,18 @@ DSTATUS disk_initialize (
)
{
BYTE n, cmd, ty, ocr[4];
+ DSTATUS res;
if (drv >= MAX_DRV)
- return STA_NOINIT; /* Supports only single drive */
- if (socket[drv].stat & STA_NODISK)
- return socket[drv].stat & STAT_MASK; /* No card in the socket */
-
+ return STA_NOINIT;
+ res = socket[drv].stat;
+ if (res & STA_NODISK) {
+ return res & STAT_MASK; /* No card in the socket */
+ }
power_on(drv); /* Force socket power on */
- socket[drv].stat &= ~STA_FAST;
+ ATOMIC_BLOCK(ATOMIC_FORCEON) {
+ socket[drv].stat &= ~STA_FAST;
+ }
SPI_CLK_SLOW();
for (n = 10; n; n--)
spi_rcvr(); /* 80 dummy clocks */
@@ -500,7 +512,10 @@ DSTATUS disk_initialize (
if (ty) { /* Initialization succeded */
/* Clear STA_NOINIT */
- socket[drv].stat = (socket[drv].stat & ~STA_NOINIT) | STA_FAST;
+ ATOMIC_BLOCK(ATOMIC_FORCEON) {
+ res = (socket[drv].stat & ~STA_NOINIT) | STA_FAST;
+ socket[drv].stat = res;
+ }
} else { /* Initialization failed */
power_off(drv);
}
@@ -516,9 +531,16 @@ DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0) */
)
{
+ DSTATUS res;
+
+ //debug("***** disk_status(%.2x)", drv);
if (drv >= MAX_DRV)
- return STA_NOINIT;
- return socket[drv].stat & STAT_MASK;
+ res = STA_NOINIT;
+ else
+ res = socket[drv].stat & STAT_MASK;
+
+ //debug(" == %.2x\n", res);
+ return res;
}
/*-----------------------------------------------------------------------*/
@@ -571,11 +593,14 @@ DRESULT disk_write (
UINT count /* Sector count (1..255) */
)
{
+ DSTATUS res;
+
if (drv >= MAX_DRV || !count)
return RES_PARERR;
- if (socket[drv].stat & STA_NOINIT)
+ res = socket[drv].stat;
+ if ( res & STA_NOINIT)
return RES_NOTRDY;
- if (socket[drv].stat & STA_PROTECT)
+ if (res & STA_PROTECT)
return RES_WRPRT;
/* Convert to byte address if needed */
@@ -713,7 +738,6 @@ DRESULT disk_ioctl (
case CTRL_POWER_OFF : /* Power off */
power_off(drv);
- socket[drv].stat |= STA_NOINIT;
res = RES_OK;
break;
diff --git a/include/config.h b/include/config.h
index c7c4511..e4e6096 100644
--- a/include/config.h
+++ b/include/config.h
@@ -9,15 +9,15 @@
/* Environment variables */
-#define ENV_BAUDRATE "baudrate"
-#define ENV_BOOTDELAY "bootdelay"
-#define ENV_BOOTCMD "bootcmd"
+#define ENV_BAUDRATE "baudrate"
+#define ENV_BOOTDELAY "bootdelay"
+#define ENV_BOOTCMD "bootcmd"
#define ENV_CPM3_SYSFILE "cpm3_file"
#define ENV_CPM3_COMMON_BASE "cpm3_commonbase"
#define ENV_CPM3_BANKED_BASE "cpm3_bankedbase"
-#define ENV_PINALIAS "pin_alias"
+#define ENV_PINALIAS "pin_alias"
#define ENV_STARTADDRESS "startaddress"
#define ENV_ESC_CHAR "esc_char"
@@ -26,7 +26,7 @@
#define CONFIG_ENVVAR_MAX 20
#define CONFIG_BAUDRATE 115200L
-#define CONFIG_PWRON_DELAY 2000 /* ms to wait after power on */
+#define CONFIG_PWRON_DELAY 2000 /* ms to wait after power on */
#define CONFIG_BOOTDELAY 4
//#define CONFIG_ZERO_BOOTDELAY_CHECK 1
@@ -59,9 +59,8 @@
#define CONFIG_SYS_FBOOTSIG "Peda"
-
+#define CONFIG_CMDLINE_EDITING 1
/* TODO: */
-//#define CONFIG_CMDLINE_EDITING 1
//#define CONFIG_AUTO_COMPLETE 1
#define CONFIG_SYS_LONGHELP 1
diff --git a/z180/config.inc b/z180/config.inc
index d10b113..4421478 100644
--- a/z180/config.inc
+++ b/z180/config.inc
@@ -140,15 +140,20 @@ mtx.fifo_id equ 0 ; This *must* have #0
mrx.fifo_len equ 64
mrx.fifo_id equ 1
-ci.fifo_len equ 32 ;AVRCON Character I/O via AVR
+ci.fifo_len equ 32 ;AVRCON (USB0) Character I/O via AVR
ci.fifo_id equ 2
co.fifo_len equ 32
co.fifo_id equ 3
+s0.rx_len equ 128 ;Serial 0 (ASCI0) buffers
+s0.rx_id equ 4 ;
+s0.tx_len equ 128 ;
+s0.tx_id equ 5 ;
+
s1.rx_len equ 128 ;Serial 1 (ASCI1) buffers
-s1.rx_id equ 4 ;
+s1.rx_id equ 6 ;
s1.tx_len equ 128 ;
-s1.tx_id equ 5 ;
+s1.tx_id equ 7 ;
AVRINT5 equ 4Fh
AVRINT6 equ 5Fh
diff --git a/z180/ddtz.180 b/z180/ddtz.180
index d5b921b..8407a1c 100644
--- a/z180/ddtz.180
+++ b/z180/ddtz.180
@@ -1229,7 +1229,7 @@ l0ce4h:
l0ce9h:
ld hl,0
l0cech:
- call get.decdigit
+ call get.bindigit
l0cefh:
inc de
jr c,l0cf8h
@@ -1239,7 +1239,7 @@ l0cefh:
l0cf8h:
cp '"'
jp nz,ERROR
- call get.decdigit
+ call get.bindigit
jr nc,l0cefh
or a
ret
@@ -2453,7 +2453,7 @@ bm_done:
ret
CMD.H:
call EXPR
- jp c,l173ch
+ jp c,l173ch ;no parameters, print High and Max
call skip_to_nextarg
push hl
call EXPR