src/video/ataricommon/SDL_ataric2p.S
author Ryan C. Gordon <icculus@icculus.org>
Fri, 06 Jan 2006 13:20:10 +0000
changeset 1234 73676c1f56ee
parent 1086 93207759e065
child 1312 c9b51268668f
permissions -rw-r--r--
For sanity's sake, removed the '&' when passing copy_row array to asm.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #ifdef SAVE_RCSID
    24 static char rcsid =
    25  "@(#) $Id$";
    26 #endif
    27 
    28 /*
    29 	Chunky to planar conversion routine
    30 	1 byte/pixel -> 4 or 8 bit planes
    31 
    32 	Patrice Mandin
    33 	Xavier Joubert
    34 	Mikael Kalms
    35 */
    36 
    37 	.globl	_SDL_Atari_C2pConvert
    38 	.globl	_SDL_Atari_C2pConvert8
    39 	.globl	_SDL_Atari_C2pConvert4
    40 	.globl	_SDL_Atari_C2pConvert4_pal
    41 
    42 /* ------------	Conversion C2P, 8 bits ------------ */
    43 
    44 	.text
    45 _SDL_Atari_C2pConvert8:
    46 	movel	sp@(4),c2p_source
    47 	movel	sp@(8),c2p_dest
    48 	movel	sp@(12),c2p_width
    49 	movel	sp@(16),c2p_height
    50 	movel	sp@(20),c2p_dblligne
    51 	movel	sp@(24),c2p_srcpitch
    52 	movel	sp@(28),c2p_dstpitch
    53 
    54 	moveml	d2-d7/a2-a6,sp@-
    55 
    56 	movel	c2p_source,c2p_cursrc
    57 	movel	c2p_dest,c2p_curdst
    58 	movel	#0x0f0f0f0f,d4
    59 	movel	#0x00ff00ff,d5
    60 	movel	#0x55555555,d6
    61 	movew	c2p_height+2,c2p_row
    62 	movew	c2p_width+2,d0
    63 	andw	#-8,d0
    64 	movew	d0,c2p_rowlen
    65 
    66 SDL_Atari_C2p8_rowloop:
    67 
    68 	movel	c2p_cursrc,a0
    69 	movel	c2p_curdst,a1
    70 
    71 	movel	a0,a2
    72 	addw	c2p_rowlen,a2
    73 
    74 	movel	a0@+,d0
    75 	movel	a0@+,d1
    76 	movel	a0@+,d2
    77 	movel	a0@+,d3
    78 /*
    79 	d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0
    80 	d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0
    81 	d2 = i7i6i5i4i3i2i1i0 j7j6j5j4j3j2j1j0 k7k6k5k4k3k2k1k0 l7l6l5l4l3l2l1l0
    82 	d3 = m7m6m5m4m3m2m1m0 n7n6n5n4n3n2n1n0 o7o6o5o4o3o2o1o0 p7p6p5p4p3p2p1p0
    83 */
    84 	movel	d1,d7
    85 	lsrl	#4,d7
    86 	eorl	d0,d7
    87 	andl	d4,d7
    88 	eorl	d7,d0
    89 	lsll	#4,d7
    90 	eorl	d7,d1
    91 
    92 	movel	d3,d7
    93 	lsrl	#4,d7
    94 	eorl	d2,d7
    95 	andl	d4,d7
    96 	eorl	d7,d2
    97 	lsll	#4,d7
    98 	eorl	d7,d3
    99 
   100 	movel	d2,d7
   101 	lsrl	#8,d7
   102 	eorl	d0,d7
   103  	andl	d5,d7
   104 	eorl	d7,d0
   105 	lsll	#8,d7
   106 	eorl	d7,d2
   107 
   108 	movel	d3,d7
   109 	lsrl	#8,d7
   110 	eorl	d1,d7
   111  	andl	d5,d7
   112 	eorl	d7,d1
   113 	lsll	#8,d7
   114 	eorl	d7,d3
   115 /*
   116 	d0 = a7a6a5a4e7e6e5e4 i7i6i5i4m7m6m5m4 c7c6c5c4g7g6g5g4 k7k6k5k4o7o6o5o4
   117 	d1 = a3a2a1a0e3e2e1e0 i3i2i1i0m3m2m1m0 c3c2c1c0g3g2g1g0 k3k2k1k0o3o2o1o0
   118 	d2 = b7b6b5b4f7f6f5f4 j7j6j5j4n7n6n5n4 d7d6d5d4h7h6h5h4 l7l6l5l4p7p6p5p4
   119 	d3 = b3b2b1b0f3f2f1f0 j3j2j1j0n3n2n1n0 d3d2d1d0h3h2h1h0 l3l2l1l0p3p2p1p0
   120 */
   121 	bras	SDL_Atari_C2p8_start
   122 
   123 SDL_Atari_C2p8_pix16:
   124 
   125 	movel	a0@+,d0
   126 	movel	a0@+,d1
   127 	movel	a0@+,d2
   128 	movel	a0@+,d3
   129 /*
   130 	d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0
   131 	d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0
   132 	d2 = i7i6i5i4i3i2i1i0 j7j6j5j4j3j2j1j0 k7k6k5k4k3k2k1k0 l7l6l5l4l3l2l1l0
   133 	d3 = m7m6m5m4m3m2m1m0 n7n6n5n4n3n2n1n0 o7o6o5o4o3o2o1o0 p7p6p5p4p3p2p1p0
   134 */
   135 	movel	d1,d7
   136 	lsrl	#4,d7
   137 	movel	a3,a1@+
   138 	eorl	d0,d7
   139 	andl	d4,d7
   140 	eorl	d7,d0
   141 	lsll	#4,d7
   142 	eorl	d7,d1
   143 
   144 	movel	d3,d7
   145 	lsrl	#4,d7
   146 	eorl	d2,d7
   147 	andl	d4,d7
   148 	eorl	d7,d2
   149 	movel	a4,a1@+
   150 	lsll	#4,d7
   151 	eorl	d7,d3
   152 
   153 	movel	d2,d7
   154 	lsrl	#8,d7
   155 	eorl	d0,d7
   156 	andl	d5,d7
   157 	eorl	d7,d0
   158 	movel	a5,a1@+
   159 	lsll	#8,d7
   160 	eorl	d7,d2
   161 
   162 	movel	d3,d7
   163 	lsrl	#8,d7
   164 	eorl	d1,d7
   165 	andl	d5,d7
   166 	eorl	d7,d1
   167 	movel	a6,a1@+
   168 	lsll	#8,d7
   169 	eorl	d7,d3
   170 /*
   171 	d0 = a7a6a5a4e7e6e5e4 i7i6i5i4m7m6m5m4 c7c6c5c4g7g6g5g4 k7k6k5k4o7o6o5o4
   172 	d1 = a3a2a1a0e3e2e1e0 i3i2i1i0m3m2m1m0 c3c2c1c0g3g2g1g0 k3k2k1k0o3o2o1o0
   173 	d2 = b7b6b5b4f7f6f5f4 j7j6j5j4n7n6n5n4 d7d6d5d4h7h6h5h4 l7l6l5l4p7p6p5p4
   174 	d3 = b3b2b1b0f3f2f1f0 j3j2j1j0n3n2n1n0 d3d2d1d0h3h2h1h0 l3l2l1l0p3p2p1p0
   175 */
   176 
   177 SDL_Atari_C2p8_start:
   178 
   179 	movel	d2,d7
   180 	lsrl	#1,d7
   181 	eorl	d0,d7
   182 	andl	d6,d7
   183 	eorl	d7,d0
   184 	addl	d7,d7
   185 	eorl	d7,d2
   186 
   187 	movel	d3,d7
   188 	lsrl	#1,d7
   189 	eorl	d1,d7
   190 	andl	d6,d7
   191 	eorl	d7,d1
   192 	addl	d7,d7
   193 	eorl	d7,d3
   194 /*
   195 	d0 = a7b7a5b5e7f7e5f5 i7j7i5j5m7n7m5n5 c7d7c5d5g7h7g5h5 k7l7k5l5o7p7o5p5
   196 	d1 = a3b3a1b1e3f3e1f1 i3j3i1j1m3n3m1n1 c3d3c1d1g3h3g1h1 k3l3k1l1o3p3o1p1
   197 	d2 = a6b6a4b4e6f6e4f4 i6j6i4j4m6n6m4n4 c6d6c4d4g6h6g4h4 k6l6k4l4o6p6o4p4
   198 	d3 = a2b2a0b0e2f2e0f0 i2j2i0j0m2n2m0n0 c2d2c0d0g2h2g0h0 k2l2k0l0o2p2o0p0
   199 */
   200 	movew	d2,d7
   201 	movew	d0,d2
   202 	swap	d2
   203 	movew	d2,d0
   204 	movew	d7,d2
   205 
   206 	movew	d3,d7
   207 	movew	d1,d3
   208 	swap	d3
   209 	movew	d3,d1
   210 	movew	d7,d3
   211 /*
   212 	d0 = a7b7a5b5e7f7e5f5 i7j7i5j5m7n7m5n5 a6b6a4b4e6f6e4f4 i6j6i4j4m6n6m4n4
   213 	d1 = a3b3a1b1e3f3e1f1 i3j3i1j1m3n3m1n1 a2b2a0b0e2f2e0f0 i2j2i0j0m2n2m0n0
   214 	d2 = c7d7c5d5g7h7g5h5 k7l7k5l5o7p7o5p5 c6d6c4d4g6h6g4h4 k6l6k4l4o6p6o4p4
   215 	d3 = c3d3c1d1g3h3g1h1 k3l3k1l1o3p3o1p1 c2d2c0d0g2h2g0h0 k2l2k0l0o2p2o0p0
   216 */
   217 	movel	d2,d7
   218 	lsrl	#2,d7
   219 	eorl	d0,d7
   220 	andl	#0x33333333,d7
   221 	eorl	d7,d0
   222 	lsll	#2,d7
   223 	eorl	d7,d2
   224 
   225 	movel	d3,d7
   226 	lsrl	#2,d7
   227 	eorl	d1,d7
   228 	andl	#0x33333333,d7
   229 	eorl	d7,d1
   230 	lsll	#2,d7
   231 	eorl	d7,d3
   232 /*
   233 	d0 = a7b7c7d7e7f7g7h7 i7j7k7l7m7n7o7p7 a6b6c6d6e6f6g6h6 i6j6k6l6m6n6o6p6
   234 	d1 = a3b3c3d3e3f3g3h3 i3j3k3l3m3n3o3p3 a2b2c2d2e2f2g2h2 i2j2k2l2m2n2o2p2
   235 	d2 = a5b5c5d5e5f5g5h5 i5j5k5l5m5n5o5p5 a4b4c4d4e4f4g4h4 i4j4k4l4m4n4o4p4
   236 	d3 = a1b1c1d1e1f1g1h1 i1j1k1l1m1n1o1p1 a0b0c0d0e0f0g0h0 i0j0k0l0m0n0o0p0
   237 */
   238 	swap	d0
   239 	swap	d1
   240 	swap	d2
   241 	swap	d3
   242 
   243 	movel	d0,a6
   244 	movel	d2,a5
   245 	movel	d1,a4
   246 	movel	d3,a3
   247 
   248 	cmpl	a0,a2
   249 	bgt		SDL_Atari_C2p8_pix16
   250 
   251 	movel	a3,a1@+
   252 	movel	a4,a1@+
   253 	movel	a5,a1@+
   254 	movel	a6,a1@+
   255 
   256 	/* Double the line ? */
   257 
   258 	movel	c2p_srcpitch,d0
   259 	movel	c2p_dstpitch,d1
   260 
   261 	tstl	c2p_dblligne
   262 	beqs	SDL_Atari_C2p8_nodblline
   263 
   264 	movel	c2p_curdst,a0
   265 	movel	a0,a1
   266 	addl	d1,a1
   267 
   268 	movew	c2p_width+2,d7
   269 	lsrw	#4,d7
   270 	subql	#1,d7
   271 SDL_Atari_C2p8_dblloop:
   272 	movel	a0@+,a1@+
   273 	movel	a0@+,a1@+
   274 	movel	a0@+,a1@+
   275 	movel	a0@+,a1@+
   276 	dbra	d7,SDL_Atari_C2p8_dblloop
   277 
   278 	addl	d1,c2p_curdst
   279 
   280 SDL_Atari_C2p8_nodblline:
   281 
   282 	/* Next line */
   283 
   284 	addl	d0,c2p_cursrc
   285 	addl	d1,c2p_curdst
   286 
   287 	subqw	#1,c2p_row
   288 	bne		SDL_Atari_C2p8_rowloop	
   289 
   290 	moveml	sp@+,d2-d7/a2-a6
   291 	rts
   292 
   293 /* ------------	Conversion C2P, 4 bits ------------ */
   294 
   295 _SDL_Atari_C2pConvert4:
   296 	movel	sp@(4),c2p_source
   297 	movel	sp@(8),c2p_dest
   298 	movel	sp@(12),c2p_width
   299 	movel	sp@(16),c2p_height
   300 	movel	sp@(20),c2p_dblligne
   301 	movel	sp@(24),c2p_srcpitch
   302 	movel	sp@(28),c2p_dstpitch
   303 
   304 	moveml	d2-d7/a2-a6,sp@-
   305 
   306 	movel	c2p_source,a0
   307 	movel	c2p_dest,a1
   308 	lea	_SDL_Atari_table_c2p,a2
   309 	movel	#0x00070001,d3
   310 #if defined(__M68020__)
   311 	moveq	#0,d0
   312 #endif
   313 	
   314 	movel	c2p_height,d7
   315 	subql	#1,d7
   316 c2p4_bcly:
   317 	movel	a0,a4	| Save start address of source
   318 	movel	a1,a5	| Save start address of dest
   319 
   320 	| Conversion
   321                  			
   322 	movel	c2p_width,d6
   323 	lsrw	#4,d6
   324 	subql	#1,d6
   325 c2p4_bclx:
   326 	| Octets 0-7
   327 	
   328 	moveq	#0,d1
   329 	moveq	#7,d5
   330 c2p4_bcl07:
   331 #if defined(__M68020__)
   332 	moveb	a0@+,d0
   333 	lea		a2@(0,d0:w:4),a3
   334 #else
   335 	moveq	#0,d0
   336 	moveb	a0@+,d0
   337 	lslw	#2,d0
   338 	lea		a2@(0,d0:w),a3
   339 #endif
   340 	lsll	#1,d1
   341 	orl		a3@,d1
   342 	dbra	d5,c2p4_bcl07
   343 
   344 	movepl	d1,a1@(0)
   345 	addw	d3,a1
   346 	swap	d3
   347 	
   348 	| Octets 8-15
   349 
   350 	moveq	#0,d1
   351 	moveq	#7,d5
   352 c2p4_bcl815:
   353 #if defined(__M68020__)
   354 	moveb	a0@+,d0
   355 	lea		a2@(0,d0:w:4),a3
   356 #else
   357 	moveq	#0,d0
   358 	moveb	a0@+,d0
   359 	lslw	#2,d0
   360 	lea		a2@(0,d0:w),a3
   361 #endif
   362 	lsll	#1,d1
   363 	orl		a3@,d1
   364 	dbra	d5,c2p4_bcl815
   365 
   366 	movepl	d1,a1@(0)
   367 	addw	d3,a1
   368 	swap	d3
   369 
   370 	dbra	d6,c2p4_bclx
   371 
   372 	| Double line ?
   373 
   374 	tstl	c2p_dblligne
   375 	beqs	c2p4_nodblligne
   376 
   377 	movel	a5,a6			| src line
   378 	movel	a5,a1			| dest line
   379 	addl	c2p_dstpitch,a1
   380 
   381 	movel	c2p_width,d6
   382 	lsrw	#3,d6
   383 	subql	#1,d6
   384 c2p4_copydbl:
   385 	movel	a6@+,a1@+
   386 	dbra	d6,c2p4_copydbl
   387 
   388 	addl	c2p_dstpitch,a5
   389 c2p4_nodblligne:
   390 
   391 	| Next line
   392 
   393 	movel	a4,a0		
   394 	addl	c2p_srcpitch,a0
   395 	movel	a5,a1
   396 	addl	c2p_dstpitch,a1
   397 
   398 	dbra	d7,c2p4_bcly
   399 
   400 	moveml	sp@+,d2-d7/a2-a6
   401 	rts
   402 
   403 /* ------------	Conversion of a light palette in 4 bits ------------ */
   404 
   405 _SDL_Atari_C2pConvert4_pal:
   406 	/* a0 is a 256-word light palette */
   407 	movel	sp@(4),a0
   408 
   409 	moveml	d2-d3,sp@-
   410 
   411 	lea		_SDL_Atari_table_c2p,a1
   412 	movew	#255,d3
   413 c2p_pal_initbcl:
   414 	movew	a0@+,d0
   415 	lsrw	#4,d0
   416 	andw	#15,d0
   417 
   418 	moveq	#3,d1
   419 c2p_pal_initbyte:
   420 	btst	d1,d0
   421 	sne		d2
   422 	negw	d2
   423 	moveb	d2,a1@(0,d1:w)
   424 
   425 	dbra	d1,c2p_pal_initbyte
   426 
   427 	addql	#4,a1
   428 	dbra	d3,c2p_pal_initbcl
   429 
   430 	moveml	sp@+,d2-d3
   431 
   432 	rts
   433 
   434 /* ------------	Buffers ------------ */
   435 
   436 	.bss
   437 
   438 	.even
   439 	.comm	_SDL_Atari_C2pConvert,4
   440 	.comm	_SDL_Atari_table_c2p,1024
   441 
   442 	.comm	c2p_source,4	/* Source framebuffer */
   443 	.comm	c2p_dest,4		/* Destination framebuffer */
   444 	.comm	c2p_width,4		/* Width of zone to convert */
   445 	.comm	c2p_height,4	/* Height of zone to convert */
   446 	.comm	c2p_dblligne,4	/* Double the lines while converting ? */
   447 	.comm	c2p_srcpitch,4	/* Source pitch */
   448 	.comm	c2p_dstpitch,4	/* Destination pitch */
   449 	.comm	c2p_cursrc,4	/* Current source line */
   450 	.comm	c2p_curdst,4	/* Current destination line */
   451 	.comm	c2p_rowlen,2	/* Line length in bytes */
   452 	.comm	c2p_row,2		/* Current line number */