1; int __CALLEE__ adt_ListPrepend_callee(struct adt_List *list, void *item) 2; 02.2003, 06.2005 aralbrec 3 4SECTION code_clib 5PUBLIC adt_ListPrepend_callee 6PUBLIC _adt_ListPrepend_callee 7PUBLIC ASMDISP_ADT_LISTPREPEND_CALLEE 8PUBLIC ASMDISP_ADT_LISTPREPEND2 9 10EXTERN ADTemptylistadd 11EXTERN _u_malloc 12 13.adt_ListPrepend_callee 14._adt_ListPrepend_callee 15 16 pop hl 17 pop bc 18 pop de 19 push hl 20 21.asmentry 22 23; enter: de = struct adt_List * 24; bc = item * 25; exit : carry reset if fail (no memory) and hl = 0 else: 26; new item prepended to start of list, current points at new item, hl != 0 27; uses : af, bc, de, hl 28 29 push bc 30 push de 31 ld hl,6 ; sizeof(struct adt_ListNode) 32 push hl 33 call _u_malloc 34 pop bc 35 pop de 36 pop bc 37 ret nc ; alloc memory failed 38 39 ld (hl),c 40 inc hl 41 ld (hl),b ; store user item into new NODE 42 inc hl ; hl = new NODE.next 43 ex de,hl ; hl = LIST*, de = new NODE.next 44 45 ld a,(hl) 46 inc (hl) ; increase item count 47 inc hl 48 jp nz, noinchi 49 inc (hl) 50 jp cont 51 52.noinchi 53 54 or (hl) ; hl = LIST.count+1, de = new NODE.next, list count & item done 55 jp z, ADTemptylistadd ; if there are no items in list jump to emptylistadd helper 56 57.cont 58 59 inc hl ; hl = LIST.state, de = new NODE.next, list count & item done 60 61.ADTListPrepend2 62 63 ld (hl),1 ; current INLIST 64 inc hl 65 dec de 66 dec de ; de = new NODE 67 push de ; stack = new NODE 68 ld (hl),d 69 inc hl 70 ld (hl),e ; current = new NODE 71 inc hl ; hl = head 72 inc de 73 inc de ; de = new NODE.next 74 ldi 75 ldi ; new NODE.next = head, hl = tail 76 xor a 77 ld (de),a 78 inc de 79 ld (de),a ; new NODE.prev = NULL 80 dec hl 81 ld e,(hl) 82 dec hl ; hl = head 83 ld d,(hl) ; de = old head NODE 84 pop bc ; bc = new NODE 85 ld (hl),b 86 inc hl 87 ld (hl),c ; head = new NODE 88 ex de,hl ; hl = old head NODE 89 inc hl 90 inc hl 91 inc hl 92 inc hl ; hl = old head NODE.prev 93 ld (hl),b 94 inc hl 95 ld (hl),c ; old head NODE.prev = new NODE 96 scf 97 ret 98 99DEFC ASMDISP_ADT_LISTPREPEND_CALLEE = asmentry - adt_ListPrepend_callee 100DEFC ASMDISP_ADT_LISTPREPEND2 = ADTListPrepend2 - adt_ListPrepend_callee 101