BBC BASIC for Windows
« Features that are never used »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:36pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Features that are never used  (Read 552 times)
hitsware
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 70
xx The most unused is the sound !
« Reply #9 on: May 8th, 2014, 02:07am »

rem: Awkward, but works ! .... smiley

envelope 1,0,0,0,0,0,0,0,127,0,0,-1,127,0

dim note(3,7),selection(40)

for x=1 to 40: read selection(x): next x
data 40,88,96,100,116,120,136,144,148,164,168
data 184,192,196,212,232,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0
print " hit any key to escape "
repeat

for count=0 to 7
n=inkey(1)
if n<>-1 then quit
for voice=0 to 3
random1=rnd(10)
random2=rnd(40)
if random1=1 then note(voice,count)=selection(random2)
next voice

if sgn(note(1,count))=1 then
sound 1,1,note(1,count),1: sound 4097,1,0,4
else sound 4097,1,0,5
endif
if sgn(note(2,count))=1 then
sound 2,1,note(2,count),1: sound 4098,1,0,4
else sound 4098,1,0,5
endif
if sgn(note(3,count))=1 then
sound 3,1,note(3,count),1: sound 4099,1,0,4
else sound 4099,1,0,5
endif
next count
until false
end
User IP Logged

rtr
Guest
xx Re: The most unused is the sound !
« Reply #10 on: May 8th, 2014, 08:18am »

on May 8th, 2014, 02:07am, hitsware wrote:
rem: Awkward, but works ! .... :)

No it doesn't, because neither note nor count is a legal variable name when Lowercase Keywords mode is selected, which it must be to load your program as listed! Here is a corrected version with those variables capitalised to make them valid in both modes:

Code:
      ENVELOPE 1,0,0,0,0,0,0,0,127,0,0,-1,127,0

      DIM Note(3,7),selection(40)

      FOR x=1 TO 40: READ selection(x): NEXT x
      DATA 40,88,96,100,116,120,136,144,148,164,168
      DATA 184,192,196,212,232,0,0,0,0,0,0,0,0,0,0
      DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0
      PRINT " hit any key to escape "
      REPEAT
  
        FOR Count=0 TO 7
          n=INKEY(1)
          IF n<>-1 THEN QUIT
          FOR voice=0 TO 3
            random1=RND(10)
            random2=RND(40)
            IF random1=1 THEN Note(voice,Count)=selection(random2)
          NEXT voice
    
          IF SGN(Note(1,Count))=1 THEN
            SOUND 1,1,Note(1,Count),1: SOUND 4097,1,0,4
          ELSE SOUND 4097,1,0,5
          ENDIF
          IF SGN(Note(2,Count))=1 THEN
            SOUND 2,1,Note(2,Count),1: SOUND 4098,1,0,4
          ELSE SOUND 4098,1,0,5
          ENDIF
          IF SGN(Note(3,Count))=1 THEN
            SOUND 3,1,Note(3,Count),1: SOUND 4099,1,0,4
          ELSE SOUND 4099,1,0,5
          ENDIF
        NEXT Count
      UNTIL FALSE
      END 

I advise running the Cross Reference Utility before uploading code to the forum.

Richard.
User IP Logged

rtr
Guest
xx Re: The most unused is the sound !
« Reply #11 on: May 8th, 2014, 1:12pm »

I'm somewhat puzzled that you've unrolled the SOUND loop. Isn't your program exactly equivalent to this:

Code:
      ENVELOPE 1,0,0,0,0,0,0,0,127,0,0,-1,127,0

      DIM Note(3,7),selection(40)

      FOR x=1 TO 40: READ selection(x): NEXT x
      DATA 40,88,96,100,116,120,136,144,148,164,168
      DATA 184,192,196,212,232,0,0,0,0,0,0,0,0,0,0
      DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0

      PRINT " hit any key to escape "
      REPEAT
        FOR beat=0 TO 7
          IF INKEY(1)<>-1 QUIT
          FOR voice=1 TO 3
            IF RND(10)=1 THEN Note(voice,beat)=selection(RND(40))
            IF Note(voice,beat)>0 THEN
              SOUND voice,1,Note(voice,beat),1
              SOUND voice+4096,1,0,4
            ELSE
              SOUND voice+4096,1,0,5
            ENDIF
          NEXT voice
        NEXT beat
      UNTIL FALSE
      END 

Then you can trivially convert it from three-voice to four-voice:

Code:
      *tempo 133
      ENVELOPE 1,0,0,0,0,0,0,0,127,0,0,-1,127,0

      DIM Note(3,7),selection(40)

      FOR x=1 TO 40: READ selection(x): NEXT x
      DATA 40,88,96,100,116,120,136,144,148,164,168
      DATA 184,192,196,212,232,0,0,0,0,0,0,0,0,0,0
      DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0

      PRINT " hit any key to escape "
      REPEAT
        FOR beat=0 TO 7
          IF INKEY(1)<>-1 QUIT
          FOR voice=0 TO 3
            IF RND(10)=1 THEN Note(voice,beat)=selection(RND(40))
            IF Note(voice,beat)>0 THEN
              SOUND voice,1,Note(voice,beat),1
              SOUND voice+4096,1,0,4
            ELSE
              SOUND voice+4096,1,0,5
            ENDIF
          NEXT voice
        NEXT beat
      UNTIL FALSE
      END 

Richard.
User IP Logged

hitsware
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 70
xx Re: Features that are never used
« Reply #12 on: May 9th, 2014, 03:53am »

how 'bout this one ? (done with your bbc4w)

http://home.comcast.net/~mnjmiller/cerisemode.exe
User IP Logged

hitsware
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 70
xx Re: Features that are never used
« Reply #13 on: May 9th, 2014, 7:02pm »

> I'm somewhat puzzled that you've
> unrolled the SOUND loop.

I don't know what you mean by
"unrolled the sound loop"
I came up with that code a long
time ago strictly by trial and error,
and never understood it at all.
The purpose is to allow notes with
envelopes to overlap when appropriate.
I.E. the way most BBC music is written
shuts all notes off after any new note,
but if each voice is considered an instrument
then this is a poor representation of reality.
There is probably a way simpler way.
User IP Logged

rtr
Guest
xx Re: Features that are never used
« Reply #14 on: May 9th, 2014, 9:17pm »

on May 9th, 2014, 7:02pm, hitsware wrote:
I don't know what you mean by "unrolled the sound loop"

I mean that instead of using a loop you wrote separate code for each SOUND channel (1,2,3), despite the code for each channel being identical - apart from the channel number itself of course!

It seemed particularly odd because you did use a loop when writing to the Note() array:

Code:
          FOR voice=0 TO 3
            random1=RND(10)
            random2=RND(40)
            IF random1=1 THEN Note(voice,Count)=selection(random2)
          NEXT voice 

If you look at my version, I simply moved the SOUND statements into the existing loop, thereby getting rid of the duplication of code. That made the program shorter and easier to understand, and also meant that changing the program from three-voices to four-voices was trivial.

Quote:
the way most BBC music is written shuts all notes off after any new note

"The way most BBC music is written"? I sincerely hope not!

Richard.
« Last Edit: May 9th, 2014, 9:22pm by rtr » User IP Logged

rtr2
Guest
xx Re: Features that are never used
« Reply #15 on: Mar 21st, 2015, 11:47pm »

2. RETURN destination

This is the second in an occasional series of posts on features of BBC BASIC for Windows which are so obscure or specialised that they are (virtually) never used.

The RETURN statement is used either to exit from a subroutine (called using GOSUB) or to indicate the completion of an ON event handler. Normally it causes execution to continue from the point in the code where the subroutine call or event interrupt happened.

However you can, optionally, follow the RETURN with a destination (line number or label) which will cause it to 'return' to the specified place instead. Effectively it is like a GOTO except that the 'return address', which was pushed onto the stack, is discarded (if you used GOTO instead the program would appear to work, for a while, until all the memory was used up by the ever-growing stack).

When might you want to do that? Hardly ever (and being equivalent to a GOTO all the arguments for avoiding them apply to this usage as well)! One possible use might be for an ON TIME interrupt to abort some lengthy process without the overhead of polling for the event:

Code:
      ON TIME RETURN (abort)

      REPEAT
        I% += 1
      UNTIL FALSE

      (abort)
      PRINT "Aborted with I% = "; I% 

Perhaps you can think of another application for this functionality.

Richard.

User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Features that are never used
« Reply #16 on: Mar 22nd, 2015, 08:12am »

SUMLEN

Not really a 'feature' of BB4W as such, but I noticed it for the first time a few days ago when I was browsing the list of ARM BASIC V's keywords. Had to check if BB4W has it as well, and of course it does.

I'm certain I had never noticed this keyword before in all my years of BBC BASIC programming.

Any other long-time BBC BASIC users new to this keyword?

Embarrassing if it's just me.


David.
--
User IP Logged

rtr2
Guest
xx Re: Features that are never used
« Reply #17 on: Mar 22nd, 2015, 10:43am »

on Mar 22nd, 2015, 08:12am, David Williams wrote:
Any other long-time BBC BASIC users new to this keyword?

I think it's reasonably well-known, but little-used. Because SUMLEN arrived in the language at the same time as SUM (which is much more useful) I would expect anybody who knows about one to be aware of the other.

Having searched through thousands of programs on my PC I have found only one genuine example of its use, which is in a program that puts a whole load of files on the clipboard (CF_HDROP format). To work out how much memory to allocate for the clipboard data it does:

Code:
      nfiles% = FNselectfiles("Select one or more files", "*.*", file$())
      ddesize% = DIM(dropfiles{}) + SUMLEN(file$()) + nfiles% + 1 

But I'd prefer the thread not to fly off-topic this soon. Any feedback specifically on the RETURN destination feature?

Richard.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Features that are never used
« Reply #18 on: Mar 22nd, 2015, 12:25pm »

on Mar 22nd, 2015, 10:43am, g4bau wrote:
Any feedback specifically on the RETURN destination feature?


Only that it was news to me, and that I've made a mental note of it.

David.
--
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Features that are never used
« Reply #19 on: Mar 23rd, 2015, 5:32pm »

Hi Richard,

I'm not sure you'd ever want to do it this way, but I guess you could use it to cut out the "PROCsys" bit of an ON PROC handler:

Code:
    5 PROCMenus
   10 ON SYS w%=50+@wparam%:RETURN w%
   20 REPEAT
   30   WAIT 1
   40 UNTIL FALSE
   45 END
   50 PRINT "Black":END
   51 PRINT "RED" :END

  100 END
      DEFPROCMenus
      SYS "CreateMenu" TO hmenu%
      SYS "SetMenu", @hwnd%, hmenu%
      SYS "AppendMenu", hmenu%, 0, 0, "Blac&k"
      SYS "AppendMenu", hmenu%, 0, 1, "&Red"
      SYS "DrawMenuBar", @hwnd%
      ENDPROC
 


Incidentally, I was interested to see that I can mix numbered and unnumbered bits of code - not that I'd recommend it...

Obviously you would probably want to jump to a handling routine rather than just a print statement, and I can't see much advantage over doing it the way recommended in the manual, but it IS a potential use for the feature!

I suspect you should probably mask @wparam% with &FFFF?

Best wishes,

D
« Last Edit: Mar 23rd, 2015, 5:37pm by DDRM » User IP Logged

rtr2
Guest
xx Re: Features that are never used
« Reply #20 on: Mar 23rd, 2015, 8:01pm »

on Mar 23rd, 2015, 5:32pm, DDRM wrote:
I suspect you should probably mask @wparam% with &FFFF?

Not in the case of a menu selection; MSDN says: "Value of the high-order word of wParam... If the message is from a menu, this parameter is 0".

Richard.
User IP Logged

rtr2
Guest
xx Re: Features that are never used
« Reply #21 on: Apr 6th, 2015, 10:32pm »

3. ELSEIF condition THEN;

This is the third in an occasional series of posts on features of BBC BASIC for Windows which are so obscure or specialised that they are (virtually) never used.

Some BASIC dialects provide an ELSEIF (or ELSIF) keyword to allow multiple conditions to be conveniently handled without nesting IF statements. Standard BBC BASIC does not support this, but an equivalent functionality can be achieved using CASE:

Code:
      CASE TRUE OF
        WHEN condition1:
          REM Do something
        WHEN condition2:
          REM Do something else
        OTHERWISE:
          REM Do default action
      ENDCASE 

However BB4W does support a form of ELSEIF, a feature which was added primarily to aid automatic translation from other dialects:

Code:
      IF condition1 THEN
        REM Do something
      ELSEIF condition2 THEN;
        REM Do something else
      ELSE
        REM Do default action
      ENDIF 

Note the semicolon ; immediately after the THEN which prevents a new (nested) multi-line IF clause being started.

Richard.
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Features that are never used
« Reply #22 on: Apr 9th, 2015, 08:56am »

Hi Richard,

Thanks for the note on ELSEIF. I quite often use the CASE TRUE construction, which is very nice, but I can see that using ELSEIF...THEN; might also work well to make multiple choices clear.

I see that there is one use of it in the wiki - is that enough to earn ELSEIF a brief mention in the manual?

Best wishes,

D
User IP Logged

rtr2
Guest
xx Re: Features that are never used
« Reply #23 on: Apr 9th, 2015, 10:13am »

on Apr 9th, 2015, 08:56am, DDRM wrote:
I see that there is one use of it in the wiki - is that enough to earn ELSEIF a brief mention in the manual?

It is already there. ELSEIF is just ELSE IF and is therefore documented under ELSE and IF. It's a standard feature of BBC BASIC, which you could use even on the BBC Micro:

Code:
      IF condition1 PROCdosomething ELSEIF condition2 PROCdoanotherthing 

The little-used, BB4W-specific, feature I drew attention to was THEN; (i.e. the trailing semicolon) which is documented, unsurprisingly, under THEN:

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin7.html#then

Richard.
« Last Edit: Apr 9th, 2015, 10:17am by rtr2 » User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls