-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMKBKGD.C
More file actions
2685 lines (2107 loc) · 70.5 KB
/
MKBKGD.C
File metadata and controls
2685 lines (2107 loc) · 70.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
File: mkbkgd.c
Date: August 1994
(C) Williams Entertainment
Mortal Kombat III Background Routines
******************************************************************************/
#define VERIFY_HACK 0 // 0-hack on 1-hack off
/* INCLUDES */
#include "system.h"
#ifdef SONY_PSX
#include "mksony.h"
#endif /* SONY_PSX */
#include "mkbkgd.h"
#include "mkobj.h"
#include "mkos.h"
#include "mkgame.h"
#include "mkutil.h"
#include "mkfx.h"
#include "mkani.h"
#include "mkguys.h"
#include "mkinit.h"
#include "mkrepell.h"
#include "mkscore.h"
#include "mkmain.h"
#include "mkpal.h"
#include "mkfile.h"
#include "mksound.h"
#include "psxspu.h"
#include "valloc.h"
typedef struct stable
{
long scrl_value;
void (*scrl_func)(WORD); /* void function(WORD) */
} STABLE;
static STABLE scrolls_table[] =
{
{0x10000,ss_10000},
{0x20000,ss_20000},
{0x28000,ss_28000},
{0x30000,ss_30000},
{0x40000,ss_40000},
{0x60000,ss_60000},
{0x70000,ss_70000},
{0x80000,ss_80000},
{0xa0000,ss_a0000},
{0x00000,NULL}
};
/******************************************************************************
Function: void do_background(WORD background)
By: David Schwartz
Date: Aug 23, 1994
Parameters: background = background module to initiailze
Returns: None
Description: This routine will do the follows:
1) Create the background process
2) Load the background data into VRAM
3) Setup all neccessary background structures/tables/variables
******************************************************************************/
void do_background(WORD background_mod)
{
load_bkgd=background_mod; // set correct load background module #
init_background_module(table_o_mods[load_bkgd]);
process_sleep(1);
CREATE(PID_BACKG,background_routine);
return;
}
/******************************************************************************
Function: void background_clear(void)
By: David Schwartz
Date: Aug 23, 1994
Parameters: None
Returns: None
Description: This routine does the following:
1) clears background display lists
2) sets background modules to dumb modules
3) clears all world x positions
4) stops all scrolling
******************************************************************************/
void background_clear(void)
{
int l;
/* clear background lists */
baklst1=baklst2=baklst3=baklst4=NULL;
baklst4=baklst5=baklst6=baklst7=NULL;
baklst8=NULL;
/* set background modules */
for (l=0;l<(sizeof(bakmods)/sizeof(bakmods[0]));l++)
bakmods[l]=(ADDRESS *)DUMB_BACKGROUND;
/* clear background bits */
for (l=0;l<BACK_BIT_SIZE/BACK_BIT_RESOLUTION;l++)
bakbit1[l]=bakbit2[l]=bakbit3[l]=bakbit4[l]=bakbit5[l]=bakbit6[l]=bakbit7[l]=bakbit8[l]=0;
/* set_all_worldtlx */
worldtlx1.pos=worldtlx.pos=worldtlx2.pos=worldtlx3.pos=worldtlx4.pos=0;
worldtlx5.pos=worldtlx6.pos=worldtlx7.pos=worldtlx8.pos=0;
/* stop scrolling */
stop_scrolling();
return;
}
/* Format:
WORD TPAGE X START,# of DYN TPAGE
WORD x,y dyn tpage
WORD x,y dyn tpage
WORD x,y dyn tpage
*/
WORD bkgd_vmem_list[] =
{
BACK_TEXTURE_BASE_X,3,
0,256,
128,256,
256,256
};
WORD mock_vmem_list[] =
{
BACK_TEXTURE_BASE_X+128,4,
0,256,
128,256,
256,256,
256+128,256
};
WORD vs_vmem_list[] =
{
BACK_TEXTURE_BASE_X+128+128,5,
0,256,
128,256,
256,256,
256+128,256,
256+128+128,256
};
#if 0
WORD sel_vmem_list[] =
{
BACK_TEXTURE_BASE_X-128,2,
0,256,
128,256
};
#endif
/******************************************************************************
Function: void sony_graphics_setup(void)
By: David Schwartz
Date: Apr 1995
Parameters: None
Returns: None
Description: This routine sets up the vcache system and loads the correct level background data
******************************************************************************/
void sony_graphics_setup(void)
{
/* load in if memory isn't already setup with correct data */
if (table_o_levels[load_bkgd]!=load_level)
{
/* load code and module data associated with level */
level_overlay_load(table_o_levels[load_bkgd]);
f_street=0;
}
/* SONY ROUTINE, START VRAM CACHE */
switch (load_bkgd)
{
#if 0
case BKGD_MK3_PSEL:
bkgd_base_x=sel_vmem_list[0];
bkgd_base_tpage=GetTPage(TEXTURE_MODE,TRANS_RATE,bkgd_base_x,BACK_TEXTURE_BASE_Y);
init_vram_cache(&sel_vmem_list[1]); // reset vram cache
break;
#endif
case BKGD_VS_MOD:
bkgd_base_x=vs_vmem_list[0];
bkgd_base_tpage=GetTPage(TEXTURE_MODE,TRANS_RATE,bkgd_base_x,BACK_TEXTURE_BASE_Y);
init_vram_cache(&vs_vmem_list[1]); // reset vram cache
break;
case BKGD_MOCKPIT_MOD:
bkgd_base_x=mock_vmem_list[0];
bkgd_base_tpage=GetTPage(TEXTURE_MODE,TRANS_RATE,bkgd_base_x,BACK_TEXTURE_BASE_Y);
init_vram_cache(&mock_vmem_list[1]); // reset vram cache
break;
default:
bkgd_base_x=bkgd_vmem_list[0];
bkgd_base_tpage=GetTPage(TEXTURE_MODE,TRANS_RATE,bkgd_base_x,BACK_TEXTURE_BASE_Y);
init_vram_cache(&bkgd_vmem_list[1]); // reset vram cache
break;
}
/* load control panel graphics names */
load_control_page();
}
/******************************************************************************
Function: void init_background_module(void *)
By: David Schwartz
Date: Aug 23, 1994
Parameters: ptr to module to init
Returns: None
Description: This routine initializes the background module and associated data
(init_bakmods)
******************************************************************************/
void init_background_module(void *module_ptr)
{
WORD rgb;
WORD section_flag;
LONG temp;
// WORD clt_mode,clt_size;
POS *world_ptr;
FUNC init_func;
ADDRESS **bakmod_ptr;
// void *text_tbl;
/* setup ram with correct code/modules/overlays etc */
sony_graphics_setup();
bakbit1[0]=bakbit2[0]=bakbit3[0]=bakbit4[0]=0;
bakbit5[0]=bakbit6[0]=bakbit7[0]=bakbit8[0]=0;
/* word #1 = background color */
rgb=GET_WORD(module_ptr)++; /* get background color*/
if (rgb != NULL_IRQSKYE)
irqskye=rgb;
/* word #2 = worldtly/ceiling_y */
ceiling_y=GET_WORD(module_ptr)++; /* set ceiling y position */
worldtly.pos=(LONG)ceiling_y<<16;
/* word #3 = ground y offset */
ground_y=(GET_WORD(module_ptr)++)+ceiling_y; /* set ground y position */
/* word #4 = world x */
temp=GET_WORD(module_ptr)++;
if ((short)temp!=CENTER_X) // this bgnd centered, if so skip
{
(long)temp=(long)temp<<16;
/* set_all_worldtlx */
worldtlx1.pos=worldtlx.pos=worldtlx2.pos=worldtlx3.pos=worldtlx4.pos=temp;
worldtlx5.pos=worldtlx6.pos=worldtlx7.pos=worldtlx8.pos=temp;
}
IBAK2:
/* word 5 & 6 = scroll limits*/
left_edge=GET_WORD(module_ptr)++;
right_edge=GET_WORD(module_ptr)++;
/* word 7 & 8 = call routine */
init_func=(FUNC)(GET_LONG(module_ptr)++); /* setup call routines */
init_func();
/* word 9 & 10 = scroll table */
scrtab=(long *)(GET_LONG(module_ptr)++); /* set scroll table */
/* word 11 & 12 = display lists */
dlists=(void *)(GET_LONG(module_ptr)++); /* set display lists */
bakmod_ptr=(ADDRESS **)(GET_LONG(module_ptr)++); /* starting bak?mod to fill */
section_flag=0; /* start with load mods(0), then center x(1) */
while (TRUE)
{
IBAK3:
temp=GET_LONG(module_ptr)++;
/* main section */
if (!section_flag)
{
if (temp==FORCE_EXIT) /* abort loop */
break;
switch (temp)
{
case CENTER_X: /* time to center planes */
section_flag++;
break;
case SKIP_BAKMOD: /* skip background plane */
*bakmod_ptr++=(ADDRESS *)temp;
break;
default:
*bakmod_ptr++=((ADDRESS *)module_ptr)-1; /* store ptr to background plane information (module ptr, x,y)*/
((LONG *)module_ptr)++; /* skip past x,y init pos */
break;
}
}
/* center x section */
else
{
if (temp==END_LIST)
break;
world_ptr=(POS *)(GET_LONG(module_ptr)++); /* get ptr to worldtlx var */
world_ptr->pos= ((((OMODULE *)temp)->xsize-SCRRGT)/2)<<16; /* calc middle of screen */
}
}
IBAK5:
/* floor stuff */
if ((temp=GET_LONG(module_ptr))!=0)
setup_floor_info(module_ptr);
/* load in module TEXTURE data, SONY ADDITION */
bkgd_texture_load(bkgd_base_x,BACK_TEXTURE_BASE_Y);
return;
}
/******************************************************************************
Function: void bkgd_texture_load(WORD tsx,WORD tsy)
By: David Schwartz
Date: Dec 1994
Parameters: tsx - start x position in frame buffer
tsy - start y position in frame buffer
text_tbl_size - # of entires in text_tbl
text_tbl - list of ptr to address of texture data
Returns: None
Description: Load a list of 256 x 256 (8 bit) textures into the frame starting at tsx,tsy.
The routine will only load if the current level loaded does not match the load_bkgd level
******************************************************************************/
void bkgd_texture_load(WORD tsx,WORD tsy)
{
WORD results;
LONG entry;
if (table_o_levels[load_bkgd]!=load_level && table_o_levels[load_bkgd]!=LVL_NONE)
{
/* set new level & load data into VRAM */
load_level=table_o_levels[load_bkgd];
#if VERIFY_HACK
if ( !bkgd_preload )
results=texture_level_load(load_level,SYNC_LOAD);
else results=0;
if (results==0)
vram_texture_load(tsx,tsy,(ADDRESS *)p2_heap);
#else
HACK:
if ( !bkgd_preload )
results=texture_level_load(load_level,SYNC_LOAD);
else results=0;
if ( results==0 )
{
entry=GET_LONG(p2_heap);
if (entry>7)
{
bkgd_preload=0;
goto HACK;
}
vram_texture_load(tsx,tsy,(ADDRESS *)p2_heap);
}
#endif
bkgd_preload=0;
}
else
{
load_level=table_o_levels[load_bkgd];
}
return;
}
/******************************************************************************
Function: void vram_texture_load(WORD tsx,WORD tsy,ADDRESS *text_tbl)
By: David Schwartz
Date: Dec 1994
Parameters: tsx - start x position in frame buffer
tsy - start y position in frame buffer
text_tbl - list of ptr to address of texture data
Returns: None
Description: Load a list of 256 x 256 (8 bit) textures into the frame starting at tsx,tsy.
The routine will only load if the current level loaded does not match the curback's level
******************************************************************************/
void vram_texture_load(WORD tsx,WORD tsy,ADDRESS *text_tbl)
{
WORD l;
RECT frame;
void *text_info;
LONG text_tbl_size;
void *text_heap=text_tbl;
void *idcomp_temp=idcomp_ptr; // save value
/* set new level & load data */
load_level=table_o_levels[load_bkgd];
/* setup start of data info */
text_tbl_size=GET_LONG(text_tbl)++; // # of tpages to load
/* load all of the tpages into vram memory */
frame.w=128;
frame.h=256;
frame.x=tsx;
frame.y=tsy;
for (l=0;l<text_tbl_size;l++)
{
(ADDRESS *)text_info=GET_LONG(text_tbl)++; /* get ptr to textyre data */
text_info=COMPUTE_ADDR(text_heap,(ADDRESS *)text_info); // compute abs addr
#if BACKGROUND_COMPRESS
(BYTE *)idcomp_ptr=(l & 1)?(BYTE *)(&player_heap[PLAYER_HEAP_SIZE]-75*1024):(BYTE *)(&player_heap[PLAYER_HEAP_SIZE]-75*1024*2); // use last 75K Pages
text_info=(void*)uncompress_image((BYTE *)text_info);
#endif
LOADIMAGE(&frame,text_info); /* load data */
frame.x +=128; /* move to next texture pos */
#if BACKGROUND_COMPRESS
DrawSync(0); // make sure we dont overwrite
#endif
}
DrawSync(0); // make sure everything gets loaded before we allow heap ram to get trashed
#if BACKGROUND_COMPRESS
idcomp_ptr=idcomp_temp;
#endif
return;
}
/******************************************************************************
Function: void setup_floor_info(void *modptr)
By: David Schwartz
Date: Nov 1994
Parameters: None
Returns: None
Description: setup floor info parameters
******************************************************************************/
void unbetterSimpleRLE(BYTE *src, BYTE **dst);
extern BYTE *subflor_addr;
extern BYTE *hellflor_addr;
void setup_floor_info(void *modptr)
{
BYTE *srcfloor;
WORD *temp;
/* #1 - sag */
srcfloor=(BYTE *)GET_LONG(modptr)++; // centered
if ( load_bkgd==BKGD_STREET_MOD) // hack to make floor space less for SBST module
{
if ( f_street==0 )
{
temp=(WORD*)subflor_addr;
unbetterSimpleRLE(srcfloor,&subflor_addr);
subflor_addr=srcfloor=(BYTE*)temp;
f_street=1;
}
else
{
srcfloor=subflor_addr;
}
}
#if 0
if ( load_bkgd==BKGD_CAVE_MOD) // hack to make floor space less for SBST module
{
if ( f_street==0 )
{
temp=(WORD*)hellflor_addr;
unbetterSimpleRLE(srcfloor,&hellflor_addr);
hellflor_addr=srcfloor=(BYTE*)temp;
f_street=1;
}
else
{
srcfloor=hellflor_addr;
}
}
#endif
/* #2 - set const:pal */
(LONG)temp=GET_LONG(modptr)++;
skew_constpal=get_fore_pal(temp);
skew_oc=0; // off center = 0
/* #3 - height of floor */
skew_height=GET_LONG(modptr)++; // floor height
skew_y=worldtly.u.intpos+(BUFFER_HEIGHT-10)-skew_height; // align floor with bottom of screen
/* #4 - scroll x to use */
skew_scroll=(ADDRESS *)(GET_LONG(modptr)++);
/* #5 - scroll call routine */
skew_calla=(FLRCALL)GET_LONG(modptr)++;
/* transfer floor into src buffer */
//memcpy(floor_src_buffer,srcfloor,FLOOR_X*FLOOR_Y); // copy memory and set skew address
//skew_sag=floor_src_buffer+(FLOOR_X/3); // center 1 pixels/byte, ( 3 scrns wide so center is screen 1)
skew_sag=srcfloor+(FLOOR_X/3); // center 1 pixels/byte, ( 3 scrns wide so center is screen 1)
f_skew=1;
return;
}
/******************************************************************************
Function: void use_next_y(void)
By: David Schwartz
Date: Dec 1994
Parameters: None
Returns: update disp_world.ypos
update dlists_ptr
Description: This routines updates the y scroll value during display via dlists_ptr info
******************************************************************************/
void use_next_y(void)
{
POS *world_ptr;
world_ptr=(POS *)GET_LONG(dlists_ptr)++;
disp_world.u.ypos=world_ptr->u.intpos;
return;
}
/******************************************************************************
Function: void use_worldtly(void)
By: David Schwartz
Date: Dec 1994
Parameters: None
Returns: update disp_world.ypos
Description: This routines updates the y scroll value based on the worldtly
******************************************************************************/
void use_worldtly(void)
{
disp_world.u.ypos=worldtly.u.intpos;
return;
}
/******************************************************************************
Function: void use_worldtly_t(void)
By: David Schwartz
Date: Dec 1994
Parameters: None
Returns: update disp_world.ypos
Description: This routines updates the y scroll value based on the worldtly_t
******************************************************************************/
void use_worldtly_t(void)
{
if (f_pause<PAUSE_OFF || f_pause==PAUSE_P1_INIT || f_pause==PAUSE_P2_INIT)
worldtly_t.u.intpos+=scrolly.u.intpos; // do y scrolling for temp planes
disp_world.u.ypos=worldtly_t.u.intpos;
return;
}
/******************************************************************************
Function: void check_only_t(void)
By: David Schwartz
Date: Dec 1994
Parameters: None
Returns: update dlists_ptr if needed
Description: check to see if we use temp lists only
******************************************************************************/
void check_only_t(void)
{
if (f_only_t!=0)
dlists_ptr=dlists_end;
return;
}
/******************************************************************************
Function: void background_routine(void)
By: David Schwartz
Date: Aug 23, 1994
Parameters: None
Returns: None
Description: This routine updates the backgrounds
******************************************************************************/
void background_routine(void)
{
current_proc->a10=BACKGROUND_SLEEP_TIME;
while (TRUE)
{
multi_plane();
process_sleep(current_proc->a10);
};
}
/******************************************************************************
Function: void multi_plane(void)
By: David Schwartz
Date: Aug 23, 1994
Parameters: None
Returns: None
Description: This routine processes the multiple planes
******************************************************************************/
void multi_plane(void)
{
static PLANETBL plane_table_info[] =
{
{&bakbit1[0],&baklst1,&worldtly,&worldtlx1,&bak1mods},
{&bakbit2[0],&baklst2,&worldtly,&worldtlx2,&bak2mods},
{&bakbit3[0],&baklst3,&worldtly,&worldtlx3,&bak3mods},
{&bakbit4[0],&baklst4,&worldtly,&worldtlx4,&bak4mods},
{&bakbit5[0],&baklst5,&worldtly,&worldtlx5,&bak5mods},
{&bakbit6[0],&baklst6,&worldtly,&worldtlx6,&bak6mods},
{&bakbit7[0],&baklst7,&worldtly,&worldtlx7,&bak7mods},
{&bakbit8[0],&baklst8,&worldtly,&worldtlx8,&bak8mods}
};
int l;
PLANETBL *plane;
LONG bmod;
XYTYPE disptl,displr;
// OMODULE *mod_ptr;
// XYTYPE mod_xysize;
for (l=0;l<(sizeof(plane_table_info)/sizeof(plane_table_info[0]));l++)
{
plane=&plane_table_info[l];
bmod=(LONG)(*((LONG *)plane->mod_ptr));
if (bmod==DUMB_BACKGROUND) /* if DUMB BACKGROUND , end list processing */
break;
if (bmod != SKIP_BAKMOD) /* process plane check */
{
/* execute bgnd_ud1 routine */
disptl.u.xpos=displr.u.xpos=plane->world_x->u.intpos;
disptl.u.ypos=displr.u.ypos=plane->world_y->u.intpos;
disptl.u.xpos=disptl.u.xpos+scrntlx-DISPLAY_PADDING_X;
disptl.u.ypos=disptl.u.ypos+scrntly-DISPLAY_PADDING_Y;
displr.u.xpos=displr.u.xpos+scrnlrx+DISPLAY_PADDING_X;
displr.u.ypos=displr.u.ypos+scrnlry+DISPLAY_PADDING_Y;
/* remove objects that aren't on screen */
display_delete(plane->baklst,&disptl,&displr);
/* add any tiles that aren't on display list */
display_modify(plane->baklst,(void *)bmod,plane->bakbit,&disptl,&displr);
}
}
return;
}
/******************************************************************************
Function: void display_delete(OBJECT **baklst,XYTYPE tl,XTYPE lr)
By: David Schwartz
Date: Aug 23, 1994
Parameters: baklst - ptr to planes display list of objects
tl - top left y:x coord of view screen
lr - lower right y:x coord of view screen
Returns: None
Description: This routine will scan through the current plane display list
and remove any object's collision box that does not fall anywhere
within the view screen.
******************************************************************************/
#if DEBUG
extern WORD objcnt;
#endif
void display_delete(OBJECT **baklst,XYTYPE *tl,XYTYPE *lr)
{
OBJECT *current_obj;
OBJECT *prev_obj;
current_obj=(OBJECT *)baklst; /* set current to start of list */
while (current_obj->olink != NULL)
{
prev_obj=current_obj;
current_obj=current_obj->olink;
if ((current_obj->oxpos.u.intpos>lr->u.xpos) ||
(current_obj->oypos.u.intpos>lr->u.ypos) ||
(current_obj->oxpos.u.intpos+current_obj->header.t_width<tl->u.xpos) ||
(current_obj->oypos.u.intpos+current_obj->header.t_height<tl->u.ypos))
{
*((LONG *)current_obj->oplink) &=~current_obj->oblockmask; /* clear block bit, not in display list */
if (current_obj->opal !=0) /* free up palette that object uses */
free_pal(current_obj->opal);
prev_obj->olink=current_obj->olink; /* remove object and reconnect node */
current_obj->olink=obj_free; /* add removed object to free list */
obj_free=current_obj;
#if DEBUG
objcnt--;
#endif
current_obj=prev_obj; /* place current ptr to prev */
}
}
return;
}
/******************************************************************************
Function: void display_modify(OBJECT **baklst,void *bak_info,LONG *bakbit,XYTYPE *tl,XYTYPE *lr)
By: David Schwartz
Date: Aug, 1994
Parameters: baklst - ptr to ptr to display list for plane
bak_info - ptr to module info and (xy start pos for module)
bakbit - ptr to array of longs (1 bit per object) on plane, indicates object already added
tl - top left corner of screen (Y:X)
lr - lower right corner of screen (Y:X)
Returns: None
Description: Scan a module lists to find out which modules contain blocks
which need to be checked for addition to the display list.
******************************************************************************/
void display_modify(OBJECT **baklst,void *bak_info,LONG *bakbit,XYTYPE *tl,XYTYPE *lr)
{
OMODULE *mod_ptr;
XYTYPE mod_xysize;
XYTYPE mod_start,mod_end;
XYTYPE topl,lowerr;
// long ytemp;
mod_ptr=(OMODULE *)(GET_LONG(bak_info)++);
mod_xysize.yx=GET_LONG(mod_ptr);
/* set module start position */
mod_start.u.xpos=GET_WORD(bak_info)++;
mod_start.u.ypos=GET_WORD(bak_info)++;
if (mod_start.u.xpos==(short)BLSTSTRT)
mod_start.u.xpos=-mod_xysize.u.xpos;
else if (mod_start.u.xpos==(short)BLSTEND)
mod_start.u.xpos=0;
/* gotnewx */
if (mod_start.u.ypos==(short)BLSTSTRT)
mod_start.u.ypos=-mod_xysize.u.ypos;
else if (mod_start.u.ypos==(short)BLSTEND)
mod_start.u.ypos=0;
/* set module end position */
mod_end.u.xpos=mod_start.u.xpos+mod_xysize.u.xpos;
mod_end.u.ypos=mod_start.u.ypos+mod_xysize.u.ypos;
/* check if any part of module is viewable */
if (!((mod_end.u.xpos<tl->u.xpos) ||
(mod_end.u.ypos<tl->u.ypos) ||
(mod_start.u.xpos>lr->u.xpos) ||
(mod_start.u.ypos>lr->u.ypos)))
{
topl.u.xpos=tl->u.xpos-mod_start.u.xpos; /* convert screen coords to relative mod screen coords */
topl.u.ypos=tl->u.ypos-mod_start.u.ypos;
lowerr.u.xpos=lr->u.xpos-mod_start.u.xpos; /* convert screen coords to relative mod screen coords */
lowerr.u.ypos=lr->u.ypos-mod_start.u.ypos;
display_add(baklst,mod_ptr,bakbit,&topl,&lowerr,&mod_start);
}
return;
}
/******************************************************************************
Function: void display_add(OBJECT **baklst,OMODULE *bakmod,LONG *bakbit,XYTYPE *tl,XYTYPE *lr,XYTYPE *start)
By: David Schwartz
Date: Aug, 1994
Parameters: baklst - ptr to ptr to display list for plane
bakmod - ptr to module list
bakbit - ptr to array of longs (1 bit per object) on plane, indicates object already added
tl - top left corner of screen (Y:X)
lr - lower right corner of screen (Y:X)
start - module start position (Y:X)
Returns: None
Description: parse through module block list and adds any modules that are not
on display list that fit on active screen area.
******************************************************************************/
void display_add(OBJECT **baklst,OMODULE *bakmod,LONG *bakbit,XYTYPE *tl,XYTYPE *lr,XYTYPE *start)
{
static LONG bit_mask_table [] =
{
0x00000001,0x00000002,0x00000004,0x00000008,
0x00000010,0x00000020,0x00000040,0x00000080,
0x00000100,0x00000200,0x00000400,0x00000800,
0x00001000,0x00002000,0x00004000,0x00008000,
0x00010000,0x00020000,0x00040000,0x00080000,
0x00100000,0x00200000,0x00400000,0x00800000,
0x01000000,0x02000000,0x04000000,0x08000000,
0x10000000,0x20000000,0x40000000,0x80000000
};
WORD done=FALSE;
short xpos;
WORD block_num=0;
LONG blk_mask;
WORD blk_index;
WORD blk_cnt;
OBLOCK *blk_ptr;
OHEADER *hdr_ptr,*hdr_info;
blk_ptr=bakmod->block_ptr;
hdr_ptr=bakmod->header_ptr;
xpos =tl->u.xpos-BACKGROUND_WIDEST_BLOCK;
blk_cnt=bakmod->blockcnt;
/* find first block that could be on screen */
while (!done && block_num<blk_cnt)
{
if ((short)blk_ptr->xoffset >= xpos)
done=TRUE;
else
{
blk_ptr++;
block_num++;
}
}
if (!done) return; /* if not done then no blocks on screen to exit */
/* loop one scan until x coord greater the tl or no blocks left */
while (block_num<blk_cnt)
{
blk_index=block_num/BACK_BIT_RESOLUTION;
blk_mask=bit_mask_table[block_num % BACK_BIT_RESOLUTION];
/* if block not on display list then check for on active screen */
if (!(*(bakbit+blk_index) & blk_mask))
{
if ((short)blk_ptr->xoffset>tl->u.xpos) /* check if x to big */
break;
else
{
hdr_info=hdr_ptr+blk_ptr->hdr_index;
if (!(((short)(blk_ptr->xoffset+hdr_info->t_width)<tl->u.xpos) ||
((short)blk_ptr->yoffset>lr->u.ypos) ||
((short)(blk_ptr->yoffset+hdr_info->t_height)<tl->u.ypos)))
if (add_block(baklst,bakbit+blk_index,blk_ptr,hdr_info,start,blk_mask,bakmod->clut_ptr))
return; /* no objects left */
}
}
/* move to next block */
block_num++;
blk_ptr++;
}
/* loop two scan until x coord greater then lr or no blocks left */
while (block_num<blk_cnt)
{
blk_index=block_num/BACK_BIT_RESOLUTION;
blk_mask=bit_mask_table[block_num % BACK_BIT_RESOLUTION];
/* if block not on display list then check for on active screen */
if (!(*(bakbit+blk_index) & blk_mask))
{
if ((short)blk_ptr->xoffset>lr->u.xpos) /* check if x to big then exit */
return;
hdr_info=hdr_ptr+blk_ptr->hdr_index;
if (!(((short)(blk_ptr->xoffset+hdr_info->t_width)<tl->u.xpos) ||
((short)blk_ptr->yoffset>lr->u.ypos) ||
((short)(blk_ptr->yoffset+hdr_info->t_height)<tl->u.ypos)))
if (add_block(baklst,bakbit+blk_index,blk_ptr,hdr_info,start,blk_mask,bakmod->clut_ptr))
return; /* no objects left */
}
/* move to next block */
block_num++;
blk_ptr++;
}
return;
}
/******************************************************************************
Function: int add_block(OBJECT **baklst,LONG *bakbit,OBLOCK bakblk,OHEADER *hdr_info,XYTYPE *start,LONG blkmask,WORD **blkclt)
By: David Schwartz
Date: Aug 23, 1994
Parameters: baklst = ptr to ptr to display list
bakbit = ptr to background display bits for current block
bakblk = ptr to background block info
hdr_info = ptr to block tile information (header info)
start = Y:X start position of module
blkmask = bit mask to set block is on display list
blkclt = ptr to clut tables
Returns: TRUE = object not allocated
FALSE = object allocated
Description: This routine does the following:
1) retrive an object block, returns TRUE if no available