View difference between Paste ID: z4VW4YpK and mABrzWVQ
SHOW: | | - or go back to the newest paste.
1
p_VLine:
2
	.db __VLineEnd-$-1
3
	ld	de,plotSScreen
4
x_VLineEntry:
5
6
;; de=buff, l=y2, (sp)=ret, (sp+2)=y1, (sp+4)=x
7
;; Rearrange stuff
8
	ld	a,l
9
	pop	hl
10
	pop	bc
11
	ex	(sp),hl
12
13
;; a=y2, c=y1, de=buff, l=x
14-
;; Check if y1 is offscreen top; if so, note and fix it
14+
;; Check if y1 is offscreen top while calculating y1*2; if so, note and fix it
15
	ld	h,0
16
	sla	c
17
	jr	nc,$+3
18
	ld	c,h
19
20-
;; carry=y1 offscreen, a=y2, c=top-fixed y1, de=buff, h=0, l=x
20+
;; carry=y1 offscreen, a=y2, c=top-fixed y1*2, de=buff, h=0, l=x
21-
;; Check if y2 is offscreen top; if so, abort if y1 was too, then fix it
21+
;; Check if y2 is offscreen top while calculating y2*2; if so, abort if y1 was 
22
;;   too, then fix it
23
	rla
24
	jr	nc,$+5
25
	rra
26
	ret	c
27
	ld	a,h
28-
;; a=top-fixed y2, c=top-fixed y1, de=buff, h=0, l=x
28+
29
;; a=top-fixed y2*2, c=top-fixed y1*2, de=buff, h=0, l=x
30
;; Check that y2>=y1; if not, swap y1 and y2
31
	cp	c
32
	jr	nc,$+5
33
	ld	b,c
34
	ld	c,a
35
	ld	a,b
36
37-
;; a=top-fixed y2, c=top-fixed y1, de=buff, h=0, l=x
37+
38-
;; Check if y1 is offscreen bottom; if so, abort
38+
;; a=top-fixed y2*2, c=top-fixed y1*2, de=buff, h=0, l=x
39
;; Check if y1 is offscreen bottom while calculating y1*4; if so, abort
40
	sla	c
41
	ret	c
42
43-
;; a=top-fixed y2, c=fixed y1, de=buff, h=0, l=x
43+
;; a=top-fixed y2*2, c=fixed y1*4, de=buff, h=0, l=x
44-
;; Check if y2 is offscreen bottom; if so, fix it
44+
;; Check if y2 is offscreen bottom while calculating y2*4; if so, fix it
45
	add	a,a
46
	jr	nc,$+4
47
	ld	a,63
48
49
;; Y Clipping complete; y1 and y2 guaranteed to be onscreen
50-
;; a=y2, c=y1, de=buff, h=0, l=x
50+
;; a=y2*4, c=y1*4, de=buff, h=0, l=x
51
;; Calculate the height of the line
52
	sub	c
53
	rra
54
	rra
55
	inc	a
56
	ld	b,a
57
58
;; y2 no longer needed
59-
;; a=height, b=height, c=y1, de=buff, h=0, l=x
59+
;; a=height, b=height, c=y1*4, de=buff, h=0, l=x
60
;; Calculate x1/8 and add it and y*12 to the buffer pointer
61
	ex	de,hl
62
	ld	a,e
63
	ld	e,c
64
	ld	c,a
65
	add	hl,de
66
	rra
67
	add	hl,de
68
	rra
69
	add	hl,de
70
	rra
71
	ld	e,a
72
	add	hl,de
73
74
75
;; y1 no longer needed
76
;; a=x/8, b=height, c=x, d=0, e=x/8, hl=y1*12+(x/8)+buff
77
;; Check if x is offscreen; if so, abort
78
	ld	e,12
79
	cp	e
80
	ret	nc
81
82
;; Begin drawing!
83
;; a=x/8, b=height, c=x, de=12, hl=y1*12+(x/8)+buff
84
;; Calculate the mask
85
	ld	a,c
86
	or	%11111000
87
	ld	c,d
88
	scf
89
__VLineMaskLoop:
90
	rl	c
91
	inc	a
92
	jr	nz,__VLineMaskLoop
93
94
95
;; a=0, b=height, c=mask, de=12, hl=y1*12+(x/8)+buff
96
;; Draw the line
97
__VLineLoop:
98
	ld	a,(hl)
99
	or	c
100
	ld	(hl),a
101
	add	hl,de
102
	djnz	__VLineLoop
103
104
	ret
105
__VLineEnd: