X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsega.c;h=27c74b2d6a135d3ab7a6bb9fe4b8bf501c59b542;hb=62f639bbb2ed0d2d1a4340ab9a7d87f537fc4eda;hp=a460ff52ef3893d83bedfbcf3b42016ba12f09c2;hpb=6706a67fb8176362055d99c4b0b34294d53a852c;p=16.git diff --git a/src/sega.c b/src/sega.c index a460ff52..27c74b2d 100644 --- a/src/sega.c +++ b/src/sega.c @@ -1,36 +1,55 @@ -#include -#include -#include +#include +#include +#include + +struct list { + struct list __based(__self) *next; + int value; +}; + +void main(int argc, char *argv[]) + { + int i; + __segment segu; + void __based(__self) *pee; + struct list __based(segu) *head; + struct list __based(segu) *p; + + /* allocate based heap */ + segu = _bheapseg( 65536 ); + if( segu == _NULLSEG ) { + printf( "Unable to allocate based heap\n" ); + exit( 1 ); + } + + /* create a linked list in the based heap */ + head = 0; + for( i = 1; i < 4096; i++ ) { + p = _bmalloc( segu, sizeof( struct list ) ); + if( p == _NULLOFF ) { + printf( "_bmalloc failed\n" ); + break; + } + p->next = head; + p->value = i; + head = p; + } + + /* traverse the linked list, printing out values */ + for( p = head; p != 0; p = p->next ) { + if(p==head || p->next==0 || p==pee){ + printf("Segu = %04X", p); printf( " Value = %d\n", p->value ); + } + } -typedef struct { - struct a __based( __self ) *next; - int number; -}a_t; - -void PrintLastTwo( a_t far *list ); - -void -main(int argc, char *argv[]) -{ - a_t far *list; - PrintLastTwo(list); -} - - void PrintLastTwo( a_t far *list ) - { - __segment seg; - a_t __based( seg ) *aptr; - - seg = FP_SEG( list ); - aptr = FP_OFF( list ); - for( ; aptr != _NULLOFF; aptr = aptr->next ) { - if( aptr->next == _NULLOFF ) { - printf( "Last item is %d\n", - aptr->number ); - } else if( aptr->next->next == _NULLOFF ) { - printf( "Second last item is %d\n", - aptr->number ); - } - } - } - \ No newline at end of file + printf("program=%FP\n", *argv[0]); + printf("seg=%04X\n", segu); + + /* free all the elements of the linked list */ + for( ; p = head; ) { + head = p->next; + _bfree( segu, p ); + } + /* free the based heap */ + _bfreeseg( segu ); +}