SHOW:
|
|
- or go back to the newest paste.
1 | - | p_HorizLine: |
1 | + | p_HLine: |
2 | - | .db __HorizLineEnd-$-1 |
2 | + | .db __HLineEnd-$-1 |
3 | ld de,plotSScreen | |
4 | x_HLineEntry: | |
5 | - | x_HorizLineEntry: |
5 | + | |
6 | - | ;; de=buff, hl=x2, (sp)=ret, (sp+2)=x1, (sp+4)=y |
6 | + | ;; de=buff, l=x2, (sp)=ret, (sp+2)=x1, (sp+4)=y |
7 | - | pop af |
7 | + | ;; Rearrange stuff |
8 | ld a,l | |
9 | - | ld h,c |
9 | + | pop hl |
10 | pop bc | |
11 | - | push af |
11 | + | ex (sp),hl |
12 | ||
13 | - | ;; c=y, de=buff, h=x1, l=x2 |
13 | + | ;; a=x2, c=x1, de=buff, l=y |
14 | - | ;; Check if x1 is offscreen left; if so, note and fix it |
14 | + | ;; Check if x2 is offscreen left; if so, note and fix it |
15 | - | ld b,0 |
15 | + | ld h,0 |
16 | - | ld a,h |
16 | + | |
17 | rla | |
18 | jr nc,$+3 | |
19 | - | ld h,b |
19 | + | ld b,h |
20 | ||
21 | - | ;; carry=x1 offscreen, b=0, c=y, de=buff, h=left-fixed x1, l=x2 |
21 | + | ;; carry=x2 offscreen, b=left-fixed x2, c=x1, de=buff, h=0, l=y |
22 | - | ;; Check if x2 is offscreen left; if so, abort if x1 was too, then fix it |
22 | + | ;; Check if x1 is offscreen left; if so, abort if x2 was too, then fix it |
23 | - | bit 7,l |
23 | + | bit 7,c |
24 | jr z,$+4 | |
25 | ret c | |
26 | - | ld l,b |
26 | + | ld c,h |
27 | ||
28 | - | ;; b=0, c=y, de=buff, h=left-fixed x1, l=left-fixed x2 |
28 | + | ;; b=left-fixed x2, c=left-fixed x1, de=buff, h=0, l=y |
29 | - | ;; Check if x1 is offscreen right, and if so, abort if x2 is too, then fix it |
29 | + | ;; Check if x1 is offscreen right; if so, abort if x2 is too, then fix it |
30 | ld a,95 | |
31 | - | cp h |
31 | + | cp c |
32 | jr nc,$+5 | |
33 | - | cp l |
33 | + | cp b |
34 | - | ret nc |
34 | + | |
35 | - | ld h,a |
35 | + | |
36 | ||
37 | - | ;; a=95, b=0, c=y, de=buff, h=fixed x1, l=left-fixed x2 |
37 | + | ;; a=95, b=left-fixed x2, c=fixed x1, de=buff, h=0, l=y |
38 | - | ;; Check if x2 is offscreen right, and if so, fix it |
38 | + | ;; Check if x2 is offscreen right; if so, fix it |
39 | - | cp l |
39 | + | cp b |
40 | jr nc,$+3 | |
41 | - | ld l,a |
41 | + | |
42 | ||
43 | ;; X Clipping complete; x1 and x2 guaranteed to be onscreen | |
44 | - | ;; a=95, b=0, c=y, de=buff, h=x1, l=x2 |
44 | + | ;; a=95, b=x2, c=x1, de=buff, h=0, l=y |
45 | - | ;; Ensure that x1<=x2 |
45 | + | ;; Locate the lesser and greater (will refer to them as x1 and x2) of x1 and x2 |
46 | - | ld a,h |
46 | + | ld a,b |
47 | - | cp l |
47 | + | cp c |
48 | jr c,$+5 | |
49 | ld c,b | |
50 | - | ld l,h |
50 | + | |
51 | - | ld h,a |
51 | + | ld a,c |
52 | ||
53 | - | x_HorizLineEntry2: |
53 | + | ;; a=x1, b=x1, c=x2, de=buff, h=0, l=y |
54 | - | ;; a=x1, b=0, c=y, de=buff, h=x1, l=x2 |
54 | + | ;; Abort if y is offscreen while calculating y*4 |
55 | - | ;; Abort if y is offscreen, add y*12 to buffer, and add x1/8 to buffer |
55 | + | add hl,hl |
56 | - | ;; y is rotated left while x1 is rotated right so rra can be used for x1 |
56 | + | add hl,hl |
57 | - | sla c |
57 | + | dec h |
58 | ret m | |
59 | inc h | |
60 | - | sla c |
60 | + | |
61 | ;; a=x1, b=x1, c=x2, de=buff, h=0, l=y*4 | |
62 | ;; Calculate x1/8 and add it and y*12 to the buffer pointer | |
63 | ex de,hl | |
64 | - | add hl,bc |
64 | + | add hl,de |
65 | rra | |
66 | - | add hl,bc |
66 | + | add hl,de |
67 | - | add hl,bc |
67 | + | |
68 | add hl,de | |
69 | - | add hl,bc |
69 | + | |
70 | ld e,a | |
71 | - | ;; y no longer needed |
71 | + | add hl,de |
72 | - | ;; a=x1/8, b=0, c=x1/8, d=x1, e=x2, hl=y*12+(x/8)+buff |
72 | + | |
73 | - | ld c,7 |
73 | + | ;; Begin drawing! y no longer needed |
74 | - | ld a,d |
74 | + | ;; a=x1/8, b=x1, c=x2, d=0, e=x1/8, hl=y*12+(x1/8)+buff |
75 | - | and c |
75 | + | ;; Calculate the mask for the first byte |
76 | - | jr z,__HorizLineLeft8 |
76 | + | ld e,b |
77 | ld a,b | |
78 | - | ld a,1 |
78 | + | and %00000111 |
79 | - | __HorizLineLeftLoop: |
79 | + | jr z,__HLineLeft8 |
80 | ld b,a | |
81 | - | djnz __HorizLineFirstLoop |
81 | + | ld a,$01 |
82 | - | __HorizLineLeft8: |
82 | + | __HLineLeftLoop: |
83 | rrca | |
84 | djnz __HLineFirstLoop | |
85 | __HLineLeft8: | |
86 | - | ld a,d |
86 | + | |
87 | - | or c |
87 | + | |
88 | - | inc c |
88 | + | ;; a=first mask, b=0, c=x2, d=0, e=x1, hl=y*12+(x1/8)+buff |
89 | - | sub e |
89 | + | ;; Prepare the first byte and calculate the negative remaining width after the |
90 | - | jr c,__HorizLineRight ;??? |
90 | + | ;; first byte; if positive, jump to the masking code for the last byte |
91 | - | __HorizLineMidLoop: |
91 | + | |
92 | - | ld (hl),b |
92 | + | ld d,a |
93 | ld a,e | |
94 | - | ld b,$FF |
94 | + | or %00000111 |
95 | sub c | |
96 | - | jr nc,__HorizLineMidLoop |
96 | + | jr nc,__HLineRight |
97 | - | __HorizLineRight: |
97 | + | |
98 | - | add a,c ;??? |
98 | + | ;; a=-width remaining, b=0, c=x2, d=byte, e=x1, hl=y*12+(x1/8)+buff |
99 | - | ret z ;??? |
99 | + | ;; Draw bytes until there is no width remaining |
100 | __HLineMidLoop: | |
101 | - | ld a,1 |
101 | + | ld (hl),d |
102 | - | __HorizLineRightLoop: |
102 | + | |
103 | ld d,$FF | |
104 | - | djnz __HorizLineRightLoop |
104 | + | add a,8 |
105 | jr nc,__HLineMidLoop | |
106 | - | and b |
106 | + | |
107 | ;; a=width remaining-1%8+1, b=0, c=x2, d=byte, e=x1, hl=y*12+(x2/8)+buff | |
108 | ;; Calculate the mask for the last byte | |
109 | __HLineRight: | |
110 | - | __HorizLineEnd: |
110 | + | |
111 | inc b | |
112 | ld a,$80 | |
113 | __HLineRightLoop: | |
114 | rlca | |
115 | djnz __HLineRightLoop | |
116 | dec a | |
117 | cpl | |
118 | ||
119 | ;; a=mask, b=0, c=x2, d=byte, e=x1, hl=y*12+(x2/8)+buff | |
120 | ;; Draw the last byte | |
121 | and d | |
122 | or (hl) | |
123 | ld (hl),a | |
124 | ||
125 | ret | |
126 | __HLineEnd: |