home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / DIR / FDATE2.ZIP / FDATE2.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-05-22  |  9.7 KB  |  406 lines

  1. PAGE    58,132
  2. TITLE    FDATE    9-3-85    [5-22-92]
  3. ;v1.1    Toad Hall Disassembly and Tweak, 22 May 92
  4.  
  5. ; - Minor tightening
  6. ; - No functional changes.
  7.  
  8. LF    EQU    0AH
  9. CR    EQU    0DH
  10. ;
  11. CSEG    SEGMENT
  12.     ASSUME DS:CSEG, SS:CSEG ,CS:CSEG ,ES:CSEG
  13.     ORG    100H
  14.  
  15. FDate2    PROC    NEAR
  16.     JMP    Start_1E3        ;skip over data
  17.  
  18. dateflag103    db    0        ;non-0 if we have a date to set
  19. timeflag105    db    0        ;non-0 if we have a time to set
  20. date107        dw    0        ;processed DOS-type date
  21. time109        dw    0        ;processed DOS-type time
  22. filedate10B    dw    0        ;original file date
  23. filetime10D    dw    0        ;original file time
  24. whour10F    dw    0
  25. wminute111    dw    0
  26. wseconds113    dw    0
  27. wday115        dw    0
  28. wmonth117    dw    0
  29. wyear119    dw    0
  30. bchar11B    DB    0        ;save date or time separator char
  31. argc11C        db    0        ;temp arg counter (was word)    v1.1
  32. arg11E        dw    0        ;argv[] pointer
  33.  
  34. usage$    DB    'Usage is: FDATE <filename> [mm/dd/yy] [hh:mm:ss]'
  35.     DB    CR,LF,'$'
  36. notfound    DB    'Could not find file'
  37.     DB    CR,LF,'$'
  38. baddate    DB    'Incorrect date, format is mm/dd/yy or mm-dd-yy'
  39.     DB    CR,LF,'$'
  40. badtime    DB    'Incorrect time, format is hh:mm:ss'
  41.     DB    CR,LF,'$'
  42. filerr    DB    'Internal error during file access'
  43.     db    CR,LF,'$'
  44.  
  45.  
  46. Start_1E3:
  47.     CALL    GetParms_3F0
  48.     CMP    argc440,0        ;any args at all?
  49.     JZ    Usage_241        ;nope, Usage, quit
  50.     CMP    argc440,3        ;more than 3?
  51.     JA    Usage_241        ;yep, Usage, quit
  52.     CMP    argc440,1        ;just one?  (should be filename)
  53.     JNZ    Got_DateParms_24D    ;nope, 2, we have date/time parms too
  54.  
  55.     MOV    AH,2AH            ;Get date
  56.     INT    21H            ;CX=year 1980..2099
  57.     SUB    CX,076CH        ;year minus 1980
  58.     MOV    wyear119,CX        ;save it
  59. ;v1.1    MOV    CL,DH            ;month (1..12)
  60. ;    MOV    CH,0            ;clear msb
  61. ;    MOV    wmonth117,CX        ;save month
  62. ;    MOV    CL,DL            ;day of month
  63. ;    MOV    wday115,CX        ;save day of month
  64.     mov    al,dh            ;month (1..12)
  65.     xor    ah,ah            ;clear msb
  66.     mov    wmonth117,ax        ;save month
  67.     mov    al,dl            ;day of month
  68.     mov    wday115,ax        ;save day of month
  69.  
  70.     MOV    AH,2CH            ;Get system time
  71.     INT    21H
  72. ;v1.1    MOV    AX,0            ;clear msb
  73.     xor    ax,ax            ;clear msb            v1.1
  74.     MOV    AL,CH            ;hour
  75.     MOV    whour10F,AX
  76.     MOV    AL,CL            ;minute
  77.     MOV    wminute111,AX
  78.     MOV    AL,DH            ;seconds
  79.     MOV    wseconds113,AX
  80.     CMP    argc440,1
  81.     JNZ    Got_DateParms_24D    ;we have date/time parms too
  82.  
  83.     MOV    dateflag103,1        ;flag we got date
  84.     MOV    timeflag105,1        ;flag we got time
  85.     JMP    Set_FileDTG_343        ;go set this file's DTG
  86.  
  87. Usage_241:
  88.     MOV    DX,OFFSET usage$
  89.     MOV    AH,9
  90.     INT    21H
  91.     MOV    AL,1
  92.     JMP    Term_3D3
  93.  
  94.  
  95. ;We have more than just a filename.
  96. ;Process other parms for possible date/time.
  97.  
  98. Got_DateParms_24D:
  99.     MOV    al,argc440        ;cmdline argc            v1.1
  100.     MOV    argc11C,al        ;save total arg count        v1.1
  101.     MOV    arg11E,0        ;start with arg 0
  102.  
  103. Lup259:    ADD    arg11E,2        ;bump argc (*2 for words)
  104.     DEC    argc11C            ;decr art count
  105.     JNZ    Skp267            ;not done yet
  106.      JMP    Set_FileDTG_343        ;go set this file's DTG
  107.  
  108. Skp267:    MOV    BX,arg11E        ;argc
  109.     MOV    SI,[BX+argv442]        ;argv[x]
  110.     CALL    AtoB_550        ;convert to number if appropriate
  111.     CMP    AL,'/'            ;this date separator?
  112.     JZ    Do_Date_289        ;yep, doing date
  113.     CMP    AL,'-'            ;this date separator?
  114.     JZ    Do_Date_289        ;yep, doing date
  115.     CMP    AL,':'            ;time separator?
  116.     JZ    Do_Time_2E9        ;yep, doing time
  117.     JMP    SHORT    Usage_241    ;error, Usage, die
  118.  
  119. ;v1.1    Moved this down closer to Term_3D3 and error msgs
  120. ;MsgTerm_280:
  121. ;    MOV    AH,9            ;display msg in DX
  122. ;    INT    21H
  123. ;    MOV    AL,2            ;ERRORLEVEL 2
  124. ;    JMP    Term_3D3        ;terminate
  125.  
  126. ;Separator is '/' or '-' : We're doing date
  127. Do_Date_289:
  128.     CMP    dateflag103,0        ;did we ever get date?
  129.     JZ    Skp292            ;nope, not yet, ok
  130.      JMP    SHORT    Usage_241    ;got two dates: bad, die
  131.  
  132. Skp292:    MOV    dateflag103,1        ;flag we got date
  133.     CMP    CX,0
  134.     JBE    BadDate_2E4
  135.     CMP    CX,0CH            ;months 1..12
  136.     JA    BadDate_2E4        ;bad month
  137.  
  138.     MOV    wmonth117,CX        ;save as month
  139.     MOV    bchar11B,AL        ;save '/' or '-'
  140.     INC    SI
  141.     CALL    AtoB_550        ;should be getting day of month
  142. ;v1.1    CMP    AL,0
  143.     or    al,al    ;0        ;parm separator?
  144.     JZ    Skp2B7            ;yep, check day
  145.      CMP    AL,bchar11B        ;we hit a date separator?
  146.      JNZ    BadDate_2E4        ;nope, bad, terminate
  147.  
  148. Skp2B7:    CMP    CX,0            ;any numeric value?
  149.     JBE    BadDate_2E4        ;nope, bad
  150.     CMP    CX,1FH            ;day is only 1..31
  151.     JA    BadDate_2E4        ;bad
  152.     MOV    wday115,CX        ;save day
  153. ;v1.1    CMP    AL,0
  154.     or    al,al    ;0        ;this parm's terminator?    v1.1
  155.     JNZ    Skp2CB            ;nope, real char
  156.      JMP    SHORT    Lup259        ;next parm
  157.  
  158. Skp2CB:    INC    SI            ;next char
  159.     CALL    AtoB_550        ;parse year
  160. ;v1.1    CMP    AL,0
  161.     or    al,al    ;0        ;hit parm separator?
  162.     JNZ    BadDate_2E4        ;nope, date was bad
  163.  
  164.     CMP    CX,50H            ;min date 80 as in 1980
  165.     JB    BadDate_2E4        ;bad year
  166.     CMP    CX,63H            ;only up to 1999?
  167.     JA    BadDate_2E4        ;bad year
  168.      MOV    wyear119,CX        ;save as year
  169.      JMP    Lup259            ;next parm
  170.  
  171. BadDate_2E4:
  172.     MOV    DX,OFFSET baddate    ;'Incorrect date'
  173.     JMP    MsgTerm_280        ;display, die
  174.  
  175. ;Hit ':' in cmdline.  Now working time.
  176. Do_Time_2E9:
  177.     CMP    timeflag105,0        ;did we get time yet?
  178.     JZ    Skp2F3            ;not yet, ok
  179.      JMP    Usage_241        ;bad, msg, terminate
  180.  
  181. Skp2F3:    MOV    timeflag105,1        ;flag we got time
  182.     CMP    CX,18H            ;<= 24?
  183.     JA    BadTime_33D        ;>24, bad time, die
  184.     MOV    whour10F,CX        ;save hours
  185.     MOV    bchar11B,AL        ;working this ':' separator
  186.     INC    SI            ;next char
  187.     CALL    AtoB_550        ;get minutes
  188. ;v1.1    CMP    AL,0
  189.     or    al,al            ;parm separator?        v1.1
  190.     JZ    Skp313            ;yep
  191.     CMP    AL,bchar11B        ;still ':' separator?
  192.     JNZ    BadTime_33D        ;nope, bad, die
  193.  
  194. Skp313:    CMP    CX,3BH            ;max 59 minutes?
  195.     JA    BadTime_33D        ;bad, die
  196.     MOV    wminute111,CX        ;save minutes
  197. ;v1.1    CMP    AL,0
  198.     or    al,al            ;parm separator yet?
  199.     JNZ    GetSeconds_329        ;not yet
  200.      MOV    wseconds113,0        ;yep, zero seconds out
  201.      JMP    Lup259            ;next parm
  202.  
  203. GetSeconds_329:
  204.     INC    SI            ;bump past separator
  205.     CALL    AtoB_550        ;get seconds
  206. ;v1.1    CMP    AL,0
  207.     or    al,al    ;0        ;separator yet?
  208.     JNZ    BadTime_33D        ;nope, time is bad, die
  209.     CMP    CX,3BH            ;max 59 seconds
  210.     JA    BadTime_33D        ;>59, bad, die
  211.  
  212.     MOV    wseconds113,CX        ;save as seconds
  213.     JMP    Lup259            ;next parm
  214.  
  215. BadTime_33D:
  216.     MOV    DX,OFFSET badtime    ;'Incorrect time'
  217.     JMP    MsgTerm_280        ;display, die
  218.  
  219.  
  220. ;We have time/date.  Set the file date/time to it.
  221.  
  222. Set_FileDTG_343:
  223.     MOV    AX,wyear119
  224.     SUB    AX,50H        ;-80
  225.     MOV    CX,4
  226.     SHL    AX,CL        ;*16
  227.     OR    AX,wmonth117
  228.     MOV    CX,5        ;*32
  229.     SHL    AX,CL
  230.     OR    AX,wday115
  231.     MOV    date107,AX    ;here's the processed DOS date word
  232.  
  233.     MOV    AX,whour10F    ;build a DOS-format time word
  234.     MOV    CX,6
  235.     SHL    AX,CL
  236.     OR    AX,wminute111
  237.     MOV    CX,5
  238.     SHL    AX,CL
  239.     MOV    BX,wseconds113
  240.     SHR    BX,1
  241.     OR    AX,BX
  242.     MOV    time109,AX        ;here's the processed date/time value
  243.  
  244.     MOV    DX,argv442        ;pointer to filename
  245. ;v1.1    MOV    AL,2            ;read-only?
  246. ;    MOV    AH,3DH            ;open file
  247.     mov    ax,3D02H        ;open file, read-only        v1.1
  248.     INT    21H
  249.     JB    NotFound_3D8        ;open failed
  250.  
  251.     MOV    BX,AX            ;file handle into BX
  252.     MOV    al,dateflag103        ;get date flag            v1.1
  253.     AND    al,timeflag105        ;mask with time flag        v1.1
  254.     JNZ    Skp3A1            ;we already have cmdline date/time
  255. ;v1.1    MOV    AH,57H            ;get file date/time
  256. ;v1.1    MOV    AL,0
  257.     mov    ax,5700H        ;get file date/time        v1.1
  258.     INT    21H
  259.     JB    File_Error_3DE        ;failed
  260.  
  261.     MOV    filedate10B,DX        ;save date
  262.     MOV    filetime10D,CX        ;save time
  263.  
  264. Skp3A1:    CMP    timeflag105,0        ;ever get time?
  265.     JZ    Skp3AE            ;nope
  266.      MOV    AX,time109        ;processed time
  267.      MOV    filetime10D,AX
  268. Skp3AE:    CMP    dateflag103,0
  269.     JZ    Skp3BB
  270.      MOV    AX,date107        ;processed date
  271.      MOV    filedate10B,AX
  272. Skp3BB:
  273. ;v1.1    MOV    AL,1
  274. ;    MOV    AH,57H
  275.     mov    ax,5701H        ;set file time            v1.1
  276.     MOV    DX,filedate10B        ;to this date
  277.     MOV    CX,filetime10D        ; and time
  278.     INT    21H
  279.     JB    File_Error_3DE        ;failed
  280.  
  281.     MOV    AH,3EH            ;close file
  282.     INT    21H
  283.     JB    File_Error_3DE        ;failed
  284.  
  285. ;v1.1    MOV    AL,0
  286.     xor    ax,ax            ;ERRORLEVEL 0            v1.1
  287.  
  288. Term_3D3:
  289.     MOV    AH,4CH            ;terminate
  290.     INT    21H
  291. ;dumb    RET_NEAR
  292.  
  293. NotFound_3D8:
  294.     MOV    DX,OFFSET notfound    ;'Could not find file'
  295.     JMP    short MsgTerm_280
  296.  
  297. File_Error_3DE:
  298.     MOV    DX,OFFSET filerr    ;'Internal error during file access'
  299. ;    JMP    MsgTerm_280
  300. MsgTerm_280:
  301.     MOV    AH,9            ;display msg in DX
  302.     INT    21H
  303.     MOV    AL,2            ;ERRORLEVEL 2
  304.     JMP    Term_3D3        ;terminate
  305.  
  306. ;dumb    DB    0CH DUP(0)
  307. FDate2    ENDP
  308.  
  309.  
  310. GetParms_3F0    PROC    NEAR
  311. ;dumb    PUSH    DS
  312. ;dumb    PUSH    ES
  313. ;dumb    CLD
  314. ;dumb    MOV    AX,CS
  315. ;dumb    MOV    DS,AX
  316. ;dumb    MOV    ES,AX
  317.     MOV    SI,80H            ;PSP cmdline
  318.     MOV    CL,[SI]            ;cmdline length
  319. ;v1.1    MOV    CH,0
  320.     xor    ch,ch            ;clear msb
  321.     PUSH    CX            ;save cmdline length
  322.     INC    SI            ;bump to space beyond length
  323.     MOV    DI,OFFSET cmdline_4C2    ;cmdline buffer
  324.     REPZ    MOVSB
  325.     MOV    BYTE PTR [DI],0        ;Asciize
  326.  
  327.     POP    CX            ;cmdline length
  328.     MOV    SI,OFFSET cmdline_4C2
  329.     MOV    argc440,0
  330.     MOV    BX,OFFSET argv442    ;argv[] array
  331.     mov    al,20H            ;constant for scanning        v1.1
  332. Lup417:
  333. ;v1.1    MOV    AL,20H    ;' '        ;gobble leading spaces
  334.     XCHG    SI,DI
  335.     REPZ    SCASB            ;scan for ' '
  336.     DEC    DI            ;back up to it
  337.     XCHG    SI,DI            ;swap
  338.     JCXZ    GetParms_X        ;zeroed out cmdline, done
  339.     MOV    [BX],SI            ;save pointer to parm[argc]
  340.     ADD    BX,2            ;bump to next parm[]
  341.     INC    argc440            ;inc parm counter
  342. ;v1.1    MOV    AL,20H    ;' '
  343.     XCHG    SI,DI            ;swap back
  344.     REPNZ    SCASB            ;find next separator
  345.     DEC    DI            ;back up to it
  346.     XCHG    SI,DI            ;swap
  347.     JCXZ    GetParms_X        ;zeroed out cmdline, done
  348.     MOV    BYTE PTR [SI],0        ;AsciiZ the string
  349.     INC    SI            ;bump to next char
  350.     DEC    CX            ;adjust counter
  351.     JMP    SHORT    Lup417        ;next parm, please
  352.  
  353. GetParms_X:
  354. ;dumb    POP    ES
  355. ;dumb    POP    DS
  356.     RET
  357. GetParms_3F0    ENDP
  358.  
  359. ;v1.1    Moved these variables down to code end to be dynamic.
  360.  
  361. ;argc440    db    0        ;was word            v1.1
  362. ;;Array of pointers to cmdline args
  363. ;;argv[]
  364. ;argv442    DB    80H DUP(0)
  365. ;cmdline_4C2    DB    5AH DUP(0)
  366. ;    DB    34H DUP(0)
  367.  
  368. ;Convert ASCII string at SI to binary integer in CX
  369. AtoB_550    PROC    NEAR
  370.     PUSH    BX
  371.     MOV    BX,0AH            ;constant multiplier
  372. ;v1.1    MOV    CX,0
  373.     xor    cx,cx    ;0        ;initialize            v1.1
  374.  
  375. Lup557:    MOV    AL,[SI]            ;snarf the char
  376.     CMP    AL,'0'
  377.     JB    Ret56D
  378.     CMP    AL,'9'
  379.     JA    Ret56D
  380.     SUB    AL,30H    ;'0'        ;Deasciify
  381.     CBW
  382.     XCHG    CX,AX
  383.     IMUL    BX            ;*10
  384.     ADD    AX,CX
  385.     XCHG    CX,AX            ;accumulate in CX
  386.     INC    SI            ;next char
  387.     JMP    SHORT    Lup557
  388.  
  389. Ret56D:    POP    BX
  390.     RET    ;_NEAR
  391. AtoB_550    ENDP
  392.  
  393.  
  394. ;argc440    db    0            ;was word        v1.1
  395. ;;Array of pointers to cmdline args
  396. ;;argv[]
  397. ;argv442    DB    80H DUP(0)
  398. ;cmdline_4C2    DB    5AH DUP(0)
  399. ;    DB    34H DUP(0)
  400. argc440    label    byte
  401. argv442        EQU    word ptr argc440+1        ;128 bytes
  402. cmdline_4C2    EQU    byte ptr argc440+129
  403.  
  404. CSEG    ENDS
  405.     END    FDate2
  406.