X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Fsega.c;h=3a271cd2a94be177795a3fc0e4057fe7c38620f4;hb=663e52d5641538fc75ccdad3ba2529a27e8e0ff8;hp=a460ff52ef3893d83bedfbcf3b42016ba12f09c2;hpb=6706a67fb8176362055d99c4b0b34294d53a852c;p=16.git diff --git a/src/sega.c b/src/sega.c old mode 100644 new mode 100755 index a460ff52..3a271cd2 --- a/src/sega.c +++ b/src/sega.c @@ -1,36 +1,67 @@ -#include -#include -#include +#include +#include +#include + +struct list { +#ifdef __WATCOMC__ + struct list __based(__self) *next; +#endif +#ifdef __BORLANDC__ + struct list _seg *next; +#endif + int value; +}; + +void main(int argc, char *argv[]) +{ + int i; +#ifdef __WATCOMC__ + __segment segu; + void __based(__self) *pee; + struct list __based(segu) *head; + struct list __based(segu) *p; +#endif +#ifdef __BORLANDC__ + void _seg *pee; + struct list _seg *head; + struct list _seg *p; +#endif + + /* 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 ); +}