Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth Mac > Re: Third draft...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 17 of 17 Topic 129 of 158
Post > Topic >>

Re: Third draft of Structures

by "Tim Trussell" <tgtrussell@[EMAIL PROTECTED] > Oct 23, 2006 at 08:19 AM

I have been using the EDO system by GT Hawkins, circa 1987, which
uses the second of the two creation conventions you show, namely:

        STRUCT{
          1 CELLS FIELD: P.X
          1 CELLS FIELD: P.Y
        }STRUCT POINT   \ -- len

Instead of STRUCT{, EDO uses S{

Instead of }STRUCT, EDO uses }S

Instead of FIELD: or OFFSET, EDO uses :: which, as Stephen Pelc
notes, has exactly the same definition of FIELD:

It has a number of additional 'features' that lend it to use in a
variety of programming utilizations.

One of those additional features is a barebones vector array
creation that takes a basic structure and extends it for use in a
much larger environment.

My including this isn't meant to obscure the thread, but rather to
give another example of what's been done.  Since there isn't a
standard at the moment, and since most all structure packages do
pretty much the same things, I haven't worried about changing the
names of the definitions in this package to conform to any other
system.

\ ---[ EDO - Extended Data Objects ]---------------------------------
\ Note that this listing is different from the basic EDO file that is
\ present on the Taygeta archive site, as I have included definitions
\ that I use in my day-to-day programming tasks
\ -------------------------------------------------------------------

: [EDO] ;

   1 CONSTANT 1BYTE
cell CONSTANT 1WORD ( -- n )
   8 CONSTANT 1FLOAT

: BYTE* ;
: WORD+   ( n -- n+WORD )  1WORD + ;
: WORD*   ( n -- n*WORD )  1WORD * ;
: FLOAT*  ( n -- n*FLOAT ) FLOATS ;

: DEF     ( size -- )      CONSTANT ;

: S{      ( -- 0 )         0 ;

: ::      ( offset object-definition -- offset )
  CREATE OVER , + DOES> @[EMAIL PROTECTED]
 + ;

: }S      ( size -- )      CONSTANT ;


\ ---[ Define Vector/Operator ]--------------------------------------

: []    ( object-definition #objects -- )
  OVER * CONSTANT               \ define the vector
  CREATE ,                      \ define the vector operator
  DOES> @[EMAIL PROTECTED]
 * + ;

\ ---[ Extended Definitions ]----------------------------------------

  1BYTE DEF {1BYTE}-DEF
2 BYTE* DEF {2BYTE}-DEF
4 BYTE* DEF {4BYTE}-DEF
  1WORD DEF {1WORD}-DEF
2 WORD* DEF {2WORD}-DEF
8 BYTE* DEF {1FLOAT}-DEF

\ ---[ Usage Example ]-----------------------------------------------

\ Define the structure

S{
  {1BYTE}-DEF :: p.red
  {1BYTE}-DEF :: p.green
  {1BYTE}-DEF :: p.blue
}S palette-obj

\ Define a vector array of this structure

palette-obj 256 [] palette[]-obj palette-ndx

\ Create the array in the dictionary

create Palette[] here palette[]-obj dup allot 0 fill

\ Access the vector array

: GetPalette    \ loads palette data from the VGA
  256 0 do
    i $03C7 P!
    $03C9 P@[EMAIL PROTECTED]
 Palette[] i palette-ndx p.red   C!
    $03C9 P@[EMAIL PROTECTED]
 Palette[] i palette-ndx p.green C!
    $03C9 P@[EMAIL PROTECTED]
 Palette[] i palette-ndx p.blue  C!
  loop
;

: SetPalette    \ sets VGA palette to data in Palette[]
  256 0 do
    i $03C8 P!
    Palette[] i palette-ndx
    dup p.red   C@[EMAIL PROTECTED]
 $03C9 P!
    dup p.green C@[EMAIL PROTECTED]
 $03C9 P!
        p.blue  C@[EMAIL PROTECTED]
 $03C9 P!
  loop
;
 




 17 Posts in Topic:
RfD: Third draft of Structures
stephenXXX@[EMAIL PROTECT  2006-08-30 10:03:23 
Re: RfD: Third draft of Structures
anton@[EMAIL PROTECTED]   2006-09-02 16:25:43 
Re: Third draft of Structures
"Charles Melice"  2006-10-03 16:25:26 
Re: Third draft of Structures
"jacko" <jac  2006-10-03 15:23:33 
Re: Third draft of Structures
"Charles Melice"  2006-10-04 14:23:36 
Naming of Standard words
"Ed" <nospam  2006-10-05 12:34:42 
Re: Naming of Standard words
"Charles Melice"  2006-10-05 11:29:08 
Re: Third draft of Structures
"jacko" <jac  2006-10-03 15:32:49 
Re: Naming of Standard words
"slava@[EMAIL PROTEC  2006-10-04 20:32:28 
Re: Naming of Standard words
ward@[EMAIL PROTECTED] (  2006-10-05 07:01:33 
Re: Naming of Standard words
"J Thomas" <  2006-10-05 05:13:43 
Re: Naming of Standard words
"slava@[EMAIL PROTEC  2006-10-05 10:45:16 
Re: Naming of Standard words
Elizabeth D Rather <er  2006-10-05 12:19:50 
Re: Third draft of Structures
"Ian Osgood" &l  2006-10-20 07:19:16 
Re: Third draft of Structures
Bernd Paysan <bernd.pa  2006-10-20 18:18:21 
Re: Third draft of Structures
"Ed" <nospam  2006-10-23 15:10:40 
Re: Third draft of Structures
"Tim Trussell"   2006-10-23 08:19:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 5:52:37 CDT 2008.