~z88dk-team/z88dk-pkg/trunk

« back to all changes in this revision

Viewing changes to libsrc/adt/linkedlist/adt_ListPopFront.asm

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-02-12 08:23:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080212082349-wgijt44scmgje90o
Tags: 1.7.ds1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - build z88dk and z88dk-bin binary packages for lpia too
  - update Maintainer field as per spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
; void __FASTCALL__ *adt_ListPopFront(struct adt_List *list)
 
2
; 11.2006 aralbrec
 
3
 
 
4
XLIB adt_ListPopFront
 
5
 
 
6
LIB l_setmem
 
7
XREF _u_free
 
8
 
 
9
.adt_ListPopFront
 
10
 
 
11
; enter: hl = struct adt_List *
 
12
; exit : no carry indicates list empty, hl = 0 else:
 
13
;        hl = item removed from list
 
14
;        last item removed from list and current points to new last item
 
15
; uses : af, bc, de, hl
 
16
 
 
17
   ld e,(hl)
 
18
   inc hl
 
19
   ld d,(hl)          ; de = count
 
20
   dec hl             ; hl = list
 
21
   ld a,d
 
22
   or e
 
23
   jr z, fail         ; fail if list empty
 
24
   dec de             ; count = count - 1
 
25
   ld a,d
 
26
   or e
 
27
   jp nz, morethanone
 
28
 
 
29
   ; getting rid of only item in list
 
30
 
 
31
   push hl            ; save list
 
32
   ld de,5
 
33
   add hl,de          ; hl = head
 
34
   ld d,(hl)
 
35
   inc hl
 
36
   ld e,(hl)          ; de = NODE
 
37
   ex de,hl           ; hl = NODE
 
38
   ld e,(hl)
 
39
   inc hl
 
40
   ld d,(hl)          ; de = item
 
41
   push de            ; save item
 
42
   dec hl
 
43
   push hl
 
44
   call _u_free       ; free NODE
 
45
   pop hl
 
46
   pop hl
 
47
   ex (sp),hl          ; hl = list, stack = item
 
48
   xor a
 
49
   call l_setmem-17
 
50
   pop hl             ; hl = item
 
51
   scf
 
52
   ret
 
53
 
 
54
   ; more than one item in list
 
55
 
 
56
.morethanone          ; hl = list, de = new count
 
57
 
 
58
   ld (hl),e
 
59
   inc hl
 
60
   ld (hl),d          ; count--
 
61
   inc hl
 
62
   ld (hl),1          ; state = INLIST
 
63
   inc hl
 
64
   inc hl
 
65
   inc hl             ; hl = head
 
66
   ld d,(hl)
 
67
   inc hl             ; hl = head+1
 
68
   ld e,(hl)          ; de = head NODE
 
69
   ex de,hl           ; hl = head NODE, de = head+1
 
70
   ld c,(hl)
 
71
   inc hl
 
72
   ld b,(hl)          ; bc = item
 
73
   push bc            ; save item
 
74
   inc hl
 
75
   ld b,(hl)
 
76
   inc hl
 
77
   ld c,(hl)          ; bc = next NODE
 
78
   ex de,hl           ; hl = head+1, de = head NODE.next+1
 
79
   ld (hl),c
 
80
   dec hl
 
81
   ld (hl),b          ; new head ptr = next NODE
 
82
   dec hl
 
83
   ld (hl),c
 
84
   dec hl
 
85
   ld (hl),b          ; new curr ptr = next NODE
 
86
   ld hl,4
 
87
   add hl,bc          ; hl = next NODE.prev
 
88
   ld (hl),0
 
89
   inc hl
 
90
   ld (hl),0          ; next NODE.prev = 0
 
91
   ld hl,-3
 
92
   add hl,de          ; hl = NODE to delete
 
93
   push hl
 
94
   call _u_free       ; free the NODE
 
95
   pop hl
 
96
   pop hl             ; hl = front item
 
97
   scf
 
98
   ret
 
99
 
 
100
.fail
 
101
 
 
102
   ex de,hl
 
103
   ret