6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 4:56 am

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Auto loading screens
PostPosted: Fri Jan 22, 2021 6:07 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
I am baffled by this one. I set COLD to a word to load some screens before calling ABORT.

I do all the resets that QUIT and ABORT do, but the system just freezes.

I am using this word to try to load screens. It works perfectly fine at the prompt, but doesn't work being called from COLD. Am I missing some other reset? The Return Stack pointer is reset by COLD, and is not necessary here.

: autoload sp! hex 0 blk ! 0 in ! dr0 [compile] [ 1 load abort ;


Does anyone else have the ability to autoload screens from startup?


Top
 Profile  
Reply with quote  
 Post subject: Re: Auto loading screens
PostPosted: Fri Jan 22, 2021 8:31 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
What's on the stack when the SP! is reached? If the stack is empty, most anything could be getting stored in the data stack pointer, and the first time something goes on the stack, it could be overwriting a ZP variable you need immediately, like IP or W or ...

BTW, I see you have a lot of occurrences of 0 <variable> ! in your code. Forth has a standard word OFF for that, storing a 0 in the cell whose address is on the stack. It definitely gets used more than enough to pay for itself.

_________________
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  
 Post subject: Re: Auto loading screens
PostPosted: Fri Jan 22, 2021 2:28 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
The name SP! is a bit of a misnomer. It initializes the data stack from the user variable S0.


Top
 Profile  
Reply with quote  
 Post subject: Re: Auto loading screens
PostPosted: Fri Jan 22, 2021 8:01 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
JimBoyd wrote:
The name SP! is a bit of a misnomer. It initializes the data stack from the user variable S0.

Oh, ok. I see that now in figForth. The '02 Forth I "grew up with" takes a parameter from the stack, so that's what I did in my '816 Forth as well, and the data-stack pointer initialization is in the reset routine, with LDX #S0adr. In theory this looks like it could be troublesome, but I don't remember ever having typed COLD <Return>. It only gets executed after a reset. I'm not finding SP! in Starting Forth or even in ANS Forth ('94).

_________________
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  
 Post subject: Re: Auto loading screens
PostPosted: Fri Jan 22, 2021 8:47 pm 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
GARTHWILSON wrote:
What's on the stack when the SP! is reached?

In FigForth, SP! is a word definition for : SP! 0 SP ! ;. The code works up until LOAD is executed. LOAD calls INTERPRET. The normal startup way does this: COLD to ABORT to QUIT to QUERY to INTERPRET.
Quote:
BTW, I see you have a lot of occurrences of 0 <variable> ! in your code. Forth has a standard word OFF for that, storing a 0 in the cell whose address is on the stack. It definitely gets used more than enough to pay for itself.

I agree. It would make a good primitive. I am still moving code around to get the bare Forth system as small as possible, so now would be a good time to add it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Auto loading screens
PostPosted: Fri Jan 22, 2021 11:09 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
IamRob wrote:
I am baffled by this one. I set COLD to a word to load some screens before calling ABORT.


Are you replacing ABORT with this word or do you set COLD to execute it?
Quote:
I do all the resets that QUIT and ABORT do, but the system just freezes.

I am using this word to try to load screens. It works perfectly fine at the prompt, but doesn't work being called from COLD. Am I missing some other reset? The Return Stack pointer is reset by COLD, and is not necessary here.

: autoload sp! hex 0 blk ! 0 in ! dr0 [compile] [ 1 load abort ;

Could you show the source for COLD and where AUTOLOAD is executed?
Quote:
Does anyone else have the ability to autoload screens from startup?

Yes. If I wanted to autoload a screen at startup in Fleet Forth, I would do the following:
Code:
: AUTOLOAD
   DOPEN 1 LOAD ;
' AUTOLOAD IS INITIAL

I would then save the system. When this version of Fleet Forth is loaded, it would automatically load block #1 from drive 8. The disk with the source screens for what I wanted to load would need to be in drive 8 and I would need to load this Fleet Forth from another drive, such as drive 9.
INITIAL is a deferred word that is normally set to the no-op NOOP . Here is the source for Fleet Forth's COLD .
Code:
HEX // USER COLD START
: COLD  ( -- )
   SAVE-BUFFERS  EMPTY
   ACLOSE     // CLOSE ALL FILES
   >ASSEM
   // POWERUP COLD START
   // PATCH THE BASIC FUSE
   DECIMAL HERE 0 (UD.)  HEX
   FUSE  OVER - SWAP CMOVE>V
   SEI,  CLD,  FF # LDX,  TXS,
   FF87 JSR,  // RAMTAS
   FF8A JSR,  // RESTOR
   FFE7 JSR,  // CLALL
   FF84 JSR,  // IOINIT
   FF81 JSR,  // CINT
   WARM  SPLIT SWAP
      # LDA,  300 STA,
      # LDA,  301 STA,
   'THERE USER.DATA - 1+ # LDY,
   (WARM) JSR,
   >FORTH
   EMPTY 0 DRIVE CONFIGURE
   0C SPACES
   [ HERE 12 + >A ]
   ." C64 FLEET FORTH  COPYRIGHT (C) 1995-2021 BY JAMES BOYD "
   [ HERE 1- >A ]
   INITIAL QUIT ; -2 ALLOT
   0D A> C!  0D0D A> !

There is one line of BASIC in Fleet Forth (the BASIC fuse):
10 SYS XXXXX
In the source for COLD , the line with SEI, is where the BASIC SYS command points.
The lines:
Code:
   [ HERE 12 + >A ]
   [ HERE 1- >A ]
   0D A> C!  0D0D A> !

embed some carriage returns in the startup message.
The subroutine at (WARM) initializes a few things including the data stack and auxiliary stack.
[Edit: fixed a typo.]


Last edited by JimBoyd on Sat Jan 23, 2021 12:26 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Auto loading screens
PostPosted: Fri Jan 22, 2021 11:30 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
GARTHWILSON wrote:
Oh, ok. I see that now in figForth. The '02 Forth I "grew up with" takes a parameter from the stack, so that's what I did in my '816 Forth as well, and the data-stack pointer initialization is in the reset routine, with LDX #S0adr. In theory this looks like it could be troublesome, but I don't remember ever having typed COLD <Return>. It only gets executed after a reset. I'm not finding SP! in Starting Forth or even in ANS Forth ('94).


From what I can find, it's not in the Forth-79, Forth-83, or Ansi Standards although it could be in some systems as a non-standard word to initialize (clear) the data stack just as RP! is in some systems to clear the return stack in the QUIT loop.
Fleet Forth has both SP! and RP! , as well as AP! for the auxiliary stack, and I've wondered if new names were in order.
Since the data stack shouldn't be used until it is initialized, SP! is a primitive:
Code:
CODE SP!  ( -- )
   ' SP0 >BODY C@ # LDY,
   UP )Y LDA,  TAX,
   NEXT JMP,  END-CODE

RP! is also a primitive but AP! is a colon definition.


Top
 Profile  
Reply with quote  
 Post subject: Re: Auto loading screens
PostPosted: Sat Jan 23, 2021 4:03 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
I solved it, but I don't really understand the difference.

the original code was this:
Code:
HOOKED   LDA #<ABORT+2
   STA IP+1
   LDA #ABORT+2
   STA IP

   CLD
   LDA #$6C   ; this is for JMP (addr,x)
   STA W-1
   JMP RSP.RESET+2

and all that was done was to change ABORT+2 to AUTOLOAD+2, but this freezes Forth with a blank screen.

: ABORT SP! HEX DR0 CR ." ProFORTH V4 (128 kb version) CR ." revised June 1, 2020" CR FORTH DEFINITIONS QUIT ;
: AUTOLOAD SP! HEX 0 BLK ! 0 IN ! DR0 1 LOAD ABORT ;

The fix was just to change QUIT at the end of ABORT to AUTOLOAD and add QUIT to AUTOLOAD and it works fine.

: AUTOLOAD SP! HEX 0 BLK ! 0 IN ! DR0 1 LOAD QUIT ;

But I don't understand the difference. LOAD must be pulling something extra off the stacks, but I can't find it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Auto loading screens
PostPosted: Sat Jan 23, 2021 4:51 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
From what I can see, the first time you tried FORTH DEFINITIONS didn't get executed before LOADing a block, but now it does.


Top
 Profile  
Reply with quote  
 Post subject: Re: Auto loading screens
PostPosted: Sun Jan 24, 2021 2:35 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
JimBoyd wrote:
From what I can see, the first time you tried FORTH DEFINITIONS didn't get executed before LOADing a block, but now it does.

I can't be sure now if I tried them or not. I see now that CONTEXT is set up with COLD, but CURRENT is not. I will have to keep that in mind.
But now in getting it to work the way it works now and seeing a lot of advantages, I am not willing to go back and do all that fiddling just to see if that is what I missed.

But thanks for your input.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


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: