blob: 6388d6c8b1de4de90c55807e63a8a9b143f2595c [file] [log] [blame]
kthacker62e146c2006-04-17 15:11:35 +00001 .globl _relocate
2 .area _CODE
3
4;; IX = address of relocate data
5_relocate::
6 call relocate_16bit
7 call relocate_8bit ;; lower byte
8 ld c,b
9 call relocate_8bit ;; upper byte
10 ret
11
12;;--------------------------------------------------------------------------
13;; Relocate 8-bit values (e.g. where low and high parts of an address
14;; are loaded seperatly into registers)
15;;
16;; IX = list of 16-bit addresses. Each address identifies an 8-bit
17;; value
18;;
19relocate_8bit:
20 ld a,0(ix)
21 inc ix
22rel8bit: push af
23 ld e,0(ix)
24 inc ix
25 ld d,0(ix)
26inc ix
27
28ld a,(de)
29add c
30ld (de),a
31pop af
32dec a
33jr nz,rel8bit
34ret
35
36
37;;--------------------------------------------------------------------------
38;; Relocate 16-bit values
39;;
40;; Entry conditions:
41;;
42;; IX = list of 16-bit addresses. Each address identifies a 16-bit
43;; value to relocate.
44;;
45;; BC = base address
46;;
47;; NOTE:
48;; - Relocatable 16-bit values come from CALL and JP instructions and
49;; loading a 16-bit register.
50
51relocate_16bit:
52ld a,0(ix) ;; number of items to relocate
53inc ix
54
55rel16bit:
56push af
57;; get address of 16-bit value to relocate
58ld e,0(ix)
59inc ix
60ld d,0(ix)
61inc ix
62
63;; get the 16-bit value
64ld a,(de)
65ld l,a
66inc de
67ld a,(de)
68ld h,a
69
70;; add base address; therefore relocating it.
71add hl,bc
72
73;; write relocated value
74ld a,h
75ld (de),a
76dec de
77ld a,l
78ld (de),a
79pop af
80dec a
81jr nz,rel16bit
82ret
83
84;;--------------------------------------------------------------------------
85
86 .area _DATA
87 .area _BSS
88 .area _GSINIT
89 .area _GSFINAL
90
91_relocate_data::