+static void
+debug_input(void)
+{
+ __xdata uint16_t count;
+ __xdata uint16_t addr;
+ __xdata uint8_t b;
+ __xdata uint8_t i;
+
+ ao_cmd_hex();
+ count = ao_cmd_lex_i;
+ ao_cmd_hex();
+ addr = ao_cmd_lex_i;
+ if (ao_cmd_status != ao_cmd_success)
+ return;
+ ao_dbg_start_transfer(addr);
+ i = 0;
+ while (count--) {
+ if (!(i++ & 7))
+ putchar('\n');
+ b = ao_dbg_read_byte();
+ ao_cmd_put8(b);
+ }
+ ao_dbg_end_transfer();
+ putchar('\n');
+}
+
+static void
+debug_output(void)
+{
+ __xdata uint16_t count;
+ __xdata uint16_t addr;
+ __xdata uint8_t b;
+
+ ao_cmd_hex();
+ count = ao_cmd_lex_i;
+ ao_cmd_hex();
+ addr = ao_cmd_lex_i;
+ if (ao_cmd_status != ao_cmd_success)
+ return;
+ ao_dbg_start_transfer(addr);
+ while (count--) {
+ b = getnibble() << 4;
+ b |= getnibble();
+ if (ao_cmd_status != ao_cmd_success)
+ return;
+ ao_dbg_write_byte(b);
+ }
+ ao_dbg_end_transfer();
+}
+
+__code struct ao_cmds ao_dbg_cmds[7] = {
+ { 'D', debug_enable, "D Enable debug mode" },
+ { 'G', debug_get, "G <count> Get data from debug port" },
+ { 'I', debug_input, "I <count> <addr> Input <count> bytes to target at <addr>" },
+ { 'O', debug_output, "O <count> <addr> Output <count> bytes to target at <addr>" },
+ { 'P', debug_put, "P <byte> ... Put data to debug port" },
+ { 'R', debug_reset, "R Reset target" },
+ { 0, debug_reset, 0 },
+};
+
+void
+ao_dbg_init(void)
+{
+ ao_cmd_register(&ao_dbg_cmds[0]);
+}