
; this patch has a bug: FreeRemember simulates only
; the original function with the 'ReallyForget' flag set at TRUE.
; So with this patch you can only deallocate the whole allocated memory not just the Remember nodes.

 STRUCTURE remember,0
    APTR next
    ULONG size
    APTR current
    LABEL REMEMBERSIZE

;intuition.library  LVO $fe74 -396  allocremember()
;AllocRemember(rememberKey,size,flags)(a0,d0/d1)
 cnop 0,4
AllocRemember
    movem.l a2/a6/d2/d3/d4,-(a7)
    move.l  a0,a2
    add.l   #REMEMBERSIZE,d0          ; we'll alocate the memory for the remember structure + requested memory in one step
    move.l  d0,d3
    move.l  _ExecBase(pc),a6
     jsr _LVOAllocMem(a6)  ; alloc the node
    move.l  d0,d2
     bne.b .l3
    moveq   #0,d0
    movem.l (a7)+,a2/a6/d2/d3/d4
   rts

.l3
    move.l  d2,a1
    clr.l   (a1)        ; node->next = NULL
    move.l  (a2),d4     ; if *rememberKey == NULL
     bne.b .l5
    move.l  d2,a0       ; initialize remember structure
    move.l  d2,(current,a0)   ; node->current = node
    move.l  d2,(a2)     ; *rememberKey = node
   bra.b .l6

.l5                      ; if *rememberKey != NULL
    move.l  d4,a1
    addq.l  #current,a1
    move.l  (a1),a0     ; cur = *rememberKey->current
    move.l  d2,(a1)     ; *rememberKey->current = node
    move.l  d2,(a0)     ; cur->next = node
.l6
    move.l  d2,a0
    move.l  d3,(size,a0)   ; node->size = size
    move.l  d2,d0
    add.l   #REMEMBERSIZE,d0
.l1
    movem.l (a7)+,a2/a6/d2/d3/d4
    rts

    cnop    0,4

; ReallyForget flag is ignored
FreeRemember ; a0 rememberKey
    movem.l a2/a3/a6/d2,-(a7)
    movea.l  a0,a3
    move.l  (a3),d0
     beq.b .l17
    movea.l d0,a2
.l20
    move.l  (a2),d2       ; cur = rememberKey->next
    move.l  _ExecBase(pc),a6
    move.l  (size,a2),d0
    movea.l  a2,a1
     jsr _LVOFreeMem(a6)
    move.l d2,a2        ; node = cur
    tst.l d2
     bne.b .l20
    clr.l   (a3)
.l17
    movem.l (a7)+,a2/a3/a6/d2
   rts

