Author |
Topic: BB4W FORTH Thoughts... (Read 1225 times) |
|
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
|
|
|
|
admin
Administrator
member is offline


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


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


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


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #34 on: Oct 7th, 2009, 10:05am » |
|
I've updated BB4Wforth to version 0.36:
http://groups.yahoo.com/group/bb4w/files/BB4Wforth/bb4wforth.zip
This version fixes a couple of minor bugs:
1. The conditions for terminating a DO...LOOP were subtly incorrect.
2. EVALUATE locked up if passed an empty string.
The following additional CORE EXT words are implemented: C" 2>R 2R> CONVERT.
Version 0.36 passes both the Hayes CORE test and the (non-Hayes) COREPLUS test. It also passes CORE EXT tests of words which are implemented.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BB4W FORTH Thoughts...
« Reply #35 on: Oct 10th, 2009, 1:33pm » |
|
I'm pleased to announce the release of BB4Wforth version 0.37:
http://groups.yahoo.com/group/bb4w/files/BB4Wforth/bb4wforth.zip
There is now support for handling Windows events (equivalent to ON CLOSE, ON MOUSE, ON MOVE, ON SYS and ON TIME in BB4W). Rather than allowing genuinely asynchronous interrupts, which could have had an adverse effect on execution time, Windows events are made synchronous by means of the POLL word.
For example, to incorporate an ON TIME handler you would write a Forth word called ONTIME containing the code you wish to execute. Then, within your 'main' program, you would put POLL wherever you want a pending event to be processed:
Code:: ONTIME ." ON TIME!" CR ;
: TEST BEGIN POLL 0 MS AGAIN ;
TEST (here 0 MS avoids 'burning' the processor).
Additionally, v0.37 allows you to specify the name of a Forth program in the command line (or via a shortcut), causing it to be executed directly:
Code: Richard.
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: BB4W FORTH Thoughts...
« Reply #36 on: Oct 20th, 2009, 5:21pm » |
|
To learn Forth:
Leo Brodie 'Starting Forth' book (a classic) online:
http://forth.com/starting-forth/
(source: magazine 'Dr. Dobb's journal')
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
|