This code renders in the SAT a number of objects in a list in RAM
Basically if the object is active and its X,Y (16 bit coordinates in the level map) fall in the screen window (256x128 from Y=64) the object is copied in the SAT in RAM using one or two sprites (according to its shape).
The screen window goes tram -32 to 255 on X and from -16 to 127 on Y, so EC bit is fully managed.
Do you have suggestion to make it way faster ?
_plot_enemy: ld iy,ram_sat ld ix,enemies ld bc,max_enem*256+0 .npc_loop1: bit 0,(ix+enemy_data.status) jp z,.next ld l,(ix+enemy_data.y) ld h,(ix+enemy_data.y+1) ld de,16 add hl,de ld de,(ymap) and a sbc hl,de ; hl = enemy.y + 16 - ymap jp c,.next ; enemy.y - ymap < -16 ld de,128+16 sbc hl,de ; enemy.y - ymap + 16 - 128 - 16 >= 0 jp nc,.next ; enemy.y - ymap >= 128 ld de,128+64 add hl,de ld a,l ex af,af ld l,(ix+enemy_data.x+0) ld h,(ix+enemy_data.x+1) ld de,32 add hl,de ld de,(xmap) and a sbc hl,de ; hl = enemy.x + 32 - xmap < 0 jp c,.next ; hl <0 <==> dx = enemy.x - xmap < -32 ld de,32 sbc hl,de ; enemy.x + 32 - xmap - 32 <0 ld a,(ix+enemy_data.color) jp nc,.noec ; -32255 ld a,(ix+enemy_data.frame) cp 16*4 ; hard coded in the SPT jp nc,.two_layers .one_layer: ld (iy+2),a ; write shape ld (iy+1),l ; write X ex af,af ; write Y ld (iy+0),a ld (iy+3),e ; write colour inc c ld de,4 add iy,de ; jp .next .next: ld de,enemy_data add ix,de djnz .npc_loop1 ld a,c ld (visible_sprts),a ret .two_layers: ld (iy+2),a ; write shape add a,8 ld (iy+2+4),a ; second layer shape ld (iy+1),l ; write X ld (iy+1+4),l ex af,af ; write Y ld (iy+0),a ld (iy+0+4),a ld (iy+3),e ; write colour ld a,e and 0xF0 or 1 ; second layer colour ld (iy+3+4),a [2] inc c ld de,8 add iy,de jp .next
Login or register to post comments