include ../consts/offsets include ../consts/map include ../consts/sprites ; /* Return the sprite id and rotation for the given map coordinates ; Inputs: ; r1: x map coord ; r2: y map coord ; Outputs: ; r12: sprite rotation ; r13: sprite id ; Locals: ; r3: tile id ; r4: map offset ; r5: counter ; r6: left tile id ; r7: up tile id ; r8: right tile id ; r9: down tile id ; */ pub sprite_rotation.get_sprite_id_and_rotation: push r1 push r2 push r3 push r4 push r5 push r6 push r7 push r8 push r9 add r4, r1, map mov r5, 0 get_sprite_id_and_rotation_map_row_loop: cmp r5, r2 je get_sprite_id_and_rotation_map_row_loop_end add r4, r4, map.width add r5, r5, 1 jmp get_sprite_id_and_rotation_map_row_loop get_sprite_id_and_rotation_map_row_loop_end: mov r12, sprites.rotation_0 ; default rotation load_8 r3, [r4] lsl r3, r3, 3 ; 2*instruction_size = *8 = <<3 add r3, r3, get_sprite_id_and_rotation_jump_table jmp r3 get_sprite_id_and_rotation_jump_table: ; tile_empty mov r13, sprites.empty jmp get_sprite_id_and_rotation_return ; tiles_wall jmp get_sprite_id_and_rotation_wall nop ; tile_coin mov r13, sprites.coin jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_wall: mov r6, 0 mov r7, 0 mov r8, 0 mov r9, 0 get_sprite_id_and_rotation_cmp_left: cmp r1, 0 je get_sprite_id_and_rotation_cmp_up sub r4, r4, 1 load_8 r6, [r4] add r4, r4, 1 get_sprite_id_and_rotation_cmp_up: cmp r2, 0 je get_sprite_id_and_rotation_cmp_right sub r4, r4, map.width load_8 r7, [r4] add r4, r4, map.width get_sprite_id_and_rotation_cmp_right: cmp r1, map.max_x je get_sprite_id_and_rotation_cmp_down add r4, r4, 1 load_8 r8, [r4] sub r4, r4, 1 get_sprite_id_and_rotation_cmp_down: cmp r2, map.max_y je get_sprite_id_and_rotation_check_connections add r4, r4, map.width load_8 r9, [r4] sub r4, r4, map.width get_sprite_id_and_rotation_check_connections: get_sprite_id_and_rotation_straight_0: cmp r7, map.tiles.wall jne get_sprite_id_and_rotation_straight_90 cmp r9, map.tiles.wall jne get_sprite_id_and_rotation_straight_90 mov r12, sprites.rotation_0 mov r13, sprites.wall_straight jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_straight_90: cmp r6, map.tiles.wall jne get_sprite_id_and_rotation_corner_0 cmp r8, map.tiles.wall jne get_sprite_id_and_rotation_corner_0 mov r12, sprites.rotation_90 mov r13, sprites.wall_straight jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_corner_0: cmp r6, map.tiles.wall jne get_sprite_id_and_rotation_corner_180 cmp r9, map.tiles.wall jne get_sprite_id_and_rotation_corner_90 mov r12,sprites.rotation_0 mov r13, sprites.wall_corner jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_corner_90: cmp r7, map.tiles.wall jne get_sprite_id_and_rotation_end_90 mov r12,sprites.rotation_90 mov r13, sprites.wall_corner jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_corner_180: cmp r8, map.tiles.wall jne get_sprite_id_and_rotation_end_0 cmp r7, map.tiles.wall jne get_sprite_id_and_rotation_corner_270 mov r12,sprites.rotation_180 mov r13, sprites.wall_corner jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_corner_270: cmp r9, map.tiles.wall jne get_sprite_id_and_rotation_end_270 mov r12,sprites.rotation_270 mov r13, sprites.wall_corner jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_end_0: cmp r9, map.tiles.wall jne get_sprite_id_and_rotation_end_180 mov r12,sprites.rotation_0 mov r13, sprites.wall_end jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_end_90: mov r12,sprites.rotation_90 mov r13, sprites.wall_end jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_end_180: mov r12,sprites.rotation_180 mov r13, sprites.wall_end jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_end_270: mov r12,sprites.rotation_270 mov r13, sprites.wall_end ;jmp get_sprite_id_and_rotation_return get_sprite_id_and_rotation_return: pop r9 pop r8 pop r7 pop r6 pop r5 pop r4 pop r3 pop r2 pop r1 ret