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