src/video/ataricommon/SDL_ataric2p.S
author Sam Lantinga <slouken@libsdl.org>
Sun, 17 Feb 2002 19:54:28 +0000
changeset 281 c5010ab8ba35
child 297 f6ffac90895c
permissions -rw-r--r--
Added initial support for Atari (thanks Patrice!)
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997, 1998, 1999, 2000, 2001  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  */
    35 
    36 /* ------------	Function pointers ------------ */
    37 
    38 	.globl	_Atari_C2pInit
    39 	.globl	_Atari_C2pConvert
    40 
    41 	.data
    42 
    43 	.even
    44 	.comm	_Atari_C2pInit,4
    45 	.comm	_Atari_C2pConvert,4
    46 
    47 /* ------------	Conversion Table C2P ------------ */
    48 
    49 	.globl	_Atari_table_c2p
    50 
    51 	.data
    52 
    53 	.comm	_Atari_table_c2p,2048
    54 
    55 /* ------------	Init table C2P, 8 bits ------------ */
    56 
    57 	.globl	_Atari_C2pInit8
    58 
    59 	.text
    60 _Atari_C2pInit8:
    61 	movel	d2,sp@-
    62 
    63 	lea	_Atari_table_c2p,a0
    64 	movew	#255,d0
    65 c2p_initbcl:
    66 #if defined (__M68020__)
    67 	lea	a0@(0,d0:w:8),a1
    68 #else
    69 	movew	d0,d2
    70 	lslw	#3,d2
    71 	lea	a0@(0,d2:w),a1
    72 #endif
    73 	moveq	#7,d1
    74 c2p_initbyte:
    75 	btst	d1,d0
    76 	sne	d2
    77 	negw	d2
    78 	moveb	d2,a1@(0,d1:w)
    79 
    80 	dbra	d1,c2p_initbyte
    81 
    82 	dbra	d0,c2p_initbcl
    83 
    84 	movel	sp@+,d2
    85 	rts
    86 
    87 /* ------------	Conversion C2P, 8 bits ------------ */
    88 
    89 	.globl	_Atari_C2pConvert8
    90 
    91 	.text
    92 _Atari_C2pConvert8:
    93 	movel	sp@(4),c2p_source
    94 	movel	sp@(8),c2p_dest
    95 	movel	sp@(12),c2p_width
    96 	movel	sp@(16),c2p_height
    97 	movel	sp@(20),c2p_dblligne
    98 	movel	sp@(24),c2p_srcpitch
    99 	movel	sp@(28),c2p_dstpitch
   100 
   101 	moveml	d2-d7/a2-a6,sp@-
   102 
   103 	movel	c2p_source,a0
   104 	movel	c2p_dest,a1
   105 	lea	_Atari_table_c2p,a2
   106 	movel	#0x000f0001,d3
   107 #if defined(__M68020__)
   108 	moveq	#0,d0
   109 #endif
   110 	
   111 	movel	c2p_height,d7
   112 	subql	#1,d7
   113 c2p8_bcly:
   114 	movel	a0,a4	| Save start address of source
   115 	movel	a1,a5	| Save start address of dest
   116 
   117 	| Conversion
   118                  
   119 	movel	c2p_width,d6
   120 	lsrw	#4,d6
   121 	subql	#1,d6
   122 c2p8_bclx:
   123 	| Octets 0-7
   124 	
   125 	moveq	#0,d1
   126 	moveq	#0,d2
   127 	moveq	#7,d5
   128 c2p8_bcl07:
   129 #if defined(__M68020__)
   130 	moveb	a0@+,d0
   131 	lea	a2@(0,d0:w:8),a3
   132 #else
   133 	moveq	#0,d0
   134 	moveb	a0@+,d0
   135 	lslw	#3,d0
   136 	lea	a2@(0,d0:w),a3
   137 #endif
   138 	lsll	#1,d1
   139 	lsll	#1,d2
   140 	orl	a3@+,d1
   141 	orl	a3@,d2
   142 	dbra	d5,c2p8_bcl07
   143 
   144 	movepl	d1,a1@(0)
   145 	movepl	d2,a1@(8)
   146 	addw	d3,a1
   147 	swap	d3
   148 	
   149 	| Octets 8-15
   150 
   151 	moveq	#0,d1
   152 	moveq	#0,d2
   153 	moveq	#7,d5
   154 c2p8_bcl815:
   155 #if defined(__M68020__)
   156 	moveb	a0@+,d0
   157 	lea	a2@(0,d0:w:8),a3
   158 #else
   159 	moveq	#0,d0
   160 	moveb	a0@+,d0
   161 	lslw	#3,d0
   162 	lea	a2@(0,d0:w),a3
   163 #endif
   164 	lsll	#1,d1
   165 	lsll	#1,d2
   166 	orl	a3@+,d1
   167 	orl	a3@,d2
   168 	dbra	d5,c2p8_bcl815
   169 
   170 	movepl	d1,a1@(0)
   171 	movepl	d2,a1@(8)
   172 	addw	d3,a1
   173 	swap	d3
   174 
   175 	dbra	d6,c2p8_bclx
   176 
   177 	| Double line ?
   178 
   179 	tstl	c2p_dblligne
   180 	beq	c2p8_nodblligne
   181 
   182 	movel	a5,a6			| src line
   183 	movel	a5,a1			| dest line
   184 	addl	c2p_dstpitch,a1
   185 
   186 	movel	c2p_width,d6
   187 	lsrw	#2,d6
   188 	subql	#1,d6
   189 c2p8_copydbl:
   190 	movel	a6@+,a1@+
   191 	dbra	d6,c2p8_copydbl
   192 
   193 	addl	c2p_dstpitch,a5
   194 c2p8_nodblligne:
   195 
   196 	| Next line
   197 
   198 	movel	a4,a0		
   199 	addl	c2p_srcpitch,a0
   200 	movel	a5,a1
   201 	addl	c2p_dstpitch,a1
   202 
   203 	dbra	d7,c2p8_bcly
   204 
   205 	moveml	sp@+,d2-d7/a2-a6
   206 	rts
   207 
   208 /* ------------	Init table C2P, 4 bits ------------ */
   209 
   210 	.globl	_Atari_C2pInit4
   211 
   212 	.text
   213 _Atari_C2pInit4:
   214 	/* Nothing to do */
   215 	/* work is done in convert_c2p_pal */
   216 	rts
   217 
   218 /* ------------	Conversion C2P, 4 bits ------------ */
   219 
   220 	.globl	_Atari_C2pConvert4
   221 
   222 	.text
   223 _Atari_C2pConvert4:
   224 	movel	sp@(4),c2p_source
   225 	movel	sp@(8),c2p_dest
   226 	movel	sp@(12),c2p_width
   227 	movel	sp@(16),c2p_height
   228 	movel	sp@(20),c2p_dblligne
   229 	movel	sp@(24),c2p_srcpitch
   230 	movel	sp@(28),c2p_dstpitch
   231 
   232 	moveml	d2-d7/a2-a6,sp@-
   233 
   234 	movel	c2p_source,a0
   235 	movel	c2p_dest,a1
   236 	lea	_Atari_table_c2p,a2
   237 	movel	#0x00070001,d3
   238 #if defined(__M68020__)
   239 	moveq	#0,d0
   240 #endif
   241 	
   242 	movel	c2p_height,d7
   243 	subql	#1,d7
   244 c2p4_bcly:
   245 	movel	a0,a4	| Save start address of source
   246 	movel	a1,a5	| Save start address of dest
   247 
   248 	| Conversion
   249                  			
   250 	movel	c2p_width,d6
   251 	lsrw	#4,d6
   252 	subql	#1,d6
   253 c2p4_bclx:
   254 	| Octets 0-7
   255 	
   256 	moveq	#0,d1
   257 	moveq	#7,d5
   258 c2p4_bcl07:
   259 #if defined(__M68020__)
   260 	moveb	a0@+,d0
   261 	lea	a2@(0,d0:w:4),a3
   262 #else
   263 	moveq	#0,d0
   264 	moveb	a0@+,d0
   265 	lslw	#2,d0
   266 	lea	a2@(0,d0:w),a3
   267 #endif
   268 	lsll	#1,d1
   269 	orl	a3@,d1
   270 	dbra	d5,c2p4_bcl07
   271 
   272 	movepl	d1,a1@(0)
   273 	addw	d3,a1
   274 	swap	d3
   275 	
   276 	| Octets 8-15
   277 
   278 	moveq	#0,d1
   279 	moveq	#7,d5
   280 c2p4_bcl815:
   281 #if defined(__M68020__)
   282 	moveb	a0@+,d0
   283 	lea	a2@(0,d0:w:4),a3
   284 #else
   285 	moveq	#0,d0
   286 	moveb	a0@+,d0
   287 	lslw	#2,d0
   288 	lea	a2@(0,d0:w),a3
   289 #endif
   290 	lsll	#1,d1
   291 	orl	a3@,d1
   292 	dbra	d5,c2p4_bcl815
   293 
   294 	movepl	d1,a1@(0)
   295 	addw	d3,a1
   296 	swap	d3
   297 
   298 	dbra	d6,c2p4_bclx
   299 
   300 	| Double line ?
   301 
   302 	tstl	c2p_dblligne
   303 	beq	c2p4_nodblligne
   304 
   305 	movel	a5,a6			| src line
   306 	movel	a5,a1			| dest line
   307 	addl	c2p_dstpitch,a1
   308 
   309 	movel	c2p_width,d6
   310 	lsrw	#3,d6
   311 	subql	#1,d6
   312 c2p4_copydbl:
   313 	movel	a6@+,a1@+
   314 	dbra	d6,c2p4_copydbl
   315 
   316 	addl	c2p_dstpitch,a5
   317 c2p4_nodblligne:
   318 
   319 	| Next line
   320 
   321 	movel	a4,a0		
   322 	addl	c2p_srcpitch,a0
   323 	movel	a5,a1
   324 	addl	c2p_dstpitch,a1
   325 
   326 	dbra	d7,c2p4_bcly
   327 
   328 	moveml	sp@+,d2-d7/a2-a6
   329 	rts
   330 
   331 * ------------	Conversion of a light palette in 4 bits ------------ */
   332 
   333 	.globl	_Atari_C2pConvert4_pal
   334 
   335 	.text
   336 _Atari_C2pConvert4_pal:
   337 	/* a0 is a 256-word light palette */
   338 	movel	sp@(4),a0
   339 
   340 	moveml	d2-d3,sp@-
   341 
   342 	lea	_Atari_table_c2p,a1
   343 	movew	#255,d3
   344 c2p_pal_initbcl:
   345 	movew	a0@+,d0
   346 	lsrw	#4,d0
   347 	and	#15,d0
   348 
   349 	moveq	#3,d1
   350 c2p_pal_initbyte:
   351 	btst	d1,d0
   352 	sne	d2
   353 	negw	d2
   354 	moveb	d2,a1@(0,d1:w)
   355 
   356 	dbra	d1,c2p_pal_initbyte
   357 
   358 	addql	#4,a1
   359 	dbra	d3,c2p_pal_initbcl
   360 
   361 	moveml	sp@+,d2-d3
   362 
   363 	rts
   364 
   365 /* ------------	Buffers ------------ */
   366 
   367 	.data
   368 
   369 	.even
   370 	.comm	c2p_source,4
   371 	.comm	c2p_dest,4
   372 	.comm	c2p_width,4
   373 	.comm	c2p_height,4
   374 	.comm	c2p_dblligne,4
   375 	.comm	c2p_srcpitch,4
   376 	.comm	c2p_dstpitch,4
   377