forked from jblang/bbcbasic-z80
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbcbasic.asm
104 lines (79 loc) · 1.15 KB
/
bbcbasic.asm
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
STKSIZ EQU $40 ; WORKING STACK SIZE
RESTART EQU $0000 ; CP/M RESTART VECTOR
;BDOS EQU $0005 ; BDOS INVOCATION VECTOR
ORG $100
LD SP, STACK ; SET NEW STACK
LD HL, (6) ;DE = HIMEM
DEC HL
LD L, 0 ; 256 BOUNDARY
DEC HL
PUSH HL
POP IX
LD DE, HL
LD HL, APP + APPSIZE - 1
LD BC, APPSIZE
LDDR
INC DE
PUSH DE ; CAPTURE START POINT IN IX
POP IX
EX DE, HL
LD DE, $100
OR A
SBC HL, DE
PUSH HL
POP IY ; OFFSET VALUE (IX - 100)
PUSH IX
POP DE ; START OF CODE
LD HL, RELOC
LD BC, RELOCSIZE / 2
LOOP:
CALL TRANSPOSE
INC HL
INC HL
DEC BC
LD A, B
OR C
JR NZ, LOOP
PUSH IX
POP HL
JP (IX)
TRANSPOSE:
PUSH HL
PUSH BC
PUSH DE
LD E, (HL)
INC HL
LD D, (HL)
EX DE, HL
PUSH IX
POP DE
ADD HL, DE
LD C, (HL)
INC HL
LD B, (HL)
PUSH IY
POP DE
PUSH HL
LD HL, DE
ADD HL, BC
LD D, H
LD E, L
POP HL
LD (HL), D
DEC HL
LD (HL), E
POP DE
POP BC
POP HL
RET
RELOC:
BINARY "_bbcbasic.reloc"
RELOCSIZE: EQU ASMPC - RELOC
STKSAV: DEFW 0 ; STACK POINTER SAVED AT START
DEFS STKSIZ ; STACK
STACK: EQU ASMPC ; STACK TOP
DEFS 8
APP:
BINARY "_bbcbasic.com"
DEFS 256 - ((ASMPC - APP) % 256)
APPSIZE: EQU ASMPC - APP