-
Notifications
You must be signed in to change notification settings - Fork 0
/
passable.s
106 lines (86 loc) · 2.29 KB
/
passable.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Dragon - Passability check
* Copyright (C) 2016 Sandor Zsuga (Jubatian)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "m74cfg.h"
#include <avr/io.h>
; (Needed only for register names for X, Y and Z)
.section .text
/*
** Checks if a given pixel location on the map is passable.
** Returns nonzero if it is so. Depends on level.
**
** Inputs:
** r25:r24: x
** r23:r22: y
**
** Outputs:
** r25:r24: 1 or 0
*/
.global passable
passable:
; Note: dimension checks are unnecessary as level_gettile will handle
; these proper (inpassable for leaving the map on X, passable for
; leaving the map on Y, allowing jumping up into parallax clouds).
; Prepare tile & pixel offsets
mov XL, r24 ; Will hold X pixel offset
mov XH, r22 ; Will hold Y pixel offset
lsr r25
ror r24
lsr r25
ror r24
lsr r25
ror r24 ; r25:r24: X tile offset
lsr r23
ror r22
lsr r23
ror r22
lsr r23
ror r22 ; r23:r22: Y tile offset
; Get passability block
call level_gettile
mov ZL, r24
ldi ZH, hi8(RES_TILEFLG_OFF)
lpm r24, Z
sbrc XH, 2
rjmp .+4
lsr r24
lsr r24 ; Upper half is on bits 2-3
andi r24, 0x03
; Check passabilities
cpi r24, 1
brne .+6 ; 1: Passable
ispr1:
ldi r25, 0
ldi r24, 1
ret
brcc .+6 ; 0: Impassable
ispr0:
ldi r25, 0
ldi r24, 0
ret
; Slopes. Prepare pixel coordinates
andi XH, 0x03
lsr XL
andi XL, 0x03
; Check passabilities
sbrc r24, 0
rjmp .+4
neg XL
subi XL, 0xFD ; XL = 3 - XL (X pixel offset inversion)
cp XL, XH
brcc ispr1
rjmp ispr0