Joined: Fri Aug 30, 2002 1:09 am Posts: 8545 Location: Southern California
|
IamRob wrote: Garth: since my Forth word definitions are from an older out-dated Forth and are not made public anywhere, I have not gotten into the newer Forth standards (ANS, 2012, and maybe others), partly because they seem unnecessarily complex for what I do, and I don't think I would live long enough to make my Forth ANS-compliant. I have posted some of the following before, but it's relevant to your quote to repeat it. Skip down to the part after your next quote if you like.
There are also some parts of ANS Forth that present extra overhead in order to make it more portable across a wide range of processors. My personal opinion is that hey may have taken this a little too far. At some point, we need to acknowledge that no language that lets you get so close to the heart of the computer will be 100% portable. We must consider the programmer(s) and platform(s) involved, and decide on a good balance between portability and optimization. I personally prefer a little more optimization at the expense of some portability. Greater optimization means a particular processor can be used for a wider range of jobs anyway, which would in itself reduce the need for portability.
Jack Woehr, a senior project manager for Vesta Technologies, who was on the X3J14 committee, says in his book "Forth: The New Model", "When Forth, which some hold to be inextricably wedded to hardware, takes responsibility for cross-platform portability, a certain light-footedness and grace will be surrendered." He admits that optimum portability and optimum efficiency don't come at the same point.
What I use is mostly Forth-83, but when I add things, I try to make them conform, as much as possible, to things in later standards or at least in common usage (which is kind of a standard in itself, even if it hasn't made it into later official specifications). Some aspects of my Forth meet different "standards", without conflicting with each other. For example, we have the old word SHIFT which uses both positive and negative shift distances, but we also have RSHIFT and LSHIFT which are in ANS Forth. There's no reason they can't both be in the same system. The same is true for the older COMPILE and [COMPILE], and ANS's POSTPONE.
Where I added useful words that are not part of Forth 83, I tried to move toward the new standard in order to become more like the standard, instead of less. For example, my word RANGE was useful in test equipment, when you want to see if a test result falls within the allowable limits. ANS has a word WITHIN which was almost the same, so I included that. I found that my word RANGE is actually in common use, but it's usually called BETWEEN, and it almost made it into the standard under that name. I changed the name of my word from RANGE to BETWEEN.
Quote: I think I will instead convert the definitions you posted to use with 65816 version I am working on. Most of the definitions are the same, just different wording being used.
Since I am winding down and getting close to being done, I should also confirm your numeric output and digit formatting word definitions. It will make what I am doing more compatible with what is mostly already out on the net. Thanks.
HOLD <# # #> SIGN #S D.R D. .R and . What I have in the .FTH file which is sort of like a shadow-screen file in that it just describes to humans what's in the .ASM file is:
Code: : HOLD ( ASCII -- ) \ SF151-156 FIG ANS_CORE HLD DECR HLD @ C! ;
: >DIGIT ( n -- ASCII_char ) ( b -- ASCII_char ) \ used in # DUP 9 > \ Greater than 9? IF 7 + THEN \ If so, add 7; then 30 + ; \ add 30.
: # ( d1 -- d2 ) \ SF152-154 FIG ANS_CORE BASE @ UD/MOD ROT >DIGIT HOLD ;
: ## # # ( d1 -- d2 ) ; \ No header. Used internally to save mem
: #> ( d -- addr len ) \ SF151-156 FIG ANS_CORE 2DROP PAD 1- HLD @ - ;
: SIGN ( n -- ) \ SF154-155 FIG ANS_CORE 0< IF ASCII - HOLD ELSE DROP THEN ;
: #S ( d1 -- d0 ) \ SF151-154, FIG, ANS_CORE BEGIN # 2DUP D0= UNTIL ;
: D.R ( d width -- ) \ SF157, FIG, ANS_DOUBLE >R DUP >R DABS <# #S R> SIGN #> R> OVER - SPACES TYPE ;
: D. ( d -- ) \ SF150,155, ANS_DOUBLE 0 D.R SPACE ;
: . ( n -- ) \ SF20,21,26, FIG, ANS_CORE S>D D. ;
: ? ( addr -- ) \ ANS_TOOLS @ . ;
: U. ( u -- ) \ SF147, ANS_CORE 0 D. ;
: U.R ( u width -- ) \ SF148, ANS_CORE_EXT 0 SWAP D.R ;
: .R ( n width -- ) \ SF123,131, FIG, ANS_CORE_EXT >R S>D R> D.R ; What I have in the .ASM actual assembly source code is the following. "DWL" in C32 is "Define Word(s), Low byte first."
Code: HEADER "HOLD", NOT_IMMEDIATE ; ( ASCII -- ) HOLD: PRIMITIVE ; 10x as fast as the secondary version! DEC HLDdata ; First, decrement HLD . LDA HLDdata ; Put the addr held by HLD in ZP so we STA N ; can STA indirect below. ACCUM_8 ; Temporarily make accum only 8-bit. LDA 0,X ; Get just the 8-bit character off the STA (N) ; stack, and store it where HLD said. ACCUM_16 ; Return the accum to 16-bit, and hp1: POP1 ; pop the character off the stack. ;------------------- HEADER ">DIGIT", NOT_IMMEDIATE ; ( n -- ASCII_CHR ) ( b -- ASCII_CHR ) TO_DIGIT: PRIMITIVE ; Turn number (0-15) into ASCII character. LDA 0,X ; We'll do it in 16-bit to avoid changing from CMP #$A ; 16 to 8 and back. It's only meaningful for BCC ja30 ; bytes though. ADC #6 ; Add only 6, not 7, because C flag was set. ja30: ADC #$30 ; Carry flag is always clear when getting here. PUT_TOS ;------------------- HEADER "#", NOT_IMMEDIATE ; ( d1 -- d2 ) SHARP: DWL nest, BASE_FETCH, UDsMOD DWL ROT, TO_DIGIT, HOLD, unnest ;------------------- NO_HEADERS HEADER "##", NOT_IMMEDIATE ; ( d1 -- d2 ) SHARP_SHARP: DWL nest, SHARP, SHARP, unnest HEADERS ;------------------- HEADER "#>", NOT_IMMEDIATE ; ( d -- addr len ) sharpGREATER: PRIMITIVE ; Primitive version 7 bytes longer & 7x as fast. LDA HLDdata ; First put addr of number string in the second- STA 2,X ; from-top stack position. ( #> as a secondary ; begins with 2DROP anyway.) LDA DPdata ; Re-derive the addr of first byte past end of CLC ; our string, which was the last byte before ADC #_tib_len + $21 ; PAD . SEC ; Then subtract the addr shown by HLD , and that SBC HLDdata ; will give us the length of our string. JMP PUT ; Put that at the top of the stack. ;------------------- HEADER "SIGN", NOT_IMMEDIATE ; ( n -- ) SIGN: PRIMITIVE LDA 0,X BPL hp1 ; Branch to pop 1 off stack and finish. LDA #"-" STA 0,X BRA HOLD + 2 ;------------------- HEADER "#S", NOT_IMMEDIATE ; ( d1 -- d0 ) sharpS: DWL nest ; Just does # enough times to shs1: DWL SHARP, _2DUP, D0EQU ; reduce the input double DWL Zbranch, shs1, unnest ; number to 0. ;------------------- HEADER "D.R", NOT_IMMEDIATE ; ( d width -- ) D.R: DWL nest, TO_R, DUP2R, DABS, LESSsharp, sharpS, R_FR, SIGN, DWL sharpGREATER, R_FR, OVER, MINUS, SPACES, TYPE, unnest ;------------------- HEADER "D.", NOT_IMMEDIATE ; ( d -- ) D.: DWL nest, ZERO, D.R, SPACE, unnest ;------------------- HEADER ".", NOT_IMMEDIATE ; ( n -- ) .: DWL nest, StoD, D., unnest ;------------------- HEADER "?", NOT_IMMEDIATE ; ( addr -- ) ?: DWL nest, FETCH, ., unnest ;------------------- HEADER "U.", NOT_IMMEDIATE ; ( u -- ) U.: DWL nest, ZERO, D., unnest ;------------------- HEADER "U.R", NOT_IMMEDIATE ; ( u width -- ) U.R: DWL nest, ZERO, SWAP, D.R, unnest ;------------------- HEADER ".R", NOT_IMMEDIATE ; ( n width -- ) .R: DWL nest, TO_R, StoD, R_FR, D.R, unnest ;------------------- so only four of them are primitives.
_________________ http://WilsonMinesCo.com/ lots of 6502 resources The "second front page" is http://wilsonminesco.com/links.html . What's an additional VIA among friends, anyhow?
|
|