Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 09:58 19 Apr 2024 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 : Pico Raycast

     Page 1 of 2    
Author Message
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 890
Posted: 09:16am 16 Nov 2022
Copy link to clipboard 
Print this post

First make it work, then make it effizient

by following the YouTube Tutorial   step by step, i translated the C /openGL Code
to MM Basic and tested it on a 378000 kHz Pico Vga.
Speed on the Pico is ok but I am sure that there is much to optimise

also tested on MMBasic4W



as in the Video, there is no collition detection by now.


'----------------------
'Raycast.bas by Martin Herhaus
'MMBasic translation from
'https://youtu.be/gYRrGTC7GtA by 3DSage
'----------------------
Dim px,py,pdy,pdx,pa As float
Dim bg%,FC%,n%,mapX,mapY,mapS,HV,HH As integer
Dim Map%(84)
P2 =Pi/2
P3=3*Pi/2
DR=0.0174533 'one degree in radians

'Init
Select Case Mm.Device$
Case "PicoMiteVGA"
  Mode 2
  Font 1
  FrameBuffer Create
  FrameBuffer Write F
Case "Colour Maximite 2", "Colour Maximite 2 G2", "MMBasic for Windows"
  Mode 7
  Font 1
  Page Write 1
Case Else
  Error "Unsupported device: " + Mm.Device$
End Select
vmul=MM.VRes/512
hmul=MM.HRes/1024
hv=MM.VRes/2
hh=MM.HRes/2

Restore MapData:For n%=0 To 63:Read Map%(n%):Next n%
bg%= RGB(0,64,0)
CLS bg%
px=300:py=300:mapS=64:mapy=8:mapx=8
pdx=Cos(pa)*5:pdy=Sin(pa)*5

'main
Do
 display
 drawRays3D
 buttons
  If Mm.Device$ = "PicoMiteVGA" Then
    FrameBuffer Copy F, N
 Else
    Page Copy 1 To 0
  EndIf
Loop

Function dist(ax,ay,bx,by,ang)
 dist=Sqr((bx-ax)*(bx-ax)+(by-ay)*(by-ay))
End Function

Sub drawRays3D
Local r,mx,my,mp,dof,xstp,wcl As Integer
Local rx,ry,ra,xo,yo,dis1 As float
ra=pa-DR*30:If ra<0 Then Inc ra,2*Pi
If ra>2*Pi Then Inc ra,-2*Pi
Box hh,0,hh,hv,,RGB(0,255,255),RGB(0,255,255)
Box hh,hv/2,hh,hv/2,,RGB(255,64,0),RGB(255,64,0)
For r=0 To 59
'check Horizontal Lines
dof=0
distH=1000000:hx=px:hy=py
atan=-1/Tan(ra)
If ra>Pi Then
  ry=((Int(py/64))*64)-0.0001:rx=(py-ry)*atan+px ' Looking up
  yo=-64:xo=-yo*atan
EndIf
If ra<Pi Then
  ry=((Int(py/64))*64)+64:rx=(py-ry)*atan+px ' Looking down
  yo=64:xo=-yo*atan
EndIf
 If ra=0 Or ra=Pi Then rx=px:ry=py:dof=8 'looking straight left or right
 Do While dof<8
 mx=Int(rx/64):my=Int(ry/64):mp=my*mapx+mx
 If mp>0 And mp<mapX*mapY Then If map%(mp)=1 Then
  hx=rx:hy=ry:distH=dist(px,py,hx,hy,ra):dof=8
  Else
   rx=rx+Xo:ry=ry+Yo:Inc dof
  EndIf
 Loop
 'Line px*hmul,py*vmul,rx*hmul,ry*vmul,,RGB(Green)

'check vertical Lines
dof=0
 distV=1000000:vx=px:vy=py
ntan=-Tan(ra)
If ra>P2 And ra< P3 Then
  rx=((Int(px/64))*64)-0.0001:ry=(px-rx)*ntan+py ' Looking left
  xo=-64:yo=-xo*ntan
EndIf
If ra<P2 Or ra > P3 Then
  rx=((Int(px/64))*64)+64:ry=(px-rx)*ntan+py ' Looking right
  xo=64:yo=-xo*ntan
EndIf
 If ra=0 Or ra=Pi Then rx=px:ry=py:dof=8 'looking straight up or down
 Do While dof<8
 mx=Int(rx/64):my=Int(ry/64):mp=my*mapx+mx
 If mp<(mapX*mapY)And mp>-1 Then If map%(mp)=1 Then
  vx=rx:vy=ry:distV=dist(px,py,vx,vy,ra):dof=8
  Else
   rx=rx+Xo:ry=ry+Yo:Inc dof
  EndIf
 Loop
 If distV<distH Then rx=vx:ry=vy:dis1=DistV:wcl=RGB(0,128,0)
 If distH<distV Then rx=hx:ry=hy:dis1=DistH:wcl=RGB(0,64,0)
 Line px*hmul,py*vmul,rx*hmul,ry*vmul,,RGB(RED)
 '--- Draw 3D Walls
 ca=pa-ra
 If ca<0 Then Inc ca,2*Pi
 If ca>2*Pi Then Inc ca,-2*Pi
 dis1=dis1*Cos(ca)
 lineH=int((mapS*hh)/dis1):If lineH>hv Then lineh=hv
 lineO=int(lineh/2)
 Box hh+xstp,(hv/2)-LineO,hh/60,Lineh,,wcl,wcl
 Inc xstp,hh/60
 Inc ra,dr:If ra<0 Then Inc ra,2*Pi
 If ra>2*Pi Then Inc ra,-2*Pi
Next
End Sub

Sub display
drawmap2d
drawPlayer
End Sub

Sub drawPlayer
 Local xo,yo
 xo=px*hmul:yo=py*vmul
 fc%=RGB(yellow)
 Box xo-1,yo-1,3,3,,fc%
 Line xo,yo,xo+pdx*5*hmul,yo+pdy*5*vmul,,fc%
End Sub


Sub buttons
Local k$
k$=Inkey$
Select Case k$
 Case "a",Chr$(130)
   Inc pa,-0.1
   If pa<0 Then Inc pa,2*Pi
   pdx=Cos(pa)*5:pdy=Sin(pa)*5
 Case "d",Chr$(131)
   Inc pa, 0.1
   If pa>2*Pi Then Inc pa,-2*Pi
   pdx=Cos(pa)*5:pdy=Sin(pa)*5
 Case "w",Chr$(128):px=px+pdx:py=py+pdy
 Case "s",Chr$(129):px=px-pdx:py=py-pdy
 Case " ": Save image "cast.bmp"
End Select
End Sub

Sub drawMap2D
Local x,y,xo,yo As integer
xo=64*hmul:yo=64*vmul
For y=0 To mapy-1:For x=0 To mapx-1
    Box x*xo,y*yo,xo,yo,,0,RGB(white)*(map%(y*mapX+x)=1)
  Next : Next
End Sub
MapData:
Data 1,1,1,1,1,1,1,1
Data 1,0,1,0,0,0,0,1
Data 1,0,1,0,0,0,0,1
Data 1,0,1,0,0,0,0,1
Data 1,0,0,0,0,0,0,1
Data 1,0,0,0,0,1,0,1
Data 1,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,1,1                                                          


dont get lost  
Edited 2022-11-16 23:52 by Martin H.
'no comment
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 501
Posted: 01:57pm 16 Nov 2022
Copy link to clipboard 
Print this post


Plasma
 
gadgetjack
Senior Member

Joined: 15/07/2016
Location: United States
Posts: 127
Posted: 04:10pm 16 Nov 2022
Copy link to clipboard 
Print this post

Very good work. I have to play around with this.
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 890
Posted: 04:01pm 17 Nov 2022
Copy link to clipboard 
Print this post

  gadgetjack said  Very good work. I have to play around with this.

maybee you ll do the next wolfenstein Clone  
'no comment
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 890
Posted: 05:09pm 22 Nov 2022
Copy link to clipboard 
Print this post

updated Version
(here in Windows)



'----------------------
'Raycast.bas by Martin Herhaus
'Raycast Engine MMBasic translated from
'https://youtu.be/gYRrGTC7GtA by 3DSage
'----------------------
Dim float px,py,pdy,pdx,pa
Dim integer fps%,bg%,FC%,n%,mapX,mapY,mapS,HV,HH,vmul,hnul
mapS=64:mapy=24:mapx=24
Dim Map%(mapy*mapx)
P2 =Pi/2
P3=3*Pi/2
P2I=2*PI
DR=0.0174533 'one degree in radians

'Init
Select Case Mm.Device$
Case "PicoMiteVGA"
 Mode 2
 Font 1
 FrameBuffer Create
 FrameBuffer Write F
Case "Colour Maximite 2", "Colour Maximite 2 G2", "MMBasic for Windows"
 Mode 1,8 '800x600
 Font 1
 Page Write 1
Case Else
 Error "Unsupported device: " + Mm.Device$
End Select
vmul=MM.VRes/512
hmul=MM.HRes/1024
hv=MM.VRes/2
hh=MM.HRes/2

Restore MapData:For n%=0 To mapx*mapy-1:Read Map%(n%):Next n%
bg%= RGB(0,64,0)
CLS bg%
px=300:py=300
pdx=Cos(pa)*5:pdy=Sin(pa)*5
tm%=Timer:fps%=0
'main
Do
' display
drawRays3D
buttons
 If Mm.Device$ = "PicoMiteVGA" Then
   FrameBuffer Copy F, N
Else
   Page Copy 1 To 0
 EndIf
inc fps%:
if fps%=500 then
tm%=timer-tm%

  text hh+20,hv+20,str$(500/(tm%/1000),4,2)+"   ":fps%=0:tm%=Timer
end if
Loop

Function dist(ax,ay,bx,by,ang)
  dist=Sqr((bx-ax)*(bx-ax)+(by-ay)*(by-ay))
End Function

Sub drawRays3D
 Local integer r,mx,my,mp,dof,xstp,wcl
 Local float rx,ry,ra,xo,yo,dis1
 ra=pa-DR*30:Inc ra,P2i*(ra<0):Inc ra,-P2I*(ra>P2I)
 Box 0,0,hh<<1,hv,,RGB(0,255,255),RGB(0,255,255)
 Box 0,hv/2,hh<<1,hv/2,,RGB(255,64,0),RGB(255,64,0)
 'Cast 120 Rays
 For r=0 To 119
     'check Horizontal Lines
     dof=0
     distH=1000000:hx=px:hy=py
     atan=-1/Tan(ra)
     If ra>Pi Then
       ry=((Int(py>>6))<<6)-0.0001:rx=(py-ry)*atan+px ' Looking up
       yo=-64:xo=-yo*atan
     else
       ry=((Int(py>>6))<<6)+64:rx=(py-ry)*atan+px ' Looking down
       yo=64:xo=-yo*atan
     EndIf
     If not ra Or ra=Pi Then rx=px:ry=py:dof=mapx 'looking straight left or right
     Do While dof<mapx
       mx=Int(rx)>>6:my=Int(ry)>>6:mp=my*mapx+mx
         If mp>0 And mp<mapX*mapY Then If map%(mp)<>0 Then
           hx=rx:hy=ry:distH=dist(px,py,hx,hy,ra):dof=mapx
         Else
           inc rx,Xo:inc ry,Yo:Inc dof
        End If
    Loop
   'check vertical Lines
   dof=0
    distV=1000000:vx=px:vy=py
   ntan=-Tan(ra)
   If ra>P2 And ra< P3 Then
     rx=((Int(px>>6))<<6)-0.0001:ry=(px-rx)*ntan+py ' Looking left
     xo=-64:yo=-xo*ntan
   else
     rx=((Int(px>>6))<<6)+64:ry=(px-rx)*ntan+py ' Looking right
     xo=64:yo=-xo*ntan
   End If
    If not ra Or ra=Pi Then rx=px:ry=py:dof=mapy 'looking straight up or down
    Do While dof<mapy
      mx=Int(rx)>>6:my=Int(ry)>>6:mp=my*mapx+mx
      If mp<(mapX*mapY)And mp>-1 Then If map%(mp)<>0 Then
        vx=rx:vy=ry:distV=dist(px,py,vx,vy,ra):dof=mapy
      Else
        inc rx,Xo:inc ry,Yo:Inc dof
     End If
    Loop
    If distH<distV Then
      rx=hx:ry=hy:dis1=DistH:wcl=RGB(0,64,255)
    else
      rx=vx:ry=vy:dis1=DistV:wcl=RGB(0,128,255)
    end if
   '
   '--- Draw 3D Walls
   '
    ca=pa-ra:Inc ca,P2I*(ca<0):Inc ca,-P2I*(ca>P2I)
    dis1=dis1*Cos(ca)
    lineH=int((mapS*hh)/dis1):lineH=Min(lineH,hv)
    lineO=int(lineh>>1)
    Box xstp,(hv>>1)-LineO,1+hh/60,Lineh,,wcl,wcl
    Inc xstp,hh/60
    Inc ra,dr/2:Inc ra,P2I*(Ra<0):Inc ra,-P2I*(ra>P2I)
Next
End Sub

Sub display
drawmap2d
drawPlayer
End Sub

Sub drawPlayer
'unused
Local xo,yo
xo=px*hmul:yo=py*vmul
fc%=RGB(yellow)
Box xo-1,yo-1,3,3,,fc%
Line xo,yo,xo+pdx*5*hmul,yo+pdy*5*vmul,,fc%
End Sub


Sub buttons
Local k$
k$=Inkey$
Select Case k$
Case "a",Chr$(130)
  Inc pa,-0.1
  If pa<0 Then Inc pa,P2I
  pdx=Cos(pa)*5:pdy=Sin(pa)*5
Case "d",Chr$(131)
  Inc pa, 0.1
  If pa>P2I Then Inc pa,-P2I
  pdx=Cos(pa)*5:pdy=Sin(pa)*5
Case "w",Chr$(128):inc px,2*pdx:inc py,2*pdy
Case "s",Chr$(129):inc px,2*-pdx:inc py,2*-pdy
Case " ": Save image "cast.bmp"
End Select
End Sub

Sub drawMap2D
'unused
Local integer x,y,xo,yo
YO=2*HV/mapy:xo=HH/mapx
xo=xo*hmul:yo=yo*vmul
For y=0 To mapy-1:For x=0 To mapx-1
   Box x*xo,y*yo,xo,yo,,0,RGB(white)*(map%(y*mapX+x)<>0)
 Next : Next
End Sub
MapData:
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1
Data 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1
Data 1,0,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1
Data 1,0,1,0,0,0,0,1,0,1,0,1,0,1,0,1,1,0,0,0,1,1,1,1
Data 1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,8
Data 1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1
Data 1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1
Data 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,1,1
Data 1,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
Data 1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,1,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,0,1,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,1,1,0,1,1
Data 1,0,1,0,1,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,1
Data 1,0,0,1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,1,1,0,1,1
Data 1,0,1,0,1,0,0,0,0,1,1,0,1,1,0,0,1,0,0,1,0,0,0,1
Data 1,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,1,0,0,0,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1



Edited 2022-11-23 15:58 by Martin H.
'no comment
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 11:10am 23 Nov 2022
Copy link to clipboard 
Print this post

Very nice Martin, a bit slow on the poor old PicoMite but nothing a bout of optimisation, or failing that, a CSUB wouldn't fix I'm sure.

I have once again taken the liberty to use your code to continue ironing out some issues with my controller library:

CMM2 version with support for Wii Nunchuk, Classic, and on the DX version Atari joystick and NES gamepad; note that the latter requires an adapter to cross-over the power pin:
       raycast-cmm2.zip

PicoMiteVGA version with support for Atari joystick and NES gamepad using the PicoGAME Port A pins:
       raycast-pmvga.zip

Best wishes,

Tom
Edited 2022-11-23 23:37 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 890
Posted: 02:08pm 23 Nov 2022
Copy link to clipboard 
Print this post

Hi Tom,
sadly, I haven't found any instructions on the web yet how to compile CSubs for the Pico (Environment, compiler etc).
But maybe, I Find a faster Algorhitm to do the casts in Basic.
On the Website, where the BubbleDemo came from, is a Algorhytm with a different approach.
For Now, you'll get it a little faster by lowering the resolution
change in the  drawRays3D sub
than it does less Scans per Frame

For r=0 To 119
to  
For r=0 To 63

and  the Part

Box xstp,(hv>>1)-LineO,1+hh/60,Lineh,,wcl,wcl
Inc xstp,hh/60

to
Box xstp,(hv>>1)-LineO,1+hh/32,Lineh,,wcl,wcl
Inc xstp,hh/32



PS: Your Version works well, as long as I use Port A for Atari or NES Controller  
Edited 2022-11-24 00:41 by Martin H.
'no comment
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1133
Posted: 03:13pm 23 Nov 2022
Copy link to clipboard 
Print this post

  Martin H. said  Hi Tom,
sadly, I haven't found any instructions on the web yet how to compile CSubs for the Pico (Environment, compiler etc).
...

Hi Martin,
you didn't ask but how about this:
For infos about CSUBs on PicoMite:
https://www.thebackshed.com/forum/ViewTopic.php?TID=14126

I would like to compile your C-Code if you want.

Regards
Michael
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 03:46pm 23 Nov 2022
Copy link to clipboard 
Print this post

  Martin H. said  Hi Tom,
sadly, I haven't found any instructions on the web yet how to compile CSubs for the Pico (Environment, compiler etc) ...


Yes, you do somewhat have to piece it together from bits and pieces on TBS. I haven't done it for the PicoMite yet, but did a couple of years ago for the CMM2. I would say that figuring it out and documenting it clearly was on my TODO list, but that would imply there was an actual list as opposed to a flaming trash heap of despair .


  Martin H. said  PS: Your Version works well, as long as I use Port A for Atari or NES Controller  


As expected, I only included the code necessary to support Port A (and I2C Channel 3 on the CMM2).

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 890
Posted: 05:32pm 23 Nov 2022
Copy link to clipboard 
Print this post

  twofingers said  
  Martin H. said  Hi Tom,
sadly, I haven't found any instructions on the web yet how to compile CSubs for the Pico (Environment, compiler etc).
...

Hi Martin,
you didn't ask but how about this:
For infos about CSUBs on PicoMite:
https://www.thebackshed.com/forum/ViewTopic.php?TID=14126

I would like to compile your C-Code if you want.

Regards
Michael

the irony of the story is, I translated the Source from  C /openGL  to MM.Basic to see, if/how it could be done. Going back to C now would be a little like cheating.
I now understand the Ray Cast functions. I had already managed to do that on the Atari ages ago.
But even if I get the Ray casting with a more efficient algorythms in Basic fast enough, I dont think  it would work If I try to implement texture mapping.  
'no comment
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1133
Posted: 06:07pm 23 Nov 2022
Copy link to clipboard 
Print this post

  Martin H. said  ...
Going back to C now would be a little like cheating. ...

I understand! But maybe only a small function to improve the speed?  

Anyway, if you need help to play with CSubs ...
 
led-bloon

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 202
Posted: 12:56am 24 Nov 2022
Copy link to clipboard 
Print this post

Martin, thanks for your work here, very interesting.
Some suggestions:
1. Add to buttons() sub:
  case Chr$(27)  '<ESC>
    If Mm.Device$ = "PicoMiteVGA" Then
      FRAMEBUFFER CLOSE: CLS: END
    Else
      ???????
    Endif

2. Convert dist() function to a cSub as this is called many
times within the 120 loop in the drawRays3D() sub.
I have tried but failed to generate the code for the PicoMite.
Maybe someone else will have better luck.
led
Miss you George
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 890
Posted: 04:48am 24 Nov 2022
Copy link to clipboard 
Print this post

  led-bloon said  Martin, thanks for your work here, very interesting.
Some suggestions:
1. Add to buttons() sub:
  case Chr$(27)  '<ESC>
    If Mm.Device$ = "PicoMiteVGA" Then
      FRAMEBUFFER CLOSE: CLS: END
    Else
      ???????
    Endif

2. Convert dist() function to a cSub as this is called many
times within the 120 loop in the drawRays3D() sub.
I have tried but failed to generate the code for the PicoMite.
Maybe someone else will have better luck.
led

Hi  Led,
in my working Version I didn't use the Distance Function anymore, cause every Function call is timeconsuming .. So i do the pythagoras calculation within the Program, two times
Also, to speed things up I try to use "IF THEN" in the Loop only if it is really necessary.
That's why some adventurous lines come out like :
Inc ra,P2I*(Ra<0)-P2I*(ra>P2I)
to keep it in the Range of 2 Pi
Another way to optimize would be to rewrite the Algorythm to use degrees instead of radius, so I can convert the "floating Point Calculations" to Integers.

the best CSub would have to contain the whole Raycast Function like
Cast PX,PY,PA,Casts
that returnes the "casts" number of distances in an Array which can be read in the Draw_Wall Sub. :-)

As you can see, there is still a lot to optimize.
I have to go to the office now, but I'll think of something.
Cheers,
Mart!n
Edited 2022-11-24 16:25 by Martin H.
'no comment
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 890
Posted: 03:33pm 25 Nov 2022
Copy link to clipboard 
Print this post

  thwill said  Very nice Martin, a bit slow on the poor old PicoMite but nothing a bout of optimisation, or failing that, a CSUB wouldn't fix I'm sure.

I have once again taken the liberty to use your code to continue ironing out some issues with my controller library:

CMM2 version with support for Wii Nunchuk, Classic, and on the DX version Atari joystick and NES gamepad; note that the latter requires an adapter to cross-over the power pin:
       raycast-cmm2.zip

PicoMiteVGA version with support for Atari joystick and NES gamepad using the PicoGAME Port A pins:
       raycast-pmvga.zip

Best wishes,

Tom

Hi Tom
today I found the Time to speed it up as much as I could.
so for PicoMite VGA its ..ok (5-10 fps)
raycast-pmvga.zip
but it does not run in MMbasic4W (dosnt know the "ON" Command.
and keyboard Controll does'nt work on both Pico and Windows.
Edited 2022-11-26 01:35 by Martin H.
'no comment
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 03:40pm 25 Nov 2022
Copy link to clipboard 
Print this post

  Martin H. said  Hi Tom
today I found the Time to speed it up as much as I could.
so for PicoMite VGA its ..ok (5-10 fps)


Great. I'll try and find time to give it a spin over the weekend, but got a lot of family stuff going on.

  Martin H. said  but it does not run in MMbasic4W (dosnt know the "ON" Command.


The version you've posted has the PicoMite controller/keyboard code included in it, not the CMM2/MMB4W controller/keyboard code.

  Martin H. said  and keyboard Controll doesn't work on both Pico and Windows.


Should work on the PicoMiteVGA if you've got the firmware with the PS/2 support, and if you haven't you should have been getting an error from the call to ON PS2 ... ah, I see you have commented out the line to ON PS2 ??? you'll need that uncommented ;-)

Best wishes,

Tom
Edited 2022-11-26 01:49 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 890
Posted: 04:04pm 25 Nov 2022
Copy link to clipboard 
Print this post

  thwill said   ... ah, I see you have commented out the line to ON PS2 ??? you'll need that uncommented ;-)

Best wishes,

Tom

I commented them Out to get it Run on MMB4W
On Pico there was no Error, but i used the NES Controller but the Keyboard just over TeraTerm ...  
With a real PS2Keyboard it works  
Edited 2022-11-26 02:07 by Martin H.
'no comment
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 04:22pm 25 Nov 2022
Copy link to clipboard 
Print this post

  Martin H. said  I commented them Out to get it Run on MMB4W
On Pico there was no Error, but i used the NES Controller but the Keyboard just over TeraTerm ...  
With a real PS2Keyboard it works  


Right, you need a different keyboard driver if you are using a serial terminal, the "single source of truth" gets quite convoluted in the area of the keyboard:

' When a key is down the corresponding byte of this 256-byte map is set,
' when the key is up then it is unset.
'
' Note that when using INKEY$ (as opposed to the CMM2 'KEYDOWN' function or
' the PicoMiteVGA 'ON PS2' command) to read the keyboard we cannot detect
' keyup events and instead automatically clear a byte after it is read.
Dim ctrl.key_map%(31 + Mm.Info(Option Base))

'!ifdef CTRL_USE_ON_PS2
' Map used to convert PS/2 set 2 scan codes to entries in ctrl.key_map%().
' The scan code first has to be converted into a single byte value,
' see ctrl.on_ps2().
Dim ctrl.scan_map%(31)
'!endif

'!ifdef CTRL_USE_KEYDOWN
' Timer number configured for reading the KEYDOWN state on the CMM2.
Dim ctrl.tick_nbr%
'!endif

' Initialises keyboard reading.
'
' @param  period%  CMM2 only - interval to read KEYDOWN state, default 40 ms.
' @param  nbr%     CMM2 only - timer nbr to read KEYDOWN state, default 4.
Sub ctrl.init_keys(period%, nbr%)
 ctrl.term_keys()
'!ifdef CTRL_USE_INKEY
 On Key ctrl.on_key()
'!endif
'!ifdef CTRL_USE_ON_PS2
 Read Save
 Restore ctrl.scan_map_data
 Local i%
 For i% = Bound(ctrl.scan_map%(), 0) To Bound(ctrl.scan_map%(), 1)
   Read ctrl.scan_map%(i%)
 Next
 Read Restore
 On Ps2 ctrl.on_ps2()
'!endif
'!ifdef CTRL_USE_KEYDOWN
 ctrl.tick_nbr% = Choice(nbr% = 0, 4, nbr%)
 SetTick Choice(period% = 0, 40, period%), ctrl.on_tick(), ctrl.tick_nbr%
'!endif
End Sub

'!ifdef CTRL_USE_KEYDOWN
' Note there is little point in calling KeyDown(0) to determine the number of
' keys that are down, hardware limitations mean it's unlikely ever to be > 4
' and if a given key isn't down it just returns 0 so we harmlessly set that
' byte in the key map.
Sub ctrl.on_tick()
 Memory Set Peek(VarAddr ctrl.key_map%()), 0, 256
 Poke Var ctrl.key_map%(), KeyDown(1), 1
 Poke Var ctrl.key_map%(), KeyDown(2), 1
 Poke Var ctrl.key_map%(), KeyDown(3), 1
 Poke Var ctrl.key_map%(), KeyDown(4), 1
End Sub
'!endif

'!ifdef CTRL_USE_INKEY
Sub ctrl.on_key()
 Poke Var ctrl.key_map%(), Asc(Inkey$), 1
End Sub
'!endif

'!ifdef CTRL_USE_ON_PS2
Sub ctrl.on_ps2()
 Local ps2% = Mm.Info(PS2)
 Select Case ps2%
   Case Is < &hE000 : Poke Var ctrl.key_map%(), Peek(Var ctrl.scan_map%(), ps2% And &hFF), 1
   Case Is < &hF000 : Poke Var ctrl.key_map%(), Peek(Var ctrl.scan_map%(), (ps2% And &hFF) + &h80), 1
   Case Is < &hE0F000 : Poke Var ctrl.key_map%(), Peek(Var ctrl.scan_map%(), ps2% And &hFF), 0
   Case Else : Poke Var ctrl.key_map%(), Peek(Var ctrl.scan_map%(), (ps2% And &hFF) + &h80), 0
 End Select
End Sub
'!endif

' Terminates keyboard reading.
Sub ctrl.term_keys()
'!ifdef CTRL_USE_INKEY
 On Key 0
'!endif
'!ifdef CTRL_USE_ON_PS2
 On Ps2 0
'!endif
'!ifdef CTRL_USE_KEYDOWN
 If ctrl.tick_nbr% <> 0 Then SetTick 0, 0, ctrl.tick_nbr%
'!endif
 Memory Set Peek(VarAddr ctrl.key_map%()), 0, 256
 Do While Inkey$ <> "" : Loop
End Sub

Function ctrl.keydown%(i%)
 ctrl.keydown% = Peek(Var ctrl.key_map%(), i%)
'!ifdef CTRL_USE_INKEY
 Poke Var ctrl.key_map%(), i%, 0
'!endif
End Function

...

'!ifdef CTRL_USE_ON_PS2
ctrl.scan_map_data:

Data &h9C92919395009900, &h0060099496989A00, &h0031710000008B00, &h00327761737A0000
Data &h0033346564786300, &h0035727466762000, &h0036796768626E00, &h003837756A6D0000
Data &h0039306F696B2C00, &h002D703B6C2F2E00, &h00003D5B00270000, &h000023005D0A0000
Data &h0008000000005C00, &h0000003734003100, &h001B383635322E30, &h0000392A2D332B9B
Data &h0000000097000000, &h0000000000000000, &h0000000000008B00, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000000000000000, &h0000000000000000, &h0000000000000000
Data &h0000000000000000, &h0000008682008700, &h0000808300817F84, &h0000889D00890000
'!endif


In theory the code could have been written with a whole bunch of IF MM.DEVICE$ calls but that isn't the route I've chosen, instead I'm generating different ctrl-device.inc files to be included (manually on the PicoMiteVGA) for the different configurations. Of course developers can do what they like with my library the main thing is to settle on the API for the driver SUBs which I think I've done.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
PilotPirx

Regular Member

Joined: 03/11/2020
Location: Germany
Posts: 62
Posted: 02:25pm 30 Nov 2022
Copy link to clipboard 
Print this post

Hello

with my PicoVGA i got a

[18] FrameBuffer Create
Error : Unknown Command

with the first listing.

The PicoMiteVGA User Manual MMBasic Ver 5.07.04
shows no FrameBuffer commands too?

What's wrong with my PicoVGA?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8566
Posted: 02:29pm 30 Nov 2022
Copy link to clipboard 
Print this post

You need a later version

https://geoffg.net/Downloads/picomite/PicoMite_Beta.zip
 
PilotPirx

Regular Member

Joined: 03/11/2020
Location: Germany
Posts: 62
Posted: 03:37pm 30 Nov 2022
Copy link to clipboard 
Print this post

Thanks for the link,
is there a description of the new commands(sprite, framebuffer, DRAW3D) for the Picomite VGA? This is quite limited in its capabilities.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024