Questions about the stack and block editor.

75 views
Skip to first unread message

Si Brindley

unread,
Jan 26, 2014, 6:11:14 PM1/26/14
to fign...@googlegroups.com
I'm gradually getting to grips with this thing, spending a bit of time each evening.  I'd like to check my understanding of a few things, please. I thought I'd number my bullets in case anyone fancies referencing any particular rambling when they reply :)

  • The initial stack and underflow protection:
    1. I'd never used a stack based system before, so it's all new to me. (Having said that, years ago my boss let me play with his beloved HP 12C RPN calculator which he thought was "Brilliant!" and I thought was "Weird!")
    2. I'm enjoying reading the Jupiter Ace manual and comparing the FIGnition to it, where I've learned that the Ace could detect a stack underflow and gave an "ERROR 2" when it did. The Ace manual says "Stack underflow isn't always detected immediately, because the Ace only checks for it at certain times. Between these times it might well have dipped below the bottom of the stack without realising it, but this doesn't matter because there are some nonsense numbers under the stack for the computer to play with." 
    3. My experimentation leads me to believe FIGnition doesn't try to detect stack underflow, but does have some numbers in the stack when I boot it up.  In fact, if I repeatedly "dot" to print the top of the stack recursively, I get something like the following sequence: 990, -255, 257, 257, 257, -256, 0, 0, 0, -128, -32640, -32640, -32640, -32640, 257, 257, 257, -257, -32640, -32640, -32640, -32640, 257, 257, 257 511 0 0 0 0 255 -32640 -32640 -32513 240 -3856 -3856 -3856 3855 3855 3855 255 -1 -1 -1 -256 -256 -256 -256 -770 -1 -1 -1 16255 -1-1 -1 -1 -1 -1 -260 -1 -1 -1 32575 8224 8224 **GIBBERISH**
    4. So what are these numbers? I'd love to know where they come from.  They mainly seem to be quite base-2 flavoured for a while but the initial "990" seems out of place. And there are repeating patterns which makes me wonder if I'm just wandering into the text interpreter recursively.  I sort of feel as if my FIGnition should be singing "Daisy, Daisy" to me as I eventually appear to hit video memory, the screen goes squiffy and FIGnition crashes. Are the numbers there as a bit of underflow buffer?  Do they have any particular meaning? Perhaps they are the remnants of using UDGs to display the boot logo and the "@nichemachines 2011-2013" welcome… or I'm just hitting the UDG part of VRAM anyway..?
    5. On discovering this, obviously I defined a word to reliably crash FIGnition just for fun : crash 999 0 do . loop ;
    6. This isn't particularly useful but made me nostalgic about entering "RANDOMIZE USR 0" on a ZX Spectrum to reset it. Anyone remember that?
  • 2 The block editor.
    1. Zero. From the "Use It" page: "Zero is command z: SW2+SW6 then SW8+SW4. It clears the editor's text."  Now what I would expect/like this to do is to clear the block, making its length 0 characters. What actually happens is the length counter goes to 0, but the display of the block doesn't clear on-screen - the cursor just moves to the top left position.  If I go back into the block to edit it, the length is actually 511 (i.e. full) and I can't type anything new into the block unless I move along / down a bit and delete some invisible characters first. This leads me to believe that using the "zero" command doesn't so much empty the block as fill it with space characters. Is that right?
    2. Erase. I can't seem to perform an "Erase".  If I press <Control> for the Cmd? prompt and type <E> then <y>, the cursor simply returns to the editor with no other effect.  Have I broken something?  (I think it worked the first time I tried it, before I had FIGkeys).
    3. Raw characters. I just don't understand this bit. "You can enter raw characters by typing Command, then a series of digits from 0..7 and then <enter>"  Well, if I press <Control> for Cmd? and then press a number key,  I get the corresponding UDG character immediately.  I must have missed something…?

Many thanks for any comments or clarifications!
 - Si

Julian Skidmore

unread,
Jan 27, 2014, 2:30:51 AM1/27/14
to FIGnition
Hi Si,

FIGnition doesn't yet have stack underflow or overflow protection, I intend to implement that for revision 0.9.9. The challenge is to do that without it costing any performance - which I think I can now do :-) !

I could easily tell you what those numbers that appear to be on the stack are, but as you say since they look a bit binary - why not set the base to 2 ( 2 base !) and then display them ( I suggest you display no more than 64) :-)

There are other ways too of crashing FIGnition (it's not hard ;-) ): try : crash 0 >r ; crash <exe>

The block editor - it's a bug in the z command, sorry about that. It'll be fixed in 0.9.9. You can create an external command to zero a flash block: : zblk dup blk> 0 -512 ! swap >blk ;

This reads in the block you want to zero (returning the physical block number that would be used to write it back); then it clears the first byte of the block and then it stores the block back.

The use it section is out of date, you're better off using the newer command reference:

https://sites.google.com/site/libby8dev/fignition/fuze/usermanual

-cheers from Julz.


--
You received this message because you are subscribed to the Google Groups "FIGnition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fignition+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
                             
                  The DIY 8-bit computer from nichemachines™

NmLogoMini.jpg
FIG - black on whiteMini.jpg

carl

unread,
Jan 27, 2014, 4:38:11 AM1/27/14
to fign...@googlegroups.com

Hi Si, 

I get a crash course on stacks and crashing when I put loop drop and not drop loop, I find that crashing tends not to harm the FIGniton unless you are fetching and calling +vram+ and looping, then the saved blocks in the memory can get corrupted. 

Also quit when executed 13+ times can cause a crash, but this is easily patched by entering  $4FB $5D in your code.

Julz has already said that he will sort this out for 0.9.9, along with cmd+z and cmd+E+y 

to perform a chip erase, I roll back to firmware 0.9.6 then reinstall 0.9.8, but this is in extreme cases, certainly not a daily occurrence! 
I might get my drops and loops the right way around one of these days.

Regards, 
Carl.



 

fignition_progs.png

Mark Wills

unread,
Jan 27, 2014, 8:48:50 AM1/27/14
to fign...@googlegroups.com

Hi Julz

The place to put the stack check is in QUIT.

QUIT (rather inappropriately named) is the permanent loop that holds the entire system together. It normally looks something like this:

: QUIT ( -- )
  BEGIN
    R0 RP! DEPTH >R S0 SP!
    R> 0< ABORT" STACK UNDERFLOW"
    INTERPRET
AGAIN ;

For the benefit of the curious, this is an endless loop that:

* fetches the start address of the return stack (R0)
* stores that address in the return stack pointer (the return stack has now been reset to its power-up location)
* gets the depth of the data stack and pushes it onto the return stack
* resets the data stack to its power up location (that's why we store the depth on the return stack! )
* gets the saved depth from the return stack
* if less than 0 then there was a stack underflow,  so issue an error.
* otherwise run the interpreter/compiler

That's about it. That's all my system does! You're free to underflow/overflow the stacks in a running program as much as you like. You're free to screw up in forth in any way you can. There's no hand-holding! :-)

Mark

Si Brindley

unread,
Feb 4, 2014, 6:23:24 PM2/4/14
to fign...@googlegroups.com
OK, come on then Julz, what are the numbers in the stack (apart from a bit symmetrical)? Please put me out of my misery.

Julian Skidmore

unread,
Feb 5, 2014, 1:49:22 AM2/5/14
to FIGnition

Hi Si,

Sure thing! When you boot up FIGnition the stack pointer will be set to the bottom of the stack = s0 = roughly 1019. Below it are the bytes for the 16 udgs. So that's what's being displayed: character patterns as numbers, 4 numbers per udg. After 64 of these (128 bytes), the stack starts to hit the screen, but since the screen gets updated as you type, it'll mess up the stack and FIGnition will crash :-)

Hope this makes sense!

-cheers julz

Si Brindley

unread,
Feb 5, 2014, 2:24:03 AM2/5/14
to fign...@googlegroups.com
Thanks Julz. In that case I feel like I was pretty close with my original guesses!

This is a fun way to really see the workings of the machine in a raw way. Personally I would incorporate it into the beginners' tutorial one day for its educational value, since it demonstrates how the stack pointer really exists in there next to the UDGs and video memory in one continuum - it makes the memory model diagrams "real".

- Si
 

Julian Skidmore

unread,
Feb 5, 2014, 4:16:28 AM2/5/14
to fign...@googlegroups.com
Hi Si,

> Thanks Julz. In that case I feel like I was pretty close with my original
> guesses!

Yes, there was a reason for the symmetry.

> This is a fun way to really see the workings of the machine in a raw way.
> Personally I would incorporate it into the beginners' tutorial one day for
> its educational value, since it demonstrates how the stack pointer really
> exists in there next to the UDGs and video memory in one continuum - it
> makes the memory model diagrams "real".

Indeed, there's a lot of rawness in FIGnition :-) It means, for
example, that you can use internal peeks and pokes ( ic@, i@, ic! and
i!) to reset the stack pointer:

sp0 sp i!

That you can have direct access to the registers (sp actually is the
address of a register, sp=26 I think, it's the x register on the AVR -
registers on an AVR can be addressed as memory locations). Also you
can use the same commands to activate the LED: 31 40 ic! 100 pause 15
40 ic!

And you can use the same commands to access lots of the hardware in
FIGnition, including i2c; timers etc (though timers 1 and 2 are
largely used by the video system) or the video ram ( e.g. $1F1E vram
i!) and ultimately, when interrupts have been hooked into the Forth
system; interrupts :-)

I'm getting near the end of the hardware description manual (draft
edition) at the moment - stay tuned for an announcement of some better
FIGnition documentation :-)

-cheers from Julz
>>>>> - *1 The initial stack and underflow protection:*
>>>>> 1. I'd never used a stack based system before, so it's all new to
>>>>> me. (Having said that, years ago my boss let me play with his
>>>>> beloved HP
>>>>> 12C RPN calculator which he thought was "Brilliant!" and I
>>>>> thought was
>>>>> "Weird!")
>>>>> 2. I'm enjoying reading the Jupiter Ace manual and comparing the
>>>>> FIGnition to it, where I've learned that the Ace could detect a
>>>>> stack
>>>>> underflow and gave an "ERROR 2" when it did. The Ace manual says
>>>>> *"**Stack underflow isn't always detected immediately, because
>>>>> the Ace only checks for it at certain times. Between these times
>>>>> it might
>>>>> well have dipped below the bottom of the stack without realising
>>>>> it, but
>>>>> this doesn't matter because there are some nonsense numbers under
>>>>> the stack
>>>>> for the computer to play with."*
>>>>> 3. My experimentation leads me to believe FIGnition doesn't try
>>>>> to detect stack underflow, but does have some numbers in the
>>>>> stack when I
>>>>> boot it up. In fact, if I repeatedly "dot" to print the top of
>>>>> the stack
>>>>> recursively, I get something like the following sequence: 990,
>>>>> -255, 257,
>>>>> 257, 257, -256, 0, 0, 0, -128, -32640, -32640, -32640, -32640,
>>>>> 257, 257,
>>>>> 257, -257, -32640, -32640, -32640, -32640, 257, 257, 257 511 0 0
>>>>> 0 0 255
>>>>> -32640 -32640 -32513 240 -3856 -3856 -3856 3855 3855 3855 255 -1
>>>>> -1 -1 -256
>>>>> -256 -256 -256 -770 -1 -1 -1 16255 -1-1 -1 -1 -1 -1 -260 -1 -1 -1
>>>>> 32575
>>>>> 8224 8224 **GIBBERISH**
>>>>> 4. So what are these numbers? I'd love to know where they come
>>>>> from. They mainly seem to be quite base-2 flavoured for a while
>>>>> but the
>>>>> initial "990" seems out of place. And there are repeating
>>>>> patterns which
>>>>> makes me wonder if I'm just wandering into the text interpreter
>>>>> recursively. I sort of feel as if my FIGnition should be singing
>>>>> "Daisy,
>>>>> Daisy" to me as I eventually appear to hit video memory, the
>>>>> screen goes
>>>>> squiffy and FIGnition crashes. Are the numbers there as a bit of
>>>>> underflow
>>>>> buffer? Do they have any particular meaning? Perhaps they are
>>>>> the remnants
>>>>> of using UDGs to display the boot logo and the "@nichemachines
>>>>> 2011-2013"
>>>>> welcome... or I'm just hitting the UDG part of VRAM anyway..?
>>>>> 5. On discovering this, obviously I defined a word to reliably
>>>>> crash FIGnition just for fun *: crash 999 0 do . loop ;*
>>>>> 6. This isn't particularly useful but made me nostalgic about
>>>>> entering "RANDOMIZE USR 0" on a ZX Spectrum to reset it. Anyone
>>>>> remember
>>>>> that?
>>>>>
>>>>>
>>>>> - *2 The block editor.*
>>>>>
>>>>>
>>>>> 1. *Zero. *From the "Use
>>>>> It<https://sites.google.com/site/libby8dev/fignition/documentation/use-it>"
>>>>> page: *"**Zero is command z**: SW2+SW6 then SW8+SW4. It clears
>>>>> the editor's text."* Now what I would expect/like this to do is
>>>>> to clear the block, making its length 0 characters. What actually
>>>>> happens
>>>>> is the length counter goes to 0, but the display of the block
>>>>> doesn't clear
>>>>> on-screen - the cursor just moves to the top left position. If I
>>>>> go back
>>>>> into the block to edit it, the length is actually 511 (i.e. full)
>>>>> and I
>>>>> can't type anything new into the block unless I move along / down
>>>>> a bit and
>>>>> delete some invisible characters first. This leads me to believe
>>>>> that using
>>>>> the "zero" command doesn't so much *empty* the block as *fill it
>>>>> with space characters*. Is that right?
>>>>> 2. *Erase. *I can't seem to perform an "Erase". If I press
>>>>> <Control> for the Cmd? prompt and type <E> then <y>, the cursor
>>>>> simply
>>>>> returns to the editor with no other effect. Have I broken
>>>>> something? (I
>>>>> think it worked the first time I tried it, before I had
>>>>> FIGkeys).
>>>>> 3. *Raw characters.* I just don't understand this bit. *"**You
>>>>> can enter raw characters by typing Command, then a series of
>>>>> digits from
>>>>> 0..7 and then <enter>" *Well, if I press <Control> for Cmd? and
>>>>> then press a number key, I get the corresponding UDG character
>>>>> immediately. I must have missed something...?
>>>>>
>>>>>
>>>>> Many thanks for any comments or clarifications!
>>>>> - Si
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "FIGnition" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to fignition+...@googlegroups.com.
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> The DIY 8-bit computer from nichemachines(tm)
>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups
>>> "FIGnition" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an
>>> email to fignition+...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "FIGnition" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to fignition+...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to the Google Groups
> "FIGnition" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to fignition+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>


--

The DIY 8-bit computer from nichemachines(tm)
Reply all
Reply to author
Forward
0 new messages