hi all, I'm doing it in a not elegant way, for sure, and maybe using too much cpu...
here's the problem:
I have on hl a coordinate in a 16bit range
and in the accumulator I have an offset that could be positive or negative.
I need often to adjust coordinates subtracting the offset value (subtracting a positive offset the coordinate decreases and subtracting a negative value the coordinate increases)
This is to determinate the respawn location in my Turrican code.
Here's how I'm doing it:
ld d,a ;a is 0 from previous code, so it is like ld d,0 ld hl,(map_pos) ;actual position inside the tilemap ld (restart_point),hl ;store it ld hl,(x_coord) ;actual x coordinate ld a,(dx) ;actual x offset. dx (and dy) are used on scrolling routine to determine if we are moving left or right (or up or down) relatively to the actual tile (tiles are 4x4 chars, so dx and dy values vary from 0 to 3 and are the values you can see in Turrican videos) and a jp m,dx_negative_fix ;check if dx has negative value ld e,a ;copy dx value in e (so we have de= dx sbc hl,de ;subtract dx from x coordinate (so when respawning to actual tile we can restore also x position to starting char without messing relation between map and coordinates set_restart_x: ld (restart_x),hl ;store obtained value to be used in case of respawn ld hl,(y_coord) ld a,(dy) and a jp m,dy_negative_fix ld e,a sbc hl,de set_restart_y: ld (restart_y),hl ret dx_negative_fix: inc hl ;subtracting a negative value is like adding its positive value so increase hl inc a ;using dx as counter increasing it until 0 jp nz,dx_negative_fix jp set_restart_x dy_negative_fix: inc hl inc a jp nz,dy_negative_fix jp set_restart_y
Login sesión o register para postear comentarios