mirror of
https://github.com/satoshinm/pill_6502.git
synced 2024-06-14 21:29:36 +00:00
Change serial commands to control characters, send everything else to ACIA (6850) input buffer
This commit is contained in:
parent
99f882ebfc
commit
a6f3f87b97
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stdbool.h>
|
||||||
#include <libopencm3/usb/usbd.h>
|
#include <libopencm3/usb/usbd.h>
|
||||||
#include <libopencm3/usb/cdc.h>
|
#include <libopencm3/usb/cdc.h>
|
||||||
|
|
||||||
|
@ -20,14 +21,36 @@ extern usbd_device *usbd_dev;
|
||||||
#define RDRF (1 << 0)
|
#define RDRF (1 << 0)
|
||||||
#define TDRE (1 << 1)
|
#define TDRE (1 << 1)
|
||||||
|
|
||||||
|
|
||||||
|
static char input[256];
|
||||||
|
static int input_index = 0;
|
||||||
|
static int input_processed_index = 0;
|
||||||
|
|
||||||
|
void process_serial_input_byte(char b) {
|
||||||
|
input[input_index++] = b;
|
||||||
|
input_index %= sizeof(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t read6850(uint16_t address) {
|
uint8_t read6850(uint16_t address) {
|
||||||
switch(address & 1) {
|
switch(address & 1) {
|
||||||
case ACIAStatus:
|
case ACIAStatus: {
|
||||||
return TDRE; // writable
|
// Always writable
|
||||||
|
uint8_t flags = TDRE;
|
||||||
|
|
||||||
|
// Readable if there is pending user input data which wasn't read
|
||||||
|
if (input_processed_index < input_index) flags |= RDRF;
|
||||||
|
|
||||||
|
return flags;
|
||||||
break;
|
break;
|
||||||
case ACIAData:
|
}
|
||||||
// TODO: read buffer from serial port
|
case ACIAData: {
|
||||||
|
char data = input[input_processed_index++];
|
||||||
|
input_processed_index %= sizeof(input);
|
||||||
|
|
||||||
|
return data;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
20
src/cdcacm.c
20
src/cdcacm.c
|
@ -189,7 +189,8 @@ void cdcacm_send_chunked_blocking(char *buf, int len, usbd_device *dev) {
|
||||||
} while (bytes_remaining > 0);
|
} while (bytes_remaining > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern char *process_serial_command(char *buf, int len);
|
extern char *process_serial_command(char b);
|
||||||
|
extern void *process_serial_input_byte(char b);
|
||||||
|
|
||||||
static void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
static void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
||||||
{
|
{
|
||||||
|
@ -198,9 +199,6 @@ static void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
||||||
char buf[CDCACM_PACKET_SIZE];
|
char buf[CDCACM_PACKET_SIZE];
|
||||||
char reply_buf[256];
|
char reply_buf[256];
|
||||||
|
|
||||||
static char typing_buf[2048] = {0};
|
|
||||||
static int typing_index = 0;
|
|
||||||
|
|
||||||
int len = usbd_ep_read_packet(dev, CDCACM_UART_ENDPOINT,
|
int len = usbd_ep_read_packet(dev, CDCACM_UART_ENDPOINT,
|
||||||
buf, CDCACM_PACKET_SIZE);
|
buf, CDCACM_PACKET_SIZE);
|
||||||
|
|
||||||
|
@ -214,21 +212,19 @@ static void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
||||||
if (buf[i] == '\r') reply_buf[j++] = '\n';
|
if (buf[i] == '\r') reply_buf[j++] = '\n';
|
||||||
reply_buf[j++] = buf[i];
|
reply_buf[j++] = buf[i];
|
||||||
|
|
||||||
typing_buf[typing_index++] = buf[i];
|
char *response = process_serial_command(buf[i]);
|
||||||
|
if (response) {
|
||||||
if (buf[i] == '\r' || buf[i] == '\n') {
|
reply_buf[j++] = '\r';
|
||||||
char *response = process_serial_command(typing_buf, typing_index);
|
reply_buf[j++] = '\n';
|
||||||
typing_index = 0;
|
|
||||||
|
|
||||||
for (size_t k = 0; k < strlen(response); ++k) {
|
for (size_t k = 0; k < strlen(response); ++k) {
|
||||||
reply_buf[j++] = response[k];
|
reply_buf[j++] = response[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
// prompt
|
|
||||||
reply_buf[j++] = '\r';
|
reply_buf[j++] = '\r';
|
||||||
reply_buf[j++] = '\n';
|
reply_buf[j++] = '\n';
|
||||||
reply_buf[j++] = '>';
|
} else {
|
||||||
reply_buf[j++] = ' ';
|
process_serial_input_byte(buf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/main.c
18
src/main.c
|
@ -103,27 +103,25 @@ static void usb_reset()
|
||||||
paused = false;
|
paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *process_serial_command(char *buf, int len) {
|
char *process_serial_command(char b) {
|
||||||
(void) len;
|
if (b == '\x16') { // ^V
|
||||||
|
|
||||||
if (buf[0] == 'v') {
|
|
||||||
return "Pill 6502 version " FIRMWARE_VERSION;
|
return "Pill 6502 version " FIRMWARE_VERSION;
|
||||||
} else if (buf[0] == 'p') {
|
} else if (b == '\x10') { // ^P
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
return paused ? "paused" : "resumed";
|
return paused ? "paused" : "resumed";
|
||||||
} else if (buf[0] == 'r') {
|
} else if (b == '\x12') { // ^R
|
||||||
reset6502();
|
reset6502();
|
||||||
paused = false;
|
paused = false;
|
||||||
return "reset";
|
return "reset";
|
||||||
} else if (buf[0] == 't') {
|
} else if (b == '\x14') { // T
|
||||||
static char buf[64];
|
static char buf[64];
|
||||||
snprintf(buf, sizeof(buf), "%ld ticks\r\n%ld instructions", clockticks6502, instructions);
|
snprintf(buf, sizeof(buf), "%ld ticks\r\n%ld instructions", clockticks6502, instructions);
|
||||||
return buf;
|
return buf;
|
||||||
} else {
|
} else if (b == '\x07') { // G
|
||||||
return "invalid command, try ? for help";
|
return "^V=version ^R=reset ^P=pause ^T=ticks ^G=help";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_clock(void) {
|
static void setup_clock(void) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user