LowRES PlayBASIC Library Function & Psub Parser

Started by kevin, April 24, 2023, 12:05:38 AM

Previous topic - Next topic

kevin

   LowRES PlayBASIC Library Function & Psub Parser


   This code will load and parse out the function and psub names from the LowRES library dumping them to the PlayBASIC debugger console.   The output is designed to the included in a forum post.  


PlayBASIC Code: [Select]
        Parse_Lowres_Library_Functions("LowREs.pba")
Sync
waitkey



function Parse_Lowres_Library_Functions(Filename$)

cr$=chr$(13)+chr$(10)

Document$=""

Dim ParamTable$(256)

fh=readnewfile(Filename$)
if fh
s$=readchr$(fh,filesize(filename$))
CloseFile Fh

Dim L$(1000)
s$=replace$(s$,chr$(13),"")
Count=SplitToArray(s$,chr$(10),l$(),0)
For lp =0 to Count
r$=l$(lp)
ru$ =upper$(r$)

Match = (left$(ru$,8)="FUNCTION") *9
Match+= (left$(ru$,5)="PSUB " )*5
if Match>0
Declare$ = mid$(r$,Match, Len(r$))

Bracket_POS =instring(Declare$,"(")
Bracket_ENDPOS =instring(Declare$,")",Bracket_POS)

Name$ =trim$(Left$(Declare$,Bracket_Pos-1))
NameUC$=upper$(Name$)

if left$(NameUC$,3)="LR_"

// ignore the intit functions
if instring(NameUC$,"LR_INIT" )=1 then continue
if instring(NameUC$,"LR_EXECUTECOPPER")=1 then continue
if instring(NameUC$,"LR_DRAW_ORDERED_SPRITES")=1 then continue

Params$ =mid$(Declare$,Bracket_POS,(Bracket_ENDPOS-Bracket_POS)+1)

// #print Name$
// #print Params$

ClosingTag$=trim$(upper$("END"+left$(ru$,Match)))

ReturnData$=""

// Find the closing statement
for SearchLP=lp+1 to Count
r$=l$(SearchLP)
ru$=upper$(r$)
if left$(ru$,len(ClosingTag$))=ClosingTag$
ReturnData$=cutleft$(r$,Len(ClosingTag$))
lp=SearchLP
exit
endif
next

// #print "Returning="+ReturnData$
example$=""
if len(ReturnData$)
example$=ReturnData$+"="
endif

// Highlight params
ParamCOUNT = splittoarray(Params$,",", ParamTable$())
Highlight$="("
if ParamCOUNT
for ParamLP=0 to ParamCOUNT-1
Highlight$+=""+ParamTable$(ParamLP)
Highlight$+=""

if ParamLP< ParamCOUNT-1
highLight$+=","
endif

next
endif
Highlight$+=")"


example$+=""+Name$+""+Highlight$
// #print Example$

Document$+=Example$+cr$+cr$

endif

endif
next

endif

#print Document$


EndFunction








   
Output example:



LR_SYNC(())

LR_OpenScreen((Width,Height,PixelWidth,PixelHeight))

LR_CopperSetPalette((ScanLine,ColourINDEX,ThisRGB ))

LR_WritePalette((INDEX,ThisRGB ))

ThisRGB=LR_ReadPalette((INDEX))

LR_DOT((X,Y,INDEX))

Palette_INDEX=LR_POINT((X,Y))

LR_VSTRIP((Y1,Y2,X,INDEX))

LR_HSTRIP((X1,X2,Y,INDEX))

LR_BOX((X1,Y1,X2,Y2,MOde,INDEX))

LR_CLS((INDEX))

LR_FilledCircle((BX,BY,RADIUS,INDEX))

LR_TEXT((X,Y,TEXT$))

   Sprite as LR_SPRITE pointer=LR_CreateSprite((SpriteINDEX,Xpos=0,Ypos=0))

LR_DeleteSprite((SpriteINDEX))

LR_PositionSprite((SpriteINDEX,XPOS,YPOS))

LR_SpriteX((SpriteINDEX,XPOS))

LR_SpriteY((SpriteINDEX,YPOS))

Result=LR_GetSpriteX((SpriteINDEX))

Result=LR_GetSpriteY((SpriteINDEX))

Result=LR_GetSpriteWidth((SpriteINDEX))

Result=LR_GetSpriteHEIGHT((SpriteINDEX))

LR_SpriteDEPTH((SpriteINDEX,Depth))

Result=LR_GetSpriteDEPTH((SpriteINDEX))

LR_WriteSprite((SpriteINDEX,X,Y,PaletteINDEX))

Sprite as LR_SPRITE pointer=LR_SPRITEPTR((SpriteINDEX))

LR_DRAWSPRITE((SpriteINDEX))

Overlap=LR_SpritesOverlap((SpriteINDEX1,SpriteINDEX2,Method=1))

LR_WRITEFONT((ThisCHR,X,Y,Palette_INDEX))

INDEX=LR_READFONT((ThisCHR,X,Y))

LR_CreateFONT((Width,Height))

Address=LR_GETCHRPTR((ThisCHR))

LR_Line((xpos1,ypos1,xpos2,ypos2,PaletteINDEX))

LR_WriteToScreen((x1,y1,x2,y2,SrcPtr,SrcModulo))

LR_ScaleWindowToDeskTop(())



   
Related Links:


       LowRES Library For PlayBASIC