home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / asm / tbsource / clockserver / cs.s next >
Text File  |  1993-12-21  |  5KB  |  289 lines

  1. *************************************************
  2. *                        *
  3. *         (C)opyright 1992        *
  4. *                        *
  5. *        by  Tomi Blinnikka        *
  6. *                        *
  7. *    Don´t try to understand the code    *
  8. *                        *
  9. * Version 0.01    25/12/1992            *
  10. *                        *
  11. * BUGS:                        *
  12. *                        *
  13. * Version 1.00    26/12/1992            *
  14. *                        *
  15. * BUGS:    Not in the program itself...        *
  16. *                        *
  17. * Version 1.01    26/12/1992            *
  18. *                        *
  19. * BUGS:                        *
  20. *                        *
  21. * Version 1.02    26/12/1992            *
  22. *                        *
  23. * Now makes a script and protects it        *
  24. * accordingly.                    *
  25. *                        *
  26. *************************************************
  27.  
  28.     INCLUDE    "JMPLibs.i"
  29.     INCLUDE    "exec/types.i"
  30.     INCLUDE    "libraries/dos.i"
  31.  
  32.     INCLUDE    "XREF:2.0.xref"
  33.     INCLUDE    "XREF:exec.xref"
  34.     INCLUDE    "XREF:dos.xref"
  35.  
  36.  
  37. nr_Name:    EQU    0
  38. nr_FullName:    EQU    4
  39. nr_Flags:    EQU    12
  40. nr_Task:    EQU    16
  41. nr_SignalNum:    EQU    20
  42.  
  43. NRF_SEND_SIGNAL    EQU    2
  44.  
  45.         section    CS,CODE
  46.  
  47.         move.l    a0,a4
  48.         clr.b    -1(a0,d0.l)
  49.         openlib    Dos,ShutDown_Out
  50.  
  51.         cmp.b    #'?',(a4)
  52.         beq    CmdLineHelp
  53.         cmp.w    #'-?',(a4)
  54.         beq    CmdLineHelp
  55.         cmp.w    #'-h',(a4)
  56.         beq    CmdLineHelp
  57.         cmp.b    #'h',(a4)
  58.         beq    CmdLineHelp
  59.  
  60. ;Set stuff for notification request
  61.  
  62.         sub.l    a1,a1            ;Find our task
  63.         lib    Exec,FindTask
  64.         move.l    d0,OurTask
  65.  
  66.         move.l    #-1,d0
  67.         lib    Exec,AllocSignal
  68.         move.b    d0,SigBit
  69.         bmi    NoSigBit
  70.  
  71. StartMain:    bsr    DoNotify
  72.         tst.l    d0
  73.         beq    ShutDown
  74.  
  75.         clr.l    d0
  76.         clr.l    d1
  77.         move.b    SigBit,d1
  78.         bset.l    d1,d0
  79.         bset.l    #SIGBREAKB_CTRL_C,d0    ;and CTRL_C
  80.         lib    Exec,Wait
  81.  
  82.         cmp.l    #SIGBREAKF_CTRL_C,d0    ;If CTRL_C
  83.         beq    Break            ;go break
  84.  
  85. ;        print    <"ClockServer: Received file notification!",13,10>    ;DEBUG
  86. ;        print    <"Stopping notification.",13,10>            ;DEBUG
  87.  
  88.         bsr    StopNotify
  89.  
  90.         lea.l    DateTime1,a0
  91.         move.l    a0,d1
  92.         lib    Dos,DateStamp
  93.  
  94.         lea.l    DateTime1,a0
  95.         move.l    a0,d1
  96.         lib    Dos,DateToStr
  97.         tst.l    d0
  98.         bne    SkipFail1
  99.         lea.l    ConvFailText1,a0
  100.         bsr    Printer
  101.         bra    StartMain
  102.  
  103. SkipFail1:    lea.l    FileName1,a0
  104.         move.l    a0,d1
  105.         move.l    #1006,d2        ;mode_newfile
  106.         lib    Dos,Open
  107.         move.l    d0,File1
  108.         bne    SkipFail2
  109.         lea.l    OpenFailText1,a0
  110.         bsr    Printer
  111.         bra    StartMain
  112.  
  113. SkipFail2:    bsr    FormatStr
  114.         lea.l    OutputBuffer1,a1
  115.         bsr    GetLength
  116.         move.l    d0,d3
  117.         move.l    File1,d1
  118.         lea.l    OutputBuffer1,a0
  119.         move.l    a0,d2
  120.         lib    Dos,Write
  121.  
  122.         move.l    File1,d1
  123.         lib    Dos,Close
  124.         clr.l    File1
  125.  
  126.  
  127.         lea.l    FileName1,a0
  128.         move.l    a0,d1
  129.         move.l    #%1000000,d2
  130.         lib    Dos,SetProtection
  131.  
  132.         bra    StartMain
  133.  
  134. ;Subroutines
  135.  
  136. FormatStr:    lea.l    OutputBuffer2,a2
  137.         lea.l    DateStr1,a0
  138.         lea.l    TimeStr1,a1
  139. FormatStr1:    cmp.b    #$00,(a0)
  140.         beq    FormatStr2
  141.         move.b    (a0)+,(a2)+
  142.         bra    FormatStr1
  143. FormatStr2:    move.b    #' ',(a2)+
  144. FormatStr2.1:    cmp.b    #$00,(a1)
  145.         beq    FormatStr3
  146.         move.b    (a1)+,(a2)+
  147.         bra    FormatStr2.1
  148. FormatStr3:    move.b    #13,(a2)+
  149.         move.b    #10,(a2)+
  150.         clr.b    (a2)+        ;here so GetLength knows to stop
  151.         rts
  152.  
  153. ;Get length of text in given address
  154. ;
  155. ;Input a1 = Address of null terminated text string
  156. ;
  157. ;Result d0 = Length (not incl. NULL)
  158.  
  159. GetLength:    clr.l    d0
  160.         cmp.l    #$00,a1        ;fixes enforcer hit
  161.         beq    GetLength_OUT
  162. GetLength2:    add.l    #1,d0
  163.         tst.b    (a1)+
  164.         bne    GetLength2
  165.         sub.l    #1,d0
  166. GetLength_OUT:    rts
  167.  
  168. DoNotify:    lea.l    NotifyReq1,a2
  169.         move.l    #NRF_SEND_SIGNAL,nr_Flags(a2)
  170.         move.l    OurTask,nr_Task(a2)        ;Set task
  171.         move.b    SigBit,nr_SignalNum(a2)        ;Set signal
  172.         lea.l    FileName1,a0
  173.         move.l    a0,nr_Name(a2)            ;Set filename
  174.         move.l    a2,d1
  175.         lib    Dos,StartNotify
  176.         tst.l    d0
  177.         beq    NotNotifying
  178.         move.b    #1,UseNotify
  179.         move.l    #-1,d0
  180.         rts
  181.  
  182. StopNotify:    tst.b    UseNotify
  183.         beq    StopNotify_OUT
  184.         lea.l    NotifyReq1,a0
  185.         move.l    a0,d1
  186.         lib    Dos,EndNotify
  187.         clr.b    UseNotify
  188. StopNotify_OUT:    rts
  189.  
  190. ShutDown:    bsr    StopNotify
  191.  
  192.         move.l    File1,d1
  193.         beq    ShutDown8000
  194.         lib    Dos,Close
  195.  
  196. ShutDown8000:    clr.l    d0
  197.         move.b    SigBit,d0
  198.         bmi    ShutDown7000
  199.         lib    Exec,FreeSignal
  200.  
  201. ShutDown7000:
  202. ShutDown1000:    closlib    Dos
  203. ShutDown_Out:    move.l    #RETURN_OK,d0
  204.         rts
  205.  
  206. CmdLineHelp:    lea.l    UsageText1,a0
  207.         bsr    Printer    
  208.         bra    ShutDown
  209.  
  210. NoSigBit:    lea.l    NoSigBitText1,a0
  211.         bsr    Printer    
  212.         bra    ShutDown
  213.  
  214. NotNotifying:    lea.l    NoNotifyText1,a0
  215.         bsr    Printer    
  216.         clr.l    d0
  217.         rts
  218.  
  219. Break:        lea.l    BreakText1,a0
  220.         bsr    Printer
  221.         bra    ShutDown
  222.  
  223. Printer:    printa    a0
  224.         rts
  225.  
  226. ;Structures & reservations
  227.  
  228. SigBit:        dc.b    -1
  229. UseNotify:    dc.b    0
  230. OurTask:    dc.l    0
  231. File1:        dc.l    0
  232.  
  233. ;Filenames and other dos related strings
  234.  
  235. FileName1:    dc.b    "T:CS_DateTime",0
  236. CmdString1:    dc.b    "Date TO T:CS_DateTime",0
  237.  
  238. ;Error strings etc...
  239.  
  240. NoSigBitText1:    dc.b    "ERROR: Couldn't allocate signal bit!",13,10,0
  241. NoNotifyText1:    dc.b    "ERROR: Not getting notification on file!",13,10,0
  242. ConvFailText1:    dc.b    "ERROR: Couldn't convert time/date!",13,10,0
  243. OpenFailText1:    dc.b    "ERROR: Couldn't open file!",13,10,0
  244. BreakText1:    dc.b    "***Break: ClockServer",13,10,0
  245.  
  246. ;Information & other strings
  247.  
  248.         dc.b    "$VER: "
  249. UsageText1:    dc.b    "ClockServer 1.02 (26.12.92). (C)opyright Tomi Blinnikka",13,10,13,10
  250. ;        dc.b    13,10,"!!! BETA TESTER VERSION !!!",13,10,13,10,13,10
  251.  
  252.         dc.b    "USAGE: ClockServer [?]",13,10,13,10
  253.         dc.b    "       Where: [?] gives this text",13,10,13,10
  254.         dc.b    "Use CTRL-C to stop program.",13,10,13,10
  255.         dc.b    "Gives time/date to networked machine(s).",13,10
  256.         dc.b    "See docs for more information.",13,10,0
  257.  
  258.         ds.l    0
  259.  
  260. ;library stuff
  261.  
  262.         libnames
  263.  
  264. ;Dos lib stuff
  265.  
  266. NotifyReq1:    dcb.b    48,0
  267.  
  268. ;Buffers
  269.  
  270. DateTime1:    dc.l    0        ;days past 1978
  271.         dc.l    0        ;mins past 00:00
  272.         dc.l    0        ;ticks past min
  273.  
  274.         dc.b    0        ;format = DOS (dd-mmm-yy)
  275.         dc.b    0        ;do not substitute etc.
  276.  
  277.         dc.l    0        ;no day, please
  278.         dc.l    DateStr1    ;pointer
  279.         dc.l    TimeStr1    ;pointer
  280.  
  281.  
  282. DateStr1:    dcb.b    16,0
  283. TimeStr1:    dcb.b    16,0
  284. OutputBuffer1:    dc.b    "Date "
  285. OutputBuffer2:    dcb.b    32,0
  286.  
  287.         END
  288.  
  289.