home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / startup_asm35 / startup.asm < prev    next >
Assembly Source File  |  1977-12-31  |  12KB  |  450 lines

  1. *******************************************************************************
  2. *    "Startup.asm"
  3. *
  4. *    $VER: Startup_asm 3.5 (7.12.95)
  5. *
  6. *    Copyright © 1995 by Kenneth C. Nilsen/Digital Surface
  7. *    This source is public domain.
  8. *
  9. *    For instructions read the Startup_Asm.doc or see the Startup_example.s
  10. *
  11. *SUMMARY:
  12. *
  13. *StartSkip    =    0 or 1 (0 = wb/cli, 1=cli only (eg. from AsmOne))
  14. *Processor    =    0 or 680x0
  15. *MathProc    =    0 or 6888x/68040
  16. *
  17. *Init:    Version        <"PrgName ver.rev (date)">        (opt)
  18. *    TaskName    <"new task name in qvotes">        (opt)
  19. *    TaskPri        <priority>                (opt)
  20. *    DefLib        <libname wo/.library>,<version>        (opt)
  21. *    DefEnd        ;must end the "Init:" section ALWAYS!    (required!)
  22. *
  23. *Start:    LibBase        <libname wo/.library>            (opt)
  24. *    StartFrom    = 0 (CLI) or <>0 (WB) in D0        (opt)
  25. *    TaskPointer    = pointer to taskstructure  (D0)    (opt)
  26. *    NextArg        = pointer to next argument or 0  (D0)    (opt)
  27. *    Return        <return value> (with RTS)        (recommended)
  28. *
  29. *******************************************************************************
  30.  
  31. zyxMax    = 17    ;max no. of libraries for AllocMem()
  32. zyxBufZ    = 308    ;size of format buffer in bytes for AllocMem()
  33.  
  34. ; (these above settings will require 512 bytes allocated memory (0.5Kb))
  35.  
  36. *-----------------------------------------------------------------------------*
  37. * Macros for Startup.asm
  38. *-----------------------------------------------------------------------------*
  39.  
  40. Return:    Macro
  41.     moveq    #\1,d0    ;* if you use rtn code >127, change to "move.l"
  42.     rts                ;exit our program
  43.     EndM
  44.  
  45. DefLib:    Macro
  46.  
  47.     lea    \1NamX(pc),a1        ;make exclusive library namelabel
  48.     move.l    a1,(a5)+        ;put name into our buffer (if print)
  49.     move.l    a1,zyxNx        ;store name in local label
  50.     moveq    #\2,d0        ;* if you use ver >127, change this to "move.l"
  51.     move.l    d0,(a5)+        ;store version in our buffer
  52.     move.l    d0,zyxVx        ;store version in local label
  53.     jsr    -552(a6)        ;try open library
  54.     move.l    d0,(a5)+        ;store result in our buffer
  55.  
  56.     move.l    d0,\1basX        ;store result in global label
  57.     bne.b    \1zyx            ;if <>0 then ok
  58.  
  59.     bsr.w    zyxLibR            ;print error message
  60.     bra.b    \1zyx            ;go on...
  61.  
  62. \1basX:    dc.l    0
  63. \1NamX:    dc.b    "\1.library",0        ;library name macro
  64.     even
  65. \1zyx:
  66.     EndM
  67.  
  68. DefEnd:    Macro
  69.     move.l    #-1,(a5)        ;this terminate our library list
  70.     rts                ;exit init section
  71.     EndM
  72.  
  73. LibBase:    Macro
  74.     move.l    \1basX(pc),a6        ;get library base with exclusive name
  75.     EndM
  76.  
  77. TaskName:    Macro
  78.  
  79.     move.l    $4.w,a6            ;exec base
  80.     jsr    -132(a6)        ;Disable()
  81.     move.l    zyxTask(pc),a0        ;get stored task pointer to our task
  82.     move.l    #.TaskN,10(a0)        ;get ptr. to new name and store
  83.     jsr    -138(a6)        ;Enable()
  84.     bra.b    .zyxTsk            ;go on...
  85.  
  86. .TaskN:    dc.b    \1            ;task name macro
  87.     dc.b    0            ;null terminate
  88.     even
  89. .zyxTsk:
  90.     EndM
  91.  
  92. TaskPri:    Macro
  93.     move.l    $4.w,a6            ;execbase
  94.     move.l    zyxTask(pc),a1        ;get stored task pointer
  95.     moveq    #\1,d0            ;get new task priority
  96.     jsr    -300(a6)        ;SetTaskPri()
  97.     EndM
  98.  
  99. TaskPointer:    Macro
  100.     move.l    zyxTask(pc),d0        ;give pointer to task in d0
  101.     EndM
  102.  
  103. StartFrom:    Macro
  104.     move.l    RtnMess(pc),d0        ;if started from WB, d0<>0
  105.     EndM
  106.  
  107. Version:    Macro
  108.     bra.w    .zyxVer            ;jump garbage code :)
  109.     dc.b    "$VER: "        ;init header
  110.     dc.b    \1            ;get rest of string from macro
  111.     dc.b    0            ;null terminate
  112.     even
  113. .zyxVer:
  114.     EndM
  115.  
  116. NextArg:    Macro
  117.     move.l    zyxArgP(pc),d0        ;get address to argument string
  118.     beq.b    *+8            ;none? (from WB) then skip
  119.     move.l    d0,a0            ;use pointer
  120.     bsr.w    zyxGArg            ;go to our internal routine
  121.     move.l    a0,zyxArgP        ;update argument pointer
  122.     tst.l    d0            ;set/unset Z flag
  123.     EndM
  124.  
  125. *-----------------------------------------------------------------------------*
  126. * MAIN routine:
  127. *-----------------------------------------------------------------------------*
  128. GoZYX:    move.l    a0,-(sp)        ;store argument pointer
  129.  
  130.     move.l    d0,zyxArgL        ;store length of arg. string
  131.     move.l    a0,zyxArgP        ;store arg. pointer in internal label
  132.  
  133.     move.l    $4.w,a6            ;exec base
  134.  
  135.     move.l    #zyxBufZ,d0        ;set buffer size
  136.     move.l    #$10001,d1        ;requirements (public, clear)
  137.     jsr    -198(a6)        ;AllocMem()
  138.     move.l    d0,zyxBuff        ;store result in label
  139.     beq.w    .DOS            ;Null? then exit
  140.  
  141.     sub.l    a1,a1            ;a1=0 (this task)
  142.     jsr    -294(a6)        ;FindTask()
  143.     move.l    d0,a4            ;copy result
  144.     move.l    d0,zyxTask        ;store for internal use
  145.  
  146.     tst.l    172(a4)            ;where we started from (wb/cli)
  147.     bne.b    .chkPro            ;<>0 then cli
  148.  
  149.     moveq    #StartSkip,d0        ;check if we wanne skip (eg. AsmOne)
  150.     bne.b    .chkPro            ;yepp, then skip
  151.     lea    92(a4),a0        ;get message port address
  152.     jsr    -384(a6)        ;WaitPort()
  153.     lea    92(a4),a0        ;get message port address
  154.     jsr    -372(a6)        ;GetMsg()
  155.     move.l    d0,RtnMess        ;store message pointer in label
  156.  
  157. .chkPro:
  158.     move.w    296(a6),d5        ;AttnFlags in execbase
  159.     and.l    #$ff,d5            ;we only need the first byte
  160.  
  161.     move.l    #Processor,d7        ;processor we want
  162.     beq.w    .ProOk            ;null? then any will do, skip this part
  163.     cmp.l    #68000,d7        ;or 68000?
  164.     beq.w    .ProOk            ;then skip too...
  165.  
  166. .nxPro1:
  167.     cmp.l    #68010,d7        ;68010?
  168.     bne.b    .nxPro2            ;no, check next
  169.     and.b    #$cf,d5            ;check bits
  170.     bne.w    .ProOk            ;we got a 68010 or higher
  171.     bra.w    .ProErr            ;we got lower, we can't start...
  172.  
  173. .nxPro2:
  174.     cmp.l    #68020,d7        ;same as above, just higher processor
  175.     bne.b    .nxPro3
  176.     and.b    #$ce,d5
  177.     bne.w    .ProOk
  178.     bra.b    .ProErr
  179.  
  180. .nxPro3:
  181.     cmp.l    #68030,d7
  182.     bne.b    .nxPro4
  183.     and.b    #$cc,d5
  184.     bne.b    .ProOk
  185.     bra.b    .ProErr
  186.  
  187. .nxPro4:
  188.     cmp.l    #68040,d7
  189.     bne.b    .nxPro5
  190.     and.b    #$c8,d5
  191.     bne.b    .ProOk
  192.     bra.b    .ProErr
  193.  
  194. .nxPro5:
  195.     cmp.l    #68060,d7        ;we want a 68060 (yes, we do :) )
  196.     bne.b    .ProWho            ;not? then I dont know about any higher
  197.     btst    #7,d5            ;test if it is a 68060 we're using
  198.     beq.b    .ProErr            ;nope
  199.     btst    #6,d5            ;are you sure?
  200.     bne.b    .ProOk            ;yepp, continue
  201.     bra.b    .ProErr            ;not a 060, print error message
  202.  
  203. .ProWho:
  204.     lea    ProcWho(pc),a0        ;unknown processor required, print
  205.     move.l    #Processor,ProcNum    ;message about it.
  206.     bra.b    .format
  207.  
  208. .ProErr:
  209.     lea    ProcErr(pc),a0        ;we don't got the processor required
  210.     move.l    #Processor,ProcNum    ;print message about it...
  211.  
  212. .format:
  213.     lea    ProcNum(pc),a1
  214.     bsr.w    zyxPrt            ;jump to our cli print routine
  215.     bra.w    .End
  216.  
  217. .ProOk:    move.l    #MathProc,d7        ;time to check for math-co-processor
  218.     beq.w    .MathOk            ;null? then any will do...
  219.  
  220.     cmp.l    #68881,d7        ;a 68881?
  221.     bne.b    .Math2            ;no check next
  222.     and.b    #$70,d5            ;check flags
  223.     bne.b    .MathOk            ;we got it
  224.     bra.b    .MathEr            ;sorry...
  225.  
  226. .Math2:    cmp.l    #68882,d7        ;same as above
  227.     bne.b    .Math3
  228.     and.b    #$60,d5
  229.     bne.b    .MathOk
  230.     bra.b    .MathEr
  231.  
  232. .Math3:    cmp.l    #68040,d7        ;we have a 68040 with FPU not 881/882
  233.     bne.b    .MathEr            ;unknown FPU if any else...
  234.     btst    #6,d5            ;we got it?
  235.     bne.b    .MathOk            ;yepp, continue
  236.  
  237. .MathEr:
  238.     lea    MathErr(pc),a0        ;print error message...
  239.     move.l    #MathProc,ProcNum
  240.     bra.w    .format
  241.  
  242. .MathOk:
  243.     bsr.w    zyxLibO            ;oki, open our libraries
  244.  
  245.     tst.b    zyxLR            ;any error?
  246.     bne.b    .noShow            ;yepp, don't jump to main program
  247.  
  248.     move.l    zyxArgP(pc),a0        ;get arg. pointer
  249.     move.l    zyxArgL(pc),d0        ;get arg. length
  250.  
  251.     bsr.w    Start            ;start main program
  252.     move.l    d0,zyxVal        ;store return code
  253.  
  254. .noShow:
  255.     bsr.w    zyxLibC            ;close libraries if any
  256.  
  257. .End:    move.l    zyxBuff(pc),d0        ;get pointer to our buffer
  258.     beq.b    .noBuff            ;no buffer?!?
  259.     move.l    d0,a1            ;copy pointer
  260.     move.l    #zyxBufZ,d0        ;length of buffer
  261.     jsr    -210(a6)        ;FreeMem()
  262.  
  263. .noBuff:
  264.     tst.l    RtnMess            ;from WB?
  265.     beq.w    .DOS            ;nope, from CLI
  266.  
  267.     jsr    -132(a6)        ;Disable()
  268.     move.l    RtnMess(pc),a1        ;put message in a1
  269.     jsr    -138(a6)        ;Enable()
  270.  
  271. .DOS:    movem.l    (sp)+,a0        ;restore stack, put arg. pointer back
  272.     move.l    zyxVal(pc),d0        ;set return code
  273.     rts                ;BYE! :)
  274.  
  275. zyxDo:    move.b    d0,(a3)+        ;for RawDoFmt(), process routine
  276.     rts
  277.  
  278. zyxPrt:    movem.l    d0-a6,-(sp)        ;store regs. on stack
  279.  
  280.     lea    zyxDo(pc),a2        ;process
  281.     move.l    zyxBuff(pc),a3        ;format buffer
  282.     jsr    -522(a6)        ;RawDoFmt()
  283.  
  284.     moveq    #0,d0            ;any version
  285.     lea    zyxDos(pc),a1        ;ptr. to dos.library name
  286.     jsr    -552(a6)        ;OpenLibrary()
  287.     tst.l    d0            ;failed?
  288.     beq.b    .exit            ;jepp, exit
  289.     move.l    d0,a6            ;use dosbase
  290.  
  291.     jsr    -60(a6)            ;Output()
  292.     move.l    d0,d1            ;copy, set Z, failed?
  293.     beq.b    .clDos            ;no output -> close dos.library
  294.  
  295.     move.l    zyxBuff(pc),a0        ;get ptr. to our buffer
  296.     move.l    a0,d2            ;copy pointer
  297.     moveq    #0,d3            ;clear D3 (length of buffer)
  298. .count:    move.b    (a0)+,d0        ;get one char
  299.     beq.b    .cntEnd            ;null? yepp, found end...
  300.     addq    #1,d3            ;nope, add one in length
  301.     bra.b    .count            ;continue
  302.  
  303. .cntEnd:
  304.     jsr    -48(a6)            ;print buffer to output handler (CLI)
  305.  
  306. .clDos:    move.l    a6,a1            ;copy dosbase to a1
  307.     move.l    $4.w,a6            ;get exebase
  308.     jsr    -414(a6)        ;CloseLibrary()
  309.  
  310. .exit:    movem.l    (sp)+,d0-a6        ;restore stack
  311.     rts                ;return
  312.  
  313. zyxLibO:
  314.     move.l    #4*3*zyxMax,d0        ;library buffer size 12*zyxMax (192)
  315.     move.l    #$10001,d1        ;any mem, clear it
  316.     jsr    -198(a6)        ;AllocMem()
  317.     move.l    d0,zyxMem        ;store result
  318.     beq.b    .memErr            ;null? then error
  319.  
  320.     move.l    d0,a5            ;use buffer
  321.     bsr.w    Init            ;jump to init section (see macros)
  322.  
  323.     rts                ;done
  324.  
  325. .memErr:
  326.     lea    zyxFR(pc),a0        ;get format text
  327.     lea    zyxMeR(pc),a1        ;get input string
  328.  
  329.     bsr.w    zyxPrt            ;print message about low memory
  330.  
  331.     st    zyxLR            ;failed, don't start main program
  332.     rts                ;return
  333.  
  334. zyxLibC:
  335.     move.l    $4.w,a6            ;execbase
  336.  
  337.     move.l    zyxMem(pc),d0        ;library buffer
  338.     beq.w    .noLibs            ;null? then no libraries
  339.     move.l    d0,a5            ;use pointer
  340.  
  341. .loop:    cmp.l    #-1,(a5)        ;end?
  342.     beq.b    .clEnd            ;yepp, then done!
  343.     move.l    8(a5),d0        ;get library base
  344.     beq.b    .noCl            ;null? then this lib. failed to open
  345.     move.l    d0,a1            ;use base
  346.     jsr    -414(a6)        ;CloseLibrary()
  347. .noCl:    lea    12(a5),a5        ;get next library base
  348.     bra.b    .loop            ;continue
  349.  
  350. .clEnd:    move.l    zyxMem(pc),a1        ;get lib. buffer pointer
  351.     move.l    #4*3*zyxMax,d0        ;size
  352.     jsr    -210(a6)        ;FreeMem()
  353.  
  354. .noLibs:
  355.     rts                ;return
  356.  
  357. zyxLibR:
  358.     st    zyxLR            ;if any errors, set error flag
  359.  
  360.     lea    zyxLib(pc),a0
  361.     lea    zyxNx(pc),a1
  362.     bsr.w    zyxPrt            ;print library name
  363.  
  364.     lea    zyxVer(pc),a0
  365.     lea    zyxVx(pc),a1
  366.     bsr.w    zyxPrt            ;print library version
  367.  
  368.     rts                ;return
  369.  
  370. zyxGArg:
  371.     move.b    (a0)+,d0        ;get a char from arg. line
  372.     beq.w    .end            ;null? end of line
  373.     cmp.b    #10,d0            ;linefeed?
  374.     beq.w    .end            ;end of line
  375.     cmp.b    #9,d0            ;tab?
  376.     beq.b    zyxGArg            ;get another char
  377.     cmp.b    #32,d0            ;space?
  378.     beq.b    zyxGArg            ;get another char
  379.  
  380.     move.l    zyxBuff(pc),a1        ;our text buffer
  381.     lea    -1(a0),a0        ;go back one byte on arg. line
  382. .copy:    move.b    (a0)+,d0        ;copy char to d0
  383.     beq.b    .stop            ;null? then stop copy
  384.     cmp.b    #10,d0            ;linefeed?
  385.     beq.b    .stop            ;stop copy
  386.     cmp.b    #32,d0            ;space?
  387.     beq.b    .eol            ;then this arg. is done
  388. .cont:    cmp.b    #'*',d0            ;asterix?
  389.     beq.b    .chkSpc            ;check for special functions
  390.     cmp.b    #'"',d0            ;qvote?
  391.     beq.b    .toggle            ;toggle copy mode
  392. .noChk:    move.b    d0,(a1)+        ;copy passed char to our buffer
  393. .cont2:    bra.b    .copy            ;continue copy
  394.  
  395. .chkSpc:
  396.     cmp.b    #'"',(a0)        ;a qvote want to be used?
  397.     bne.b    .chk2            ;no, check for a linefeed then...
  398.     move.b    #'"',(a1)+        ;copy a qvote to our buffer
  399.     lea    1(a0),a0        ;skip one byte (2(*")->1("))
  400.     bra.b    .copy            ;continue copy argument
  401. .chk2:    cmp.b    #'n',(a0)        ;a linefeed?
  402.     bne.b    .noChk            ;nope, skip special funcs.
  403.     move.b    #10,(a1)+        ;copy a linefeed to our buffer
  404.     lea    1(a0),a0        ;make 2 -> 1
  405.     bra.b    .copy            ;continue copy
  406.  
  407. .toggle:
  408.     tst.b    zyxQ            ;already toggled?
  409.     beq.b    .set            ;nope, then toggle
  410.     sf    zyxQ            ;re toggle
  411.     bra.b    .stop            ;end of argument
  412. .set:    st    zyxQ            ;toggle so we can use space in arg.
  413.     bra.b    .cont2            ;continue copying argument
  414.  
  415. .eol:    tst.b    zyxQ            ;end of line -> toggled?
  416.     bne.b    .cont            ;jepp, continue
  417.  
  418. .stop:    tst.b    zyxQ            ;toggled?
  419.     bne.b    .end            ;jepp,don't care about this arg (error)
  420.     clr.b    (a1)            ;terminate buffer
  421.     move.l    zyxBuff(pc),d0        ;pointer to extracted argument
  422.     rts                ;return to macro
  423.  
  424. .end:    moveq    #0,d0            ;no more args
  425.     rts                ;return to macro
  426.  
  427. RtnMess:    dc.l    0        ;pointer to WB message
  428. ProcNum:    dc.l    0        ;processor wanted
  429. zyxArgL:    dc.l    0        ;argument line length
  430. zyxArgP:    dc.l    0        ;pointer to argument string
  431. zyxVal:        dc.l    0        ;return code
  432. zyxMem:        dc.l    0        ;pointer to library buffer
  433. zyxNx:        dc.l    0        ;temp lib. name
  434. zyxVx:        dc.l    0        ;temp lib. version
  435. zyxTask:    dc.l    0        ;pointer to task structure
  436. zyxLR:        dc.b    0        ;error flag
  437. zyxQ:        dc.b    0        ;toggle flag for qvotes
  438. zyxBuff:    dc.l    0        ;pointer to string buffer
  439. zyxMeR:        dc.l    zyxMemR        ;pointer to a format string
  440.  
  441. zyxDos:        dc.b    'dos.library',0
  442. zyxLib:        dc.b    "Couldn't open %s ",0
  443. zyxVer:        dc.b    'version %ld.',10,0
  444. zyxMemR:    dc.b    'Not enough memory!',10,0
  445. zyxFR:        dc.b    '%s',0
  446. ProcWho:    dc.b    'INTERN: %ld ?',10,0
  447. ProcErr:    dc.b    'This program require %ld+',10,0
  448. MathErr:    dc.b    'This program need %ld FPU',10,0
  449.         even
  450.