-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelcor.h
76 lines (61 loc) · 2.28 KB
/
levelcor.h
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
/*
* Dragon - Level (map) coordinate encoding & decoding
* Copyright (C) 2017 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/>.
*/
/*
** Encodes and decodes level (map) coordinates.
**
** The maximal possible dimension of a map on an axis is 8192 pixels (256 L0
** blocks). The same time assuming allowing at most 2048 L0 blocks (requiring
** 256 bytes of replacement map RAM), 2M pixels is the maximal map area. This
** requires 21 coordinate bits, which allows the coordinates to be represented
** in 3 bytes (instead of 4 which would be used if they were uint16s).
**
** Using the map height (level_h) this performs such encoding.
**
** The encoding is fixed, supporting 8192 x 2048 pixels. The reason is that
** tall maps aren't typical (in the end I didn't need such), so there was no
** point in supporting them. The maximal height is limited to 28 L1 blocks
** (due to 256 pixels top / bottom clearance).
*/
#ifndef LEVELCOR_H
#define LEVELCOR_H
#include "types.h"
/*
** Encodes coordinates into dst (3 bytes).
** For assembly calls, ZL, r1:r0 and r19:r18 are not clobbered.
** For assembly calls, XH:XL upon return is set dst + 3.
*/
void levelcor_encode(uint8* dst, uint16 x, uint16 y);
/*
** Decodes coordinates from src (3 bytes).
** For assembly calls, r1:r0 and r19:r18 are not clobbered.
** For assembly calls, XH:XL upon return is set src + 3.
*/
void levelcor_decode(uint8 const* src, uint16* x, uint16* y);
/*
** Note: For assembler uses, another routine is provided, producing results
** into registers instead of memory locations: levelcor_decode_asm.
**
** Inputs:
** XH:XL: src (3 bytes)
**
** Outputs:
** r23:r22: X
** r21:r20: Y
** XH:XL: src + 3
*/
#endif