View difference between Paste ID: mABrzWVQ and nPQVru36
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
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
21
;; Check if y2 is offscreen top; if so, abort if y1 was too, then fix it
22
	rla
23
	jr	nc,$+5
24
	rra
25
	ret	c
26
	ld	a,h
27
28
;; a=top-fixed y2, c=top-fixed y1, de=buff, h=0, l=x
29
;; Check that y2>=y1; if not, swap y1 and y2
30
	cp	c
31
	jr	nc,$+5
32
	ld	b,c
33
	ld	c,a
34
	ld	a,b
35
36
;; y1 is now guaranteed to be <=y2
37
;; a=top-fixed y2, c=top-fixed y1, de=buff, h=0, l=x
38
;; Check if y1 is offscreen bottom; if so, abort
39
	sla	c
40
	ret	c
41
	ld	c,a
42
43
;; a=top-fixed y2, c=fixed y1, de=buff, h=0, l=x
44
;; Check if y2 is offscreen bottom; if so, fix it
45
	rla
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
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
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
;; a=x/8, b=height, c=x, d=0, e=x/8, hl=y1*12+(x/8)+buff
76
;; Check if x is offscreen; if so, abort
77
	ld	e,12
78
	cp	e
79
	ret	nc
80
81
;; Begin drawing!
82
;; a=x/8, b=height, c=x, de=12, hl=y1*12+(x/8)+buff
83
;; Calculate the mask
84
	ld	a,c
85
	or	%11111000
86
	ld	c,d
87
	scf
88
__VLineMaskLoop:
89
	rl	c
90
	inc	a
91
	jr	nz,__VLineMaskLoop
92
93
94
;; a=0, b=height, c=mask, de=12, hl=y1*12+(x/8)+buff
95
;; Draw the line
96
__VLineLoop:
97
	ld	a,(hl)
98
	or	c
99
	ld	(hl),a
100
	add	hl,de
101
	djnz	__VLineLoop
102
103
	ret
104
__VLineEnd: