-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbcdlib.asc
57 lines (54 loc) · 1.48 KB
/
bcdlib.asc
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
; MSX Block Puzzle game, released as entry for the MSXDev'20
; Created by David Heremans, aka turbor on mrc
;
;
; simple BCD encoded number lib
; A simple BCD encode number is a decimal number stored one digit per byte
; order is based on simple out instructions to vram so most significante byte first followed by decreasing significance
; on both sides a 255 byte marker needs to be placed.
; for instance 19235 is to be stored as db 255,1,9,2,3,5,255
; or if more leading zero's are needed db 255,0,0,0,0,1,9,2,3,5,255
bcdcmpdehl:
; in: HL and DE point to the BCD encoded number (the address just behind the ending 255)
; important: make sure that both numbers have an equal amount of digits
; out: Z-flag indicates if numbers are equal, if not equal then C flag if HL>DE
; changes: DE,HL, AF {{{
ld a,(de)
cp (hl)
ret nz
inc de
inc hl
ld a,(hl)
cp 255
ret z
jp bcdcmpdehl
;}}}
bcdadddehl:
; in HL and DE point to the unit of simple BCD encoded number (the highest address just below the ending 255)
; important: make sure that both numbers have an equal amount of digits
; out: Z-flag indicates if numbers are equal
; changes: DE,HL, AF {{{
ld c,0
bcdadddehl1:
ld a,(de)
add a,c
add a,(hl)
cp 10
jr nc,bcdadddehl3
ld (hl),a
xor a
ld c,a
jr bcdadddehl5
bcdadddehl3:
sub 10
ld (hl),a
ld c,1
bcdadddehl5:
dec de
dec hl
ld a,(hl)
cp 255
ret z
jp bcdadddehl1
;}}}
; vim:foldmethod=marker:ft=z8a:ts=16