2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation, either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 /* loader for the original Avish level format */
16 /* warning: no checks are made, so don't try to load invalid levels! */
18 proc: avish_level_loader
20 locals: .pos, .x, .y, .item_count
21 locals: .fframe, .lframe, .frame, .animated, .type, .tid
22 rst FRST_OPEN_LEVEL_FILE, [.level_idx]
24 rst FRST_GET_LEVEL_FILE_BYTE, 0 ; name length
25 rst FRST_SET_LEVEL_NAME, -2, [rst_result]
27 rst FRST_SET_LEVEL_SIZE, 44, 41 ; standard Avish level size
29 rst FRST_GET_LEVEL_FILE_BYTE, 25
30 set [level_backpic], [rst_result]
32 rst FRST_GET_LEVEL_FILE_BYTE, 27
33 set [pos_x], [rst_result]
34 rst FRST_GET_LEVEL_FILE_BYTE, 28
35 set [pos_y], [rst_result]
36 ; set viewport position
37 rst FRST_GET_LEVEL_FILE_BYTE, 29
38 set [pos_x], [rst_result]
39 rst FRST_GET_LEVEL_FILE_BYTE, 30
40 set [pos_y], [rst_result]
43 ; load background tiles
48 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
50 msb [.x], [.y], [rst_result]
52 jlt .backtiles_row_loop, [.y], [map_height]
54 jlt .backtiles_col_loop, [.y], [map_width]
55 ; load foreground tiles
60 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
62 msb [.x], [.y], [rst_result]
64 jlt .foretiles_row_loop, [.y], [map_height]
65 add [.pos], 3 ; skip 3 unknown bytes
67 jlt .foretiles_col_loop, [.y], [map_width]
69 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
71 add [rst_result], 1, [.item_count]
74 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
76 set [.x], [rst_result]
78 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
80 set [.y], [rst_result]
82 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
84 set [.fframe], [rst_result]
86 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
88 set [.lframe], [rst_result]
90 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
92 set [.frame], [rst_result]
94 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
96 set [.animated], [rst_result]
97 jne .item_anim_nofix, [.animated], 0
98 set [.frame], [.fframe]
103 ; skip 4 unknown bytes
106 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
108 set [.type], [rst_result]
109 ; spawn and initialize item thread
110 new entry_item, [.tid]
111 set item_id, [.type], [.tid]
112 set animated, [.animated], [.tid]
113 set afirst_frame, [.fframe], [.tid]
114 set alast_frame, [.lframe], [.tid]
115 set aframe, [.frame], [.tid]
116 set spr_num, [.frame], [.tid]
117 jne .no_fix_aframe, [.type], ITEM_HARRY
119 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
121 set aframe, [rst_result], [.tid]
122 set spr_num, [rst_result], [.tid]
124 set pos_x, [.x], [.tid]
125 set pos_y, [.y], [.tid]
126 set spr_bank, BANK_ITEMS, [.tid]
127 set spr_dir, DIR_LEFT, [.tid]
130 jgt .item_loop, [.item_count], 0
133 endp: avish_level_loader