Annotation of pmsdk/samples/opendlg/toola.asm, revision 1.1.1.1

1.1       root        1: ;/*
                      2: ; *   File Dialog Library
                      3: ; *   Created by Microsoft Corporation, 1989
                      4: ; */
                      5: .xlist
                      6: include cmacros.inc
                      7: .list
                      8: 
                      9: errnz   ?PLM-1          ; this module must use Pascal convention
                     10: 
                     11: TRUE   = 1
                     12: 
                     13: externFP        <WinCreateHeap, WinDestroyHeap>
                     14: 
                     15: sBegin DATA
                     16: externW vhModule
                     17: externD vhheap
                     18: globalW __acrtused,0
                     19: sEnd    DATA
                     20: 
                     21: sBegin CODE
                     22: 
                     23: assumes cs,CODE
                     24: assumes ds,NOTHING
                     25: 
                     26: ; The following trick is to avoid any need for a DS where a constant
                     27: ;   string is needed, any (PSZ)"foo" is replaced by (PSZ)szfoo with
                     28: ;   szfoo created in the Code Selector. As we can't do that with C,
                     29: ;   we do it with MASM.
                     30: ;
                     31:        PUBLIC  szStarStar
                     32: szStarStar  LABEL   BYTE
                     33:        DB      '*','.','*',0
                     34:         PUBLIC  szDot
                     35: szDot   LABEL   BYTE
                     36:         DB      '.',0
                     37:  
                     38: ;======================================================
                     39: ; LCopyStruct(pbSrc, pbDst, cb)
                     40: ;
                     41: cProc   LCopyStruct, <PUBLIC, NODATA, FAR>, <ds,si,di>
                     42: ParmD lpchSrc
                     43: ParmD lpchDst
                     44: ParmW cb
                     45: 
                     46: cBegin
                     47:         mov     cx, cb
                     48:         jcxz    lcopydone           ; all done if crc   == 0
                     49:         lds     si, lpchSrc
                     50:         les     di, lpchDst
                     51:         cmp     si,di
                     52:         jae     lcopyok
                     53:         mov     ax,cx
                     54:         dec     ax
                     55:         add     si,ax
                     56:         add     di,ax
                     57:         std
                     58:         rep     movsb
                     59:         cld
                     60:         jmp     short lcopydone
                     61: lcopyok:
                     62:         cld
                     63:         rep     movsb
                     64: lcopydone:
                     65: 
                     66: cEnd
                     67: 
                     68: 
                     69: ;======================================================
                     70: ; LFillStruct(pbSrc, pbDst, cb)
                     71: ;
                     72: cProc   LFillStruct, <PUBLIC, NODATA, FAR>, <di>
                     73: ParmD lpchDst
                     74: ParmW cb
                     75: ParmB fillByte
                     76: 
                     77: cBegin
                     78:         mov     cx, cb
                     79:         jcxz    lfilldone           ; all done if crc   == 0
                     80:         les     di, lpchDst
                     81:         cld
                     82:         mov     al,fillByte
                     83:         rep     stosb
                     84: lfilldone:
                     85: cEnd
                     86: ;======================================================
                     87: ;
                     88: ; lstrlen: Same as strlen except for taking long ptrs
                     89: ;
                     90: 
                     91: cProc   lstrlen,<PUBLIC, NODATA, FAR>
                     92: ;       parmD   pStr
                     93: cBegin  nogen
                     94:         mov     bx,sp
                     95:         push    di
                     96:         les     di,ss:[bx+4]
                     97:         cld
                     98:         xor     ax,ax                   ; get zero in ax
                     99:         mov     cx,-1                   ; at most 64 k to move
                    100:         repnz   scasb                   ; look for end
                    101:         mov     ax,cx
                    102:         neg     ax
                    103:         dec     ax
                    104:         dec     ax
                    105:         pop     di
                    106:         ret     4
                    107: cEnd    nogen
                    108: 
                    109: 
                    110: lstrsetup:
                    111:         pop     dx
                    112:         mov     bx,sp
                    113: 
                    114:         push    ds
                    115:         push    si
                    116:         push    di
                    117: 
                    118:         lds     si,ss:[bx+4]
                    119:         les     di,ss:[bx+8]
                    120:         regptr  dssi,ds,si
                    121:         regptr  esdi,es,di
                    122:         cld
                    123:         jmp     dx
                    124: 
                    125: lstrfinish  proc    far
                    126:         pop     di
                    127:         pop     si
                    128:         pop     ds
                    129:         ret     8
                    130: lstrfinish  endp
                    131: 
                    132: 
                    133: ;======================================================
                    134: ;
                    135: ;lstrcpy: strcpy with long pointers
                    136: ;
                    137: cProc   lstrcpy,<PUBLIC, NODATA, FAR>
                    138: ;       parmD   pDst                    ; [bx+8]
                    139: ;       parmD   pSrc                    ; [bx+4]
                    140: 
                    141: cBegin  nogen
                    142:         call    lstrsetup
                    143: lcp1:   lodsb
                    144:         stosb
                    145:         or      al,al
                    146:         jnz     lcp1
                    147:         mov     ax,di                   ; point at last byte copied
                    148:         dec     ax
                    149:         mov     dx,es                   ; and its segment
                    150:         jmp     lstrfinish
                    151: cEnd    nogen
                    152: 
                    153: 
                    154: ;======================================================
                    155: ;
                    156: ;lstrcat: Same as strcat except with long ptrs.
                    157: ;
                    158: cProc   lstrcat,<PUBLIC, NODATA, FAR>
                    159: ;   parmD   pDst
                    160: ;   parmD   pSrc
                    161: 
                    162: cBegin  nogen
                    163:         call    lstrsetup
                    164:         xor     ax,ax                   ; get zero in ax
                    165:         mov     cx,-1                   ; at most 64 k to look
                    166:         repnz   scasb                   ; look for end
                    167:         dec     di                      ; Point at null byte
                    168:         jmp     lcp1                    ; jump to lstrcpy loop
                    169: cEnd    nogen
                    170: 
                    171:         ; convert lower case to upper, must preserve es,di,cx
                    172:         public  MyUpper
                    173: MyUpper:
                    174:         cmp     al,'a'
                    175:         jb      myu2
                    176:         cmp     al,'z'
                    177:         jbe     myu1
                    178:         ja      myu2
                    179: myu1:   sub     al,'a'-'A'
                    180: myu2:   ret
                    181: 
                    182:         ; convert upper case to lower, must preserve es,di,cx
                    183:         public  MyLower
                    184: MyLower:
                    185:         cmp     al,'A'
                    186:         jb      myl2
                    187:         cmp     al,'Z'
                    188:         jbe     myl1
                    189: 
                    190:         ja      myl2
                    191: myl1:   add     al,'a'-'A'
                    192: myl2:   ret
                    193: 
                    194: ;=========================================
                    195: ;
                    196: ;lstrcmp:   long ptr lVersion of strcmp
                    197: ;
                    198: cProc   lstrcmp,<PUBLIC, NODATA, FAR>
                    199: ;       parmD   ps1
                    200: ;       parmD   ps2
                    201: cBegin  nogen
                    202:         call    lstrsetup
                    203: lcmploop:
                    204:         xor     ax,ax                   ; AH needs to be zero inside this loop
                    205:         cmp     byte ptr [si],al
                    206:         je      lsidone                 ; si is finished check for di finish
                    207:         cmp     es:byte ptr [di],al
                    208:         je      ldismall                ; di finished before si
                    209:         lodsb
                    210:         mov     bx,ax
                    211:         mov     al,es:[di]
                    212:         inc     di
                    213:         cmp     ax,bx
                    214:         je      lcmploop                ; still equal
                    215:         mov     al,0                    ; preverve flags
                    216:         jb      lsismall                ; si is less than di
                    217: ldismall:
                    218:         inc     ax
                    219:         jmp     lstrfinish
                    220: lsidone:
                    221:         cmp     byte ptr es:[di],0
                    222:         je      lstrfinish
                    223: lsismall:
                    224:         dec     ax
                    225:         jmp     lstrfinish
                    226: cEnd    nogen
                    227: sEnd CODE
                    228: 
                    229: 
                    230: createSeg _INIT,INIT,byte,public,CODE
                    231: 
                    232: sBegin  INIT
                    233: externNP    <InitLibrary>
                    234: assumes CS,INIT
                    235: assumes DS,DATA
                    236: 
                    237: ;======================================================
                    238: ; BOOL FAR PASCAL LibInit ()
                    239: ; 
                    240: ; Initializes the library
                    241: ; int dataSelector       /* DS = automatic data selector */
                    242: ; int wHeapSize;         /* SI = heap size */
                    243: ; int hmod;           /* DI = module handle */
                    244: ;     {
                    245: ;     vhModule = hmod;
                    246: ;     if (!(vhheap = WinCreateHeap(dataSelector, wHeapsize, 0, 0, 0, 0)))
                    247: ;         return FALSE;;
                    248: ;     return (InitLibrary());
                    249: ;     }
                    250: ;
                    251: ; DS already usSet
                    252: ;
                    253: cProc   LibInit,<FAR, PUBLIC>
                    254: cBegin  nogen
                    255:         mov     [vhModule],di           ; Remember module handle
                    256: 
                    257:         sub     ax,ax
                    258:         cCall   WinCreateHeap,<ds, si, ax, ax, ax, ax>
                    259:         mov     bx, ax
                    260:         or      ax, dx
                    261:         jz      loaddone                ; Heap wasn't created
                    262:         mov     word ptr vhheap, bx
                    263:         mov     word ptr vhheap + 2, dx
                    264: 
                    265:         cCall   InitLibrary                ; continue initialization
                    266:         or      ax,ax
                    267:         jnz     loaddone                ; OK, init done
                    268:         cCall   WinDestroyHeap,<vhheap> ; Non OK, destroy the heap
                    269: ;
                    270: ; Return non-zero to indicate successful initialization
                    271: ;
                    272: loaddone:
                    273:         ret
                    274: cEnd
                    275: 
                    276: sEnd    INIT
                    277:         END LibInit

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.