Author |
Topic: BB4W FORTH Thoughts... (Read 1218 times) |
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: BB4W FORTH Thoughts...
« Reply #15 on: Sep 14th, 2009, 3:04pm » |
|
on Sep 14th, 2009, 2:15pm, Richard Russell wrote:I have uploaded the latest version (0.22) of BB4Wforth:
[As this thread has gone very quiet, I would value any feedback, bug reports etc. to indicate that somebody out there is appreciative of my efforts!
Richard. |
|
Richard, yes, this is very much appreciated.
I tested yesterday some programs from the Forth book from Leo Brody, using BB4WForth, and that went fine. Now even with graphics.
Note: See also http://www.techworld.com.au/article/250530/-z_programming_languages_forth which might be an interesting read.
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
afarlie
New Member
member is offline


Posts: 18
|
 |
Re: BB4W FORTH Thoughts...
« Reply #16 on: Sep 14th, 2009, 3:06pm » |
|
on Sep 14th, 2009, 2:15pm, Richard Russell wrote:
Perhaps this thread should now be entitled BB4th? 
Fern examples works as intended.
In terms of EMIT16 the U/MOD word wasn't something I knew about, but my graphics code was planning on doing that as well.
I'll post my graphics code later, (the reason for ROLL) was to do with some VDU commands like viewports which need a rectangle (i.e 2 XY pairs rather than a single)
Having an indication of a stack underflow is useful. 
Quote:Changes in this version include:
1. The following standard Forth words, which work incorrectly in Jonesforth (v45), have been corrected: ROT, -ROT, ALLOT, DEPTH, HERE, MOD, / and U. (etc.)
2. The following standard Forth words, which aren't present at all in Jonesforth (v45) have been added: ROLL, DO, ?DO, LOOP, +LOOP, I, J, LEAVE, UNLOOP, <BUILDS, DOES>
|
|
I will have to do some reading to understand these in more depth.
Quote:3. The following custom Forth words (specific to this version) have been added: ERR, OSCLI, SYSCALL, HWND, VERSION$, LoadLibrary, FreeLibrary, GetProcAddress, EMIT16, XY, MODE, CLS, CLG, COLOUR, GCOL, ORIGIN, PLOT, MOVE, DRAW, FILL, MOVEBY, DRAWBY, EXEC
|
|
And the documentation is remarkably clear .
It' should not be that hard to add more advanced commands..
Digging out the MIDITEST example is something else I might look at, given that there isn't an AMPLE like system on Windows... (Reimplementing all of AMPLE is beyond me, (some of it being Intterurpt driven 6502 code, but I could at least have a go at seeing if something is possible with simple MIDI maybe...)
Quote:4. Operation of the following Forth words has been slightly modified: DEPTH, .S |
|
I assume what this now does is explained in the code? I must go and read it 
The Fern demo worked fine for me 
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #17 on: Sep 14th, 2009, 4:45pm » |
|
Quote:| I assume what this now does is explained in the code? |
|
Nope, no explanations! You'll have to find out by experiment what the difference is; sorry. This was a 'minimum effort' exercise which has already taken up more of my time than I intended.
Richard.
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: BB4W FORTH Thoughts...
« Reply #18 on: Sep 14th, 2009, 5:17pm » |
|
I have put on my wish list (to maybe todo one time) and am playing with the thought to create a Forth implementation in pure BBCBASIC for Windows (thus not assembler).
Maybe base it on some existing BASIC implementation somewhere to be found.
There is or there seems to be no Backus Naur Form or formal syntax for Forth. If that would have existed that would maybe have made the implementation a little bit more streamlined and to be created more automated.
But I might diverge soon, as usual.
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
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
|
|
Logged
|
|
|
|
David Williams
Developer
member is offline

meh

Gender: 
Posts: 452
|
 |
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?
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
afarlie
New Member
member is offline


Posts: 18
|
 |
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 » |
Logged
|
|
|
|
afarlie
New Member
member is offline


Posts: 18
|
 |
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 
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 » |
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #25 on: Sep 15th, 2009, 11:06am » |
|
Quote: 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.
|
|
Logged
|
|
|
|
afarlie
New Member
member is offline


Posts: 18
|
 |
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?
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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 » |
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
|