-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.asm
135 lines (131 loc) · 1.99 KB
/
math.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
;#############################################################################################
;# SHAPES AND DRAWING
;b = height
;c = width
;d = starting x
;e = starting y
drawBox:
dec b
dec b
dec b
dec b
ld a,(yOff)
add a,e
ld e,a
ld a,(xOff)
add a,d
ld d,a
and $7
ex af,af'
ld a,d
ld l,e
ld h,0
ld d,h
add hl,hl
add hl,de
add hl,hl
add hl,de
add hl,hl ;y*14
rra
rra
rra
and %00011111
ld e,a
add hl,de ;+x
ld de,gbuf
add hl,de ;position in gbuf
ex af,af'
ld de,%1111111011111111
ld (scratchSpace),de
ld e,%01111111
call drawLine
ld de,%1111111111111111
ld (scratchSpace),de
call drawLine
middleLoop:
ld de,%0000000100000000
ld (scratchSpace),de
ld e,%10000000
call drawLine
djnz middleLoop
ld de,%1111111111111111
ld (scratchSpace),de
call drawLine
ld de,%1111111011111111
ld (scratchSpace),de
ld e,%01111111
drawLine:
push bc
push af
ld b,a
or a
ld a,$FF
jr z,$+9 ;check if aligned
inc c
srl a
srl e
djnz $-5
cpl
and (hl)
or e
ld (hl),a ;store in gbuf
inc hl
ld a,(scratchSpace)
ld e,a ;e = the pattern to draw in the middle of the line
ld a,c ;width+xOff
sub 16 ;-16 for the first two bytes in the line
jr c,exitLine
lineLoop:
ld (hl),e ;draw 8 pixels at a time until we've got
inc hl ; fewer than 8 pixels to draw
sub 8
jr nc,lineLoop
exitLine:
neg
cp 8
ld b,a
ld a,(scratchSpace+1)
jr nz,unAlined
dec hl
ld (hl),a
inc hl
jr nextRow
unAlined: ;)
ld e,a
ld a,$FF
sla a
sla e
djnz $-4
cpl
and (hl) ;a holds the mask
or e
ld (hl),a
nextRow:
ld a,c
rra
rra
rra
and %00011111
ld e,a
ld a,14
sub e
ld e,a
ld d,0
add hl,de ;+x
pop af
pop bc
ret
;#############################################################################################
;# MATH
;multiplica E*H y guarda el resultado en HL
multEH:
ld l,0
ld d,l
ld b,8
multLoop: ;hl=e*h
add hl,hl
jr nc,noAdd
add hl,de
noAdd:
djnz multLoop
ret