home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI10.ARJ / ictari.10 / C / BOINKOUT / LASINIT.C < prev    next >
C/C++ Source or Header  |  1987-04-22  |  2KB  |  75 lines

  1. /****    init.c - Laser program/accessory startup *****/
  2.  
  3. /* Base page definitions */
  4. #define codelen 12        /* Code segment length */
  5. #define datalen 20        /* Data segment length */
  6. #define bsslen 28        /* Bss  segment length */
  7. #define par_bp 36        /* Parent basepage */
  8.  
  9. extern _main(), main(), _dbuginit();
  10. char *_base;            /* points to base page of program */
  11. int _app;                /* 0xff=program is app, 0=program is accessory */
  12.  
  13. long _progsize;            /* since I must calc this, I will leave this */
  14.                         /* value handy for terminate-stay resident progs */
  15. int errno;
  16. extern char _stack[];
  17. extern long _stksize;
  18.  
  19. asm {
  20.     _main:
  21.         ; I know I am running as a desk accessory by 2 tests:
  22.         ; if my initial stack is zero, or if I have a null
  23.         ; pointer to my parents basepage (All PROGRAMS have a
  24.         ; parent, be it the desktop or another program.
  25.         ; Null stack is undocumented, though! (so don't count on it)
  26.         ; note 2:
  27.         ; At startup, a program may get its basepage address from the
  28.         ; stack, ie
  29.         ;
  30.         ;            move.l 4(sp),A5        ;A5 points to basepage
  31.         ;
  32.         ; For an accessory, however, the stack pointer is null and
  33.         ; this generates a bus error, so we assume that the basepage
  34.         ; immediately precedes the program, which is true if the
  35.         ; desktop or most shells executed the program. The following
  36.         ; code could be tweaked to accomodate discontiguous basepages
  37.         ; if necessary.
  38.  
  39.         lea        _main, A5        ;Compute basepage address
  40.         suba    #0x100, A5        ;subtract size of basepage
  41.         lea        _stack,A7
  42.         adda.l    _stksize,A7        ;set up our stack
  43.  
  44.         moveq    #0,D5
  45.         tst.l   par_bp(A5)        ;Parent basepage pointer clear if ACC
  46.         sne        D5                ;D5 set if application
  47.         move    D5,_app
  48.         beq     cont            ;is an accessory
  49.  
  50.     app:
  51.             ; if we are here, our thing is being run as a program, not
  52.             ; an accessory.
  53.  
  54.         move.l    codelen(A5),D0
  55.         add.l    datalen(A5),D0
  56.         add.l    bsslen(A5),D0
  57.         addi.l    #0x100,D0
  58.  
  59.         move.l    D0,_progsize    ;save program size
  60.         move.l    D0,-(A7)        ;amount of memory to keep
  61.         move.l    A5,-(A7)        ;starting at basepage
  62.         clr        -(A7)            ;junk word
  63.         move    #0x4a,-(A7)        ;Mshrink() - return excess storage
  64.         trap    #1
  65.         lea        12(A7),A7
  66.  
  67.     cont:
  68.         move.l    A5, _base;        ;so user progs can find basepage
  69.  
  70.         jsr        main            ;call applications entry point
  71.  
  72.         clr        -(A7)            ;do Pterm0() on return
  73.         trap    #1
  74. }
  75.