Skip to content

Commit e659987

Browse files
authored
Merge pull request #2525 from jepler/runcpm
Updates to the code for the Runcpm-pico guide
2 parents ea66fcb + 4de9363 commit e659987

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// pio-usb is required for rp2040 host
66
#include "pio_usb.h"
77
#include "Adafruit_TinyUSB.h"
8+
#include "pico/stdlib.h"
89

910
// Pin D+ for host, D- = D+ + 1
1011
#ifndef PIN_USB_HOST_DP
@@ -34,20 +35,14 @@ void loop() {
3435

3536
void setup1() {
3637

38+
// override tools menu CPU frequency setting
39+
set_sys_clock_khz(120'000, true);
40+
3741
#if 0
3842
while ( !Serial ) delay(10); // wait for native usb
3943
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
4044
#endif
4145

42-
// Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
43-
uint32_t cpu_hz = clock_get_hz(clk_sys);
44-
if ( cpu_hz != 120000000UL && cpu_hz != 240000000UL ) {
45-
while ( !Serial ) delay(10); // wait for native usb
46-
Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
47-
Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
48-
while (1) delay(1);
49-
}
50-
5146
#ifdef PIN_5V_EN
5247
pinMode(PIN_5V_EN, OUTPUT);
5348
digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
@@ -68,9 +63,11 @@ void setup1() {
6863

6964
int old_ascii = -1;
7065
uint32_t repeat_timeout;
71-
const uint32_t repeat_time = 150;
66+
// this matches Linux default of 500ms to first repeat, 1/20s thereafter
67+
const uint32_t default_repeat_time = 50;
68+
const uint32_t initial_repeat_time = 500;
7269

73-
void send_ascii(uint8_t code) {
70+
void send_ascii(uint8_t code, uint32_t repeat_time=default_repeat_time) {
7471
old_ascii = code;
7572
repeat_timeout = millis() + repeat_time;
7673
if (code > 32 && code < 127) {
@@ -86,9 +83,8 @@ void loop1()
8683
uint32_t now = millis();
8784
uint32_t deadline = repeat_timeout - now;
8885
if (old_ascii >= 0 && deadline > INT32_MAX) {
89-
repeat_timeout += repeat_time;
90-
deadline = repeat_timeout - now;
9186
send_ascii(old_ascii);
87+
deadline = repeat_timeout - now;
9288
} else if (old_ascii < 0) {
9389
deadline = UINT32_MAX;
9490
}
@@ -133,7 +129,7 @@ const char * const lut[] = {
133129
"!@#$%^&*()", /* 0 - shifted numeric keys */
134130
"\r\x1b\10\t -=[]\\#;'`,./", /* 1 - symbol keys */
135131
"\n\x1b\177\t _+{}|~:\"~<>?", /* 2 - shifted */
136-
"\3\4\2\1", /* 3 - arrow keys RLDU */
132+
"\12\13\10\22", /* 3 - arrow keys RLDU */
137133
"/*-+\n1234567890.", /* 4 - keypad w/numlock */
138134
"/*-+\n\xff\2\xff\4\xff\3\xff\1\xff\xff.", /* 5 - keypad w/o numlock */
139135
};
@@ -217,7 +213,7 @@ void process_event(uint8_t dev_addr, uint8_t instance, const hid_keyboard_report
217213
}
218214
if (ctrl) code &= 0x1f;
219215
if (alt) code ^= 0x80;
220-
send_ascii(code);
216+
send_ascii(code, initial_repeat_time);
221217
break;
222218
}
223219
}

runcpm-rp2040-dvi-usb/runcpm-pico/abstraction_arduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ uint8 _getch(void) {
515515

516516
uint8 _getche(void) {
517517
uint8 ch = _getch();
518-
Serial.write(ch);
518+
_putch(ch);
519519
return(ch);
520520
}
521521

runcpm-rp2040-dvi-usb/runcpm-pico/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#define STR_HELPER(x) #x
9292
#define STR(x) STR_HELPER(x)
9393
// #define CCPHEAD "\r\nRunCPM Version " VERSION " (CP/M " STR(TPASIZE) "K)\r\n"
94-
#define CCPHEAD "\r\nRunCPM [\e[1mv" VERSION "\e[0m] => CCP:[\e[1m" CCPname "\e[0m] TPA:[\e[1m" STR(TPASIZE) "K\e[0m]\r\n"
94+
#define CCPHEAD "\r\nRunCPM [" TEXT_BOLD "v" VERSION TEXT_NORMAL "] => CCP:[" TEXT_BOLD CCPname TEXT_NORMAL "] TPA:" TEXT_BOLD STR(TPASIZE) "K" TEXT_NORMAL "\r\n"
9595

9696
#define NOSLASH // Will translate '/' to '_' on filenames to prevent directory errors
9797

runcpm-rp2040-dvi-usb/runcpm-pico/hardware/pico/feather_dvi.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
44
// SPDX-License-Identifier: MIT
55

66
#include <SdFat.h> // SDFat - Adafruit Fork
7-
#include <Adafruit_TinyUSB.h>
87
#include <PicoDVI.h>
98
#include "../../console.h"
109
#include "../../arduino_hooks.h"
1110

12-
#undef USE_DISPLAY
11+
#ifndef USE_DISPLAY
1312
#define USE_DISPLAY (1)
13+
#endif
14+
15+
#ifndef USE_MSC
16+
#define USE_MSC (0)
17+
#endif
1418

1519
#if USE_DISPLAY
16-
DVItext1 display(DVI_RES_800x240p60, adafruit_feather_dvi_cfg);
20+
DVItext1 display(DVI_RES_800x240p30, adafruit_feather_dvi_cfg);
1721
#endif
1822
#define SPI_CLOCK (20'000'000)
1923
#define SD_CS_PIN (10)
2024
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
2125
DedicatedSpiCard blockdevice;
2226
FatFileSystem SD; // Filesystem object from SdFat
23-
Adafruit_USBD_MSC usb_msc; // USB mass storage object
2427

2528
// =========================================================================================
2629
// Define Board-Data
@@ -34,6 +37,8 @@ Adafruit_USBD_MSC usb_msc; // USB mass storage object
3437

3538
// FUNCTIONS REQUIRED FOR USB MASS STORAGE ---------------------------------
3639

40+
#if USE_MSC
41+
Adafruit_USBD_MSC usb_msc; // USB mass storage object
3742
static bool msc_changed = true; // Is set true on filesystem changes
3843

3944
// Callback on READ10 command.
@@ -54,11 +59,7 @@ void msc_flush_cb(void) {
5459
digitalWrite(LED_BUILTIN, LOW);
5560
msc_changed = true;
5661
}
57-
58-
void _puthex32(uint32_t x) {
59-
_puthex16(x >> 16);
60-
_puthex16(x & 0xffff);
61-
}
62+
#endif
6263

6364
#if USE_DISPLAY
6465
uint16_t underCursor = ' ';
@@ -97,23 +98,26 @@ bool kbhit_serial1(void) {
9798

9899
bool port_init_early() {
99100
#if USE_DISPLAY
100-
// vreg_set_voltage(VREG_VOLTAGE_1_30);
101+
vreg_set_voltage(VREG_VOLTAGE_1_20);
102+
delay(10);
101103
if (!display.begin()) { return false; }
102104
_putch_hook = putch_display;
103105
#endif
104106
_getch_hook = getch_serial1;
105107
_kbhit_hook = kbhit_serial1;
106108
// USB mass storage / filesystem setup (do BEFORE Serial init)
107-
if (!blockdevice.begin(SD_CONFIG)) { _puts("!blockdevice.begin()"); return false; }
109+
if (!blockdevice.begin(SD_CONFIG)) { _puts("Failed to initialize SD card"); return false; }
110+
#if USE_MSC
108111
// Set disk vendor id, product id and revision
109112
usb_msc.setID("Adafruit", "Internal Flash", "1.0");
110113
// Set disk size, block size is 512 regardless of blockdevice page size
111114
usb_msc.setCapacity(blockdevice.sectorCount(), 512);
112115
usb_msc.setReadWriteCallback(msc_read_cb, msc_write_cb, msc_flush_cb);
113116
usb_msc.setUnitReady(true); // MSC is ready for read/write
114117
if (!usb_msc.begin()) {
115-
_puts("!usb_msc.begin()"); return false;
118+
_puts("Failed to initialize USB MSC"); return false;
116119
}
120+
#endif
117121
return true;
118122
}
119123

runcpm-rp2040-dvi-usb/runcpm-pico/runcpm-pico.ino

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// only AVR and ARM CPU
66
// #include <MemoryFree.h>
77

8-
#include "globals.h"
9-
108
// =========================================================================================
119
// Guido Lehwalder's Code-Revision-Number
1210
// =========================================================================================
@@ -16,10 +14,21 @@
1614

1715
#include <SdFat.h> // One SD library to rule them all - Greinman SdFat from Library Manager
1816
#include <Adafruit_SPIFlash.h>
19-
#include <Adafruit_TinyUSB.h>
2017

18+
#ifndef USE_VT100
19+
#define USE_VT100 (0)
20+
#endif
21+
22+
#if USE_VT100
2123
#define TEXT_BOLD "\033[1m"
2224
#define TEXT_NORMAL "\033[0m"
25+
#else
26+
#define TEXT_BOLD ""
27+
#define TEXT_NORMAL ""
28+
#endif
29+
30+
#include "globals.h"
31+
2332

2433
// =========================================================================================
2534
// Board definitions go into the "hardware" folder, if you use a board different than the
@@ -133,7 +142,7 @@ void setup(void) {
133142
// { _puts("Recognized " TEXT_BOLD "#" TEXT_NORMAL " key as pressed! :)\r\n\r\n");
134143
// }
135144

136-
_puts("CP/M Emulator " TEXT_BOLD "v" VERSION "" TEXT_NORMAL " by " TEXT_BOLD "Marcelo Dantas\e[0m\r\n");
145+
_puts("CP/M Emulator " TEXT_BOLD "v" VERSION "" TEXT_NORMAL " by " TEXT_BOLD "Marcelo Dantas" TEXT_NORMAL "\r\n");
137146
_puts("----------------------------------------------\r\n");
138147
_puts(" running on [" TEXT_BOLD BOARD_TEXT TEXT_NORMAL "]\r\n");
139148
_puts("----------------------------------------------\r\n");

0 commit comments

Comments
 (0)