BBC BASIC for Windows
« BB4W FORTH Thoughts... »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:50pm



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 3  Notify Send Topic Print
 veryhotthread  Author  Topic: BB4W FORTH Thoughts...  (Read 1224 times)
knudvaneeden
Developer

member is offline

Avatar




Homepage PM


Posts: 32
xx Re: BB4W FORTH Thoughts...
« Reply #19 on: Sep 14th, 2009, 6:51pm »

For those wanting maybe to compare the Forth source code in fern.f versus an equivalent BBCBASIC, here an approximate equivalent.

MODE 8
GCOL 0, 2
VDU 29, 639; 0;
X = 0: Y = 0
COLOUR 15
PRINT TAB( 1, 1 ); "Fractal Fern"
PRINT TAB( 1, 2 ); "from PC Magazine"
FOR I = 1 TO 40000
:
R = RND( 1 )
:
IF (R <= .01) THEN
A = 0: B = 0: C = 0: D = .16: E = 0: F = 0
ELSEIF R > .01 AND R <= .86 THEN;
A = .85: B = .04: C = -.04: D = .85: E = 0: F = 1.6
ELSEIF R > .86 AND R <= .93 THEN;
A = .2: B = -.26: C = .23: D = .22: E = 0: F = 1.6
ELSE
A = -.15: B = .28: C = .26: D = .24: E = 0: F = .44
ENDIF
:
NEWX = (A * X) + (B * Y) + E
NEWY = (C * X) + (D * Y) + F
:
PLOT 69, 100 * X, 100 * Y
:
X = NEWX: Y = NEWY
:
NEXT I
:
END
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: BB4W FORTH Thoughts...
« Reply #20 on: Sep 14th, 2009, 8:11pm »

on Sep 14th, 2009, 6:51pm, knudvaneeden wrote:
For those wanting maybe to compare the Forth source code in fern.f versus an equivalent BBCBASIC, here an approximate equivalent.



Didn't Richard do a one-line version of that program?
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #21 on: Sep 14th, 2009, 9:23pm »

Quote:
Didn't Richard do a one-line version of that program?

Indeed so:

Code:
MODE8:GCOL2:OFF:x=0:y=0:FORI=1TO80000:r=RND(1):s=r>.1:t=r>.86:u=r>.93:A=-.86*s+.65*t+.35*u:B=-.04*s+.3*t-.54*u:C=.04*s-.27*t-.01*u:D=.16-.69*s+.63*t-.02*u:F=-1.6*s+1.16*u:z=A*x+B*y:y=C*x+D*y+F:x=z:LINE600+96*x,32+96*y,600+96*x,32+96*y:NEXT 

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #22 on: Sep 14th, 2009, 9:29pm »

Quote:
here an approximate equivalent

Very approximate (your program uses floating-point values, whereas the Forth version is integer only of course). Here is the actual BBC BASIC program from which the Forth version was translated:

Code:
      MODE 8
      OFF
      GCOL 2
      :
      X%=0
      Y%=0
      :
      FOR I%=1 TO 80000
        R% = RND(100)
        :
        CASE TRUE OF
          WHEN R%<=10 A%=0: B%=0: C%=0: D%=16: F%=0
          WHEN R%>10 AND R%<=86 A%=85: B%=4: C%=-4: D%=85: F%=160
          WHEN R%>86 AND R%<=93 A%=20: B%=-26: C%=23: D%=22: F%=160
          WHEN R%>93 A%=-15: B%=28: C%=26: D%=24: F%=44
        ENDCASE
        :
        Z%=A%*X%DIV100+B%*Y%DIV100
        Y%=C%*X%DIV100+D%*Y%DIV100+F%
        X%=Z%
        MOVE 600+X%, Y%
        DRAW 600+X%, Y%
        :
      NEXT I% 

Richard.
User IP Logged

afarlie
New Member
Image


member is offline

Avatar




PM


Posts: 18
xx Re: BB4W FORTH Thoughts...
« Reply #23 on: Sep 15th, 2009, 10:11am »

This was what I'd worked out so far on accessing MIDI.

This is NOT complete code yet, as I was unsure on some points..

Code:
\  MIDI Functions - NOT Quite AMPLE but may be 
workable...

\ TODO:  GM-Style Instrument numbering
1 CONSTANT  'Grand_Piano' 

\ TODO:  GM-Style Drum Mapping....
\ These would be pitch values used by Channel 10.

S" WINMM.DLL" LoadLibrary CONSTANT WinMM \Load WinMM  Library


\ Obtain addresses for relevant functions in WinMM

WinMM S" midiOutOpen" GetProcedureAddress CONSTANT midiOpenOut
WinMM S" midiOutShortMsg" GetProcedureAddress CONSTANT midiOutShortMsg
WinMM S" midiOutClose" GetProcedureAddress CONSTANT midiOutClose


VARIABLE MidiHandle
0 MidiHandle ! \Variable Initialisation
\ Is this correct way  to set up variable to hold midichannels?


\ Per MIDITEST.BBC
:GetMidi
0 0 0 -1  \ Params in order on stack needed.
MidiHandle \
\ Probably need to test return value here...
;

:_SendShortMsg
MidiHandle @    \ Contents NOT address...
midiOutShortMsg SYSCALL
;

:PlayNote (note --)  \ Based on PlayNewNote in MIDITEST.BBC
256 * 144 +  
127 16 LSHIFT  + \ dwmsg
_SendShortMsg
;


:StopNote  \ (note  --) StopNoteBased on StopPlay in MIDITEST.BBC
256 * 128 + 
_SendShortMsg
;


:Insturment (voice --) \ Change Instrument
1 -  256 *  192 + \ Setup voice change.
127 16 LSHIFT + \ Question do we have LSHIFT/ RSHIFT?
_SendShortMsg
;

:CloseMidi
MidiHandle @
DUP \ Because we need it for closing the midi device
IF    \ I.E Non Zero handle
 midiOutClose SYSCALL \  Close the device using it.
THEN ;
DROP \Drop duplicate param...
;

 
« Last Edit: Sep 15th, 2009, 2:58pm by afarlie » User IP Logged

afarlie
New Member
Image


member is offline

Avatar




PM


Posts: 18
xx Re: BB4W FORTH Thoughts...
« Reply #24 on: Sep 15th, 2009, 10:35am »

Further VDU related words... :
(modified)

If you find a bug or misunderstanding please LMK smiley

0 CONSTANT NULL \ This can be defined directly.
27 CONSTANT ESC \ This can be defined directly.

:
EMIT_LPT (n --) \ Emit 1 Character to the printer.
1 EMIT EMIT
;

:
PRINTER_ON (--) \Enable printer.
2 EMIT
;

:
PRINTER_OFF (--) \Disable printer.
3 EMIT
;

:
PRINTER_FF (--) \ Form feed to printer.
12 LPT_EMIT
;


:
SPLIT_CURSORS (--) \Text cursor is seperate
4 EMIT
;

:
JOIN_CURSORS (--) \ Text cursor joined with graphics.
5 EMIT
;

:
SHOW_VDU (--) \ Enable VDU
6 EMIT
;

:
HIDE_VDU (--) \Disable VDU
21 EMIT
;

:
BELL (--) \ ASCII BELL - Warning tone etc...
7 EMIT
;


\ Defining the following as constants, rather than fixing
them in the implementation

8 CONSTANT _left
9 CONSTANT _right
10 CONSTANT _down
11 CONSTANT _up

:
CUR_LEFT
_left EMIT
;

:
CUR_RIGHT
_right EMIT
;

:
CUR_UP
_up EMIT
;

:
CUR_DOWN
_down EMIT
;

:
LINE_HOME
\ Actual behaviour is listed as return to col 0 in current row... as opposed to full LF CR..
13 EMIT
;


:
DEFINECHAR
\ (n1 n2 n3 n4 n5 n6 n7 n8 char --- )
\(This makes NO checks on the input, it probably should..)

23 EMIT EMIT
7 ROLL EMIT \n1
6 ROLL EMIT \ n2
5 ROLL EMIT \ n3
4 ROLL EMIT \ n4
3 ROLL EMIT \ n5
2 ROLL EMIT \ n6
1 ROLL EMIT \ n7
EMIT \n8


:
_EMIT_RECT (x y x y --)
2SWAP \ Move first pair over top pair (I am not sure 2 SWAP is per standard though)
XY \ First coordiante pair
XY \Second coordinate pair.
;


:
VIEWPORT ( x1 y1 x2 y2 --) \ Define graphics viewport.
0 0 ORIGIN \ Use Absolute coordinates.
24 EMIT \ VDU command
_EMIT_RECT \ Rectangular region to use.
CLG \ Clear graphics viewport.
;

« Last Edit: Sep 15th, 2009, 9:35pm by afarlie » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #25 on: Sep 15th, 2009, 11:06am »

Quote:
7 ROLL 256 MOD EMIT

Surely there's no need to use '256 MOD' before EMIT (since EMIT outputs just a single byte)? In any case the parameters you supply to DEFINECHAR are presumably all in the range 0-255 anyway!

There are many typos and other errors in your code, but presumably you are aware of that. Maybe in future it would be better to check that Forth at least accepts it before listing it here.

Richard.
User IP Logged

afarlie
New Member
Image


member is offline

Avatar




PM


Posts: 18
xx Re: BB4W FORTH Thoughts...
« Reply #26 on: Sep 15th, 2009, 1:13pm »

on Sep 15th, 2009, 11:06am, Richard Russell wrote:
Surely there's no need to use '256 MOD' before EMIT (since EMIT outputs just a single byte)? In any case the parameters you supply to DEFINECHAR are presumably all in the range 0-255 anyway!

There are many typos and other errors in your code, but presumably you are aware of that. Maybe in future it would be better to check that Forth at least accepts it before listing it here.

Richard.


OK. Question to the FORTH people here, what are the more obvious glaring misunderstandings I have?


User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #27 on: Sep 16th, 2009, 8:44pm »

Quote:
This is NOT complete code yet, as I was unsure on some points..

Here is a complete, tested, working version:

Code:
\ MIDI Functions - NOT Quite AMPLE but may be workable...

\ TODO:  GM-Style Instrument numbering
1 CONSTANT 'Grand_Piano' 

\ TODO:  GM-Style Drum Mapping....
\ These would be pitch values used by Channel 10.

\ Obtain addresses for relevant functions in WinMM

Z" WINMM.DLL" LoadLibrary ( Load WinMM library )
DUP Z" midiOutOpen" GetProcAddress CONSTANT midiOutOpen
DUP Z" midiOutShortMsg" GetProcAddress CONSTANT midiOutShortMsg
DUP Z" midiOutClose" GetProcAddress CONSTANT midiOutClose
FreeLibrary DROP ( Free WinMM library )

Z" Kernel32.DLL" LoadLibrary ( Load Kernel32 library )
DUP Z" Sleep" GetProcAddress CONSTANT Sleep
FreeLibrary DROP ( Free Kernel32 library )

VARIABLE MidiHandle 

: OpenMidi ( -- )
  0 0 0 -1 MidiHandle midiOutOpen SYSCALL
  IF
    ." Failed to open MIDI output device" CR
    ABORT
  THEN
;

: CloseMidi ( -- )
  MidiHandle @ midiOutClose SYSCALL
  DROP
;

: SendOutShortMsg ( msg -- )
  MidiHandle @ midiOutShortMsg SYSCALL
  DROP
;

: Delay ( ms -- )
  Sleep SYSCALL DROP
;

HEX
: StartNote ( note -- )
  100 * 7F0090 +
  SendOutShortMsg
;
DECIMAL

: StopNote ( note -- )
  256 * 128 +
  SendOutShortMsg
;

: PlayNote ( note time -- )
  SWAP TUCK 
  StartNote
  Delay
  StopNote
; 

HEX
: Instrument ( voice -- )
  100 * 7F00C0 +
  SendOutShortMsg
;
DECIMAL

: CE3K
  OpenMidi
  'Grand_Piano' Instrument
  70 500 PlayNote
  72 500 PlayNote
  68 500 PlayNote
  56 500 PlayNote
  63 1000 PlayNote
  1000 Delay
  CloseMidi
;

CE3K 

Can you guess what it plays? To find out, 'EXEC' it into BB4Wforth!

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #28 on: Sep 20th, 2009, 9:35pm »

I have uploaded the latest version (0.25) of BB4Wforth here:

http://groups.yahoo.com/group/bb4w/files/BB4Wforth/BB4Wforth.zip

This version implements the following additional words: UM*, INKEY, OPENIN, OPENOUT, OPENUP, BGET, BPUT, CLOSE, ABS, MAX, MIN, TABXY, MS. The following aliases are also provided: PAGE (same as CLS), AT-XY (same as TABXY) and TYPE (same as TELL). The following variables are now available (corresponding to the similarly-named 'system variables' in BB4W): hwnd, memhdc, prthdc, hcsr, hpal, midiid, hfiles, flags, vduvar, ox, oy, cmd$, dir$, lib$, tmp$, usr$.

It is not my intention to make any more changes to BB4Wforth, unless a major bug or omission is reported. Although the full source code is provided in the above ZIP file, I would ask that changes are submitted to me for incorporation, rather than multiple incompatible versions being proliferated.

Richard.
« Last Edit: Sep 21st, 2009, 08:45am by admin » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #29 on: Sep 22nd, 2009, 09:50am »

I've updated BB4Wforth to version 0.26:

http://groups.yahoo.com/group/bb4w/files/BB4Wforth/BB4Wforth.zip

This version fixes a couple of bugs:

1. Using *LIST (S" list filename" OSCLI) caused an 'abort error'.

2. If 'Close' was clicked whilst a Forth program was executing, the window would go into an 'unresponding' state.

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #30 on: Oct 1st, 2009, 08:19am »

I've updated BB4Wforth to version 0.30:

http://groups.yahoo.com/group/bb4w/files/BB4Wforth/bb4wforth.zip

This version has the LEAVE bug corrected, and also implements the following new Forth words: M* */ */MOD U< U> S>D 2* 2/ U2/ SOURCE >IN UM/MOD SM/REM FM/MOD R@ D+ D- [CHAR] 2OVER CELL+ CHARS CHAR+ 2! LSHIFT RSHIFT COUNT DIGIT >NUMBER

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #31 on: Oct 2nd, 2009, 10:16pm »

How about this then....

Code:
BB4Wforth version 0.33 adapted from Jonesforth version 45
Corrections and additions by R.T. Russell, September 2009
244681 cells remaining
OK
S" tester.fr" INCLUDED
S" core.fr" INCLUDED

TESTING CORE WORDS
TESTING BASIC ASSUMPTIONS
TESTING BOOLEANS: INVERT AND OR XOR
TESTING 2* 2/ LSHIFT RSHIFT
TESTING COMPARISONS: 0= = 0< < > U< MIN MAX
TESTING STACK OPS: 2DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP
TESTING >R R> R@
TESTING ADD/SUBTRACT: + - 1+ 1- ABS NEGATE
TESTING MULTIPLY: S>D * M* UM*
TESTING DIVIDE: FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD
TESTING HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2! ALIGN ALIGNED +! ALLOT
TESTING CHAR [CHAR] [ ] BL S"
TESTING ' ['] FIND EXECUTE IMMEDIATE COUNT LITERAL POSTPONE STATE
TESTING IF ELSE THEN BEGIN WHILE REPEAT UNTIL RECURSE
TESTING DO LOOP +LOOP I J UNLOOP LEAVE EXIT
TESTING DEFINING WORDS: : ; CONSTANT VARIABLE CREATE DOES> >BODY
TESTING EVALUATE
TESTING SOURCE >IN WORD
TESTING <# # #S #> HOLD SIGN BASE >NUMBER HEX DECIMAL
TESTING FILL MOVE
TESTING OUTPUT: . ." CR EMIT SPACE SPACES TYPE U.
YOU SHOULD SEE THE STANDARD GRAPHIC CHARACTERS:
 !"#$%&'()*+,-./0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
abcdefghijklmnopqrstuvwxyz{|}~
YOU SHOULD SEE 0-9 SEPARATED BY A SPACE:
0 1 2 3 4 5 6 7 8 9 
YOU SHOULD SEE 0-9 (WITH NO SPACES):
0123456789
YOU SHOULD SEE A-G SEPARATED BY A SPACE:
A B C D E F G 
YOU SHOULD SEE 0-5 SEPARATED BY TWO SPACES:
0  1  2  3  4  5  
YOU SHOULD SEE TWO SEPARATE LINES:
LINE 1
LINE 2
YOU SHOULD SEE THE NUMBER RANGES OF SIGNED AND UNSIGNED NUMBERS:
  SIGNED: -80000000 7FFFFFFF 
UNSIGNED: 0 FFFFFFFF 
TESTING INPUT: ACCEPT

PLEASE TYPE UP TO 80 CHARACTERS:
The quick brown fox jumps over the lazy dog.

RECEIVED: "The quick brown fox jumps over the lazy dog."
TESTING DICTIONARY SEARCH RULES

End of Core word set tests 


Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #32 on: Oct 3rd, 2009, 4:20pm »

I'm pleased to announce the release of BB4Wforth version 0.33:

http://groups.yahoo.com/group/bb4w/files/BB4Wforth/bb4wforth.zip

This version passes the Hayes CORE tests successfully (see previous message).

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BB4W FORTH Thoughts...
« Reply #33 on: Oct 4th, 2009, 4:13pm »

I'm pleased to announce the release of BB4Wforth version 0.35:

http://groups.yahoo.com/group/bb4w/files/BB4Wforth/bb4wforth.zip

This version runs somewhat more quickly than version 0.33 (but is otherwise functionally equivalent).

Richard.
User IP Logged

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

| |

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