OpenCores
URL https://opencores.org/ocsvn/light8080/light8080/trunk

Subversion Repositories light8080

[/] [light8080/] [trunk/] [tools/] [c80/] [c80.lib] - Blame information for rev 89

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 65 motilito
#asm
2
;
3
;------------------------------------------------------------------
4
;       Small-C  Run-time Librray
5
;
6
;       V4d     As of July 16, 1980 (gtf)
7
;                  Added EXIT() function
8
;------------------------------------------------------------------
9
;
10
;Fetch a single byte from the address in HL and sign extend into HL
11
ccgchar:
12
        ld a,(hl)
13
ccsxt:
14
        ld l,a
15
        rlca
16
        sbc     a
17
        ld      h,a
18
        ret
19
;Fetch a full 16-bit integer from the address in HL
20
ccgint:
21
        ld a,(hl)
22
        inc     hl
23
        ld      h,(hl)
24
        ld l,a
25
        ret
26
;Store a single byte from HL at the address in DE
27
ccpchar:
28
        ld      a,l
29
        ld      (de),a
30
        ret
31
;Store a 16-bit integer in HL at the address in DE
32
ccpint:
33
        ld      a,l
34
        ld      (de),a
35
        inc     de
36
        ld      a,h
37
        ld      (de),a
38
        ret
39
;Inclusive "or" HL and DE into HL
40
ccor:
41
        ld      a,l
42
        or      e
43
        ld l,a
44
        ld      a,h
45
        or      d
46
        ld      h,a
47
        ret
48
;Exclusive "or" HL and DE into HL
49
ccxor:
50
        ld      a,l
51
        xor     e
52
        ld l,a
53
        ld      a,h
54
        xor     d
55
        ld      h,a
56
        ret
57
;"And" HL and DE into HL
58
ccand:
59
        ld      a,l
60
        and     e
61
        ld l,a
62
        ld      a,h
63
        and     d
64
        ld      h,a
65
        ret
66
;Test if HL = DE and set HL = 1 if true else 0
67
cceq:
68
        call cccmp
69
        ret z
70
        dec     hl
71
        ret
72
;Test if DE ~= HL
73
ccne:
74
        call cccmp
75
        ret nz
76
        dec     hl
77
        ret
78
;Test if DE > HL (signed)
79
ccgt:
80
        ex de,hl
81
        call cccmp
82
        ret c
83
        dec     hl
84
        ret
85
;Test if DE <= HL (signed)
86
ccle:
87
        call cccmp
88
        ret z
89
        ret c
90
        dec hl
91
        ret
92
;Test if DE >= HL (signed)
93
ccge:
94
        call cccmp
95
        ret nc
96
        dec hl
97
        ret
98
;Test if DE < HL (signed)
99
cclt:
100
        call cccmp
101
        ret c
102
        dec hl
103
        ret
104
; Signed compare of DE and HL
105
; Performs DE - HL and sets the conditions:
106
;       Carry reflects sign of difference (set means DE < HL)
107
;       Zero/non-zero set according to equality.
108
cccmp:
109
        ld      a,e
110
        sub     l
111
        ld      e,a
112
        ld      a,d
113
        sbc     h
114
        ld      hl,1
115
        jp      m,cccmp1
116
        or      e       ;"OR" resets carry
117
        ret
118
cccmp1:
119
        or      e
120
        scf             ;set carry to signal minus
121
        ret
122
;Test if DE >= HL (unsigned)
123
ccuge:
124
        call ccucmp
125
        ret nc
126
        dec hl
127
        ret
128
;Test if DE < HL (unsigned)
129
ccult:
130
        call ccucmp
131
        ret c
132
        dec hl
133
        ret
134
;Test if DE > HL (unsigned)
135
ccugt:
136
        ex de,hl
137
        call ccucmp
138
        ret c
139
        dec hl
140
        ret
141
;Test if DE <= HL (unsigned)
142
ccule:
143
        call ccucmp
144
        ret z
145
        ret c
146
        dec hl
147
        ret
148
;Routine to perform unsigned compare
149
;carry set if DE < HL
150
;zero/nonzero set accordingly
151
ccucmp:
152
        ld      a,d
153
        cp      h
154
        jp      nz,$+5
155
        ld      a,e
156
        cp      l
157
        ld      hl,1
158
        ret
159
;Shift DE arithmetically right by HL and return in HL
160
ccasr:
161
        ex      de,hl
162
        ld      a,h
163
        rla
164
        ld      a,h
165
        rra
166
        ld      h,a
167
        ld      a,l
168
        rra
169
        ld      l,a
170
        dec     e
171
        jp      nz,ccasr+1
172
        ret
173
;Shift DE arithmetically left by HL and return in HL
174
ccasl:
175
        ex      de,hl
176
        add     hl,hl
177
        dec     e
178
        jp      nz,ccasl+1
179
        ret
180
;Subtract HL from DE and return in HL
181
ccsub:
182
        ld      a,e
183
        sub     l
184
        ld l,a
185
        ld      a,d
186
        sbc     h
187
        ld      h,a
188
        ret
189
;Form the two's complement of HL
190
ccneg:
191
        call cccom
192
        inc     hl
193
        ret
194
;Form the one's complement of HL
195
cccom:
196
        ld      a,h
197
        cpl
198
        ld      h,a
199
        ld      a,l
200
        cpl
201
        ld l,a
202
        ret
203
;Multiply DE by HL and return in HL
204
ccmult:
205
        ld      b,h
206
        ld      c,l
207
        ld      hl,0
208
ccmult1:
209
        ld      a,c
210
        rrca
211
        jp      nc,$+4
212
        add     hl,de
213
        xor     a
214
        ld      a,b
215
        rra
216
        ld      b,a
217
        ld      a,c
218
        rra
219
        ld      c,a
220
        or      b
221
        ret z
222
        xor     a
223
        ld      a,e
224
        rla
225
        ld      e,a
226
        ld      a,d
227
        rla
228
        ld      d,a
229
        or      e
230
        ret z
231
        jp      ccmult1
232
;Divide DE by HL and return quotient in HL, remainder in DE
233
ccdiv:
234
        ld      b,h
235
        ld      c,l
236
        ld      a,d
237
        xor     b
238
        push af
239
        ld      a,d
240
        or      a
241
        call m,ccdeneg
242
        ld      a,b
243
        or      a
244
        call m,ccbcneg
245
        ld      a,16
246
        push af
247
        ex      de,hl
248
        ld      de,0
249
ccdiv1:
250
        add hl,hl
251
        call ccrdel
252
        jp      z,ccdiv2
253
        call cccmpbcde
254
        jp      m,ccdiv2
255
        ld      a,l
256
        or      1
257
        ld l,a
258
        ld      a,e
259
        sub     c
260
        ld      e,a
261
        ld      a,d
262
        sbc     b
263
        ld      d,a
264
ccdiv2:
265
        pop af
266
        dec     a
267
        jp      z,ccdiv3
268
        push af
269
        jp      ccdiv1
270
ccdiv3:
271
        pop af
272
        ret     p
273
        call ccdeneg
274
        ex de,hl
275
        call ccdeneg
276
        ex de,hl
277
        ret
278
ccdeneg:
279
        ld      a,d
280
        cpl
281
        ld      d,a
282
        ld      a,e
283
        cpl
284
        ld      e,a
285
        inc     de
286
        ret
287
ccbcneg:
288
        ld      a,b
289
        cpl
290
        ld      b,a
291
        ld      a,c
292
        cpl
293
        ld      c,a
294
        inc     bc
295
        ret
296
ccrdel:
297
        ld      a,e
298
        rla
299
        ld      e,a
300
        ld      a,d
301
        rla
302
        ld      d,a
303
        or      e
304
        ret
305
cccmpbcde:
306
        ld      a,e
307
        sub     c
308
        ld      a,d
309
        sbc     b
310
        ret
311
#endasm

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.