1;
2; Extremely putc implementation for low resolution graphics
3; and small memory sizes
4;
5; Sept 2018 - Stefano
6;
7; Much More Generic version
8; Uses clg, plot and unplot
9;
10;
11; $Id: putc4x6.asm $
12;
13
14	INCLUDE	"graphics/grafix.inc"
15
16		SECTION         code_graphics
17
18
19	PUBLIC    putc4x6
20	PUBLIC    _putc4x6
21
22	EXTERN     swapgfxbk
23        EXTERN	__graphics_end
24
25	EXTERN	plot
26	EXTERN	unplot
27	EXTERN	clg
28
29
30.putc4x6
31._putc4x6
32        ld      hl,2
33        add     hl,sp
34
35		ld		a,(hl)
36
37		cp		12		; cls ?
38		jr		nz,nocls
39		ld		hl,0
40		ld		(x_4x6),hl
41		ld		(y_4x6),hl
42		jp		clg
43.nocls
44
45		cp	10
46		jp	z,do_nl
47		cp	13
48		jp	z,do_nl
49
50		cp  8
51		jr	nz,nobs
52		ld	a,(x_4x6)
53		sub 4
54		jr c,nobs1
55		ld	(x_4x6),a
56.nobs1
57		ld	a,' '
58		call nolower
59		ld	a,(x_4x6)
60		sub 4
61		ld	(x_4x6),a
62		ret
63
64.nobs
65		cp	97
66		jr	c,nolower
67		sub 32	; uppercase only
68.nolower
69		sub 32
70
71		ld	(chr),a
72
73IF !__CPU_INTEL__ & !__CPU_GBZ80__
74		push	ix
75ENDIF
76		call swapgfxbk
77
78		ld	a,(chr)
79		rra
80
81		ld e,a
82		add a
83		add a
84		add e	; a=a*5 !
85
86		ld	d,0
87		ld	e,a
88		ld	hl,font4x5
89		add hl,de
90
91		ld	b,5
92.rowloop
93		push bc
94		push hl
95		ld	a,(chr)
96		rra ; even odd ?
97		ld	a,(hl)
98		jr	nc,iseven
99		rla
100		rla
101		rla
102		rla
103.iseven
104		ld b,4
105		ld c,a
106
107		ld	a,(x_4x6)
108		ld	d,0
109		ld	e,a
110.colloop
111IF __CPU_INTEL__
112		ld	a,c
113		rla
114		ld	c,a
115ELSE
116		rl c		; cy = pixel status
117ENDIF
118		push bc
119		push de
120		ld	a,(y_4x6)
121		ld	e,a
122		push de
123
124		jr	nc,noplot
125		call	plot
126		jr	nores
127.noplot
128		call	unplot
129.nores
130		pop de
131		pop de
132		inc e
133
134		pop bc
135		djnz	colloop
136
137		ld	hl,y_4x6
138		inc (hl)
139
140		pop hl
141		inc hl
142		pop bc
143		djnz rowloop
144
145		ld b,4
146		ld	a,(x_4x6)
147		ld	d,0
148		ld	e,a
149.lrloop
150		push bc
151		push de
152		ld  a,(y_4x6)
153		ld	e,a
154		push de
155		call	unplot
156		pop de
157		pop de
158		inc e
159		pop bc
160		djnz	lrloop
161		ld	a,e				; new x position
162
163		IF maxx <> 256
164		cp  maxx
165		call  nc,do_nl
166		ELSE
167		and a
168		call  z,do_nl
169		ENDIF
170
171		ld	(x_4x6),a		; update x position
172
173		ld  a,(y_4x6)
174		sub 5
175		ld  (y_4x6),a
176
177		jp       __graphics_end
178
179.do_nl
180		ld  a,(y_4x6)
181		add 6
182		ld  (y_4x6),a
183		xor a
184		ld	(x_4x6),a		; update x position
185		ret
186
187
188		SECTION		bss_graphics
189
190	PUBLIC    x_4x6
191	PUBLIC    _x_4x6
192	PUBLIC    y_4x6
193	PUBLIC    _y_4x6
194
195.x_4x6
196._x_4x6
197 defw 0
198
199.y_4x6
200._y_4x6
201 defw 0
202
203.chr
204 defb 0
205
206
207
208        SECTION rodata_clib
209
210; 4x5 font (it will be 4x6 because the driver adds a bottom blank row)
211.font4x5
212defb	0x04 , 0x04 , 0x04 , 0x00 , 0x04
213defb	0xAA , 0xAE , 0x0A , 0x0E , 0x0A
214defb	0x48 , 0xC2 , 0xE4 , 0x68 , 0x42
215defb	0xC4 , 0xC8 , 0x60 , 0xC0 , 0xE0
216defb	0x28 , 0x44 , 0x44 , 0x44 , 0x28
217defb	0xA0 , 0x44 , 0xEE , 0x4e , 0xA0
218defb	0x00 , 0x00 , 0x0E , 0x40 , 0x80
219defb	0x00 , 0x02 , 0x04 , 0x08 , 0x40
220defb	0x44 , 0xAC , 0xE4 , 0xA4 , 0x44
221defb	0xCC , 0x22 , 0x64 , 0x82 , 0xEC
222defb	0xAE , 0xA8 , 0xEC , 0x22 , 0x2C
223defb	0x4E , 0x82 , 0xC2 , 0xA2 , 0x42
224defb	0x44 , 0xAA , 0x46 , 0xA2 , 0x42
225defb	0x00 , 0x44 , 0x00 , 0x44 , 0x08
226defb	0x20 , 0x4E , 0x80 , 0x4E , 0x20
227defb	0x8C , 0x42 , 0x24 , 0x40 , 0x84
228defb	0xC4 , 0x2A , 0x6E , 0xAA , 0x4A
229defb	0xC4 , 0xAA , 0xC8 , 0xAA , 0xC4
230defb	0xCE , 0xA8 , 0xAC , 0xA8 , 0xCE
231defb	0xE6 , 0x88 , 0xCA , 0x8A , 0x86
232defb	0xAE , 0xA4 , 0xE4 , 0xA4 , 0xAE
233defb	0x6A , 0x2C , 0x2C , 0xAC , 0x4A
234defb	0x8A , 0x8E , 0x8E , 0x8E , 0xEE
235defb	0xA4 , 0xEA , 0xEA , 0xEA , 0xA4
236defb	0xC4 , 0xAA , 0xCA , 0x8E , 0x86
237defb	0xC6 , 0xA8 , 0xC4 , 0xC2 , 0xAC
238defb	0xEA , 0x4A , 0x4A , 0x4A , 0x4E
239defb	0xAE , 0xAE , 0xAE , 0x4E , 0x44
240defb	0xAA , 0xAA , 0x44 , 0xA4 , 0xA4
241defb	0xE6 , 0x24 , 0x44 , 0x84 , 0xE6
242defb	0x0C , 0x84 , 0x44 , 0x24 , 0x0C
243defb	0x40 , 0xA0 , 0x00 , 0x00 , 0x0E
244defb	0x40 , 0x26 , 0x0A , 0x0A , 0x06
245
246