Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 16:14 27 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 : MMBasic Programming Challenge 2022

     Page 2 of 7    
Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 07:11pm 21 May 2022
Copy link to clipboard 
Print this post

  LeoNicolas said  My game is 50% implemented. This weekend I will try to reach 80%.


I seem to recall from my days of employment that when the spec was 90% completed, only about 50% of the time needed to actually finish had been put in.  

YMMV
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Lodovik

Newbie

Joined: 17/05/2021
Location: Canada
Posts: 40
Posted: 04:01pm 22 May 2022
Copy link to clipboard 
Print this post

My project is almost finished but I have some doubts about if it could be accepted.

I ported a fractal landscape generator that I found in an old Compute magazine from 1987. I put a lot of time enhancing it and it now produces results that are quite better and vastly different than the original. The problem is that the main algorithm is not mine and, just until this morning, I hadn't thought about that, absorbed in my programming frenzy.

Is it OK to enter it? I intend to give full credits to the original author, of course, as well as a reference to the article.

As a side note, I had real fun retyping an old AmigaBASIC program that I probably entered when it was published.

If it's not OK, I have a backup entry project and I will still release the fractal generator to the CMM community anyways.

Thanks.
 
Rado
Regular Member

Joined: 27/11/2020
Location: Croatia
Posts: 59
Posted: 08:33am 23 May 2022
Copy link to clipboard 
Print this post

It has been published in a magazine and was substantially improved with your work? Go with it, just credit the original author for the inspiration, I'd say.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3841
Posted: 10:33am 23 May 2022
Copy link to clipboard 
Print this post

Hi Ludovik,

I've sent a query out to the other judges, but my suspicion is that this will not be a problem - though you might lose a couple of points in the originality category - or then again maybe not.

Please note that the only entry that has been received so far is @vegipete's - and even that hasn't been "officially" received since it was not submitted to mmbasic.challenge@outlook.com.

If anyone does need an extension of the deadline (currently Wednesday 1st June) then please let us know and we will consider it.

Best wishes,

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

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 532
Posted: 01:06pm 23 May 2022
Copy link to clipboard 
Print this post

  thwill said  If anyone does need an extension of the deadline (currently Wednesday 1st June) then please let us know and we will consider it.

Tom
Hi Tom,
from my side will be extension by 2 weeks very welcomed...
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
Lodovik

Newbie

Joined: 17/05/2021
Location: Canada
Posts: 40
Posted: 02:08pm 23 May 2022
Copy link to clipboard 
Print this post

  thwill said  I've sent a query out to the other judges, but my suspicion is that this will not be a problem - though you might lose a couple of points in the originality category - or then again maybe not.
Tom


That’s OK with me, thanks. I’m now in the « crunch the code » phase trying to cram some additional features and niceties while trying to keep the code readable. The optimization is the fun part for me. After all, I learned programming BASIC on a pocket computer that had a total of 1424 bytes of memory…
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 444
Posted: 06:20am 24 May 2022
Copy link to clipboard 
Print this post

The same for me, the extension will be very welcome as well
 
Lodovik

Newbie

Joined: 17/05/2021
Location: Canada
Posts: 40
Posted: 03:07pm 24 May 2022
Copy link to clipboard 
Print this post

Here’s my submission for the contest. It’s an adaptation of a program originally published in Compute! Aug 1987, page 89. This program was developed on a CMM2 at 480 MHz.

The original program has been enhanced, reworked and modified to suit a faster machine with better graphics. Even if the core algorithm is basically the same, the rest is quite different.

When you first run the program, you will see the first fractal land generated in real time. Since the process is quite long, the subsequent images are generated while the last completed one is displayed. Be patient! It takes several minutes to generate a landscape and a progress bar will show you the current state of the progress.

The original program generated only one type of landscape in one color (brown), at low resolution. I’ve added more color, bigger landscapes and a totally configurable landscape parameters system (in DATAs). Five presets are already entered and the program will cycle between them. For each preset, the sets of parameters will provide enough randomness to produce greatly varied outputs. More can be added but the file size limit of the contest only allowed me to put 5 sets.

Here’s a description of one of the presets:

data "Jungle",.25,3, 75,85, 65,70, 10,13, 6,8, 2,3,3,4,1 ,0,64,128

‘Jungle' is the displayed title
.25 and 3 describe the range of terrain roughness. .25 is quite flat, 3 will have big mountains. The program choose a random value between them.
75 and 85: random range (%) for the top of mountains
65 and 70: random range (%) for near the top
10 and 13: random range (%) where the middle portion starts
6 and 8: random range (%) for near the flat surfaces (beaches)
2,3,3,4,1: index for the colors to apply to the different sections above
0,64,128: RGB color of the flat surfaces (water, sand or snow), 31 shades will be generated from the base color

The colors shades are generated here:
mkpal 1, 255,158,79 'Brn
mkpal 2, 255,255,255 'Wht
mkpal 3, 0,255,0 'Grn
mkpal 4, 128,128,128 'Gry
mkpal 5, 200,200,255 ’Blu

Format is index,R,G,B. 8 colors slots defined, only 5 used.

The mkpal sub also generates lighter versions of the colors with a +8 index.

In addition to posting the program here, I've sent an email with my entry as per the rules.

Best of luck to the other participants!


'Fractal Landscapes by Stephane Edwardson (Lodovik)
'Original program in Compute! 08/1987 by Matthew Timmerman
mode 1,16

const prg$="Fractal Landscapes"
dim szx=192,szy=576,yof=80,xof=-192
dim xs=.66,tx%(4),ty%(4),lv(szx,szy),cm(16,32)
dim pw,pd,nm$,mx,top,crn,med,rif,bch
dim cp=0,pa$(10),se(10,20),np'Pname,Prfl,#prfl,curprfl

data "Jungle",.25,3,75,85,65,70,10,13,6,8,2,3,3,4,1,0,64,128
data "Arctic",.50,.70,75,85,65,70,10,15,13,5,13,13,5,5,5, 200,200,255
data "Oasis",.5,1,75,85,65,70,10,15,10,15,1,1,1,1,3,0,64,128
data "Alps",2,3,75,85,65,70,10,15,4,8,13,13,2,3,1, 0,64,128
data "Mars",2,3,75,85,65,70,10,15,4,8,1,1,1,1,1,127,79,40
data "Moon",.25,.5,75,85,65,70,10,15,4,8,2,2,2,2,2, 255,255,255
data "-"'ele,top,crn,mid,rif,c1-5,wtrRGB

np=0
do while n$<>"-"
read n$
if n$<>"-" then
 inc np:pa$(np)=n$
 for z=1 to 15:read se(np,z):next
 read r,g,b
 se(np,16)=rgb(r,g,b):se(np,17)=rgb(rw(r,5),g,b)
 se(np,18)=rgb(r,rw(g,5),b):se(np,19)=rgb(r,g,rw(b,5))
end if
loop

mkpal 1,255,158,79'Brn
mkpal 2,255,255,255'Wht
mkpal 3,0,255,0'Grn
mkpal 4,128,128,128'Gry
mkpal 5,200,200,255'Blu

sub mkpal(p,r,g,b)
for a=0 to 31
cm(p,a)=rgb(a/31*r,a/31*g,a/31*b)
cm(p+8,a)=rgb(a/62*r+127,a/62*g+127,a/62*b+127)
next
end sub

pw=0:pd=0
rn$="landscape"
rn2$="next "+rn$
cls
do while k$<>chr$(27)
page write pd:status prg$,"Generating","elevation map","Please wait",-1
cp=cp+1:if cp>np then cp=1
mx=rndrng(se(cp,1),se(cp,2))
MakeMount
RndScn
page write pd:status "","Rendering",rn$,,-1
if pw=1 then page write pw:cls
text 0,599,pa$(cp),"LB",2,,rgb(white),rgb(black)
DrawMount
if pw=1 then swipe
pw=1:rn$=rn2$
loop


sub swipe
local s=1
page write 0
for x=0 to 800-s step s
blit x,0,x,0,s,600,1
pause 2
next
end sub

sub status(t$,l1$,l2$,l3$,pc)
local tb=rgb(15,15,30),tf=rgb(90,120,255)
page write pd
if t$<>"" then
rbox 620,2,179,100,3,rgb(blue),tb
text 710,6,ucase$(prg$),"CT",1,,rgb(white),tb
end if
if l1$<>"" then text 710,40,pad$(l1$),"CB",1,,tf,tb
if l2$<>"" then text 710,60,pad$(l2$),"CB",1,,tf,tb
if l3$<>"" then text 710,80,pad$(l3$),"CB",1,,tf,tb
if pc<0 then
box 625,86,169,10,,tf,tb
elseif pc>0 then
box 625,86,pc*169,10,,tf,tf
else
box 625,86,169,10,,tb,tb
end if
page write pw
end sub

function pad$(t$)
local l
l=int((18-len(t$))/2)
pad$=space$(l)+t$+space$(l)
end function

function rw(c,v)
local r,s
r=c+v
if r>255 then r=c-v
rw=r
end function

function rndrng(l,h)
rndrng=rnd*(h-l)+l
end function

function intrnd(l,h)
intrnd=int(rnd*(h-l+1))+l
end function

sub RndScn
nm$=pa$(cp)
top=maxlv*rndrng(se(cp,3),se(cp,4))/100
crn=maxlv*rndrng(se(cp,5),se(cp,6))/100
med=maxlv*rndrng(se(cp,7),se(cp,8))/100
rif=maxlv*rndrng(se(cp,9),se(cp,10))/100
for z=1 to 8:cm(z,32)=se(cp,16):next
end sub


sub MakeMount
maxlv=0
for iter=6 to 1 step -1
sk=2^iter:hl=sk/2
for y=0 to szy step sk
 for x=hl to szx step sk
  ran=(rnd-.5)*mx*sk
  old=(lv(x-hl,y)+lv(x+hl,y))/2
  lv(x,y)=old+ran
 next
next
for x=0 to szx step sk
 for y=hl to szy step sk
  ran=(rnd-.5)*mx*sk
  old=(lv(x,y-hl)+lv(x,y+hl))/2
  lv(x,y)=old+ran
 next
next
for x=hl to szx step sk
 for y=hl to szy step sk
  ran=(rnd-.5)*mx*sk
  old1=(lv(x+hl,y-hl)+lv(x-hl,y+hl))/2
  old2=(lv(x-hl,y-hl)+lv(x+hl,y+hl))/2
  old=(old2+old1)/2
  lv(x,y)=old+ran
  if lv(x,y) > maxlv then maxlv=lv(x,y)
 next
next
status "",,,,((7-iter)/6)
next
end sub

sub DrawMount
xm=4:ym=1:xp=70
for x=0 to szx
if lv(x,0) < 0 then lv(x,0)=0
next
for y=0 to szy-1
if lv(0,y) < 0 then lv(0,y)=0
for x=0 to szx-1
 k$=inkey$
 if lv(x+1,y+1) < 0 then lv(x+1,y+1)=0
 lvl=(lv(x,y)+lv(x+1,y)+lv(x,y+1)+lv(x+1,y+1))/4
 a=x:b=y:rx1=xm*a+xs*b:ry1=ym*b+yp-lv(a,b):sh1=gs()
 a=x+1:rx2=xm*a+xs*b:ry2=ym*b+yp-lv(a,b):sh2=gs()
 a=x:b=y+1:rx3=xm*a+xs*b:ry3=ym*b+yp-lv(a,b):sh3=gs()
 a=x+1:rx4=xm*a+xs*b:ry4=ym*b+yp-lv(a,b):sh4=gs()
 a=x+.5:b=y+.5:rx=xm*a+xs*b:ry=ym*b+yp
 a=x:b=y:ry=ry-lvl
 area(rx,ry,rx1,ry1,rx2,ry2,sh1)
 area(rx,ry,rx2,ry2,rx4,ry4,sh2)
 area(rx,ry,rx1,ry1,rx3,ry3,sh3)
 area(rx,ry,rx3,ry3,rx4,ry4,sh4)
 if k$=" " or k$=chr$(27) then exit for
next
status "",,,,((y+1)/szy)
if k$=" " or k$=chr$(27) then exit for
next
end sub

sub area(x1,y1,x2,y2,x3,y3,c)
tx%(0)=x1+xof:ty%(0)=y1+yof
tx%(1)=x2+xof:ty%(1)=y2+yof
tx%(2)=x3+xof:ty%(2)=y3+yof
polygon 3,tx%(),ty%(),c,c
end sub

function gs()
c=x+1-(b-y):d=y+(a-x):xc=x+.5:yc=y+.5
xr1=xc-a:xr2=xc-c:yr1=yc-b:yr2=yc-d
ri1=lvl-lv(a,b):ri2=lvl-lv(c,d)
yri=abs(ri1*xr2-ri2*xr1)
yru=abs(yr1*xr2-xr1*yr2)
if yru = yri then yru=1:yri=1
xri=abs(ri1*yr2-ri2*yr1)
xru=abs(xr1*yr2-yr1*xr2)
if xru = xri then xru=1:xri=1
xri=xri/2:yri=yri/2
xsh=1-abs(xri/(xru+xri))
ysh=1-abs(yri/(yru+yri))
sha=30*xsh*ysh+1
cl=se(cp,intrnd(16,19))
if lvl>0 then cl=cm(se(cp,15),sha)
if lvl>rif then cl=cm(se(cp,14),sha)
if lvl>med then cl=cm(se(cp,13),sha)
if lvl>crn then cl=cm(se(cp,12),sha)
if lvl>top then cl=cm(se(cp,11),sha)
gs=cl
end function


 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3841
Posted: 12:11pm 25 May 2022
Copy link to clipboard 
Print this post

  Lodovik said  Here’s my submission for the contest ...


Thank you for your entry Lodovik, I've received your email but am unable to download the files from the links therein: "An unexpected error occurred."

In further news:

@bigmik, @lizby, @Turbo46 and myself have discussed it and:

1. This entry is within the rules; submissions only have to be original to MMBasic, plus as @lizby put it "True originality is hard to come by, standing, as we do, on the shoulders of those standing on the shoulders ..."

2. We are officially extending the submission deadline to Friday 1st July; I hope that neither @vegipete nor @Lodovik object.

Best wishes,

Tom
Edited 2022-05-25 22:11 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Lodovik

Newbie

Joined: 17/05/2021
Location: Canada
Posts: 40
Posted: 12:39pm 25 May 2022
Copy link to clipboard 
Print this post

Thank you for accepting my submission. I’m OK with the deadline extension, of course.

I will retry to send the email without the download links generated by my email program.

Regards
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 08:23pm 27 May 2022
Copy link to clipboard 
Print this post

Re: Stellar Battle in the Seven Green Hills Zone

I'm trying to run this on MMB4W. Without making any changes, I get a screen where I can scroll with the arrow keys apparently around a horizon (sun, moon, and Jupiter appear).



I can shoot at something with Shift or Ctrl. I even got a shooter to disappear by aligning with it. I blew up some kind of starship (I think). But after not very many seconds I get this:



Do I need to slow it down (how?). Is this something like what it's supposed to look like and how it should work (obviously not the "GAME OVER" screen)? (I have no familiarity with how a game of this sort is supposed to look, or how one should interact with it.)
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 09:16pm 27 May 2022
Copy link to clipboard 
Print this post

  lizby said  Do I need to slow it down (how?). Is this something like what it's supposed to look like and how it should work (obviously not the "GAME OVER" screen)? (I have no familiarity with how a game of this sort is supposed to look, or how one should interact with it.)

Hmmm. My work computer won't allow me to run MMB4W any more - most peculiar. It gets deleted if I even try to copy the zip file. Excessive organizational security, I guess. I'll try again at home.

That looks sort of right, but not entirely. Speed shouldn't be an issue, the frame rate is timed. Line 76 forces minimum 25ms per frame.

Your shield has dropped to zero, hence your death and game over.

Do you see cubes and pyramids, plus moving enemies? Can you see your shots when your press CTRL or SHIFT?
Visit Vegipete's *Mite Library for cool programs.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 10:57pm 27 May 2022
Copy link to clipboard 
Print this post

I can see shots incoming and outgoing, but no cubes or pyramids (or on re-looking, tiny cubes and pyramids which I am not able to align with to shoot--if I'm supposed to shoot them). I occasionally see a shooting moving enemy, and succeeded at hitting on. I did see what appeared to be an aircraft or starship, and destroyed it.

Perhaps I'll last longer if I don't shot without seeing what I'm shooting at.

Sometimes I see blue triangles which grow larger as they approach. If I do nothing, the column marked "S" diminished and after about 45 seconds, I get "GAME OVER".
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 11:19pm 27 May 2022
Copy link to clipboard 
Print this post

Sounds like there is a scaling issue.

On line 16, change this part:
math scale v(),sc*10,v()

Note the "*10". Try different values to see what you get.
Visit Vegipete's *Mite Library for cool programs.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 01:23am 28 May 2022
Copy link to clipboard 
Print this post

Just tried it on my pc at home with the last posted MMB4W I could find (v5.07.03b10) and my code posted higher up works mostly as expected, including sound. There are some text scaling issues (ex: S and F don't line up with their corresponding gauges, some colours are different and individual pixels look especially tiny. This latter affects the radar display in the bottom center most. Also, the keyboard doesn't quite work as it should. Pressing SHIFT or CTRL to fire seems to clear any active arrow keys. Use ALT instead to fire.

The text size improves when I CTRL-C from the program and run again.

Change line 5 to
dim di(AC),o(AC,6),c(8)=(&h2A2AA5,&hFF00,&hAF00,&h6000,2^14,0,&hFFC000,&hC000FF,&h404040)
to fix the colours.

Change lines 161 and 162 to
circle 51+x*140/B,51-y*140/B,1,,,c(0+6*(o(n,6)=5)+(o(n,6)=4))  
circle 51,51,1,,,&h00FFFF
to improve the radar visibility.

(Leave line 16 unchanged - no scale change needed.)

===================
About the game:
I deliberately omitted any specific description in the original post so that people would have to run it to see what it was. Tom (thwill) 'leaked' that info when he mentioned "Battle Zone" - indeed, this is a take on Battle Zone or Stellar 7.

The player pilots and has a first person view from a battle tank, driving around on a rectangular plain (surrounded by Seven Green Hills!) Scattered about the field are indestructible obstacles - cubes and pyramids. There is a fuel bay - marked in green on the radar. Drive through it to fuel up, and get some shield repair. There are also a pair of enemy tanks driving around the field, and they are coming for you! There's a slower one and a faster one. If they run into things, they stop, turn a bit, then continue chasing you. Shoot them before they shoot you. Fortunately for you, they will also shoot each other. When destroyed, the enemy tanks are replaced with new ones, starting from a far corner. Once you kill enough on a given level, a Star Gate appears. Drive through it for transport to the next level. Enemy tanks get faster with increasing levels.
Visit Vegipete's *Mite Library for cool programs.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3527
Posted: 08:39pm 31 May 2022
Copy link to clipboard 
Print this post

Hereby I send in (last minute) my contribution to the 2022 programming challenge,

The contribution is a simple SSTV decoding program running on a PicomiteVGA.

There is a description of the contribution in this document

SSTV.zip

The program uses the Picomite PIO sequencer to demodulate the SSTV video. The MMBasic program presents the video on screen.

This is by no means a 100% solid example of programming. Some corners had to be cut to stay within 5kbyte (like hardcoding values, that could have been defines calculated from theory). It is an adventure in technology that shows my developemnt and education on the topic. It will not score for quality, but may get points for originality.

I will try to provide a video on youtube about the program in action next weekend.

The code
'SSTV decoder program for ROBOT-8 mode for PICOMITE MMBasic
Option default integer
MODE 1

'pio program measure overlapping rising and falling period and send to FIFO
'loops increment both X and Y, alternating X and Y are reset and pushed.
'0 E020   'set X=0
'1 A029   'X -> fffffff
'2 00C5   'jmp (pin=1) to loop2
'3 0084   'Y-- (first loop Y contains rubbish)
'4 0042   'count X-- loop1
'5 A0CA   'mov -Y to ISR
'6 8000   'push noblock
'7 E040   'set Y=0
'8 A04A   'Y -> fffffff
'9 004A   'count X-- loop2
'A 008B   'Y--
'B 00C9   'jmp (pin=1) in loop2
'C A0C9   'mov -X to ISR
'D 8000   'push noblock
'E 0000   'jmp 0 (rest is filled with 0 = jmp->0)
Dim a%(7)=(&h008400C5A029E020,&hE0408000A0CA0042,&h00C9008B004AA04A,&h8000A0C9,
0,0,0,0)
f=3e6     '3MHz @ 3cycles per loop = 1us per tick

'configure pio1
e=Pio(execctrl 0,0,&h1f)  'use gp0 for PIN
s=Peek(word &h503000d0)   'use old value
p=0                       'no GPxx pins for PIO1

'program pio1 and start
PIO program 1,a%()
PIO init machine 1,0,f,p,e,s
PIO start 1,0

'pio fifo register
ff=&h50300020

'sstv specific frequecies converted to time in us
l=1e6/1100 'sync low
r=1e6/1200 'sync
u=1e6/1300 'sync high
b=1e6/1500 'black
v=1e6/1900 'black/white threshold
w=1e6/2300 'white

menu:
CLS
Print "SSTV Robot-8 playground":Print
Print "1 = measure frequency"
Print "2 = waterfall"
Print "3 = picture in burst mode (no hsync)"
Print "4 = picture monochrome"
Print "5 = picture in 4 green levels"
Print "6 = picture in dithered white"
Print "7 = stop"
Do
 kn$=Inkey$
Loop Until kn$<>""
Select Case Val(kn$)
 Case 1
   GoSub frequency
 Case 2
   GoSub waterfall
 Case 5
   GoSub greenvideo
 Case 3
   GoSub videobrute
 Case 6
   GoSub greyvideo
 Case 4
   GoSub video
 Case 7
   End
End Select
GoTo menu




frequency:
'measure time and convert to frequency
Do
 cnt=Peek(word ff) 'read fifo pio 1 seq 0
 period = cnt+3      'period
 Print @(300,240) Int(1e6/period);" Hz      "
 Pause 100
Loop While Inkey$=""
Return




waterfall:
'show frequency graph on horizontal axis, scolling down
CLS
Do
 Text 1,1,"frequency (Hz)","LT"
 Text r/2,1,"1200","CT"
 Text b/2,1,"1500","CT"
 Text w/2,1,"2300","CT"
 Line u/2,20,u/2,479
 Line l/2,20,l/2,479
 For y=20 To 479
   cnt=Peek(word ff)
   Pixel cnt/2,y,1
   Pause 0.5   'delay to slow waterfall
 Next y
 CLS
Loop While Inkey$=""
Return




video:
'video decode using both hsync and vsync
're-syncing every line and frame
Do
 'CLS
 y=180
 Do
   x=240
   Timer =0
   'pixel video read an display
   Do
     Pause 0.3 'horizontal timing
     x=Min(390,x+1)
     p=Peek(word ff)
     Pixel x,y,(p<v)
   Loop Until p>u And Timer>58
   Timer =0
   'hsync detect > 3.5ms, vsync > 10ms
   Do
     Pause 0.3 'lower misses syncs
     p=Peek(word ff)
   Loop Until p<u And Timer>3.5
   If Timer > 10 Then Exit
   Inc y
 Loop
Loop While Inkey$=""
Return




videobrute:
'video decode fixed timing from vertical sync

brute:
'find vsync
Do
 Do
   p=Peek(word ff)
 Loop Until p>u
 Timer =0
 Do
   p=Peek(word ff)
 Loop Until p<b
Loop Until Timer > 10

'brute force process all pixels and hsync equally
For y=180 To 298
 For x=240 To 359
   p=Peek(word ff)
   Pixel x,y,(p<v)
   Pause 0.487
 Next x
Next y
If Inkey$="" Then GoTo brute
Return




greenvideo:
'video decode in mode 2 using 4 level green
're-syncing every line and frame
MODE 2
Dim c%(3)=(0,&h4000,&h8000,&hC000) '3 green levels and black

Do
 CLS
 y=50
 Do
   x=80
   'capture pixel data and display
   Timer =0
   Do
     Pause 0.3 'rough horizontal timing
     x=Min(220,x+1)
     p=Peek(word ff)
     i=(p<580)+(p<522)+(p<470)
     Pixel x,y,c%(i)
   Loop Until p>u And Timer>60
   Timer =0
   'detect end of hsync to start new line
   Do
     p=Peek(word ff)
   Loop Until p<b And Timer>4
   If Timer > 10 Then Exit 'sync is vsync
   Inc y
 Loop
Loop While Inkey$=""
MODE 1
Return



greyvideo:
'create greyscale out of 3x3 tiles in B/W pixels
're-syncing every line and frame

CLS
Do
 y=50
 Do
   x=100
   'dither pixels by drawing them individually depending grey level
   Timer =0
   Do
     Pause 0.1
     x=Min(500,x+1)
     k=y+1:l=k+1
     p=Peek(word ff)
     Pixel x,y,(p<571)
     Pixel x,k,(p<522)
     Pixel x,l,(p<480)
     Inc x
     Pixel x,y,(p<500)
     Pixel x,k,(p<632)
     Pixel x,l,(p<445)
     Inc x
     Pixel x,y,(p<600)
     Pixel x,k,(p<462)
     Pixel x,l,(p<545)
   Loop Until p>u And Timer>60
   Timer =0
   Print @(0,0) x
   'detect end of hsync to start new line
   Do
     p=Peek(word ff)
   Loop Until p<u And Timer>3.5
   If Timer > 10 Then Exit 'sync is a vsync
   Inc y,3
 Loop Until y>407
Loop While Inkey$=""
Return


Edited 2022-06-01 07:05 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3527
Posted: 06:56am 01 Jun 2022
Copy link to clipboard 
Print this post

This post may be deleted, or moved to another thread if required.
I did put it here since it was part of my learning curve for the PIO sequencer.
Below is the sequencer program that is the heart of the SSTV program. I will try to explain why things are what they are.


'0 E020   'set X=0
'1 A029   'X -> fffffff
'2 00C5   'jmp (pin=1) to loop2
'3 0084   'Y-- (first loop Y contains rubbish)
'4 0042   'count X-- loop1
'5 A0CA   'mov -Y to ISR
'6 8000   'push noblock
'7 E040   'set Y=0
'8 A04A   'Y -> fffffff
'9 004A   'count X-- loop2
'A 008B   'Y--
'B 00C9   'jmp (pin=1) in loop2
'C A0C9   'mov -X to ISR
'D 8000   'push noblock
'E 0000   'jmp 0 (rest is filled with 0 = jmp->0)


First of all, the PIO sequencer cannot do a calculation. It can not add, it can not subtract. The only "arithmetic" it know is a (post) decrement of a value. So there is not even an increment ... only decrement.

The PIO has 2 registers X and Y (appart from the shift registers).

Normally the duration of an event can be measured as follows

counter = 0
DO
 INC counter
LOOP UNTIL event


But since there is no increment in the PIO it has to be written as

counter = -1
DO
 DEC counter
LOOP UNTIL event
counter = -counter


The preset value of -1 is because the PIO cannot do a arithmetic counter = -counter, but it can invert bits. And when you invert -1 (&hffffffff) you get 0.

Above is exactly what the PIO program does, only the instructions to do this are a bit non-intuitive.

The "event" in above code is the state change of a GPIO pin of the pico. The most logical method the PIO has to do this is to use a conditional jump instruction (JMP). In this instruction a pre-defined pin can be sampled. This pre-defined pin is defined in the EXECCTRL register (not in the PINCTRL register) and is completely independent of pins used for SET, OUT, IN, SIDE-SET. And the conditional JMP can only jump when the pin is HIGH. So there is no JMP on pin low. This restriction determines the flow of the program.


DO
 X=-1
loop1:
 JMP on PIN to loop2
 DEC Y
 DEC X and JMP to loop1
loop2:
 PUSH Y
 Y=-1
loop3:
 DEC Y
 DEC X
 JMP on PIN to loop3:
 PUSH X
LOOP


So the input pin condition is tested in loop1, where the condition escapes the counting loop. And the input pin condition is tested in loop2(3) where it continues the counting loop.

Now it gets a bit confusing. The DEC instruction in above pseudo code does not exist in the PIO instruction set. It is a side effect (post decrement) of the JMP instruction. DEC in fact is:


 JMP (Y--) next_instruction
next_instruction:


So regardless the initial value of Y, JMP either goes to the next instruction, or it jumps to the next instruction. But it has decremented Y.

How do we get the data from the counter loops. In above code we see a PUSH pseudo instruction. The PIO can push data to a FIFO that can be ready by the ARM processor. However , it can only push data into the FIFO from the ISR (Input Shift Register). So the PUSH pseudo instruction is implemented as follows:


 MOV X to ISR and invert all bits (counter = -counter)
 PUSH ISR to FIFO


I hope this may give other people some insight on what you can do with the PIO, and may even attract others to do something with it. So much to learn, and so little time...
Edited 2022-06-01 17:11 by Volhout
PicomiteVGA PETSCII ROBOTS
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3841
Posted: 08:34am 01 Jun 2022
Copy link to clipboard 
Print this post

  Volhout said  Hereby I send in (last minute) my contribution to the 2022 programming challenge,


Thanks Volhout. Not "last minute" as we extended the deadline until Friday 1st July a few posts back.

  Lodovik said  I will retry to send the email without the download links generated by my email program.


Hi Ludovik, no luck second time either, something called MIMEDefang decided the .bas file was evil and removed it. Let's not worry about it for now; when the deadline passes I'll chase up any submissions that can't be scraped from TBS.

Best wishes,

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

Joined: 06/03/2016
Location: Brazil
Posts: 303
Posted: 12:07pm 01 Jun 2022
Copy link to clipboard 
Print this post

Sorry, everyone, I had serious health problems with pneumonia and then I caught dengue, so I lost 40 days of my professional work. After that, my SEGA Genesis/Mega Drive port of Final Fight was delayed a bit and I'm worried about the schedule.

I'll do my best to participate in this contest, but I'm not sure if I'll have time to develop something.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5726
Posted: 12:33pm 01 Jun 2022
Copy link to clipboard 
Print this post

Panic not, Mauro, we know your heart's in the right place. :)
Sorry to hear about those nasty health problems, I hope you are a lot better now.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
     Page 2 of 7    
Print this page
© JAQ Software 2024