Author Topic: FBSL v3.5 = Retrogamecoding AND Basicprogramming  (Read 4656 times)

Mike Lobanovsky

  • Guest
FBSL v3.5 = Retrogamecoding AND Basicprogramming
« on: September 09, 2016, 06:03:09 AM »
@B+

Hi,

I finally recalled which BASIC sorting program exactly I had in mind when we were discussing Galileo's animated sort at basicpro. It was a QB4.5 sorting demo from its distro package.

Here it is in its full glory ported to FBSL v3.5 practically word for word. A couple of DOS-specific statements and procedure forward declarations were removed but all other things stay intact. Original comments go behind a regular single quote, FBSL comments, behind double slashes.

The script is 675 lines long (too long for a message here) so it's been zipped in the attachment below together with a precompiled executable.

It's an absolute killer under XP with its PC sound but regretfully, PC beeps have been deprecated since Vista and may not work properly or reliably in your 7's, 8's, and 10's.


(Now who can say FBSL isn't BASIC, and moreover, isn't a retro BASIC to cater for toddlers and shellbacks alike?) :D
« Last Edit: September 09, 2016, 08:12:05 AM by Mike Lobanovsky »

jj2007

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #1 on: September 09, 2016, 07:19:30 AM »
regretfully, PC beeps have been deprecated since Vista.

Works fine on Windows 10 and Windows 7:

include \masm32\MasmBasic\MasmBasic.inc      ; download
  Init
  Sound "440:220"   ; tatatataaaaa!
  Sound "440:200"
  Sound "440:200"
  Sound "352:600"
EndOfCode


If you are interested: What’s up with the Beep driver in Windows 7? - a very, very lengthy excuse by Mr. Larry Osterman (Redmond) explaining that they were not able to route calls to Beep() to the audio hardware in this caricature of an OS called "Vista". What he doesn't mention is that although they eventually managed to make Beep() work again, it now has an undocumented "feature" (Micros**t speak): Your duration should be at least around 100 milliseconds, otherwise you hear - nothing 8)
« Last Edit: September 09, 2016, 08:21:05 AM by jj2007 »

Mike Lobanovsky

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #2 on: September 09, 2016, 07:44:13 AM »
32 or 64 bits? Native or VM? Can I have a binary, please? DosBox reproduces QB SOUND everywhere just fine but its only an emulation -- not native.

They say they've fixed the beep.sys driver for 32 bits but not for 64. My x64 Windows 7 would rather play jingle bells at me through its audio than genuine beeps through the PC speaker. I wouldn't mind, in principle, but the only problem with these jingle bells is they are all of the same tune and duration. ;D

What's behind your Sound(), Jochen, if it's not top secret?


[Edit] i) Yours seems a genuine PC speaker Beep(). So what's your system -- native or VM? ii) I've read this article before, thanks! iii) The new zip is beneath the OP. Can you please try and tell me if it beeps for you?
« Last Edit: September 09, 2016, 08:15:03 AM by Mike Lobanovsky »

jj2007

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #3 on: September 09, 2016, 10:03:12 AM »
What's behind your Sound(), Jochen, if it's not top secret?

Beep(), as indicated above


Quote
[Edit] i) Yours seems a genuine PC speaker Beep(). So what's your system -- native or VM? ii) I've read this article before, thanks! iii) The new zip is beneath the OP. Can you please try and tell me if it beeps for you?

i) Win7-64 and Win10-64, not VMs; ordinary low cost notebooks with Celeron and i5
iii) it beeps; you might have a hardware problem

Mike Lobanovsky

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #4 on: September 09, 2016, 05:02:58 PM »
Nah, no way Jochen. Tried both your sound test and my sort demo on my three Win'7 computers -- a 32-bit notebook w/ on-board HD Audio and two x64 PCs w/ HD Audio and AC97 to the same very poor effect. XP generates very pure and clean legato through the PC's own speaker while 7 uses very dirty staccato emulation through its regular audio out channel, full of clicks and stalls at short sounds.

I might try wave audio simulation myself but that would require an additional include probably even longer than the demo itself. I once used FBSL BASIC to build a real time envelope filter for the wave audio SND_ASYNC read-ahead buffer to reduce clicks heard when Windows system Winmm.dll pumps wave audio to a high-impedance sound system, and I might still find the include and try to fill in the buffer with a sawtooth waveform of required pitch in real time. Surprisingly, the interpretation speed is sufficient for that task and wouldn't even require DynC/DynAsm.

But I certainly won't do this for the sake of this demo alone. I ain't no QB or FB after all, am I? ;)

B+

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #5 on: September 11, 2016, 02:43:53 AM »
@ Mike

This Quick sort is genius, your comments excellent, this comparison demo does not do it justice.

jj2007

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #6 on: September 11, 2016, 08:47:14 AM »
I agree with B+, it's a great demo!

Code: [Select]
▀▀                                           ║                               ║
▀▀▀                                          ║    QUICKBASIC SORTING DEMO    ║
▀▀▀▀                                         ║                               ║
▀▀▀▀▀                                        ║  Insertion    28.222 seconds  ║
▀▀▀▀▀▀                                       ║  Bubble       26.732 seconds  ║
▀▀▀▀▀▀▀                                      ║  Heap         14.294 seconds  ║
▀▀▀▀▀▀▀▀                                     ║  Exchange      2.431 seconds  ║
▀▀▀▀▀▀▀▀▀                                    ║  Shell         7.400 seconds  ║
▀▀▀▀▀▀▀▀▀▀                                   ║  Quick         8.817 seconds  ║

The exchange sort is remarkably fast for this small number of elements.

P.S.: The exe works fine but...
Code: [Select]
[00565][SORTDEMO.fbs] Error &H64: called object isn't a function
Code: [Select]
              ***********************************************************************
              > FBSL         :  Freestyle BASIC Script Language -=Version 3.5 RC3=- <
              ***********************************************************************
              > Author       :  (c)2001-2014 Gerome GUILLEMIN                       <
              > Co-author #1 :  Mehdi BOUAZIZ (parser, lexer, vtables, pcode, ...)  <
              > Co-author #2 :  Mike LOBANOVSKY (SDI, MDI, GUI, DynAsm, DynC, ...)  <
              > Mailto       :  gerome.guillemin@fbsl.net                           <

P.P.S.:
Code: [Select]
//============================================================================
// QB4.5 to FBSL v3.5 RC3 port (c)2016 Mike Lobanovsky
//============================================================================

I wonder who wrote the original code, which is online here since 1995.
« Last Edit: September 11, 2016, 09:16:07 AM by jj2007 »

Mike Lobanovsky

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #7 on: September 11, 2016, 03:20:39 PM »
Hi guys,

Yeah, the demo is kinda viral. I used the code directly from the QB4.5 installation which happens to be exactly the same code as in your .EDU link, JJ. So, since there's no better (meaning more personal) attribution, I've now added your link to the file header. It won't go into any distros since it probably still might be under MS' protection but there's no reason why it shouldn't be quoted on open forums if it's available on academic sites: (thnx Jochen!)

Code: [Select]
//============================================================================
// QB4.5 to FBSL v3.5 RC3 port (c)2016 Mike Lobanovsky
//============================================================================
' ============================================================================
' http://galileo.phys.virginia.edu/classes/551.jvn.fall01/SORTS.BAS
' ============================================================================
'                                 SORTDEMO
' This program graphically demonstrates six common sorting algorithms.  It
' prints 25 or 43 horizontal bars, all of different lengths and all in random
' order, then sorts the bars from smallest to longest.
........

QuickSort (or QwickSort to avoid a naming conflict with FBSL's built-in function of the same name) should've been at least as fast as ExchangeSort but procedure returns in FBSL BASIC are points of unconditional garbage collection, so the four recursive calls within Qwick are definitely taking their toll.

As for
Code: [Select]
[00565][SORTDEMO.fbs] Error &H64: called object isn't a function
that's because you're evidently using an older RC3 build that didn't support InKey() (line 565 in the original script), nor blocking WaitKey(), nor Wait(), and that's exactly why I supplied a precompiled executable in my OP. Get the newer RC3 build from the 7-zip below -- it will run the script by dragging and dropping perfectly. I'm currently revising the FBSL BASIC console vocab to substitute its functions' rigid sets of parameters with more flexible optional ones.

B+

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #8 on: September 11, 2016, 04:40:57 PM »
Oh, those aren't Mike's comments. Oh well, it is a classic well worth viewing again!

I find it extremely anti-intuitive to base the pivot point in the Qwick or Quick Sort on a random number.

Why not systematically use the mid point?

Wouldn't it be a tiny bit faster to calculate mid point than to call up a random number?

I suppose all this has been debated by the professors well before 1995.

Mike Lobanovsky

  • Guest
Re: FBSL v3.5 = Retrogamecoding AND Basicprogramming
« Reply #9 on: September 11, 2016, 05:43:37 PM »
Oh, those aren't Mike's comments.

... which doesn't in any way detract from their merits. :D

Wouldn't it be a tiny bit faster to calculate mid point than to call up a random number?

Perhaps yes -- here and instead of this:

Code: [Select]
RandInt% = INT(RND * (Upper - lower + 1)) + lower
But integer randomizers of acceptable quality are usually implemented with a couple of simple integer CPU register bitshifts of a carefully chosen integer seed, which is way, way faster than this QB run-time FPU jugglery. Once seeded at app start, FBSL RANDINT simply returns the next value in the pseudo-random sequence pre-generated by RANDOMIZE. RANDINT is fast while RANDOMIZE (relatively) isn't.