home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC6.DMS / in.adf / libsrc.lha / LIBSRC / memory.asm < prev    next >
Encoding:
Assembly Source File  |  1994-04-15  |  2.7 KB  |  160 lines

  1.  
  2. *    Maxon C++:
  3. *    Library-Modul "memory"
  4. *    Jens Gelhar 19.04.93
  5.  
  6.     xdef    _malloc,malloc__Ui
  7.     xdef    _calloc,calloc__UiUi
  8.     xdef    _free,free__Pv
  9.     xdef    FreeStore__HashTable,___MEMFLAGS
  10.     xdef    _EXIT_1_Please_free_Allocated_Store
  11.     xdef    set_new_handler__PFvp,_set_new_handler
  12.  
  13.     xref    uintmult,exit__i,_errno
  14.  
  15. ExecBase    = 4
  16.  
  17. AllocMem    = -198
  18. FreeMem        = -210
  19.  
  20. HushAnz        = 64
  21.  
  22.  
  23. _calloc:
  24. calloc__UiUi:    ; Stack-Parameter: (unsigned num, unsigned size)
  25.     move.l 8(a7),d0
  26.     cmp.l #2,d0
  27.     bls.b noalign
  28.     addq.l #1,d0
  29.     and.w #$FFFE,d0
  30. noalign:    move.l d1,-(a7)
  31.     move.l 8(a7),d1
  32.     jsr uintmult
  33.     move.l (a7)+,d1
  34.     move.l d0,-(a7)
  35.     jsr _malloc(pc)
  36.     addq.l #4,a7
  37.     rts
  38.  
  39. memhush: ; Aus Adresse d0 Hashnummer*4 machen
  40.     lsr.l #4,d0
  41.     and.l #4*(HushAnz-1),d0
  42.     rts
  43.  
  44. _malloc:
  45. malloc__Ui:    ; Stack-Parameter: (unsigned)
  46.     move.l 4(a7),d0
  47.     addq.l #3,d0
  48.     and.w #$FFFC,d0
  49.     addq.l #8,d0
  50.     movem.l d2/a6,-(a7)
  51.     move.l ExecBase.w,a6
  52.     move.l ___MEMFLAGS(pc),d1
  53.     move.l d0,-(a7)
  54.     jsr AllocMem(a6)
  55.     move.l (a7)+,d1
  56.     tst.l d0
  57.     beq.b memfail
  58.     move.l d0,a0
  59.     bsr.b memhush
  60.     lea    FreeStore__HashTable,a1
  61.     add.l    d0,a1
  62.     move.l (a1),(a0)
  63.     move.l a0,(a1)
  64.     move.l d1,4(a0)
  65.     move.l a0,d0
  66.     addq.l #8,d0
  67.     bra.b memret
  68. memfail:    move.l NewHandler(pc),d0
  69.     beq.b memret
  70.     move.l d0,a6
  71.     jsr (a6)
  72.     movem.l (a7)+,d2/a6
  73.     bra.b _malloc           ; nochmal versuchen
  74. memret:    movem.l (a7)+,d2/a6
  75.     rts
  76.  
  77. set_new_handler__PFvp:
  78. _set_new_handler:
  79.     move.l NewHandler(pc),d0
  80.     move.l 4(a7),NewHandler
  81.     rts
  82.  
  83. NewHandler:    dc.l 0
  84.  
  85.  
  86. _free:
  87. free__Pv: ; Stack-Parameter: Zeiger
  88.     movem.l d0-d2/a0/a1/a6,-(a7)
  89.     move.l 6*4+4(a7),d0
  90.     beq.b freret
  91.     subq.l #8,d0
  92.     move.l d0,a1
  93.     bsr memhush
  94.     lea    FreeStore__HashTable,a0
  95.     add.l    d0,a0
  96. freLoop: move.l (a0),d1
  97.     beq.b freIndirect
  98.     cmp.l a1,d1
  99.     beq.b freFound
  100.     move.l d1,a0
  101.     bra.b freLoop
  102. freIndirect:    ; Eintrag "indirekt", d. h. innerhalb anderem Eintrag, vorhanden?
  103.     lea FreeStore__HashTable,a6
  104.     moveq #HushAnz-1,d2
  105. freSchleif:    ; Hashtables durchackern:
  106.     move.l a6,a0
  107.     addq.l #4,a6
  108. freInIt:    move.l (a0),d1
  109.     beq.b freNextList
  110.     cmp.l a1,d1
  111.     bhi.b freInNot
  112.     move.l a0,-(a7)
  113.     move.l d1,a0
  114.     add.l 4(a0),d1
  115.     move.l (a7)+,a0
  116.     cmp.l a1,d1
  117.     bhs.b freThats
  118. freInNot:    move.l (a0),d1
  119.     move.l d1,a0
  120.     bra.b freInIt
  121. freNextList:
  122.     dbra d2,freSchleif
  123.     bra.b freFail
  124. freThats:    move.l (a0),a1
  125. freFound:
  126.     move.l (a1),(a0)
  127.     move.l 4(a1),d0
  128.     move.l ExecBase.w,a6
  129.     jsr FreeMem(a6)
  130. freret:    movem.l (a7)+,d0-d2/a0/a1/a6
  131.     rts
  132. freFail:    move.l #996,d0
  133.     move.l d0,-(a7)
  134.     move.l d0,_errno
  135.     jsr exit__i
  136.  
  137.  
  138. _EXIT_1_Please_free_Allocated_Store:
  139.     lea FreeStore__HashTable,a0
  140.     moveq #HushAnz-1,d1
  141. CleanUp:    move.l (a0),d0
  142.     beq.b CleanNext
  143.     addq.l #8,d0
  144.     move.l d0,-(a7)
  145.     bsr _free
  146.     addq.l #4,a7
  147.     bra.b CleanUp
  148. CleanNext:    addq.l #4,a0
  149.     dbra d1,CleanUp
  150.     rts
  151.  
  152. ___MEMFLAGS:    dc.l $10000
  153.  
  154.     section bss,"bss"
  155.  
  156. FreeStore__HashTable:    blk.l HushAnz,0
  157.  
  158.     end
  159.  
  160.