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
|
;; Load an assembly program at BOFA and handle relocations
;; Relocations are a list of 16-bit addresses at the end of
;; the image, processed in reverse order, terminated with
;; an FFFFh sentinel.
org 0 ; This code must be position-independent
BOFA: equ 65052
offset: equ 0xeeee ; Length of the BASIC prefix
ENTRY: equ 0xbbbb
ld hl,(BOFA)
push hl
ld e,l
ld d,h
ld bc,offset ; Offset < 256 so B = 0
add hl,bc
; Get data block length
loop:
ld a,-8
add (hl)
jr nc,reloc ; END is a shorter line than any data line
; Skip length byte + line number (2 bytes) + string opcode (3 bytes)
ld c,6
add hl,bc
; Copy remaining data
ld c,a
ldir
; Skip return + CR
inc hl
inc hl
jr loop
;; Process relocations. At this point DE points beyond
;; the end of the contiguous image.
reloc:
pop bc ; BC <- BOFA
reloc_loop:
ex de,hl
dec hl
ld d,(hl)
dec hl
ld e,(hl)
ld a,e
and d
inc a ; A = FFh only if BC = FFFFh
jr z,reloc_done
ex de,hl
add hl,bc
ld a,(hl)
add c
ld (hl),a
inc hl
ld a,(hl)
adc a,b
ld (hl),a
jr reloc_loop
reloc_done:
ld hl,ENTRY
add hl,bc
jp (hl)
|