mirror of
https://github.com/satoshinm/pill_6502.git
synced 2024-06-14 06:29:29 +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/cdc.h>
|
||||
|
||||
|
@ -20,14 +21,36 @@ extern usbd_device *usbd_dev;
|
|||
#define RDRF (1 << 0)
|
||||
#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) {
|
||||
switch(address & 1) {
|
||||
case ACIAStatus:
|
||||
return TDRE; // writable
|
||||
case ACIAStatus: {
|
||||
// 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;
|
||||
case ACIAData:
|
||||
// TODO: read buffer from serial port
|
||||
}
|
||||
case ACIAData: {
|
||||
char data = input[input_processed_index++];
|
||||
input_processed_index %= sizeof(input);
|
||||
|
||||
return data;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -198,9 +199,6 @@ static void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep)
|
|||
char buf[CDCACM_PACKET_SIZE];
|
||||
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,
|
||||
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';
|
||||
reply_buf[j++] = buf[i];
|
||||
|
||||
typing_buf[typing_index++] = buf[i];
|
||||
|
||||
if (buf[i] == '\r' || buf[i] == '\n') {
|
||||
char *response = process_serial_command(typing_buf, typing_index);
|
||||
typing_index = 0;
|
||||
char *response = process_serial_command(buf[i]);
|
||||
if (response) {
|
||||
reply_buf[j++] = '\r';
|
||||
reply_buf[j++] = '\n';
|
||||
|
||||
for (size_t k = 0; k < strlen(response); ++k) {
|
||||
reply_buf[j++] = response[k];
|
||||
}
|
||||
|
||||
// prompt
|
||||
reply_buf[j++] = '\r';
|
||||
reply_buf[j++] = '\n';
|
||||
reply_buf[j++] = '>';
|
||||
reply_buf[j++] = ' ';
|
||||
} else {
|
||||
process_serial_input_byte(buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
src/main.c
18
src/main.c
|
@ -103,27 +103,25 @@ static void usb_reset()
|
|||
paused = false;
|
||||
}
|
||||
|
||||
char *process_serial_command(char *buf, int len) {
|
||||
(void) len;
|
||||
|
||||
if (buf[0] == 'v') {
|
||||
char *process_serial_command(char b) {
|
||||
if (b == '\x16') { // ^V
|
||||
return "Pill 6502 version " FIRMWARE_VERSION;
|
||||
} else if (buf[0] == 'p') {
|
||||
} else if (b == '\x10') { // ^P
|
||||
paused = !paused;
|
||||
return paused ? "paused" : "resumed";
|
||||
} else if (buf[0] == 'r') {
|
||||
} else if (b == '\x12') { // ^R
|
||||
reset6502();
|
||||
paused = false;
|
||||
return "reset";
|
||||
} else if (buf[0] == 't') {
|
||||
} else if (b == '\x14') { // T
|
||||
static char buf[64];
|
||||
snprintf(buf, sizeof(buf), "%ld ticks\r\n%ld instructions", clockticks6502, instructions);
|
||||
return buf;
|
||||
} else {
|
||||
return "invalid command, try ? for help";
|
||||
} else if (b == '\x07') { // G
|
||||
return "^V=version ^R=reset ^P=pause ^T=ticks ^G=help";
|
||||
}
|
||||
|
||||
return "";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void setup_clock(void) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user