Advertisement
Guest User

Untitled

a guest
Jun 9th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. ; Set up my trap #1 handler
  3. ;
  4.                 move.l  $84.w,old_trap1
  5.                 move.l  #my_trap1,$84.w
  6.  
  7. ;
  8. ; This routine catches mallocs and replaces them with more convinient code!
  9. ;
  10. my_trap1:
  11.                 movea.l SP,A0
  12.                 adda.l  cpu_trap_offset,A0 ;that's either 6 or 8 (68000/68030)
  13.  
  14.                 cmpi.w  #$48,(A0)       ;malloc?
  15.                 beq.s   do_malloc
  16.                 cmpi.w  #$68,(A0)       ;mxalloc?
  17.                 bne.s   no_malloc
  18.  
  19. do_malloc:      movea.l 2(A0),A0        ;requested memory amount
  20.                 move.l  malloc_ptr(PC),D0 ;the pointer to memory we're going to give
  21.                 lea     0(A0,D0.l),A0   ;advance our pointer as many bytes as those reserved
  22.                 move.l  A0,malloc_ptr   ;save the pointer for next malloc
  23.                 rte                     ;and go back to program
  24.  
  25. no_malloc:      cmpi.w  #$49,(A0)       ;mfree?
  26.                 bne.s   no_mfree
  27.                 rte                     ;do nothing
  28.  
  29. no_mfree:
  30. old_trap1       EQU *+2
  31.                 jmp     0               ;jump to O/S' vector
  32.  
  33. malloc_ptr:     DC.L buffer
  34. cpu_trap_offset:DS.L 1
  35.  
  36. buffer:         DS.W 65535
  37.                 DS.W 65535
  38.                 DS.W 65535
  39.                 DS.W 65535
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement