Missing commands and functions

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
LCD
Enthusiast
Enthusiast
Posts: 206
Joined: Sun Jun 01, 2003 10:55 pm
Location: Austria, Vienna
Contact:

Missing commands and functions

Post by LCD »

I downloaded the PB demo some days ago, nice, bet I'm missing some commands and functions:
INC, DEC, TIME()(miliseconds or better, for optimising routines), CL$() (Command line, and THEN (I like to code one-line command sequences if possible). The variables are also a bit strange:
signed byte, word and long... Nobody needs signed byte, byte should be 0-255 (unsigned), Integer (0-65535) is missing, and double integer too. That is offered even in DarkBasic.
Has anyone a idea how to access these functions? DEC, INC, CL$() and TIME()?
My PC
Ryzen 9 5950, 64 GB RAM, nVidia RTX A4000, Win 10
Ryzen 7 1700, 32 GB RAM, nVidia RTX A2000, Win 10
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Missing commands and functions

Post by tinman »

LCD wrote:I downloaded the PB demo some days ago, nice, bet I'm missing some commands and functions:
INC, DEC
You mean like "a = a + 1" or "a + 1"
TIME()(miliseconds or better, for optimising routines)
For now you should use the "GetTickCount_()" which returns the number of milliseconds since Windows was started. Obviousy if you do:

a.l=GetTickCount_()
; Some processing
b.l = GetTickCount_() - a

You can time how long things take.
CL$() (Command line
Same as RunProgram() ?
and THEN


I think Fred said he is working on this, but I cannot remember exactly.
Nobody needs signed byte
Rather sweeping generalisation.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
LCD
Enthusiast
Enthusiast
Posts: 206
Joined: Sun Jun 01, 2003 10:55 pm
Location: Austria, Vienna
Contact:

Post by LCD »

Exactly: a=a+1, but I did not knew that a+1 works too.
"GetTickCount_()" helps mee too, thank you.
CL$() is not the same as RunProgram: If you start the PureBasic compilat, you should find in CL$() the command line, so if you then drop a bmp over the compiled PureBasic program, you will find the path, filename and suffix of the file in variable CL$(). So if you start a PureBasic program with additional parameters, you will get these parameters in variable CL$(). This is supported in DarkBasic/Pro.
THEN must be hard to code ;).
And I never saw any serious Basic with signed bytes, XBasic, RapidQ, DarkBasic, they all have unsigned bytes.
My PC
Ryzen 9 5950, 64 GB RAM, nVidia RTX A4000, Win 10
Ryzen 7 1700, 32 GB RAM, nVidia RTX A2000, Win 10
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

LCD wrote:CL$() is not the same as RunProgram: If you start the PureBasic compilat, you should find in CL$() the command line, so if you then drop a bmp over the compiled PureBasic program, you will find the path, filename and suffix of the file in variable CL$(). So if you start a PureBasic program with additional parameters, you will get these parameters in variable CL$(). This is supported in DarkBasic/Pro.
OK, you need to use the ProgramParameter() command for that.
THEN must be hard to code ;).
I guess it depends how high it is on Fred's list of priorities (not high I would guess), and how difficult it would be to add it to the parser. It could affect how the compiler interprests lines and blocks of code, so it maybe is more difficult than it would appear.
And I never saw any serious Basic with signed bytes, XBasic, RapidQ, DarkBasic, they all have unsigned bytes.
I never saw any serious language which forced you to use only one type of byte ;)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

>And I never saw any serious Basic with signed bytes,
>XBasic, RapidQ, DarkBasic, they all have unsigned bytes.

DarkBasic? Serious? DB was deposited in my bin a few weeks ago :twisted:
--Kale

Image
LCD
Enthusiast
Enthusiast
Posts: 206
Joined: Sun Jun 01, 2003 10:55 pm
Location: Austria, Vienna
Contact:

Post by LCD »

Dark Basic supports dirty coding. I was able to speedup my BMP2SCR by very high factor just by using some dirty tricks, and it is now much faster than the first experiments with PureBasic, but I hope to learn some dirty tricks with PB too, as it looks very good (I know, demo version is slowed down by the debugger)... This is why I like DarkBasic, but on the other side it has very high hardware needs and no Win-gadgets support, so I hate it.
I never saw any serious language which forced you to use only one type of byte ;)
Does not PB force me to use only signed byte? ;)
My PC
Ryzen 9 5950, 64 GB RAM, nVidia RTX A4000, Win 10
Ryzen 7 1700, 32 GB RAM, nVidia RTX A2000, Win 10
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

why did you need THEN?

maybe im wrong but i don't see any particular reason to add it, and its easier like its now.
ARGENTINA WORLD CHAMPION
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Missing commands and functions

Post by fsw »

LCD wrote:I'm missing some commands and functions:
INC, DEC...
no problem with that, for this use :
INC
and
DEC

It's that easy.

PureBasic has inline assembler, INC and DEC are assembler commands.
Simply switch Inline ASM on (in the editor - maybe not available in the demo).
LCD
Enthusiast
Enthusiast
Posts: 206
Joined: Sun Jun 01, 2003 10:55 pm
Location: Austria, Vienna
Contact:

Post by LCD »

@ricardo:
Because every newbie to PB tries as first to write IF THEN ELSEIF ELSE structures in one line, this is the way I prefer, and the demo is also limited in number of source code lines.
@fsw:
Ooops, I forgot that x86 has INC and DEC too... You´re completly right, but "a+1" works fine too.
Another question: Is there a way to make memory block from image (not loading image from disc, but taking existing image to read it out with PEEK, modify it with POKE, and then put it back on screen. This should be faster than PLOT())?
My PC
Ryzen 9 5950, 64 GB RAM, nVidia RTX A4000, Win 10
Ryzen 7 1700, 32 GB RAM, nVidia RTX A2000, Win 10
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post by Froggerprogger »

THEN (I like to code one-line command sequences if possible).
It's not the same, but it works in one line:

Code: Select all

If then$="nonexistent" : then$="don't care" : Endif
%1>>1+1*1/1-1!1|1&1<<$1=1
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

LCD wrote:Another question: Is there a way to make memory block from image (not loading image from disc, but taking existing image to read it out with PEEK, modify it with POKE, and then put it back on screen. This should be faster than PLOT())?
You have the ultimate solution in PB: the pointers. Ok, there is some good tutorial on this forums made by 'freak' so you can launch a search for further explanation.

Quick example:

Code: Select all

Structure Byte
  Pixel.b
EndStructure

*Memory.Pixel = AllocateMemory(....) : ReadData(...) ; to read the file in memory

; And then you can access the buffer with like that

; read
yourPixel = *Memory\Pixel

; write
*Memory\Pixel = $FF 

; Move for 4 bytes in the buffer:
*Memory+4

And this is very very fast. Without pointer support, any other BASIC can compare. Of course, the debugger has a big impact on such code, about 3 to 6 times slower.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> Ok, there is some good tutorial on this forums made by 'freak' :D

Here you go: viewtopic.php?t=6070
Here's an even better one (but german): http://freak.coolfreepages.com/help/

Timo
quidquid Latine dictum sit altum videtur
LCD
Enthusiast
Enthusiast
Posts: 206
Joined: Sun Jun 01, 2003 10:55 pm
Location: Austria, Vienna
Contact:

Post by LCD »

Thanks, FroggerProgger, Fred & Freak!
1. If then$="nonexistent" : then$="don't care" : Endif
Nice, but not the same, but now I know that I can do the same thing in one line, just the usage is a bit new for me:
IF a=1:DO JOBS:ELSEIF a=0:NOJOBS:ENDIF, this works very well and I´m sure, I will learn to like this too.
2. I readed about the pointers in the help file, but I though, they only work with Screen() and not with Image() aswell, will chech this later. My problem was:
In Dark Basic Pro it took me 25 ms to display a SCR (ZX Spectrum screen image) (Okay, without tricks it was slower than PB, I made my own Plot procedures that works on memblocks), in PB it takes ~100 ms with more optimised code and the PLOT, and I´m sure, with direct Image memory access I can reach 20 or less ms, and this is millions times faster than RapidQ, and easier to use.
3. Hallo Freak: Ist eigentlich kein problem, da ich Deutsch spreche, ich komme ja aus Wien (Vienna), lass Dich nicht davon täuschen dass ich das internationale Forum benutze. We austrians can talk very good in german, and some of us can even talk in english... :). Your Tutorial page was not displayed with Netscape 4.8... Fortunaly I have Mozilla too. Thanks, I´m sure, this will help me.
My PC
Ryzen 9 5950, 64 GB RAM, nVidia RTX A4000, Win 10
Ryzen 7 1700, 32 GB RAM, nVidia RTX A2000, Win 10
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

don't hesitate to post a source, if you need utime speed, we could probably found some tricks to optimize even more :).
LCD
Enthusiast
Enthusiast
Posts: 206
Joined: Sun Jun 01, 2003 10:55 pm
Location: Austria, Vienna
Contact:

Post by LCD »

Okay, here it is:

Code: Select all

; Show spectrum screen
Procedure recall_scr(x3.w,y3.w,trans.b,hide.b,siz.b,grey.b)
  stime=GetTickCount_():FreeImage(1):CreateImage(1,256,192):StartDrawing(ImageOutput())
  For y=0 To 23:For x=0 To 31:z=y*32+x
  If grey=0:p=pap(z):i=ink(z):b=191+bri(z)*64:Else:p=pap(z)*32:i=ink(z)*32:b=bri(z):z=min(p+(b*16)-8,0):v=min(i+(b*16)-8,0):EndIf
  If hide:p=7:i=0:b=191:EndIf
  If grey=0
    bytesplit8(p):rp=bit(6)*b:gp=bit(5)*b:bp=bit(7)*b:bytesplit8(i):ri=bit(6)*b:gi=bit(5)*b:bi=bit(7)*b:ria=ri:rpa=rp:gia=gi:gpa=gp:bia=bi:bpa=bp
  Else
    ria=v:gia=v:bia=v:rpa=z:gpa=z:bpa=z
  EndIf
  For y1=0 To 7:y2=y*8+y1:For x1=0 To 7:x2=x*8+x1
  If p=trans:rpa=r1(x2,y2):gpa=g1(x2,y2):bpa=b1(x2,y2):EndIf
  If i=trans:ria=r1(x2,y2):gia=g1(x2,y2):bia=b1(x2,y2):EndIf
  If scr(x2,y2)=0:Plot(x2,y2,rpa+gpa<<8+bpa<<16):Else:Plot(x2,y2,ria+gia<<8+bia<<16):EndIf
  Next x1:Next y1:Next x:Next y:StopDrawing():StartDrawing(WindowOutput()):If siz=2:ResizeImage(1,512,384):EndIf
  adr.l=UseImage(1):DrawImage(adr,x3,y3):StopDrawing():time=GetTickCount_()-stime
  StatusBarText(0,0,"Time:"+Str(time),#PB_StatusBar_Center)
EndProcedure

Procedure bytesplit8(bte.w)
  If bte>3:bit(5)=1:bte-4:Else:bit(5)=0:EndIf
  If bte>1:bit(6)=1:bte-2:Else:bit(6)=0:EndIf
  bit(7)=bte
EndProcedure

Procedure min (v.w,min.w)
  If v<min:v=min:EndIf
  ProcedureReturn v
EndProcedure
Don´t be scared...

The image data is decoded earlier into global array SCR(), sized 256x192, and the colour data is in global arrays PAP(), INK() and BRI(), size:768 each. BIT() 0-7 is used for decode colour imformation.
Anything is displayed in windowed mode. And the displaying routine can also be as Greyscale pic and in transparency mode over a BMP picture. PLOT() is the slowing down factor.
My time on Athlon 1200 is 121ms.
My PC
Ryzen 9 5950, 64 GB RAM, nVidia RTX A4000, Win 10
Ryzen 7 1700, 32 GB RAM, nVidia RTX A2000, Win 10
Post Reply