home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 11 / labnotes / pcmark.asm < prev    next >
Assembly Source File  |  1992-02-24  |  9KB  |  248 lines

  1. ;PCMark.ASM
  2. ;Utility to mark .DLL headers for use with Windows 3.0
  3. ;Copyright (c) 1992 Jay Munro
  4. ;First Published in PC Magazine June 16, 1992
  5. ;----------------------------------------------------------------------------
  6. ;  PCMark sets the version byte, and bits for memory and font use in a
  7. ;  new style header.  It is the programmers responsibility to make sure
  8. ;  the program being marked really is compatible with Windows 3.0
  9. ;
  10. ;----------------------------------------------------------------------------
  11. DosSeg                  ;standard DOS program
  12.  
  13. .Model Small
  14. .Data
  15.    Logo         DB      'PCMark ■ Copyright (c) 1992 ■ Jay Munro',13,10
  16.                 DB      'First Published in PC Magazine June 16, 1992$'
  17.    ErrorNumber  DW      0
  18.    FileHandle   DW      0
  19.    NE_Start     DW      0                       ;offset of new header
  20.    CRLF         DB      10,13,'$'
  21.    TooBig       DB      'Too much on command line $'
  22.    BadDll       DB      'Not a Windows DLL file $'
  23.  
  24.    BeenMarked   DB      'File already is Windows 3 compatible $'
  25.    NoFile       DB      'No file specified $'
  26.    FileError    DB      'File Error $'
  27.    FileNotFound DB      'File Not Found $'
  28.    PathNotFound DB      'Path Not Found $'
  29.    AccessDenied DB      'Access Denied $'
  30.    BadDos       DB      'PCMark needs Version 3.0 DOS or better $'
  31.    Success      DB      'File marked $'
  32.  
  33.    CmdLineMsg   DB      'Checking File '
  34.    Buffer       DB      100h Dup (?)             ;set aside 256 byte buffer
  35.  
  36. .Stack          256
  37.  
  38. .Code
  39.  
  40. Start:
  41.         Mov     AX,@DATA
  42.         Mov     DS,AX
  43.         Assume  DS:@Data
  44.         Mov     DX, Offset Logo ;print logo first
  45.         Call    PrintMsg
  46.  
  47.         Mov     AH,30h          ;get dos version number
  48.         Int     21h
  49.         Cmp     AL,3            ;is it 3 or better?
  50.         Mov     DX,Offset BadDos
  51.         Jge     @F
  52.         Jmp     ErrorMsg        ;nope, then we can't use it
  53.  
  54. @@:
  55. ;----- Get PSP address to retrieve command line arguments
  56.         Mov     AH,62h
  57.         Int     21h
  58.         Push    DS              ;point ES at DS
  59.         Pop     ES              ;
  60.         Mov     DS,BX           ;assign PSP segment to DS
  61.         Mov     CL,Byte Ptr DS:[80h]  ;get length of command line (80h = offset)
  62.         Xor     CH,CH           ;clear CH so we can use all of CX
  63.         Mov     SI,81h          ;point SI to the beginning of the command$
  64.  
  65. FindStart:                      ;move past any leading "white space"
  66.         Mov     AL,[SI]           ;get a character
  67.         Cmp     AL," "          ;is it a blank space?
  68.         Je      @F              ;yes, then get next character
  69.         Cmp     AL,9            ;no, but is it a tab character?
  70.         Jne     CopyCmd         ;no, then go copy the string
  71. @@:
  72.         Inc  SI                 ;point to next byte in COMMAND$
  73.         Loop FindStart
  74.  
  75. CopyCmd:
  76.         Mov     DX,Offset NoFile
  77.         Or      CX,CX
  78.         Jnz     @F
  79.         Push    ES
  80.         Pop     DS
  81.         Jmp     ErrorMsg        ;no command line, no file
  82. @@:
  83.         Lea     DI, Buffer      ;get address of command line
  84.         Rep     Movsb           ;copy command line args to local buffer
  85.         Mov     AX,0024h        ;put a 0$ at the end
  86.         StoSW                   ;store it
  87.         Push    ES              ;restore DS to DGroup
  88.         Pop     DS
  89.         Mov     DX,Offset CmdLineMsg
  90.         Call    PrintMsg
  91.  
  92. OpenFile:
  93.         Mov     SI,Offset Buffer ;save address in SI for later use
  94.         Mov     DX,SI           ;and put it in DX for DOS use
  95.         Mov     AX,3D02h        ;open for read/write - compatibility mode
  96.         Int     21h             ;open it.
  97.         Jc      ErrorLily       ;oops an error
  98.         Mov     BX,AX           ;put file handle in BX
  99.         Mov     FileHandle,BX
  100.  
  101.                                 ;now clear buffer
  102.         Mov     CX,50           ;do 50 words
  103.         Xor     AX,AX
  104.         Mov     DI,SI           ;point DI at start of buffer
  105.         Rep     StoSw
  106.  
  107.         Call    ReadFile
  108.         Jnc     @F
  109.         Jmp     FileErrorExit
  110. @@:
  111.         Cmp     AX,99           ;how about a not enough file?
  112.         Jz      ErrorLily
  113.  
  114. CheckEXE:
  115.         Cmp     Word Ptr [SI],"MZ"      ;is there an EXE signature?
  116.         Mov     AX,99
  117.         Jnz     @F
  118.  
  119. ErrorLily:
  120.         Jmp     FileErrorExit           ;no, get out now
  121. @@:
  122.  
  123.         Mov     DX,[SI+3Ch]             ;get offset of new-style header
  124.                                         ;assuming Stub is < 64K
  125.         Mov     DI,SI                   ;save SI in DI
  126.         Mov     NE_Start,DX             ;save this info
  127.  
  128.         Call    Seek                    ;Move file pointer
  129.         Jnc     @F
  130.         Jmp     FileErrorExit
  131. @@:
  132.         Call    ReadFile                ;and read in some more
  133.         Jnc     CheckSignature
  134.         Jmp     FileErrorExit
  135.  
  136. ;----- Check Signature
  137. CheckSignature:
  138.  
  139.         Cmp     Word Ptr [SI],"EN"      ;check for new-style header signature
  140.         Jz      @F
  141.         Mov     DX,Offset BadDLL
  142.         Jmp     ErrorMsg
  143.  
  144. ;----- Check Window Operating System Flag
  145. @@:
  146.         Mov     AL,[SI+36h]             ;get byte flag
  147.         And     AL,02                   ;check Windows byte
  148.         Jnz     @F
  149.         Mov     DX,Offset BadDLL
  150.         Jmp     ErrorMsg
  151.  
  152. ;----- Set Flags that mark a Win3 file
  153. @@:
  154.         Mov     AL,[SI+37h]
  155.         And     AL,11b                  ;has it already been set?
  156.         Jz      @F
  157.         Mov     DX,Offset BeenMarked
  158.         Jmp     ErrorMsg
  159. @@:
  160.         Or      AL,011b                 ;set the Protected mode and
  161.                                         ;   proportional font bits
  162.         Mov     Byte Ptr [SI+37h],AL    ;put it back
  163.         Mov     Word Ptr [SI+3Eh],300h  ;set for V3
  164.  
  165. ;-----  Put back changed data
  166.         Mov     DX,Ne_Start             ;point SI at start of new header
  167.         Call    Seek                    ;and seek to that spot again
  168.                                         ;DS:DX points to buffer
  169.         Mov     CX,40h                  ;just write what we changed
  170.                                         ;BX contains Handle
  171.         Mov     DX,Offset Buffer        ;and point DX at buffer
  172.         Mov     AH,CL                   ;CL contains 40h, same as service
  173.         Int     21h
  174.         Jc      FileErrorExit
  175.         Mov     DX,Offset Success
  176.         Call    PrintMsg
  177.         Jmp     CloseFile
  178.  
  179. ;------ Error reporter
  180. FileErrorExit:
  181.         Mov     ErrorNumber,AX
  182.         Cmp     AX,2h                   ;file not found
  183.         Jnz     @F
  184.         Mov     DX,Offset FileNotFound
  185.         Jmp     ErrorMsg
  186. @@:
  187.         Cmp     AX,3h                   ;Path not found
  188.         Jnz     @F
  189.         Mov     DX,Offset PathNotFound
  190.         Jmp     ErrorMsg
  191. @@:
  192.         Cmp     AX,5h                   ;AccessDenied
  193.         Jnz     @F
  194.         Mov     DX,Offset AccessDenied
  195.         Jmp     ErrorMsg
  196. @@:
  197.         Cmp     AX,99                   ;file too short, not good
  198.         Mov     DX,Offset BadDLL
  199.         Jmp     ErrorMsg
  200.  
  201. @@:
  202.         Mov     DX,Offset FileError
  203.  
  204. ErrorMsg:
  205.         Call    PrintMsg
  206.         Cmp     FileHandle,0            ;do we have a handle?
  207.         Jz      Exit
  208.  
  209. CloseFile:
  210.         Mov     BX,FileHandle
  211.         Mov     AH,3Eh                  ;close file service
  212.         Int     21h                     ;close it
  213.  
  214. Exit:
  215.         Mov     AL,Byte Ptr ErrorNumber         ;if there was an error, get it
  216.         Mov     AH,4Ch          ;leave peacefully
  217.         Int     21h
  218.  
  219. PrintMsg:                       ;DS:DX enters pointing toward string to print
  220.         Mov     AH,9h           ;service 9, print a string
  221.         Int     21h             ;print it
  222.         Mov     DX,Offset CRLF
  223.         Int     21h
  224.         RetN
  225.  
  226. ReadFile:
  227.         Mov     DX,SI           ;point DX at Buffer
  228.         Mov     AH,3Fh          ;read service
  229.         Mov     CX,40h          ;read in 40h bytes
  230.         Int     21h             ;read it
  231.         Jc      @F
  232.         Cmp     AX,CX           ;did we get enough
  233.         Jz      @F
  234.         Mov     AX,99           ;our own code
  235.  
  236. @@:
  237.         RetN
  238.  
  239. Seek:
  240.         Xor     CX,CX           ;clear MSW of pointer
  241.         Mov     AX,4200h        ;service 42h, offset from start of file
  242.                                 ;BX contains handle
  243.         Int     21h
  244.         RetN
  245.  
  246.  
  247. End     Start                   ;show dos where to begin
  248.