1; 2; Sprite Rendering Routine 3; original code by Patrick Davidson (TI 85) 4; modified by Stefano Bodrato - nov 2010 5; 6; MicroBEE high resolution version, 512x256 dots variant (2016) 7; 8; 9; $Id: w_putsprite_512.asm,v 1.1 2016-11-25 14:45:01 stefano Exp $ 10; 11 12 SECTION smc_clib 13 PUBLIC putsprite 14 PUBLIC _putsprite 15 EXTERN w_pixeladdress 16 17 EXTERN swapgfxbk 18 EXTERN swapgfxbk1 19 20 INCLUDE "graphics/grafix.inc" 21 22; __gfx_coords: d,e (vert-horz) 23; sprite: (ix) 24 25.putsprite 26._putsprite 27 push ix ;save callers 28 ld hl,4 29 add hl,sp 30 ld e,(hl) 31 inc hl 32 ld d,(hl) ; sprite address 33 push de 34 pop ix 35 36 inc hl 37 ld e,(hl) 38 inc hl 39 ld d,(hl) 40 inc hl 41 ld c,(hl) 42 inc hl 43 ld b,(hl) ; x and y __gfx_coords 44 45 inc hl 46 ld a,(hl) ; and/or/xor mode 47 ld (ortype+1),a ; Self modifying code 48 ld (ortype2+1),a ; Self modifying code 49 50 inc hl 51 ld a,(hl) 52 ld (ortype),a ; Self modifying code 53 ld (ortype2),a ; Self modifying code 54 55 call swapgfxbk 56 ; @@@@@@@@@@@@ 57 ld h,b 58 ld l,c 59 ld (oldx),hl 60 ld (cury),de 61 call w_pixeladdress 62 ; ------ 63 ;ld a,(hl) 64 ; @@@@@@@@@@@@ 65 ld c,a 66 ld hl,offsets_table 67 ld c,a 68 ld b,0 69 add hl,bc 70 ld a,(hl) 71 ld (wsmc1+1),a 72 ld (wsmc2+1),a 73 ld (_smc1+1),a 74 75 ld h,d 76 ld l,e ; display location from pixeladdress 77 78 ld a,(ix+0) 79 cp 9 80 jp nc,putspritew 81 82 ld d,a 83 ld b,(ix+1) 84._oloop push bc ;Save # of rows 85 ld b,d ;Load width 86 ld c,(ix+2) ;Load one line of image 87 inc ix 88._smc1 ld a,1 ;Load pixel mask 89._iloop sla c ;Test leftmost pixel 90 jp nc,_noplot ;See if a plot is needed 91 ld e,a 92.ortype 93 nop ; changed into nop / cpl 94 nop ; changed into and/or/xor (hl) 95 ld (hl),a 96 ld a,e 97._noplot rrca 98 99 jp nc,_notedge ;Test if edge of byte reached 100 101 ;@@@@@@@@@@ 102 ;Go to next byte 103 ;@@@@@@@@@@ 104 ex af,af 105 ld a,16 106 add l 107 ld l,a 108 jp nc,gonehi 109 inc h 110.gonehi 111 ex af,af 112 ;@@@@@@@@@@ 113 114._notedge djnz _iloop 115 116 push de 117 ;@@@@@@@@@@ 118 ;Go to next line 119 ;@@@@@@@@@@ 120 ld hl,(oldx) 121 ld de,(cury) 122 inc de 123 ld (cury),de 124 call w_pixeladdress 125 ;ld h,d 126 ;ld l,e 127 ;@@@@@@@@@@ 128 pop de 129 pop bc ;Restore data 130 djnz _oloop 131 pop ix ;restore callers 132 jp swapgfxbk1 133 134 135.putspritew 136 ld d,a 137 ld b,(ix+1) 138.woloop push bc ;Save # of rows 139 ld b,d ;Load width 140 ld c,(ix+2) ;Load one line of image 141 inc ix 142.wsmc1 ld a,1 ;Load pixel mask 143.wiloop sla c ;Test leftmost pixel 144 jp nc,wnoplot ;See if a plot is needed 145 ld e,a 146.ortype2 147 nop ; changed into nop / cpl 148 nop ; changed into and/or/xor (hl) 149 ld (hl),a 150 ld a,e 151.wnoplot rrca 152 jp nc,wnotedge ;Test if edge of byte reached 153 154 ;@@@@@@@@@@ 155 ;Go to next byte 156 ;@@@@@@@@@@ 157 ex af,af 158 ld a,16 159 add l 160 ld l,a 161 jp nc,wgonehi 162 inc h 163.wgonehi 164 ex af,af 165 ;@@@@@@@@@@ 166 167.wnotedge 168.wsmc2 cp 1 169 jp z,wover_1 170 171 djnz wiloop 172 173 push de 174 ;@@@@@@@@@@ 175 ;Go to next line 176 ;@@@@@@@@@@ 177 ld hl,(oldx) 178 ld de,(cury) 179 inc de 180 ld (cury),de 181 call w_pixeladdress 182 ;ld h,d 183 ;ld l,e 184 ;@@@@@@@@@@ 185 pop de 186 187 pop bc ;Restore data 188 djnz woloop 189 pop ix ;restore callers 190 jp swapgfxbk1 191 192 193.wover_1 ld c,(ix+2) 194 inc ix 195 djnz wiloop 196 dec ix 197 198 push de 199 ;@@@@@@@@@@ 200 ;Go to next line 201 ;@@@@@@@@@@ 202 ld hl,(oldx) 203 ld de,(cury) 204 inc de 205 ld (cury),de 206 call w_pixeladdress 207 ;ld h,d 208 ;ld l,e 209 ;@@@@@@@@@@ 210 pop de 211 212 pop bc 213 djnz woloop 214 pop ix ;restore callers 215 jp swapgfxbk1 216 217 SECTION rodata_clib 218.offsets_table 219 defb 1,2,4,8,16,32,64,128 220 SECTION bss_clib 221.oldx 222 defw 0 223.cury 224 defw 0 225 226 227