(http://underwaredesign.com/forums/BlitzBASIC-2-PlayBASIC-Banner-800p.jpg)
BlitzBASIC 2 PlayBASIC - Source Code Conversion WIP
Releases
Download Blitz 2 PlayBASIC V1.00 (https://www.underwaredesign.com/forums/index.php?topic=4625.msg30642#msg30642) (8th May 2022)
Blog
Objective: Howdy, somehow you've found your way here at another development blog. The goals of this project are to create a tool (in PlayBASIC) that does source level conversions of Blitz BASIC (for Windows) source code to PlayBASIC.
My ambitions for this project are pretty humble and as such you should temper any expectations for the quality of the output code being produced. The conversion will be most syntax level adjustments, some direct command set mapping, but commands are expected to be emulated via wrapper.
Porting BlitzBASIC 2 PlayBASIC - First Look - (2022-02-20) During the process of porting XLnt GUI episode #8, I talked a lot about the repetitive processes of code conversion. In the context of our XLnt GUI conversion there's a bunch of common changes we're making that could better done with a tool.
So here's our first look a our tool to convert BlitzBASIC to PLayBASIC..
Script: -- Script On PasteBin (https://pastebin.com/4K9JNtzX)
BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode# 02 This is the second look in our attempts to write a tool that can handle most syntax level conversion of Blitz BASIC code and convert it in to PlayBASIC syntax.
Remapping common Blitz BASIC string functions for PlayBASIC
BlitzBASIC 2 PlayBASIC Conversion: Parsing Blitz Basic Types - 24th feb 2022
Been parsing BLITZ types this arvo and have even learned thing or two about blitz syntax Namely that it supports static typed arrays as fields within types. Didn't know that :)
Currently my parser supports Integer / floats / strings in both variable and array form, but not nested types as yet. That's not to say it can remap the usages as they appear within the code, just that it understands the type well enough to get fields and data types that we want prior to parsing the code.
Example:
type Vector3
field x#,y#,z#
end type
Type cool
Field a1,b1#,c1$ ` rem this is rem
` another rem on another line
field IntArray[10000]
field FltArray#[10000],StringArray$[10000],zzzzz
field ccccc,AnotherIntArray[100]
Field a2#[100],b2#[200],c3$[300*100]
Field a,b,c
field pos.vector3
End Type
Session #2
So the decoder is now understanding the various valid syntaxes for Types in Blitz, or at least the ones I know. The code bellow is a mash up of the field variations, with the code bellow that being the is the PB conversion and the table of how the translated keeps this data.
type Vector3
field x#,y#,z#
end type
Type cool
Field a1,b1#,c1$ ` rem this is rem
` another rem on another line
field IntArray[10000]
field FltArray#[10000],StringArray$[10000],zzzzz
field ccccc,AnotherIntArray[100]
Field a2#[100],b2#[200],c3$[300*100]
Field a,b,c
field pos.vector3
field pos2.vector3 , pos3.vector3
field pos4.vector3[123]
field pos5.vector3[234],pos6.vector3[666],xyz
End Type
Here's the PlayBASIC version of this TYPE. Mind you this doesn't compile in PB as there's some syntax that PB doesn't like, but for simpler TYPES it's basically working.
[pbcode]
Type Vector3
x#,y#,z#
EndType
Type cool
a1,b1#,c1$ ` rem this is rem
` another rem on another line
IntArray(10000)
FltArray#(10000),StringArray$(10000),zzzzz
ccccc,AnotherIntArray(100)
a2#(100),b2#(200),c3$(300*100)
a,b,c
pos.vector3
pos2.vector3 , pos3.vector3
pos4.vector3(123)
pos5.vector3(234),pos6.vector3(666),xyz
EndType
[/pbcode]
Parsed Structures
TYPE Vector3
Src Position:6 - 23
#00 x--------------- Type:2 Src POS:13
#01 y--------------- Type:2 Src POS:16
#02 z--------------- Type:2 Src POS:19
EndTYPE
TYPE cool
Src Position:31 - 176
#000 a1-------------- Type:1 Src POS:38
#001 b1-------------- Type:2 Src POS:40
#002 c1-------------- Type:4 Src POS:43
#003 IntArray-------- Type:257 Src POS:54 [ 55 - 57 ]
#004 FltArray-------- Type:258 Src POS:62 [ 64 - 66 ]
#005 StringArray----- Type:260 Src POS:68 [ 70 - 72 ]
#006 zzzzz----------- Type:1 Src POS:74
#007 ccccc----------- Type:1 Src POS:79
#008 AnotherIntArray- Type:257 Src POS:81 [ 82 - 84 ]
#009 a2-------------- Type:258 Src POS:90 [ 92 - 94 ]
#010 b2-------------- Type:258 Src POS:96 [ 98 - 100 ]
#011 c3-------------- Type:260 Src POS:102 [ 104 - 108 ]
#012 a--------------- Type:1 Src POS:114
#013 b--------------- Type:1 Src POS:116
#014 c--------------- Type:1 Src POS:118
#015 pos------------- of vector3 Type:8 Src POS:126 UDT POS:128
#016 pos2------------ of vector3 Type:8 Src POS:133 UDT POS:135
#017 pos3------------ of vector3 Type:8 Src POS:139 UDT POS:141
#018 pos4------------ of vector3 Type:264 Src POS:148 UDT POS:150 [ 151 - 153 ]
#019 pos5------------ of vector3 Type:264 Src POS:158 UDT POS:160 [ 161 - 163 ]
#020 pos6------------ of vector3 Type:264 Src POS:165 UDT POS:167 [ 168 - 170 ]
#021 xyz------------- Type:1 Src POS:172
EndTYPE
BlitzBASIC 2 PlayBASIC Conversion: Parsing Blitz Basic FUNCTIONS - 25th feb 2022
Today was about getting the parser to the pick and up start having some understanding of Function declarations. It's early days, so we're just picking out where the declarations are and the name of the functions to start with., will look at deciphering the input and return parameter stuff over the weekend.
For now, here's a simpler example of what the conversion pass is doing for us. Syntax wise we're got some issues with stacked arrays (declarations on one line) within TYPE blocks, as well as no support for Type variables so those are passed straight for the time being. But many other changes are being made for us, it's not there yet though.
Input Code:
type Vector3
field x#,y#,z#
end type
Type cool
Field a1,b1#,c1$ ;` rem this is rem
;` another rem on another Line
Field IntArray[10000]
Field FltArray#[10000],StringArray$[10000],zzzzz
Field ccccc,AnotherIntArray[100]
Field a2#[100],b2#[200],c3$[300*100]
Field a,b,c
Field pos.vector3
Field pos_1d_array.vector3[10]
; Field pos_2d_array.vector3[10,20] <- Blitz DOESN"T SUPPROT more than 1D arrays
; Field pos_3d_array.vector3[10,20,30] <- Blitz DOESN"T support this either .. yay
End Type
me.cool = New cool
me\a=125
me\b=200
me\c=333
Print me\a
Print me\b
Print me\c
s$="Yeah Cool"
Print Mid(s$,2)
Print Mid(s$,2)
Print Mid$(s$,2)
Print Mid$(s$,2)
Print Left(s$,4)
Print Left$(s$,4)
Print Right(s$,4)
Print Right$(s$,4)
If a=1
Print "YEAH"
EndIf
If a=1
Print "YEAH"
Else If a=3
Print "a=3"
Else
Print "Nah"
End If
Select a
Case 1
Print "A=1"
Default
Print "A<>1"
End Select
Const Cool1= 45
Const Cool2= 45
Const Cool3= 45
Const Cool4= 45
While A>0
A=A-1
Wend
function TestMyFunction(Param1,Param2,Param3$)
end function
function TestMyFunction2(Param1,Param2#,Param3$)
end function
Output Code:
[pbcode]
Type Vector3
x#,y#,z#
EndType
Type cool
a1,b1#,c1$ ;` rem this is rem
;` another rem on another Line
IntArray(10000)
FltArray#(10000),StringArray$(10000),zzzzz
ccccc,AnotherIntArray(100)
a2#(100),b2#(200),c3$(300*100)
a,b,c
pos.vector3
pos_1d_array.vector3(10)
; Field pos_2d_array.vector3[10,20] <- Blitz DOESN"T SUPPROT more than 1D arrays
; Field pos_3d_array.vector3[10,20,30] <- Blitz DOESN"T support this either .. yay
EndType
me.cool = New cool
me\a=125
me\b=200
me\c=333
Print me\a
Print me\b
Print me\c
s$="Yeah Cool"
Print Mid$(s$,2)
Print Mid$(s$,2)
Print Mid$(s$,2)
Print Mid$(s$,2)
Print Left$(s$,4)
Print Left$(s$,4)
Print Right$(s$,4)
Print Right$(s$,4)
If a=1
Print "YEAH"
EndIf
If a=1
Print "YEAH"
ElseIf a=3
Print "a=3"
Else
Print "Nah"
EndIf
Select a
Case 1
Print "A=1"
Default
Print "A<>1"
EndSelect
Constant Cool1= 45
Constant Cool2= 45
Constant Cool3= 45
Constant Cool4= 45
While A>0
A=A-1
EndWhile
Function TestMyFunction(Param1,Param2,Param3$)
EndFunction
Function TestMyFunction2(Param1,Param2#,Param3$)
EndFunction
[/pbcode]
BlitzBASIC 2 PlayBASIC Conversion: Parsing Blitz Basic DIM statements - ARRAYS - 28th feb 2022 The last couple of sessions has been about trapping DIM / LOCAL / GLOBAL statements but mainly DIM statements first. Here's a bit of a look at the conversion progress, so far we can catch and remap various types of DIM statements and output them in a more PlayBASIC friendly fashion. What it can't do yet is understand arrays() that appear with expressions. But first we need to find their declarations, then we'll worry about catching their usages through the code..
Input Code:
Type MY_TYPE
Field x#,y#,z#
End Type
Type MY_TYPE2
Field x#,y#,z#
End Type
Dim iTable1d(100)
Dim iTable2d(100,200)
Dim iTable3d(100,200,300)
Dim iTable1d%(100)
Dim iTable2d%(100,200)
Dim iTable3d%(100,200,300)
Dim fTable1d#(100)
Dim fTable2d#(100,200)
Dim fTable3d#(100,200,300)
Dim sTable1d$(100)
Dim sTable2d$(100,200)
Dim sTable3d$(100,200,300)
; Arrays are global by default
; Stacked DIMS on one line
Dim Array1(100), Array2(200)
; Dim Typed Array
Dim Array3.MY_TYPE(100) , Array4.MY_TYPE(400)
; Dim Typed Array
Dim Array5.MY_TYPE( iTable1d(100)+ 100) , Array6.MY_TYPE( Val(sTable1d$(100))+400)
Output Code: [pbcode]
Type MY_TYPE
x#,y#,z#
EndType
Type MY_TYPE2
x#,y#,z#
EndType
Dim iTable1d(100)
Dim iTable2d(100,200)
Dim iTable3d(100,200,300)
Dim iTable1d(100)
Dim iTable2d(100,200)
Dim iTable3d(100,200,300)
Dim fTable1d#(100)
Dim fTable2d#(100,200)
Dim fTable3d#(100,200,300)
Dim sTable1d$(100)
Dim sTable2d$(100,200)
Dim sTable3d$(100,200,300)
; Arrays are global by default
; Stacked DIMS on one line
Dim Array1(100):DIM Array2(200)
; Dim Typed Array
Dim Array3(100) as MY_TYPE :DIM Array4(400) as MY_TYPE
; Dim Typed Array
Dim Array5( iTable1d(100)+ 100) as MY_TYPE :DIM Array6( Val(sTable1d$(100))+400) as MY_TYPE
[/pbcode]
Video Script:
hello welcome back we're outside again
so it's a bit noisy um
it's a beautiful day so i'm outside
that's why i'm recording outside as well
just easier for me
where are we with blitz basic to play
basic well we've been working on the
dimensioning support here in magpie in
the background
so i'll give it a
run debug mode
so
information is a bit different than i
was before but not much all that
interesting
this is our resulting code
so i'll sort of pick through this
well actually i'll pick through the
original code and we'll go through what
the converter supports
but that actually does compile now in
play basic
here's the original blitz code
so in blitz
our main changes are going to be we
the field
keyword here is obsolete so we don't
need that
and we
we have an n-type keyword rather than
end-end type keywords so those changes
have been made for us
the dimension statements are basically
the same there's nothing different about
those
well there is but we'll get to that in a
second
in blitz we also have a thing
an integer
postfix
which is the percent symbol
so in pv we don't have that so we have
to remove those
which is what we do in our translation
floats the same strings the same now
blitz has a support for stacked arrays
and i thought i added this
well
this came up during the amos conversion
stuff because amos supports the same
thing
but haven't and you can also do it with
typed arrays notice the different syntax
here
this inverted syntax
and here i'm just testing whether you
can have complex expressions inside the
dimension statement
for the
field size
if i just grab these couple lines here
which the ones we want to look at really
the rest of it's all pretty much for
matches
we go to the translated
one which is
this is the one yeah
so you can see what the converter's done
is it's looked at this
first line i'll put the original lines
beside them
so this was the input line sorry
this was the original input line
this one was the
other original input line
the one at the bottom there was the
other one as well
let's comment them out
so
in the first case we've got a stack
dimension
a stacked array dimension we've got uh
array one integer type and then we've
got a second dimension on the same line
to do that in pb we've got to substitute
this comma with a dim colon
so we keep the things on the same line
but we're inserting the statement um
to allow us to phrase this and act the
same
when we have a type we've got a
rearranged expression
so
when we find this this declaration here
we're going okay array three all right
cool
as of of this type
and we've got these brackets here so we
need to rearrange these back into here
and replace our dot syntax with as
which is what pv accepts and because
they can be stacked we need to do the
same thing through here
and the last one has an expression
inside those things to show that we can
we can unlink these tokens
from in here
more sort of complicate sorry a more
complex expression
and move them back without damaging it
i hope not anyway um
let's try and run this one here and
debug
without getting output because there's
just nothing it's doing but we can see
what a race we have an array one which
is our integer array array two is fine
typed array
[Music]
yeah
we're getting now our arcade types
because the array has been declared but
the individual types within it are not
created until we actually
do a new of them
our flight array looks good and our
integer arrays look good as well so it's
all
working
so i've been doing this smaller subset
testing
to these larger ones i haven't tried the
bigger source code for for a few days
actually
this won't produce anything that's
useful like at the moment
uh
our converter is catching these
dimension statements and phrasing out
what arrays we need
are within them but it's not storing
this in in a list
we need that because as we go through
the code
like these are the declarations but when
something's been used like we go print
um
was it a rate one or something uh l5
position five or something
plus uh i think it was
i used i in front of
10 let's say let's say
um
at the moment when it's phrasing through
and it'll pick up these statements but
won't understand what these keywords are
so
if it's an integer array like that
no dramas it'll get spelled out the same
way it went in
because there's no translation required
but if that's obviously uh
one of these float arrays for example
or the inter ray up here that was
declared with the
oh it's been removed in this example
with a symbol added to it
and that keeps popping up later on in
the code we'd have to remove those
during our translation so we have to
skim through find this keyword and go
all right what's this word mean
look it up within our current scope
which is what we also need to do is keep
track of
are these arrays global are they local
so we sort of have to do that
and once we do that we should be able to
get a pretty good
you know not a great translation well
i think i think pretty good is about the
best we hope for
it'll be better than doing replacements
but it won't
give you
full out working code
out of the blocks
you'll find some expressions that white
that it won't understand or
or that i've not considered
it just has no clue about what to do
with them
you know to make this line here pb
compatible would have to remove these
percentage symbols
uh
or as we're saying before if if you go
dim you know
my strings
maybe a size 100 of them or whatever
in blitz you you don't have to use that
the perfect symbol so it's not baked
into the name
with pva it kind of is baked into the
name so we
it's okay to do stuff like this
in blitz
you know run through and grab
print out all the strings or whatever
you want to do
when we look through this to convert it
we'd have to
look for my string
check is my string declared within our
current scope if it is
then we look at the symbol
following that and we go okay
this was originally declared as a string
array and we're not using the string so
we better output this to make it
compatible with pba otherwise people
would just assume that that was
and we'll just assume this is an integer
version of that array
which is going to cause problems
but hopefully if we can catch
that kind of stuff
catch a lot a lot of the tight film
you know the um backslash stuff and
types won't work out of the box but
we'll get
a lot of the clunky syntax stuff work
and hopefully you get these variable and
array problems solved and that'll
actually go a long way
to you having a working program
when i started this the other day i
thought well if we get to a point where
it can solve you know
50 of your problems
that's pretty good because on these
large co-bases that's hours and hours of
work
and for some programs if they don't use
things outside of what it what
understands how to solve that'll be fine
they'll you better pace them in convert
them and
get something that's probably 90
ready to run
um
that's what we are at the moment anyway
we'll just give it a go that uh the
longest source code
to see how long it takes should be a lot
slower now
should be um
this is the gy code
just wrote
not in debug but right straight out
well a fair bit slower so phrase times 3
325 and the convert times about half a
second so we're almost at a second to do
a pretty full-on
uh
we're not fully compiling the code
obviously we're kind of picking through
and looking for things that we're
interested in and then when we find them
we're replacing those things
all right again to see if we're under
stress doing that
yeah i
thought as much
so about half a second to to load it and
tokenize it and output it
that's pretty acceptable for a 9000 line
9000 lines of code
87 000 tokens to run through
in just
pv
now that's not going to produce working
code
it will take ages we'll try and debug
mode but i've got a lot of debug dumps
at the moment so we might get stuck here
for a little while
um
so it took a lot longer because we've
got a lot more stuff being spat out to
the console
uh every time it finds a variable what
it thinks is a variable it's going to
speed up this little message
because also doing
it's a very preliminary version of
detecting variables but it's not
remembering them at the moment
so just look at the start of that
function we'll just see if we we've done
some
replacements of that
well there you go
so we've actually made a working
replacement this is the menus gy that
was
uh it was in
now we've converted something that's
compiles and will run straight out of
the box in play basic
those five lines there have been
converted perfectly
these lines here won't be that's our
next port of call with arrays is to
catch these
situations here and then
rearrange the expression suitably
[Music]
we might have to put warnings on some of
those there too
like if we know something's not gonna
not not being converted
uh correctly then we should warn you
know the end user that hey this line's
broken come and fix it
um
we've got some chicken before the egg
stuff here as well we've got
arrays with the typed been declared
before the types have been defined
you can do that in blitz you can't do
that in play basics that that code won't
build anyone
but syntactically we're closer
to something that's um
that will work
we haven't even started you know once we
get
and we get variables done means that
programs that just use arrays and
variables will will port
with a high degree of certainty
but we have to have you know emulations
of bullets functions so
this uh
well in our gy example
we've got this wrapping code where is
the code going there is
sorry
this thing called blitzwrapper which is
a list of just functions i'm emulating
uh in play basic code they do what blitz
does
sometimes they're just namesake wrappers
like that one there
we could substitute this for that and
life would go on straight away
these won't be so i know blitz has
different ideas about how images work
but for the most part we'll be able to
build a build a wrapper of these
commonplace functions and
commonplace
stuff will work straight out of the box
well
has a high degree of
possibility of working
it's the best we can hope for
all right thanks for listening to this
and thanks sorry for all the the car
noise in the background
uh i'll catch you next time bye
-- Script on Paste Bin (https://pastebin.com/x1ZvwVxM)
BlitzBASIC 2 PlayBASIC Conversion: Parsing Blitz Basic DIM statements - ARRAYS - 28th feb 2022 This is the 4th look at writing a tool that can handle most syntax level conversions of Blitz BASIC code and convert it in to PlayBASIC syntax.
In this episode we cover recent works that handle variable/array (keyword really) level scope detection and type matching in the output. This means the translation can detect variables and arrays and export them with the correct type symbols.
EG. Blitz BASIC
Dim MyString$(100)
For lp% =0 to 100
MyString(lp) = "Hello World"
next
Exported PlayBASIC
Dim MyString$(100)
For lp =0 to 100
MyString$(lp) = "Hello World"
next
Simple yes, but these are important changes for the conversion to not only compile, but functoin the same in PlayBASIC
Check the development blog for more interesting examples
Input Code:
Type POS
Field x#,y#
End Type
Global iVar2,fVar2#,sVar2$
Global MyList2.Pos
global GUI_SCREENW = 800
Local iVar,fVar#,sVar$
; Local MyList.Pos
; Type
; Dim iTable(1)
; Dim fTable#(1)
; Dim sTable$(1)
; Dim Aliens.pos(10)
Function MY_Function1()
local MyFloat#,myString$
for lp% = 1 to 100
a%=lp*100
b%=a
c=a+b
This$=MyString +"aaasss"
print myFloat * a / c
next
Dim Strings$(100)
for lp =0 to 100
print Strings(lp)
next
print GUI_SCREENW
End Function
Function MY_Function2()
local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,Pi#
width=800 : Pi = 3.14159
cx = width / 2
ax = cx: ay = 50 ' apex
ex = cx: ey = 330 ' ellipse
xr = cx * 0.7 : yr = 0.33 * xr
do
cls
x1 = ex + xr * Cos(a) : y1 = ey + yr * Sin(a)
x2 = ex + xr * Cos(a + Pi * 0.5) : y2 = ey + yr * Sin(a + Pi * 0.5)
x3 = ex + xr * Cos(a + Pi) : y3 = ey + yr * Sin(a + Pi)
x4 = ex + xr * Cos(a + Pi * 1.5) : y4 = ey + yr * Sin(a + Pi * 1.5)
fcolor 220,200,100
line x1, y1, x2, y2
line x2, y2, x3, y3
line x3, y3, x4, y4
line x4, y4, x1, y1
line x1, y1, ax, ay
line x2, y2, ax, ay
line x3, y3, ax, ay
line x4, y4, ax, ay
a = a + 0.01 ; use 0.01 if is slow
swap
loop
End Function
Output Code: [pbcode]
Type POS
x#,y#
EndType
Global iVar2,fVar2#,sVar2$
Global MyList2.Pos
Global GUI_SCREENW = 800
Local iVar,fVar#,sVar$
; Local MyList.Pos
; Type
; Dim iTable(1)
; Dim fTable#(1)
; Dim sTable$(1)
; Dim Aliens.pos(10)
Function MY_Function1()
Local MyFloat#,myString$
For lp = 1 To 100
a=lp*100
b=a
c=a+b
This$=MyString$ +"aaasss"
Print myFloat# * a / c
Next
Dim Strings$(100)
For lp =0 To 100
Print Strings$(lp)
Next
Print GUI_SCREENW
EndFunction
Function MY_Function2()
Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,Pi#
width#=800 : Pi# = 3.14159
cx# = width# / 2
ax# = cx#: ay# = 50 apex
ex# = cx#: ey# = 330 ellipse
xr# = cx# * 0.7 : yr# = 0.33 * xr#
do
Cls
x1# = ex# + xr# * Cos(a#) : y1# = ey# + yr# * Sin(a#)
x2# = ex# + xr# * Cos(a# + Pi# * 0.5) : y2# = ey# + yr# * Sin(a# + Pi# * 0.5)
x3# = ex# + xr# * Cos(a# + Pi#) : y3# = ey# + yr# * Sin(a# + Pi#)
x4# = ex# + xr# * Cos(a# + Pi# * 1.5) : y4# = ey# + yr# * Sin(a# + Pi# * 1.5)
fcolor 220,200,100
Line x1#, y1#, x2#, y2#
Line x2#, y2#, x3#, y3#
Line x3#, y3#, x4#, y4#
Line x4#, y4#, x1#, y1#
Line x1#, y1#, ax#, ay#
Line x2#, y2#, ax#, ay#
Line x3#, y3#, ax#, ay#
Line x4#, y4#, ax#, ay#
a# = a# + 0.01 ; use 0.01 if is slow
swap
loop
EndFunction
[/pbcode]
Video Script:
hello welcome back here we are looking
at another one of these blitz to play basic translation videos
so today i was working on the identification of variables uh
the implicit ones in particular
so it'll pick up dim statements it'll
pick up global and local statements
but also has to pick up
variables throughout the code
just pull up this
pretty rudimentary example so we've got
our global statements we can phrase
those
uh i don't think we've got list support
at the moment but i think we're picking
up the keyword
and just storing this for later
locals the same
we just want to raise as well but i'm
not working on those at the moment
just
been working on variables
so i've got global scope which is this
initial part of the program they'll be
all tagged as global scope
and
a function here
and we've got a
bit of code inside here we've got some
array stuff there we'll just pull it out
so we don't confuse ourselves
now things here to notice really are
our usages of our variables so i've got
local
declared here my float my string
my float has the hash symbol on it my
string
it's the first usage
so it has dollar sign at the end of it
and a loop here has
the integer
tag which is the percent symbol
input
but as we move through you'll notice
that uh
i've tagged a as an integer
i've used loop without its
postfix without
suffix b the same these are all used
without them
and down here we've got a string
and then we're using my string
without its
dollar sign
and same goes to float so previously i
was talking about wanting it to pick
these up
and do those translations for us and so
which is something you really can't just
do with like a replacement
things like the percent sign here
if you just pull in a bunch of code
into you know notepad or whatever just
and just do a raw replacement
that would probably get you a long way
to fixing those problems but um
you have a you'll have collisions as
well inside strings and comments etc but
but for the most part you wouldn't no
one would care
here's another bit of code which
actually dragged across from
from facebook just before
to demonstrate this in a broader
spectrum so we've got
in that language all variables were
inherently float
so here i've just added a local
statement with the variables in it
but left all of the occurrences
throughout the program
and without the
hash symbol on them
i've done that intentionally because i
want the converter to pick them up and
and do that work for us
so i'll just hit save on that and close
it
go back to here back to play basic now
this is an example we're loading and
running
running debug so we can see the output
you know in debug is taking 91
milliseconds
most that's just text airport to the
console
here's the function that's that's output
for this last piece here
just send that in a little bit
you can use the scroll function too with
text boxes
you'll notice that all of the variables
that follow
here
so after a declaration up here
the original code hand
was just width etc
all of these are now
read and read and run pretty much in pv
which is pretty good
that saves a lot of messing around
i won't say it's going to be perfect
there's probably some situation where it
will do the wrong thing or whatever
at the moment that's more likely than
not but
that will give us curry that we almost
run in pv as it stands
almost
[Music]
this is actually using radians rather
than angles so we have to convert these
two
that might be something we need to do
um
in blitz as well i'm not quite sure if
the cos and sine functions are actually
if we need to wrap them or not
i haven't tried this wasn't blips code
by the way this was on something else
but
i use that as a good example of
how we can get to
add the postfix symbols do our variables
for us
on mass
uh this is the code that was that's the
converted code so this is a
it won't
probably won't compile in pv we'll
probably get some functions in there
that we're not using
but we should come pretty close um
up here
this is the list of
scopes we've found so we found
what we're kind of like calling global
scope
which is the
the entire program that's not inside a
function
from top to bottom
and this is my function which is
the source position there is wrong
but these are the variables that are
known to be inside it
um some of these are getting or
incorrect is picking up some common
commands that it shouldn't
um
we might do a secondary search on those
and make sure that they're
they're
blips keywords they should already be
classified but i think there's
i think that classification's not quite
working probably
anyway so
you know a function that we dragged
across before we've got all of these
variables widths etc
and they're all tagged as
being a type 2 which is a float and it
gives us an indication of how frequently
the variables are used
and that's kind of that's handy because
we might be able to
use that to give hints about
uh
you know in certain scopes there are
variables that are only used once
that you're not you know maybe it's a
typo maybe it's something else
give warnings possibly
so you could add you can insert a bit of
a header in front of a function let's
say
that's it with a comment that says you
know this variable is not used
more than once or something like that
possibly even remove it
the problem with that would be of course
is is if we've misclassified something
and it turns out to be a constant
somewhere else or something like that
which we don't actually support at the
moment
come to think of it
so we'll have to add
support for constants to make sure and
they'll have precedence over uh
variables as well
the variables are kind of the lowest
thing on the pecking order
but our output here so
this just gives me a bit of idea of what
variables that's found inside the scope
they all seem to be okay if you look
down the bottom here what's
in this scope here
it's picked up things like swap
do
ellipse it thinks they're variables
they're not
of course not
but you know
we're getting somewhere
uh
i'm getting somewhere with this
at the top here
pick up us
our skypes i'm not sure if our
about searching is uh
our scope searching it's working
as per blitz
but i can update that later if it's not
quite quite correct
as we're inside a function is going to
work out what version of a variable
you're using
um
you know if the thing's declared
that's global uh above it
then we need to go okay use the global
occurrence of this so if the global was
declared
let's say it was a floating point
variable and then later on using it
without the hash symbol it must update
that as well
rather than think that's a new variable
inside the scope
but i think actually
even though we're not doing a full
compile
we're just picking through with this
logic we should be able to get a lot of
that stuff done
um
to be horrified if we run it in
on the on the large code base
this takes about 10 seconds to run this
well i'm sorry i can pull compile and
run it to straight
with no debug
so
this is the
9206 line
block of code
so it's been converted in about 900
milliseconds just under a second
that's pretty good i'm actually
i'm happy about that i wasn't expecting
it to do that well
i thought it might take you know five
ten seconds or something for code bases
that were large
run debug this takes a while because
it's dumping all of that crap to the
console and the console is just a
buffered window
so the thing looks like it's died
as you can see it's a long
lot of code
yeah now i can
pick through the scopes and and see what
um
what we've uncovered so this function
gy wind but skin
has these variables in it
some of these might not be variables
because it at the moment doesn't
understand types and the field uh
separators and types so might be picking
up field field separators as variables
here we've got some
references to these things here we're
looking for that in the code base
let's find the global scope
all right that's global scope there
got a bunch of just gar materials at the
front
gui screen width
see that's surprising
saying that screenwrites is only used
once the skin variables are used
that one's used 10 times
so that includes its initial occurrence
so it's declaration
i wonder if that's true
gee i scream with hmm
i don't believe that for a second
so gy screen
width
occurs
yeah it's more like it
was gonna say that that can't be right
so clearly we're not we're not fetching
um
hmm
we're not skipping over something there
we're not searching and finding those
correctly for us
good
what have you learnt well we're kind of
working we're kind of not working so
that's pretty much what we expect to
find isn't it
uh if i try this array thing actually i
might try the array
one here function scopes
so dimension
uh
dim
and i call it uh strings
a hundred
i'll use the example always do it the
other day so four
from the pickles naught to 100
i just want to see if it picks that up
actually sorry print
string
no
dollar sign
loop
thank you let's go
and we didn't pick that up
oh
yeah i know why there's no
trapping of the bracket
if it sees
this keyword and then a bracket
following it
you might know what to do and just
assume that's an integer
and strings without that will just be
integer so
in that scope
my function one there should be a thing
called where are we
yes yet
hmm
that's some some more oranges there
we're not getting both of those we
should have two strings if that's how it
was to seeing it
i had some really weird problems with
this this afternoon actually
weird is not saying the least and i was
at the point where i thought oh no
i found another weird bug in pv
it was right at that moment where i
uncovered oh hang on
it's not a bug in pb it's just i haven't
initialized
okay so we've opened
yeah
uh here's the logic here so if we scan
through we find a word
which is just any group of characters
that's been classified
so we'll see a block of character like
that
there is no white space the block of
characters is alphanumeric so you can
have lowercase uppercase and
numbers
and lower score character as well but i
think it can it has to start with it
with a underscore or
has to start with a
letter
anyway so we're skimming through we find
our word
we go okay
grab the token that's our variable name
we'll
need that to search for it in a second
we grab
whatever's after this thing
if this is an open bra which means that
the character after this so i just
just here for example
um
with the actual card again
so if we go let's zoom off a bit
so we're looking at this
keyword here
uh
it'll grab the token next to it which is
going to be the bracket token now what i
can actually do and get away with is you
have white space between these things
i think in pb generally it doesn't like
the white space to be there but in a lot
of languages that are pre
tokenized and then translated
which means that the white space can
just be thrown away so it doesn't matter
if there's white space between stuff
which is kind of weird
if people can't really do that well
i'm not sure enough to talk ahead but
anyway so we said this keyword here this
strings keyword
and since the next token is an unknown
stop character it's not a hash it's not
it doesn't know what to do if this is
presenting as an integer array
that's why it's failing so
what do here
sounds pretty crazy it's just um
just
jump to check this variable
that's how lazy i am yep
so look
and there we go we fixed our fix one
little shortcoming so
strings has been picked up as being
that is the array because it's saying
the next character is here or that's the
assumption it's going to make
it's pretty good assumption
um
and we're looking for that in the
current skype and found it so it's happy
to to promote it
here we have
we've got our strings array
and we found two occurrences of it
that's what we wanted
happy days
isn't that terrific so it's pretty much
just bumbling logic to fall through and
go okay this is our best guess for what
this keyword is
uh if we were building a full-on
compiler we actually have
as i was saying before you
you grab
as you found each keyword you then
dissect what the keyword actually is if
is it a
structural statement like a for
statement or a go-to or you know or a
compare you know where it's going to be
and then
uh they all have a certain pattern
so a for loop has okay after the full
statement we have a declaration then we
have
an assignment and then we have an
expression
a two statement and an expression
that's that's the pattern that i have
and if statement has
you know it's just an if and it's an
expression
uh
what we have to do is we have to break
the code down
at least then if we did that we could be
type aware this is not type aware
what i mean by that is is it
is it's not aware if you
like if you go hey here's my string
right here and i add
an integer value to it
pv is going to go what the hell are you
doing you know it might have a clue
but if we
wrote this as a true compiler we could
run through here
uh
promote this is to be the correct array
we wouldn't even need to do that
actually
uh and then we have a string we have
this replacement
we have um
conceptually half we've seen the
expression the first time
we pull the fullest result see it we end
up with like result
string plus this integer then we have a
bit of logic there going okay
you
since it's a string mixed with integers
we're going to want to treat the string
like an and a number so i have the value
of the string
yeah you could do that stuff
in a translator for you
and life would go on but in our version
here we can't do that
because i don't know
what this is
right or what the parameters in here are
i have no idea
i'm not matching types i'm not matching
the patterns of expressions nothing
so
so we can get you know get away with a
very preliminary um
comparison comparative sort of
replacement but we're not going to have
things that are
you know if your input code makes no
sense and your apple code won't make any
sense and in places
the output code here white making sense
in pb because you'll have
i noticed there's a thing in blitz where
you can do you can do type conversions
like
you know
a equals
so you have a literal string
and have it converted for you to an
integer value
um
yeah it just saves having you know a
function
val for example
you know
this is a shortcut they've added
anyway
is the this is the basic logic we're
just picking through here
um
just to select a slight case
with if the next the character after our
current current word is this
and it's most likely this thing
yeah so i have an example statement eg
this word bracket
if for the percent
it would be this word
percent
hash dollar sign etc
um there should be a you know
another version here that handles um
the trapping of
fields within types
but that's not something it even looks
at the moment
we'll try and get this to work pretty
well and then we'll worry about
stepping up for types
make sure it can pick up the
blitz commands correctly output them you
know into a
wrapped function a format and
then try and
make some simple programs
in blitz and try and get them to run
so
isn't that fun
anyway uh thanks thanks for hanging
around and listening to me ramble on
and i'll see you next time bye
-- Script On PasteBin (https://pastebin.com/eG515YSR)
BlitzBASIC 2 PlayBASIC Conversion: It's Alive - Blitz Wrapper - 7th Mar 2022 This is the 5th look at writing a tool that can handle most syntax level conversions of Blitz BASIC code and convert it into PlayBASIC compatible syntax.
In this episode we take giant leap forward by implementing implicit variable and array name detection as well command set emulation with our simple Blitz BASIC wrapper of blitz commands. This results in our first 99% translation and execution of that code in PlayBASIC.
Input Code:
MY_Function2()
Function MY_Function2()
Graphics 800,600,32,2
Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,myPi#
width=800 : myPi = 3.14159
cx = width / 2
ax = cx: ay = 50 ; apex
ex = cx: ey = 330 ; ellipse
xr = cx * 0.7
yr = 0.33 * xr
While GetKey()=0
Cls
x1 = ex + xr * Cos(a) : y1 = ey + yr * Sin(a)
x2 = ex + xr * Cos(a + 90) : y2 = ey + yr * Sin(a + 90)
x3 = ex + xr * Cos(a + 180) : y3 = ey + yr * Sin(a + 180)
x4 = ex + xr * Cos(a + 270) : y4 = ey + yr * Sin(a + 270)
Color 220,200,100
Line x1, y1, x2, y2
Line x2, y2, x3, y3
Line x3, y3, x4, y4
Line x4, y4, x1, y1
Line x1, y1, ax, ay
Line x2, y2, ax, ay
Line x3, y3, ax, ay
Line x4, y4, ax, ay
a = a + 0.1 ; use 0.01 if is slow
Flip
Wend
EndGraphics
End Function
Output Code: [pbcode]
;--------------------------------------------------------------------------------
#include "--->PATH OF LIBRARY<--\BlitzWrapper.pba"
;--------------------------------------------------------------------------------
MY_Function2()
Function MY_Function2()
BB_Graphics 800,600,32,2
Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,myPi#
width#=800 : myPi# = 3.14159
cx# = width# / 2
ax# = cx#: ay# = 50 ; apex
ex# = cx#: ey# = 330 ; ellipse
xr# = cx# * 0.7
yr# = 0.33 * xr#
While BB_GetKey()=0
BB_Cls
x1# = ex# + xr# * Cos(a#) : y1# = ey# + yr# * Sin(a#)
x2# = ex# + xr# * Cos(a# + 90) : y2# = ey# + yr# * Sin(a# + 90)
x3# = ex# + xr# * Cos(a# + 180) : y3# = ey# + yr# * Sin(a# + 180)
x4# = ex# + xr# * Cos(a# + 270) : y4# = ey# + yr# * Sin(a# + 270)
BB_Color 220,200,100
BB_Line x1#, y1#, x2#, y2#
BB_Line x2#, y2#, x3#, y3#
BB_Line x3#, y3#, x4#, y4#
BB_Line x4#, y4#, x1#, y1#
BB_Line x1#, y1#, ax#, ay#
BB_Line x2#, y2#, ax#, ay#
BB_Line x3#, y3#, ax#, ay#
BB_Line x4#, y4#, ax#, ay#
a# = a# + 0.1 ; use 0.01 if is slow
BB_Flip
EndWhile
BB_EndGraphics
EndFunction
[/pbcode]
Blitz Wrapper: Attached bellow
Tackling FUNCTION input and Return Parameters
Last night I build in support Input parameter and return parsing fro the function header. Today the focus is getting the convertor to build a return expression for our ENDFUNCTION prototype.
The current parser detects the return type, scans the scope for RETURN statements and if none are found exports the appropriate null to EndFuntion so the PB parser can detect the return type.
BlitzBASIC input code:
; Empty Function shell, returns NULL and No return type specified
Function Test1()
End Function
; Returns INTEGER, but not return statement, so returns NULL
Function Test2%()
End Function
; Returns Float, but not return statement, so returns NULL
Function Test3#()
End Function
; Returns String, but not return statement, so returns empty string
Function Test4$()
End Function
; Returns MyVector, but NO return .. so should return NULL
Function Test5.MyVector()
End Function
PlayBASIC output code:
[pbcode]
; Empty Function shell, returns NULL and No return type secified
Function Test1()
EndFunction 0 // Assumed Integer return
; Returns INTEGER, but not return statement, so returns NULL
Function Test2()
EndFunction 0
; Returns Float, but not return statement, so returns NULL
Function Test3#()
EndFunction 0.0
; Returns String, but not return statement, so returns empty string
Function Test4$()
EndFunction ""
; Returns MyVector, but NO return .. so should return NULL
Function Test5()
EndFunction <FIXME: RETURN PROTOTYPE MISSING>
[/pbcode]
Promoting User Defined Type Variable and Array Fields
Today we've made our way through to one of the last remaining issues; which is catching those pesky implicit typed variable declarations as well as those back slash characters used throughout the program.
Here's tonight's result..
BlitzBASIC input code:
Type MyVector
Field x#,y#,z#
End Type
Dim Verts.MyVector(10)
For lp =0 To 9
Verts(lp)= New MyVector
Verts(lp)\x = lp
Verts(lp)\y = lp
Verts(lp)\z = lp
Next
Function Test14.MyVector()
cool.MyVector = New MyVector
cool\x =111.1111
cool\y =222.2222
cool\z =333.3333
Return Cool
End Function
PlayBASIC output code:
[pbcode]
Type MyVector
x#,y#,z#
EndType
Dim Verts(10) as MyVector
For lp =0 To 9
Verts(lp)= New MyVector
Verts(lp).x = lp
Verts(lp).y = lp
Verts(lp).z = lp
Next
Function Test14()
Dim cool as MyVector Pointer : cool = New MyVector
cool.x =111.1111
cool.y =222.2222
cool.z =333.3333
ExitFUNCTION Cool
EndFunction Cool as MyVector Pointer
[/pbcode]
This compiles and runs.. It's not functionality identical mind you, but the objective here is to get it as close to compiling as possible and then YOU pick up the slack.... :)
BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode 06 - 3D Gouraud Shaded Torus - 14th March 2022 This is the 6th look at writing a tool that can handle most syntax level conversions of Blitz BASIC code and convert it into PlayBASIC compatible syntax.
In this episode we convert some software 3D rendering code from 2001. The code renders a light sourced gouraud shaded spinning 3D torus. To convert the program we first pass it through our convertor then make the final adjustments on screen. Once the code is up and running; we optimize it for best performance from PlayBASIC.
Performance wise we found something that you might not be expecting, the converted PlayBASIC code runs on par with the original Blitz BASIC code (on the same system). This is surprising as Blitz BASIC is natively compiled language (compiles to machine code) while PlayBASIC compiles to it's own run time. The gap widens further by implementing GouraudStrip and GouraudTri into the mix, but i'm stunned at the performance of PlayBASIC V1.65 runtime and even come close to Blitz in the first place..
The resulting code is attached to this post bellow !
[ Links: ]
BlitzBASIC 2 PlayBASIC - Source Code Conversion WIP (https://www.underwaredesign.com/forums/index.php?topic=4625.0)
XLNT GUI - Porting Blitz Basic GUI to PlayBASIC (Is it possible?) (https://www.underwaredesign.com/forums/index.php?topic=4620.0)
Visit PlayBASIC.com (http://playbasic.com)
Script
https://pastebin.com/CbXbvGHK (https://pastebin.com/CbXbvGHK)
hello and welcome back here we are
tackling this blitz basic to play basic
converter in today's episode we're
actually going to look at
the lovely taurus that's spinning around
on the screen
the current level of the build pretty
much puts us at a workable state now it
doesn't produce working code for this
example
but i'll put it on screen
for you
and we'll write and it's pretty cool
okay let's take a look at the original
blitz code
it was written in 2001 this example and
it's quite a nice example when running
as you've already seen
but the whole thing is
all in software there's no hardware
acceleration no internal polygon
rendering in it
all the poly rendering is done
uh
well brute force really
it's drawing a batch of polygons doing
this stuff here trying out vertices
sorting the faces etc
so a lot of work has been done
that's my key point here that's the the
takeaway point is that there's a lot of
work being done
until we come right down to the software
rendering this example is doing groud
shaded polygons and they're also light
source which just makes it look a bit
more interesting
what i've actually done is i've taken
the original code
and attached the data statements because
it was selectable in the original
our translator at the moment doesn't
understand include statement so we
couldn't have that
set up this way
this way we can just pass it through as
one big blob and get a blob out
back to the translation
so let's run the translator now we'll
write in normal mode so we can see the
the speed of the conversion
uh it's about a thousand lines i think
no sorry it's 2000 lines but most of
those data statements so don't get too
excited
so we're doing our conversion in about a
hundred and you know i'll be generous
say 150 milliseconds not bad
if we run into bug mode it'll take a lot
longer so it's spitting out a lot of
data to the console
we've got about half a second there all
up so the console is over here
that's our code
that's been translated
the data statements didn't need to be
translated at all so they've just passed
through
uh where are we our program code up here
has been converted
we go up the top we can see that's the
start of our code and
sorry above this is the information
about the scopes what local variables
there were
how many times they were used etc some
are used very frequently some are used
hardly ever
so we i think we'll be able to use that
to our advantage and give tips about the
conversion
uh for each scope
yeah you know
let's not get him ahead of ourselves
let's just get this thing converted
so let's grab all this
head down the bottom yeah okay grab that
thing
and uh quit out of this
okay i've already set up a
an empty project for us to paste into so
let's paste our code
from our conversion across
so we're getting 2
700-ish lines of blitzcode
now we've got an include file up the
front here sorry let's grab that before
we've inserted an include file this is
coming from our my own wrapper at the
moment to emulate blitz functions
um let's kind of see how we go
uh see how far we get without
our dying
i know some functions here we're going
to need to remap like this read
statements here
pb has a different syntax for data
statements
i've got some collisions there too but
we'll go through them so we can you can
sort of follow what's happening with
this stuff we compile
right so our first
first problem is this read statement
uh
reading traditional basic is is a
command
and we don't support that we actually
have a read data function
to grab the next uh bit of data off of
the data
we can think of a data like a stack
can't you
now
it's really just like an index to it
to a table but
so branch ahead
uh vertex signal vertex we've got some
data statements there put those there
get rid of those thanks
i can see some problems with this
already
and they're not to do with the
translation they did to do with
differences in
well
how one language
likes to use keywords in one one uh
doesn't oh undo that thing so what i'll
just do then
delayed that terrible
some dummy reads there so that day has
got some empty stuff in it
don't need the reed stavens there of
course
pull them out
quick save
let's just see what the next thing is
doesn't like about this is
uh yeah i thought it would like this
actually see how we've got a type name
called vertex and an array called vertex
now
it can't really distinguish between the
two
obviously in blips you're allowed to do
that
oh in pv you can't so what we'll do is
we'll
put like a lowercase t in front of the
type names
and
so
it's in front of vertex
i thought a poly was another one as well
poly was one
and
all light source was one
okay
so like south park there yeah eric you
know there you go
that was my mistake terrell
ah here we go so this is a byproduct of
the wrapping pepe likes that it's um
functions to have
a pair of brackets on them
okay
this is something that popped up when i
was doing the a monster truck a most to
play basic conversion
in blitz um it's valid to have a
variable called fps
in pb that's the name of a function
so
the error is going
hang on what are you trying to do with
fps you can't do that with this so we
have to rename this um
when i did the amos converter it would
just put a prefix in front of these ones
that's what we'll do now we'll just go
yep
anything that's fps
just call it local fps yeah
i'm going to call it anything we want to
do there's ones over there too
hidden away anymore
can't see any more of those so let's
just compile and see how we go
oh text yeah text is a bit of a pain
because of the conversion
i've got a version of text that'll do
strings but here we've got a combination
of
string data and integer data so we have
to have like a string wrapper around
this
for the amos converter i did
actually
that's actually what i did is it went
through it it
did a rough reese
a rough sort of bracketing of these
these things here just assuming that
they're integers or whatever
i might just get rid of the wrapping for
this
command
because text is pretty much text there's
not much we're just drawing stuff in the
current font
i will have to actually put strings
around these
isn't that terrible oh good goodness
goodness gracious
uh
put the closing bracket on
yeah it's definitely something we should
definitely try and tackle
and then the variable collision stuff
too that could be a problem with big
code bases
um i forgot about that one
next one let's just hit compile again
see how we got
that flip need some brackets
flip is basically sink
you know
places plays in play basic lands just
flipping the back buff for the front
buffer
hey
that's a long way through
lock buffer
i think it blitz it requires a parameter
and we'll let's set up to
set up so that surface 0
is the screen so we'll just put lock
buffer 0
for that and there's another collision
there see how it's got rgb equals
this
expression wow i'm surprised it's done
like that
um
we'll leave that there
just to show you that that's going to
upset play basics see how this variable
name here it's going hey you've got a
function
using the function name in some wacky
way what are you doing
ah we'll just call it
put l in front of it for local or
something
you can so how far we get
right pixel
uh
oh it's got a surfacing on the end
point zero for surface
you know
pretend like we know what we're doing
unlock buffer no
zero for surface yep good on you
fantastic no no
oh man so on
so the functions ex
yeah okay
so the bottom there we're exporting a
integer which is a assumed return from
from the translation
um so for this exit function here we
have the same
same response
otherwise you might just get some stack
misalignment
um there is an error for that actually
if you get one
press on dudes let's go
yeah oh
yeah
yeah some basics will allow you to do
if expression and then then and then as
long as there's nothing following them
then you can you can use an end if
statement we don't do that
i must trap this one and cut it out or
just add it to the phrase at some point
lock buffer it's going to be screen
isn't it
unlock's going to be the
screen right pixel
one two three
pv
back buffer same collision
issue there
so that we're constructing a color and
then running it to the screen so i've
got a lot of work to draw a pixel
yeah so it's going to run pretty pretty
terribly initially but um i know we can
speed it up
when we get this thing going
same drama
don't need the then statements thanks
hit save
ah we've got through the code that's
cool
got a die in front of the label anymore
what else we got
chords
you can pile again
one more
surely that must be the end of the data
let's hit run
wow it's running
and it
actually is running but there's some
problems with it
as you can see
and one of the problems is not what you
what you're expecting
i did put this the other day and ran
into the same same drama so
i know roughly what the what this issue
is going to be
so before we tackle that i'll just
demonstrate we're working
why is working up front
so
we won't draw um the polygons as groud
we'll just draw them as a set of
vertices
the function's already in here
hopefully it should work there you go
in other words the code that handles the
rotation uh projection etc and
the polysorting that's all actually
working
what's not working is this drawing this
draw polygon function
uh
if we cut poly out
put one of these line savings in now
this has the old syntax see how it's got
the the backslash
that's the blitz syntax
because this code was inside a comment
and this wasn't converted
um quick save
let's hit
run
hmm so we are actually working
that's pretty cool i like that
and the rate's not too bad either we're
getting you know 10s and 15s etc
uh
we can do better now
sorry
i might just put a space bar
on this main loop where are we really
i've set an exit time there so if it
runs for a number of frames it'll exit
by itself i might drop that down to 50
frames
um
it sounds like a short time but
uh when we get this we start tackling
this um
this poly rendering routine it's very
slow initially because of all the
wrapping
it has a few bugs in it too that we've
got to actually track down
so it'll run for 50 foot and i'll run
for
200 frames 250 frames okay
or until hit the space bar all this guy
all the escape go
spacebar good
right let's tackle this draw polly
go to
the groud poly function
um
i think what we'll do is
so we'll actually have a look at this uh
oh are we drawing the lines
or not what are we drawing
all right that's a little
that's the x
for this row
it's the x from the next row and we'll
draw it in like a
green maybe
so i should draw a strip for where the
hot each horizontal strip of the
the polynomial's drawing is
um
should
now clearly the lines are outside of the
polygons because the polygons are these
white lines here
and our lines are way outside that so
something's not right
i do know what the problem actually is
so i'll talk you through it this one
here
it's in this edge function
where we're lying on
well
let's go back a bit you might have
noticed that all of the values here
for coordinates
uh see how we've got x1
and then we've got rgb coordinates for
it we've got x2 rgb coordinates
uh these are to draw
down the edge of the polygons as it's
being scanned converted
now when we have a triangle we we work
out what's the top point
and we work out what edges we need to
draw and we draw
ideally from the top to the bottom you
can actually draw in any whatever your
order you like
as long as you end up with a bunch of
lists bunch of spans
that represent the shape
now this doesn't work
because here we've got a translation
where we're going
we're subtracting x1 from x2 and then
shifting it up 8 bits
if x1 x2 are positive
that's fine
and it's the same goes for y1 y2 if
that's positive that's fine
but at any point
we end up with something that's that's
negative
we're mixing signed arithmetic with
bitwise arithmetic
so something between how the shift
operator works in blitz and how the
shift operator works in pv is different
here i'm just moving the bits just going
hey
shift the bits up who cares about the
side of it
so we've actually got to do a division
here or sorry multiplication
so so
if we shift something
if we shift something up eight bits
i'll just call it scala i guess
so we're just going
um
we can do it like this
we can compute that scala
that's the level of precision
which is going to be an integer value of
256.
so we could substitute in here
we're multiplying this sorry wrong
operator
now because pv is interpreted
the cost of having in an integer mold or
an integer shift is not that great
to be honest
it's really almost nothing
well actually i wonder there too see how
we've got
we've got a shift and then in addition i
wonder if the precedence
of this is actually a problem
let's just check that
hey we're here now let's just do it yeah
come on
i know you're bored i know you want to
see it running fantastic yeah
this is computing our edges if our
engines look normal then that's our
problem that it's not
there's not a difference between the
shift it's a difference between the
precedence of the operators
i don't know
let's find out together
hey that's the problem
that's nice to know
yeah all right
just to check that
that means we can get away with we don't
need to do
those modifications we can just go yeah
all right do your thing dude
do this that's very good do this thing
very good
lovely long as it still works
the slide performance is actually
a common problem with direct draw
applications all right so that that's
actually solved
our problem so
if we go back
that's our pixel rendering loop
that's our line rendering rendering loop
now if we do
something
simple like we go a lock buffer here
so we're drawing all of these lines
batched up with and we're locking the
surface
that should
make people a lot happier when we're
doing this job
should
yeah it's much happier with that
cool
now we know the the
vertex locations are accurate we know
that our
they're all the same so now we need to
tackle this in a loop and i know this
three slides could take you know
quite a while to render so i'll put that
abort case
back into the code
of you know
i have it be uh
20 frames
see how bad we get how bad it runs up
from up front
about a frame a second
but
it is running
can we improve on this you better
how we're going to do it well the same
old way we always do it
like in the buffers dude
so we know it works and all of our
efforts there have been have not been in
vain so
get rid of the line drawing stuff there
for a second
go up to
and draw a polygon and go have a look at
the draw
oh
that's right below it
right
now
right pixel is pretty much a wrapper
around
the
the dot function so we can substitute
right pixel
with dot we don't need to know the
buffer all the time we don't
people work that stuff out for us so we
could just do this
dot c which is the colored version
for the lrgb and that should help us out
a lot
doesn't seem like it has though does it
and
the main reason for that is that we are
drawing
500 polygons in every scan line of those
polygons which is going to be let's say
each polygon's got 20 scan lines so
that's
570 times 20.
that's how many times we are locking and
unlocking the surface
that's a lot
uh so what we need to do what we should
do really is that rather than lock the
buffer
every time we draw a strip draw one one
span
which is how this is has provisioned for
it before
go up to the
animal drawer these four those
so here we go
would you look at that
so we're running actual translated blitz
basic code
uh it's drawing every polygon dot by dot
we've got some buffer management control
in there
we're drawing lots of extra dots there
too so i bet they they don't have great
uh buff sorry
buffer management stuff in them as well
but we're still doing something that's
not great though isn't it we're locking
the buffers
every time we draw a polygon so if we
draw the more polygons we draw
in this case here if we if
we have 500 polygons and half of those
polygons are visible
so let's say 250 on average
then
we're going to be drawing attempting to
lock the buffer and unlock it
250 times so we want to actually
probably a better solution would be to
lock the buffers
at the start of the polygon batching and
then release it at the end
let's try that then so let's draw a
polygon routine here
we're running through and doing all this
good stuff so we'll just do the locking
it at this level
and strip out the other stuff we added
before
where are we there we are there we are
so it locks the current surface by the
way if you're not familiar
uh draw vertices
there's no buff although there is some
there that's not too bad
sorry
let's go to grab polygon find that thing
we don't need to lock the buffer in here
so
we can do our strip
render our strips
and the buffer state is being managed on
a higher level so we don't need to have
all this pleasing thank you with those
that there's this low level here
that shouldn't make it perform much
better
should
and does
now we're capturing the screen we're
drawing a bunch of dots as well so you
know
it's not bad
it's just a complete translation of the
same application
uh clearly the inner loop here has some
things there we could probably get rid
of
like
if we know we're never drawing outside
of the display
constraints
we can swap dot with uh fast
fast dot
and we probably should do
here i think we're always rendering to
the same surface
so that would mean our our lock would be
appropriate for the for the same surface
all the time
but you've got to be careful with that
stuff
one way to ensure that's never going to
was going to work as we can read
if you ask
us pb to read a pixel from the surface
it will see the locking every time so we
read one pixel at the start of the batch
of all the polygons then we never needed
to do it again
if you're jumping around changing images
you're rendering to locking something
unlocking it
the
the optimizations that track the lock
state can
can you know they can work against you i
know
i'm a terrible person
should be the same
cool
that's pretty good some stuff in here
too yeah i could grab the
grab this thing here
um
just call it
this is your index
grab your index from there
save reading that array three times
so i'll read it once and then just throw
it away
those kind of you know there's micro
optimizations you can run through and do
those things yourself
um
you probably probably always treat your
colors separately and have the light
source computed
or you've got more actually
you can clip the range there's for
example c2 equals
clip range
c2
north of 255
you know
that sort of thing
um you're probably not really winning
back any performance by doing those
things but it can just reduce your code
it's pretty cool i like it
i like it a lot ah right
that's our translation for you um hope
you enjoyed that
let's say we wanted to push this a bit
further we could we could make this a
bit more play basic friendly
get rid of the dot rendering stuff
draw vertices get rid of that
don't really need it let's check this
thing out
that's nice
uh one thing we could do is obviously
since we're in pv land
now draw a polygon
now
let's head down to
our draw a line where are those
this particular section of code here
that's it's forming an rgb color
what we couldn't do is we could of
course
use the rgb function
rgb
was it rt
uh gt and then bt
we don't have to do this in software so
we you know we're two function calls
that approximate
this is
we get rid of a shift a shift and two
additions
but we substitute them for one function
call
let's try it
it's pretty hard to know
if if we've won much back in that i
would say we probably have
obviously the best way to do this in pv
is actually to do this
let's draw a groud strip from x1
from r1 g1
b1
to x2 rgb
it's going to be
r2
blue 2
and green two and
on the y row so we can just get rid of
all of that really
yeah
it's pretty comfortable now it's
obviously we're switching a lot of the
the runtime dependency to command set
dependencies
uh which is because the built-in
function for drawing a grad strip is
pretty much
well it's pretty optimal you know
compared to
i don't know how many cycles this takes
to
to execute through the through the
runtime but
every single pixel is doing that
i guess what you could do is you could
use some of the
[Music]
the paired pixel optimization stuff
where you
you know when you draw
you unroll the this inner loop a bit
further you draw pairs of pixels you
know in one pass compute them etc and
that actually works pretty well to be
honest
and you draw a pair of dots
at one time rather than a single lot
that makes that can be beneficial
because you're drawing
or you're saving
some overhead from calling a function
which in the runtime is quite expensive
so even though this is relatively fast
you know this is the fully
fully interpreted rendering loop
so we're probably somewhere in that you
know in the
between 30 to 60 frames per second
which is stunning to me
while it's been captured or
now this is going to be you know
comparing to the
the native loop that draws ground pixels
it's not that much detriment it's
probably twice as fast let's say
if i converted the whole thing to use
the groud polygon
it would be much faster again
but i want
i'll
just revert the code back to how it was
and you can
tackle this yourself
what if we avoided drawing the line at
all and just drew
a ground line in here
so we computed the start of the line
x1 yep go for it
x2 is going to equal
it's the here
so we just need these
rgb
values here
and that function should pretty much
work the way it was working before
we've got x y x one y is the same
let's try her out
i think for this approach we're pretty
much um
at maximize our throughput for it
to draw strips
to get quicker we're gonna have to go to
drawing polygons
just draw the whole thing
um
grab triangle x1 y1
rgb
one x2 y2
rgb2
x3
y3 rgb3
exit function to avoid all that other
stuff at the bottom there
you know
uh so rgb one equals rgb rgb
g1 b1
because the command expects uh the
parameters to be fed to it
as colors
um
that are compressed
so they're packed together as
rgb rather than separate rgb
fields
all right
let's give it a go
goodness gracious
oh
i've got a return to zero
yeah no surprises there
is you can see it kind of peaking at a
few hundred frames per second
what if we just keep those in the code
or have uh
i'll make three different versions of it
so version two
which will just be the
the line optimization and version three
will be the full polygon rendering
thing so we'll just
cut all of that out
so version three of the
function will be this
don't need anything below that
version two will be the
so doing all this work here great all
going well and then we're doing this
so we
using ground strip to do for this
version
uh
where are we and
for the original version we just you
were doing
as it was the stock version
uh
just
restore that to how it was cut all that
stuff there out again
excuse this video for being so long
so the inner loop no we want the actual
pixel rendering
run it give it a test
we're back to the normal software
rendering
which is still pretty good
cool
what if we put a switch in there
to choose which rendering method we
wanted
to
[Music]
global uh render
random method equals zero by default
uh at the bottom here we'll just
display this to the user
i don't draw up there actually
so i'll come down about
that lori 60 random method
random
random method
and
just call it render
yeah i'll do that
everything on the end here render
sorry method
come on
i know it's light it's not that light
add a bit of crappy logic up front you
know
all the good stuff
select
uh render
method
case zero
top
this is the fast dot
in a loop
then select
a couple of those
two
this is the
ground
strip
round triangle
um
so we'll just have a
bit of a check here um
i don't know if the answer is press or
something
whatever
uh this bump that
bigger than two
making it a zero it's kind of a default
case
i couldn't be bothered
isn't that terrible
now i could use like
call function in this and do some
as9
kind of crap
uh we we'll just have the polygon
rendering stuff wherever that's going to
uh draw a poly
select random method
have a select case
very old school
all right so we were method one method
two i'll make this correlate here
actually method one
method two um
uh sorry i didn't think this was
going what
what the hell
all right so method one is the
ground strip version and polygon
2 is the full blown polygon version
let's try it out so we can check them
side by side
all right so looking at the the fast dot
which is the original emulation of the
blitz code
we're switching to ground strip mode
which is we're drawing the inner strips
with our groud strip command
we're peaking at 125 frames per second
we're averaging around over 60 frames
per second now
all in software
on the interpreter so with polygon
we're hitting 250 frames per second
the average is coming up and up and up
now of course that's going to be
quickest because we're doing the
we're passing control from the
interpreter
to machine code to fill the triangle and
come back
i hope this was insightful have you
learned something hope you've interested
in something
thanks for watching i'll see you next
time
bye
READ DATA parsing and remapping to ReadDATA() statements
Here's an input-> output example from todays conversion engine. This one focuses on the REAd data command and attempts to remap those commands to PlayBASIC's various readData() / ReadData#() / ReadData$() functions.
Dim iarray(100)
Dim farray#(100)
Dim sarray$(100)
Read a
Read b#
Read c$
Read iarray(0)
Read farray#(0)
Read sarray$(0)
Print a
Print b
Print c
Print iarray(0)
Print farray(0)
Print sarray(0)
Print "Stacked "
Read x,y
Print x
Print y
Read x,y,z
Print x
Print y
Print z
Read iArray(0),iArray(1),iArray(2)
Print iArray(0)
Print iArray(1)
Print iArray(2)
Read fArray#(0),fArray(1),fArray(2)
Print fArray(0)
Print fArray(1)
Print fArray(2)
Input
Data 100
Data 123.456
Data "Hello World"
Data 200
Data 222.222
Data "Hello World2"
Data 111,222
Data 111,222,333
Data 1111,2222,3333
data 1111.23 , 2222.23 , 3333.23
Converted code ... only one change and it runs
[pbcode]
Dim iarray(100)
Dim farray#(100)
Dim sarray$(100)
a = ReadData()
b# = ReadData#()
c$ = ReadData$()
iarray(0) = ReadData()
farray#(0) = ReadData#()
sarray$(0) = ReadData$()
Print a
Print b#
Print c$
Print iarray(0)
Print farray#(0)
Print sarray$(0)
Print "Stacked "
x = ReadData() : y = ReadData()
Print x
Print y
x = ReadData() : y = ReadData() : z = ReadData()
Print x
Print y
Print z
iArray(0) = ReadData() : iArray(1) = ReadData() : iArray(2) = ReadData()
Print iArray(0)
Print iArray(1)
Print iArray(2)
fArray#(0) = ReadData#() : fArray#(1) = ReadData#() : fArray#(2) = ReadData#()
Print fArray#(0)
Print fArray#(1)
Print fArray#(2)
BB_Input
Data 100
Data 123.456
Data "Hello World"
Data 200
Data 222.222
Data "Hello World2"
Data 111,222
Data 111,222,333
Data 1111,2222,3333
Data 1111.23 , 2222.23 , 3333.23
[/pbcode]
Download:
Attached 3D Torus code bellow
BlitzBASIC 2 PlayBASIC: Labels and Include Statements (19th March 2022)
After making [plink]Blog 22 (https://www.underwaredesign.com/forums/index.php?topic=4617.msg30595#msg30595)[/plink] I sat back down to wrap this thing up; adding support for LABELS, which are stored with a dot prefix in Blitz and then tackling the bigger issue of the Include statement.
The Include functionality is an interesting problem, I think i've tackled this in about every variation know to man and never felt good about it. Generally When I parse stuff and hit an Include statement, it means loading that file into memory and doing a manual insertion at that position; So it's a brute force operation. But, this time we have linked tokens in our document so the data doesn't need to be physically inserted, rather we can load the tokenized document and link the new token stream into the old stream. This is a bit tricky in PB when your trying not to use pointers. So it requires a bit of magic to merge of pair of lists, but all in all it seems to work fine now.
Initially though it was making all sorts of strangeness occur, I kept getting a bizarre error from PlayBASIC about an array not existing. Which I took as a given, but it turned out to be PlayBASIC was returning the wrong error massage, throwing me off the rather obvious scent. Which was as simple as an index being out of bounds. Once that was corrected, it actually worked. Although then I ran into another drama; where the convertor would hang if a file was included twice. Which turned to be nothing about the inclusion process, but another function that searched for Local variables could fall into an infinite loop if there was two functions of the same name.
#indiedev #gamedev #programming #coding #coder #convert #sourcecode #blitz #bltzbasic #blitz3d #basic #conversion #programmer #howtoprogram #learntcode
BlitzBASIC input code:
Dim iarray(100)
Dim farray#(100)
Dim sarray$(100)
Read a
Read b#
Read c$
Read iarray(0)
Read farray#(0)
Read sarray$(0)
Print a
Print b
Print c
Print iarray(0)
Print farray(0)
Print sarray(0)
function Stuff()
;Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
;Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,myPi#
End Function
function Stuff()
;Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
;Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,myPi#
End Function
Print "Stacked "
Read x,y
Print x
Print y
Read x,y,z
Print x
Print y
Print z
Read iArray(0),iArray(1),iArray(2)
Print iArray(0)
Print iArray(1)
Print iArray(2)
Read fArray#(0),fArray(1),fArray(2)
Print fArray(0)
Print fArray(1)
Print fArray(2)
Type dude
Field x,y#,z$
End Type
me.dude = New dude
Print "TYPE FIELDS:"
Read me\x , me\y, me\z
Print me\x
Print me\y
Print me\z
Input
Data 100
Data 123.456
Data "Hello World"
Data 200
Data 222.222
Data "Hello World2"
Data 111,222
Data 111,222,333
Data 1111,2222,3333
Data 1111.23 , 2222.23 , 3333.23
; type field data
Data 9999,9999.123,"This is a type"
.MyLabel1
Data 10,20,30,40,50
.MyLabel2
.myLabel3
include "Pyramid-Demo.txt"
; This is a comment between includes
include "Pyramid-Demo.txt"
; Last LIne of code in file
PlayBASIC output code:
[pbcode]
Dim iarray(100)
Dim farray#(100)
Dim sarray$(100)
a = ReadData()
b# = ReadData#()
c$ = ReadData$()
iarray(0) = ReadData()
farray#(0) = ReadData#()
sarray$(0) = ReadData$()
Print a
Print b#
Print c$
Print iarray(0)
Print farray#(0)
Print sarray$(0)
Function Stuff()
;Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
;Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,myPi#
EndFunction 0
Function Stuff()
;Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
;Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,myPi#
EndFunction 0
Print "Stacked "
x = ReadData() : y = ReadData()
Print x
Print y
x = ReadData() : y = ReadData() : z = ReadData()
Print x
Print y
Print z
iArray(0) = ReadData() : iArray(1) = ReadData() : iArray(2) = ReadData()
Print iArray(0)
Print iArray(1)
Print iArray(2)
fArray#(0) = ReadData#() : fArray#(1) = ReadData#() : fArray#(2) = ReadData#()
Print fArray#(0)
Print fArray#(1)
Print fArray#(2)
Type dude
x,y#,z$
EndType
Dim me as dude Pointer : me = New dude
Print "TYPE FIELDS:"
me.x = ReadData() : me.y = ReadData() : me.z = ReadData()
Print me.x
Print me.y
Print me.z
BB_Input
Data 100
Data 123.456
Data "Hello World"
Data 200
Data 222.222
Data "Hello World2"
Data 111,222
Data 111,222,333
Data 1111,2222,3333
Data 1111.23 , 2222.23 , 3333.23
; type field data
Data 9999,9999.123,"This is a type"
MyLabel1:
Data 10,20,30,40,50
MyLabel2:
myLabel3:
/* Include "Pyramid-Demo.txt" */ "Pyramid-Demo.txt"
MY_Function2()
Function MY_Function2()
BB_Graphics 800,600,32,2
Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,myPi#
width#=800 : myPi# = 3.14159
cx# = width# / 2
ax# = cx#: ay# = 50 ; apex
ex# = cx#: ey# = 330 ; ellipse
xr# = cx# * 0.7
yr# = 0.33 * xr#
While BB_GetKey()=0
BB_Cls
x1# = ex# + xr# * Cos(a#) : y1# = ey# + yr# * Sin(a#)
x2# = ex# + xr# * Cos(a# + 90) : y2# = ey# + yr# * Sin(a# + 90)
x3# = ex# + xr# * Cos(a# + 180) : y3# = ey# + yr# * Sin(a# + 180)
x4# = ex# + xr# * Cos(a# + 270) : y4# = ey# + yr# * Sin(a# + 270)
BB_Color 220,200,100
BB_Line x1#, y1#, x2#, y2#
BB_Line x2#, y2#, x3#, y3#
BB_Line x3#, y3#, x4#, y4#
BB_Line x4#, y4#, x1#, y1#
BB_Line x1#, y1#, ax#, ay#
BB_Line x2#, y2#, ax#, ay#
BB_Line x3#, y3#, ax#, ay#
BB_Line x4#, y4#, ax#, ay#
a# = a# + 0.1 ; use 0.01 if is slow
BB_Flip
EndWhile
BB_EndGraphics
EndFunction 0
//LastLineOfPymamidSourceCode
; This is a comment between includes
/* Include "Pyramid-Demo.txt" */ "Pyramid-Demo.txt"
MY_Function2()
Function MY_Function2()
BB_Graphics 800,600,32,2
Local x1#,y1#,x2#,y2#,x3#,y3#,x4#,y4#
Local ax#,ay#,cx#,ex#,ey#,xr#,yr#,a#,width#,myPi#
width#=800 : myPi# = 3.14159
cx# = width# / 2
ax# = cx#: ay# = 50 ; apex
ex# = cx#: ey# = 330 ; ellipse
xr# = cx# * 0.7
yr# = 0.33 * xr#
While BB_GetKey()=0
BB_Cls
x1# = ex# + xr# * Cos(a#) : y1# = ey# + yr# * Sin(a#)
x2# = ex# + xr# * Cos(a# + 90) : y2# = ey# + yr# * Sin(a# + 90)
x3# = ex# + xr# * Cos(a# + 180) : y3# = ey# + yr# * Sin(a# + 180)
x4# = ex# + xr# * Cos(a# + 270) : y4# = ey# + yr# * Sin(a# + 270)
BB_Color 220,200,100
BB_Line x1#, y1#, x2#, y2#
BB_Line x2#, y2#, x3#, y3#
BB_Line x3#, y3#, x4#, y4#
BB_Line x4#, y4#, x1#, y1#
BB_Line x1#, y1#, ax#, ay#
BB_Line x2#, y2#, ax#, ay#
BB_Line x3#, y3#, ax#, ay#
BB_Line x4#, y4#, ax#, ay#
a# = a# + 0.1 ; use 0.01 if is slow
BB_Flip
EndWhile
BB_EndGraphics
EndFunction 0
//LastLineOfPymamidSourceCode
; Last LIne of code in file
[/pbcode]
BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode 07 - Sneak Peek - Syntax Highlighted View - 23rd March 2022 This sneak peek gives us a glimpse at a syntax highlighted view of the freshly converted blitz basic code, But more on that later ! :)
BlitzBASIC 2 PlayBASIC: Variable Collisions + Print & Text Remapping (26th March 2022)
Added a pass to check if variable names collide with known PLayBASIC function names. If they do those variable end up with an underscore stock in front of them.
The other addition tonight has been some support for detecting and replacement of string additions between literal strings an Integers & Floats. Don't get too excited it's pretty dumb and anoything more complex then "String"+Variable isn't likely to work .. But it's better than nothing :)
Here's the main loop from the torus demo, which includes both problems. It uses a variable called FPS and the TEXT function needs it's parameters mapped into strings..
While Not KeyDown(1)
rotate_transform_vertices(x_angle,y_angle,z_angle)
sort_polys()
Cls
draw_polys()
; draw_vertices()
fps=(1000/(MilliSecs()-t))
t=MilliSecs()
Text 10,10,"Current FPS : "+fps
Text 10,30,"Highest FPS : "+hfps
Text 10,40,"Average FPS : "+afps#
Text 10,50," Lowest FPS : "+lfps
Text 210,10," Points : "+numvertex
Text 210,20,"Polygons : "+numpoly
If hfps=0 Then hfps=fps
If lfps=0 Then lfps=fps
If afps#=0 Then afps#=fps : afpscount=1
If fps>hfps Then hfps=fps
If fps<lfps Then lfps=fps
afps#=((afps#*afpscount)+fps)/(afpscount+1)
afpscount=afpscount+1
Flip
x_angle=x_angle+1
y_angle=y_angle+2
z_angle=z_angle+4
If x_angle>360 Then x_angle=x_angle-360
If y_angle>360 Then y_angle=y_angle-360
If z_angle>360 Then z_angle=z_angle-360
quittime=quittime+1
If quittime> 500 Then End
Wend
Which is converted into this for you;
[pbcode]
While Not BB_KeyDown(1)
rotate_transform_vertices(x_angle,y_angle,z_angle)
sort_polys()
BB_Cls
draw_polys()
; draw_vertices()
_fps=(1000/(BB_MilliSecs()-t))
t=BB_MilliSecs()
Text 10,10,"Current FPS : "+str$(_fps)
Text 10,30,"Highest FPS : "+str$(hfps)
Text 10,40,"Average FPS : "+str$(afps#)
Text 10,50," Lowest FPS : "+str$(lfps)
Text 210,10," Points : "+str$(numvertex)
Text 210,20,"Polygons : "+str$(numpoly)
If hfps=0 Then hfps=_fps
If lfps=0 Then lfps=_fps
If afps#=0 Then afps#=_fps : afpscount=1
If _fps>hfps Then hfps=_fps
If _fps<lfps Then lfps=_fps
afps#=((afps#*afpscount)+_fps)/(afpscount+1)
afpscount=afpscount+1
Sync
x_angle=x_angle+1
y_angle=y_angle+2
z_angle=z_angle+4
If x_angle>360 Then x_angle=x_angle-360
If y_angle>360 Then y_angle=y_angle-360
If z_angle>360 Then z_angle=z_angle-360
quittime=quittime+1
If quittime> 500 Then End
EndWhile
[/pbcode]
BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode 07 - Syntax highlighting - Variable Collisions This is the 7th look at writing a tool that can handle most syntax level conversions from Blitz BASIC into PlayBASIC compatible syntax.
In this episode we recap current additions, namely support for variable collisions / simple Print/TEXT expressions and Syntax Highlighting. Visually the tool now has a syntax highlighted view to make it easier to see each alternation.
Since the conversion tool has progressed as has the Blitz command set wrapper, we do another live conversion of the 3D Torus code. This time, we're left with only a hand full of changes before it's up and running in PlayBASIC.
Remember the goal here is not necessarily to build a BlitzBASIC 2 PlayBASIC transiler; rather a tool that can perform the majority of the tedious changes for us systematically. So you should as assume the converted code will need to be manually tweaked.
Check the development blog for more interesting examples
---[ Links: ]---------------------------------------------------------------------------------------------
BlitzBASIC 2 PlayBASIC - Source Code Conversion WIP
https://www.underwaredesign.com/forums/index.php?topic=4625.0
XLNT GUI - Porting Blitz Basic GUI to PlayBASIC (Is it possible?)
https://www.underwaredesign.com/forums/index.php?topic=4620.0
PlayBASIC
http://PlayBASIC.com
BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode 08 - Code Optimizations - Variable Shortcuts
This is the 8th look at writing a tool that can handle most syntax level conversions from Blitz BASIC into PlayBASIC compatible syntax.
In this episode we take a quick look at the results of the optimization pass applies to the freshly converted BlitzBASIC code. In this video; the code is set up to perform the optimization pass upon pressing the enter key. We test various source codes from one with than less than a hundred lines through to the Xlnt GUI source code which is over 8500 lines and it barely impacts the frame rate.
Check the development blog for more interesting examples
(http://underwaredesign.com/forums/BlitzBASIC-2-PlayBASIC-Banner-800p.jpg)
BlitzBASIC 2 PlayBASIC - Source Code Conversion WIP
String Functions Today has been adding support for some function to pass through the translator and not get wrapped. This helpful for things like the String Functions, which almost all of the map into a native PlayBASiC function of the same name. You'll notice the promotion of the $ post fixes through the example. Meaning this code compiles and runs directly..
Number#= 123.456
Result$ = Str(Number)
Print result$
Result$ = Str$(Number)
Print result$
; -----------------------------------------------------------------------
; LEFT and RIGHT string -------------------------------------------------
; -----------------------------------------------------------------------
helloWorld$="HELLO World"
Print Left(helloworld,5)
Print Left$(helloworld,5)
Print Right(helloworld,5)
Print Right$(helloworld,5)
For lp=1 To Len(HelloWorld)
Print Mid(helloworld,lp)
Next
For lp=1 To Len(HelloWorld)
Print Mid(helloworld,lp,1)
Next
; -----------------------------------------------------------------------
; REPLACE -----------------------------------------------------
; -----------------------------------------------------------------------
Print Replace(HelloWorld,"world","<><>")
Print Replace$(HelloWorld,"world","<><>")
; -----------------------------------------------------------------------
; INSTR -----------------------------------------------------
; -----------------------------------------------------------------------
Print Instr(HelloWorld,"world")
Print Instr(HelloWorld,"world",5)
Print Instr(HelloWorld,"zzzzz")
; -----------------------------------------------------------------------
; UPPER & LOWER -----------------------------------------------------
; -----------------------------------------------------------------------
Print Lower(helloworld$)
Print Lower$(helloworld$)
Print Upper(helloworld$)
Print Upper$(helloworld$)
; -----------------------------------------------------------------------
; TRIM -----------------------------------------------------
; -----------------------------------------------------------------------
result$= Trim(" "+helloworld$+Chr$(5))
Print result$
result$= Trim(" "+helloworld$+Chr$(5))
Print result$
; -----------------------------------------------------------------------
; LSET RSET -----------------------------------------------------
; -----------------------------------------------------------------------
Print ">>>>>:"+LSet(helloworld$,40) +":<<<<<"
Print ">>>>>:"+LSet$(helloworld$,40)+":<<<<<"
Print ">>>>>:"+RSet(helloworld$,40) +":<<<<<"
Print ">>>>>:"+RSet$(helloworld$,40)+":<<<<<"
; -----------------------------------------------------------------------
; CHR and ASC -----------------------------------------------------
; -----------------------------------------------------------------------
Print Asc("")
Print Asc("A")
Print Asc("ABCDE")
Print Chr(Asc("ABCDE"))
Print Chr$(Asc("ABCDE"))
; -----------------------------------------------------------------------
; LEN -----------------------------------------------------
; -----------------------------------------------------------------------
Print Len(Helloworld)
; -----------------------------------------------------------------------
; HEX + BIN -----------------------------------------------------
; -----------------------------------------------------------------------
Print Hex(255)
Print Hex$(255)
Print Bin(255)
Print Bin$(255)
; -----------------------------------------------------------------------
; STRING -----------------------------------------------------
; -----------------------------------------------------------------------
Print String("A",5)
Print String$("A",5)
Print String(helloworld,5)
Print String$(helloworld,5)
Input
[pbcode]
; PROJECT : Project4
; AUTHOR :
; CREATED : 4/04/2022
; ---------------------------------------------------------------------
;--------------------------------------------------------------------------------
#include "BlitzWrapper.pba"
;--------------------------------------------------------------------------------
Number#= 123.456
Result$ = Str$(Number#)
Print result$
Result$ = Str$(Number#)
Print result$
; -----------------------------------------------------------------------
; LEFT and RIGHT string -------------------------------------------------
; -----------------------------------------------------------------------
helloWorld$="HELLO World"
Print Left$(helloworld$,5)
Print Left$(helloworld$,5)
Print Right$(helloworld$,5)
Print Right$(helloworld$,5)
For lp=1 To Len(HelloWorld$)
Print Mid$(helloworld$,lp)
Next
For lp=1 To Len(HelloWorld$)
Print Mid$(helloworld$,lp,1)
Next
; -----------------------------------------------------------------------
; REPLACE -----------------------------------------------------
; -----------------------------------------------------------------------
Print Replace$(HelloWorld$,"world","<><>")
Print Replace$(HelloWorld$,"world","<><>")
; -----------------------------------------------------------------------
; INSTR -----------------------------------------------------
; -----------------------------------------------------------------------
Print Instring(HelloWorld$,"world")
Print Instring(HelloWorld$,"world",5)
Print Instring(HelloWorld$,"zzzzz")
; -----------------------------------------------------------------------
; UPPER & LOWER -----------------------------------------------------
; -----------------------------------------------------------------------
Print Lower$(helloworld$)
Print Lower$(helloworld$)
Print Upper$(helloworld$)
Print Upper$(helloworld$)
; -----------------------------------------------------------------------
; TRIM -----------------------------------------------------
; -----------------------------------------------------------------------
result$= Trim$(" "+helloworld$+Chr$(5))
Print result$
result$= Trim$(" "+helloworld$+Chr$(5))
Print result$
; -----------------------------------------------------------------------
; LSET RSET -----------------------------------------------------
; -----------------------------------------------------------------------
Print ">>>>>:"+BB_LSet$(helloworld$,40) +":<<<<<"
Print ">>>>>:"+BB_LSet$(helloworld$,40)+":<<<<<"
Print ">>>>>:"+BB_RSet$(helloworld$,40) +":<<<<<"
Print ">>>>>:"+BB_RSet$(helloworld$,40)+":<<<<<"
; -----------------------------------------------------------------------
; CHR and ASC -----------------------------------------------------
; -----------------------------------------------------------------------
Print Asc("")
Print Asc("A")
Print Asc("ABCDE")
Print Chr$(Asc("ABCDE"))
Print Chr$(Asc("ABCDE"))
; -----------------------------------------------------------------------
; LEN -----------------------------------------------------
; -----------------------------------------------------------------------
Print Len(Helloworld$)
; -----------------------------------------------------------------------
; HEX + BIN -----------------------------------------------------
; -----------------------------------------------------------------------
Print Hex$(255)
Print Hex$(255)
Print Bin$(255)
Print Bin$(255)
; -----------------------------------------------------------------------
; STRING -----------------------------------------------------
; -----------------------------------------------------------------------
Print Make$("A",5)
Print Make$("A",5)
Print Make$(helloworld$,5)
Print Make$(helloworld$,5)
;BB_Input()
Sync
waitkey
[/pbcode]
Banks + File Commands
Moving my way through the basic command sets building PlayBASIC wrappers of Blitz BASIC functions. With most blitz commands there's either a or close direct translation, it's only the odd one needs to be wrapped up. But I'm putting them all in functions none the less. So they can tweaked.
Basic File handling
Print CurrentDir$()
ChangeDir "\_TEMP_FOLDER\"
Path$=CurrentDir$()
Print Path$
NewPath$=Path$+"My_NEW_DIR"
CreateDir NewPath$
Print " Folder Status:" +FileType(NewPath$)
If FileType(NewPath$)=2
DeleteDir NewPath$
EndIf
Print "Folder Status After Delete:" +FileType(NewPath$)
Print ""
SrcFile$=Path$+"DoesThisFileExist.txt"
DestFile$=Path$+"DoesThisFileExist_COPY.txt"
Print " SrcFile Status:" +FileType(SrcFile$)
Print "DestFile Status:" +FileType(destFile$)
CopyFile SrcFile$,DestFile$
Print " SrcFile Status:" +FileType(SrcFile$)
Print "DestFile Status:" +FileType(destFile$)
DeleteFile DestFile$
Gosub Test1
Test_ReadString()
Test_ReadLine()
Test_ReadWriteBytes()
Input
End
.Test1
; Changing part of a file using OpenFile, SeekFile and WriteInt
; Open/create a file to Write
fileout = WriteFile("mydata.dat")
; Write the information to the file
WriteInt( fileout, 1 )
WriteInt( fileout, 2 )
WriteInt( fileout, 3 )
WriteInt( fileout, 4 )
WriteInt( fileout, 5 )
WriteFloat( Fileout, 123.456)
; Close the file
CloseFile( fileout )
DisplayFile( "The file as originally written", "mydata.dat" )
; Open the file and change the Third Integer
file = OpenFile("mydata.dat")
SeekFile( file, 8 ) ; Move to the third integer in the file
WriteInt( file, 9999 ) ; Replace the original value with 9999
CloseFile( file )
DisplayFile( "The file after being midified", "mydata.dat" )
DeleteFile "mydata.dat"
; **** Function Definitions follow ****
Return
; Read the file and print it
Function DisplayFile( Tittle$, Filename$ )
Print tittle$
filein = ReadFile( Filename$ )
While Not Eof( filein )
Number = ReadInt( filein )
Print Number
Wend
CloseFile( filein )
Print ""
End Function
Function Test_ReadString()
; Reading and writing a file using ReadString$ and WriteString functions
; Initialise some variables for the example
String1$ = "A short string"
String2$ = "A longer string since these are variables lengths"
String3$ = "This is string3 "
String4$ = "joined to string4"
; Open a file to write to
fileout = WriteFile("mydata.dat")
; Write the information to the file
WriteString( fileout, String1 )
WriteString( fileout, String2 )
WriteString( fileout, String3 + String4)
WriteString( fileout, "Just to show you don't have to use variables" )
; Close the file
CloseFile( fileout )
; Open the file to Read
filein = ReadFile("mydata.dat")
Read1$ = ReadString$( filein )
Read2$ = ReadString$( filein )
Read3$ = ReadString$( filein )
Read4$ = ReadString$( filein )
; Close the file once reading is finished
CloseFile( filein )
Print "String Variables Read From File - mydata.dat "
Print ""
Print Read1
Print Read2
Print Read3
Print Read4
End Function
Function test_ReadLine()
; Reading and writing a file using ReadLine$ and WriteLine functions
; Initialise some variables for the example
String1$ = "Line 1 is short"
String2$ = "Line 2 is a longer line but they can be much longer"
String3$ = "Line 3 is made up "
String4$ = "of two parts joined together."
; Open a file to write to
fileout = WriteFile("mydata.txt")
; Write the information to the file
WriteLine( fileout, String1 )
WriteLine( fileout, String2 )
WriteLine( fileout, String3 + String4)
WriteLine( fileout, "Just to show you don't have to use variables" )
; Close the file
CloseFile( fileout )
; Open the file to Read
filein = ReadFile("mydata.txt")
Read1$ = ReadLine( filein )
Read2$ = ReadLine$( filein )
Read3$ = ReadLine$( filein )
Read4$ = ReadLine$( filein )
; Close the file once reading is finished
CloseFile( filein )
DeleteFile "mydata.txt"
Print "Lines of text read from file - mydata.txt "
Print ""
Print Read1
Print Read2
Print Read3
Print Read4
End Function
Function test_ReadWriteBytes()
; Read/WriteBytes Commands Example
; Create a 50 byte memory bank
bnkTest=CreateBank(500)
; Let's fill the bank with random data
For t = 1 To 50
ThisByte=Rnd(255)
PokeByte bnkTest,t,ThisByte
s$=s$+Str$(ThisByte)+","
Next
Print s$
s$=""
; Open a file to write to
fileBank=WriteFile("test.bnk")
; Write the bank to the file
WriteBytes bnkTest,fileBank,0,50
; Close it
CloseFile fileBank
; Free the bank
FreeBank bnkTest
; Make a new one
bnkTest=CreateBank(500)
; Open the file to read from
fileBank=OpenFile("test.bnk")
; Write the bank to the file
ReadBytes bnkTest,fileBank,0,50
; Close it
CloseFile fileBank
; Write back the results!
For t = 1 To 50
s$=s$+Str$(PeekByte (bnkTest,t) )+","
Next
Print s$
End Function
[pbcode]
;--------------------------------------------------------------------------------
#include "BlitzWrapper.pba"
;--------------------------------------------------------------------------------
Print BB_CurrentDir$()
BB_ChangeDir "_TEMP_FOLDER\"
Path$=BB_CurrentDir$()
Print Path$
NewPath$=Path$+"My_NEW_DIR"
BB_CreateDir NewPath$
Print " Folder Status:" +str$(BB_FileType(NewPath$))
If BB_FileType(NewPath$)=2
BB_DeleteDir NewPath$
EndIf
Print "Folder Status After Delete:" +str$(BB_FileType(NewPath$))
Print ""
SrcFile$=Path$+"DoesThisFileExist.txt"
DestFile$=Path$+"DoesThisFileExist_COPY.txt"
Print " SrcFile Status:" +str$(BB_FileType(SrcFile$))
Print "DestFile Status:" +str$(BB_FileType(destFile$))
BB_CopyFile SrcFile$,DestFile$
Print " SrcFile Status:" +str$(BB_FileType(SrcFile$))
Print "DestFile Status:" +str$(BB_FileType(destFile$))
BB_DeleteFile DestFile$
Gosub Test1
Test_ReadString()
Test_ReadLine()
Test_ReadWriteBytes()
;BB_Input()
sync
waitkey
End
Test1:
; Changing part of a file using OpenFile, SeekFile and WriteInt
; Open/create a file to Write
fileout = BB_WriteFile("mydata.dat")
; Write the information to the file
BB_WriteInt( fileout, 1 )
BB_WriteInt( fileout, 2 )
BB_WriteInt( fileout, 3 )
BB_WriteInt( fileout, 4 )
BB_WriteInt( fileout, 5 )
BB_WriteFloat( Fileout, 123.456)
; Close the file
BB_CloseFile( fileout )
DisplayFile( "The file as originally written", "mydata.dat" )
; Open the file and change the Third Integer
file = BB_OpenFile("mydata.dat")
BB_SeekFile( file, 8 ) ; Move to the third integer in the file
BB_WriteInt( file, 9999 ) ; Replace the original value with 9999
BB_CloseFile( file )
DisplayFile( "The file after being midified", "mydata.dat" )
BB_DeleteFile "mydata.dat"
; **** Function Definitions follow ****
Return
; Read the file and print it
Function DisplayFile( Tittle$, Filename$ )
Print tittle$
filein = BB_ReadFile( Filename$ )
While Not BB_Eof( filein )
Number = BB_ReadInt( filein )
Print Number
EndWhile
BB_CloseFile( filein )
Print ""
EndFunction 0
Function Test_ReadString()
; Reading and writing a file using ReadString$ and WriteString functions
; Initialise some variables for the example
String1$ = "A short string"
String2$ = "A longer string since these are variables lengths"
String3$ = "This is string3 "
String4$ = "joined to string4"
; Open a file to write to
fileout = BB_WriteFile("mydata.dat")
; Write the information to the file
BB_WriteString( fileout, String1$ )
BB_WriteString( fileout, String2$ )
BB_WriteString( fileout, String3$ + String4$)
BB_WriteString( fileout, "Just to show you don't have to use variables" )
; Close the file
BB_CloseFile( fileout )
; Open the file to Read
filein = BB_ReadFile("mydata.dat")
Read1$ = BB_ReadString$( filein )
Read2$ = BB_ReadString$( filein )
Read3$ = BB_ReadString$( filein )
Read4$ = BB_ReadString$( filein )
; Close the file once reading is finished
BB_CloseFile( filein )
Print "String Variables Read From File - mydata.dat "
Print ""
Print Read1$
Print Read2$
Print Read3$
Print Read4$
EndFunction 0
Function test_ReadLine()
; Reading and writing a file using ReadLine$ and WriteLine functions
; Initialise some variables for the example
String1$ = "Line 1 is short"
String2$ = "Line 2 is a longer line but they can be much longer"
String3$ = "Line 3 is made up "
String4$ = "of two parts joined together."
; Open a file to write to
fileout = BB_WriteFile("mydata.txt")
; Write the information to the file
BB_WriteLine( fileout, String1$ )
BB_WriteLine( fileout, String2$ )
BB_WriteLine( fileout, String3$ + String4$)
BB_WriteLine( fileout, "Just to show you don't have to use variables" )
; Close the file
BB_CloseFile( fileout )
; Open the file to Read
filein = BB_ReadFile("mydata.txt")
Read1$ = BB_ReadLine$( filein )
Read2$ = BB_ReadLine$( filein )
Read3$ = BB_ReadLine$( filein )
Read4$ = BB_ReadLine$( filein )
; Close the file once reading is finished
BB_CloseFile( filein )
BB_DeleteFile "mydata.txt"
Print "Lines of text read from file - mydata.txt "
Print ""
Print Read1$
Print Read2$
Print Read3$
Print Read4$
EndFunction 0
Function test_ReadWriteBytes()
; Read/WriteBytes Commands Example
; Create a 50 byte memory bank
bnkTest=BB_CreateBank(500)
; Let's fill the bank with random data
For t = 1 To 50
ThisByte=BB_Rnd(255)
BB_PokeByte bnkTest,t,ThisByte
s$=s$+Str$(ThisByte)+","
Next
Print s$
s$=""
; Open a file to write to
fileBank=BB_WriteFile("test.bnk")
; Write the bank to the file
BB_WriteBytes bnkTest,fileBank,0,50
; Close it
BB_CloseFile fileBank
; Free the bank
BB_FreeBank bnkTest
; Make a new one
bnkTest=BB_CreateBank(500)
; Open the file to read from
fileBank=BB_OpenFile("test.bnk")
; Write the bank to the file
BB_ReadBytes bnkTest,fileBank,0,50
; Close it
BB_CloseFile fileBank
; Write back the results!
For t = 1 To 50
s$=s$+Str$(BB_PeekByte (bnkTest,t) )+","
Next
Print s$
EndFunction 0
[/pbcode]
BANK COMMANDS / FUNCTIONS
; Bank Commands Example
; ---------------------
bnkTest=CreateBank(12)
PokeByte bnkTest,0,Rand(255)
PokeShort bnkTest,1,Rand(65535)
PokeInt bnkTest,3,Rand(-2147483648,2147483647)
PokeFloat bnkTest,7,0.5
Print PeekByte(bnkTest,0)
Print PeekShort(bnkTest,1)
Print PeekInt(bnkTest,3)
Print PeekFloat(bnkTest,7)
FreeBank bnkTest
[pbcode]
;--------------------------------------------------------------------------------
#include "BlitzWrapper.pba"
;--------------------------------------------------------------------------------
; Bank Commands Example
; ---------------------
bnkTest=BB_CreateBank(12)
BB_PokeByte bnkTest,0,BB_Rand(255)
BB_PokeShort bnkTest,1,BB_Rand(65535)
BB_PokeInt bnkTest,3,BB_Rand(-2147483648,2147483647)
BB_PokeFloat bnkTest,7,0.5
Print BB_PeekByte(bnkTest,0)
Print BB_PeekShort(bnkTest,1)
Print BB_PeekInt(bnkTest,3)
Print BB_PeekFloat#(bnkTest,7)
BB_FreeBank bnkTest
[/pbcode]
Image Commands
Tonight i've been picking through the image command set trying to improve our wrappers emulation of Blitz commands. Bellow is the progress so far, where the code converts and executes in PlayBASIC out of the box. There's a notable difference in the scale image function, but apart from that we're hitting approaching something of a major milestone with the tool..
This code chopped together from various blitz help file fragments into a bigger demo, I guess the newest additions to the wrapper are support for Blitzs frames concept in its images. So each image can include a list of sub-images a but like an atlus. Although I believe the surfaces are seperate, which is what i've done in the wrapper. It seems to work just the same.. so that's cool :)
; Initiate Graphics Mode
;Graphics 640,480,16
Graphics 640,480,32,2
Global BallImage$="bubble_64x64.bmp"
test_ScaleIMage(BallImage$)
Test_TileImage()
Test_GrabAndCopyIMage()
Text_ImageHandles()
;-------------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------------
; GrabImage example
;-------------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------------
Function Test_GrabAndCopyIMage()
Cls
; We'll be drawing right to the front buffer
SetBuffer BackBuffer()
; You must create an empty image to grab from first
gfxGrab=CreateImage(100,100)
; Draw random rectangles on the screen until the
; user presses ESC
For lp=0 To 1000
; random color
Color Rnd(255),Rnd(255),Rnd(255)
; super random rectangles
Rect Rnd(640),Rnd(480),Rnd(100),Rnd(100),Rnd(1)
;Delay 50
Next
; Now, grab an image, starting at 100,100 and put it in gfxGrab
GrabImage gfxGrab,100,100
While Not KeyHit(57)
; Clear screen and show user the grabbed image
Cls
Text 0,0, "Here is your grabbed image! Press a mouse key ..."
DrawImage gfxgrab,MouseX(),MouseY()
; Duplicate the gfxOld image to a new handle variable
gfxNew=CopyImage(gfxGrab)
DrawImage gfxgrab,MouseX()+250,MouseY()
FreeImage GfxNEw
Flip
Wend
FlushKeys
End Function
;--------------------------------------------------------------------------------------------
; MidHandle/ImageXHandle()/ImageYHandle()/AutoMidHandle
;--------------------------------------------------------------------------------------------
Function Text_ImageHandles()
; Load the image - you may need to change the location of the file
gfxBall=LoadImage (BallImage$)
; Until the user presses ESC key ...
While Not KeyHit(57)
Cls
Text 0,0,"Default Image Handle for gfxBall... Press ESC ..."
Text 0,14,"X handle-" + ImageXHandle(gfxBall) ; Print the location of the image handle x location
Text 0,28,"Y handle-" + ImageYHandle(gfxBall) ; Print the location of the image handle y location
DrawImage gfxBall,MouseX(),MouseY(),0 ; draw the image at 200,200
Flip
Wend
; Clear the screen
Cls
; Set the ball's handle to the center of the image
MidHandle gfxBall
; Until the user presses ESC key ... show the new information
While Not KeyHit(57)
Cls
Text 0,0,"New Image Handle for gfxBall... Press ESC ..."
Text 0,14,"X handle-" + ImageXHandle(gfxBall)
Text 0,28,"Y handle-" + ImageYHandle(gfxBall)
DrawImage gfxBall,MouseX(),MouseY(),0 ; draw the image at 200,200
Flip
Wend
FreeImage gfxBall
; Makes all images load up with their handles in the center of the image
AutoMidHandle True
Cls
; Load the image again
gfxBall=LoadImage (BallImage$)
; Until the user presses ESC key ... show the new information
While Not KeyHit(57)
Cls
Text 0,0,"Automatic image handle of gfxBall... Press ESC ..."
Text 0,14,"X handle-" + ImageXHandle(gfxBall)
Text 0,28,"Y handle-" + ImageYHandle(gfxBall)
DrawImage gfxBall,MouseX(),MouseY(),0 ; draw the image at 200,200
Flip
Wend
FlushKeys
End Function
Function Test_TileImage()
; CreateImage/TileImage/ImageBuffer example
; Create a blank image that is 32 pixels wide and 32 high with 10 frames of 32x32
gfxStarfield=CreateImage(32,32,10)
; loop through each frame of the graphic we just made
For t = 0 To 9
; Set the drawing buffer to the graphic frame so we can write on it
SetBuffer ImageBuffer(gfxStarfield,t)
; put 50 stars in the frame at random locations
For y = 1 To 50
Plot Rnd(32),Rnd(32)
Next
Next
; Double buffer mode for smooth screen drawing
SetBuffer BackBuffer()
;ClsColor 255,0,0
; Loop until ESC is pressed
While Not KeyHit(57)
ThisFrame=MilliSecs()
; slower screen updates
If Abs(ThisFrame-LastFrame)>250
; tmrScreen+300
LastFrame =ThisFrame
Cls ; clear the screen
; Tile the screen with a random frame from our new graphic starting at
; x=0 and y=0 location.
TileImage gfxStarfield,0,0,Rnd(9)
Flip ; Flip the screen into view
tmrScreen=MilliSecs() ; reset the time
;Else
; Delay 10
End If
Wend
FlushKeys
End Function
Function test_ScaleIMage(File$)
scale=4
For ylp=0 To scale
For Xlp=-scale To scale
If Xlp<>0 And Ylp<>0
Cls
; Load an image to tile (your location might vary)
gfxBall=LoadImage(File$)
DrawImage gfxball,300,0
; Scale it randomly from 50% to 150% both x and y
ScaleImage gfxBall,xlp,ylp
; Wait for ESC to hit
DrawImage gfxball,300,200
Flip
Delay 250
FreeImage gfxball
End If
Next
Next
End Function
[pbcode]
; PROJECT : Project1
; AUTHOR :
; CREATED : 9/04/2022
; ---------------------------------------------------------------------
;--------------------------------------------------------------------------------
#include "BlitzWrapper.pba"
;--------------------------------------------------------------------------------
; Initiate Graphics Mode
;Graphics 640,480,16
BB_Graphics 640,480,32,2
Global BallImage$="bubble_64x64.bmp"
test_ScaleIMage(BallImage$)
Test_TileImage()
Test_GrabAndCopyIMage()
Text_ImageHandles()
;-------------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------------
; GrabImage example
;-------------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------------
Function Test_GrabAndCopyIMage()
BB_Cls()
; We'll be drawing right to the front buffer
BB_SetBuffer BB_BackBuffer()
; You must create an empty image to grab from first
gfxGrab=BB_CreateImage(100,100)
; Draw random rectangles on the screen until the
; user presses ESC
For lp=0 To 1000
; random color
BB_Color BB_Rnd(255),BB_Rnd(255),BB_Rnd(255)
; super random rectangles
BB_Rect BB_Rnd(640),BB_Rnd(480),BB_Rnd(100),BB_Rnd(100),BB_Rnd(1)
;Delay 50
Next
; Now, grab an image, starting at 100,100 and put it in gfxGrab
BB_GrabImage gfxGrab,100,100
While Not BB_KeyHit(57)
; Clear screen and show user the grabbed image
BB_Cls()
Text 0,0, "Here is your grabbed image! Press a mouse key ..."
BB_DrawImage gfxgrab,MouseX(),MouseY()
; Duplicate the gfxOld image to a new handle variable
gfxNew=BB_CopyImage(gfxGrab)
BB_DrawImage gfxgrab,MouseX()+250,MouseY()
BB_FreeImage GfxNEw
Sync
EndWhile
BB_FlushKeys()
EndFunction 0
;--------------------------------------------------------------------------------------------
; MidHandle/ImageXHandle()/ImageYHandle()/AutoMidHandle
;--------------------------------------------------------------------------------------------
Function Text_ImageHandles()
; Load the image - you may need to change the location of the file
gfxBall=BB_LoadImage (BallImage$)
; Until the user presses ESC key ...
While Not BB_KeyHit(57)
BB_Cls()
Text 0,0,"Default Image Handle for gfxBall... Press ESC ..."
Text 0,14,"X handle-" + str$(BB_ImageXHandle(gfxBall)) ; Print the location of the image handle x location
Text 0,28,"Y handle-" + str$(BB_ImageYHandle(gfxBall)) ; Print the location of the image handle y location
BB_DrawImage gfxBall,MouseX(),MouseY(),0 ; draw the image at 200,200
Sync
EndWhile
; Clear the screen
BB_Cls()
; Set the ball's handle to the center of the image
BB_MidHandle gfxBall
; Until the user presses ESC key ... show the new information
While Not BB_KeyHit(57)
BB_Cls()
Text 0,0,"New Image Handle for gfxBall... Press ESC ..."
Text 0,14,"X handle-" + str$(BB_ImageXHandle(gfxBall))
Text 0,28,"Y handle-" + str$(BB_ImageYHandle(gfxBall))
BB_DrawImage gfxBall,MouseX(),MouseY(),0 ; draw the image at 200,200
Sync
EndWhile
BB_FreeImage gfxBall
; Makes all images load up with their handles in the center of the image
BB_AutoMidHandle True
BB_Cls()
; Load the image again
gfxBall=BB_LoadImage (BallImage$)
; Until the user presses ESC key ... show the new information
While Not BB_KeyHit(57)
BB_Cls()
Text 0,0,"Automatic image handle of gfxBall... Press ESC ..."
Text 0,14,"X handle-" + str$(BB_ImageXHandle(gfxBall))
Text 0,28,"Y handle-" + str$(BB_ImageYHandle(gfxBall))
BB_DrawImage gfxBall,MouseX(),MouseY(),0 ; draw the image at 200,200
Sync
EndWhile
BB_FlushKeys()
EndFunction 0
Function Test_TileImage()
; CreateImage/TileImage/ImageBuffer example
; Create a blank image that is 32 pixels wide and 32 high with 10 frames of 32x32
gfxStarfield=BB_CreateImage(32,32,10)
; loop through each frame of the graphic we just made
For t = 0 To 9
; Set the drawing buffer to the graphic frame so we can write on it
BB_SetBuffer BB_ImageBuffer(gfxStarfield,t)
; put 50 stars in the frame at random locations
For y = 1 To 50
BB_Plot BB_Rnd(32),BB_Rnd(32)
Next
Next
; Double buffer mode for smooth screen drawing
BB_SetBuffer BB_BackBuffer()
;ClsColor 255,0,0
; Loop until ESC is pressed
While Not BB_KeyHit(57)
ThisFrame=Timer()
; slower screen updates
If Abs(ThisFrame-LastFrame)>250
; tmrScreen+300
LastFrame =ThisFrame
BB_Cls() ; clear the screen
; Tile the screen with a random frame from our new graphic starting at
; x=0 and y=0 location.
BB_TileImage gfxStarfield,0,0,BB_Rnd(9)
Sync ; Flip the screen into view
tmrScreen=Timer() ; reset the time
;Else
; Delay 10
EndIf
EndWhile
BB_FlushKeys()
EndFunction 0
Function test_ScaleIMage(File$)
scale=4
For ylp=0 To scale
For Xlp=-scale To scale
If Xlp<>0 And Ylp<>0
BB_Cls()
; Load an image to tile (your location might vary)
gfxBall=BB_LoadImage(File$)
BB_DrawImage gfxball,300,0
; Scale it randomly from 50% to 150% both x and y
BB_ScaleImage gfxBall,xlp,ylp
; Wait for ESC to hit
BB_DrawImage gfxball,300,200
Sync
BB_Delay 250
BB_FreeImage gfxball
EndIf
Next
Next
EndFunction 0
[/pbcode]
BlitzBASIC 2 PlayBASIC Conversion Tool WIP - Episode 09 - Working On Command Sets This is the 9th look at writing a tool that can handle most syntax level conversions from Blitz BASIC into PlayBASIC compatible syntax.
In this episode we've entered the grind phase of this applications development, which in this project is getting as many of the common Blitz commands working in our wrapper. So far i've covered the STRINGS / MATH / FILE / BANKS and most of IMAGES the more exotic stuff will be left until later if there's need.
Check the development blog for more interesting examples
Video Script:
hi welcome back here we are with episode
9 of this long conversation about
building a translator from blitz basic
to play basic
uh the last week
i've really been doing
the ugly kind of side of this this thing
here it's kind of fun to do to do the
big things make things that make big
obvious changes but lately it's just
been small things
what i've been doing is
building up some simple example code
focusing on commands within the string
functions the math functions
the bank functions the file functions
image functions and graphics
now
whatever i can get done the next week or
so that will pretty much be it for the
for the first revision here we're
looking at one called graphics it sets
up a graphics mode calls a few different
tests
this one's
mostly just getting things about the
screen
doing a viewport test
they've got some basic drawing
primitives things
um which i haven't noticed one
one difference we'll have to fix
the last one there is about getting
colors
exit that
i'll grab that code
here's our translated code
uh the include the type is is the
wrapper
it's the blitz um well it's our
emulation of blitz function so anything
with bb in front of it
is a function written in playbasic to
to
to do that same behavior
let's write
f5
that's correct
hit space
that's correct as well
this one's not actually
see where that circle is that oval
it's in the wrong position it should be
pretty much the same down here so
how it treats its uh circle coordinates
is different than the more what i expect
but the rest of it's all working okay
here i made some posts about we've done
string function we haven't done them all
i think
sorry i think we've done pretty much all
the ones we could possibly do that makes
sense
bank and file commands
same thing there got some test code
there that does those things
uh
image commands
so what we'll do is we'll just select
the image
you must stick the gui frame on this
thing as well
so you can just kind of run it and do
translations and dump them out this
one's a bit more elaborate this this
demo um
i wouldn't get too excited again
you know it's doing
a fair amount of stuff you'll definitely
be able to
trip the conversion up in your real
world code so again the new the
translated code has a point to the
wrapper
eventually we'll have just
that will be
uh probably an s-leave or something over
something like that or
and we've got a ball which is hard code
location there so for these demos here
to use let's run it so look
okay
this is doing scale image this does have
a difference in it too
so
us using the animation image which turns
out that in blitz you can have images
that have
frames attached to them as well
so i had to emulate that
um
i think
it's doing it correctly i don't really
know
i'm pretty sure it is
uh hit space the next one
uh we're doing a copy image clone image
of the same thing and we'll draw some
image to a rectangle and we'll grab the
image so all that's working
as example
this one is the handles of the images
that's the the default which is the top
left
space will center it
and the last one is we're creating a new
image with it with the library
automatically centering the handle
that's the end of that demo
um
i won't boy with
every little nuance about what's
happened a bunch of the like the
converter has changed
somewhat picked up some more situations
that uh that weren't
being supported
originally
most notably the changes have been in
the wrapper
the main function here is nothing in it
it's this blitz wrapper
over here that does
where i've been putting all the code so
i can just include this into other
projects
and you'll notice the convention there
so we've got
all the bb commands our
have our bb underscore prefix
followed by the command name and the
parameters
um app title which is just title screen
and pb flip is
remapped as sync
now some of these
i think do pretty much the same thing
some probably don't quite do the same
thing and that's going to be the case
moving forward between everything a good
example is the circle command being
different actually
it's not even called that what's it
called
oval
oh there it is
yeah so so we're mapping this as an
ellipse
but we're going to need to
adjust its position here
to get pretty much
much the same
and if you compare the pixel outputs
they would be different as well that's
going to be one of the things that will
be different so
if you have if your program is very
particular about
uh using graphics functions that draw
that light
certain pixels that's dependent upon how
blitz feels
then that might be an issue for you as
well
can't do much a bit much about that
without actually trying to replicate
exactly how
those routines work
um i mean if you're up to it great have
a guide but uh
but that's kind of beyond the scope of
what i'm sort of interested in doing
i will get the ellipse one to match up
pretty well but uh
it will probably light pixels
slightly different
same as the line function slayers all
those functions if they have any if
there's any ambiguity in them
you'll find them
as you can see most most of
most of the functions here are wrapped
pretty much one-to-one
um there's the odd accept exception
where we've got image buffers and things
like that happening
um
and our handle system there is
difference
in principle what we're doing to emulate
blitz's dynamic sort of application
stuff
where
all this kind of global handles concept
is we're just using the new functions to
create
images if we need images and
any other resource which we do the same
thing
copy image is just
two functions
image height you know
there's there are some differences
though i've got this thing about
drawing
drawing block and
drawing image which i didn't quite get
i'm not quite sure
why we need two of them
um
but we seem to need those this is
emulating
so we can have images that are centered
around the handle
for each each particular image or we can
have a frame within that image so
if you select a frame that's bigger than
zero
it'll come from the frame set that's
been set up when the image was created
i just thought of another commander
another command that i haven't
implemented which is the load anim
something i remember seeing that in the
command listing the other day
i think it just loads uh
an image as a tile sheet
to these frames
so
why sorry i'm pretty sure that's what it
does anyway
so in pv world
we're getting you know we're just
getting image indexes back rather than
these global handles
if we load this animation
it would
load it to an image and
that would be frames underneath that
parent that parent animation that parent
image
which is kind of what i was talking
about doing with with pb a little while
ago but
my v i guess my take on that would be
that you would
have a
parental and child relationship between
certain images so you could create a
second image
that doesn't have its own data
is just uv mapped from the parent so
you can load in an atlas
of animation you know animation frames
or whatever it's going to be
and then
still use image indexes but
set the indexes to wherever
you want to find them from the parent so
uh
yeah
that way that fits in really well with
with how gpus like to work and it will
work within software rendering as well
so
if you kind of can wrap your head around
how that would be implemented and
function a bit like the sprite well
sorry exactly like the sprite uv
commands in pv already if you ever use
them
so you can
specifically tell it you want to draw a
portion of an image but not the whole
thing
the case of the image system when you
set up a
set up
a parent child relationship between
your um your secondary image and like
the frame from that parent image
uh for all intents and purposes pbe will
tell you
that
the image width is whatever your the
frame width is and
it would treat it like it was uh
a separate image altogether
we sort of already have this actually
when when you tr when you build a map
that's kind of what you're doing anyway
that's what with maps you sort of you've
got this concept where you've got the
the blo the big tile map and it's
imported it's laid out in a fashion it's
just easy to index pretty much
and then you can grab
and that format depends on the kind of
driver you run in the background in pv
effects it's an atlas with uv mapping
and with
different versions of pb
to date
pivot classic we'll call it i guess the
164 165 all those versions
they either have blender based or they
have software rendering
and
the buff is stored slightly differently
depending on which kind of method you're
rendering
this is the state of the wrapper and
the
some things are just empty they're not
they don't do anything so
calling them is and expecting them to
give a great result is not going to be
not going to be that
beneficial for you
uh one of the things that the converter
does do now it comes to mind
i'll just run that again we'll be on
this graphics functions one here
alright
something that we couldn't do beforehand
and i've added a bit more support for
but
don't get too excited
you notice in this text
statement here we've got a text drawn at
uh
x03 and then y 30 and then
with a bit of a string and originally it
didn't have the string here
it just had
width plus graphics width which is a way
you can do
you can append
numeric data with strings in blitz
now we don't support that um
it's not a bad idea i don't actually
mind it
it's
a bit less work than this but
um
you know i mean having a
concatenation sort of character might be
a way to go
and when
that would mean that anytime it saw that
saw an operation between a string an
integer or maybe a float or even a
vector in the in the future
it would do an automatic
format of that
so you can kind of shortcut this but but
the converter at the moment
um previously it didn't know what to do
so this is an internal blitz function
because i've got some extra information
in the keyword file now about what what
this function returns
it's it's able to pick up
this is a function call that returns an
integer so i i should wrap this around
here so we can we get a bit more um
a bit more control over
this kind of wrapping of the string
functions around these to sort of
emulate what blitz is doing
you'll do simple expressions like this
but it won't do really complicated
expressions so don't get too excited
it would have to be type aware it's not
by type aware i mean you would have to
know the types of parameters being
passed into all the functions and what
the functions return etc
what the return result what the type of
some
operation is going to be
just in case it's used in a string
function like that
it's too much too much work and this
generally gets to get you most of the
way there anyway
that would get you all the way there um
depending on how we feel about this in
the future we'll see how we go
i do want to do a converter to
from dark basic as well
adobe classic would be really quite
straightforward because it has no types
no
very simple 2d support but we couldn't
do the 3d support that would be the
caveat there
for my own personal products that would
be fine because i wrote mostly 2d games
in blitz rather than 3d stuff
sorry in
in dark basin
but you could using the same wrapping
concept you could build your own 3d
back end and pretty much run dark basic
code and play basic
it again you wouldn't be able to do it
out of the box but you could get your
old stuff running in that and then it's
not
it's no longer something that it doesn't
exist do i have have a future pathway
we're pretty much at a conclusion
now i just want to picture and get you
know as many of those basic there's
really core commands and blitz
working
the best i possibly can
and
that will give most people i'll give my
own products the most
chance of compiling and running even
though there might might still be some
work that they needed to be done but
most of the big things will be sold for
us
um
there's still work to do but we're
running out of time want
i want to get the layers
section of this done so i can
put a framed on this thing get it up as
a tool and then
worry about doing that
worry about the next revision at some
other point
but for the time being it should be more
than capable of getting people
interested
that'll have to do for now thanks for
watching and i'll see you next time bye
[plink]Script On PasteBin (https://pastebin.com/YSrrjDTg)[/plink]
Mod operators
While finishing up the IMAGE commands I ran into the missing MOD operator. The trouble is in Blitz MOD is an operator and in PlayBASIC currently MOD is a function. This means we have to remap the expression around the operator. If we were building a transpiler this would have been easier as we'd call the expression solver over each expression and dump out our equivalent; but we can't do that here so the translator has to guess the terms and remap accordingly.
This is about as good as I can get it; glad I added support for it as it uncovered another issue dynamic variable declarations between operators that the parser could miss. So this is more complete now.
;print frames+frames+frames
Print 10 Mod 4
Print 5+10 Mod 4
Print 10 Mod Test%()
Print 10 Mod Test%()+100
Print (10 Mod Test%())+100
For lp=0 To 5
Print (lp+1) Mod 4
Next
frames=4
frmSparks= ( frmSparks + 1 ) Mod Frames
frmSparks= ( frmSparks + 1 ) Mod Frames ; increment the frame
Print "Sparks:"+frmSparks
result= test() Mod 40
Print result
Dim MyArray(10)
MyArray(5) = 1001
MyArray(10)=10
result= MyArray(5) Mod 10
result= MyArray(5) Mod frames
result= MyArray(5) Mod MyArray(10)
Print result
Print "-------------------------float array"
Dim MyArray2#(10)
MyArray2#(5) = 1001
MyArray2#(10)=10
result= MyArray2#(5) Mod 10
result= MyArray2#(5) Mod frames
result= MyArray2#(5) Mod MyArray2#(10)
Print result
Print "-------------------------Command Set Functions"
Test1=Test2
Test1= Test2
Test1= Test2
Test10 =Testb10 Shl 5
Test11= Testb11 Shl 6
Test12= Testb12 And $00fff
Test13= Testb13 Or $00fff
Test14= Testb14 Xor $00fff
result =fTestb10# Shl 5
result =fTestb11# Shl 6
result =fTestb12# And $00fff
result =fTestb13# Or $00fff
result =fTestb14# Xor $00fff
Value =124
result= Value Mod MouseX()
result= Value Mod MouseX()
result=Value Mod MouseX()
result=MouseX() Mod Frames
result= MouseX() Mod Frames
result=MouseX() Mod MouseX()
result= MouseX() Mod MouseX()
Print result
Input
Function Test%()
Return 4
End Function
[pbcode]
;--------------------------------------------------------------------------------
#include "BlitzWrapper.pba"
;--------------------------------------------------------------------------------
;print frames+frames+frames
Print MOD(10 , 4)
Print 5+MOD(10 , 4)
Print MOD(10 , Test())
Print MOD(10 , Test())+100
Print (MOD(10 , Test()))+100
For lp=0 To 5
Print MOD((lp+1) , 4)
Next
frames=4
frmSparks= MOD(( frmSparks + 1 ) , Frames)
frmSparks= MOD(( frmSparks + 1 ) , Frames) ; increment the frame
Print "Sparks:"+str$(frmSparks)
result= MOD(test() , 40)
Print result
Dim MyArray(10)
MyArray(5) = 1001
MyArray(10)=10
result= MOD(MyArray(5) , 10)
result= MOD(MyArray(5) , frames)
result= MOD(MyArray(5) , MyArray(10))
Print result
Print "-------------------------float array"
Dim MyArray2#(10)
MyArray2#(5) = 1001
MyArray2#(10)=10
result= MOD(MyArray2#(5) , 10)
result= MOD(MyArray2#(5) , frames)
result= MOD(MyArray2#(5) , MyArray2#(10))
Print result
Print "-------------------------Command Set Functions"
Test1=Test2
Test1= Test2
Test1= Test2
Test10 =Testb10 << 5
Test11= Testb11 << 6
Test12= Testb12 And $00fff
Test13= Testb13 Or $00fff
Test14= Testb14 Xor $00fff
result =fTestb10# << 5
result =fTestb11# << 6
result =fTestb12# And $00fff
result =fTestb13# Or $00fff
result =fTestb14# Xor $00fff
Value =124
result= MOD(Value , MouseX())
result= MOD(Value , MouseX())
result=MOD(Value , MouseX())
result=MOD(MouseX() , Frames)
result= MOD(MouseX() , Frames)
result=MOD(MouseX() , MouseX())
result= MOD(MouseX() , MouseX())
Print result
BB_Input()
Function Test()
ExitFUNCTION 4
EndFunction 0
[/pbcode]
Supported Image Functions
Here's a list of the supported Blitz 2D / BlitzBASIC image functions.
- LoadImageAnim
- SaveImage
- imagesOverlap
- imagesCollide
- TileImage
- TileBlock
- DrawImageRect
- DrawBlockRect
and more...
BlitzBASIC 2 PlayBASIC Conversion - Episode 10 - From Syntax Highlighting To IDE This is the 10th look at writing a tool that can handle most syntax level conversions from Blitz BASIC into PlayBASIC compatible syntax.
In this episode we discuss the viability of using building a working PlayBASIC source code edit control from the syntax highlighting code found the Blitz2PlayBASIC translator.
Video Script
hi guys welcome back
i wanted to just show you something
as an offshoot to this conversion
project i've been thinking about the
last couple of weeks
you've seen the highlighting stuff
before
um
why am i showing you this again well
at some point we're going to
replace the ide and replace the phrase
now
as far as i'm concerned
if we want to keep this kind of concept
that uh the play basic is really
is easy for beginners to understand it's
going to have to add
have certain modern traits without going
crazy
so
here i'm just trying to mimic some of
the behaviors in the ide
so we've got the current idea so we've
got hover
ability so we can detect when the mouse
is over something
we just scroll
you might notice that functions now
have an area where
the background
color can be changed so i can detect
when we're inside this block of code
i put a little highlight in the side as
well
and i can do
i've implemented a collapse
hmm interesting isn't it
i've had a few other things too but
really um what i want to get get really
is just that
that after we get this conversion
thing done and i'll have to do the gui
of this probably over the next week i
guess
on the weekend
got stuck up with some other products
last week with the 3d aligned thing
up and running
and we've had server problems the last
10 days so trying to upload things or do
anything on the website it's been just
incredibly frustrating upcoming project
list pretty much is
build a new version of the website
uh
do some sort of lexa and use the lexa
maybe to either build
the back end for an ide
so it can do all the
the tokenization the editing aspect and
we just have a high level
sort of high level functions to do
things like add a character or change
things or or cut and paste a section
from it
that sort of stuff you know add queries
as a bit of a joke i add you can toggle
uh
comments
on and off
and you can do the live refactoring here
there's nothing here that actually
understands of course we'll at the
moment we're looking at the translated
blitz code rather than pb dedicated code
uh any lexa would would handle pb code
just so we we're on the same path
this method is much
it's much easier to implement some of
this stuff than what what the other
the previous ide attempt i had a number
of years ago probably 10 years ago now
and that was spawned you know
out of
a sort of gnawing question i had about
is it would be possible to write a
custom
display and edit in visual basic six and
the answer is yeah it is
but you still have some problems with
them
with this
my goal is that we have
an edit control
that doesn't have a display element to
it
so it does all the document
the library will do the the manhandling
the document you're loading it your text
it'll wax
the document
still a thing as a this similar idea is
what we're doing here is pretty much a
linked list of these cells
and that allows things to be inserted
deleted remapped all kinds of stuff
really
things that just weren't possible with
the way the old one uh worked well
they were possible but they were really
clumsy
uh here it's still still difficult to do
them but but
nowhere near
the same level of
complexity
the things that i i would be interested
in implementing is everything that we
have here so
it would need it would be type aware
at the moment there's no character
editing in this at all
i'm just sort of experimenting with the
display process
so even if the process was just used in
a debugger
so we have the the debugger application
be
written in play basic for example and
the two things communicate the current
running app
and the debugger communicate with each
other via like a local network or
whatever
that would be fantastic so that would
mean we could reuse the same code
and because written in plain basic you
guys can make modifications implement
stuff into it as well
if we're going to try and
you know make it attractive to people
who are
you know beginners to programming or
people who are
in use we want to make sure that
our tool set is comparable to other
other tools
but it isn't that overwhelming that it
will scare people away
and if
unfortunately we look at some of the
the really mature
uh very elaborate um editing solutions
now like ide solutions
they are they are terrifying to people
well i want this thing to work to be
specifically for play basic
and understand the trade to play basic
you know if that means
you know how we
we have to
modify the
alexa in between things and
um so bad
the other part of the conversation is
the same lexing principle i want to use
that in playbasic as well
and that'll open up
i want to get rid of the original pass
one of the compiler which is the
compiler's kind of two phases so there's
past one
which is like i'm skimming through the
code looking for declarations of certain
things like functions namely and labels
and then the second pass is where it
actually starts to build code
that allows you to
um
because past one skims through
and sees all the function names
when it encounters that name
uh
it's some other point like
for hearing there's example there so
i've got
this bb sar function
is used here
but declared down here so the only way
pb can work out
if this exists or not at this time
the only way people can understand this
is is that we uncover the functions
we're using in a pre
in the initial pre-pass and then
as we go through then we
flesh them all out but that just means
that when we get to here we could go yep
this is a function that has this
particular parameter set and returns
this data for us
and that's also why
in this example i've left the return
function here so if you have a return
value you can see what's going here in
terms of the idea an ide
you'd have to keep a second piece of
data
that tags
what
the
well the collapse state of any uh
function on screen which is something
that our current ide doesn't do
and and not as my remake either and even
the
the one danny wrote which is before the
one you you're familiar with
um
that was way back like 2002 or something
2003 or something
maybe 2004 i'm not quite sure
but that was a long time ago
the lexa in in this particular version
you know can be tricked in full and
that's why we have some of the problems
we do have with it
that's why i'm keen to write it
from um
from the same perspective what the
actual compile alexa works
yeah so the two things match we should
get the same behavior between one and
the other if there's a weird bargain
alexa in the ide then that'll that'll
happen in the
compiler as well unfortunately
um
yeah so
just wanted to show that running
and give you a heads up about
what's on my mind concerning that so
pretty much in the next
our next projects pretty much are going
to be
having some sort of website replacement
at least doing the lexa project and then
trying to
do some research on that to see how
viable that is
this this example here i mean on my
laptop it's cloud it'll clock at 200
frames per second rendering a document
with no optimization
and that's what you want yeah i mean
if i run again
um sort of clock
a bit clutchy because we're catching
capturing the whole thing
but
what the way this works at the moment is
it's rendering everything
this entire document's been rendered
every time we would call a refresh
in a real editing environment we
wouldn't do that we would just
if the cursor was on this line here
that's the line will i would be updating
and if we have to display anything over
the top like
like one idea i was having before is
that you could reveal the local
variables for this particular function
or
you know or have any secondary data
that's been picked up during the
it's skimming through the document
like you know the variables or any
constants or whatever belongs to this
but this this code here we can we can
treat that as
as a local thing
um
it's not that difficult to do the the
phrase it does this anyway the lexa does
this already
it runs through and classifies
everything as
the handful of types that are available
and by types i mean
is the is this a
is this bit of text a key a keyword is a
user defined function
is it an array name is it a variable is
it a type name
and that's pretty much the scope of what
you need we still have to store this
data search for it etc
um it's not doing all that every time we
have a refresh here
that's not how the ide would work
or the editor would work
it would
load the document in
uh do do what it's done here compute a
tokenized view of the whole thing
and as we edit it then we can edit it
token by token which is trivial to do
there will be some complexities in it of
course
there was always going to be something
that's awkward to do but
that model is much better and it means
you could you could link
any
any pair or cell or group of these
tokens that you wanted to link together
so
all those features you see in um
in mod 90s with which have collapsible
if statements and for loops and so on
that we could have
you know you could right click and
insert a particular kind of block of
code if you wanted to add a have a
framework inserted for you
i'm not saying it would be the best
thing since last sliced bread
but
it
that's the kind of stuff that's missing
at the moment like auto complete is
missing
um we do have auto complete in
the ide but we we need a more modern
version so if you enter a type name or
you know
have any kind of field reference it can
just prompt you with what fields this
thing has
i'll let you select from them which gets
i get through a lot of typo problems you
know
where you you're rushing through typing
something out and you type the field
name incorrectly or whatever it doesn't
get picked up until you hit compile
all right
that'll do us this is pretty brief
hopefully that gives you something to
chew on get excited about
worse things worse worst case scenario
is that we could have an ide
that's written in playmatic itself and i
love that as a concept i love the idea
that i i can just go here you go here's
the idea source code if you want to go
modify it my point is is that if we
could get more of the the tools that
make up play basic
to be written in pb or at least have a
large percentage of themselves written
in pb
that gives us options that gives not
just me options gives you guys options
to do things and as we change
apis uh we can have something that
runs entirely modern straight out of the
box
you know if you want to have a
completely visual ide then you know
graphical id running on the latest
interface whatever that would be whether
it's you know
the way that the rendering and here
works or the way the document stuff
works is that it it takes care of the
the document in the background and you
just have to render
the it's just a loop really like i'll
show you
sorry
uh and this is the render loop
we've just got a stepping through of
this
um there's a list of lists of tokens
i'm actually grabbing the string every
time we do that i probably shouldn't do
that at all
and then we work out what the color is
just by a select case
obviously you can make most of those
cases you can make into a into a table
so you wouldn't even it wouldn't even
need the select case
something you couldn't because you've
got a bit of logic happening here or
there but you know
it's not the end of the world
this is just the thing to toggle um the
collapse
of the function before
so displaying array names and different
their own palette
types in their own palette
something else whatever
but just fall through if you find end of
line we're going to build logic to
handle what we're doing on the next line
uh it draws
it cleans the next row out and then
starts drawing text over top of it
so it's only drawing rows of that that
we're drawing over
just small optimization but not really
necessary and the last one here is just
the rendering of the draw text
that's the whole loop
now that that could be in anything
yeah
all this really what really matters here
is
is that we have uh
the vertical scroll element and then we
have some sort of uh information about
having the cursor
and um
we render whatever font we want
you know
something to think about
um
something to think about i've been i've
been kind of obsessing over this for the
last probably a month actually i thought
a lot about it and i really think this
is the way to go
because it it means that if we have
all we need is a basic um surface to
render onto
as long as we can render text to that
service and and do some
simple filling in the background
we could port the idea to anything
i mean anything
that's future though
let's focus on my focus on the present
i'll leave that leave that with you
have fun and i'll see you next time bye
BlitzBASIC 2 PlayBASIC Conversion - Episode 11 - Wrapping This Up This is the 11th look at writing a tool that can handle most syntax level conversions from Blitz BASIC into PlayBASIC compatible syntax.
In this episode we take a quick look t the simple (yeah incredibly simple) GUI interface for the final Blitz2PlayBASIC translator.
The tool breaks down into four main options. Load / Delete / Export and View.
LOAD pops a dialog for you to select a Bitz BASIC source code (or text file). Once selected the file is lexed and converted immediately.
REMOVE - Remove the current source from memory. It doesn't delete from disk !
EXPORT - Export will dump the current source as PlayBASIC project folder at the same location as the original code. The translator will name that folder after the loaded source and will append a time stamp. This is to avoid overwriting a previously exported edition of the code. The project will contain the PlayBASIC project file (PBP) the MAIN.PBA (The converted code) and the BlitzWrapper.PBA So you can just load and try and run it from PlayBASIC as normal.
VIEW - Shows a syntax high lighted version of the code. The feature contains a right click menu of secondary view and modification features. Such a Optimize / Hide Remarks / Strip Null Lines for the time being. The menu is contextual; so if you hover over a Function Name and right click it'll pop the Find Function option. THis is really just to let you get some idea of state of the translated code.
SPACE will exit from the VIEW page. UP / DOWN Arrows to scroll up / Down. Page Up / Page Down and HOME are also supported.
QUIT - ENd application :)
Check the development blog for more interesting examples
[ Links: ]
--BlitzBASIC 2 PlayBASIC - WIP Playlist (https://www.youtube.com/playlist?list=PL_dvm0gvzzIVBpPBEP8wbK07DKNJmncsf)
--XLNT GUI - Porting Blitz Basic GUI to PlayBASIC (Is it possible?) (https://www.underwaredesign.com/forums/index.php?topic=4620.0)
--PlayBASIC.com (http://playbasic.com)
[ HashTags: ]
#blitzbasic #playbasic #sourcecode
BlitzBASIC 2 PlayBASIC Conversion - Interface View
Just wrapping this thing up; throwing in some icons a bit of shadow etc.. Terrible coder colours I know.. Just it seems about as simple as I can make it now. Previous there was some keyboard codes etc.. Now you can just use the mouse.
BlitzBASIC To PlayBASIC - V1.00 - Download (8th May 2022)
Here's the current build of the BlitzBASIC To PlayBASIC conversion tool.
Download
[plink] BlitzBASIC To PlayBASIC (V1.00) (http://www.underwaredesign.com/requestfile.php?file=Blitz2PBhn73sxFjakasf45sxasfd3)[/plink]
BlitzBASIC 2 PlayBASIC Conversion Tool Episode 12 Release Build
This is the 12th look at writing a tool that can handle most syntax level conversions from Blitz BASIC into PlayBASIC compatible syntax.
In this episode we review the release build; show it's simple GUI and operation.
The tool breaks down into four main options. Load / Delete / Export and View.
LOAD pops a dialog for you to select a Bitz BASIC source code (or text file). Once selected the source code file is lexed and converted immediately in memory.
REMOVE - Remove the current source from memory. It doesn't delete from disk !
EXPORT - Export will dump the current source as PlayBASIC project folder at the same location as the original code. The translator will name that folder after the loaded source and will append a time stamp. This is to avoid overwriting a previously exported edition of the code. The project will contain the PlayBASIC project file (PBP) the MAIN.PBA (The converted code) and the BlitzWrapper.PBA So you can just load and try and run it from PlayBASIC as normal.
VIEW - Shows a syntax high lighted version of the code. The feature contains a right click menu of secondary view and modification features. Such a Optimize / Hide Remarks / Strip Null Lines for the time being. The menu is contextual; so if you hover over a Function Name and right click it'll pop the Find Function option. THis is really just to let you get some idea of state of the translated code.
SPACE will exit from the VIEW page. UP / DOWN Arrows to scroll up / Down. Page Up / Page Down and HOME are also supported.
QUIT - End the application :)
Check the development blog for more interesting examples
[ Watch Episode 12 ]
[ Links: ]
BlitzBASIC 2 PlayBASIC - WIP Playlist (https://www.youtube.com/playlist?list=PL_dvm0gvzzIVBpPBEP8wbK07DKNJmncsf)
XLNT GUI - Porting Blitz Basic GUI to PlayBASIC (Is it possible?) (https://www.underwaredesign.com/forums/index.php?topic=4620.0)
PlayBASIC.com (http://playbasic.com)
[ Video Script: ]
hello and welcome back to
release day
today is episode 12 in our journey of converting
blitz basic 2d pretty much into playbasic
so i built a release of our current state of the the tool and
it's on the forums
in the
pretty much the work in progress um
thread this blog
whatever i call them
i tend to put all try and put all of the
conversation about one
idea in one thread
so you can follow through what's
happening etc if you feel like it you
know
uh we can go and download from here but
of course i've got a tool thing right
here in front of us
let's have a quick look at it
pretty basic isn't it
nothing pretty a bit probably a bit of a
change since the last time you saw it
i'm not quite sure got a home button
there
which will take you to the playlist at
home home page i didn't want to have any
uh info or about window
i thought about it and just thought i
can't be bothered i'm just having like a
home button for it
so the tool works the same use large
source code
i'll use the taurus source code again
apologies
because you've seen this a million times
if i hit remove it just removes that
from memory a little load again
it doesn't delete the file it just
removes it from uh in memory at the
moment
we've got a temporary view over here
i can move to different projects if we
load more than one source
we'll just check that
go up here
load one of those
what's a longer one that one image
what's image
so we're looking at blitz image
functions
it'll either load files with an
extension of text or extension
bb by the way
so you just move forward and back
in between what project what you want to
be
looking at so
if you change product then
you're removing this project from memory
or exporting it or viewing it
so we'll look at the tourist example
here so we'll
have a hit view
a squeeze at it
same old same old you've seen this stuff
a million times
uh it translates the whole program now
except for the collision issue
in this particular one
um which occurs in the
in this type declarations here
notice how we've got
vertex array
of type vertex that's not legal pv code
so
to run this we'll we'll have to rename
those but the other other issues that
were in older versions like
uh
we've got a draw
uh a short edge so in the older version
of their code
uh
in the original blips code
it was doing a shift in addition see
over here i did say shift
uh
i tested blitz and tested pv side by
side with a bunch of these conditions
it turns out
that if you have a shift with an
addition or a subtraction the precedence
is different
but if it's a shift followed by
multiplication or division they seem to
be the same so
i've had to insert brackets in this
this particular case so
if that occurs in other programs too
this should actually solve that problem
now i mean beyond that
it's all the same as what it was before
i hit export
i'm going to check for saying the code's
been exported
i could just show those shift operators
up down here somewhere too
so let's have a look
so it's important that we that the
translator tries to to mimic the
mathematical behavior of blitz
even though they are two different
products
they will there will be differences in
why expressions are resolved etc
the precedence of some things it's quite
common when you move from one language
to another
so an expression that's fine one
language may not you know work in
another one it happens then
uh so here i'm just testing the shift
with an addition after it's the pink
brackets here are to demonstrate that
the translator inserted the brackets
around the shift
to protect the the order operations
uh i compared the two in blitz and the
shift followed by and is fine
i've just tried here with brackets and
variables and inside
the parameters
from a function etc
uh well there you guys know in there as
well so
uh in blitz as an sar
operator
uh we don't have that so we've had to
have to import this as a function so
it'll remap those
those sars
uh into a function call it does the same
thing
just says not it's not in line that's
all
go back to the bigger one the taurus
source code
so if you hit home to go to the top of
the code
i've added a few things in here
extra
so
if i if i right click i've got optimize
so we can see
just the
sort of um
the compressed additive subtraction
operators uh we can do other things too
we can strip null lines we can add
function headers
which adds these there's one there
our function headers
uh and strip null lines
which will
remove any
redundancy between lines
uh we can toggle remarks but they're
they're always kept on in the export so
that's really just
to check
we're looking at code pretty much
because sometimes code if you have lots
of remarks around code it can be
confusing what's code and what's not
um
turn the remarks back on
close get out of that i'll hit export
again and that will export a new version
than the one we just did before
all right so we'll open up our examples
uh i'll grab the
the last version of
this
this is their 3d tourist demo
so i generated
a folder
with
a pv project it copied the wrap the
current wrapper which is just the as
we'll see in a second it's the emulation
of the blitz functions so
if you add more things that you want to
support you can add them to the main
wrapper and i'd suggest actually
duplicating that
or sharing them with other people or
make fixings fixes within something
but it copies the wrapper in makes a
product file and dumps all of your blips
code into this main
for for our pb project
australian driver across so
so code as we're
pretty used to seeing it by now
um
we still have that
we have one fault
with this with this particular example
and that's
that's the collision with the vertex
the type names and the vertices
so i rename
our type so i just put a t in front of
them
i might do this in the actual the tool
itself
to
prevent this from happening in the
future
which would mean this would be one
example that would load and
sorry they would translate and run
straight away
to be honest i was there i wasn't
expecting anything to ever translate and
run straight away
but you know
it's how things go
and here we are we're running straight
out of the box
we had to fix the the type collision
name problem
uh but we don't have that
that shifting error anymore and the code
actually works
now it's the same problem with the um
the time
is it
our overzealous buffer locking
it's more efficient just to lock the
buffers once then draw everything and
then unlock them
as you've heard me say now a gazillion
times if you watch these videos
there you go
hmm
now i'm pretty happy with this you know
i when i started this
you know a few months ago i didn't
actually think we'd get anything to work
in
so getting something that's relatively
complicated to work is
actually pretty impressive for me
uh
to make other programs work you'd have
to
add
add your own emulations of these things
if it says a
command in your program
in your blitz program it'll just output
it as underscore bb
so the assumption is that you'll provide
a function that does that equivalent
thing whatever it happens to be
if there's no function then it won't
compile when you import the code into
play basic of course
it just can't conjure up things out of
nothing
yeah my objective is not to go through
and
and try and emulate blitz and try and
clone it or whatever it was just to get
a way of translating my own old blitz
code to play basic
and by extension
anyone out there who exports code who
who might be interested in playbase etc
so it just removes one of those
barriers to entry for some people
and as you can see
it actually runs pretty well
uh
i did get a question from one one guy
suggesting to me that uh
well
i'll go there okay i did yeah this
person was asking about well
you know
it
looks kind of
okay
writing in pb
but surely the original blips code is
much faster and i had to say well no
it's not actually
as really comes down to
we put a lot of onus a lot of work into
bb
fixing
on stuff that you just wouldn't
normally do you know
in blitz it's perfectly
yeah
the reliance upon
yeah um
the compiled machine code
model it's very high so
so everyone's caught up in the
assumption of if we build everything in
a machine car that's that's going to
make our applications fly
it does for some things and other things
it doesn't primarily when
when you look at command set on
operations
by dealing with strings in blitz and and
dark basic and a bunch of these other
products
they're quite horrific really
so we can
we lose out in some areas because blitz
is much faster with number crunching
absolutely
but we win back in other places where
you might not expect so
it's quite often what happens is
programs run pretty much the same
i just cleaned up a bit of code in there
gives us about a 60
averaging 42
peak of 62.
you know
we haven't replaced the dot function or
anything like that
drawing edge where's the dot function
the render marina loop function
so fast dot
is that x y rgb
rt
by now you've seen me
write the same code a million times if
you're pretty bored about it
get rid of those two things there
and that will make our inner loop
you know still very comparable
comparable so
but we peak now at 83
frames per second we're heading towards
an average of around
50
54 frames per second
it's terrifying really
but you know this is uh
a fairly complicated blitz program it's
uh you know it's
i chose it because it's kind of similar
to
the same kind of structures that pb has
the converter doesn't really support
have linked list support in it today
right
you have some type support it's very
preliminary so
most blitz programs that are heavily
list orientated will have to be
manhandled by you at the other end
it's just the way it goes
um
they just function very differently at
the time at
between the two and at the time i
i don't have much more time to implement
or to try and add
these things to it
definitely come back and add more to it
all right just uh pasted our taurus
example into blitz
that's just blitz plus by the way
uh
let's run this
so it's suffering from the same buffer
locking problem that what we have as
well
um
everything in director all
pretty much has this problem
these days
oh all right so as you saw it's running
you know the same kind of basic problem
that uh
which is inherent with all direct draw
generation applications these days
anything around the structural based
chokes
so let's draw a poly
and just do the same thing wipe our lock
lock the current surface
and then unlock it at the very end and
that should
give us pretty much the same result
now we're talking
so we
oh
sorry so we're running here in navy
blitz
uh we're averaging our frame rates
around about 56 57 frames per second
but our peak's about 160.
so
that's what i'm talking about before
about this average performance thing is
you often get
the two kind of cattle that cancel each
other out a bit
we're not using
anything like i mean here i'm emulating
blitz this is the play basic version
we're averaging about 56 57
but we don't have the peak
the peak performance we don't have but
the average performance is about the
same
which is terrifies people because
they're like
how's that possible
we spent a lot of time
optimizing stuff that other people
wouldn't
bother optimizing because they're
compiling to machine gun
we have to make those things faster
because
we're trying to make sure we don't spit
out operations that aren't necessary
try to make sure that things are doing
working the best they possibly can and
this is through the
the internal run time from the idea
it would be quicker to in a built uh
executable but probably not by much
maybe a few frames here and there but
not a lot because all it really does is
it removes a lot of the
debug
elements that are stored within the
runtime
so a release builders in pb on these old
versions of pb
has a lot of hooks in it
checking things to make sure they're
okay
like media queries that kind of stuff
um making sure you you're rendering an
image that exists or that you know all
those sort of things
so in blades
why we can't we do those things in here
like yeah i think really we're crippled
in blitz because of this right pixel
if we take our
back buffer
so you just grab that as
yeah
so we so we're calling a function every
time we draw a pixel which is not
not that eloquent
um
this should be faster
not really
so averaging at 55 56 frames per second
so there you go
same system
you know i'm sure you can optimize this
code
better than what i can but
let's just try getting rid of that
completely
hmm that's about
56 to 57 frames per second
so now we're pulling ahead of the the pb
conversion
i think if we unrolled these loops and
got rid of the four next loop stuff and
if the buffer's already locked we
shouldn't be calling lock buffer on it
a little bit
you know you have to do better timing to
work out
how much your bare feet for each little
change
there's a fast version of that isn't it
what does that do
we're not getting anything anything
obvious out of doing that
so there's probably a better way of
doing that in blitz absolutely
this is old blitz code in the first
place
same as with with pva if you wanted to
draw a ground strip you'd use ground
strip to draw all right let's go back to
the tool one last look guys
i think i couldn't make it much simpler
really you just load your source code
i will load text files
gives you a bit of a preview of this
thing
do i have a bit of sticky noise check
them out over here
some of the stuff in there it's really
just for
experimental purposes like the
collapsing
that kind of stuff you can hit up up and
down keys
go through page up and down
you know
hit back on there that'll take you to
the home page if you want to
if you're interested in how the menus
draw one of those things there it's
pretty straightforward stuff
this is just text me news that code was
posted in the forums a while ago
i made one change to it
uh
which is just the rendering aspect of it
wherever that's going to
yeah so instead of drawing a box i'm
drawing a shade box now with a little
bit of a drop shadow underneath it
for each for the highlighted item
and the thing that we're hovering over
i'm just drawing that
drawing that text multiple times
so we're blending it against the
background
because the text is crf so the whole
point of crf is you can do alias re font
rendering against
your effects surface
it'll work on you know bitmap surfaces
as well
but you've got to
read the data from the bitmap to do the
blending
it's just easier to do this on an
effects surface
so the whole this whole application
doesn't use any
doesn't use any
system
services at all
beyond the screen
so when you light up something you know
our favorite tesco code again
the blue section screens and effects
surface they've got effects images of
yfx images for the icons
the hovering syst you just got two
versions of the icon
and it's pre-processed so it's
we had an alpha edition
added to all the rgbs
using the box command
and we can just draw the thing with uh
anti-aliasing
uh what else do we got
the view code here this is the centex
highline control
um
we've got the hovering stuff i mean
that's just all it's all possible
because the crf font
so we can color thing alias it etc and
here i'm using one feature of crfs where
you can have a blended against the
background color
so
the blending's occurring against this
this common background color here so it
never has to fetch the backdrop color at
all
very handy
it's a shame capturing
murdering the frame rate but uh oh well
that concludes my uh
review of it
quick
the uh
but the code is pretty simple just
drawing three different versions of it
so one's a very dark shadow
a moderate shadow
and uh
the sort of half shadow
so it's drawn in black and it's it's
blended against the background
think of that as almost fifty percent
you know if you
just got rid of those there for a second
see we just got one shadow on the text
so
let's just see it underneath there
the same codes used to render the pop-up
window here
that's the same
okay it's just drawing that to an image
i'm drawing the image to the to the the
screen
it's all in fact
everything's an effects surface
go back restore those co bits of code
just to see how how little those impact
the frame just gives a you know
it's they're still there
anyway i'll put the this version of the
menu up on the
on the uh
in the thread that i posted this in i
forget where it is now it's on the it's
on the boards of course
uh
i think there's only one change that's
allowing you to to reposition
to have it offset
of where the menu is happening so you
can
i think by default it draws the menu
in from zero zero down
but sometimes for the drop for the
pop-up menu like that
i've got a displacement for this top
left-hand coordinate so you can
if you have a pop-up mean you can change
set the displacement and then your menu
will appear in that
yeah anyway
if you pick it out yourself there's
heaps of stuff in here that i'm doing
that's probably
useful but as a big collective it's kind
of wasteful
this is what i do here
is i i don't call sync at all inside my
application i use gy sync and that's to
take care of the focus
if i run the application
just one more time
now
just scrunch the window a bit
now if i click
on something else
over here
the app's still running
but we don't have focus
i'm clicking it back into focus the
beauty of that is it means that the
quicker way to do something else
the app's not
taking up a lot of process of time it's
doing a refresh every
what's it's dropping the frame rate down
to 10 frames per second or lower
so it's going
anytime that i've called sync at the
main program
by calling a sync
i'm checking if the screen's in focus in
other words has our window
is it the currently active window if
it's not let's do a white
do a big long wait
and give a bunch of time that our app
might be using back to the system to do
other stuff
but we're still refreshing you know
anyway that'll do for this long drawn
out conversation
uh thanks for watching
i hope you find the tool
in some way useful you know
i know you might want to be watching
this and used to you know years to come
going why didn't you add such and such
well i don't know
blame future me on that one
thanks for watching and i'll see you next time bye
[ Hash: ]
#blitzbasic #playbasic #sourcecode
Oh my! :o
Just been searching some i did along time ago here and came across this very interesting! Not had the time to look properly yet! im currently using BlitzmaxNG.
Do you have any plans for this! I currently have a few Emulators on the go!
Kind Regards Baggey
QuoteDo you have any plans for this!
Unlikely.. If I did another similar styled project it'd be for DarkBASIC and DarkBASIC PRO..
DarkBasic ::)
There were others like Ibasic, Ebasic, Emergence Basic and IWbasic?
I have some interseting stuff in Blitz3D, Which are in .bb
Does this convert those type of files ::)
if it does i shall spend sometime and take a look!
Kind Regards Baggey
QuoteDarkBasic
There were others like Ibasic, Ebasic, Emergence Basic and IWbasic?
And??
I'm writing convertors to translate my own personal code, if others find them useful then that's a bonus. I've a pretty sizable collection of DarkBASIC / DarkBASIC pro code hence the interest..
Which conversely is why we have tools like the Amos 2 PlayBASIC (https://www.underwaredesign.com/forums/index.php?topic=4024.0) convertor.. and a few others.
Quote
I have some interseting stuff in Blitz3D, Which are in .bb
Does this convert those type of files Roll Eyes
It supports most of the legacy blitz syntax which would include Blitz3D.. However it doesn't attempt to recreate the command sets.