View difference between Paste ID: 52NwefB9 and D2ArBCLp
SHOW: | | - or go back to the newest paste.
1
p_HorizLine:
2
	.db __HorizLineEnd-$-1
3
	ld	de,plotSScreen
4
5
x_HorizLineEntry:
6
;; de=buff, hl=x2, (sp)=ret, (sp+2)=x1, (sp+4)=y
7
	pop	af
8
	pop	bc
9
	ld	h,c
10
	pop	bc
11
	push	af
12
13
;; c=y, de=buff, h=x1, l=x2
14
;; Check if x1 is offscreen left; if so, note and fix it
15-
	xor	a
15+
	ld	b,0
16
	ld	a,h
17-
	bit	7,h
17+
	rla
18
	jr	nc,$+3
19-
	scf
19+
20
21
;; carry=x1 offscreen, b=0, c=y, de=buff, h=left-fixed x1, l=x2
22-
;; carry=x1 offscreen, a=0, b=0, c=y, de=buff, h=left-fixed x1, l=x2
22+
23
	bit	7,l
24
	jr	z,$+4
25
	ret	c
26
	ld	l,b
27
28
;; b=0, c=y, de=buff, h=left-fixed x1, l=left-fixed x2
29-
;; a=0, b=0, c=y, de=buff, h=left-fixed x1, l=left-fixed x2
29+
30
	ld	a,95
31
	cp	h
32
	jr	nc,$+5
33
	cp	l
34
	ret	nc
35
	ld	h,a
36
37
;; a=95, b=0, c=y, de=buff, h=fixed x1, l=left-fixed x2
38
;; Check if x2 is offscreen right, and if so, fix it
39
	cp	l
40
	jr	nc,$+3
41
	ld	l,a
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
45
;; Ensure that x1<=x2
46
	ld	a,h
47
	cp	l
48
	jr	c,$+5
49
	ld	a,l
50
	ld	l,h
51
	ld	h,a
52
53
x_HorizLineEntry2:
54
;; a=x1, b=0, c=y, de=buff, h=x1, l=x2
55
;; Abort if y is offscreen, add y*12 to buffer, and add x1/8 to buffer
56
;;   y is rotated left while x1 is rotated right so rra can be used for x1
57
	sla	c
58
	ret	c
59
	rra
60
	sla	c
61
	ret	c
62
	rra
63
	ex	de,hl
64
	add	hl,bc
65
	rra
66
	add	hl,bc
67
	add	hl,bc
68
	ld	c,a
69
	add	hl,bc
70
71
;; y no longer needed
72
;; a=x1/8, b=0, c=x1/8, d=x1, e=x2, hl=y*12+(x/8)+buff
73
	ld	c,7
74
	ld	a,d
75
	and	c
76
	jr	z,__HorizLineLeft8
77
	ld	b,a
78
	ld	a,1
79
__HorizLineLeftLoop:
80
	rrca
81-
	dec	d
81+
82
__HorizLineLeft8:
83
	dec	a
84
	or	(hl)
85
	ld	b,a
86
	ld	a,d
87
	or	c
88
	inc	c
89-
	add	a,c
89+
90
	jr	c,__HorizLineRight	;???
91
__HorizLineMidLoop:
92-
	jr	c,__HorizLineRight
92+
93
	inc	hl
94
	ld	b,$FF
95-
	.db	$38			;jr c to skip the first write
95+
96
	jr	nc,__HorizLineMidLoop
97
__HorizLineRight:
98
	add	a,c	;???
99
	ret	z	;???
100
	ld	b,a
101
	ld	a,1
102-
	add	a,c
102+
103-
	ret	z
103+
104
	djnz	__HorizLineRightLoop
105
	dec	a
106
	and	b
107
	or	(hl)
108
	ld	(hl),a
109
	ret
110
__HorizLineEnd: