src/video/ataricommon/SDL_ataric2p.S
author Patrice Mandin
Fri, 26 Nov 2004 16:16:50 +0000
changeset 991 12b13601a544
parent 734 0310bb01091f
child 1086 93207759e065
permissions -rw-r--r--
Final touches to OSMesa OpenGL support on Atari, using loadable libraries. Hope SDL 1.2.8 is out soon.
     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 	.globl	_SDL_Atari_table_c2p
    42 
    43 /* ------------	Conversion C2P, 8 bits ------------ */
    44 
    45 	.text
    46 _SDL_Atari_C2pConvert8:
    47 	movel	sp@(4),c2p_source
    48 	movel	sp@(8),c2p_dest
    49 	movel	sp@(12),c2p_width
    50 	movel	sp@(16),c2p_height
    51 	movel	sp@(20),c2p_dblligne
    52 	movel	sp@(24),c2p_srcpitch
    53 	movel	sp@(28),c2p_dstpitch
    54 
    55 	moveml	d2-d7/a2-a6,sp@-
    56 
    57 	movel	c2p_source,c2p_cursrc
    58 	movel	c2p_dest,c2p_curdst
    59 	movel	#0x0f0f0f0f,d4
    60 	movel	#0x00ff00ff,d5
    61 	movel	#0x55555555,d6
    62 	movew	c2p_height+2,c2p_row
    63 	movew	c2p_width+2,d0
    64 	andw	#-8,d0
    65 	movew	d0,c2p_rowlen
    66 
    67 SDL_Atari_C2p8_rowloop:
    68 
    69 	movel	c2p_cursrc,a0
    70 	movel	c2p_curdst,a1
    71 
    72 	movel	a0,a2
    73 	addw	c2p_rowlen,a2
    74 
    75 	movel	a0@+,d0
    76 	movel	a0@+,d1
    77 	movel	a0@+,d2
    78 	movel	a0@+,d3
    79 /*
    80 	d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0
    81 	d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0
    82 	d2 = i7i6i5i4i3i2i1i0 j7j6j5j4j3j2j1j0 k7k6k5k4k3k2k1k0 l7l6l5l4l3l2l1l0
    83 	d3 = m7m6m5m4m3m2m1m0 n7n6n5n4n3n2n1n0 o7o6o5o4o3o2o1o0 p7p6p5p4p3p2p1p0
    84 */
    85 	movel	d1,d7
    86 	lsrl	#4,d7
    87 	eorl	d0,d7
    88 	andl	d4,d7
    89 	eorl	d7,d0
    90 	lsll	#4,d7
    91 	eorl	d7,d1
    92 
    93 	movel	d3,d7
    94 	lsrl	#4,d7
    95 	eorl	d2,d7
    96 	andl	d4,d7
    97 	eorl	d7,d2
    98 	lsll	#4,d7
    99 	eorl	d7,d3
   100 
   101 	movel	d2,d7
   102 	lsrl	#8,d7
   103 	eorl	d0,d7
   104  	andl	d5,d7
   105 	eorl	d7,d0
   106 	lsll	#8,d7
   107 	eorl	d7,d2
   108 
   109 	movel	d3,d7
   110 	lsrl	#8,d7
   111 	eorl	d1,d7
   112  	andl	d5,d7
   113 	eorl	d7,d1
   114 	lsll	#8,d7
   115 	eorl	d7,d3
   116 /*
   117 	d0 = a7a6a5a4e7e6e5e4 i7i6i5i4m7m6m5m4 c7c6c5c4g7g6g5g4 k7k6k5k4o7o6o5o4
   118 	d1 = a3a2a1a0e3e2e1e0 i3i2i1i0m3m2m1m0 c3c2c1c0g3g2g1g0 k3k2k1k0o3o2o1o0
   119 	d2 = b7b6b5b4f7f6f5f4 j7j6j5j4n7n6n5n4 d7d6d5d4h7h6h5h4 l7l6l5l4p7p6p5p4
   120 	d3 = b3b2b1b0f3f2f1f0 j3j2j1j0n3n2n1n0 d3d2d1d0h3h2h1h0 l3l2l1l0p3p2p1p0
   121 */
   122 	bras	SDL_Atari_C2p8_start
   123 
   124 SDL_Atari_C2p8_pix16:
   125 
   126 	movel	a0@+,d0
   127 	movel	a0@+,d1
   128 	movel	a0@+,d2
   129 	movel	a0@+,d3
   130 /*
   131 	d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0
   132 	d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0
   133 	d2 = i7i6i5i4i3i2i1i0 j7j6j5j4j3j2j1j0 k7k6k5k4k3k2k1k0 l7l6l5l4l3l2l1l0
   134 	d3 = m7m6m5m4m3m2m1m0 n7n6n5n4n3n2n1n0 o7o6o5o4o3o2o1o0 p7p6p5p4p3p2p1p0
   135 */
   136 	movel	d1,d7
   137 	lsrl	#4,d7
   138 	movel	a3,a1@+
   139 	eorl	d0,d7
   140 	andl	d4,d7
   141 	eorl	d7,d0
   142 	lsll	#4,d7
   143 	eorl	d7,d1
   144 
   145 	movel	d3,d7
   146 	lsrl	#4,d7
   147 	eorl	d2,d7
   148 	andl	d4,d7
   149 	eorl	d7,d2
   150 	movel	a4,a1@+
   151 	lsll	#4,d7
   152 	eorl	d7,d3
   153 
   154 	movel	d2,d7
   155 	lsrl	#8,d7
   156 	eorl	d0,d7
   157 	andl	d5,d7
   158 	eorl	d7,d0
   159 	movel	a5,a1@+
   160 	lsll	#8,d7
   161 	eorl	d7,d2
   162 
   163 	movel	d3,d7
   164 	lsrl	#8,d7
   165 	eorl	d1,d7
   166 	andl	d5,d7
   167 	eorl	d7,d1
   168 	movel	a6,a1@+
   169 	lsll	#8,d7
   170 	eorl	d7,d3
   171 /*
   172 	d0 = a7a6a5a4e7e6e5e4 i7i6i5i4m7m6m5m4 c7c6c5c4g7g6g5g4 k7k6k5k4o7o6o5o4
   173 	d1 = a3a2a1a0e3e2e1e0 i3i2i1i0m3m2m1m0 c3c2c1c0g3g2g1g0 k3k2k1k0o3o2o1o0
   174 	d2 = b7b6b5b4f7f6f5f4 j7j6j5j4n7n6n5n4 d7d6d5d4h7h6h5h4 l7l6l5l4p7p6p5p4
   175 	d3 = b3b2b1b0f3f2f1f0 j3j2j1j0n3n2n1n0 d3d2d1d0h3h2h1h0 l3l2l1l0p3p2p1p0
   176 */
   177 
   178 SDL_Atari_C2p8_start:
   179 
   180 	movel	d2,d7
   181 	lsrl	#1,d7
   182 	eorl	d0,d7
   183 	andl	d6,d7
   184 	eorl	d7,d0
   185 	addl	d7,d7
   186 	eorl	d7,d2
   187 
   188 	movel	d3,d7
   189 	lsrl	#1,d7
   190 	eorl	d1,d7
   191 	andl	d6,d7
   192 	eorl	d7,d1
   193 	addl	d7,d7
   194 	eorl	d7,d3
   195 /*
   196 	d0 = a7b7a5b5e7f7e5f5 i7j7i5j5m7n7m5n5 c7d7c5d5g7h7g5h5 k7l7k5l5o7p7o5p5
   197 	d1 = a3b3a1b1e3f3e1f1 i3j3i1j1m3n3m1n1 c3d3c1d1g3h3g1h1 k3l3k1l1o3p3o1p1
   198 	d2 = a6b6a4b4e6f6e4f4 i6j6i4j4m6n6m4n4 c6d6c4d4g6h6g4h4 k6l6k4l4o6p6o4p4
   199 	d3 = a2b2a0b0e2f2e0f0 i2j2i0j0m2n2m0n0 c2d2c0d0g2h2g0h0 k2l2k0l0o2p2o0p0
   200 */
   201 	movew	d2,d7
   202 	movew	d0,d2
   203 	swap	d2
   204 	movew	d2,d0
   205 	movew	d7,d2
   206 
   207 	movew	d3,d7
   208 	movew	d1,d3
   209 	swap	d3
   210 	movew	d3,d1
   211 	movew	d7,d3
   212 /*
   213 	d0 = a7b7a5b5e7f7e5f5 i7j7i5j5m7n7m5n5 a6b6a4b4e6f6e4f4 i6j6i4j4m6n6m4n4
   214 	d1 = a3b3a1b1e3f3e1f1 i3j3i1j1m3n3m1n1 a2b2a0b0e2f2e0f0 i2j2i0j0m2n2m0n0
   215 	d2 = c7d7c5d5g7h7g5h5 k7l7k5l5o7p7o5p5 c6d6c4d4g6h6g4h4 k6l6k4l4o6p6o4p4
   216 	d3 = c3d3c1d1g3h3g1h1 k3l3k1l1o3p3o1p1 c2d2c0d0g2h2g0h0 k2l2k0l0o2p2o0p0
   217 */
   218 	movel	d2,d7
   219 	lsrl	#2,d7
   220 	eorl	d0,d7
   221 	andl	#0x33333333,d7
   222 	eorl	d7,d0
   223 	lsll	#2,d7
   224 	eorl	d7,d2
   225 
   226 	movel	d3,d7
   227 	lsrl	#2,d7
   228 	eorl	d1,d7
   229 	andl	#0x33333333,d7
   230 	eorl	d7,d1
   231 	lsll	#2,d7
   232 	eorl	d7,d3
   233 /*
   234 	d0 = a7b7c7d7e7f7g7h7 i7j7k7l7m7n7o7p7 a6b6c6d6e6f6g6h6 i6j6k6l6m6n6o6p6
   235 	d1 = a3b3c3d3e3f3g3h3 i3j3k3l3m3n3o3p3 a2b2c2d2e2f2g2h2 i2j2k2l2m2n2o2p2
   236 	d2 = a5b5c5d5e5f5g5h5 i5j5k5l5m5n5o5p5 a4b4c4d4e4f4g4h4 i4j4k4l4m4n4o4p4
   237 	d3 = a1b1c1d1e1f1g1h1 i1j1k1l1m1n1o1p1 a0b0c0d0e0f0g0h0 i0j0k0l0m0n0o0p0
   238 */
   239 	swap	d0
   240 	swap	d1
   241 	swap	d2
   242 	swap	d3
   243 
   244 	movel	d0,a6
   245 	movel	d2,a5
   246 	movel	d1,a4
   247 	movel	d3,a3
   248 
   249 	cmpl	a0,a2
   250 	bgt	SDL_Atari_C2p8_pix16
   251 
   252 	movel	a3,a1@+
   253 	movel	a4,a1@+
   254 	movel	a5,a1@+
   255 	movel	a6,a1@+
   256 
   257 	/* Double the line ? */
   258 
   259 	movel	c2p_srcpitch,d0
   260 	movel	c2p_dstpitch,d1
   261 
   262 	tstl	c2p_dblligne
   263 	beqs	SDL_Atari_C2p8_nodblline
   264 
   265 	movel	c2p_curdst,a0
   266 	movel	a0,a1
   267 	addl	d1,a1
   268 
   269 	movew	c2p_width+2,d7
   270 	lsrw	#4,d7
   271 	subql	#1,d7
   272 SDL_Atari_C2p8_dblloop:
   273 	movel	a0@+,a1@+
   274 	movel	a0@+,a1@+
   275 	movel	a0@+,a1@+
   276 	movel	a0@+,a1@+
   277 	dbra	d7,SDL_Atari_C2p8_dblloop
   278 
   279 	addl	d1,c2p_curdst
   280 
   281 SDL_Atari_C2p8_nodblline:
   282 
   283 	/* Next line */
   284 
   285 	addl	d0,c2p_cursrc
   286 	addl	d1,c2p_curdst
   287 
   288 	subqw	#1,c2p_row
   289 	bne	SDL_Atari_C2p8_rowloop	
   290 
   291 	moveml	sp@+,d2-d7/a2-a6
   292 	rts
   293 
   294 /* ------------	Conversion C2P, 4 bits ------------ */
   295 
   296 _SDL_Atari_C2pConvert4:
   297 	movel	sp@(4),c2p_source
   298 	movel	sp@(8),c2p_dest
   299 	movel	sp@(12),c2p_width
   300 	movel	sp@(16),c2p_height
   301 	movel	sp@(20),c2p_dblligne
   302 	movel	sp@(24),c2p_srcpitch
   303 	movel	sp@(28),c2p_dstpitch
   304 
   305 	moveml	d2-d7/a2-a6,sp@-
   306 
   307 	movel	c2p_source,a0
   308 	movel	c2p_dest,a1
   309 	lea	_SDL_Atari_table_c2p,a2
   310 	movel	#0x00070001,d3
   311 #if defined(__M68020__)
   312 	moveq	#0,d0
   313 #endif
   314 	
   315 	movel	c2p_height,d7
   316 	subql	#1,d7
   317 c2p4_bcly:
   318 	movel	a0,a4	| Save start address of source
   319 	movel	a1,a5	| Save start address of dest
   320 
   321 	| Conversion
   322                  			
   323 	movel	c2p_width,d6
   324 	lsrw	#4,d6
   325 	subql	#1,d6
   326 c2p4_bclx:
   327 	| Octets 0-7
   328 	
   329 	moveq	#0,d1
   330 	moveq	#7,d5
   331 c2p4_bcl07:
   332 #if defined(__M68020__)
   333 	moveb	a0@+,d0
   334 	lea	a2@(0,d0:w:4),a3
   335 #else
   336 	moveq	#0,d0
   337 	moveb	a0@+,d0
   338 	lslw	#2,d0
   339 	lea	a2@(0,d0:w),a3
   340 #endif
   341 	lsll	#1,d1
   342 	orl	a3@,d1
   343 	dbra	d5,c2p4_bcl07
   344 
   345 	movepl	d1,a1@(0)
   346 	addw	d3,a1
   347 	swap	d3
   348 	
   349 	| Octets 8-15
   350 
   351 	moveq	#0,d1
   352 	moveq	#7,d5
   353 c2p4_bcl815:
   354 #if defined(__M68020__)
   355 	moveb	a0@+,d0
   356 	lea	a2@(0,d0:w:4),a3
   357 #else
   358 	moveq	#0,d0
   359 	moveb	a0@+,d0
   360 	lslw	#2,d0
   361 	lea	a2@(0,d0:w),a3
   362 #endif
   363 	lsll	#1,d1
   364 	orl	a3@,d1
   365 	dbra	d5,c2p4_bcl815
   366 
   367 	movepl	d1,a1@(0)
   368 	addw	d3,a1
   369 	swap	d3
   370 
   371 	dbra	d6,c2p4_bclx
   372 
   373 	| Double line ?
   374 
   375 	tstl	c2p_dblligne
   376 	beq	c2p4_nodblligne
   377 
   378 	movel	a5,a6			| src line
   379 	movel	a5,a1			| dest line
   380 	addl	c2p_dstpitch,a1
   381 
   382 	movel	c2p_width,d6
   383 	lsrw	#3,d6
   384 	subql	#1,d6
   385 c2p4_copydbl:
   386 	movel	a6@+,a1@+
   387 	dbra	d6,c2p4_copydbl
   388 
   389 	addl	c2p_dstpitch,a5
   390 c2p4_nodblligne:
   391 
   392 	| Next line
   393 
   394 	movel	a4,a0		
   395 	addl	c2p_srcpitch,a0
   396 	movel	a5,a1
   397 	addl	c2p_dstpitch,a1
   398 
   399 	dbra	d7,c2p4_bcly
   400 
   401 	moveml	sp@+,d2-d7/a2-a6
   402 	rts
   403 
   404 /* ------------	Conversion of a light palette in 4 bits ------------ */
   405 
   406 _SDL_Atari_C2pConvert4_pal:
   407 	/* a0 is a 256-word light palette */
   408 	movel	sp@(4),a0
   409 
   410 	moveml	d2-d3,sp@-
   411 
   412 	lea	_SDL_Atari_table_c2p,a1
   413 	movew	#255,d3
   414 c2p_pal_initbcl:
   415 	movew	a0@+,d0
   416 	lsrw	#4,d0
   417 	and	#15,d0
   418 
   419 	moveq	#3,d1
   420 c2p_pal_initbyte:
   421 	btst	d1,d0
   422 	sne	d2
   423 	negw	d2
   424 	moveb	d2,a1@(0,d1:w)
   425 
   426 	dbra	d1,c2p_pal_initbyte
   427 
   428 	addql	#4,a1
   429 	dbra	d3,c2p_pal_initbcl
   430 
   431 	moveml	sp@+,d2-d3
   432 
   433 	rts
   434 
   435 /* ------------	Buffers ------------ */
   436 
   437 	.data
   438 
   439 	.even
   440 	.comm	_SDL_Atari_C2pConvert,4
   441 	.comm	_SDL_Atari_table_c2p,2048
   442 
   443 	.comm	c2p_source,4	/* Source framebuffer */
   444 	.comm	c2p_dest,4	/* Destination framebuffer */
   445 	.comm	c2p_width,4	/* Width of zone to convert */
   446 	.comm	c2p_height,4	/* Height of zone to convert */
   447 	.comm	c2p_dblligne,4	/* Double the lines while converting ? */
   448 	.comm	c2p_srcpitch,4	/* Source pitch */
   449 	.comm	c2p_dstpitch,4	/* Destination pitch */
   450 	.comm	c2p_cursrc,4	/* Current source line */
   451 	.comm	c2p_curdst,4	/* Current destination line */
   452 	.comm	c2p_rowlen,2	/* Line length in bytes */
   453 	.comm	c2p_row,2	/* Current line number */