6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat May 18, 2024 3:18 pm

All times are UTC




Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Wed Jul 08, 2020 4:03 am 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
So, one trick with WIDTH is to create hexadecimal-literal words $xx and $xxxx with WIDTH set to 1. They'd be IMMEDIATE, and parse their text after the first character as a hexadecimal literal. I forget where I came across this trick, and I don't believe I ever used it.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 08, 2020 8:35 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 861
I've never tried this and Fleet Forth does not have WIDTH , but it does set the high bit of the count and the high bit of the last character in the name ( to keep (FIND) fast ) so the following would accomplish the same thing in Fleet Forth:
Code:
: $  ( -- N )
   BASE @ >R HEX HERE 1+ -NUMBER R> BASE ! ?HUH
   DROP STATE @ 0EXIT [COMPILE] LITERAL ; IMMEDIATE
// GIVE $ A COUNT OF 3
LATEST 2 TOGGLE
: $  ( -- N )
   [COMPILE] $XX ; IMMEDIATE
// GIVE THIS $ A COUNT OF 5
LATEST 4 TOGGLE

Since this is for a Commodore 64, just read each double forward slash as a backslash.


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 19, 2020 3:09 am 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 575
I've been playing around with Fig Forth and one thing mystifies me. I can't see how it initializes the X register for the argument stack. Does it just use page zero as a circular buffer and starts with whatever X value has originally? Or does it somehow stealth initializes it?


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 19, 2020 3:16 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8438
Location: Southern California
Martin_H wrote:
I've been playing around with Fig Forth and one thing mystifies me. I can't see how it initializes the X register for the argument stack. Does it just use page zero as a circular buffer and starts with whatever X value has originally? Or does it somehow stealth initializes it?

It's initialized in SP! (at $5E8) which is called from ABORT (which is at $121D).

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 19, 2020 2:17 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 575
Thanks. I was looking for an ldx instructions, but I see how it's done now.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 18, 2021 8:06 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Here is a slight speed improvement for CMOVE

From this
Code:
   LDA #3
   JSR SETUP

L370   CPY N
   BNE L375
   DEC N+1
   BPL L375
   JMP NEXT

L375   LDA (N+4),Y
   STA (N+2),Y
   INY
   BNE L370

   INC N+5
   INC N+3
   JMP L370

To this
Code:
   LDA #3
   JSR SETUP   ; Y-reg returns with zero

L370   CPY N
   BEQ L380

L375   LDA (N+4),Y
   STA (N+2),Y
   INY
   BNE L370

   INC N+3
   INC N+5
   BNE L370      ; always

L380   DEC N+1
   BPL L375
   JMP NEXT


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 18, 2021 8:58 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8438
Location: Southern California
Since CMOVE and CMOVE> are usually used for segments of less than a page, I wrote words QCMOVE (for "quick CMOVE) and QCMOVE> to be faster. Here's QCMOVE:
Code:
     JSR  QSETUP       ; Put "TO" addr in N, and "FROM" addr in N+2)
     LDY  #0
 2$: TYA
     CMP  0,X
     BEQ  1$
     LDA  (N+2),Y
     STA  (N),Y
     INY
     BRA  2$
 1$: JMP  POP3
where QSETUP is:
Code:
QSETUP: LDA  2,X
        STA  N
        LDA  3,X
        STA  N+1
        LDA  4,X
        STA  N+2
        LDA  5,X
        STA  N+3
        RTS
(which is used by other things as well, and doesn't do the looping and testing like SETUP does).
Here's QCMOVE>:
Code:
     JSR  QSETUP       ; Put "TO" addr in N, and "FROM" addr in N+2
     LDY  0,X
 2$: DEY
     CPY  #$FF
     BEQ  1$
     LDA  (N+2),Y
     STA  (N),Y
     BRA  2$
 1$: JMP  POP3

Hopefully I copied it correctly from a less-readable form.

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 18, 2021 10:48 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
I had broken the code, but nobody complained. Shows the fix with indented lines.

IamRob wrote:
Code:
For a slightly quicker method, but a few more bytes, this could be done.

QSETUP:
      CLC
   LDA  2,X
      ADC 0,X   ; add count
   STA  N
   LDY  3,X
   DEY      ; note hi-bytes are decremented
   STY  N+1

   LDA  4,X
      ADC #0
   STA  N+2
   LDY  5,X
   DEY      ; note hi-bytes are decremented
   STY  N+3
   RTS


     JSR QSETUP
     LDA 0,X
     EOR #$FF      ; reverse count to count up to 0
     TAY
      INY      ; count correction due to EOR

]LP LDA  (N+2),Y
     STA  (N),Y
     INY
     BNE  ]LP

     JMP  POP3


Last edited by IamRob on Wed Mar 24, 2021 7:49 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 19, 2021 12:03 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
ProForth, which is based on FigForth but is fully compatible with the '79 standard, and I have also added some '83 standard words, for some further enhanced compatibility.

One of the changes I have made that doesn't seem to have broken any compatibility with FigForth, is to have -FIND return with the CFA instead of the PFA.

Steps to do that are:
' (find) 36 dup c@ ( it is decimal 36 ($24)( make sure it says 5)( do a memory DUMP if not showing the 5 and adjust the 36)
' (find) 36 dup + 3 swap c! ; ( change it to 3)

once you do that you can now see that (find) has changed to the CFA and requires 36 2+
' (find) 38 dup c@

next change these definitions from
: cfa pfa 2 - ;
: lfa pfa 4 - ;
: nfa pfa 5 - -1 traverse ;
: pfa traverse 5 + ;

to
: cfa ; ( make this into a NULL word)
: lfa 4 - ;
: nfa 3 - -1 traverse
: pfa 1 traverse 5 + ;
or
: pfa dup @ 1f and + 5 + ;

INTERPRET has two occurrences of CFA that are no longer needed, but since the CFA word above was made into a NULL word, they have no effect.

Make sure you are saving this on a backup of the Forth System.

At this point, the only word that is broken after all the changes is (;CODE). (;CODE) has PFA CFA, but since CFA is now a NUL word, the CFA word cannot be used. A couple of options: one is to make 2- a word definition higher up in memory and manually link to it or since (;CODE) is so short, just make a new definition for it:

: (;CODE) ( --- ) R> LATEST PFA 2 - ! ;

At this point, nothing is broken and we are now closer to being able to use new words that are supported by newer standards which were created to aid in Forth compatibility across platforms.

words that can now be used are
: >body 2+ ;


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: