home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / MISC_ASM.ZIP / EC.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-05-31  |  8.9 KB  |  299 lines

  1.                 TITLE exec clock, 5-21-89 
  2.         PAGE  63,132
  3.  
  4. cr        equ    0dh            ; ASCII carriage return
  5. lf        equ    0ah            ; ASCII line feed
  6. row        equ    0            ; row position for clock
  7. column        equ    72            ; column  "     "    "
  8.  
  9. code        segment    para public 'code'
  10.         assume    cs:code, ds:code, es:code
  11.  
  12.         org    100h
  13. start:
  14.         mov    sp,offset stk        ; set up the 'stack'
  15.         call    de_alloc        ; free up the hogged ram area,
  16.                         ; must make room for a child
  17.         call    video_set        ; cga/mono detect
  18.         call    time_set        ; read in the trigger time
  19. cloop:
  20.         mov    ah,0            ; get timer count, placed in
  21.         int    1Ah            ; BIOS CALL, result => cx,dx
  22. ;
  23. ; we're going to 'paint' once every eight timer ticks, or every 8/18th seconds
  24.         mov    al,dl            ; set up
  25.         and    al,0F8h            ; mask out 3 low bits, 8 counts
  26.         cmp    al,entry        ; can we enter?
  27.         je    skip_out        ; if same, then no, jump out
  28.         mov    entry,al        ; save it as the next mask
  29.         call    time_paint        ; toss up the time on the crt
  30. ;let's see if it's time to go do an 'exec'
  31.         mov    al,exec_flag        ; flag, bit 0 & bit 1 are used
  32.         cmp    al,3            ; both bits true to go for it
  33.         jz    do_exec
  34. skip_out:
  35.         mov    ah,6            ; get a keypress, don't wait!
  36.         mov    dl,0ffh            ; if we get one, break the loop
  37.         int    21h
  38.         jz    cloop
  39. main_exit:
  40.         mov    ax,4C00h        ; exit to dos
  41.         int    21h
  42. err_exit:
  43.         mov    ax,4c01h        ; exit with 'errorlevel' to 1
  44.         int    21
  45. do_exec:
  46.         clc                ; clear the carry
  47.         call    exec            ; stupid 8088 can't do a call
  48.                         ; on a flag condition
  49.         jc    err_exit        ; did we boo boo?
  50.         jmp    short main_exit        ;
  51.  
  52. ;---------------------------------------------------
  53. ; --------------process the command line parameter
  54. ;---------------------------------------------------
  55. time_set    proc    near
  56.         mov    bx,80h            ; point to command string
  57.         cmp    byte ptr [bx],0        ; if we don't have one
  58.         je    time_explain        
  59.         mov    di,offset hour        ; point to ram for the time
  60.         inc    bx            ; bump to skip over the 'space'
  61. time_get:
  62.         inc    bx            ; hopefully points to first 
  63.         mov    al,[bx]            ; number of time
  64.         cmp    al,cr            ; done & exit
  65.         je    time_done
  66.         mov    [byte ptr di],al    ; stuff to hour, minute
  67.         inc    di            ; bump
  68.         jmp    short time_get        ; loop
  69.  
  70. time_explain:
  71.         mov    dx,offset help_msg    ; explain how it works
  72.         mov    ah,9
  73.         int    21h
  74.         jmp    short time_exit
  75.  
  76. time_done:
  77.         mov    ax,hourW        ; build the string before out
  78.         mov    hour_msgW,ax
  79.         mov    ax,minuteW
  80.         mov    min_msgW,ax
  81.         mov    dx,offset signon_msg    ; sign on, tell its working
  82.         mov    ah,9
  83.         int    21h
  84. time_exit:
  85.         retn
  86. time_set    endp
  87.  
  88. ;----------------------------------------------------------
  89. ; ------------- de-allocation, return mem to the mem pool
  90. ;----------------------------------------------------------
  91. de_alloc    proc    near
  92.         mov    ah,4Ah            ; mod mem alloc
  93.         mov    bx,offset end_code    ; how big we are
  94.         mov    cl,4
  95.         shr    bx,cl            ; converted to pages
  96.         int    21h
  97. ;        jc    alloc_fail        ; we got errors
  98.         retn
  99. ;alloc_fail:
  100. ;        retn        
  101. de_alloc    endp
  102.  
  103. ;-----------------------------------------------------
  104. ; ------------- estab and setup the video seg/offset
  105. ;-----------------------------------------------------
  106. video_set    proc    near
  107.         mov    ax,0F00h        ; find out the video mode
  108.         int    10h            ; video display, 'al' is mode
  109.  
  110.         cmp    al,7            ; is it monochrome mode?
  111.         je    calc_offset        ; yes, jump
  112.         mov    crt_seg,0B800h        ; must be color offset
  113. calc_offset:
  114.         mov    al,row            ; get row, top!
  115.         mov    cl,80            ; 
  116.         imul    cl            ; times '80', in ax
  117.         mov    cl,column        ; get col, far right!
  118.         xor    ch,ch            ; first, zero 'ch'
  119.         add    ax,cx            ; add 
  120.         add    ax,ax            ; mul
  121.         mov    seg_offset,ax        ; save it
  122.         retn
  123. video_set    endp
  124.  
  125. ;--------------------------------------------
  126. ; ------------- paint screen, check to exec
  127. ;--------------------------------------------
  128. time_paint    proc    near
  129.         mov    es,crt_seg        ; load extra seg to crt ram
  130.         mov    di,seg_offset        ; 
  131.  
  132.         mov    ax,cx            ; convert the hours to ascii
  133.         mov    cl,24            ; note a 24 hour clock
  134.         idiv    cl            ; al, ah rem = ax/reg
  135.         mov    al,ah
  136.         cmp    al,0            ; is it midnight?
  137.         jne    not_midnight        ; no, keep value
  138.         mov    al,24            ; yes, set to '24'
  139. not_midnight:
  140.         aam                ; ascii adjust
  141.         add    ax,3030h        ; ascii covert 
  142. ;test for match
  143.         xchg    ah,al            ; swap for test
  144.         cmp    ax,hourW
  145.         jne    hr_continue
  146.         or    exec_flag,2        ;true, set the 1 bit
  147. hr_continue:
  148.         xchg    ah,al            ; swap back to continue
  149.         cmp    ah,30h            ; is tenths digit a '0'?
  150.         jne    tenths_digit        ; no, keep value
  151.         mov    ah,20h            ; yes, set to ' '
  152. tenths_digit:
  153.         xchg    ah,al
  154.                         ; write out the tenths hour
  155.         stosb                ; Store al to es:[di]
  156.         inc    di            ; skip over ATTRIBUTE byte
  157.         mov    al,ah
  158.                         ; write out the units hour
  159.         stosb                ; Store al to es:[di]
  160.         inc    di            ; skip attr.
  161.         mov    al,':'            ; write out the hours to
  162.                         ; minutes separator 
  163.         stosb                ; Store al to es:[di]
  164.  
  165.         inc    di            ; skip attr.
  166.         mov    ax,dx            ; convert the minutes to ascii
  167.         mov    cx,60
  168.         mul    cx            ; dx:ax = reg * ax
  169.         xchg    ax,dx
  170.         aam                ; Ascii adjust
  171.         add    ax,3030h
  172. ;test for match
  173.         xchg    ah,al            ; flip for test
  174.         cmp    ax,minuteW
  175.         jne    min_continue
  176.         or    exec_flag,1        ; true, set the 0 bit
  177. min_continue:
  178. ;        xchg    ah,al            ; flip back
  179. ;        xchg    ah,al            ; oops, well flip for an 'out
  180.                         ; write out the tenths minute
  181.         stosb                ; Store al to es:[di]
  182.         inc    di            ; skip attr
  183.         mov    al,ah
  184.                         ; write out the units minute
  185.         stosb                ; Store al to es:[di]
  186.         inc    di            ; skip attr
  187.         mov    al,':'            ; write out the minutes to
  188.                         ; seconds separator
  189.         stosb                ; Store al to es:[di]
  190.  
  191.         inc    di            ; skip attr
  192.         mov    ax,dx            ; convert the seconds to ascii
  193.         mov    cx,60            ; SECONDS
  194.         mul    cx            ; dx:ax = reg * ax
  195.         xchg    ax,dx
  196.         aam                ; Ascii adjust
  197.         add    ax,3030h
  198.         xchg    ah,al
  199.                         ; write out the tenths second
  200.         stosb                ; Store al to es:[di]
  201.         inc    di            ; skip attr
  202.         mov    al,ah
  203.                         ; write out the units second
  204.         stosb                ; Store al to es:[di]
  205.         retn
  206. time_paint    endp
  207.  
  208. ;-------------------------------------------------
  209. ; ------------- the parent makes a child process
  210. ;-------------------------------------------------
  211. exec        proc    near
  212.         lea    bx,parm_blk        ; seg override for debug of
  213.                         ; set up exec block info
  214. ;now spawn child
  215.         lea    dx,prgm_name
  216.         push    ds            ; ES: was used for crt seg
  217.                 pop     es                      ; ES: must point to our seg
  218.                 mov     ax,ds
  219.                 mov     parm_seg,ax        ; fix up segment registers
  220.                 mov     fcb1_seg,ax        ; of the child process
  221.                 mov     fcb2_seg,ax
  222.         mov    ax,4B00h        ; do exec
  223.         int    21h
  224.         jc    error_exit        ; exit if error spawning child
  225. ;back to the parent        
  226.         mov    ah,4dh            ; get return code
  227.         int    21h            ; used by a parent after the
  228.         jmp    short exec_exit        ; successful completion of call
  229. error_exit:        
  230.         mov    dx,offset err_msg0    ; report error to console
  231.         mov    ah,9
  232.         int    21h
  233. exec_exit:
  234.         retn
  235. exec        endp
  236.  
  237. ;-------------------------------------
  238. ; ---------- data area -----------
  239. ;-------------------------------------
  240. exec_flag    db    0            ; do we have an exec? init off
  241. entry        db    0FFh            ; counter to screen painter
  242. crt_seg        dw    0B000h            ; assume we got a MONO crt
  243. seg_offset    dw    00000h
  244. hourW        label    word            ; for comparison, to allow it
  245. hour        db    '00'            ; target time
  246. minuteW        label    word
  247. minute        db    '00'
  248. err_msg0        db      cr,lf,'Error reported by DOS when trying to run the '
  249.         db    'batch.$';
  250. help_msg    db    cr,lf,'You have envoked "EXEC-CLK" without specifying '
  251.         db    'a time for the batch file',cr,lf
  252.         db    '( EXEC-CLK.BAT ) to execute. The default time for '
  253.         db    'execution is midnight.',cr,lf
  254.         db    'Press any key to immediately stop the process. If '
  255.         db    'you wish to specify',cr,lf
  256.         db    'the time, type "EC 1930" to start up your batch at '
  257.         db    '7:30 at night.$'
  258. signon_msg    db    cr,lf,'You have envoked "EXEC-CLK". The time for '
  259.         db    'batch execution will be '
  260. hour_msgW    label    word
  261. hour_msg    db    '00:'
  262. min_msgW    label    word
  263. min_msg        db    '00.',cr,lf,cr,lf,'$'
  264. ;--------- program data area ----------
  265. stk_seg    dw    0                ; stack segment pointer
  266. stk_off    dw    0                ; save area during exec
  267. ;---------- the needs of the child -----------
  268. prgm_name       db      'C:\COMMAND.COM',0    ; the batch file to do!
  269. fname        equ    ($ + 3)
  270. parm_str    db      fcb1-parm_str-2        ; dynamix adj.
  271.                 db      '/C EXEC-CLK.BAT',cr    ; actual parameter string
  272. fcb1        db    0
  273.         db    11 dup (' ')
  274.         db    25 dup (0)
  275. fcb2        db    0
  276.         db    11 dup (' ')
  277.         db    25 dup (0)
  278. ; --------- parameter block for dos function 4Bh --------
  279. parm_blk    dw    0            ; use current environment
  280.  
  281. parm_off    dw    offset parm_str        ; command line address
  282. parm_seg        dw      0                       ; fill in at init
  283.  
  284. fcb1_off    dw    offset fcb1        ; default FCB #1
  285. fcb1_seg        dw      0                       ; fill in at init
  286.  
  287. fcb2_off    dw    offset fcb2        ; default FCB #2
  288. fcb2_seg        dw      0                       ; fill in at init
  289. ;
  290.         dw    128 dup ( 0 )        ; program stack area
  291. stk        equ    $
  292.  
  293.         align    16            ; round up to next page
  294. end_code    equ    $            ; marker for de-alloc
  295.  
  296. code        ends
  297.  
  298.         end    start
  299.