Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:53 31 May 2025 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 : MMBasic on PicoCalc - using sprites ?

Author Message
DigitalDreams
Newbie

Joined: 03/05/2025
Location: United Kingdom
Posts: 13
Posted: 05:38pm 04 May 2025
Copy link to clipboard 
Print this post

Heading into sprite handling on PicoCalc and hitting issues straight away. Whether I load a bmp to the screen and ‘sprite read’ from it OR ‘sprite load bmp’ from the bmp file itself I get the error “not available on physical display” ??

I find it hard to accept or believe it's not possible on this device as other emulators are handling them fine.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10107
Posted: 05:48pm 04 May 2025
Copy link to clipboard 
Print this post

Sprites on LCD displays only work on memory framebuffers. LCD displays, and particularly SPI connected displays are too slow to be usable. Also many SPI LCD displays do not connect MISO and without that you can't read the data from display.
Have a look at the code for Petscii Robots to see what can be done with a slow SPI display
 
DigitalDreams
Newbie

Joined: 03/05/2025
Location: United Kingdom
Posts: 13
Posted: 06:43pm 04 May 2025
Copy link to clipboard 
Print this post

Yes it seems I'm stuck with the task of writing my own sprite functions that utilise the framebuffer commands. There's also 'GUI BITMAP' ?.

Might seem like a slow lcd yet saw a post recently where someone had managed to get a game emulator running at 40fps on a PicoCalc
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10107
Posted: 06:54pm 04 May 2025
Copy link to clipboard 
Print this post

Sprites are already fully implemented using a framebuffer. The emulator is almost certainly doing the same thing. Build the image in memory and then just copy areas that have changed to the display.
 
DigitalDreams
Newbie

Joined: 03/05/2025
Location: United Kingdom
Posts: 13
Posted: 07:03pm 04 May 2025
Copy link to clipboard 
Print this post

  matherp said  Sprites are already fully implemented using a framebuffer. The emulator is almost certainly doing the same thing. Build the image in memory and then just copy areas that have changed to the display.


I'd love to see a short and simple working example of the sprite commands using a framebuffer on LCD to create a simple sprite and move it... Early days for me so forgive the newbie image I portray..
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10107
Posted: 10:38am 05 May 2025
Copy link to clipboard 
Print this post

Option console serial
FRAMEBUFFER create
FRAMEBUFFER write f
CLS
'brownian motion demo using sprites
Dim integer x(32),y(32),c(32)
Dim float direction(32)
Dim integer i,j,k, collision=0
Dim string q$
For i=1 To 32
direction(i)=Rnd*360 'establish the _
starting direction for each atom
c(i)=RGB(Rnd*255,Rnd*255,Rnd*255) _
'give each atom a colour
Circle 9,9,9,1,,RGB(white),c(i) 'draw _
the atom
Sprite read i,0,0,19,19 'read it in _
as a sprite
Next i
CLS RGB(myrtle)
Box 1,1,MM.HRES-2,MM.VRES-2
k=1
For i=MM.HRES\9 To MM.HRES\9*8 Step _
MM.HRES\9
For j=MM.VRES\9 To MM.VRES\9*8 Step _
MM.VRES\5
  Sprite show k,i,j,1
  x(k)=i
  y(k)=j
  vector k,direction(k), 0, x(k), _
y(k) 'load up the vector move
  k=k+1
Next j
Next i
'
Do
For i=1 To 32
  vector i, direction(i), 1, x(i), _
y(i)
  Sprite show i,x(i),y(i),1
  If sprite(S,i)<>-1 Then
    break_collision i
  EndIf
Next i
FRAMEBUFFER copy f,n
Print Timer:Timer =0
Loop
'
Sub vector(myobj As integer, angle As _
float, distance As float, x_new As _
integer, y_new As integer)
Static float y_move(32), x_move(32)
Static float x_last(32), y_last(32)
Static float last_angle(32)
If distance=0 Then
  x_last(myobj)=x_new
  y_last(myobj)=y_new
EndIf
If angle<>last_angle(myobj) Then
  y_move(myobj)=-Cos(Rad(angle))
  x_move(myobj)=Sin(Rad(angle))
  last_angle(myobj)=angle
EndIf
x_last(myobj) = x_last(myobj) + _
distance * x_move(myobj)
y_last(myobj) = y_last(myobj) + _
distance * y_move(myobj)
x_new=Cint(x_last(myobj))
y_new=Cint(y_last(myobj))
Return

' keep doing stuff until we break the _
collisions
Sub break_collision(atom As integer)
Local integer j=1
Local float _
current_angle=direction(atom)
'start by a simple bounce to break _
the collision
If sprite(e,atom)=1 Then
  'collision with left of screen
  current_angle=360-current_angle
ElseIf sprite(e,atom)=2 Then
  'collision with top of screen
    _
current_angle=((540-current_angle) Mod _
360)
ElseIf sprite(e,atom)=4 Then
  'collision with right of screen
  current_angle=360-current_angle
ElseIf sprite(e,atom)=8 Then
  'collision with bottom of screen
  current_angle=((540-current_angle) _
Mod 360)
Else
  'collision with another sprite or _
with a corner
  current_angle = current_angle+180
EndIf
direction(atom)=current_angle
vector atom,direction(atom),j,x(atom),_
y(atom) 'break the collision
Sprite show atom,x(atom),y(atom),1
'if the simple bounce didn't work try _
a random bounce
Do While (sprite(t,atom) Or sprite(e,_
atom)) And j<10
  Do
    direction(atom)= Rnd*360
    vector atom,direction(atom),j,_
x(atom),y(atom) 'break the collision
    j=j+1
  Loop Until x(atom)>=0 And _
x(atom)<=MM.HRES-sprite(w,atom) And _
y(atom)>=0 And _
y(atom)<=MM.VRES-sprite(h,atom)
  Sprite show atom,x(atom),y(atom),1
Loop
' if that didn't work then place the _
atom randomly
Do While (sprite(t,atom) Or sprite(e,_
atom))
  direction(atom)= Rnd*360
  x(atom)=Rnd*(MM.HRES-sprite(w,_
atom))
  y(atom)=Rnd*(MM.VRES-sprite(h,_
atom))
  vector atom,direction(atom),0,_
x(atom),y(atom) 'break the collision
  Sprite show atom,x(atom),y(atom),1
Loop
End Sub
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3331
Posted: 01:55pm 05 May 2025
Copy link to clipboard 
Print this post

When I try this sprite test it chokes on the line continuation:

> run
[12] starting direction For each atom
Error : Unknown command
> option list
PicoMite MMBasic RP2040 Edition V6.00.02RC21
OPTION SYSTEM SPI GP18,GP19,GP16
OPTION CPUSPEED (KHz) 200000
OPTION DISPLAY 50, 120
OPTION LCDPANEL ILI9341, RLANDSCAPE,GP21,GP20,GP17
OPTION SDCARD GP2
OPTION MODBUFF ENABLE
>


I did a clear_flash and downloaded V6.00.02RC21 again to make sure I hadn't flashed an older version.

What am I doing wrong?

EDIT: Answer--using wrong firmware; downloaded PicoMiteRP2040V6.00.02RC20e and all works.

Brilliant.


~
Edited 2025-05-06 00:01 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
dddns
Guru

Joined: 20/09/2024
Location: Germany
Posts: 412
Posted: 03:45pm 05 May 2025
Copy link to clipboard 
Print this post

If you don't need to detect collisions: I could realize 1,3s of video sequence on a ili9143. Using blit could be an alternative..early work of mine

moving a blit looks much better on a highres colour lcd because its in full colour and flicker free and fast for a square like 50x50 which can also be done with a RP2040. Copy away the area and redraw it for restoring the background is not visible to the eye

a size of a mouse cursor can be moved almost as fast as on PC on my ssd1963(on a photo as background)

You can also do your first tries and move a triangle by using TRIANGLE SAVE.
It would be wonderful if this would exist for POLYGON

I have to get that right: read and restoring the background can be done with a blit. the object which should be drawn cannot be a blit but any graphical command can be used including pixel. The object needs to be drawn exactly with its outline as I couldn't find a way for transparent color with blit especially not for BLIT LOAD
A mouse cursor e.g. can be a polygon and is drawn like in a millisecond..
Amazing complex objects can be realized with polygon and are all drawn in one step e.g. a complete outline of a building. it only needs fantasy
Edited 2025-05-06 03:16 by dddns
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025