kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 1 | .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 | ;; |
| 19 | relocate_8bit: |
| 20 | ld a,0(ix) |
| 21 | inc ix |
| 22 | rel8bit: push af |
| 23 | ld e,0(ix) |
| 24 | inc ix |
| 25 | ld d,0(ix) |
| 26 | inc ix |
| 27 | |
| 28 | ld a,(de) |
| 29 | add c |
| 30 | ld (de),a |
| 31 | pop af |
| 32 | dec a |
| 33 | jr nz,rel8bit |
| 34 | ret |
| 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 | |
| 51 | relocate_16bit: |
| 52 | ld a,0(ix) ;; number of items to relocate |
| 53 | inc ix |
| 54 | |
| 55 | rel16bit: |
| 56 | push af |
| 57 | ;; get address of 16-bit value to relocate |
| 58 | ld e,0(ix) |
| 59 | inc ix |
| 60 | ld d,0(ix) |
| 61 | inc ix |
| 62 | |
| 63 | ;; get the 16-bit value |
| 64 | ld a,(de) |
| 65 | ld l,a |
| 66 | inc de |
| 67 | ld a,(de) |
| 68 | ld h,a |
| 69 | |
| 70 | ;; add base address; therefore relocating it. |
| 71 | add hl,bc |
| 72 | |
| 73 | ;; write relocated value |
| 74 | ld a,h |
| 75 | ld (de),a |
| 76 | dec de |
| 77 | ld a,l |
| 78 | ld (de),a |
| 79 | pop af |
| 80 | dec a |
| 81 | jr nz,rel16bit |
| 82 | ret |
| 83 | |
| 84 | ;;-------------------------------------------------------------------------- |
| 85 | |
| 86 | .area _DATA |
| 87 | .area _BSS |
| 88 | .area _GSINIT |
| 89 | .area _GSFINAL |
| 90 | |
| 91 | _relocate_data:: |