**************************************************************************** **************************************************************************** ** ** Monster (Background rendering) ** ** Copyright 2002 by Patrick Davidson. This software may be freely ** modified and/or copied with no restrictions. There is no warranty. ** ** by Patrick Davidson (pad@calc.org, http://pad.calc.org/) ** ** Last updated March 6, 2002 ** **************************************************************************** **************************************************************************** Draw_Background: move.l a5,-(sp) lea (a5),a3 lea map(a5),a4 lea tiles0(pc),a2 move.w screenx(a5),d3 move.w d3,d2 lsr.w #4,d3 add.w d3,a4 and.w #15,d2 moveq #(WIDTH_BYTES/2)-1,d7 moveq #0,d6 btst #3,d2 bne.s \hi_draw tst.w d2 bne.s \low_loop_draw \loop_draw: moveq #BACKGROUND_WIDTH,d5 bsr Render_Background_Column_Shift0 addq.w #2,a3 addq.w #1,a4 dbra d7,\loop_draw move.l (sp)+,a5 rts \low_loop_draw: moveq #BACKGROUND_WIDTH,d5 bsr Render_Background_Column_ShiftLow addq.w #2,a3 addq.w #1,a4 dbra d7,\low_loop_draw move.l (sp)+,a5 rts \hi_draw: neg.w d2 and.w #15,d2 \hi_loop_draw: moveq #BACKGROUND_WIDTH,d5 bsr Render_Background_Column_ShiftHigh addq.w #2,a3 addq.w #1,a4 dbra d7,\hi_loop_draw move.l (sp)+,a5 rts ******************************************** MACROS FOR DRAWING * * The BDRAWER macro creates a routine for drawing a column of tiles. * * The routine's arguments are as follows: * * A4 -> The map (pointer to first entry in this column, entries are bytes) * A3 -> Pointer to this column in first bitplane * A2 -> Tile data (tiles must be 16x16 grayscale) * D5 = width (in bytes) of a column in the tile map * D2 = amount to shift * * This routine modifies A0, A1, A5, A6, D0, D1, D3, D4, D5. * The first argument to the macro is the label name of a tile routine, and * the second is 0 for a 16-bit aligned column, nonzero otherwise. * * Calling the label must draw 16 lines of the background in a 16-bit column. * Calling the label with L appended draws D0 + 1 lines of the background. * * The routine is responsible for drawing in the specific way needed by * this column routine (i.e. shifted left, shifted left, or center and * overwrite or overlay) depending on which part of the draw the routine is * used for. * * The routine receives a pointer to the tile graphics in A1 (and, if not * centered, the tile to the right in A5) and a pointer to the starting area * on the screen to draw in A0. It is expected to advance A0 to the line * past the end of where it draws, and to add D5 to A6. A1, A5, D0, D1, and * D4 may be destroyed. * ******** BDRAWER MACRO \draw_main_tiles: move.l a4,a6 move.l a3,a0 subq.w #1,d5 moveq #11,d3 \draw_main_tiles_loop: moveq #0,d1 move.b (a6)+,d1 ; get tile # IFD ti89 lsl.w #5,d1 ENDIF IFND ti89 mulu #40,d1 ENDIF lea 0(a2,d1.w),a1 ; A1 -> tile image IFNE \2 moveq #0,d1 move.b (a6),d1 ; get tile # IFD ti89 lsl.w #5,d1 ENDIF IFND ti89 mulu #40,d1 ENDIF lea 0(a2,d1.w),a5 ; A5 -> tile image ENDIF bsr \1 dbra d3,\draw_main_tiles_loop rts ENDM *************************************** ACTUAL COLUMN RENDERING Render_Background_Column_Shift0: ; overwrite, no shift BDRAWER RTS0,0 RTS0: moveq #TILE_HEIGHT-1,d0 RTS0L: move.w TILE_HEIGHT*2(a1),PLANE_SIZE(a0) ; copy second bitplane move.w (a1)+,(a0) ; copy first bitplane lea WIDTH_BYTES(a0),a0 dbra d0,RTS0L add.w d5,a6 rts Render_Background_Column_ShiftLow: ; overwrite, shift left D2 BDRAWER RTSL,1 RTSL: moveq #TILE_HEIGHT-1,d0 RTSLL: move.w TILE_HEIGHT*2(a5),d4 ; 12 swap d4 ; 4 move.w TILE_HEIGHT*2(a1),d4 ; 12 rol.l d2,d4 ; 8 + 2x move.w d4,PLANE_SIZE(a0) ; 12 move.w (a5)+,d4 ; 8 swap d4 ; 4 move.w (a1)+,d4 ; 8 rol.l d2,d4 ; 8 + 2y move.w d4,(a0) ; 8 lea WIDTH_BYTES(a0),a0 ; 8 dbra d0,RTSLL ; 10 add.w d5,a6 rts Render_Background_Column_ShiftHigh: ; overwrite, shift right D2 - 16 BDRAWER RTSR,1 RTSR: moveq #TILE_HEIGHT-1,d0 RTSRL: move.w TILE_HEIGHT*2(a1),d4 swap d4 move.w TILE_HEIGHT*2(a5),d4 lsr.l d2,d4 move.w d4,PLANE_SIZE(a0) move.w (a1)+,d4 swap d4 move.w (a5)+,d4 lsr.l d2,d4 move.w d4,(a0) lea WIDTH_BYTES(a0),a0 dbra d0,RTSRL add.w d5,a6 rts ******************************************** TILE DATA BACKGROUND_WIDTH equ 18 BACKGROUND_HEIGHT equ 12 tiles0: IFD ti89 INCLUDE tiles.i ENDIF IFND ti89 INCLUDE tiles92.i ENDIF