**************************************************************************** **************************************************************************** ** ** Platinum Edition for TI-89 (Sprite Plotting Routines) ** ** This software is in the public domain. There is no warranty. ** ** by Patrick Davidson (pad@calc.org, http://pad.calc.org/) ** ** Last updated September 27, 2001 ** **************************************************************************** **************************************************************************** ******************************************** GENERIC SPRITE-PLOTTER * * This routine draws a sprite to the screen buffer at (D0, D1). * For Xor_Sprite_D2, D2 is the sprite handle * For Xor_Sprite, A0 should point to the sprite * This routine changes, A0 - A2, D0 - D4 * * Each sprite begins with a word specifying its height, minus one. It is * followed by one longword for each line of the image. The sprite image * starts at the 8th bit, and can be up to 17 pixels wide. * ******** clip_top: move.w d1,d2 ;D2 = - # of lines skipped add.w (a0)+,d1 ;D1 = # of lines to draw - 1 blt.s off_the_screen add.w d2,d2 add.w d2,d2 ;D2 = -4 * # of lines skipped sub.w d2,a0 ;A0 -> First used sprite data move.w d0,d2 and.w #15,d0 lsr.w #4,d2 add.w d2,d2 lea 0(a5,d2.w),a1 move.w d1,d2 bra.s clipped_vert Xor_Sprite_D2: lea image_table(pc),a0 add.w d2,a0 Xor_Sprite: tst.w (a0) blt Grayscale_Sprite sub.w #SCREEN_TOP,d1 ;D1 = # of lines from top to start blt.s clip_top move.w d1,d3 move.w d0,d2 and.w #15,d0 lsl.w #5,d1 lea 0(a5,d1.w),a1 lsr.w #4,d2 add.w d2,d2 add.w d2,a1 move.w (a0)+,d2 ;A0 -> Sprite data add.w d2,d3 sub.w #SCREEN_HEIGHT-1,d3 ;D3 = # lines past bottom ble.s clipped_vert sub.w d3,d2 blt.s off_the_screen clipped_vert: subq.w #8,d0 bgt.s xs_ShiftRight beq.s xs_alignedOK xs_ShiftLeft: neg.w d0 xs_ShiftLeft_: move.l (a0)+,d1 lsl.l d0,d1 or.l d1,(a1) or.l d1,SCREEN_SIZE(a1) lea 32(a1),a1 dbra d2,xs_ShiftLeft_ off_the_screen: rts xs_alignedOK: move.l (a0)+,d1 or.l d1,(a1) or.l d1,SCREEN_SIZE(a1) lea 32(a1),a1 dbra d2,xs_alignedOK rts xs_ShiftRight: move.l (a0)+,d1 lsr.l d0,d1 or.l d1,(a1) or.l d1,SCREEN_SIZE(a1) lea 32(a1),a1 dbra d2,xs_ShiftRight rts ;************************************** MASKING (D1,D2) over (A1) MASKDRAW MACRO move.l d1,d2 ; D2 = plane 0 data or.l d3,d2 ; D2 = plane data ORed not.l d2 ; D2 = unchanged pixel mask move.l d2,d5 ; D5 = unchanged pixel mask and.l (a1),d5 ; D5 = plane 0 masked or.l d1,d5 ; D5 = plane 0 masked and drawn ona move.l d5,(a1) ; save new plane 0 data and.l SCREEN_SIZE(a1),d2 ; D2 = plane 1 masked or.l d3,d2 ; D2 = plane 1 masked and drawn ona move.l d2,SCREEN_SIZE(a1) ; save new plane 1 data ENDM ;************************************** GRAYSCALE SPRITE ROUTINE Grayscale_Sprite: move.w (a0)+,d4 neg.w d4 ;D4 = height in lines - 1 move.w d4,d2 add.w d2,d2 add.w d2,d2 ;D2 = length of plane data - 4 lea 4(a0,d2.w),a2 ;A2 -> second image sub.w #SCREEN_TOP,d1 ;D1 = # of lines from top to start blt.s \clip_top move.w d1,d3 move.w d0,d2 ;D2 = X coordinate and.w #15,d0 ;D0 = low 4 bits of X coordinate lsl.w #5,d1 ;D1 = line's offset in buffer lea 0(a5,d1.w),a1 ;A1 -> start of line in buffer lsr.w #4,d2 ;D2 = word offset in line add.w d2,d2 ;D2 = byte offset in line add.w d2,a1 ;A1 -> long image drawn at add.w d4,d3 sub.w #SCREEN_HEIGHT-1,d3 ;D3 = # lines past bottom ble.s \clipped_vert sub.w d3,d4 blt.s \rts \clipped_vert: subq.w #8,d0 bgt.s \right beq.s \cent \left: neg.w d0 \leftloop: move.l (a0)+,d1 move.l (a2)+,d3 lsl.l d0,d1 lsl.l d0,d3 MASKDRAW lea 32(a1),a1 dbra d4,\leftloop \rts: rts \clip_top: move.w d1,d2 ;D2 = - # of lines skipped add.w d4,d1 ;D1 = # of lines to draw - 1 blt.s \rts add.w d2,d2 add.w d2,d2 ;D2 = -4 * # of lines skipped sub.w d2,a0 ;A0 -> First used sprite data sub.w d2,a2 move.w d0,d2 and.w #15,d0 lsr.w #4,d2 add.w d2,d2 lea 0(a5,d2.w),a1 move.w d1,d4 bra.s \clipped_vert \cent: move.l (a0)+,d1 move.l (a2)+,d3 MASKDRAW lea 32(a1),a1 dbra d4,\cent rts \right: move.l (a0)+,d1 move.l (a2)+,d3 lsr.l d0,d1 lsr.l d0,d3 MASKDRAW lea 32(a1),a1 dbra d4,\right rts