home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / startup_asm35 / startup_example.s < prev    next >
Text File  |  1977-12-31  |  6KB  |  150 lines

  1. *******************************************************************************
  2. *                                          *
  3. *    Startup example for "Startup.asm" version 3.4                  *
  4. *                                          *
  5. *    © 1995, Kenneth C. Nilsen                          *
  6. *                                          *
  7. *    See bottom line!                              *
  8. *                                          *
  9. *******************************************************************************
  10.  
  11. StartSkip    =    0        ;0=WB/CLI, 1=CLI only (eg. from AsmOne)
  12. Processor    =    68000        ;0/680x0 (= 0 is faster than 68000)
  13. MathProc    =    0        ;FPU: 0(none)/68881/68882/68040
  14.  
  15.  
  16.     incdir    inc:            ;your include dir
  17.     include    Startup.asm        ;our file
  18. *------------------------------------------------------------------------------
  19. *## here is our init section (Init: label and DefLib macro are required)
  20. *------------------------------------------------------------------------------
  21.  
  22.     dc.b    "$VER: Example 1.45 (7.12.95)",0
  23.     even
  24.  
  25. Init:    TaskName "Startup_test"        ;set our task name
  26.     TaskPri    1            ;set task pri
  27.  
  28.     DefLib    intuition,0        ;open intuition.library ver. 0
  29.     DefLib    dos,37            ;open dos.library ver. 37
  30.     DefEnd                ;ALWAYS REQUIRED!!!
  31.  
  32. *------------------------------------------------------------------------------
  33. ;## our main example code comes from here (Start: label is required!)
  34. *------------------------------------------------------------------------------
  35.  
  36. Start:    LibBase    dos            ;use dos.library base
  37.  
  38.     jsr    -60(a6)            ;Output()
  39.     move.l    d0,d1            ;copy handler
  40.     beq.b    .noOut            ;null? then skip
  41.  
  42.     move.l    #Text,d2        ;pointer to our text
  43.     move.l    #TextL,d3        ;length of text
  44.     jsr    -48(a6)            ;Write() (to handler)
  45.  
  46. *------------------------------------------------------------------------------
  47. ;## if we started from Wb then blink (just to differ a little)
  48. *------------------------------------------------------------------------------
  49.  
  50. .noOut    StartFrom            ;a macro which tells you where the prg.
  51.     beq.b    .cli            ;started from. (=0 cli / <>0 wb)
  52.  
  53. .wb    LibBase    intuition        ;use "LibBase" to get library bases
  54.  
  55. *------------------------------------------------------------------------------
  56. ;## now intuition.library base is put into A6 and we can start using it:
  57. *------------------------------------------------------------------------------
  58.  
  59.     move.l    60(a6),a0        ;frontmost screen (hehe, wonder how?)
  60.     jsr    -96(a6)            ;DisplayBeep(), blink the screen
  61.  
  62.     TaskPointer            ;get pointer to this task in d0.
  63.                     ;use it what you want :)
  64. *------------------------------------------------------------------------------
  65. ;here we demostrade the argument parsing. You get one seperate argument by
  66. ;each time you use the "NextArg" macro. Pointer to argument [0] in d0 or NULL:
  67. *------------------------------------------------------------------------------
  68.  
  69. .cli    NextArg                ;macro which gives us the pointer to
  70.     beq.b    .exit            ;our arg. in D0 (or NULL in D0)
  71.                     ;Branch EQual if end of args.
  72.     move.l    d0,d2            ;we store pointer to buffer in D2
  73.  
  74. *------------------------------------------------------------------------------
  75. ;## print arguments to default output (in cli) to see some actions:
  76. *------------------------------------------------------------------------------
  77.  
  78.     LibBase    dos            ;internal macro (dosbase in a6)
  79.  
  80.     jsr    -60(a6)            ;Output()
  81.     move.l    d0,d1            ;handler
  82.     beq.b    .exit            ;no handler? then exit printing
  83.  
  84.     moveq    #0,d3            ;length
  85.     move.l    d2,a0            ;copy buffer address to a0
  86. .count    move.b    (a0)+,d0        ;get one byte from buffer
  87.     beq.b    .gotLen            ;found null, exit loop
  88.     addq    #1,d3            ;add one to length in D3
  89.     bra.b    .count            ;count some more...
  90.  
  91. .gotLen    jsr    -48(a6)            ;Write(), print argument in cli
  92.  
  93.     jsr    -60(a6)            ;Output()
  94.     move.l    d0,d1            ;output handler in D1
  95.     move.l    #Text,d2        ;pointer to text/linefeed
  96.     moveq    #1,d3            ;length
  97.     jsr    -48(a6)            ;Write(), print linefeed in cli
  98.  
  99.     bra.b    .cli            ;repeat until no args are left
  100.  
  101. .exit    Return    0            ;return code and bye bye!
  102.  
  103. *-----------------------------------------------------------------------------*
  104. ;## Our data section for this example source:
  105. *-----------------------------------------------------------------------------*
  106.  
  107. Text    dc.b    10,'Startup.asm example 3.4',10
  108.     dc.b    'Give some arguments to test the NextArg macro:',10,10
  109. TextL    =*-Text
  110.  
  111. *-----------------------------------------------------------------------------*
  112. *######    BOTTOM LINE
  113. *-----------------------------------------------------------------------------*
  114. ;    Some assemblers like DevPac and Barfly will not accept spaces in
  115. ;    macro names like the "Version" and "TaskName" macros. This works fine
  116. ;    with the AsmOne assembler and I can't see why it shouldn't work with
  117. ;    the others. If you notice this problem then do one of two things:
  118. ;
  119. ;    1) Use underscores in the "TaskName" name and don't use the "Version"
  120. ;       macro.
  121. ;    2) Use none of these two macros.
  122. ;
  123. ;    You can of course do this manually by looking at the Startup.asm file
  124. ;    and see how this is done.
  125. ;
  126. ;    Remember that supporting Workbench startup will make more people happy!
  127. ;    :) (like that guy) and by using this startup code you have easy support
  128. ;    for that AND extra features like reading arguments without having to
  129. ;    parse the line, use ReadArgs(), or remove spaces and qvotes yourself.
  130. ;    You can also easily make a version string into your binary programs and
  131. ;    set your own task name. You have even control on where your program
  132. ;    where started from. You can also prevent your program to crash on a
  133. ;    machine with a lower processor than you require. The same thing about
  134. ;    the FPU.
  135. ;
  136. ;    The assembled startup code is in itself only about 1Kb! and that's
  137. ;    worth making your program safe!
  138. ;
  139. ;    Feel free to contact me if any problems occure or if you want features
  140. ;    included. If you change the Startup.asm source it would be nice to see
  141. ;    what you have done :)
  142. ;
  143. ;    Add: kenneth@norconnect.no
  144. ;
  145. ;    Digital Surface
  146. ;    Attn: Kenneth Nilsen
  147. ;    Kvernhusrenen 31
  148. ;    N-5227 S-Neset
  149. ;    Norway
  150.