News:

Function Finder  Find all the functions within source code files

Main Menu

BlitzBASIC 2 PlayBASIC - Source Code Conversion WIP

Started by kevin, February 22, 2022, 08:53:34 AM

Previous topic - Next topic

kevin

#15




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






PlayBASIC Code: [Select]
; 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
Login required to view complete source code

kevin

#16
  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







PlayBASIC Code: [Select]
;--------------------------------------------------------------------------------
#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$

Login required to view complete source code





  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  


 




 
PlayBASIC Code: [Select]
;--------------------------------------------------------------------------------
#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




kevin


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







PlayBASIC Code: [Select]
; 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()
Login required to view complete source code


kevin

#18
   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




    Script On PasteBin (login required)



kevin

#19
 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





 
PlayBASIC Code: [Select]
;--------------------------------------------------------------------------------
#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









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...


kevin

   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



kevin

  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

   --XLNT GUI - Porting Blitz Basic GUI to PlayBASIC (Is it possible?)
   
   --PlayBASIC.com



 
[  HashTags:   ]


   #blitzbasic #playbasic #sourcecode


kevin


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.

kevin

#23

 
BlitzBASIC To PlayBASIC - V1.00 - Download  (8th May 2022)


     Here's the current build of the BlitzBASIC To PlayBASIC conversion tool.    


  Download

  BlitzBASIC To PlayBASIC (V1.00) (login required)






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

   XLNT GUI - Porting Blitz Basic GUI to PlayBASIC (Is it possible?)

   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


baggey

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
Jesus was only famous because of his dad

kevin


QuoteDo you have any plans for this!

     Unlikely..   If I did another similar styled project it'd be for DarkBASIC and DarkBASIC PRO..   

baggey

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
Jesus was only famous because of his dad

kevin


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 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.