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