-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_fix.asm
More file actions
84 lines (71 loc) · 2.23 KB
/
list_fix.asm
File metadata and controls
84 lines (71 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
; LIST_FIX.ASM - Single-linked list implementation for elements of the same
; size
; The list structure requires 16 bytes in memory, plus 4+elem_size bytes
; per element.
;
; The struct has these fields:
;
; Name Size Description
; ==== ==== ===========
; length 2 bytes Number of elements in the list
; elem_size 2 bytes Size of the elements in the list
; ptr_first 4 bytes Mapped pointer to the first element
; ptr_last 4 bytes Mapped pointer to the last element
; ptr_next 4 bytes Mapped pointer to the next element
; Include mapper support
include mapper.inc
STRUCT_SIZE equ 16 ; List struct size
; Public routines
public flist_alloc ; Allocate and initialize a list structure
public flist_first ; Get pointer to first element
public flist_next ; Get pointer to next element and move next
; pointer
public flist_last ; Get pointer to last element
public flist_rewind ; Rewind the list
public flist_length ; Return the number of elements
public flist_add ; Add an element
public flist_delete ; Delete an element
public flist_get ; Get an element
public flist_swap ; Swap two elements
public flist_insert ; Insert an element
public flist_replace ; Replace an element
.z80
cseg
; flist_alloc - Allocate and initialize a list structure.
; Input: HL Pointer to a mapped pointer to a 16-byte area for the
; list struct
; BC Size of the list elements, in bytes
; Output: DE Pointer to an mpointer to the list structure
; Modifies: AB, HL, BC, DE
;
flist_init: ; Map the mapped pointer's segment into RAM and load the
; patched pointer in HL
;call map_mptr_p2
; XXX TO BE IMPLEMENTED
ret
; Input: HL Pointer to a 16-byte area for the list struct
; BC Size of single list elements, in bytes
; Output: List struct zeroed, and elem_size field set
; Modifies: AF, HL, BC, DE
;
;flist_init: ; Zero the area holding the list struct
; push hl
; push bc
; xor a
; ld (hl),a
; ld d,h
; ld e,l
; inc de
; ld bc,STRUCT_SIZE-1
; ldir
; pop bc
; pop hl
; ; Set the element size
; ld (hl),c
; inc hl
; ld (hl),b
; ret
; flist_first - Return pointer to the first element in the list
; Input: HL Mapped pointer to the list structure
; Output: DE