home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wunderki.zip / OBJH.ASM < prev    next >
Assembly Source File  |  1993-08-16  |  3KB  |  162 lines

  1.  
  2. ; *******************************************************
  3. ; *                            *
  4. ; *     Turbo Pascal Run-time Library                   *
  5. ; *    Object Handling Routines            *
  6. ; *                            *
  7. ; *     Copyright (c) 1989,92 Borland International     *
  8. ; *                            *
  9. ; *******************************************************
  10.  
  11.     TITLE    OBJH
  12.  
  13.     INCLUDE    SE.ASM
  14.  
  15. CODE    SEGMENT    BYTE PUBLIC
  16.  
  17.     ASSUME    CS:CODE
  18.  
  19. ; Externals
  20.  
  21.     EXTRN    NewMemory:NEAR,DisMemory:NEAR,HaltError:NEAR
  22.  
  23. ; Publics
  24.  
  25.     PUBLIC    Construct,Destruct,CopyObject,MethodCheck
  26.  
  27. ; Constructor support routine
  28. ; In    DI = Method field offset
  29. ;    BP = Constructor stack frame
  30. ; Out    ZF = 1 if failed
  31.  
  32. Construct:
  33.  
  34.     MOV    SI,[BP+10]        ;SI = VMT offset
  35.     CMP    SI,1            ;Inherited constructor call?
  36.     JB    @@2            ;Yes, exit with ZF = 0
  37.     LES    BX,[BP+6]        ;ES:BX = Self
  38.     MOV    AX,ES            ;Self = nil?
  39.     OR    AX,BX
  40.     JE    @@3            ;Yes, allocate
  41.     MOV    WORD PTR [BP+10],0    ;No deallocation on Fail
  42. @@1:    MOV    ES:[BX+DI],SI        ;Store VMT link in object
  43. @@2:    RETF                ;Exit
  44. @@3:    MOV    AX,[SI]            ;AX = Object size
  45.     IF WindowsVersion
  46.     INC    BP            ;Setup stack frame
  47.     PUSH    BP
  48.     MOV    BP,SP
  49.     PUSH    DS
  50.     ELSE
  51.     PUSH    BP            ;Setup stack frame
  52.     MOV    BP,SP
  53.     ENDIF
  54.     PUSH    SI
  55.     PUSH    DI
  56.     CALL    NewMemory        ;Allocate dynamic object
  57.     POP    DI
  58.     POP    SI
  59.     IF WindowsVersion
  60.     MOV    SP,BP            ;Remove stack frame
  61.     POP    BP
  62.     DEC    BP
  63.     ELSE
  64.     POP    BP
  65.     ENDIF
  66.     JC    @@4            ;Error if allocation failed
  67.     MOV    CX,AX            ;Out of memory?
  68.     OR    CX,DX
  69.     JE    @@2            ;Yes, exit with ZF = 1
  70.     MOV    [BP+6],AX        ;Store in Self pointer
  71.     MOV    [BP+8],DX
  72.     MOV    ES,DX            ;ES:BX = Self
  73.     MOV    BX,AX
  74.     JMP    @@1            ;Init and exit with ZF = 0
  75. @@4:    MOV    SP,BP            ;Remove callers stack frame
  76.     POP    BP
  77.     IF WindowsVersion
  78.     DEC    BP
  79.     ENDIF
  80.     MOV    AX,203
  81.     JMP    HaltError
  82.  
  83. ; Destructor support routine
  84. ; In    DI = Method field offset
  85. ;    BP = Destructor stack frame
  86.  
  87. Destruct:
  88.  
  89.     CMP    WORD PTR [BP+10],0    ;Inherited destructor call?
  90.     JE    @@1            ;Yes, exit
  91.     LES    BX,[BP+6]        ;ES:BX = Self
  92.     MOV    SI,ES:[BX+DI]        ;SI = VMT offset
  93.     MOV    AX,[SI]            ;AX = Object size
  94.     MOV    CX,BX            ;BX:CX = Self
  95.     MOV    BX,ES
  96.     IF WindowsVersion
  97.     INC    BP            ;Setup stack frame
  98.     PUSH    BP
  99.     MOV    BP,SP
  100.     PUSH    DS
  101.     ELSE
  102.     PUSH    BP            ;Setup stack frame
  103.     MOV    BP,SP
  104.     ENDIF
  105.     CALL    DisMemory        ;Dispose dynamic object
  106.     IF WindowsVersion
  107.     MOV    SP,BP            ;Remove Windows stack frame
  108.     POP    BP
  109.     DEC    BP
  110.     ELSE
  111.     POP    BP            ;Remove Windows stack frame
  112.     ENDIF
  113.     JC    @@2            ;Error if deallocation failed
  114. @@1:    XOR    AX,AX            ;Self = nil
  115.     MOV    [BP+6],AX
  116.     MOV    [BP+8],AX
  117.     RETF
  118. @@2:    MOV    SP,BP            ;Remove callers stack frame
  119.     POP    BP
  120.     IF WindowsVersion
  121.     DEC    BP
  122.     ENDIF
  123.     MOV    AX,204
  124.     JMP    HaltError
  125.  
  126. ; Object assignment support routine
  127.  
  128. CopyObject:
  129.  
  130.     PUSH    BP
  131.     MOV    BP,SP
  132.     LES    DI,[BP+8]
  133.     MOV    BX,[BP+6]
  134.     ADD    BX,DI
  135.     MOV    AX,ES:[BX]
  136.     MOV    SI,AX
  137.     MOV    CX,DS:[SI]
  138.     MOV    DX,DS
  139.     LDS    SI,[BP+12]
  140.     CLD
  141.     REP    MOVSB
  142.     MOV    DS,DX
  143.     MOV    ES:[BX],AX
  144.     POP    BP
  145.     RETF    10
  146.  
  147. ; Check method table
  148.  
  149. MethodCheck:
  150.  
  151.     MOV    CX,[DI]
  152.     JCXZ    @@1
  153.     ADD    CX,[DI+2]
  154.     JNE    @@1
  155.     RETF
  156. @@1:    MOV    AX,210
  157.     JMP    HaltError
  158.  
  159. CODE    ENDS
  160.  
  161.     END
  162.