home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk408.lzh / KickDate / cli.asm < prev    next >
Assembly Source File  |  1990-11-21  |  4KB  |  195 lines

  1. * /* KICKDATE - Copyright 1990 Joe Porkka
  2. *         FREELY DISTRIBUTABLE
  3. *     Purpose: Keeps the current date on the Kickstart disk
  4. *          for A1000 owners with autoboot harddrives.
  5. * Version 1.0
  6. * */
  7. pr_CLI    equ $00ac
  8. cli_CommandName equ $0010
  9.  
  10. * This is a modified ASTARTUP.ASM file
  11. * it is stripped down to work only from a CLI
  12.  
  13. ******* Imported *******************************************************
  14.  
  15. xlib    macro
  16.     xref    _LVO\1
  17.     endm
  18.  
  19.     xref    _AbsExecBase
  20.     xlib    Input
  21.     xlib    Output
  22.  
  23.     xref    _main            ; C code entry point
  24.  
  25.     xlib    FindTask
  26.     xlib    OpenLibrary
  27.     xlib    CloseLibrary
  28.  
  29. ******* Exported *******************************************************
  30.  
  31.     xdef    _SysBase
  32.     xdef    _DOSBase
  33.  
  34.     xdef    _errno
  35.     xdef    _stdin
  36.     xdef    _stdout
  37.     xdef    _stderr
  38.  
  39.     xdef    _exit            ; standard C exit function
  40.  
  41. callsys macro
  42.     jsr _LVO\1(a6)
  43.     endm
  44.  
  45.  
  46. ************************************************************************
  47. *
  48. *    Standard Program Entry Point
  49. *
  50. ************************************************************************
  51. *
  52. *    main (argc, argv)
  53. *       int    argc;
  54. *       char *argv[];
  55. *
  56. ************************************************************************
  57.  
  58. startup:                ; reference for Wack users
  59.         move.l    sp,initialSP    ; initial task stack pointer
  60.         move.l    d0,dosCmdLen
  61.         move.l    a0,dosCmdBuf
  62.  
  63.     ;------ get Exec's library base pointer:
  64.         move.l    _AbsExecBase,a6
  65.         move.l    a6,_SysBase
  66.  
  67.     ;------ get the address of our task
  68.         suba.l    a1,a1
  69.         callsys FindTask
  70.         move.l    d0,a4
  71.  
  72. fromCLI:
  73.     ;------ attempt to open DOS library:
  74.         bsr    openDOS
  75.  
  76.     ;------ find command name:
  77.         move.l    pr_CLI(a4),a0
  78.         add.l    a0,a0        ; bcpl pointer conversion
  79.         add.l    a0,a0
  80.         move.l    cli_CommandName(a0),a0
  81.         add.l    a0,a0        ; bcpl pointer conversion
  82.         add.l    a0,a0
  83.  
  84.     ;------ create buffer and array:
  85.         movem.l d2/a2/a3,-(sp)
  86.         lea    argvArray,a3
  87.         moveq.l #1,d2        ; param counter
  88.  
  89.     ;------ fetch command name:
  90.         moveq.l #0,d0
  91.         move.b    (a0)+,d0        ; size of command name
  92.         move.l    a0,(a3)+        ; ptr to command name
  93.         clr.b  0(a0,d0.w)          ; zero byte at end
  94.  
  95.     ;------ collect parameters:
  96.         move.l    dosCmdLen,d0
  97.         move.l    dosCmdBuf,a0
  98.     ;------ skip control characters and space:
  99. 3$:        move.b    (a0)+,d1
  100.         subq.l    #1,d0
  101.         ble.s    parmExit
  102.         cmp.b    #' ',d1
  103.         ble.s    3$
  104.  
  105.     ;------ copy parameter:
  106.         addq.l    #1,d2    ; param count
  107.         lea.l  -1(a0),a1
  108.         move.l    a1,(a3)+
  109. ;         bra.s     5$
  110. 4$:        move.b    (a0)+,d1
  111.         subq.l    #1,d0
  112.         cmp.b    #' ',d1
  113.         bgt    4$
  114. ;         ble.s     6$
  115. 5$:        ;move.b  d1,(a2)+
  116. ;         bra.s     4$
  117. ;6$:
  118.         clr.b    -1(a0)
  119.         cmp    #32,d2
  120.         blt    3$
  121. ;         bra.s     3$
  122. parmExit:    clr.b    (a0)+
  123.         clr.l    (a3)+
  124.  
  125.         move.l    d2,d0
  126.         movem.l (sp)+,d2/a2/a3
  127.         pea    argvArray
  128.         move.l    d0,-(sp)
  129.  
  130.  
  131. *
  132. *  The above code relies on the end of line containing a control
  133. *  character of any type, i.e. a valid character must not be the
  134. *  last.  This fact is ensured by DOS.
  135. *
  136.  
  137.  
  138.     ;------ get standard input handle:
  139.         move.l    _DOSBase,a6
  140.         callsys Input
  141.         move.l    d0,_stdin
  142.  
  143.     ;------ get standard output handle:
  144.         callsys  Output
  145.         move.l    d0,_stdout
  146.         move.l    d0,_stderr
  147.  
  148.     ;------ call C main entry point
  149.         jsr    _main
  150.  
  151.     ;------ return success code:
  152.         moveq.l #0,D0
  153.         move.l    initialSP,sp    ; restore stack ptr
  154.         rts
  155.  
  156. _exit:
  157.         move.l    4(SP),d0        ; extract return code
  158. exit2:
  159.         move.l    initialSP,SP    ; restore stack pointer
  160.         move.l    d0,-(SP)        ; save return code
  161.  
  162.     ;------ close DOS library:
  163.         move.l    _AbsExecBase,A6
  164.         move.l    _DOSBase,d0
  165. ******************************************
  166.  
  167.     DATA
  168.  
  169. ************************************************************************
  170.  
  171. _SysBase    dc.l    0
  172. _DOSBase    dc.l    0
  173.  
  174. _errno        dc.l    0
  175. _stdin        dc.l    0
  176. _stdout     dc.l    0
  177. _stderr     dc.l    0
  178.  
  179. initialSP    dc.l    0
  180.  
  181. dosCmdLen    dc.l    0
  182. dosCmdBuf    dc.l    0
  183.  
  184. argvArray    ds.l    32  ; MAX 32 args
  185.  
  186. DOSName     dc.b 'dos.library',0
  187.  
  188.  
  189.     END
  190.