-
Notifications
You must be signed in to change notification settings - Fork 3
/
saturn.cpp
3850 lines (3462 loc) · 131 KB
/
saturn.cpp
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
//#define USE_SPRITES 1
#include "wl_def.h"
#include "sdl/SDL.h"
#include "sdl/SDL_mixer.h"
#include <stdlib.h> /* malloc */
//#include <string.h> /* memcpy */
#include <ctype.h> /* toupper */
#include <malloc.h>
#include "pcmsys.h"
extern "C" {
//#include "L:\saturn\dev\sms_elf2\cdc\SEGA_CDC.H"
#include "C:/SaturnOrbit/SGL_302j/INC/sl_def.h"
//#ifdef VBT
#include "sega_cdc.h"
#include "sega_snd.h"
//#endif
}
unsigned char *saturnChunk;
unsigned int vdds = 0;
unsigned char vtno = 0;
unsigned short vrep = 0;
//
#ifdef USE_SPRITES
extern TEXTURE tex_spr[SPR_NULLSPRITE+SATURN_WIDTH];
#endif
extern unsigned char hz;
extern "C" {
extern void DMA_ScuInit(void);
extern void DMA_ScuMemCopy(void *dst, void *src, Uint32 cnt);
extern Uint32 DMA_ScuResult(void);
extern void memcpywh(char *dst, char *src, short width, short height, short step);// , long srchstep, long srcwstep, char flag);
extern void load_driver_binary(char * filename, void * buffer);
}
void SCU_DMAWait(void);
void sc_usleep(unsigned long usec);
extern void CheckWeaponChange (void);
//extern void ShapeTest (void);
//#define ACTION_REPLAY 1
#ifndef ACTION_REPLAY
GfsDirName dir_name[MAX_DIR];
#endif
/*
#define SDL_FillRect(arg1, dest, arg3) \
slBMBoxFill((dest)->x, (dest)->y, (dest)->x + (dest)->w - 1, (dest)->y + (dest)->h - 1, 0)
*/
inline void Pal2CRAM( Uint16 *Pal_Data , void *Col_Adr , Uint32 suu );
void InitCD();
void InitCDBlock(void);
void ChangeDir(char *dirname);
int SDL_InitSubSystem(Uint32 flags);
Sint32 GetFileSize(int file_id);
/*
debug
*/
//Uint32 frame = 0;
static unsigned char vbt_event[13];
//static int current_event=0;
static Uint32 previouscount=0;
static Uint16 previousmillis=0;
//PCM m_dat[4];
static CdcPly playdata;
static CdcPos posdata;
static Uint16 pad_asign[] = {
PER_DGT_KU,
PER_DGT_KD,
PER_DGT_KR,
PER_DGT_KL,
PER_DGT_TA,
PER_DGT_TB,
PER_DGT_TC,
PER_DGT_ST,
PER_DGT_TX,
PER_DGT_TY,
PER_DGT_TZ,
PER_DGT_TR,
PER_DGT_TL,
};
static const Sint8 logtbl[] = {
/* 0 */ 0,
/* 1 */ 1,
/* 2 */ 2, 2,
/* 4 */ 3, 3, 3, 3,
/* 8 */ 4, 4, 4, 4, 4, 4, 4, 4,
/* 16 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
/* 32 */ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
/* 64 */ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
/* 128 */ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
};
//--------------------------------------------------------------------------------------------------------------------------------------
static unsigned int get_hz(void)
{
#define TVSTAT (*(volatile Uint16 *)0x25F80004)
if((TVSTAT & 1) == 0)
return 60;
else
return 50;
}
//--------------------------------------------------------------------------------------------------------------------------------------
SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
{
unsigned char tv_mode=TV_320x224;
SDL_Surface *screeny;
screeny = (SDL_Surface*)malloc(sizeof(SDL_Surface));
CHECKMALLOCRESULT(screeny);
if(width==320)
{
tv_mode = TV_320x224;
if(height==240) tv_mode = TV_320x240;
}
if(width==352)
{
tv_mode = TV_352x224;
if(height==240) tv_mode = TV_352x240;
}
if(width==640)
{
tv_mode = TV_640x224;
if(height==240) tv_mode = TV_640x240;
}
#ifdef USE_SPRITES
slInitSystem(tv_mode, (TEXTURE*)tex_spr, 1);
#else
slInitSystem(tv_mode, NULL, 1);
#endif
hz = get_hz();
// slZdspLevel(8);
// vbt 26/07/2020
// slDynamicFrame(ON);
slTVOff();
if(bpp==8)
{
slColRAMMode(CRM16_2048);
slCharNbg1(COL_TYPE_256 , CHAR_SIZE_1x1);
}
else
{
slColRAMMode(CRM32_1024);
slCharNbg1(COL_TYPE_32768 , CHAR_SIZE_1x1);
}
slInitBitMap(bmNBG1, BM_512x256, (void *)VDP2_VRAM_A0);
slBMPaletteNbg1(1);
extern Uint16 VDP2_RAMCTL;
VDP2_RAMCTL = VDP2_RAMCTL & 0xFCFF;
extern Uint16 VDP2_TVMD;
VDP2_TVMD &= 0xFEFF;
slScrAutoDisp(NBG0ON| NBG1ON);
slScrCycleSet(0x55EEEEEE , NULL , 0x044EEEEE , NULL);
//#define BACK_COL_ADR ( VDP2_VRAM_A1 + 0x1fffe )
// slBack1ColSet((void *)BACK_COL_ADR , RGB(14,14,14));
// slScrTransparent(RBG0ON);
// slScrAutoDisp(RBG0ON| NBG0ON| NBG1ON| NBG3ON);
// VDP2_RAMCTL = VDP2_RAMCTL & 0xFCFF;
/* /// vbt ? remettre
slCharNbg3(COL_TYPE_256, CHAR_SIZE_1x1);
slPageNbg3((void*)0x25e60000, 0, PNB_1WORD|CN_10BIT );
slPlaneNbg3(PL_SIZE_1x1);
slMapNbg3((void*)0x25e76000, (void*)0x25e76000, (void*)0x25e76000, (void*)0x25e76000);
slBitMapNbg0(COL_TYPE_16, BM_512x256, (void *)VDP2_VRAM_A0);
slBMPalette(bmNBG0 , 0);
slPriorityRbg0(7);
slPriorityNbg3(7);
*/
slPriorityNbg0(7); // avant rbg0
slPriorityNbg1(6);
slPrioritySpr0(5);
#ifdef USE_SPRITES
slZdspLevel(7); // vbt : ne pas d?placer !!!
#endif
screeny->pixels = (unsigned char*)malloc(sizeof(unsigned char)*width*height);
CHECKMALLOCRESULT(screeny->pixels);
screeny->pitch = width;
screeny->w = width;
screeny->h = height;
// memset(screen->pixels,0x00,width*height);
return screeny;
}
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors)
{
Uint16 palo[256];
// CHECKMALLOCRESULT(palo);
for(int i=0;i<ncolors;i++)
{
palo[i] = RGB(colors[i].r>>3,colors[i].g>>3,colors[i].b>>3);
}
Pal2CRAM(palo , (void *)NBG1_COL_ADR , ncolors);
Pal2CRAM(palo+14 , (void *)NBG0_COL_ADR , ncolors);
return 1;
}
//--------------------------------------------------------------------------------------------------------------------------------------
/*int SDL_SetColorKey (SDL_Surface *surface, Uint32 flag, Uint32 key)
{
return 0;
}*/
//--------------------------------------------------------------------------------------------------------------------------------------
static unsigned char initcddone=0;
int SDL_Init(Uint32 flags)
{
#ifndef ACTION_REPLAY
if(initcddone==0)
{
InitCD();
InitCDBlock();
initcddone=1;
}
#endif
// SYS_Exit(0);
// DMA_ScuInit();
// SPR_InitSlaveSH();
SDL_InitSubSystem(flags);
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
void sound_external_audio_enable(Uint8 vol_l, Uint8 vol_r) {
volatile Uint16 *slot_ptr;
//max sound volume is 7
if (vol_l > 7) {
vol_l = 7;
}
if (vol_r > 7) {
vol_r = 7;
}
// Setup SCSP Slot 16 and Slot 17 for playing
slot_ptr = (volatile Uint16 *)(0x25B00000 + (0x20 * 16));
slot_ptr[0] = 0x1000;
slot_ptr[1] = 0x0000;
slot_ptr[2] = 0x0000;
slot_ptr[3] = 0x0000;
slot_ptr[4] = 0x0000;
slot_ptr[5] = 0x0000;
slot_ptr[6] = 0x00FF;
slot_ptr[7] = 0x0000;
slot_ptr[8] = 0x0000;
slot_ptr[9] = 0x0000;
slot_ptr[10] = 0x0000;
slot_ptr[11] = 0x001F | (vol_l << 5);
slot_ptr[12] = 0x0000;
slot_ptr[13] = 0x0000;
slot_ptr[14] = 0x0000;
slot_ptr[15] = 0x0000;
slot_ptr = (volatile Uint16 *)(0x25B00000 + (0x20 * 17));
slot_ptr[0] = 0x1000;
slot_ptr[1] = 0x0000;
slot_ptr[2] = 0x0000;
slot_ptr[3] = 0x0000;
slot_ptr[4] = 0x0000;
slot_ptr[5] = 0x0000;
slot_ptr[6] = 0x00FF;
slot_ptr[7] = 0x0000;
slot_ptr[8] = 0x0000;
slot_ptr[9] = 0x0000;
slot_ptr[10] = 0x0000;
slot_ptr[11] = 0x000F | (vol_r << 5);
slot_ptr[12] = 0x0000;
slot_ptr[13] = 0x0000;
slot_ptr[14] = 0x0000;
slot_ptr[15] = 0x0000;
*((volatile Uint16 *)(0x25B00400)) = 0x020F;
}
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_InitSubSystem(Uint32 flags)
{
if(flags &= SDL_INIT_AUDIO)
{
#ifdef PONY
sound_external_audio_enable(5, 5);
/*
//unsigned char *tno = (unsigned char *) 0x6000CCD;
slPrintHex(vtno, slLocate(10,8));
//unsigned short *rep = (unsigned short *) 0x6000CCF;
slPrintHex(vrep, slLocate(10,9));
slPrint((Uint8 *)GFS_IdToName(2), slLocate(10,11));
slPrint((Uint8 *)GFS_IdToName(3), slLocate(10,12));
slPrint((char *)GFS_IdToName(vrep), slLocate(10,13));
*/
ChangeDir(GFS_IdToName(vrep));
//slPrint((Uint8 *)GFS_IdToName(2), slLocate(10,14));
//slPrint((Uint8 *)GFS_IdToName(3), slLocate(10,15));
load_drv(ADX_MASTER_768);
// add_raw_pcm_buffer(0,SOUNDRATE,nBurnSoundLen*20);
#else
char sound_map[] = {0xff,0xff,0xff,0xff};//,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
//slPrint("init sound ",slLocate(2,21));
#ifdef ACTION_REPLAY
slInitSound(sddrvstsk , sizeof(sddrvstsk) , (Uint8 *)sound_map , sizeof(sound_map)) ;
#else
#define SDDRV_NAME "SDDRVS.TSK"
#define SDDRV_SIZE 26610 //0x7000
#define SDDRV_ADDR 0x00202000//0x6080000
unsigned char *sndDrvAddr;
sndDrvAddr = (unsigned char *)SDDRV_ADDR;
GFS_Load(GFS_NameToId((Sint8*)SDDRV_NAME),0,(void *) sndDrvAddr,SDDRV_SIZE);
slInitSound(sndDrvAddr , SDDRV_SIZE , (Uint8 *)sound_map , sizeof(sound_map)) ;
sndDrvAddr = NULL;
// slPrint(" ",slLocate(2,21));
#endif
#endif
}
if(flags &= SDL_INIT_TIMER)
{
TIM_FRT_INIT(TIM_CKS_32);
TIM_FRT_SET_16(0);
}
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
/*
Uint8 SDL_EventState(Uint8 type, int state)
{
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_WarpMouse(Uint16 x, Uint16 y)
{
}
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_JoystickNumHats(SDL_Joystick *joystick)
{
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_NumJoysticks(void)
{
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_JoystickNumButtons(SDL_Joystick *joystick)
{
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
SDL_Joystick * SDL_JoystickOpen(int device_index)
{
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_JoystickUpdate(void)
{
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_JoystickClose(SDL_Joystick *joystick)
{
}
*/
//--------------------------------------------------------------------------------------------------------------------------------------
/*SDLMod SDL_GetModState(void)
{
//slPrint("SDL_GetModState empty" ,slLocate(2,22));
return KMOD_NONE;
}
//--------------------------------------------------------------------------------------------------------------------------------------
SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode)
{
return SDL_GRAB_OFF;
}
//--------------------------------------------------------------------------------------------------------------------------------------
Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button)
{
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat)
{
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis)
{
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
Uint8 SDL_GetMouseState(int *x, int *y)
{
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_LockSurface(SDL_Surface *surface)
{
return 0;
}*/
//--------------------------------------------------------------------------------------------------------------------------------------
/*Uint32 SDL_MapRGB (SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
{
return RGB(r>>3,g>>3,b>>3);
}*/
//--------------------------------------------------------------------------------------------------------------------------------------
//int nb_unlock =0;
void SDL_UnlockSurface(SDL_Surface *surface)
{
unsigned short i; // vbt : le plus rapide
unsigned char *surfacePtr = (unsigned char*)surface->pixels;
unsigned int *nbg1Ptr = (unsigned int*)VDP2_VRAM_A0;
for (i = 0; i < screenHeight; i++)
{
// DMA_ScuMemCopy((unsigned char*)(VDP2_VRAM_A0 + (i<<9)), (unsigned char*)(surface->pixels + (i * screenWidth)), screenWidth); // vbt 20-22fps
// SCU_DMAWait();
// memcpyl((unsigned long*)(VDP2_VRAM_A0 + (i<<9)), (unsigned long*)(surface->pixels + (i * screenWidth)), screenWidth); // vbt : 22-24fps
// vbt : remttre la copie dma
// slDMACopy((unsigned long*)surfacePtr,(void *)(VDP2_VRAM_A0 + (i<<9)),screenWidth);
slDMACopy((unsigned long*)surfacePtr,(void *)nbg1Ptr,screenWidth); // vbt à remettre !!!
surfacePtr+=screenWidth;
// nb_unlock+=screenWidth;
nbg1Ptr+=128;
}
slDMAWait();
}
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
{
Sint8 err=0;
memcpy(obtained,desired,sizeof(SDL_AudioSpec));
#ifdef PONY
#else
Sint32 oct, shift_freq, fns;
Uint8 i;
for (i=0; i<4; i++)
{
m_dat[i].mode = 0;
if(desired->format==AUDIO_U8 || desired->format==AUDIO_S8) m_dat[i].mode|=_PCM8Bit;
if(desired->format==AUDIO_U16LSB || desired->format==AUDIO_S16LSB) m_dat[i].mode|=_PCM16Bit;
if(desired->channels==1) m_dat[i].mode|=_Mono;
if(desired->channels==2) m_dat[i].mode|=_Stereo;
oct = PCM_CALC_OCT(desired->freq);
shift_freq = PCM_CALC_SHIFT_FREQ(oct);
fns = PCM_CALC_FNS(desired->freq, shift_freq);
m_dat[i].pitch =PCM_SET_PITCH_WORD(oct, fns);
m_dat[i].level = 127;
m_dat[i].channel = i*2;
//m_dat[i].efselectR = i;
/*
if(!slPCMParmChange(&m_dat[i]))
{
err--;
} */
// slSynch(); // vbt 26/05/2019 remis // change rien
}
#endif
return err;
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_CloseAudio(void)
{
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_PauseAudio(int pause_on)
{
#ifdef PONY
Uint8 i;
for (i=0;i<4;i++)
pcm_cease(i);
#else
Uint8 i;
for (i=0;i<4;i++)
slPCMOff(&m_dat[i]);
#endif
}
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_UpperBlit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
{
unsigned char *surfacePtr = (unsigned char*)src->pixels + ((srcrect->y) * src->pitch) + srcrect->x;
// unsigned char *surfacePtrD = (unsigned char*)dst->pixels + (dstrect->y* dst->pitch)+ dstrect->x;
unsigned int *nbg1Ptr = (unsigned int*)(VDP2_VRAM_A0 + (dstrect->y<<9)+ dstrect->x);
if((srcrect)!=NULL)
for( Sint16 i=0;i<srcrect->h;i++)
{
// slDMACopy((unsigned long*)((byte*)src->pixels + ((i + srcrect->y) * src->pitch) + srcrect->x),(unsigned long*)(void *)(VDP2_VRAM_A0 + ((i + dstrect->y)<<9)+ dstrect->x),srcrect->w);
// memcpyl((unsigned long*)nbg1Ptr, (unsigned long*)surfacePtr, srcrect->w); // vbt : 22-24fps
// VBT copie en VRAM au lieu de copier dans la destination
// slDMACopy((unsigned long*)surfacePtr,(unsigned long*)(void *)surfacePtrD,dstrect->w); // vbt à remettre
// memcpy(surfacePtrD,surfacePtr,srcrect->w);
slDMACopy((unsigned long*)surfacePtr,(unsigned long*)(void *)nbg1Ptr,srcrect->w); // vbt à remettre
// slDMACopy((unsigned long*)((byte*)src->pixels + ((i + srcrect->y) * src->pitch) + srcrect->x),(unsigned long*)(void *)(VDP2_VRAM_A0 + ((i + dstrect->y)<<9)+ dstrect->x),srcrect->w);
surfacePtr+=src->pitch;
// surfacePtrD+=352;
// nb_unlock+=srcrect->w;
nbg1Ptr+=128;
}
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
/*void SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects)
{
// slBMPut(0, 0, 320-1, 240-1, (Sint8*)screen->pixels);
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_UpdateRect (SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
{
//slPrint("SDL_UpdateRect empty ",slLocate(10,22));
}
*/
//--------------------------------------------------------------------------------------------------------------------------------------
int SDL_FillRect (SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color)
{
if((dst)!=NULL)
if((dstrect)!=NULL)
{
// slBMBoxFill(dstrect->x, dstrect->y, dstrect->x + dstrect->w - 1, dstrect->y + dstrect->h - 1, color);
Uint8*d = (Uint8*)dst->pixels + dstrect->x + dstrect->y*screenWidth;
int w = dstrect->w;
int p = dst->pitch;
for( Sint16 i=0;i<dstrect->h;i++)
{
memset(d,color,dstrect->w);
d+=dst->pitch;
// nb_unlock+=dst->pitch;
}
}
else
{
// slBMBoxFill(dstrect->x, dstrect->y, dstrect->x + dstrect->w - 1, dstrect->y + dstrect->h - 1, color);
memset(dst->pixels,color,screenWidth*screenHeight);
// nb_unlock+=screenWidth*screenHeight;
}
return 0;
}
//--------------------------------------------------------------------------------------------------------------------------------------
SDL_Surface * SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
SDL_Surface *screeny;
screeny = (SDL_Surface*)malloc(sizeof(SDL_Surface));
CHECKMALLOCRESULT(screeny);
screeny->pixels = (unsigned char*)malloc(sizeof(unsigned char)*width*height);
// screeny->pixels = (unsigned char*)0x002E0000;
CHECKMALLOCRESULT(screeny->pixels);
screeny->pitch = width;
screeny->w = width;
screeny->h = height;
return screeny;
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_Quit(void)
{
SYS_Exit(0);
}
//--------------------------------------------------------------------------------------------------------------------------------------
char * SDL_GetError(void)
{
return (char*)"Error !!!";
}
//--------------------------------------------------------------------------------------------------------------------------------------
const SDL_VideoInfo * SDL_GetVideoInfo(void)
{
SDL_VideoInfo vidInfo;
// vidInfo = (SDL_VideoInfo *)malloc(sizeof(SDL_VideoInfo));
// CHECKMALLOCRESULT(vidInfo);
vidInfo.vfmt = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat));
CHECKMALLOCRESULT(vidInfo.vfmt);
vidInfo.vfmt->BitsPerPixel = 8;
return &vidInfo;
}
//--------------------------------------------------------------------------------------------------------------------------------------
SDL_Rect ** SDL_ListModes(SDL_PixelFormat *format, Uint32 flags)
{
return (SDL_Rect **)-1;
}
//--------------------------------------------------------------------------------------------------------------------------------------
/*int SDL_SetPalette(SDL_Surface *surface, int flags, SDL_Color *colors, int firstcolor, int ncolors)
{
SDL_SetColors(surface, colors, firstcolor, ncolors);
return 0;
}*/
//--------------------------------------------------------------------------------------------------------------------------------------
/*
void SDL_WM_SetCaption(const char *title, const char *icon)
{
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_WM_GetCaption(char **title, char **icon)
{
}
//--------------------------------------------------------------------------------------------------------------------------------------
SDL_Surface * SDL_CreateRGBSurfaceFrom(void *pixels,
int width, int height, int depth, int pitch,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
return NULL;
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask)
{
}
*/
/*
<vbt> :) looks easy but hard for me
<MartinMan> hmm
<MartinMan> ah
<vbt> for me at first poll I can add multiple events
<MartinMan> no, you just need to return 1 at a time
<vbt> then return the first event not executed
<MartinMan> First, make a list of all supported buttons/directions
<MartinMan> then you assign a number (starting from 0) to each of them
<MartinMan> then when poll() is called, you increase the number until you find a changed button/direction
<MartinMan> and if no more left, return false
<MartinMan> of course you need to store and update a joypad state variable to look for changed buttons/directions
*/
// boucle si UP+RIGHT ou UP+LEFT
/*
sc_1, sc_2, sc_3, sc_4
*/
void SDL_PollEvent(int start,int end, SDL_Event *event)
{
Uint16 data = 0;
Uint8 i,found=0;
if(Per_Connect1) {
// push = ~Smpc_Peripheral[0].push;
if(start!=8)
data = ~Smpc_Peripheral[0].data;
else
data = ~Smpc_Peripheral[0].push;
}
if(data & PER_DGT_ST && data & PER_DGT_TA && data & PER_DGT_TB && data & PER_DGT_TC)
{
event->type = SDL_QUIT;
return ;
}
unsigned char *evt=(unsigned char *)vbt_event+start;
for (i=start;i <end; i++)
{
if(data & pad_asign[i])
{
if(*evt!=SDL_KEYDOWN)
{
*evt=SDL_KEYDOWN;
found=1;
break;
}
}
else
{
if(*evt==SDL_KEYDOWN)
{
*evt=SDL_KEYUP;
found=1;
break;
}
*evt=0;
}
evt++;
}
/*
if(start==0)
{
if(data & pad_asign[0])
{
if(! (data & pad_asign[2]))
Keyboard[sc_RightArrow]=0;
if(! (data & pad_asign[3]))
Keyboard[sc_LeftArrow]=0;
}
if(data & pad_asign[1])
{
if(! (data & pad_asign[2]))
Keyboard[sc_RightArrow]=0;
if(! (data & pad_asign[3]))
Keyboard[sc_LeftArrow]=0;
}
if(data & pad_asign[2])
Keyboard[sc_RightArrow]=1;
if(data & pad_asign[3])
Keyboard[sc_LeftArrow]=1;
// IN_ClearKeysDown();
}
*/
if(found)
{
event->type = *evt;
if(*evt==SDL_KEYUP)
{
*evt = SDL_NOEVENT;
}
switch(i)
{
case 4:/*PER_DGT_TA: */
event->key.keysym.sym = SDLK_KP_ENTER;
break;
case 5:/*PER_DGT_TB: */
event->key.keysym.sym = SDLK_SPACE;
break;
case 6:/*PER_DGT_TC: */
event->key.keysym.sym = SDLK_RCTRL;
break;
case 7:/*PER_DGT_ST: */
event->key.keysym.sym = SDLK_ESCAPE;
break;
case 8:/*PER_DGT_TX: */
// event->key.keysym.sym = SDLK_RALT;
buttonstate[bt_prevweapon] = true;
CheckWeaponChange ();
event->type = SDL_NOEVENT;
break;
case 9:/*PER_DGT_TY: */
// event->key.keysym.sym = SDLK_RSHIFT;
buttonstate[bt_nextweapon] = true;
CheckWeaponChange ();
event->type = SDL_NOEVENT;
break;
case 10:/*PER_DGT_TZ: */
event->key.keysym.sym = SDLK_RSHIFT; // speed
break;
case 11:/*PER_DGT_TL: */
event->key.keysym.sym = SDLK_RALT; // strafe
// buttonstate[bt_prevweapon] = true;
// CheckWeaponChange ();
break;
case 12:/*PER_DGT_TR: */
event->key.keysym.sym = SDLK_RALT; // strafe
// buttonstate[bt_nextweapon] = true;
// CheckWeaponChange ();
break;
case 3:/*PER_DGT_KL: */
event->key.keysym.sym = SDLK_LEFT;
break;
case 2:/*PER_DGT_KR: */
event->key.keysym.sym = SDLK_RIGHT;
break;
case 1:/*PER_DGT_KD: */
event->key.keysym.sym = SDLK_DOWN;
break;
case 0:/*PER_DGT_KU: */
event->key.keysym.sym = SDLK_UP;
break;
default:
event->key.keysym.sym = SDLK_LAST;//SDLK_FIRST;
break;
}
return;
}
//IN_ClearKeysDown();
event->type = SDL_KEYUP;
// return found;
}
//--------------------------------------------------------------------------------------------------------------------------------------
/*
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_DestroyMutex(SDL_mutex *mutex)
{
}
//--------------------------------------------------------------------------------------------------------------------------------------
void Mix_FreeChunk(Mix_Chunk *chunk)
{
}
//--------------------------------------------------------------------------------------------------------------------------------------
Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
{
return NULL;
}*/
//--------------------------------------------------------------------------------------------------------------------------------------
int Mix_PlayChannel (int channel, Mix_Chunk *chunk, int loops)
{
// slPrintHex(channel,slLocate(2,10));
// slPrintHex(&chunk->abuf[0],slLocate(2,11));
// slPCMOn(sounds[chunk].pcm, sounds[chunk].data, sounds[chunk].size);
#ifdef PONY
pcm_play(channel, PCM_SEMI, 6);
#else
unsigned char i;
if(chunk->alen>0 && chunk->alen <100000)
for(i=0;i<4;i++)
{
if(!slPCMStat(&m_dat[i]))
{
//slPCMOff(&m_dat[i]);
//slPCMParmChange(&m_dat[i]);
slSndFlush() ;
// vbt 26/07/2020 : ? remettre
m_dat[i].mode= _PCM8Bit;
slPCMOn(&m_dat[i],chunk->abuf,chunk->alen);
break;
}
}
#endif
return 1;
}
//--------------------------------------------------------------------------------------------------------------------------------------
Uint32 SDL_GetTicks(void)
{
Uint32 tmp = TIM_FRT_CNT_TO_MCR(TIM_FRT_GET_16())+previousmillis;
Uint32 tmp2 = tmp/ 1000;
previouscount += tmp2;
TIM_FRT_SET_16(0);
previousmillis= (tmp-(tmp2*1000));
//set_imask(imask);
//
return previouscount;
}
//--------------------------------------------------------------------------------------------------------------------------------------
void SDL_Delay(long delay)
{
// sc_usleep(delay);
}
//--------------------------------------------------------------------------------------------------------------------------------------
#define TVSTAT (*(volatile Uint16 *)0x25F80004)
void wait_vblank(int nb)
{
for(int i=0;i<nb;i++)
{
// slSynch();
while((TVSTAT & 8) == 8);
while((TVSTAT & 8) == 0);
}
}
//--------------------------------------------------------------------------------------------------------------------------------------
void sc_tmr_start(void)
{
TIM_FRT_INIT(8); // 8, 32 or 128
TIM_FRT_SET_16(0);
}
//--------------------------------------------------------------------------------------------------------------------------------------
unsigned short sc_tmr_lap(void)
{
return (TIM_FRT_GET_16());
}
//--------------------------------------------------------------------------------------------------------------------------------------
unsigned short sc_tmr_lap_usec(void)
{
Float32 f = TIM_FRT_CNT_TO_MCR(TIM_FRT_GET_16());
return ((unsigned short)(f));
}
//--------------------------------------------------------------------------------------------------------------------------------------
unsigned long sc_tmr_tick2usec(unsigned long tick)
{
Float32 f = TIM_FRT_CNT_TO_MCR(tick);
return ((unsigned long)(f));
}
//--------------------------------------------------------------------------------------------------------------------------------------
void sc_tick_sleep(unsigned short tick)
{
sc_tmr_start();
while(sc_tmr_lap() < tick);
}
//--------------------------------------------------------------------------------------------------------------------------------------
void sc_usleep(unsigned long usec)
{
/* Convert delay to tick value. */
unsigned long delay_tick = 0;
if(usec < 50*1000)
{ /* Compute tick value at good precision for delay lower than 50 msec. */
delay_tick = (usec*60000) / (sc_tmr_tick2usec(60000));
}
else
{ /* Poor precision, but no overflow (up to 42 seconds) for higher values. */
delay_tick = (usec*100) / (sc_tmr_tick2usec(100));
}
/* Sleep at most 60000 ticks. */
unsigned long i;
for(i=0; i<delay_tick; i+=60000)
{
unsigned long s = ((i+60000) < delay_tick ? 60000 : delay_tick - i);
sc_tick_sleep(s);
}
}
//--------------------------------------------------------------------------------------------------------------------------------------
void Pal2CRAM( Uint16 *Pal_Data , void *Col_Adr , Uint32 suu )
{
Uint16 i;
Uint16 *VRAM;
VRAM = (Uint16 *)Col_Adr;
for( i = 0; i < suu; i++ )
*(VRAM++) = *(Pal_Data++);
}
//--------------------------------------------------------------------------------------------------------------------------------------
#ifndef ACTION_REPLAY
void InitCD()
{
Uint32 lib_work[GFS_WORK_SIZE(MAX_OPEN) / sizeof(Uint32)];
GfsDirTbl dirtbl;
#ifndef ACTION_REPLAY
#ifdef VBT
CdUnlock();
#endif
// Sint32 ret;
CDC_CdInit(0x00,0x00,0x05,0x0f);
unsigned int *dds = (unsigned int *) 0x6000CCC;
unsigned char *tno = (unsigned char *) 0x6000CCD;
unsigned short *rep = (unsigned short *) 0x6000CCF;
vdds = SWAP_BYTES_32(*dds);
vtno = *tno;
vrep = SWAP_BYTES_16(*rep);
*((Uint32 *)GFS_DDS_ADDR) = vdds;
GFS_DIRTBL_TYPE(&dirtbl) = GFS_DIR_NAME;
GFS_DIRTBL_DIRNAME(&dirtbl) = dir_name;
GFS_DIRTBL_NDIR(&dirtbl) = MAX_DIR;
GFS_Init(MAX_OPEN, lib_work, &dirtbl);
*dds = SWAP_BYTES_32(vdds);
#endif
}
//--------------------------------------------------------------------------------------------------------------------------------------
void ChangeDir(char *dirname)
{
#ifndef ACTION_REPLAY
Sint32 fid;
GfsDirTbl dirtbl;