Skip to content

Commit 4151751

Browse files
committed
Port RunCPM to the Metro RP2350 with HSTX
This uses the built in HSTX connector for video out, and the built in SD card for file storage. It's a 1-board emulator for the 8-bit CP/M operating system! At this time, unreleased modifications to Adafruit_dvhstx and Pico-PIO-USB are needed. Otherwise, the code will not work properly.
1 parent a6851c5 commit 4151751

File tree

6 files changed

+294
-329
lines changed

6 files changed

+294
-329
lines changed

runcpm-rp2040-dvi-usb/keyboard-copro/keyboard-copro.ino

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "pio_usb.h"
77
#include "Adafruit_TinyUSB.h"
88
#include "pico/stdlib.h"
9+
#include "Adafruit_dvhstx.h"
10+
11+
DVHSTXText3 display(DVHSTX_PINOUT_DEFAULT);
912

1013
// Pin D+ for host, D- = D+ + 1
1114
#ifndef PIN_USB_HOST_DP
@@ -28,16 +31,22 @@ Adafruit_USBH_Host USBHost;
2831
SerialPIO pio_serial(1 /* RX of the sibling board */, SerialPIO::NOPIN);
2932

3033
void setup() {
34+
// ensure text generation interrupt takes place on core0
35+
display.begin();
36+
display.println("Hello hstx\n");
3137
}
3238

3339
void loop() {
3440
}
3541

3642
void setup1() {
37-
43+
while(!display) ;
44+
delay(10);
45+
display.println("Hello hstx in setup1\n");
3846
// override tools menu CPU frequency setting
39-
set_sys_clock_khz(120'000, true);
47+
//set_sys_clock_khz(264'000, true);
4048

49+
Serial.begin(115200);
4150
#if 0
4251
while ( !Serial ) delay(10); // wait for native usb
4352
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
@@ -50,6 +59,9 @@ void setup1() {
5059

5160
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
5261
pio_cfg.pin_dp = PIN_USB_HOST_DP;
62+
pio_cfg.tx_ch = dma_claim_unused_channel(true);
63+
dma_channel_unclaim(pio_cfg.tx_ch);
64+
5365
USBHost.configure_pio_usb(1, &pio_cfg);
5466

5567
// run host stack on controller (rhport) 1
@@ -59,6 +71,8 @@ void setup1() {
5971

6072
// this `begin` is a void function, no way to check for failure!
6173
pio_serial.begin(115200);
74+
display.println("end of setup1\n");
75+
display.show_cursor();
6276
}
6377

6478
int old_ascii = -1;
@@ -70,16 +84,21 @@ const uint32_t initial_repeat_time = 500;
7084
void send_ascii(uint8_t code, uint32_t repeat_time=default_repeat_time) {
7185
old_ascii = code;
7286
repeat_timeout = millis() + repeat_time;
73-
if (code > 32 && code < 127) {
74-
Serial.printf("'%c'\r\n", code);
87+
if (code >= 32 && code < 127) {
88+
display.printf("%c", code);
7589
} else {
76-
Serial.printf("'\\x%02x'\r\n", code);
90+
display.printf("\\x%02x", code);
7791
}
7892
pio_serial.write(code);
7993
}
8094

8195
void loop1()
8296
{
97+
static bool last_serial;
98+
if (!last_serial && Serial) {
99+
last_serial = true;
100+
Serial.println("Hello host serial");
101+
}
83102
uint32_t now = millis();
84103
uint32_t deadline = repeat_timeout - now;
85104
if (old_ascii >= 0 && deadline > INT32_MAX) {
@@ -166,12 +185,12 @@ bool report_contains(const hid_keyboard_report_t &report, uint8_t key) {
166185

167186
hid_keyboard_report_t old_report;
168187

188+
static bool caps, num;
189+
static uint8_t old_leds;
169190
void process_event(uint8_t dev_addr, uint8_t instance, const hid_keyboard_report_t &report) {
170191
bool alt = report.modifier & 0x44;
171192
bool shift = report.modifier & 0x22;
172193
bool ctrl = report.modifier & 0x11;
173-
bool caps = old_report.reserved & 1;
174-
bool num = old_report.reserved & 2;
175194
uint8_t code = 0;
176195

177196
if (report.keycode[0] == 1 && report.keycode[1] == 1) {
@@ -188,8 +207,10 @@ void process_event(uint8_t dev_addr, uint8_t instance, const hid_keyboard_report
188207

189208
/* key is newly pressed */
190209
if (keycode == HID_KEY_NUM_LOCK) {
210+
Serial.println("toggle numlock");
191211
num = !num;
192212
} else if (keycode == HID_KEY_CAPS_LOCK) {
213+
Serial.println("toggle capslock");
193214
caps = !caps;
194215
} else {
195216
for (const auto &mapper : keycode_to_ascii) {
@@ -219,15 +240,15 @@ void process_event(uint8_t dev_addr, uint8_t instance, const hid_keyboard_report
219240
}
220241
}
221242

222-
uint8_t leds = (caps | (num << 1));
223-
if (leds != old_report.reserved) {
243+
uint8_t leds = (caps << 1) | num;
244+
if (leds != old_leds) {
245+
old_leds = leds;
224246
Serial.printf("Send LEDs report %d (dev:instance = %d:%d)\r\n", leds, dev_addr, instance);
225247
// no worky
226-
auto r = tuh_hid_set_report(dev_addr, instance/*idx*/, 0/*report_id*/, HID_REPORT_TYPE_OUTPUT/*report_type*/, &leds, sizeof(leds));
248+
auto r = tuh_hid_set_report(dev_addr, instance/*idx*/, 0/*report_id*/, HID_REPORT_TYPE_OUTPUT/*report_type*/, &old_leds, sizeof(old_leds));
227249
Serial.printf("set_report() -> %d\n", (int)r);
228250
}
229251
old_report = report;
230-
old_report.reserved = leds;
231252
}
232253

233254
// Invoked when received report from device via interrupt endpoint

runcpm-rp2350-hstx-usb/keyboard-copro/.feather_rp2040_tinyusb.test.only

Whitespace-only changes.

runcpm-rp2350-hstx-usb/runcpm-pico/abstraction_arduino.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#define HostOS 0x01
1414
// #endif
1515

16+
#if !defined(FILE_TYPE)
17+
#define FILE_TYPE FsFile
18+
#endif
19+
1620
#if defined CORE_TEENSY
1721
#define HostOS 0x04
1822
#endif
@@ -26,7 +30,7 @@
2630
/* Memory abstraction functions */
2731
/*===============================================================================*/
2832
bool _RamLoad(char* filename, uint16 address) {
29-
File32 f;
33+
FILE_TYPE f;
3034
bool result = false;
3135

3236
if (f = SD.open(filename, FILE_READ)) {
@@ -40,7 +44,7 @@ bool _RamLoad(char* filename, uint16 address) {
4044

4145
/* Filesystem (disk) abstraction fuctions */
4246
/*===============================================================================*/
43-
File32 rootdir, userdir;
47+
FILE_TYPE rootdir, userdir;
4448
#define FOLDERCHAR '/'
4549

4650
typedef struct {
@@ -60,31 +64,29 @@ typedef struct {
6064
uint8 al[16];
6165
} CPM_DIRENTRY;
6266

63-
static DirFat_t fileDirEntry;
64-
6567
bool _sys_exists(uint8* filename) {
6668
return(SD.exists((const char *)filename));
6769
}
6870

69-
File32 _sys_fopen_w(uint8* filename) {
71+
FILE_TYPE _sys_fopen_w(uint8* filename) {
7072
return(SD.open((char*)filename, O_CREAT | O_WRITE));
7173
}
7274

73-
int _sys_fputc(uint8 ch, File32& f) {
75+
int _sys_fputc(uint8 ch, FILE_TYPE& f) {
7476
return(f.write(ch));
7577
}
7678

77-
void _sys_fflush(File32& f) {
79+
void _sys_fflush(FILE_TYPE& f) {
7880
f.flush();
7981
}
8082

81-
void _sys_fclose(File32& f) {
83+
void _sys_fclose(FILE_TYPE& f) {
8284
f.close();
8385
}
8486

8587
int _sys_select(uint8* disk) {
8688
uint8 result = FALSE;
87-
File32 f;
89+
FILE_TYPE f;
8890

8991
digitalWrite(LED, HIGH ^ LEDinv);
9092
if (f = SD.open((char*)disk, O_READ)) {
@@ -98,7 +100,7 @@ int _sys_select(uint8* disk) {
98100

99101
long _sys_filesize(uint8* filename) {
100102
long l = -1;
101-
File32 f;
103+
FILE_TYPE f;
102104

103105
digitalWrite(LED, HIGH ^ LEDinv);
104106
if (f = SD.open((char*)filename, O_RDONLY)) {
@@ -110,13 +112,12 @@ long _sys_filesize(uint8* filename) {
110112
}
111113

112114
int _sys_openfile(uint8* filename) {
113-
File32 f;
115+
FILE_TYPE f;
114116
int result = 0;
115117

116118
digitalWrite(LED, HIGH ^ LEDinv);
117119
f = SD.open((char*)filename, O_READ);
118120
if (f) {
119-
f.dirEntry(&fileDirEntry);
120121
f.close();
121122
result = 1;
122123
}
@@ -125,7 +126,7 @@ int _sys_openfile(uint8* filename) {
125126
}
126127

127128
int _sys_makefile(uint8* filename) {
128-
File32 f;
129+
FILE_TYPE f;
129130
int result = 0;
130131

131132
digitalWrite(LED, HIGH ^ LEDinv);
@@ -145,7 +146,7 @@ int _sys_deletefile(uint8* filename) {
145146
}
146147

147148
int _sys_renamefile(uint8* filename, uint8* newname) {
148-
File32 f;
149+
FILE_TYPE f;
149150
int result = 0;
150151

151152
digitalWrite(LED, HIGH ^ LEDinv);
@@ -165,7 +166,7 @@ void _sys_logbuffer(uint8* buffer) {
165166
#ifdef CONSOLELOG
166167
puts((char*)buffer);
167168
#else
168-
File32 f;
169+
FILE_TYPE f;
169170
uint8 s = 0;
170171
while (*(buffer + s)) // Computes buffer size
171172
++s;
@@ -181,7 +182,7 @@ void _sys_logbuffer(uint8* buffer) {
181182
bool _sys_extendfile(char* fn, unsigned long fpos)
182183
{
183184
uint8 result = true;
184-
File32 f;
185+
FILE_TYPE f;
185186
unsigned long i;
186187

187188
digitalWrite(LED, HIGH ^ LEDinv);
@@ -204,7 +205,7 @@ bool _sys_extendfile(char* fn, unsigned long fpos)
204205

205206
uint8 _sys_readseq(uint8* filename, long fpos) {
206207
uint8 result = 0xff;
207-
File32 f;
208+
FILE_TYPE f;
208209
uint8 bytesread;
209210
uint8 dmabuf[BlkSZ];
210211
uint8 i;
@@ -234,7 +235,7 @@ uint8 _sys_readseq(uint8* filename, long fpos) {
234235

235236
uint8 _sys_writeseq(uint8* filename, long fpos) {
236237
uint8 result = 0xff;
237-
File32 f;
238+
FILE_TYPE f;
238239

239240
digitalWrite(LED, HIGH ^ LEDinv);
240241
if (_sys_extendfile((char*)filename, fpos))
@@ -256,7 +257,7 @@ uint8 _sys_writeseq(uint8* filename, long fpos) {
256257

257258
uint8 _sys_readrand(uint8* filename, long fpos) {
258259
uint8 result = 0xff;
259-
File32 f;
260+
FILE_TYPE f;
260261
uint8 bytesread;
261262
uint8 dmabuf[BlkSZ];
262263
uint8 i;
@@ -297,7 +298,7 @@ uint8 _sys_readrand(uint8* filename, long fpos) {
297298

298299
uint8 _sys_writerand(uint8* filename, long fpos) {
299300
uint8 result = 0xff;
300-
File32 f;
301+
FILE_TYPE f;
301302

302303
digitalWrite(LED, HIGH ^ LEDinv);
303304
if (_sys_extendfile((char*)filename, fpos)) {
@@ -325,7 +326,7 @@ static uint16 fileExtentsUsed = 0;
325326
static uint16 firstFreeAllocBlock;
326327

327328
uint8 _findnext(uint8 isdir) {
328-
File32 f;
329+
FILE_TYPE f;
329330
uint8 result = 0xff;
330331
bool isfile;
331332
uint32 bytes;
@@ -339,7 +340,6 @@ uint8 _findnext(uint8 isdir) {
339340
f.getName((char*)&findNextDirName[0], 13);
340341
isfile = !f.isDirectory();
341342
bytes = f.size();
342-
f.dirEntry(&fileDirEntry);
343343
f.close();
344344
if (!isfile)
345345
continue;
@@ -440,7 +440,7 @@ uint8 _findfirstallusers(uint8 isdir) {
440440
}
441441

442442
uint8 _Truncate(char* filename, uint8 rc) {
443-
File32 f;
443+
FILE_TYPE f;
444444
int result = 0;
445445

446446
digitalWrite(LED, HIGH ^ LEDinv);

0 commit comments

Comments
 (0)