-
Notifications
You must be signed in to change notification settings - Fork 0
/
preferencesgui.c
2188 lines (2040 loc) · 62.2 KB
/
preferencesgui.c
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
/* :ts=2 preferencesgui.c
*
* cp4 - Commodore C+4 emulator
* Copyright (C) 1998 Gáti Gergely
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* e-mail: [email protected]
*/
#include <proto/asl.h>
#include <xpk/xpk.h>
#include <clib/xpkmaster_protos.h>
#include <proto/dos.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <utility/hooks.h>
#include <proto/locale.h>
#include <libraries/locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "common.h"
#include "p4req.h"
#include "c2p_module.h"
#include "keymap.h"
#include "cp4_loc.h"
#include "soft_iec.h"
#include "macros.h"
#include "snapshot.h"
#include "cp4_ver.h"
/* from cp4_loc.c
*/
extern struct LocaleBase *LocaleBase;
/*
* from 7501.asm
*/
extern int initsid(void);
extern int endsid(void);
/*
* from kmapedit.c
*/
extern struct Window *kmapeditWnd;
/*
* változók a dbg.c-bõl
*/
extern void savemem(char *filename,int from,int to);
/*
* változók a cp4-bõl
*/
extern int opt_direct; // 1-direct mode
extern int opt_xpk; // 0-nem, 1-igen
extern int opt_xpkeff; // hatásfok: 0-100%
extern char *opt_xpktype; // xpk subype (4 char + \0)
extern char *opt_palettefile; // palette filename
extern int opt_listwidth;
extern int load(char *filename,int *to2d);
extern u_byte *p4ram; // ram
extern u_byte *p4rom;
extern char *opt_keymap; // keymapfile
extern char *opt_p4dir; // default dir
extern int opt_nosound; // hang? (0-van)
extern int opt_limit; // ==0 nem kell speed limit
extern int opt_percent; // ==1 kell százalék
extern int opt_iec; // 0-nemkell 1-van -1-nincs
extern int opt_realtime; // 0-nincs 1-realtime
extern unsigned long opt_scrmode; // scrmode
extern unsigned long opt_overscan; // overscan
extern unsigned long opt_twoscr; // twoscr
extern char *opt_c2p; // name of c2p
extern int opt_sid; // 1-enable 0-disable
extern int opt_onscreendisplay; // led stb. (0-nem)
extern int opt_drive08; // 0-semmi 1-iec 2-soft
extern int opt_drive09;
extern int opt_drive10;
extern int opt_drive11;
/*
* változók a ted-bõl
*/
extern u_byte opt_border;
extern void loadpalette(char *file,struct Window *win);
extern int setkeymap(char *name);
extern int testkeymap(char *name); // 0-ok
extern u_byte skipflag;
extern long skiptime;
extern struct iecbase *IECBase;
extern struct Library *XpkBase;
extern int nojoy;
extern int getjoy(void);
extern void freejoy(void);
extern u_byte userblank;
extern struct c2pvec *c2pv;
extern char c2pdir[];
extern char *makefilename(struct FileRequester *f);
extern void tederror(char *str);
extern int initdisplay(void);
extern void freedisplay(void);
extern struct FileRequester *frq;
extern struct ScreenModeRequester *scrrq;
extern ULONG otvened1,otvened2; // 1/2 frame otvenedsec
extern ULONG hz80,hz1,hz2;
extern ULONG otvenedsec; // ebbe
extern u_byte joyfireup; // '$40' normal
extern u_byte joykeyindex;
extern u_byte joyfiredown;
extern u_byte joyfire[];
extern unsigned char chalf; // percent külsõ szín
extern unsigned char cfull; // percent belsõ szín
extern struct Screen *cp4Scr;
extern struct Window *cp4Window;
extern void soundpause(void);
extern void soundresume(void);
extern int initaudio(void);
extern void freeaudio(void);
extern int vol1,vol2,per1,per2;
extern int actinchar;
extern int actcharaddr;
extern int actraster;
extern int numraster;
extern int hscroll;
extern int vscroll;
extern int colplace;
extern int textplace;
extern int curpos;
extern int leftborder;
extern u_word rasreq;
extern u_word gfxaddr;
extern u_byte colback;
extern u_byte col1;
extern u_byte col2;
extern u_byte col3;
extern u_byte actrom;
extern u_byte colbord;
extern unsigned long colbordlong;
extern u_byte ec1;
extern u_byte ec2;
extern u_byte ec3;
extern int tbordminus;
extern int rightborder;
extern int cols;
extern int sideborders;
extern u_byte cureor;
extern u_byte *amirasaddr;
extern unsigned char *chunky;
int DefPrfLeft=0;
int DefPrfTop=-1;
int prefsgui(void); // called from dbg.c
int prefsguis(void); // called from 7501.asm
int ptwoframe; // readed from 7501.asm
int pswapjoy;
int plimit; // O
int pc2p; // !=0 changed c2p
int pscr; // !=0 changed scrmode
static int c2pInfoWidth=0; // listview szélessége
static unsigned long newscrmode;
static unsigned long newoverscan;
static char *newpalette;
static char *newc2pname;
static int pERROR=0;
static char *c2pInfo=NULL,*c2pAuthor=NULL,*c2pName=NULL;
static char kmapname[220];
static char old_keymaps[450];
static char *old_keymap;
static char *drivecyc[]={
"1 ",
"2 ",
"3 ",
"4 ",
NULL
};
static char *drivetypecyc[]={
"a ",
"b ",
"c ",
NULL
};
static int actdrive; // bal cycle állása
static char driveoptname[]="D64NAME___";
static char drive2optname[]="DRIVE__";
static int drivestore[4];
static char *d64names[4];
// xpk support
static u_byte *xpkbuffer=NULL;
static int xpkbufferpnt=0;
static int xpkbufferlen=0;
static ULONG checksum;
static char *xpknames=NULL;
static struct NewMenu *xpknewmenu=NULL;
static int xpknumpacker=0;
static struct Menu *xpkmenu=NULL;
int addxpkmenus(struct Menu *origmenu);
void freexpkmenus(struct Menu *menu);
void handlexpkselect(int num);
#include "prefs.h"
#include "preferences.c"
struct c2ps {
struct Node node; // ln_Name == filaname without extension
char *filename; // full path/filename
};
static void getgui(void);
static int ret; // retval
static struct Requester InvisibleRequester;
static struct NameInfo scrmodename;
static struct List c2plist={NULL,NULL,NULL,0,0};
static char *overnames[]={
NULL, NULL, NULL, NULL, NULL
};
static struct Hook D64Hook;
static struct Hook P4Hook;
static struct Hook SnapHook;
static struct Hook PaletteHook;
static struct Hook DateHook;
static char *DateHook_Data;
static int DateHook_Count=0;
static void setcheckmarkfull(int menunum,int itemnum,int sub,int state) {
struct MenuItem *n;
if(NULL==(n=ItemAddress(cp4prefsMenus,FULLMENUNUM(menunum,itemnum,sub)))) return;
ClearMenuStrip(cp4prefsWnd);
if(state==TRUE) n->Flags|=CHECKED;
else n->Flags&=~CHECKED;
ResetMenuStrip(cp4prefsWnd,cp4prefsMenus);
} // setcheckmarkfull
static void setcheckmark(int menunum,int itemnum,int state) {
struct MenuItem *n;
if(NULL==(n=ItemAddress(cp4prefsMenus,FULLMENUNUM(menunum,itemnum,0)))) return;
ClearMenuStrip(cp4prefsWnd);
if(state==TRUE) n->Flags|=CHECKED;
else n->Flags&=~CHECKED;
ResetMenuStrip(cp4prefsWnd,cp4prefsMenus);
} // setcheckmark
static int getcheckmarkfull(int menunum,int itemnum,int sub) {
struct MenuItem *n;
if(NULL==(n=ItemAddress(cp4prefsMenus,FULLMENUNUM(menunum,itemnum,sub)))) return(-1);
if((n->Flags&CHECKED)!=0) return(TRUE);
return(FALSE);
} // getcheckmarkfull
static int getcheckmark(int menunum,int itemnum) {
struct MenuItem *n;
if(NULL==(n=ItemAddress(cp4prefsMenus,FULLMENUNUM(menunum,itemnum,0)))) return(-1);
if((n->Flags&CHECKED)!=0) return(TRUE);
return(FALSE);
} // getcheckmark
static void disableitemfull(int menunum,int itemnum,int sub,int state) {
if(state==TRUE) OffMenu(cp4prefsWnd,FULLMENUNUM(menunum,itemnum,sub));
else OnMenu(cp4prefsWnd,FULLMENUNUM(menunum,itemnum,sub));
} // disableitemfull
static void disableitem(int menunum,int itemnum,int state) {
if(state==TRUE) OffMenu(cp4prefsWnd,FULLMENUNUM(menunum,itemnum,0));
else OnMenu(cp4prefsWnd,FULLMENUNUM(menunum,itemnum,0));
} // disableitem
int addxpkmenus(struct Menu *origmenu) { // 104 byte loss!! ERR
static struct XpkPackerList list;
static struct TagItem pqt[]={
{ XPK_PackersQuery, (ULONG)&list },
{ TAG_DONE,0 }
};
static struct XpkMode xminfo;
static struct XpkPackerInfo xpinfo;
static struct TagItem mqt[]={
{ XPK_PackMethod, 0 },
{ XPK_ModeQuery, (ULONG)&xminfo },
{ XPK_PackMode, 99 },
{ TAG_DONE,0 }
};
static struct TagItem p2qt[]={
{ XPK_PackMethod, 0 },
{ XPK_PackerQuery, (ULONG)&xpinfo },
{ TAG_DONE,0 }
};
struct NewMenu *nm;
struct MenuItem *n;
struct Menu *m;
int i;
ULONG mx;
xpknumpacker=0;
xpinfo.xpi_Name[0]='\0';
xminfo.xm_Description[0]='\0';
if(XpkBase==NULL) return(-1);
if(XpkQuery(pqt)) return(-1);
if(NULL==(xpknames=calloc(list.xpl_NumPackers,5))) return(-1);
if(NULL==(xpknewmenu=calloc(list.xpl_NumPackers+2,sizeof(struct NewMenu)))) return(-1);
for(i=0;i<list.xpl_NumPackers;i++) {
if(xpknumpacker>30) continue; // max 31 almenü!
mqt[0].ti_Data=(ULONG)list.xpl_Packer[i];
p2qt[0].ti_Data=(ULONG)list.xpl_Packer[i];
if(XpkQuery(mqt)) continue;
if(XpkQuery(p2qt)) continue;
if((xpinfo.xpi_Flags&(XPKIF_NEEDPASSWD|XPKIF_LOSSY))!=0) continue;
if((xminfo.xm_Ratio/10)<2) continue;
strcpy(&xpknames[xpknumpacker*5],list.xpl_Packer[i]);
nm=&xpknewmenu[xpknumpacker];
nm->nm_Type=NM_SUB;
nm->nm_Label=&xpknames[xpknumpacker*5];
nm->nm_Flags=CHECKIT|MENUTOGGLE;
nm->nm_UserData=(APTR)xpknumpacker+1;
mx=~((1<<((ULONG)(xpknumpacker+2)))|1);
nm->nm_MutualExclude=mx;
if(strcmp(opt_xpktype,nm->nm_Label)==0) nm->nm_Flags|=CHECKED;
if(opt_xpk==0) nm->nm_Flags|=NM_ITEMDISABLED;
xpknumpacker++;
nm=&xpknewmenu[xpknumpacker];
nm->nm_Type=NM_END;
}
if(xpknumpacker==0) return(0);
if(!(m=CreateMenus(xpknewmenu,GTMN_FrontPen,0L,TAG_DONE,0L))) return(-1);
xpkmenu=m;
if(NULL==(n=ItemAddress(origmenu,FULLMENUNUM(M_PREFS,M2_XPK,M2_XPK_LASTFIX)))) return(-1);
if(n->NextItem!=NULL) return(-1);
n->NextItem=(struct MenuItem *)m;
return(0);
}
void freexpkmenus(struct Menu *menu) { // 104 byte loss!! ERR
struct MenuItem *n;
if(NULL!=(n=ItemAddress(menu,FULLMENUNUM(M_PREFS,M2_XPK,M2_XPK_LASTFIX)))) n->NextItem=NULL;
if(xpkmenu!=NULL) FreeMenus(xpkmenu);
xpkmenu=NULL;
if(xpknames!=NULL) free(xpknames);
xpknames=NULL;
if(xpknewmenu!=NULL) free(xpknewmenu);
xpknewmenu=NULL;
}
void handlexpkselect(int num) {
int i,v;
char *n;
if(xpknames==NULL) return;
n=&xpknames[(num-1)*5];
AddOption("XPKTYPE",n);
opt_xpktype=GetOption("XPKTYPE","----");
for(i=0;i<xpknumpacker;i++) {
n=&xpknames[i*5];
v=FALSE;
if(strcmp(n,opt_xpktype)==0) v=TRUE;
setcheckmarkfull(M_PREFS,M2_XPK,M2_XPK_FIRSTPCK+i,v);
}
}
static char *getpath(char *filename) {
static char n[230];
char *a;
if(DOSBase==NULL) return(NULL);
a=PathPart(filename);
strncpy(n,filename,(a-filename));
n[(a-filename)+1]='\0';
// SetWindowTitles(cp4prefsWnd,(UBYTE *)~0,n);
return(n);
}
static void SleepWindow(void) {
static struct TagItem BusyPointerTagList[]={
{WA_BusyPointer,TRUE},
{TAG_END,0}
};
if(cp4prefsWnd) {
InitRequester(&InvisibleRequester);
Request(&InvisibleRequester,cp4prefsWnd);
SetWindowPointerA(cp4prefsWnd,BusyPointerTagList);
}
}
static void AwakeWindow(void) {
if(cp4prefsWnd) {
EndRequest(&InvisibleRequester,cp4prefsWnd);
SetWindowPointerA(cp4prefsWnd,NULL);
}
}
/*
* egy teljes path+file-névbõl elkészíti a filenevet
*/
void getpurename(char *fullname,char *name) {
int i;
if(fullname==NULL) return;
i=strlen(fullname);
for(;i>=0&&fullname[i]!=':'&&fullname[i]!='/';i--);
strcpy(name,&fullname[i+1]);
} // getpurename()
/*
* felszabadítja a c2p listát
*/
static void freec2ps(void) {
struct c2ps *node;
if(c2plist.lh_Head==NULL) { // inicializálás
c2plist.lh_Head=(struct Node *)&c2plist.lh_Tail;
c2plist.lh_Tail=NULL;
c2plist.lh_TailPred=(struct Node *)&c2plist.lh_Head;
c2plist.lh_Type=0;
} else { // free
while(NULL!=(node=(struct c2ps *)RemHead(&c2plist))) {
if(node->filename!=NULL) FreeVec(node->filename);
if(node->node.ln_Name!=NULL) FreeVec(node->node.ln_Name);
FreeVec(node);
}
}
} // freec2ps
/*
* Egy exec listához hozzáad egy elemet, név szerinti rendezésben
*/
static void AddSorted(struct List *ls,struct Node *nd) {
struct Node *n;
if(ls->lh_Head->ln_Succ) {
for(n=ls->lh_Head;n->ln_Succ;n=n->ln_Succ) if(strcmp(nd->ln_Name,n->ln_Name)<=0) break;
Insert(ls,nd,n->ln_Pred);
} else AddTail(ls,nd);
} // AddSorted()
/*
* read c2p-directory into a linked list
* ret: hány file-t talált, ami stimmel
*/
static int readc2ps(ULONG *selected) {
static char pat[50];
struct FileInfoBlock *fib;
struct Node *sel=NULL,*n;
struct c2ps *newc2p;
int r=0,i;
BPTR lock;
freec2ps();
*selected=~0;
if(NULL!=(fib=AllocDosObject(DOS_FIB,NULL))) {
if(0!=(lock=Lock("PROGDIR:c2p",ACCESS_READ))) {
if(-1!=ParsePatternNoCase("#?.c2p",pat,50)) {
Examine(lock,fib);
while(ExNext(lock,fib)) {
if(fib->fib_DirEntryType<0) {
if(MatchPatternNoCase(pat,fib->fib_FileName)) {
if(NULL!=(newc2p=AllocVec(sizeof(struct c2ps),MEMF_ANY))) {
if(NULL!=(newc2p->filename=AllocVec(strlen(fib->fib_FileName)+1,MEMF_ANY))) {
strcpy(newc2p->filename,fib->fib_FileName);
if(NULL!=(newc2p->node.ln_Name=AllocVec(strlen(fib->fib_FileName)+1,MEMF_ANY))) {
strcpy(newc2p->node.ln_Name,fib->fib_FileName);
newc2p->node.ln_Name[strlen(newc2p->node.ln_Name)-4]='\0';
if(strcmp(newc2pname,fib->fib_FileName)==0) sel=(struct Node *)newc2p;
AddSorted(&c2plist,(struct Node *)newc2p);
r++;
} else {
FreeVec(newc2p->filename);
FreeVec(newc2p);
}
} else FreeVec(newc2p);
}
}
}
}
UnLock(lock);
} else {
p4req1(cp4prefsWnd,P4_ERROR,GetStr(MSG_020B));
pERROR=1;
r=-1;
}
} else {
p4req1(cp4prefsWnd,P4_ERROR,GetStr(MSG_020C));
pERROR=1;
r=-1;
}
FreeDosObject(DOS_FIB,fib);
} else {
p4req1(cp4prefsWnd,P4_ERROR,GetStr(MSG_020D));
pERROR=1;
r=-1;
}
if(r>0&&sel!=NULL) {
for(i=0,n=c2plist.lh_Head;n->ln_Succ;n=n->ln_Succ,i++) if(n==sel) break;
*selected=i;
}
return(r);
} // readc2ps()
/*
* betölti a megadott c2p-rõl az info-kat a
* c2pName, c2pAuthor, c2pInfo globálisokba
*/
static int getc2pinfos(char *filename) {
static char *none="-";
static char c2pname[200];
static char s[44];
struct c2pvec *cv;
struct c2pvec *(*cst)(REG(d0,unsigned long m));
BPTR seg;
if(c2pInfo!=NULL&&c2pInfo!=none) free(c2pInfo);
if(c2pAuthor!=NULL&&c2pAuthor!=none) free(c2pAuthor);
c2pName=none;
c2pInfo=none;
c2pAuthor=none;
if(filename==NULL) return(-1);
if(strlen(newc2pname)>160) return(-1);
strcpy(c2pname,c2pdir);
strcat(c2pname,filename);
if(NULL==(seg=LoadSeg(c2pname))) return(-1);
cst=(struct c2pvec *(*)(REG(d0,unsigned long m)))(((ULONG)seg)*4+4);
cv=cst(C2P_MAGIC);
strcpy(c2pname,cv->c2p_Name);
strcat(c2pname," V");
sprintf(s,"%s.%s",cv->c2p_Version,cv->c2p_Revision);
strcat(c2pname,s);
c2pName=c2pname;
c2pInfo=malloc(strlen(cv->c2p_Info)+1);
if(c2pInfo!=NULL) {
strcpy(c2pInfo,cv->c2p_Info);
c2pAuthor=malloc(strlen(cv->c2p_Author)+4);
if(c2pAuthor!=NULL) {
strcpy(c2pAuthor,GetStr(MSG_0210));
strcat(c2pAuthor," ");
strcat(c2pAuthor,cv->c2p_Author);
} else c2pAuthor=none;
} else c2pInfo=none;
UnLoadSeg(seg);
return(0);
} // getc2pinfos()
/*
* megadja a stringbõl a következõ szó elejét, és annak végét
* ha utolsó szó: NULL
*/
char *skipword(char *s,char **ends) {
char *end;
while(*s!=' '&&*s!='\0') s++;
if(*s=='\0') return(NULL);
s++;
if(*s=='\0') return(NULL);
end=s;
while(*end!=' '&&*end!='\0') end++;
if(*end!='\0') end++;
*ends=end;
return(s);
} // skipword()
/*
* megadja, hogy az input string elsõ hány karaktere fér el az
* adott pixelszélességen... (-1 hiba/semmi sem fér ki)
* 0==minden kifér
* n==az elsõ n char fér csak ki
*/
int teststrlen(char *str,int pix) {
static struct IntuiText itext;
char *tmp;
int len,ret=-1,i,l;
len=strlen(str);
if(NULL!=(tmp=malloc(len+1))) {
itext.ITextFont=&myTextAttr;
itext.NextText=NULL;
itext.IText=tmp;
for(i=0,l=-1;i<len&&l<pix;i++) {
tmp[i]=str[i];
tmp[i+1]='\0';
l=IntuiTextLength(&itext);
}
if(l>pix) ret=i+1;
else if(l!=-1) ret=0;
else ret=-1;
free(tmp);
}
return(ret);
} // teststrlen()
/*
* megadja, hogy honnan kezdve kell új sort kezdeni a
* listview-ban
*/
static char *getnextline(char *s) {
static struct IntuiText itext;
char *now,*endnow;
int store,textinner;
ULONG len=0,l;
textinner=c2pInfoWidth-opt_listwidth;
itext.ITextFont=&myTextAttr;
itext.NextText=NULL;
if(textinner<8) return(NULL);
endnow=s;
while(*endnow!=' '&&*endnow!='\0') endnow++;
if(*endnow=='\0') return(NULL); // egy szóból áll
now=s;
while(now!=NULL&&len<=textinner) {
store=*endnow;
*endnow='\0';
itext.IText=now;
l=IntuiTextLength(&itext);
len+=l;
*endnow=store;
if(len<=textinner) now=skipword(now,&endnow);
}
if(len<=textinner) return(NULL);
if(now!=NULL) *(now-1)='\0';
return(now);
} // getnextline()
/*
* beállítja az info szerint a gc2plist gadgetet
*/
static void setupinfo(char *info) {
static char *mi=NULL;
static struct List ml;
static struct Node *nd;
char *p1;
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gc2pinfo],cp4prefsWnd,NULL,GTLV_Labels,~0,TAG_DONE);
if(mi!=NULL) { free(mi); mi=NULL; }
if(ml.lh_Head!=NULL) while(NULL!=(nd=RemHead(&ml))) free(nd);
ml.lh_Head=(struct Node *)&ml.lh_Tail;
ml.lh_Tail=NULL;
ml.lh_TailPred=(struct Node *)&ml.lh_Head;
ml.lh_Type=0;
if(info!=NULL) {
mi=malloc(strlen(info)+1);
if(mi==NULL) return;
strcpy(mi,info);
p1=mi;
while(p1!=NULL) {
if(NULL==(nd=malloc(sizeof(struct Node)))) return;
nd->ln_Name=p1;
AddTail(&ml,nd);
p1=getnextline(p1);
}
} else return;
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gc2pinfo],cp4prefsWnd,NULL,GTLV_Labels,(ULONG)&ml,TAG_DONE);
} // setupinfo()
/* beállítja a középsõ cycle állását (none/real1541/d64+name)
* 0-none
* 1-iec
* 2-soft
*/
static void updatecyc(int mode,int devaddr) {
static char *tm[]={" ",NULL};
static UBYTE name[17];
static char *modes[]={ "NONE", "IEC", "SOFT" };
int v,d;
char *d64name;
int i;
FILE *f;
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gdrivetypecyc],cp4prefsWnd,NULL,GTCY_Labels,(ULONG)tm,TAG_DONE);
// set d64 name
strcpy(drivetypecyc[2],GetStr(MSG_0301));
driveoptname[8]=(devaddr/10)+'0';
driveoptname[9]=(devaddr%10)+'0';
drive2optname[5]=(devaddr/10)+'0';
drive2optname[6]=(devaddr%10)+'0';
d64name=GetOption(driveoptname,"NONE");
if(strcmp(d64name,"NONE")!=0&&mode==2) {
if(NULL!=(f=fopen(d64name,"rb"))) {
fseek(f,(357*256)+144,SEEK_SET);
fread(name,1,16,f);
fclose(f);
name[16]='\0';
for(i=0;i<17;i++) if(name[i]==0xa0) name[i]=0;
strcat(drivetypecyc[2]," \"");
strcat(drivetypecyc[2],name);
strcat(drivetypecyc[2],"\"");
} else if(mode==2) p4req1(cp4prefsWnd,P4_WARNING,GetStr(MSG_0268));
}
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gdrivetypecyc],cp4prefsWnd,NULL,GTCY_Labels,(ULONG)drivetypecyc,GTCY_Active,mode,TAG_DONE);
if(opt_iec!=0) GT_SetGadgetAttrs(cp4prefsGadgets[GD_gdrivetypecyc],cp4prefsWnd,NULL,GA_Disabled,FALSE,TAG_DONE);
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gdrivetypecyc],cp4prefsWnd,NULL,GTCY_Active,(ULONG)&v,TAG_DONE);
AddOption(drive2optname,modes[v]);
if(actdrive==8) opt_drive08=v;
if(actdrive==9) opt_drive09=v;
if(actdrive==10) opt_drive10=v;
if(actdrive==11) opt_drive11=v;
if(v==2) d=FALSE;
else d=TRUE;
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gd64sel],cp4prefsWnd,NULL,GA_Disabled,(ULONG)d,TAG_DONE);
} // updatecyc()
/*
* gui functs
*/
static int gdriveselcycClicked( void ) { //NEW cyc
int v,i=0;
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gdriveselcyc],cp4prefsWnd,NULL,GTCY_Active,(ULONG)&v,TAG_DONE);
actdrive=v+8;
if(v==0) i=opt_drive08;
if(v==1) i=opt_drive09;
if(v==2) i=opt_drive10;
if(v==3) i=opt_drive11;
updatecyc(i,actdrive);
return(TRUE);
}
static int gdrivetypecycClicked( void ) { //NEW cyc
int v;
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gdrivetypecyc],cp4prefsWnd,NULL,GTCY_Active,(ULONG)&v,TAG_DONE);
updatecyc(v,actdrive);
/*
static char *modes[]={ "NONE", "IEC", "SOFT" };
int v,d;
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gdrivetypecyc],cp4prefsWnd,NULL,GTCY_Active,(ULONG)&v,TAG_DONE);
AddOption(drive2optname,modes[v]);
if(actdrive==8) opt_drive08=v;
if(actdrive==9) opt_drive09=v;
if(actdrive==10) opt_drive10=v;
if(actdrive==11) opt_drive11=v;
if(v==2) d=FALSE;
else d=TRUE;
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gd64sel],cp4prefsWnd,NULL,GA_Disabled,(ULONG)d,TAG_DONE);
*/
return(TRUE);
}
static ULONG SAVEDS REGARGS D64HookFunc(REG(a0,struct Hook *mh),REG(a2,struct FileRequester *fr),REG(a1,struct AnchorPath *ap)) {
if(ap->ap_Info.fib_Size==174848) return(TRUE);
return(FALSE);
} // D64HookFunc()
static void InitD64Hook(void) {
D64Hook.h_Entry=(HOOKFUNC)D64HookFunc;
D64Hook.h_SubEntry=NULL;
D64Hook.h_Data=NULL;
} // InitD64Hook()
static int gd64selClicked( void ) { //NEW butt "?"
char *filename;
InitD64Hook();
if(AslRequestTags(frq,
ASLFR_TitleText,(ULONG)GetStr(MSG_0304),
ASLFR_Window, (ULONG)cp4prefsWnd,
ASLFR_SleepWindow, TRUE,
ASLFR_RejectIcons, TRUE,
ASLFR_DoSaveMode, FALSE,
ASLFR_InitialDrawer, (ULONG)GetOption("D64DIR","PROGDIR:"),
ASLFR_Screen, (ULONG)Scr,
ASLFR_FilterFunc, (ULONG)&D64Hook,
ASLFR_FilterDrawers,FALSE,
TAG_DONE,0L )) {
filename=makefilename(frq);
AddOption("D64DIR",frq->fr_Drawer);
AddOption(driveoptname,filename);
updatecyc(2,actdrive);
}
return(TRUE);
}
static int gscrmodeClicked( void ) {
/* routine when gadget "ScreenMode" is clicked. */
static char name[240];
APTR handle;
SleepWindow();
if(AslRequestTags(scrrq,
ASLSM_Window, (ULONG)cp4prefsWnd,
ASLSM_SleepWindow, FALSE,
ASLSM_InitialOverscanType, newoverscan,
ASLSM_InitialDisplayID, newscrmode,
ASLSM_TitleText,(ULONG)GetStr(MSG_0211),
ASLSM_DoOverscanType, TRUE,
ASLSM_PropertyMask, (ULONG)0,
TAG_DONE,0L)) {
newscrmode=scrrq->sm_DisplayID;
newoverscan=scrrq->sm_OverscanType;
handle=FindDisplayInfo(newscrmode);
if(0<GetDisplayInfoData(handle,(UBYTE *)&scrmodename,sizeof(struct NameInfo),DTAG_NAME,0)) {
if(strlen(scrmodename.Name)>200) GT_SetGadgetAttrs(cp4prefsGadgets[GD_gscrtxt],cp4prefsWnd,NULL,GTTX_Text,(ULONG)scrmodename.Name,TAG_DONE);
else {
strcpy(name,scrmodename.Name);
strcat(name," ");
if(newoverscan<5&&newoverscan>0) strcat(name,overnames[newoverscan]);
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gscrtxt],cp4prefsWnd,NULL,GTTX_Text,(ULONG)name,TAG_DONE);
}
} else {
strcpy(name,GetStr(MSG_01DB));
strcat(name," ");
if(newoverscan<5&&newoverscan>0) strcat(name,overnames[newoverscan]);
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gscrtxt],cp4prefsWnd,NULL,GTTX_Text,(ULONG)name,TAG_DONE);
}
}
AwakeWindow();
return(TRUE);
}
/*
static int gsndClicked( void ) {
// routine when gadget "Sound" is clicked.
int v;
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gsnd],cp4prefsWnd,NULL,GTCB_Checked,(ULONG)&v,TAG_DONE);
setcheckmark(M_PREFS,M2_SOUND,v);
disableitem(M_PREFS,M2_SID,!v);
return(TRUE);
}*/
/*
static int gsplimClicked( void ) {
// routine when gadget "Speed Limit" is clicked.
int v;
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gsplim],cp4prefsWnd,NULL,GTCB_Checked,(ULONG)&v,TAG_DONE);
setcheckmark(M_PREFS,M2_SPLIM,v);
return(TRUE);
}*/
/*
static int gtwoframeClicked( void ) {
// routine when gadget "TwoFrame" is clicked.
int v;
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gtwoframe],cp4prefsWnd,NULL,GTCB_Checked,(ULONG)&v,TAG_DONE);
setcheckmark(M_PREFS,M2_TWOFRAME,v);
return(TRUE);
}*/
/*
static int gswapjoyClicked( void ) {
// routine when gadget "Swap Joys" is clicked.
int v;
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gswapjoy],cp4prefsWnd,NULL,GTCB_Checked,(ULONG)&v,TAG_DONE);
setcheckmark(M_PREFS,M2_SWAPJOY,v);
return(TRUE);
}*/
static int gkeymapClicked( void ) {
/* routine when gadget "KeyMap" is clicked. */
char *filename;
if(AslRequestTags(frq,
ASLFR_TitleText,(ULONG)GetStr(MSG_01D2),
ASLFR_Window, (ULONG)cp4prefsWnd,
ASLFR_SleepWindow, TRUE,
ASLFR_RejectIcons, TRUE,
ASLFR_DoSaveMode, FALSE,
ASLFR_InitialDrawer, (ULONG)"PROGDIR:KeyMap",
ASLFR_Screen, (ULONG)Scr,
ASLFR_FilterFunc, (ULONG)&KMapHook,
ASLFR_FilterDrawers,FALSE,
TAG_DONE,0L )) {
filename=makefilename(frq);
if(0!=setkeymap(filename)) {
p4req1(cp4prefsWnd,P4_WARNING,GetStr(MSG_01D4));
} else {
if(strlen(filename)<420) {
AddOption("KEYMAP",filename);
opt_keymap=GetOption("KEYMAP",NULL);
if(opt_keymap==NULL) p4req1(cp4prefsWnd,P4_ERROR,GetStr(MSG_01D5));
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gkeymaptxt],cp4prefsWnd,NULL,GTTX_Text,(ULONG)frq->rf_File,TAG_DONE);
}
}
}
return(TRUE);
}
static int gc2plistClicked( void ) {
/* routine when gadget "" is clicked. */
struct Node *node;
ULONG sel;
int i;
GT_GetGadgetAttrs(cp4prefsGadgets[GD_gc2plist],cp4prefsWnd,NULL,GTLV_Selected,(ULONG)&sel,TAG_DONE);
if(sel!=~0) {
node=c2plist.lh_Head;
for(i=0;i<sel;i++) node=node->ln_Succ;
newc2pname=((struct c2ps *)node)->filename;
getc2pinfos(newc2pname);
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gc2pauthortxt],cp4prefsWnd,NULL,GTTX_Text,(ULONG)c2pAuthor,TAG_DONE);
GT_SetGadgetAttrs(cp4prefsGadgets[GD_gc2pnametxt],cp4prefsWnd,NULL,GTTX_Text,(ULONG)c2pName,TAG_DONE);
if(c2pInfo!=NULL&&strlen(c2pInfo)>3) setupinfo(c2pInfo);
}
return(TRUE);
}
static int gc2pinfoClicked( void ) {
/* routine when gadget "" is clicked. */
return(TRUE);
}
static int gsaveClicked( void ) {
/* routine when gadget "Save" is clicked. */
SleepWindow();
getgui();
SavePrefsAll();
WindowToFront(cp4prefsWnd);
ScreenToFront(Scr);
ActivateWindow(cp4prefsWnd);
AwakeWindow();
return(TRUE);
}
static int guseClicked( void ) {
/* routine when gadget "Use" is clicked. */
getgui();
UsePrefs();
return(FALSE);
}
static int gcancelClicked( void ) {
/* routine when gadget "Cancel" is clicked. */
opt_drive08=drivestore[0];
opt_drive09=drivestore[1];
opt_drive10=drivestore[2];
opt_drive11=drivestore[3];
// reset old_keymap
if(0!=setkeymap(old_keymap)) {
p4req1(cp4prefsWnd,P4_WARNING,GetStr(MSG_01D4));
} else {
if(old_keymap!=NULL) {
AddOption("KEYMAP",old_keymap);
if(NULL==(opt_keymap=GetOption("KEYMAP",NULL))) p4req1(cp4prefsWnd,P4_ERROR,GetStr(MSG_01D5));
} else {
AddOption("KEYMAP","DEFAULT");
opt_keymap=NULL;
}
}
return(FALSE);
}
static int gquitClicked( void ) {
/* routine when gadget "Quit" is clicked. */
ret=2;
return(FALSE);
}
static int cp4prefsCloseWindow( void ) {
/* routine for "IDCMP_CLOSEWINDOW". */
return(FALSE);
}
static ULONG SAVEDS REGARGS P4HookFunc(REG(a0,struct Hook *mh),REG(a2,struct FileRequester *fr),REG(a1,struct AnchorPath *ap)) {
static char fullname[512];
int st,siz,hi,lo;
BPTR fp;
ULONG ret=FALSE;
strcpy(fullname,fr->fr_Drawer);
AddPart(fullname,ap->ap_Info.fib_FileName,512);
siz=ap->ap_Info.fib_Size-2;
if(NULL!=(fp=Open(fullname,MODE_OLDFILE))) {
lo=FGetC(fp);
hi=FGetC(fp);
Close(fp);
st=(hi<<8)|lo;
if((st+siz)<=0x10000) ret=TRUE;
}
return(ret);
} // P4HookFunc()
static void InitP4Hook(void) {
P4Hook.h_Entry=(HOOKFUNC)P4HookFunc;
P4Hook.h_SubEntry=NULL;
P4Hook.h_Data=NULL;
} // InitP4Hook()
/*
* MENUPICK
*/
int cp4prefsmpload( void ) {
/* routine when (sub)item "Load File" is selected. */
char *filename,*s;
int lastaddr;
InitP4Hook();
if(AslRequestTags(frq,