home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 303.lha / AssemTools / Include / execlib.i < prev    next >
Text File  |  1980-12-03  |  8KB  |  357 lines

  1.  
  2. * Include file for Amiga metacc macro assembler *
  3. * created 04.03.89 TM - Supervisor Software *
  4. * for handling Exec events *
  5.  
  6. *T
  7. *T    EXECLIB.I * Metacc Include File
  8. *T        Version 1.09
  9. *T          Date 02.07.1989
  10. *T
  11.  
  12. ;  "alloc, free, stop" created -> v1.00 04.03.89
  13. ;  "createport, deleteport, createio, deleteio"
  14. ;     adapted from JM -> v1.01 05.03.89
  15. ;  "stop" changed for a68k, '.l''s remvd -> v1.02 17.03.89
  16. ;  "free" modified to return no NULL in a0
  17. ;     -> v1.03 08.04.89
  18. ;  "format, sformat" created -> v1.04 01.05.89
  19. ;  "format, sformat" modified:
  20. ;     -result to a0,a1 (formerly only a0)
  21. ;     -result is the right one now
  22. ;     -> v1.05 01.05.89
  23. ;  "alloc" debugt; now allocates 4 bytes more than the given
  24. ;     amount for industry needs -> v1.06 27.05.89
  25. ;  "c-, d-port, c-, d-io" modified not to need any special
  26. ;     includes -> v1.07 12.06.89
  27. ;  "beep" from jm (what a WORK to change not to need those
  28. ;     stupid includes, phew!) -> v1.08 12.06.89
  29. ;  "beep" debugt -> v1.085 12.06.89
  30. ;  "createport" debugged by jm -> v1.07 01.07.1989
  31.  
  32.  
  33.  
  34. *B
  35.  
  36. ;  alloc    (allocate memory)
  37. ;  in:        d0=bytesize; d1=requirements;
  38. ;  call:    execlib    alloc;
  39. ;  out:        a0=d0=*memory;
  40. ;  notes:    /allocates 4 bytes more and saves/
  41. ;        /the length, like util.i's/
  42.  
  43. ;  free        (free memory)
  44. ;  in:        a0=*memory;
  45. ;  call:    execlib    free;
  46. ;  notes:    /frees that being allocated by alloc/
  47. ;          /doesn't care even if the pointer be/
  48. ;          /NULL - just doesn't free it/
  49.  
  50. ;  stop        (check whether SIGBREAKB_CTRL_C set)
  51. ;  call:    execlib stop;
  52. ;  out:        p.z=(boolean) result; /z=0: stop/
  53.  
  54. ;  format    (format a string)
  55. ;  in:        a0=*format_string;
  56. ;          a1=*output_buffer;
  57. ;          a2=*data_stream;
  58. ;  call:    execlib    format;
  59. ;  out:        a0=a1=*output_buffer_end==*(NULL);
  60. ;  notes:    /data_stream may contain either words,
  61. ;          longwords, or both. The 'l' specifiers
  62. ;          must be used accordingly./
  63. ;          /The format for the item specifier is:
  64. ;            %-0xxx.yyylc
  65. ;          where
  66. ;            '-' , if specified, left-aligns the value,
  67. ;            '0' right-aligns the value filling the
  68. ;                opening space with zeros,
  69. ;            'xxx' and 'yyy' are the field widths,
  70. ;            'l' is a longword specifer, and
  71. ;            'c' is one of the following:
  72. ;               's': string output, pointer in data stream
  73. ;                    pointer is supposed to be 'l' even if
  74. ;                    the specifier were not used.
  75. ;               'c': single character output
  76. ;               'd': decimal value output
  77. ;               'x': hexadecimal value output/
  78.  
  79. ;  sformat    (format a string)
  80. ;  in:        a0=*format_string;
  81. ;          a1=*output_buffer;
  82. ;          d0..d7=data;
  83. ;  call:    execlib sformat;
  84. ;  out:        a0=a1=*output_buffer_end==*(NULL);
  85. ;  notes:    /the same as "format", but the data is
  86. ;          given in data registers, from d0 and higher,
  87. ;          instead of a specific data stream. All the
  88. ;          data must be specified as longwords, with the
  89. ;          'l' specifier, since the data is entered into
  90. ;          a temporary data stream allocated from stack./
  91.  
  92. ;  beep        (beep)
  93. ;  in:        d0=(uword) period, d1=(uword) cycles;
  94. ;  call:    execlib    beep;
  95. ;  out:        d0=success; /0 = error/
  96. ;  notes:    /"cycles" defines the length of the beep/
  97. ;          /if d0 is -1, default values are used for
  98. ;          both the period (1050) and cycles (300)/
  99.  
  100. ;  createport    (creates a message port)
  101. ;  in:        a0=*name; d0=sizeof;
  102. ;  call:    execlib createport;
  103. ;  out:        a0=d0=*port;
  104. ;  trashed:    a1, d1;
  105.  
  106. ;  deleteport    (deletes a message port)
  107. ;  in:        a0=*port;
  108. ;  call:    execlib    deleteport;
  109. ;  trashed:    a0-a1, d0-d1;
  110.  
  111. ;  createio    (creates an IORequest structure)
  112. ;  in:        a0=*messageport; d0=size;
  113. ;  call:    execlib    createio;
  114. ;  out:        a0=d0=*iorequest;
  115. ;  trashed:    a1, d1;
  116.  
  117. ;  deleteio    (deletes an IORequest structure)
  118. ;  in:        a0=*iorequest;
  119. ;  call:    execlib    deleteio
  120. ;  trashed:    a0-a1, d0-d1;
  121.  
  122. *E
  123.  
  124.  
  125. execlib        macro    name
  126.         ifnc    '\1',''
  127. _EXECF\1    set    1
  128.         bsr    _EXEC\1
  129.         mexit
  130.         endc
  131.  
  132.         ifd    _EXECFbeep
  133. _EXECbeep    push    d1-d7/a0-a5
  134.         moveq    #0,d4
  135.         cmp.w    #-1,d0
  136.         bne.s    _EXECbeep1
  137.         move.w    #1050,d0    ;default period
  138.         move.w    #300,d1        ;default "cycles"
  139. _EXECbeep1    move.l    d0,a5
  140.         move.l    d1,a4
  141.         sub.l    a3,a3        ;success = false
  142.         moveq.l    #-1,d5
  143.         moveq.l    #34,d0
  144.         sub.l    a0,a0
  145.         execlib    createport
  146.         move.l    d0,d7
  147.         beq    _EXECbeep.c
  148.         moveq.l    #68,d0
  149.         move.l    d7,a0
  150.         execlib    createio
  151.         move.l    d0,d6
  152.         beq.s    _EXECbeep.c
  153.         lea.l    _EXECbeep.t2(pc),a0
  154.         moveq.l    #0,d0
  155.         move.l    d6,a1
  156.         moveq.l    #0,d1
  157.         move.b    #127,9(a1)
  158.         lea.l    _EXECbeep.t1(pc),a2
  159.         move.l    a2,34(a1)
  160.         moveq.l    #4,d2
  161.         move.l    d2,38(a1)
  162.         lib    Exec,OpenDevice
  163.         move.l    d0,d5
  164.         bne.s    _EXECbeep.c
  165.         moveq.l    #16,d3
  166.         move.l    d4,d0
  167.         moveq    #1!2,d1
  168.         execlib    alloc
  169.         move.l    d0,d4
  170.         beq.s    _EXECbeep.c
  171.         move.l    d4,a0
  172.         move.l    #$80007f00,(a0)
  173.         move.l    d6,a1
  174.         move.l    d4,34(a1)
  175.         moveq.l    #4,d0
  176.         move.l    d0,38(a1)
  177.         move.w    a5,42(a1)    ;period
  178.         move.w    a4,46(a1)    ;cycles
  179.         move.w    #64,44(a1)
  180.         move.b    #(1<<4),30(a1)
  181.         move.w    #3,28(a1)
  182.         move.l    20(a1),a6
  183.         jsr    -30(a6)
  184.         move.l    d6,a1
  185.         lib    Exec,WaitIO
  186.         moveq    #-1,d0
  187.         move.l    d0,a3        ;success = true
  188. _EXECbeep.c    tst.l    d5
  189.         bne.s    _EXECbeep.c1
  190.         move.l    d6,a1
  191.         lib    Exec,CloseDevice
  192. _EXECbeep.c1    move.l    d7,a0
  193.         execlib    deleteport
  194.         move.l    d6,a0
  195.         execlib    deleteio
  196.         move.l    d4,a0
  197.         execlib    free
  198.         move.l    a3,d0
  199.         pull    d1-d7/a0-a5
  200.         rts
  201. _EXECbeep.t1    dc.b    1,2,4,8
  202. _EXECbeep.t2    dc.b    'audio.device',0
  203.         ds.w    0
  204.         endc
  205.  
  206.         ifd    _EXECFalloc
  207. _EXECalloc    push    a1/d1
  208.         addq.l    #4,d0
  209.         move.l    d0,-(sp)
  210.         lib    Exec,AllocMem
  211.         move.l    (sp)+,d1
  212.         move.l    d0,a0
  213.         tst.l    d0
  214.         beq.s    _EXECalloc0
  215.         move.l    d1,(a0)+
  216. _EXECalloc0    move.l    a0,d0
  217.         pull    a1/d1
  218.         rts
  219.         endc
  220.  
  221.         ifd    _EXECFfree
  222. _EXECfree    push    d0-d1/a0-a1
  223.         move.l    a0,d0
  224.         beq.s    _EXECfree0
  225.         move.l    -(a0),d0
  226.         move.l    a0,a1
  227.         lib    Exec,FreeMem
  228. _EXECfree0    pull    d0-d1/a0-a1
  229.         rts
  230.         endc
  231.  
  232.         ifd    _EXECFstop
  233. _EXECstop    push    d0-d1/a0-a1
  234.         moveq.l    #0,d0
  235.         moveq.l    #0,d1
  236.         lib    Exec,SetSignal
  237.         btst    #12,d0
  238.         beq.s    _EXECstop0
  239.         moveq.l    #0,d0
  240.         moveq.l    #0,d1
  241.         bset    #12,d1
  242.         flib    Exec,SetSignal
  243.         moveq.l    #1,d0            NE: STOP!!!
  244.         pull    d0-d1/a0-a1
  245.         rts
  246. _EXECstop0    moveq.l    #0,d0            EQ: no stop
  247.         pull    d0-d1/a0-a1
  248.         rts
  249.         endc
  250.  
  251.         ifd    _EXECFsformat    ;a0=*format_string;
  252. _EXECsformat    move.l    a2,-(sp)    ;a1=*output_string;
  253.         link    a4,#-32        ;d0..d7=data;
  254.         move.l    sp,a2
  255.         movem.l    d0-d7,(a2)
  256.         execlib    format
  257.         unlk    a4
  258.         move.l    (sp)+,a2
  259.         rts
  260.         endc
  261.  
  262.         ifd    _EXECFformat    ;a0=*format_string;
  263. _EXECformat    push    a2-a3/d0-d1    ;a1=*output_string;
  264.         move.l    a1,a3        ;a2=*data_stream;
  265.         move.l    a2,a1
  266.         lea.l    _EXECformat_s(pc),a2
  267.         lib    Exec,RawDoFmt
  268. _EXECformat1    tst.b    (a3)+
  269.         bne.s    _EXECformat1
  270.         move.l    a3,a1
  271.         subq.w    #1,a1
  272.         move.l    a1,a0
  273.         pull    a2-a3/d0-d1
  274.         rts            ;a1=*(NULL) /of_outstr/
  275. _EXECformat_s    move.b    d0,(a3)+
  276.         rts
  277.         endc
  278.  
  279.         ifd    _EXECFcreateport
  280. _EXECcreateport    push    d2/a2-a3    in: d0 = SIZEOF; out: d0 = port
  281.         move.l    a0,a3        name*
  282.         addq.l    #4,d0        space for SIZEOF
  283.         move.l    d0,d2
  284.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  285.         lib    Exec,AllocMem
  286.         move.l    d0,a2
  287.         tst.l    d0
  288.         beq.s    _EXECcreaport1        -> no mem
  289.         move.l    d2,(a2)+        save SIZEOF
  290.         moveq.l    #-1,d0
  291.         flib    Exec,AllocSignal
  292.         move.b    d0,MP_SIGBIT(a2)
  293.         bmi.s    _EXECcreaporte        -> no sigbit
  294.         sub.l    a1,a1
  295.         flib    Exec,FindTask
  296.         move.l    d0,MP_SIGTASK(a2)
  297.         move.b    #NT_MSGPORT,LN_TYPE(a2)
  298.         move.l    a3,LN_NAME(a2)
  299.         move.b    #PA_SIGNAL,MP_FLAGS(a2)
  300.         lea    MP_MSGLIST(a2),a0
  301.         ;  NEWLIST A0:
  302.         move.l    a0,(a0)
  303.         addq.l    #LH_TAIL,(a0)
  304.         clr.l    LH_TAIL(a0)
  305.         move.l    a0,(LH_TAIL+LN_PRED)(a0)
  306.         ;  ;
  307.         move.l    a2,d0
  308.         bra.s    _EXECcreaport1
  309. _EXECdeleteport    push    d2/a2-a3        In: port in a0
  310.         move.l    a0,d0
  311.         beq.s    _EXECcreaport1        -> no port to delete
  312.         move.l    a0,a2
  313.         moveq.l    #0,d0
  314.         move.b    MP_SIGBIT(a2),d0
  315.         bmi.s    _EXECcreaporte        -> no sigbit to free
  316.         lib    Exec,FreeSignal
  317. _EXECcreaporte    move.l    -(a2),d0        SIZEOF
  318.         move.l    a2,a1
  319.         lib    Exec,FreeMem
  320.         moveq.l    #0,d0
  321. _EXECcreaport1    pull    d2/a2-a3
  322.         move.l    d0,a0
  323.         rts
  324.         endc
  325.  
  326.         ifd    _EXECFcreateio
  327. _EXECcreateio    push    d2/a2        in: d0=SIZEOF, a0=MsgPort; out: d0=ioreq
  328.         move.l    a0,a2        save msgport*
  329.         addq.l    #4,d0        space for SIZEOF
  330.         move.l    d0,d2
  331.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  332.         lib    Exec,AllocMem
  333.         move.l    d0,a0
  334.         tst.l    d0
  335.         beq.s    _EXECcreateio.e        -> no mem
  336.         move.l    d2,(a0)+        save SIZEOF
  337.         move.l    a2,MN_REPLYPORT(a0)
  338.         move.b    #NT_MESSAGE,LN_TYPE(a0)
  339.         subq.l    #4,d2            subtract SIZEOF(SIZEOF)
  340.         move.w    d2,MN_LENGTH(a0)
  341.         move.l    a0,d0
  342. _EXECcreateio.e    pull    d2/a2
  343.         rts
  344.         endc
  345.  
  346.         ifd    _EXECFdeleteio
  347. _EXECdeleteio    move.l    a0,d0            in: a0 = ioreq
  348.         beq.s    _EXECdeleteio0        -> nothing to delete
  349.         move.l    a0,a1
  350.         move.l    -(a1),d0        get SIZEOF
  351.         lib    Exec,FreeMem
  352. _EXECdeleteio0    rts
  353.         endc
  354.  
  355.         endm
  356.  
  357.