asm: dbg macros; decoded one more level byte
[awish.git] / asm / loaders / avishlevel.awa
blobd39012c7f6d944193c22d802fff3fe46a481fcff
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 const: AVISH_MAP_WIDTH  = 44
19 const: AVISH_MAP_HEIGHT = 41
21 proc: avish_level_loader
22 arg: .level_idx
23 locals: .pos, .x, .y, .item_count
24 locals: .fframe, .lframe, .frame, .animated, .animspeed, .type, .tid
25   dbgprintstr "loading level #"
26   dbgprintnumnl [.level_idx]
27   ;
28   rst FRST_OPEN_LEVEL_FILE, [.level_idx]
29   ; set level name
30   rst FRST_GET_LEVEL_FILE_BYTE, 0  ; name length
31   rst FRST_SET_LEVEL_NAME, -2, [rst_result]
32   ; set level size
33   rst FRST_SET_LEVEL_SIZE, 44, 41  ; standard Avish level size
34   ; set backpic
35   rst FRST_GET_LEVEL_FILE_BYTE, 26
36   set [level_backpic], [rst_result]
37   ; set prof position
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]
47   ;
48   set [.pos], 31
49   ; load background tiles
50   set [.x], 1
51 .backtiles_col_loop:
52   set [.y], 0
53 .backtiles_row_loop:
54   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
55   add [.pos], 1
56   msb [.x], [.y], [rst_result]
57   add [.y], 1
58   jlt .backtiles_row_loop, [.y], [map_height]
59   add [.x], 1
60   jlt .backtiles_col_loop, [.x], [map_width]
61   ; load foreground tiles
62   set [.x], 1
63 .foretiles_col_loop:
64   set [.y], 0
65 .foretiles_row_loop:
66   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
67   add [.pos], 1
68   msf [.x], [.y], [rst_result]
69   add [.y], 1
70   jlt .foretiles_row_loop, [.y], [map_height]
71   add [.pos], 3  ; skip 3 unknown bytes
72   add [.x], 1
73   jlt .foretiles_col_loop, [.x], [map_width]
74   ; load items
75   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
76   add [.pos], 1
77   add 1, [rst_result], [.item_count]
78   ;
79 .item_loop:
80   ; x
81   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
82   add [.pos], 1
83   set [.x], [rst_result]
84   ; y
85   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
86   add [.pos], 1
87   set [.y], [rst_result]
88   ; fframe
89   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
90   add [.pos], 1
91   set [.fframe], [rst_result]
92   ; lframe
93   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
94   add [.pos], 1
95   set [.lframe], [rst_result]
96   ; frame
97   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
98   add [.pos], 1
99   set [.frame], [rst_result]
100   ; animated
101   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
102   add [.pos], 1
103   set [.animated], [rst_result]
104   ;
105   jne .item_anim_nofix, [.animated], 0
106   set [.frame], [.fframe]
107 .item_anim_nofix:
108   ; skip 0xff
109 ;;;  rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
110 ;;;  jeq @@f, [rst_result], 255
111 ;;;  rst FRST_DEBUG_ABORT
112 ;;;@@:
113   add [.pos], 1
114   ; skip 1 unknown byte
115   add [.pos], 1
116   ; animation speed
117   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
118   ;mul ITEM_ANIM_DELAY, [rst_result], [.animspeed]
119   set [.animspeed], [rst_result]
120   add [.pos], 1
121   ; skip unknown byte
122 ;;;  rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
123 ;;;  jeq @@f, [rst_result], 0
124 ;;;  rst FRST_DEBUG_ABORT
125 ;;;@@:
126   add [.pos], 1
127   ; skip unknown byte
128 ;;;  rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
129 ;;;  jeq @@f, [rst_result], 0
130 ;;;  rst FRST_DEBUG_ABORT
131 ;;;@@:
132   add [.pos], 1
133   ; item type
134   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
135   add [.pos], 1
136   set [.type], [rst_result]
137   ; skip unknown byte
138 ;;;  rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
139 ;;;  jeq @@f, [rst_result], 0
140 ;;;  rst FRST_DEBUG_ABORT
141 ;;;@@:
142   add [.pos], 1
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
153   sub [.pos], 6
154   rst FRST_GET_LEVEL_FILE_BYTE, [.pos]
155   add [.pos], 6
156   set aframe, [rst_result], [.tid]
157   ;set spr_num, [rst_result], [.tid]
158 .no_fix_aframe:
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]
163   ;
164   sub [.item_count], 1
165   jgt .item_loop, [.item_count], 0
166   ;
167   ret
168 endp: avish_level_loader