grf_ultms.g revision 1.7
11.7Sjdolecek; $NetBSD: grf_ultms.g,v 1.7 2002/05/26 12:53:22 jdolecek Exp $
21.2Schopps;
31.2Schopps; ite support for A2410.
41.2Schopps
51.2Schopps;
61.2Schopps; Copyright (c) 1995 Ignatios Souvatzis.
71.2Schopps; All rights reserved.
81.2Schopps;
91.2Schopps; Redistribution and use in source and binary forms, with or without
101.2Schopps; modification, are permitted provided that the following conditions
111.2Schopps; are met:
121.2Schopps; 1. Redistributions of source code must retain the above copyright
131.2Schopps;    notice, this list of conditions and the following disclaimer.
141.2Schopps; 2. Redistributions in binary form must reproduce the above copyright
151.2Schopps;    notice, this list of conditions and the following disclaimer in the
161.2Schopps;    documentation and/or other materials provided with the distribution.
171.2Schopps; 3. All advertising materials mentioning features or use of this software
181.2Schopps;    must display the following acknowledgement:
191.3Sis;	This product contains software developed by Ignatios Souvatzis
201.3Sis;	for the NetBSD project.
211.2Schopps; 4. The name of the author may not be used to endorse or promote products
221.5Swiz;    derived from this software without specific prior written permission
231.2Schopps;
241.2Schopps; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
251.2Schopps; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
261.2Schopps; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
271.2Schopps; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
281.2Schopps; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
291.2Schopps; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
301.2Schopps; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
311.2Schopps; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
321.2Schopps; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
331.2Schopps; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
341.2Schopps
351.7Sjdolecek; This file contains the source code for grf_ultmscode.c. It is
361.6Saymeric; assembler code for the TMS34010 CPU/graphics processor.
371.2Schopps;
381.2Schopps; Use Paul Mackerras' gspa assembler to transfer it to hex format, then
391.7Sjdolecek; Ignatios Souvatzis' gpsahextoc utility to convert it to grf_ultmscode.c.
401.2Schopps;
411.7Sjdolecek; Use 'make grf_ultms.c' to generate the .c file.
421.2Schopps
431.2Schopps; memory map:
441.2Schopps; FF800000 .. FF9FFFFF	overlay planes
451.2Schopps; FFA00000 .. FFA0FFFF	ite support code
461.2Schopps; FFA10000 .. FFA1FFFF	ite support, input queue
471.2Schopps; FFA20000 .. FFA2FEFF	variables
481.2Schopps; FFA2FF00 .. FFA2FFFF	variables, X server
491.2Schopps; FFA30000 .. FFA3FFFF	font data
501.2Schopps; FFA40000 .. FFA4FFFF	font data, bold
511.2Schopps; FFA50000 .. FFA5FFFF	X server, input queue
521.2Schopps; FFA60000 .. FFFFC000	X server, onboard pixmaps
531.2Schopps
541.2Schopps; Start of data area
551.2Schopps	.org	$FFA20000
561.2Schoppsd:
571.2Schopps
581.2Schopps;
591.2Schopps; Ring buffer for getting stuff from host
601.2Schopps; Data buffer:
611.2Schoppsinbuf	=	$FFA10000	; 64kbits here (8k bytes)
621.2Schopps;
631.2Schopps; Pointers: (these must be at address $FFA20000)
641.2Schoppsput:		.long	inbuf
651.2Schoppsget:		.long	inbuf
661.2Schopps
671.2Schopps;
681.2Schopps; Mode bits for communication between GSP and CPU
691.2Schopps;
701.2Schopps; GSP mode bits: set by CPU, control GSP operation
711.2SchoppsGSP_HOLD =	0
721.2SchoppsGSP_FLUSH =	1
731.2SchoppsGSP_ALT_SCRN =	2
741.2SchoppsGSP_DISP_CTRL =	3
751.2SchoppsGSP_NO_CURSOR =	4
761.2SchoppsGSP_CALL_X =	5
771.2Schoppsgsp_mode:	.word	0
781.2Schopps
791.2Schopps;
801.2Schopps; Pointer to X operation routine
811.2Schoppsxproc:		.long	0
821.2Schopps
831.2Schopps; We leave the next few words for future communication requirements
841.2Schopps
851.2Schopps		.org	d+0x100
861.2Schopps;
871.2Schopps; Other data:
881.2Schoppsmagic:		.blkl	1		; set => screen already inited
891.2SchoppsMAGIC =		0xD0D0BEAC
901.2Schopps
911.2Schoppsscreen_width:	.word	1024
921.2Schoppsscreen_height:	.word	768
931.2Schoppsscreen_origin:	.long	$FE000000	; just a placeholder
941.2Schoppsscreen_pitch:	.word	8192		; 1024*8
951.2Schoppspixel_size:	.word	8
961.2Schopps
971.2Schopps		.org	d+0x200
981.2Schoppsfont_adr:
991.2Schopps;
1001.2Schopps; Font information is stored in the structure defined declared below.
1011.2Schopps;
1021.2Schoppsbitmap_ptrs:	.long	$FFA30000	; points to first bitmap
1031.2Schoppsfont_size:	.long	$00080008	; Y:X bitmap size
1041.2Schoppsunder_row:	.word	6		; row # for underlines
1051.2Schoppsunder_ht:	.word	1		; thickness of underline
1061.2Schoppsfirst_char:	.word	32		; first and last char in font
1071.2Schoppslast_char:	.word	255		;
1081.2Schoppsbold_smear:	.word	1		; for making bold fonts
1091.2Schopps
1101.2Schoppsbgcolor:	.long	0		; background color
1111.2Schoppsfgcolor:	.long	$01010101	; foreground color
1121.2Schopps;precomputed out of what the host gave us:
1131.2Schoppsfont_area:	.word	64		; in pixels
1141.2Schoppsfont_pitch:	.word	8
1151.2Schoppsfont_lmo:	.word	28
1161.2Schopps
1171.2Schopps
1181.2Schopps; Control register addresses
1191.2Schoppshesync	=	$c0000000
1201.2Schoppsdpyctl	=	$c0000080
1211.2Schoppscontrol	=	$c00000b0
1221.2Schoppsconvsp	=	$c0000130
1231.2Schoppsconvdp	=	$c0000140
1241.2Schoppspsize	=	$c0000150
1251.2Schopps
1261.2Schopps;
1271.2Schopps; Bits in control register
1281.2SchoppsT	=	$20		; enable transparency
1291.2SchoppsW	=	$C0		; window options
1301.2SchoppsPBH	=	$100		; pixblt horiz dirn
1311.2SchoppsPBV	=	$200		; pixblt vertical dirn
1321.2SchoppsPPOP	=	$7C00		; pixel processing options
1331.2Schopps
1341.2Schopps;
1351.2Schopps; Bits in dpyctl register
1361.2SchoppsSRT	=	$800		; do serial register transfers
1371.2Schopps
1381.2Schoppsfree_memory:	.long	free_memory_start
1391.2Schoppsfree_memory_start:		; allocate dynamic arrays from here
1401.2Schopps
1411.2Schopps;
1421.2Schopps; Program starts here.
1431.2Schopps	.org	$FFA00000
1441.2Schopps	.start	.
1451.2Schopps
1461.2Schopps;
1471.2Schopps; initialization
1481.2Schopps;
1491.2Schopps	setf	16,0,0		; just in case
1501.2Schopps	setf	32,0,1
1511.2Schopps	move	$fffff000,sp
1521.2Schopps
1531.2Schopps; Set up sync, blank parameters
1541.2Schopps; done by host through interface
1551.2Schopps
1561.2Schopps; set up overlay clut:
1571.2Schopps	move	$0,a0
1581.2Schopps	move	a0,@$fe800000
1591.2Schopps	move	$fe800030,a1
1601.2Schopps	move	128,a0
1611.2Schopps	move	a0,*a1
1621.2Schopps	move	a0,*a1
1631.2Schopps	move	a0,*a1
1641.2Schopps	move	0,a0
1651.2Schopps	move	a0,*a1
1661.2Schopps	move	a0,*a1
1671.2Schopps	move	a0,*a1
1681.2Schopps	move	a0,*a1
1691.2Schopps	move	a0,*a1
1701.2Schopps	move	a0,*a1
1711.2Schopps	move	a0,*a1
1721.2Schopps	move	a0,*a1
1731.2Schopps	move	a0,*a1
1741.2Schopps
1751.2Schopps; set up overlay planes:
1761.2Schopps	move	6,a0
1771.2Schopps	move	a0,@$fe800000
1781.2Schopps	move	$0b,a0
1791.2Schopps	move	a0,@$fe800020
1801.2Schopps
1811.2Schopps; set up global registers
1821.2Schopps	move	@screen_pitch,b3,0
1831.2Schopps	move	@screen_origin,b4,1
1841.2Schopps	move	@bgcolor,b8,1
1851.2Schopps	lmo	b3,b0
1861.2Schopps	move	b0,@convdp,0
1871.2Schopps	move	@control,a0,0
1881.2Schopps	andn	$7FE0,a0		; clear PPOP, PBV, PBH, W, T fields
1891.2Schopps	move	a0,@control,0
1901.2Schopps	move	@pixel_size,a0,0
1911.2Schopps	move	a0,@psize,0
1921.2Schopps	move	@psize,a0,0
1931.2Schopps
1941.2Schopps
1951.2Schopps; clear the entire screen
1961.2Schopps	move	b4,b2
1971.2Schopps	move	0,b9
1981.2Schopps	move	@screen_width,b7,1
1991.2Schopps	fill	l
2001.2Schopps
2011.2Schopps4:
2021.2Schopps; main stuff...
2031.2Schopps	move	@get,a0,1
2041.2Schopps	jruc	main_loop
2051.2Schoppsloop_end:
2061.2Schopps	clr	a4
2071.2Schopps	move	a4,*a0,0
2081.2Schopps	addxy	a1,a0
2091.2Schopps	move	a0,@get,1
2101.2Schoppsmain_loop:
2111.2Schopps	move	@gsp_mode,a1,0
2121.2Schopps	btst	GSP_CALL_X,a1
2131.2Schopps	jreq	main_loop_1
2141.2Schopps
2151.2Schopps	mmtm	sp,a0,a1,a2,a3
2161.2Schopps	move	@xproc,a4,1
2171.2Schopps	call	a4
2181.2Schopps	mmfm	sp,a0,a1,a2,a3
2191.2Schopps
2201.2Schoppsmain_loop_1:
2211.2Schopps	move	@put,a3,1
2221.2Schopps	move	*a0,a1,0
2231.2Schopps
2241.2Schopps	move	a1,a2
2251.2Schopps	andi	$FFF0,a1
2261.2Schopps	jrz	main_loop
2271.2Schopps
2281.2Schopps	sub	a0,a3
2291.2Schopps	jreq	main_loop
2301.2Schoppscontinue:
2311.2Schopps	andi	$F,a2
2321.2Schopps	jrz	loop_end
2331.2Schopps	dec	a2
2341.2Schopps	jrnz	testfor2
2351.2Schopps; op 1 - char
2361.2Schopps	movk	6,b10
2371.2Schopps	move	b10,@$fe800000,0
2381.2Schopps	movk	1,b10
2391.2Schopps	move	b10,@$fe800020,0
2401.2Schopps
2411.2Schopps	move	a0,b10
2421.2Schopps	move	*b10+,b12,0	; dummy move (faster than addk)
2431.2Schopps	move	*b10+,b12,0	; char code
2441.2Schopps	move	@first_char,b11,0
2451.2Schopps	sub	b11,b12		; minus first char in font
2461.2Schopps	move	@font_size,b7,1	;dydx - char size->pixel array dimensions
2471.2Schopps	move	@font_pitch,b1
2481.2Schopps	move	@font_lmo,b0
2491.2Schopps	move	b0,@convsp,0
2501.2Schopps	move	@font_area,b11
2511.6Saymeric
2521.2Schopps	mpyu	b12,b11		; times char offset
2531.2Schopps	move	@font_adr,b0,1	; font bitmaps base
2541.2Schopps	add	b11,b0		; character bitmap start addr. linear
2551.2Schopps
2561.2Schopps	move	*b10+,b8,0	; fg
2571.2Schopps	move	*b10+,b9,0	; bg
2581.2Schopps	move	*b10+,b2,1	; y:x
2591.2Schopps
2601.2Schopps	move	*b10+,b11,0	; flags
2611.2Schopps	move	b11,a4
2621.2Schopps	btst	0,a4
2631.2Schopps	jreq	noinv
2641.2Schopps	move	b8,b11
2651.2Schopps	move	b9,b8
2661.2Schopps	move	b11,b9
2671.2Schoppsnoinv:
2681.2Schopps	btst	2,a4
2691.2Schopps	jreq	nobold
2701.2Schopps	addi	$10000,b0
2711.2Schoppsnobold:
2721.2Schopps	move	b2,a5
2731.2Schopps	pixblt	b,xy
2741.2Schopps	move	a5,b2
2751.2Schopps
2761.2Schopps	btst	1,a4
2771.2Schopps	jreq	noul
2781.2Schopps	move	@under_row,b11,0
2791.2Schopps	sll	16,b11		; shift into Y half
2801.2Schopps	add	b11,b2
2811.2Schopps	move	@under_ht,b11,0
2821.2Schopps	sll	16,b11		; shift into Y half
2831.2Schopps	movy	b11,b7		; and move Y half only
2841.2Schopps	fill	xy
2851.2Schoppsnoul:
2861.2Schopps	jruc	loop_end
2871.2Schoppstestfor2:
2881.2Schopps	dec	a2
2891.2Schopps	jrnz	testfor3
2901.2Schopps; op 2 - fill
2911.2Schopps	move	a0,b10
2921.2Schopps	move	*b10+,b9,0	; dummy move
2931.2Schopps	move	*b10+,b9,0	; color
2941.2Schopps	move	*b10+,b2,1	; XY start address
2951.2Schopps	move	*b10+,b7,1	; dydx
2961.2Schopps
2971.2Schopps	move	@control,b0,0
2981.2Schopps	move	b0,*-sp
2991.2Schopps	move	*b10+,b0
3001.2Schopps	setf	5,0,0
3011.2Schopps	move	b0,@control+10
3021.2Schopps	setf	16,0,0
3031.2Schopps	move	@control,b0,0
3041.2Schopps
3051.2Schopps	fill	xy
3061.2Schopps
3071.2Schopps	move	*sp+,b0
3081.2Schopps	move	b0,@control,0
3091.2Schopps	jruc	loop_end,l
3101.2Schopps
3111.2Schoppstestfor3:
3121.2Schopps	dec	a2
3131.2Schopps	jrnz	testfor4
3141.2Schopps; op 3 - pixblt
3151.2Schopps	move	a0,b10
3161.2Schopps	move	@convdp,@convsp,0
3171.2Schopps	move	*b10+,b0,0	; dummy move
3181.2Schopps	move	*b10+,b0,1	; XY src
3191.2Schopps	move	*b10+,b7,1	; dxdy
3201.2Schopps	move	*b10+,b2,1	; XY dst
3211.2Schopps	move	b3,b1
3221.2Schopps	move	@control,b11,0
3231.2Schopps	andni	PBH|PBV,b11
3241.2Schopps	cmpxy	b0,b2
3251.2Schopps	jrc	yok
3261.2Schopps	ori	PBV,b11
3271.2Schoppsyok:	jrv	xok
3281.2Schopps	ori	PBH,b11
3291.2Schoppsxok:	move	b11,@control,0
3301.2Schopps	move	@control,b11,0
3311.6Saymeric
3321.2Schopps	pixblt	xy,xy
3331.2Schopps	jruc	loop_end,l
3341.2Schopps
3351.2Schoppstestfor4:
3361.2Schopps	dec	a2
3371.2Schopps	jrnz	testfor5
3381.2Schopps
3391.2Schopps; op 4 - mirror the font and precompute some values.
3401.2Schopps
3411.2Schopps	move	@font_size,a5,0
3421.2Schopps	movk	8,a6
3431.2Schopps	cmp	a6,a5
3441.2Schopps	jrle	t4b8
3451.2Schopps	movi	16, a6
3461.2Schoppst4b8:	move	a6,@font_pitch,0
3471.2Schopps	lmo	a5,a6
3481.2Schopps	move	a6,@font_lmo,0
3491.2Schopps	move	@font_size+$10,a6,0
3501.2Schopps	move	@font_pitch,a5,0
3511.2Schopps	mpyu	a6,a5
3521.2Schopps	move	a5,@font_area,0
3531.2Schopps
3541.2Schopps	move	@last_char,a6,0
3551.2Schopps	move	@first_char,a5,0
3561.2Schopps	sub	a5,a6
3571.2Schopps	addk	1,a6
3581.2Schopps	move	@font_size+$10,a5,0
3591.2Schopps	mpyu	a6,a5
3601.2Schopps	move	@font_size,a7,0
3611.2Schopps	cmpi	8,a7
3621.2Schopps	move	$7f7f,a12	; mask for bold smearing
3631.2Schopps	jrgt	t4bf		; wider than 8 pixels?
3641.2Schopps	addk	1,a5		; yes, the words are only half the # of rows
3651.2Schopps	srl	1,a5
3661.2Schopps	move	$7fff,a12	; mask for bold smearing changes, too
3671.2Schoppst4bf:	move	@font_adr,a6,1
3681.2Schopps	move	a6,a9
3691.2Schopps	addi	$10000,a9 ; start address of bold font
3701.2Schopps	move	@bold_smear,a10
3711.2Schopps
3721.2Schopps; fortunately, this loop fits into 3 of the 4 cache segments:
3731.2Schopps; execution time: about 32 periods per word of font.
3741.2Schopps
3751.2Schoppsmirlp:	move	*a6,a7
3761.2Schopps	clr	a8
3771.2Schopps
3781.2Schopps	srl	1,a7
3791.2Schopps	addc	a8,a8
3801.2Schopps	srl	1,a7
3811.2Schopps	addc	a8,a8
3821.2Schopps	srl	1,a7
3831.2Schopps	addc	a8,a8
3841.2Schopps	srl	1,a7
3851.2Schopps	addc	a8,a8
3861.2Schopps
3871.2Schopps	srl	1,a7
3881.2Schopps	addc	a8,a8
3891.2Schopps	srl	1,a7
3901.2Schopps	addc	a8,a8
3911.2Schopps	srl	1,a7
3921.2Schopps	addc	a8,a8
3931.2Schopps	srl	1,a7
3941.2Schopps	addc	a8,a8
3951.2Schopps
3961.2Schopps	srl	1,a7
3971.2Schopps	addc	a8,a8
3981.2Schopps	srl	1,a7
3991.2Schopps	addc	a8,a8
4001.2Schopps	srl	1,a7
4011.2Schopps	addc	a8,a8
4021.2Schopps	srl	1,a7
4031.2Schopps	addc	a8,a8
4041.2Schopps
4051.2Schopps	srl	1,a7
4061.2Schopps	addc	a8,a8
4071.2Schopps	srl	1,a7
4081.2Schopps	addc	a8,a8
4091.2Schopps	srl	1,a7
4101.2Schopps	addc	a8,a8
4111.2Schopps	srl	1,a7
4121.2Schopps	addc	a8,a8
4131.2Schopps
4141.2Schopps	move	a8,*a6+
4151.2Schopps	move	a8,a7
4161.2Schopps	move	a10,a11
4171.2Schoppssmearlp:
4181.2Schopps	and	a12,a7
4191.2Schopps	sll	1,a7
4201.2Schopps	or	a7,a8
4211.2Schopps	dsj	a11,smearlp
4221.2Schopps	move	a8,*a9+
4231.2Schopps
4241.2Schopps	dsj	a5,mirlp
4251.2Schopps;; support odd-sized fonts. pitch must still be 8 or 16
4261.2Schopps	move	@font_size,a5,0
4271.2Schopps	move	@font_pitch,a6,0
4281.2Schopps	sub	a5,a6
4291.2Schopps	move	@font_adr,a5,1
4301.2Schopps	add	a5,a6
4311.2Schopps	move	a6,@font_adr,1
4321.2Schopps;;
4331.2Schopps	jruc	loop_end,l
4341.2Schopps
4351.6Saymeric
4361.2Schoppstestfor5:
4371.2Schopps	dec	a2
4381.2Schopps	jrne	testfor6
4391.2Schopps; loadclut --- load clut entry.
4401.2Schopps;	1==overlay index red green blue
4411.2Schopps;	for speed reasons, the host will load the image clut directly rather
4421.6Saymeric;	than through us, but its not that expensive to support both here
4431.2Schopps;	just in case
4441.2Schopps	move	a0,a4
4451.2Schopps	addk	$10,a4
4461.2Schopps	move	$fe800030,a6
4471.2Schopps	move	*a4+,a5,0
4481.2Schopps	jrne	t5l1
4491.2Schopps	subk	$20,a6
4501.2Schoppst5l1:	move	*a4+,a5,0
4511.2Schopps	move	a5,@$fe800000,0
4521.2Schopps	move	*a4+,a5,0
4531.2Schopps	move	a5,*a6,0
4541.2Schopps	move	*a4+,a5,0
4551.2Schopps	move	a5,*a6,0
4561.2Schopps	move	*a4+,a5,0
4571.2Schopps	move	a5,*a6,0
4581.2Schopps	jruc	loop_end,l
4591.6Saymeric
4601.2Schoppstestfor6:
4611.2Schopps	dec	a2
4621.2Schopps	jrne	testfor7
4631.2Schopps
4641.2Schopps; op 6: load new framebuffer size and position for ite support.
4651.2Schopps	move	a0,b10
4661.2Schopps	addk	$10,b10
4671.2Schopps	move	*b10+,b7,1
4681.2Schopps	move	b7,@screen_width,1
4691.2Schopps	move	*b10+,b4,1
4701.2Schopps	move	b4,@screen_origin,1
4711.2Schopps	move	*b10+,b3,0
4721.2Schopps	move	b3,@screen_pitch,0
4731.2Schopps	lmo	b3,b0
4741.2Schopps	move	b0,@convdp,0
4751.2Schopps	move	*b10,b0,0
4761.2Schopps	move	b0,@psize,0
4771.2Schopps	move	b0,@pixel_size,0	; this syncs the psize write, too
4781.2Schopps
4791.2Schopps	jruc	loop_end,l
4801.6Saymeric
4811.2Schoppstestfor7:
4821.2Schopps	jruc	loop_end,l
4831.2Schopps;;;
484