Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : On the Road again

   Page 1 of 5    
Posted: 09:37am
10 Oct 2022
Copy link to clipboard
Martin H.
Guru


PicoMiteVGA MMBasic Version 5.07.05RC6
CPUSPEED 378000

Proof of concept..
parts of the concept are inspired by olc https://youtu.be/KkMZI5Jbf18

Dim Col%(15),Xofs%(160)
Restore colors:For f%=1 To 15:Read Col%(f%):Next f%
SH%=240:SW%=320
dist%=0:Speed%=15
Option Break 4: On Key 3, on_break
MODE 2
FRAMEBUFFER create
FRAMEBUFFER WRITE F
For f%=0 To 159:Xofs%(f%)=((160*Exp(f%/50))/20)-8:Next
CLS COL%(1)
HW%=SW%/2:HH%=SH%/2:t%=Timer
'-------endless loop -----------------------
Do
 'bend right
 For n%=1 To 1000 Step Speed%
   Box 0,hh%,SW%,hh%,,COL%(2),COL%(2)
   For F%=0 To HH%
     bc%=get_BorderCol%()
     ofs%=xofs%(hh%-f%)*n%/400
     BB%=Int(f%/5)
     Box HW%-F%-bb%+ofs%,HH%+F%,bb%+bb%+f%+f%,1,,bc%,bc%
     Box HW%-F%+ofs%,HH%+F%,f%+f%,1,,0,0
   Next
   FRAMEBUFFER COPY F,N,b
   Inc dist%
 Next

'bend back
 For n%=1000 To 1 Step -Speed%
   Box 0,hh%,SW%,hh%,,COL%(2),COL%(2)
   For F%=0 To HH%
     bc%=get_BorderCol%()
     ofs%=xofs%(hh%-f%)*n%/400
     BB%=Int(f%/5)
     Box HW%-F%-bb%+ofs%,HH%+F%,bb%+bb%+f%+f%,1,,bc%,bc%
     Box HW%-F%+ofs%,HH%+F%,f%+f%,1,,0,0
   Next
   FRAMEBUFFER COPY F,N,b
   Inc dist%
 Next

'bend left
 For n%=1 To 1000 Step Speed%
   Box 0,hh%,SW%,hh%,,COL%(2),COL%(2)
   For F%=0 To HH%
     bc%=get_BorderCol%()
     ofs%=xofs%(hh%-f%)*n%/400
     BB%=Int(f%/5)
     Box HW%-F%-bb%-ofs%,HH%+F%,bb%+bb%+f%+f%,1,,bc%,bc%
     Box HW%-F%-ofs%,HH%+F%,f%+f%,1,,0,0
   Next
   FRAMEBUFFER COPY F,N,b
   Inc dist%
 Next

'bend back
 For n%=1000 To 1 Step -Speed%
   Box 0,hh%,SW%,hh%,,COL%(2),COL%(2)
   For F%=0 To HH%
     bc%=get_BorderCol%()
     ofs%=xofs%(hh%-f%)*n%/400
     BB%=Int(f%/5)
     Box HW%-F%-bb%-ofs%,HH%+F%,bb%+bb%+f%+f%,1,,bc%,bc%
     Box HW%-F%-ofs%,HH%+F%,f%+f%,1,,0,0
   Next
   Inc dist%
   FRAMEBUFFER COPY F,N,b
 Next
 dist%=dist% And 1023
Loop
'------------------------------

Function get_BorderCol%()
 get_BorderCol%=col%(7)':Exit Function
 ClipColor=Sin((((120-f%)/40)^3)+dist%)
  If ClipColor>0 Then get_BorderCol%=col%(4)
End Function

Sub on_break
 Sprite CLOSE all: FRAMEBUFFER CLOSE
 Do While Inkey$<>"":Loop
 CLS :MODE 1: Option Break 3
 End
End Sub
colors:
'--Colorscheme accordung to matherp
Data RGB(BLUE),RGB(GREEN),RGB(CYAN),RGB(RED),RGB(MAGENTA),RGB(YELLOW),RGB(WHITE)
Data RGB(MYRTLE),RGB(COBALT),RGB(MIDGREEN),RGB(CERULEAN),RGB(RUST),RGB(FUCHSIA)
Data RGB(BROWN),RGB(LILAC)

feel free to use and improve it,
if someone likes to write a Racing game for the Pico  
if you want to drive straight ahead just do a loop with ofs%=0







Cheers
Mart!n
Edited 2022-10-10 20:00 by Martin H.
 
Posted: 11:25am
10 Oct 2022
Copy link to clipboard
Nimue
Guru


Very "Chequered Flag" from my Speccy days.

 
 
Posted: 12:34pm
10 Oct 2022
Copy link to clipboard
Amnesie
Guru

Wow! This is really cool! Thanks!
 
Posted: 12:41pm
11 Oct 2022
Copy link to clipboard
Martin H.
Guru


  Amnesie said  Wow! This is really cool! Thanks!

Thank you
As this is just a proof of concept, I tested if it could be done that way.

In the next Step i try to optimise the code and add a track and a Car  
 
Posted: 04:08pm
11 Oct 2022
Copy link to clipboard
stanleyella
Guru


Looks interesting but I have not used vga picomite so not sure how it works.
It can not be palette switching and do not understand frame buffer but is vgapicomite faster than non vga picomite using a spi lcd?
 
Posted: 05:23pm
11 Oct 2022
Copy link to clipboard
Martin H.
Guru


Every single Frame is completly redrawn.
With the use of the Framebuffer I can redraws the screen hidden and make it Vissible when it is ready. This makes the screen animation flicker-free.

Here I paint the Lower half of the screen, green, then I draw Line by Line, the Border and the Street.

by giving up the get_BorderCol% Function call and replacing with
bc%=col%(7-3*((Sin((((150-f%)/40)^3)+dist%))>0))

this little demo gets up to 30 fps

I dont know, how fast the spi lcd can be redrawn.
Edited 2022-10-12 03:34 by Martin H.
 
Posted: 10:07pm
11 Oct 2022
Copy link to clipboard
stanleyella
Guru


  Martin H. said  Every single Frame is completly redrawn.
With the use of the Framebuffer I can redraws the screen hidden and make it Vissible when it is ready. This makes the screen animation flicker-free.

Here I paint the Lower half of the screen, green, then I draw Line by Line, the Border and the Street.

by giving up the get_BorderCol% Function call and replacing with
bc%=col%(7-3*((Sin((((150-f%)/40)^3)+dist%))>0))

this little demo gets up to 30 fps

I dont know, how fast the spi lcd can be redrawn.

Not 30fps using ili9341 but lots of speed increase if blit load blit write used.
 
Posted: 06:54am
12 Oct 2022
Copy link to clipboard
Mixtel90
Guru


BLIT sends over the new data to replace the old. It does this over the SPI connection in a single bust as far as I know. Thus, although it isn't dependent on the speed of the CPU it is dependent on the speed of the SPI link. Only CPU1 is used.

In VGA output CPU1 writes screen data to the framebuffer RAM and then just carries on with whatever it's doing. CPU2 reads the contents of the framebuffer and outputs it as RGB signals syncronised with the VSYNC and HSYNC signals being produced by PIO1. The display process takes up virtually nothing of CPU1's time - that mere;y writes to the framebuffer and forgets it. You lose the use of CPU2 (but MMBasic has no support for it anyway) and PIO1, but you still have PIO2 to play with.

AFAIK the VGA output from the PicoMite VGA is 50Hz so I suppose that the maximum possible update speed is 50fps. CPU1 can write to the framebuffer faster than this, which is why there is a FRAMEBUFFER function, so that you can wait until the flyback period and update the screen during that. It will then give you flicker-free graphics.

Exactly which sort of display is "faster" probably depends on how you define "faster" as LCDs can do some things in hardware, saving on SPI time. Parallel LCD displays are much faster than SPI but use up almost all of the I/O pins.
.
Edited 2022-10-12 17:06 by Mixtel90
 
Posted: 07:01am
12 Oct 2022
Copy link to clipboard
Martin H.
Guru


  Quote  Not 30fps using ili9341 but lots of speed increase if blit load blit write used.


sadly, I dont have a ili9341 here to test it, but to use Blit, we would need a source to Blit from and I have no Idea, if it is possibl.
to paint in the Blit source  
Nevertheless, I tryed a Version without using a framebuffer, which hopefully would also run with the ili9341...


Dim Col%(15),Xofs%(160)
Restore colors:For f%=1 To 15:Read Col%(f%):Next f%
'SH% and SW% Displayresolution
SH%=240:SW%=320
dist%=0:Speed%=4
Option Break 4: On Key 3, on_break
MODE 2
'Precalculate the Curve
For f%=0 To 159:Xofs%(159-f%)=((160*Exp(f%/50))/20)-8:Next
'
CLS COL%(1)
HW%=SW%/2:HH%=SH%/2
'-------endless loop -----------------------
'b1x% left x position of the left Border
'b2x% right x position of the left Border and left x position of the street
'b3x% right x position of the street and left x position of the right Border
'b4x% right x position of the right Border
'BB% Border broad
'bc% Border Color (red or white) calculated over Sinus Function
'HH% Half Screen y-Res  HW% Half Screen x-Res
'xofs%() Pre calculated Curve over Exponetial function
'ofsx% how much has the Curve to be bended
Do
t%=Timer
 'bend right
 For n%=1 To 1000 Step Speed%
   For F%=0 To HH%
     bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
     ofs%=xofs%(f%)*n%/1000
     y%=hh%+f%
     BB%=Int(f%/4)
     b1X%=HW%-F%-bb%+ofs%:b2x%=HW%-F%+ofs%
     b3x%=HW%-F%+ofs%+2*f%:b4x%=b1x%+(2*bb%+2*f%)
     Line 0,y%,b1x%,y%,,COL%(2):Line b1x%,y%,b2x%,y%,,bc%
     Line  b2x%,y%,b3x%,y%,,0
     Line b3x%,y%,b4x%,y%,,bc%:Line b4x%,y%,SW%,y%,,COL%(2)
   Next
   Inc dist%
  Next
'bend back
 For n%=1000 To 1 Step -Speed%
   For F%=0 To HH%
     bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
     ofs%=xofs%(f%)*n%/1000
     y%=hh%+f%
     BB%=Int(f%/4)
     b1X%=HW%-F%-bb%+ofs%:b2x%=HW%-F%+ofs%
     b3x%=HW%-F%+ofs%+2*f%:b4x%=b1x%+(2*bb%+2*f%)
     Line 0,y%,b1x%,y%,,COL%(2):Line b1x%,y%,b2x%,y%,,bc%
     Line  b2x%,y%,b3x%,y%,,0
     Line b3x%,y%,b4x%,y%,,bc%:Line b4x%,y%,SW%,y%,,COL%(2)
   Next
   Inc dist%
 Next
'bend left
 For n%=1 To 1000 Step Speed%
  For F%=0 To HH%
     bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
     ofs%=xofs%(f%)*n%/1000
     y%=hh%+f%:BB%=Int(f%/4)
     b1X%=HW%-F%-bb%-ofs%:b2x%=HW%-F%-ofs%
     b3x%=HW%-F%-ofs%+2*f%:b4x%=b1x%+(2*bb%+2*f%)
     Line 0,y%,b1x%,y%,,COL%(2):Line b1x%,y%,b2x%,y%,,bc%
     Line b2x%,y%,b3x%,y%,,0
     Line b3x%,y%,b4x%,y%,,bc%:Line b4x%,y%,SW%,y%,,COL%(2)
   Next
  Inc dist%
 Next
'bend back
 For n%=1000 To 1 Step -Speed%
   For F%=0 To HH%
     bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
     ofs%=xofs%(f%)*n%/1000
     y%=hh%+f%:BB%=Int(f%/4)
     b1X%=HW%-F%-bb%-ofs%:b2x%=HW%-F%-ofs%
     b3x%=HW%-F%-ofs%+2*f%:b4x%=b1x%+(2*bb%+2*f%)
     Line 0,y%,b1x%,y%,,COL%(2):Line b1x%,y%,b2x%,y%,,bc%
     Line b2x%,y%,b3x%,y%,,0
     Line b3x%,y%,b4x%,y%,,bc%:Line b4x%,y%,SW%,y%,,COL%(2)
   Next
   Inc dist%
 Next
 dist%=dist% And 255
 t%=(Timer-t%)
 t%=t%/1000
 Print @(0,0)1000/t%
Loop
'------------------------------
Sub on_break
 MODE 1: Option Break 3
 End
End Sub
colors:
'--Colorscheme accordung to matherp
Data RGB(BLUE),RGB(GREEN),RGB(CYAN),RGB(RED),RGB(MAGENTA),RGB(YELLOW),RGB(WHITE)
Data RGB(MYRTLE),RGB(COBALT),RGB(MIDGREEN),RGB(CERULEAN),RGB(RUST),RGB(FUCHSIA)
Data RGB(BROWN),RGB(LILAC)                                                                    

with CPUSPEED 378000 i get a result of 22-23 fps. To speed things up, one can half the Resolution of the street (as originally using the Box Command with the height of 2 and just draw every 2nd Line)
please try it and give me a Feedback
Cheers
Mart!n
Edited 2022-10-12 17:10 by Martin H.
 
Posted: 02:05pm
12 Oct 2022
Copy link to clipboard
stanleyella
Guru


@Martin.H
Thanks for the code/advice.
The lcd is 320x240 and it does not have a buffer ... as vga does.
I have not used the sd card on the lcd display to load bitmaps yet.
How do lines like bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
work in real time ??? Lot of repeated calc. in a screen.
There are 32 .. not 8 blit buffers for the lcd but scrolling a part of the screen is slow. Maybe a spi thing and do not know if baud rate would make it faster.
stan
I will try to use your code, cheers
 
Posted: 02:31pm
12 Oct 2022
Copy link to clipboard
stanleyella
Guru


I tried the code but mode 2 is unknown and I have not read the vga mmb manual.
 
Posted: 02:34pm
12 Oct 2022
Copy link to clipboard
Martin H.
Guru


  stanleyella said  I tried the code but mode 2 is unknown and I have not read the vga mmb manual.

Mode 2 switches VGA to 320x240 Mode with 16 colors.
As your Display has this resolution fixed, just delete the Line
Edited 2022-10-13 00:36 by Martin H.
 
Posted: 02:53pm
12 Oct 2022
Copy link to clipboard
Martin H.
Guru


  stanleyella said  @Martin.H

How do lines like bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
work in real time ???

The Spaces of the upper strips at the Border is less than the Lower ones,
for this:
Sin((((120-f%)/40)^3)+dist%)
f% is the y position of the Line and Dist% is just a Framecounter to simulate driving.
calculates a point in a Sinewave at which frequency increases starting with the Phase dist%
I use this to deside to use Color 7 (White) or Color 4 (Red) for the Border

bc%=col%(7-3*((Sin((((120-f%)/40)^3)+dist%))>0))
the color value is 7 but subtracts 3 if the Result of the Sine-Function is Positiv.
Look at the Listing in the first Post.
It is the Function get_BorderCol%() from the Listing above in a conpressed form.
Cause every function call takes some time and it is called 120 times per Frame, so I put it in one basic Line.
The Idea for this method is from javidx9 (one Lone Coder) who used the same calculation in his video.
Code-It-Yourself! Retro Arcade Racing Game - Programming from Scratch (Quick and Simple C++)

easy, eh  
Maybee I've been working with Excel for to long, where you're used to summarizing formulas
Edited 2022-10-13 02:09 by Martin H.
 
Posted: 05:56pm
12 Oct 2022
Copy link to clipboard
stanleyella
Guru


@Martin.H. thank you. I was thinking how it works on the eye and no flicker.
I can not compare until I setup vga mmb. I like the NON vga mmb.
It is not the same mmb but both have features you can use for graphic animation.

Dim Col%(15),Xofs%(160)
Restore colors:For f%=1 To 15:Read Col%(f%):Next f%

Data RGB(BLUE),RGB(GREEN),RGB(CYAN),RGB(RED),RGB(MAGENTA),RGB(YELLOW),RGB(WHITE)
Data RGB(MYRTLE),RGB(COBALT),RGB(MIDGREEN),RGB(CERULEAN),RGB(RUST),RGB(FUCHSIA)
Data RGB(BROWN),RGB(LILAC)  
Did not work, code ran-no display.
I will try

CONST bk = RGB(BLack)
const wh = rgb(white)
const bl = rgb(blue)
const gr = rgb(green)
const cy = rgb(cyan)
const re = rgb(red)
const ma = rgb(magenta)
const ye = rgb(yellow)
const br = rgb(brown)
 
Posted: 06:22pm
12 Oct 2022
Copy link to clipboard
Martin H.
Guru


I can't see the benefit of using constants instead of an array.
Except that you can't call up the colors by a number and so the Program for the Calculation will get more complex
 
Posted: 06:51pm
12 Oct 2022
Copy link to clipboard
stanleyella
Guru


  Martin H. said  I can't see the benefit of using constants instead of an array.
Except that you can't call up the colors by a number and so the Program for the Calculation will get more complex


Your code did not work with mmedit as I think mmbasic  vga and non vga are incompatible. I use an emulator to redo the 80's software so vga no interest as I have 3500 zx spectrum games. I want to do my own clone games on touch lcd and no mechanical buttons.
anyone done missile command? How to do line x,y , xend.yend a pixel at at a time.
ie break down line to a pixel each loop.
I am resorting to Bresenham's line algorithm.
I think trig may be better.
cheers stan
Edited 2022-10-13 05:15 by stanleyella
 
Posted: 07:28pm
12 Oct 2022
Copy link to clipboard
Martin H.
Guru


ähhhm .. no
we both use the RGB() function in both examples

using an Array or reading data are also no specific functions in the VGA Version of MM Basic/ Picomite..
but let it test ...

Here from my standard PicoMite (NonVGA)
using TeraTerm and serial connection
PicoMite MMBasic Version 5.07.03



Saved 212 bytes
> run
>
> for f%=0 to 15:print col%(f%);",";: next
0, 255, 65280, 65535, 16711680, 16711935, 16776960, 16777215, 16384, 16639, 32768, 33023, 16728064, 16728319, 16744448, 16744703,
> list
Dim Col%(15)
Restore colors:For f%=1 To 15:Read Col%(f%):Next f%
colors:
Data RGB(BLUE),RGB(GREEN),RGB(CYAN),RGB(RED),RGB(MAGENTA),RGB(YELLOW),RGB(WHITE)
Data RGB(MYRTLE),RGB(COBALT),RGB(MIDGREEN),RGB(CERULEAN),RGB(RUST),RGB(FUCHSIA)
Data RGB(BROWN),RGB(LILAC)
>
> option list
OPTION SYSTEM SPI GP18,GP19,GP16
OPTION COLOURCODE ON
OPTION KEYBOARD GR
OPTION CPUSPEED (KHz) 252000
OPTION DISPLAY 40, 120
OPTION SDCARD GP22

so, I dont know what goes wrong on your system  
 
Posted: 08:26pm
12 Oct 2022
Copy link to clipboard
stanleyella
Guru


Nice,tried on lcd. carp camera
https://www.youtube.com/watch?v=fAhvyDnnfYc
 
Posted: 09:06pm
12 Oct 2022
Copy link to clipboard
TassyJim
Guru


Your version without framebuffer runs well on a LCD (ILI9341) at a framerate of 10.526

Looks smooth.

Because the LCD version doesn't use MODE, you just have to rem out the MODE 2 and MODE 1 lines. Because of that, you don't need the on_break sub

NO other changes needed.

Jim

For those who refuse to use the console/terminal change the PRINT (~ line 86) to
text 1,1, str$(1000/t%,3,3)

Edited 2022-10-13 07:22 by TassyJim
 
Posted: 05:37am
13 Oct 2022
Copy link to clipboard
Martin H.
Guru


Hi Jim  
  Quote  Because the LCD version doesn't use MODE, you just have to rem out the MODE 2 and MODE 1 lines. Because of that, you don't need the on_break sub

Right, I just forgot to take these commands out when adopting the code.
Thanks

  Quote  For those who refuse to use the console/terminal change the PRINT (~ line 86) to

That gives me the idea to write a "ASCII ART Version" for VT 100 Terminal.
Somehow ZX81 like but with Colors

Cheers
  Mart!n
Edited 2022-10-13 15:41 by Martin H.
 
   Page 1 of 5    
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026