PicoCalc Lua - now with sound!

starting a new thread for the PicoCalc Lua firmware for a huge new release! here’s what version 0.5 brings:

  • Replaces SPI with PIO in LCD driver for a small speed boost without the need to change clk_peri
  • Sound module
  • Sprites support
  • Some API changes
  • Kilo text editor:
    • Improvements in Page Up/Down, Shift-Left/Right cursor movement
    • Selection mode with clipboard
    • Line numbers (CTRL-L) (thanks @wkjagt)
    • Less flicker when moving cursor
    • Adding newline keeps previous’ indentation
  • Demos:
    • New demo: boxworld.lua to showcase music, sprites, and contains 100 classic Sokoban levels to keep you busy :slight_smile:
    • New demo: speedtest.lua is a very simple tool to determine screen-writing speeds
    • New demo: piano.lua to showcase the sound driver in real-time
    • New demo: browser.lua as a very simple but easy way to browse and edit Lua files
    • asteroids.lua: Added sound effects
    • bubble.lua: Speed up with look-up tables
  • Added a credits() command

download here!

with this update i’ve included a conversion of a beloved Windows 3.11 game of mine, Box World, to showcase the new graphics and sound drivers :]

13 Likes

Great work!

In case if anyone wants to try this lua with sound on Pico 1 for PicoCalc

here is the pre-compiled version based on the commit hash

847aa1778607de66a3533b2ed62a2259816f1b1f

uf2 file:

multi boot bin file:

and here is the patch I’ve made:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fcc867f..cbe27c1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,7 +12,7 @@ if (EXISTS ${picoVscode})
     include(${picoVscode})
 endif()
 # ====================================================================================
-set(PICO_BOARD pico2 CACHE STRING "Board type")
+set(PICO_BOARD pico CACHE STRING "Board type")
 
 cmake_minimum_required(VERSION 3.13)
 
diff --git a/drivers/keyboard.c b/drivers/keyboard.c
index 344755a..2044924 100644
--- a/drivers/keyboard.c
+++ b/drivers/keyboard.c
@@ -11,7 +11,7 @@
 #define KBD_MOD    i2c1
 #define KBD_SDA    6
 #define KBD_SCL    7
-#define KBD_SPEED  20000 // if dual i2c, then the speed of keyboard i2c should be 10khz
+#define KBD_SPEED  10000 // if dual i2c, then the speed of keyboard i2c should be 10khz
 #define KBD_ADDR   0x1F
 
 // Commands defined by the keyboard driver
@@ -31,7 +31,7 @@ enum {
 	REG_ID_C64_JS = 0x0d,  // joystick io bits
 };
 
-#define I2C_TIMEOUT 10000
+#define I2C_TIMEOUT 50000
 volatile atomic_bool i2c_in_use = false;
 
 #define KEY_COUNT 256
@@ -54,7 +54,7 @@ static int keyboard_modifiers;
 static int i2c_kbd_write(unsigned char* data, int size) {
 	if (atomic_load(&i2c_in_use) == true) return 0;
 	atomic_store(&i2c_in_use, true);
-	int retval = i2c_write_timeout_us(KBD_MOD, KBD_ADDR, data, size, false, I2C_TIMEOUT * size);
+	int retval = i2c_write_timeout_us(KBD_MOD, KBD_ADDR, data, size, false, I2C_TIMEOUT );
 	atomic_store(&i2c_in_use, false);
 	if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
 		printf("i2c_kbd_write: i2c write error\n");
@@ -66,7 +66,7 @@ static int i2c_kbd_write(unsigned char* data, int size) {
 static int i2c_kbd_read(unsigned char* data, int size) {
 	if (atomic_load(&i2c_in_use) == true) return 0;
 	atomic_store(&i2c_in_use, true);
-	int retval = i2c_read_timeout_us(KBD_MOD, KBD_ADDR, data, size, false, I2C_TIMEOUT * size);
+	int retval = i2c_read_timeout_us(KBD_MOD, KBD_ADDR, data, size, false, I2C_TIMEOUT);
 	atomic_store(&i2c_in_use, false);
 	if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT) {
 		printf("i2c_kbd_read: i2c read error\n");
@@ -216,4 +216,4 @@ int get_battery(bool* charging) {
 	result >>= 8;
 	if (charging) *charging = (result & 1<<7) != 0;
 	return result & ~(1<<7);
-}
\ No newline at end of file
+}

1 Like

hmm, i did try the 2040 binary i generated with a 1w, since i don’t have a way to wire my 1h for debugging , and didn’t find any issues with the keyboard

i’ll try those patches on my end and if the keyboard works just as well on my 2 and 1w with those values i’ll just apply that patch upstream anyway

thanks!

This is beyond my dreams, bravo!

Do you think you could extend the PIO display driver to do palette lookups from the framebuffer (instead of doing it on the CPU)? Also, sprites could be accelerated by PIO as well…

likely! i thought about it, but i know aaabsolutely nothing about how to properly interface with and program the PIO yet, i only aped the LCD example here with some adaptation: pico-examples/pio/st7789_lcd/st7789_lcd.c at master · raspberrypi/pico-examples · GitHub

i would love to make it better, polpo’s psram library is also very limiting because it measures transfer length in bits and uses an 8-bit value to do so, so you max out at asking for about 20 bytes or so before transfers just stop working, and i couldn’t figure out how to make it use a 16-bit value instead…

i think increasing the PSRAM transfer length (maybe even blit from PSRAM to LCD without CPU involvement at all!) and palettized sprites and framebuffer would make this killer for programming games :] i’ll study the PIO more and maybe one day!