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 const: AVISH_MAP_WIDTH = 44
19 const: AVISH_MAP_HEIGHT = 41
21 proc: avish_level_loader
23 locals: .pos, .x, .y, .item_count
24 locals: .fframe, .lframe, .frame, .animated, .animspeed, .type, .tid
25 dbgprintstr "loading level #"
26 dbgprintnumnl [.level_idx]
28 rst FRST_OPEN_LEVEL_FILE, [.level_idx]
30 rst FRST_GET_LEVEL_FILE_BYTE, 0 ; name length
31 rst FRST_SET_LEVEL_NAME, -2, [rst_result]
33 rst FRST_SET_LEVEL_SIZE, 44, 41 ; standard Avish level size
35 rst FRST_GET_LEVEL_FILE_BYTE, 26
36 set [level_backpic], [rst_result]
38 rst FRST_GET_LEVEL_FILE_BYTE, 27
39 set [pos_x], [rst_result]
40 rst FRST_GET_LEVEL_FILE_BYTE, 28
41 set [pos_y], [rst_result]
42 ; set viewport position
43 rst FRST_GET_LEVEL_FILE_BYTE, 29
44 set [scr_x], [rst_result]
45 rst FRST_GET_LEVEL_FILE_BYTE, 30
46 sub [rst_result], 1, [scr_y]
49 ; load background tiles
54 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
56 msb [.x], [.y], [rst_result]
58 jlt .backtiles_row_loop, [.y], [map_height]
60 jlt .backtiles_col_loop, [.x], [map_width]
61 ; load foreground tiles
66 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
68 msf [.x], [.y], [rst_result]
70 jlt .foretiles_row_loop, [.y], [map_height]
71 add [.pos], 3 ; skip 3 unknown bytes
73 jlt .foretiles_col_loop, [.x], [map_width]
75 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
77 add 1, [rst_result], [.item_count]
81 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
83 set [.x], [rst_result]
85 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
87 set [.y], [rst_result]
89 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
91 set [.fframe], [rst_result]
93 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
95 set [.lframe], [rst_result]
97 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
99 set [.frame], [rst_result]
101 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
103 set [.animated], [rst_result]
105 jne .item_anim_nofix, [.animated], 0
106 set [.frame], [.fframe]
109 ;;; rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
110 ;;; jeq @@f, [rst_result], 255
111 ;;; rst FRST_DEBUG_ABORT
114 ; skip 1 unknown byte
117 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
118 ;mul ITEM_ANIM_DELAY, [rst_result], [.animspeed]
119 set [.animspeed], [rst_result]
122 ;;; rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
123 ;;; jeq @@f, [rst_result], 0
124 ;;; rst FRST_DEBUG_ABORT
128 ;;; rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
129 ;;; jeq @@f, [rst_result], 0
130 ;;; rst FRST_DEBUG_ABORT
134 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
136 set [.type], [rst_result]
138 ;;; rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
139 ;;; jeq @@f, [rst_result], 0
140 ;;; rst FRST_DEBUG_ABORT
143 ; spawn and initialize item thread
144 new entry_item, [.tid]
145 set item_id, [.type], [.tid]
146 set animated, [.animated], [.tid]
147 set animspeed, [.animspeed], [.tid]
148 set afirst_frame, [.fframe], [.tid]
149 set alast_frame, [.lframe], [.tid]
150 set aframe, [.frame], [.tid]
151 set spr_num, [.frame], [.tid]
152 jne .no_fix_aframe, [.type], ITEM_HARRY
154 rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
156 set aframe, [rst_result], [.tid]
157 ;set spr_num, [rst_result], [.tid]
159 set pos_x, [.x], [.tid]
160 set pos_y, [.y], [.tid]
161 set spr_bank, BANK_ITEMS, [.tid]
162 set spr_dir, DIR_LEFT, [.tid]
165 jgt .item_loop, [.item_count], 0
168 endp: avish_level_loader