alot of code changed; first try to move level loader out of C engine; not working yet
[awish.git] / asm / loaders / avishlevel.awa
blob4bb37cd2bff032c53f305859ab8494ba24257c71
1 /*
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.
6  *
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.
11  *
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/>.
14  */
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
19 arg: .level_idx
20 locals: .pos, .x, .y, .item_count
21 locals: .fframe, .lframe, .frame, .animated, .type, .tid
22   rst FRST_OPEN_LEVEL_FILE, [.level_idx]
23   ; set level name
24   rst FRST_GET_LEVEL_FILE_BYTE, 0  ; name length
25   rst FRST_SET_LEVEL_NAME, -2, [rst_result]
26   ; set level size
27   rst FRST_SET_LEVEL_SIZE, 44, 41  ; standard Avish level size
28   ; set backpic
29   rst FRST_GET_LEVEL_FILE_BYTE, 25
30   set [level_backpic], [rst_result]
31   ; set prof position
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]
41   ;
42   set [.pos], 31
43   ; load background tiles
44   set [.x], 1
45 .backtiles_col_loop:
46   set [.y], 0
47 .backtiles_row_loop:
48   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
49   add [.pos], 1
50   msb [.x], [.y], [rst_result]
51   add [.y], 1
52   jlt .backtiles_row_loop, [.y], [map_height]
53   add [.x], 1
54   jlt .backtiles_col_loop, [.y], [map_width]
55   ; load foreground tiles
56   set [.x], 1
57 .foretiles_col_loop:
58   set [.y], 0
59 .foretiles_row_loop:
60   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
61   add [.pos], 1
62   msb [.x], [.y], [rst_result]
63   add [.y], 1
64   jlt .foretiles_row_loop, [.y], [map_height]
65   add [.pos], 3  ; skip 3 unknown bytes
66   add [.x], 1
67   jlt .foretiles_col_loop, [.y], [map_width]
68   ; load items
69   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
70   add [.pos], 1
71   add [rst_result], 1, [.item_count]
72 .item_loop:
73   ; x
74   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
75   add [.pos], 1
76   set [.x], [rst_result]
77   ; y
78   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
79   add [.pos], 1
80   set [.y], [rst_result]
81   ; fframe
82   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
83   add [.pos], 1
84   set [.fframe], [rst_result]
85   ; lframe
86   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
87   add [.pos], 1
88   set [.lframe], [rst_result]
89   ; frame
90   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
91   add [.pos], 1
92   set [.frame], [rst_result]
93   ; animated
94   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
95   add [.pos], 1
96   set [.animated], [rst_result]
97   jne .item_anim_nofix, [.animated], 0
98   set [.frame], [.fframe]
99 .item_anim_nofix:
100   ; skip 0xff
101   add [.pos], 1
102   ;
103   ; skip 4 unknown bytes
104   add [.pos], 4
105   ; item type
106   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
107   add [.pos], 1
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
118   sub [.pos], 6
119   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
120   add [.pos], 6
121   set aframe, [rst_result], [.tid]
122   set spr_num, [rst_result], [.tid]
123 .no_fix_aframe:
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]
128   ;
129   sub [.item_count], 1
130   jgt .item_loop, [.item_count], 0
131   ;
132   ret
133 endp: avish_level_loader