1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
23 #include "src/lib/16_spri.h"
\r
24 #include <hw/vga/vrl1xdrc.h>
\r
25 //void draw_vrl1_vgax_modex_strip(unsigned char far *draw,unsigned char far *s);
\r
27 //===========================================================================
\r
29 //#define NEWVRSDRAWFUN
\r
30 void DrawVRL (unsigned int x,unsigned int y,struct vrl1_vgax_header *hdr,vrl1_vgax_offset_t *lineoffs/*array hdr->width long*/,unsigned char *data,unsigned int datasz) {
\r
31 unsigned char far *draw;
\r
32 unsigned int vram_offset = (y * vga_state.vga_draw_stride) + (x >> 2),sx;
\r
33 unsigned int vramlimit = vga_state.vga_draw_stride_limit;
\r
34 unsigned char vga_plane = (x & 3);
\r
37 // byte outputvars[72][128];
\r
38 word a;//,by,bxmax,bymax;
\r
40 printf("DrawVRL:\n");
\r
42 /* draw one by one */
\r
43 for (sx=0;sx < hdr->width;sx++) {
\r
44 draw = vga_state.vga_graphics_ram + vram_offset;
\r
45 vga_write_sequencer(0x02/*map mask*/,1 << vga_plane);
\r
46 s = data + lineoffs[sx];
\r
47 draw_vrl1_vgax_modex_strip(draw,s);
\r
50 for(a=0;a<hdr->height;a++)//hdr->width*
\r
52 // if((*(s+a)==0x0) && (*(s+(a+1))==0x20) && (*(s+(a+2))==0xff)) a+=2;
\r
54 // if (!(a%4) && a ) printf("\n");
\r
55 // sprintf(outputvars[sx][by], "%02x", *(s+a));
\r
56 printf("[%02u] %02x\n", a, *(s+a));
\r
60 /* end of a vertical strip. next line? */
\r
61 if ((++vga_plane) == 4) {
\r
62 if (--vramlimit == 0) break;
\r
68 bxmax = sx; bymax = by;
\r
69 for(by=0;by<bymax;by++)
\r
71 for(sx=0;sx<bxmax;sx++)
\r
73 // if (!(sx%hdr->width) && sx ) printf("\n ");
\r
74 printf("%02x ", outputvars[sx][by]);
\r
81 //===========================================================================
\r
83 char* get_curr_anim_name(struct sprite *spri)
\r
85 // Retrive animation name list
\r
86 struct vrs_header far *vrs = spri->spritesheet.vrs_hdr;
\r
87 uint32_t far *anim_names_offsets = (uint32_t far *)
\r
89 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_NAME_LIST]);
\r
91 return (char *)(vrs + anim_names_offsets[spri->curr_anim]);
\r
94 void init_anim(struct sprite *spri, int anim_index)
\r
96 struct vrs_header far *vrs = spri->spritesheet.vrs_hdr;
\r
97 uint32_t far *anim_lists_offsets = (uint32_t far *)
\r
99 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_LIST]);
\r
100 struct vrs_animation_list_entry_t far *anim_list = (struct vrs_animation_list_entry_t far *)
\r
102 anim_lists_offsets[anim_index]);
\r
104 // Upon new animation, start from the first sprite in it
\r
105 spri->curr_anim = anim_index;
\r
106 spri->curr_anim_spri = 0;
\r
107 spri->curr_spri_id = anim_list[0].sprite_id;
\r
108 spri->delay = anim_list[0].delay;
\r
110 spri->curr_anim_list = anim_list;
\r
113 int set_anim_by_id(struct sprite *spri, int anim_id)
\r
115 int new_anim_index = 0;
\r
117 struct vrs_header far *vrs = spri->spritesheet.vrs_hdr;
\r
118 // Retruve animation ids list
\r
119 uint16_t far *anim_ids = (uint16_t far *)
\r
121 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_ID_LIST]);
\r
123 // Loop through animation id untill match or end of list
\r
124 while(iter_id = anim_ids[new_anim_index])
\r
126 // Return on successful match
\r
127 if (iter_id == anim_id)
\r
129 init_anim(spri, new_anim_index);
\r
137 void print_anim_ids(struct sprite *spri)
\r
139 int new_anim_index = 0;
\r
141 struct vrs_header far *vrs = spri->spritesheet.vrs_hdr;
\r
142 // Retruve animation ids list
\r
143 uint16_t far *anim_ids = (uint16_t far *)
\r
145 vrs->offset_table[VRS_HEADER_OFFSET_ANIMATION_ID_LIST]);
\r
147 if(!anim_ids[new_anim_index])
\r
149 // Loop through animation id untill match or end of list
\r
150 while(iter_id = anim_ids[new_anim_index])
\r
152 printf("s%d ", iter_id);
\r
157 void animate_spri(entity_t *enti, video_t *video)
\r
159 #define INC_PER_FRAME if(enti->q&1) enti->persist_aniframe++; if(enti->persist_aniframe>4) enti->persist_aniframe = 1;
\r
160 unsigned int i,o,o2; int j;
\r
162 static struct glob_game_vars *ggvv;
\r
163 VGA_RAM_PTR omemptr = (VGA_RAM_PTR)video->page[0].data;// save original mem ptr
\r
169 // Depending on delay, update indices
\r
170 //#define FRAME1 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 48, player[pn].enti.dire, 24, 32, PLAYERBMPDATAPTR);
\r
171 //#define FRAME2 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 24, player[pn].enti.dire, 24, 32, PLAYERBMPDATAPTR); stand
\r
172 //#define FRAME3 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 0, player[pn].enti.dire, 24, 32, PLAYERBMPDATAPTR);
\r
173 //#define FRAME4 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 24, player[pn].enti.dire, 24, 32, PLAYERBMPDATAPTR); stand
\r
175 // copy active display (0) to offscreen buffer (0x4000)
\r
176 /*vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = vga_state.vga_stride;
\r
177 vga_setup_wm1_block_copy();
\r
178 vga_wm1_mem_block_copy(copy_ofs, display_ofs, vga_state.vga_stride * vga_state.vga_height);
\r
179 vga_restore_rm0wm0();*/
\r
181 switch(enti->spri.delay)
\r
183 // Delay = 0 means that sprite should loop. Nothing to change here
\r
187 // Delay = 1 means that on next time unit sprite should be changed
\r
190 enti->spri.curr_anim_spri++;
\r
192 // If we hit the end of an animation sequence, restart it
\r
193 if(!( enti->spri.curr_spri_id = enti->spri.curr_anim_list[enti->spri.curr_anim_spri].sprite_id)){
\r
194 enti->spri.curr_anim_spri = 0;
\r
195 enti->spri.curr_spri_id = enti->spri.curr_anim_list[enti->spri.curr_anim_spri].sprite_id;
\r
197 enti->spri.delay = enti->spri.curr_anim_list[enti->spri.curr_anim_spri].delay;
\r
199 // Delay > 1 means that we should not change sprite yet. Decrease delay
\r
201 enti->spri.delay--;
\r
210 j = get_vrl_by_id(&enti->spri.spritesheet, enti->spri.curr_spri_id, &enti->spri.sprite_vrl_cont);
\r
213 //Quit (gv, "Error retriving required sprite");
\r
217 // render box bounds. y does not need modification, but x and width must be multiple of 4
\r
218 if(!video->vga_state.rss)
\r
220 if (x >= enti->overdraww) rx = (x - enti->overdraww) & (~3);
\r
221 else rx = -(video->page[0].dx);
\r
222 if (y >= enti->overdrawh) ry = (y - enti->overdrawh);
\r
223 else ry = -(video->page[0].dy);
\r
224 h = enti->spri.sprite_vrl_cont.vrl_header->height + enti->overdrawh + y - ry;
\r
225 w = (x + enti->spri.sprite_vrl_cont.vrl_header->width + (enti->overdraww*2) + 3 - rx) & (~3) - enti->overdraww;//round up
\r
226 if ((rx+w) > video->page[0].width) w = video->page[0].width-rx;
\r
227 if ((ry+h) > video->page[0].height) h = video->page[0].height-ry;
\r
229 if(!video->vga_state.bgps){
\r
230 // block copy pattern to where we will draw the sprite
\r
231 vga_setup_wm1_block_copy();
\r
232 o2 = video->ofs.offscreen_ofs;
\r
233 o = video->ofs.pattern_ofs + (ry * video->page[0].stridew) + (rx >> 2); // source offscreen
\r
234 for (i=0;i < h;i++,o += video->page[0].stridew,o2 += (w >> 2)) vga_wm1_mem_block_copy(o2,o,w >> 2);
\r
236 // must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally
\r
237 vga_restore_rm0wm0();
\r
239 // replace VGA stride with our own and mem ptr. then sprite rendering at this stage is just (0,0)
\r
240 vga_state.vga_draw_stride = w >> 2;
\r
241 vga_state.vga_graphics_ram = omemptr + video->ofs.offscreen_ofs;
\r
242 }else{ rx=ry=w=h=0; vga_state.vga_graphics_ram = (VGA_RAM_PTR)video->page[0].data; }
\r
243 vga_state.vga_draw_stride_limit = (video->page[0].width + 3 - x) >> 2;//round up
\r
245 // then the sprite. note modding ram ptr means we just draw to (x&3,0)
\r
247 modexClearRegion(&video->page[0], x, y, 16, 32, 1);
\r
249 #ifndef NEWVRSDRAWFUN
\r
250 draw_vrl1_vgax_modex
\r
257 enti->spri.sprite_vrl_cont.vrl_header,
\r
258 enti->spri.sprite_vrl_cont.line_offsets,
\r
259 enti->spri.sprite_vrl_cont.buffer + sizeof(struct vrl1_vgax_header),
\r
260 enti->spri.sprite_vrl_cont.data_size
\r
263 #ifdef __DEBUG_SPRI__
\r
264 // if(ggvv->player[0].enti.q<5)
\r
265 if(dbg_delayanimation)
\r
267 IN_Ack(ggvv);// delay(250);//{ while(!IN_KeyDown(sc_Space)/* && !IN_KeyDown(sc_Escape)*/){} delay(250); }
\r
270 if(!video->vga_state.rss)
\r
273 vga_state.vga_graphics_ram = omemptr;
\r
275 if(!video->vga_state.bgps){
\r
276 // block copy to visible RAM from offscreen
\r
277 vga_setup_wm1_block_copy();
\r
278 o = video->ofs.offscreen_ofs; // source offscreen
\r
279 o2 = (ry * video->page[0].stridew) + (rx >> 2); // dest visible (original stride)
\r
280 for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += video->page[0].stridew) vga_wm1_mem_block_copy(o2,o,w >> 2);
\r
281 // must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally
\r
282 vga_restore_rm0wm0();
\r
286 vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = video->page[0].stridew;
\r
288 vga_state.vga_graphics_ram = video->vga_state.omemptr;
\r