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