Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:17 22 Jun 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Bubble universe on steroids

     Page 1 of 2    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11516
Posted: 11:49am 20 Jun 2026
Copy link to clipboard 
Print this post


if instr(mm.device$,"HDMI") or instr(mm.device$,"VGA") then MODE 2
Font 7
FRAMEBUFFER create
FRAMEBUFFER write f

Dim Float t,pf(15)              ' pf: 0=i 1=b 2=v 3=x 4=pi/2 5=xs 6=ys 7=xc 8=yc
Dim Integer c(65),d(65),n(65),m(32,65),nn
Dim Integer a,g,i,j,xc,yc,xs,ys
Dim Integer ct = MM.INFO(CALLTABLE)
Const r=(2*Pi)/235,k=255,s=50
CLS RGB(black)
t=Rnd*10
nn=Peek(varaddr n())

'centre and scale factor
xc=MM.HRES\2:yc=MM.VRES\2
xs=MM.HRES/4.2:ys=MM.VRES/4.0  'Oval
pf(2)=0:pf(3)=0:pf(4)=Pi/2     ' v=0, x=0, half-pi
pf(5)=xs:pf(6)=ys:pf(7)=xc:pf(8)=yc

For a=0 To 65
For g=0 To 65
 If a<18 And g<18 Then
  n(g)=RGB(0,255,0)
 Else
  n(g)=RGB(a*3.93,g*3.93,128*(a+g<65))
 EndIf
Next 'g
Memory pack nn,Peek(varaddr m(0,a)),66,32
Next 'a

Do
CLS
Inc t,0.035:g=0:Print Timer:Timer=0
For i=60 To 255 Step 3
 pf(0)=i:pf(1)=r*i+t
 bubblerow c(),d(),pf(),ct                 ' recurrence + scale + offset -> c(),d()
 Memory unpack Peek(varaddr m(0,g)),nn,66,32
 Pixel c(),d(),n()
 Inc g
Next 'i
FRAMEBUFFER copy f,n
Loop

CSUB bubblerow INTEGER, INTEGER, FLOAT, INTEGER
 00000000
 B5F0681B 001A0014 68123290 9201B09D 32A4001A 33886815 68123A04 9206681B
 68229307 920C6863 68A2930D 920E68E3 6922930F 92026963 69A29303 920469E3
 6A229305 92086A63 6AA29309 92106AE3 6B229311 92126B63 6BA29313 92146BE3
 6C229315 92166C63 23009317 911B901A 9A029300 980C9B03 47A8990D 00069B01
 4798000F 9B099A08 91039002 00390030 9B0147A8 9B014798 91199018 99059804
 9A084798 900A9B09 9804910B 47A89905 47989B01 9B0B9A0A 000F0006 99039802
 003247A8 900A003B 9818910B 47A89919 9B0F9A0E 91039002 990B980A 9A1047A8
 90049B11 980A9105 9E06990B 9A1447B0 47A89B15 47989B07 9B1A9A00 189B9E06
 60596018 9B139A12 99039802 9A1647B0 47A89B17 47989B07 9B1B9A00 6018189B
 00136059 33082284 00929300 D1A04293 9A022000 21009B03 61636122 9B059A04
 61E361A2 BDF0B01D
END CSUB


This was an experiment in asking Claude to optimise the bubble universe program. It's first attempt in Basic was to create a sine/cos lookup table which slowed the program down. It then suggested a CSUB so I coached it through how to write one, how to make it RP2040/RP2350 agnostic and how to deal with floating point numbers. I did this by getting it to slowly go through a number of simple examples, squaring an integer, then squaring a float. We then moved on to optimising the bubble universe. On a HDMI build at 378MHz the frame rate increases from 5.1 to 42.4FPS.
The next step is to improve the whole csub architecture to make writing them a bit easier. There will be a python script to generate a csub direct from the c source.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1761
Posted: 12:10pm 20 Jun 2026
Copy link to clipboard 
Print this post

[29] Memory pack nn,Peek(varaddr m(0,a)),66,32
Error : Address not divisible by 8
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11516
Posted: 12:20pm 20 Jun 2026
Copy link to clipboard 
Print this post

Works for me, hdmi and tft - you don't say what firmware and version you are running on
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1761
Posted: 12:22pm 20 Jun 2026
Copy link to clipboard 
Print this post

..."you don't say what firmware and version you are running on"
PicoMiteHDMI MMBasic USB RP2350A Edition V6.03.00RC12

causality ≠ correlation ≠ coincidence
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1960
Posted: 12:29pm 20 Jun 2026
Copy link to clipboard 
Print this post

  matherp said  
the frame rate increases from 5.1 to 42.4FPS.
The next step is to improve the whole csub architecture to make writing them a bit easier. There will be a python script to generate a csub direct from the c source.


 

Love seeing such a performance boost....only problem is...no one around me gets excited

 
dddns
Guru

Joined: 20/09/2024
Location: Germany
Posts: 843
Posted: 12:52pm 20 Jun 2026
Copy link to clipboard 
Print this post

  matherp said  It then suggested a CSUB so I coached it through how to write one, how to make it RP2040/RP2350 agnostic and how to deal with floating point numbers. I did this by getting it to slowly go through a number of simple examples, squaring an integer, then squaring a float. We then moved on to optimising the bubble universe.


I never (knowingly) used AI up to now. Teaching AI is one thing, I surely couldn't do that with CSUB.
Would one benefit from your teaching and simply say, write an CSUB for some issue If he signs to Claude today?

  PhenixRising said  
Love seeing such a performance boost....only problem is...no one around me gets excited

I am but I think its hard to express if you don't understand :))
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11516
Posted: 01:10pm 20 Jun 2026
Copy link to clipboard 
Print this post

  Quote  PicoMiteHDMI MMBasic USB RP2350A Edition V6.03.00RC12

Try RC21
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1761
Posted: 01:23pm 20 Jun 2026
Copy link to clipboard 
Print this post

  matherp said  
  Quote  PicoMiteHDMI MMBasic USB RP2350A Edition V6.03.00RC12

Try RC21

Will do!
I commented out the memory pack/unpack code and am getting a displayed value of approximately 26.45 (at 315MHz); I just don't know if the output was affected.



With the Tracecache enabled, a cycle takes 25.7 ms (= 38.9 at 315 MHz).
Edited 2026-06-20 23:35 by twofingers
causality ≠ correlation ≠ coincidence
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1960
Posted: 01:26pm 20 Jun 2026
Copy link to clipboard 
Print this post

  dddns said  
I am but I think its hard to express if you don't understand :))


A couple of guys came by and asked what I'm doing...wire-wrapping a prototype board and of course I had to demonstrate...they couldn't get away fast enough  

Probably gone to watch grown men chase a ball around a field.  
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1960
Posted: 01:41pm 20 Jun 2026
Copy link to clipboard 
Print this post

duplicate
Edited 2026-06-21 00:01 by PhenixRising
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11516
Posted: 02:04pm 20 Jun 2026
Copy link to clipboard 
Print this post

  Quote  I commented out the memory pack/unpack code and am getting a displayed value of approximately 26.45 (at 315MHz); I just don't know if the output was affected.

Yes, it will be. I've just looked at the code again and that error isn't possible both addresses have to be divisible by 8.

Replace the loop with this:
For a=0 To 65
For g=0 To 65
If a<18 And g<18 Then
 n(g)=RGB(0,255,0)
Else
 n(g)=RGB(a*3.93,g*3.93,128*(a+g<65))
EndIf
Next 'g
x%=Peek(varaddr m(0,a)):print x%,nn
Memory pack nn,x%,66,32
Next 'a

What do you get?
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1761
Posted: 02:12pm 20 Jun 2026
Copy link to clipboard 
Print this post

Hi Peter,
Unfortunately, I’m still getting the same error (RC12).
However, the memory pack seems unnecessary to me.

By the way, it would be helpful if you could post the C source code from time to time. Thanks!
Michael

The console shows (still RC12):
537029796       537047460
537030060       537047460
537030324       537047460
537030588       537047460
537030852       537047460
537031116       537047460
537031380       537047460
537031644       537047460
537031908       537047460
537032172       537047460
537032436       537047460
537032700       537047460
537032964       537047460
537033228       537047460
537033492       537047460
537033756       537047460
537034020       537047460
537034284       537047460
537034548       537047460
537034812       537047460
537035076       537047460
537035340       537047460
537035604       537047460
537035868       537047460
537036132       537047460
537036396       537047460
537036660       537047460
537036924       537047460
537037188       537047460
537037452       537047460
537037716       537047460
537037980       537047460
537038244       537047460
537038508       537047460
537038772       537047460
537039036       537047460
537039300       537047460
537039564       537047460
537039828       537047460
537040092       537047460
537040356       537047460
537040620       537047460
537040884       537047460
537041148       537047460
537041412       537047460
537041676       537047460
537041940       537047460
537042204       537047460
537042468       537047460
537042732       537047460
537042996       537047460
537043260       537047460
537043524       537047460
537043788       537047460
537044052       537047460
537044316       537047460
537044580       537047460
537044844       537047460
537045108       537047460
537045372       537047460
537045636       537047460
537045900       537047460
537046164       537047460
537046428       537047460
537046692       537047460
537046956       537047460

Edited 2026-06-21 00:18 by twofingers
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11516
Posted: 02:20pm 20 Jun 2026
Copy link to clipboard 
Print this post

Not having the pack/unpack destroys the colour rendering. What did  the print output show before the crash?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11516
Posted: 02:28pm 20 Jun 2026
Copy link to clipboard 
Print this post

OK, for some reason the heap isn't aligned on that version. It should be 256 aligned.
unsigned char __attribute__((aligned(256))) AllMemory[HEAP_MEMORY_SIZE + 256 + 320 * 240 * 2];

I assume you are using default 640x480 @315MHz?
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1761
Posted: 02:35pm 20 Jun 2026
Copy link to clipboard 
Print this post

  matherp said   I assume you are using default 640x480 @315MHz?

I can confirm that.
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11516
Posted: 02:37pm 20 Jun 2026
Copy link to clipboard 
Print this post

Definitely something wrong with that build. variables should always by 8-byte aligned
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1761
Posted: 02:39pm 20 Jun 2026
Copy link to clipboard 
Print this post

That’s not really relevant if I can fix it with an update. I just hadn't expected those differences. Thanks!
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11516
Posted: 03:04pm 20 Jun 2026
Copy link to clipboard 
Print this post

What worries me is that the linker has somehow ignored the alignment for that build
Edited 2026-06-21 01:05 by matherp
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1761
Posted: 03:07pm 20 Jun 2026
Copy link to clipboard 
Print this post

At the very least, this is a point to keep an eye on in the future.
causality ≠ correlation ≠ coincidence
 
javavi

Guru

Joined: 01/10/2023
Location: Ukraine
Posts: 562
Posted: 04:54pm 20 Jun 2026
Copy link to clipboard 
Print this post

Hi Peter,
I launched Bubble Universe on CSUB steroids,

PicoMiteHDMI MMBasic RP2350A Edition V6.03.00RC21
OPTION FLASH SIZE 4194304
OPTION COLOURCODE ON
OPTION KEYBOARD US
OPTION KEYBOARD PINS GP2,GP3
OPTION RESOLUTION 640x480 @ 315000KHz
OPTION HDMI PINS  1, 3, 5, 7
OPTION SDCARD GP5, GP6, GP7, GP4
OPTION AUDIO I2S GP10,GP9', ON PWM CHANNEL 11
OPTION PSRAM PIN GP8

and here's the result for me:
MODE 1 -- 28.5mS 35fps
MODE 2 -- 27.7mS 36fps
MODE 3 -- 44.9mS 22fps

! MODE 3 worked only with the PSRAM connected
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026