-
Notifications
You must be signed in to change notification settings - Fork 25
/
gui.c
2507 lines (2186 loc) · 83.3 KB
/
gui.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
/*
** Oricutron
** Copyright (C) 2009-2014 Peter Gordon
**
** 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, version 2
** of the License.
**
** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
** GUI
*/
/*
** The GUI in Oricutron is built on the basic element of the "textzone". This
** is a simple structure containing the position, size and contents of an area
** of text, which you can render onto an SDL surface whenever you like.
*/
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/stat.h>
#ifdef __amigaos4__
#include <proto/dos.h>
#endif
#if defined(__MORPHOS__) || defined(__AROS__)
#include <proto/exec.h>
#include <proto/openurl.h>
#endif
#include "system.h"
#include "6502.h"
#include "via.h"
#include "8912.h"
#include "gui.h"
#include "disk.h"
#include "monitor.h"
#include "6551.h"
#include "machine.h"
#include "filereq.h"
#include "render_sw.h"
#include "render_sw8.h"
#include "render_gl.h"
#include "render_null.h"
#include "ula.h"
#include "tape.h"
#include "joystick.h"
#include "snapshot.h"
#include "msgbox.h"
#include "keyboard.h"
#include "plugins/ch376/ch376.h"
#include "plugins/ch376/oric_ch376_plugin.h"
#include "plugins/twilighte_board/oric_twilighte_board_plugin.h"
extern SDL_bool fullscreen;
char tapepath[4096], tapefile[512];
char diskpath[4096], diskfile[512];
char telediskpath[4096], telediskfile[512];
char pravdiskpath[4096], pravdiskfile[512];
extern char atmosromfile[];
extern char oric1romfile[];
extern char mdiscromfile[];
extern char bd500romfile[];
extern char jasmnromfile[];
extern char pravetzromfile[2][1024];
extern char telebankfiles[8][1024];
char snappath[4096], snapfile[512];
char mappingpath[4096], mappingfile[512];
char filetmp[4096+512+4];
SDL_bool refreshstatus = SDL_TRUE, refreshdisks = SDL_TRUE, refreshavi = SDL_TRUE, refreshtape = SDL_TRUE,
refreshkeyboard = SDL_TRUE;
extern struct avi_handle *vidcap;
extern SDL_bool need_sdl_quit;
extern SDL_AudioSpec obtained;
extern Uint32 cyclespersample;
#define GIMG_W_DISK 18
#define GIMG_W_TAPE 20
#define GIMG_W_AVIR 16
// Images used in the GUI
struct guiimg gimgs[NUM_GIMG] = { { IMAGEPREFIX"statusbar.bmp", 640, 16, NULL },
{ IMAGEPREFIX"disk_ejected.bmp", GIMG_W_DISK, 16, NULL },
{ IMAGEPREFIX"disk_idle.bmp", GIMG_W_DISK, 16, NULL },
{ IMAGEPREFIX"disk_active.bmp", GIMG_W_DISK, 16, NULL },
{ IMAGEPREFIX"disk_modified.bmp", GIMG_W_DISK, 16, NULL },
{ IMAGEPREFIX"disk_modactive.bmp", GIMG_W_DISK, 16, NULL },
{ IMAGEPREFIX"tape_ejected.bmp", GIMG_W_TAPE, 16, NULL },
{ IMAGEPREFIX"tape_pause.bmp", GIMG_W_TAPE, 16, NULL },
{ IMAGEPREFIX"tape_play.bmp", GIMG_W_TAPE, 16, NULL },
{ IMAGEPREFIX"tape_stop.bmp", GIMG_W_TAPE, 16, NULL },
{ IMAGEPREFIX"tape_record.bmp", GIMG_W_TAPE, 16, NULL },
{ IMAGEPREFIX"avirec.bmp", GIMG_W_AVIR, 16, NULL },
#ifndef WWW_NO_ORIC1
{ IMAGEPREFIX"gfx_oric1kbd.bmp", 640, 240, NULL },
#endif
{ IMAGEPREFIX"gfx_atmoskbd.bmp", 640, 240, NULL },
#ifndef WWW_NO_PRAVETZ
{ IMAGEPREFIX"gfx_pravetzkbd.bmp", 640, 240, NULL }
#endif
};
SDL_bool soundavailable, soundon;
#if defined(__linux__)
Sint16 soundsilence = 0;
#else
Sint16 soundsilence = -32768;
#endif
extern SDL_bool microdiscrom_valid, jasminrom_valid, pravetzrom_valid;
// GUI image locations
#define GIMG_POS_SBARY (480-16)
#define GIMG_POS_TAPEX (640-4-GIMG_W_TAPE)
#define GIMG_POS_DISKX (GIMG_POS_TAPEX-(6+(GIMG_W_DISK*4)))
#define GIMG_POS_AVIRECX (GIMG_POS_DISKX-(6+GIMG_W_AVIR))
// Text zone (and other gui area) colours R, G, B
unsigned char sgpal[] = { 0x00, 0x00, 0x00, // 0 = black
0xff, 0xff, 0xff, // 1 = white
0xcc, 0xcc, 0xff, // 2 = light blue
0x00, 0x00, 0xff, // 3 = dark blue
0x00, 0x00, 0x40, // 4 = very dark blue
0x70, 0x70, 0xff, // 5 = mid blue
0x80, 0x80, 0x80, // 6 = grey
0xa0, 0xa0, 0x00, // 7 = yellow
0x80, 0x00, 0x00, // 8 = dark red
0xff, 0x00, 0x00, // 9 = red
0xcc, 0xcc, 0xcc, // 10 = Oric-1 bc
0x33, 0x66, 0x99, // 11 = Oric-1 sel
0xff, 0x66, 0x00, // 12 = Atmos sel
0xff, 0x33, 0x33, // 13 = Telestrat sel
0x99, 0x99, 0x66, // 14 = Pravetz bc
0xcc, 0xcc, 0x99 // 15 = Pravetz sel
};
// Colors for the menu, see sgpal for color index
// MACH_ORIC1 = 0, MACH_ORIC1_16K, MACH_ATMOS, MACH_TELESTRAT, MACH_PRAVETZ
// Name = { OR TE PR Or
// OR IC AT LE AV ig
// IC -1 MO ST ET in a$
// -1, 16, S , RA, Z , al, c };
static char g_foregroundc[] = { 0, 0, 1, 1, 0, 2, 1 };
static char g_backgroundc[] = { 10, 10, 0, 0, 14, 3, 0 };
static char g_foregroundcsel[] = { 1, 1, 0, 0, 0, 1, 0 };
static char g_backgroundcsel[] = { 11, 11, 12, 13, 15, 5, 9 };
int g_menu_scheme = 5; // Default is original color scheme, set to the current machine type in machine.c swapmach
// All the textzones. Spaces in this array
// are reserved in gui.h
struct textzone *tz[NUM_TZ];
// Temporary string buffer
char vsptmp[VSPTMPSIZE];
// FPS calculation vars
extern Uint32 frametimeave;
SDL_bool warpspeed=SDL_FALSE;
// Current menu, and highlighted item number
struct osdmenu *cmenu = NULL;
int cmenuitem = 0;
static char* aciabackends[ACIA_TYPE_LAST] = {
" Serial none ",
"\x0e""Serial loopback $xxxx",
"\x0e""Serial modem $xxxx",
"\x0e""Serial com $xxxx",
};
static char aciabackendlabel[32];
char menufc(SDL_bool bSelected) { return (bSelected ? g_foregroundcsel[g_menu_scheme] : g_foregroundc[g_menu_scheme]); }
char menubc(SDL_bool bSelected) { return (bSelected ? g_backgroundcsel[g_menu_scheme] : g_backgroundc[g_menu_scheme]); }
// Menufunctions
void toggletapenoise( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglesound( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void inserttape( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void insertdisk( struct machine *oric, struct osdmenuitem *mitem, int drive );
void resetoric( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void toggletapeturbo( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglech376(struct machine *oric, struct osdmenuitem *mitem, int dummy);
void toggletwilighte(struct machine *oric, struct osdmenuitem *mitem, int dummy);
void toggleautowind( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void toggleautoinsrt( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglesymbolsauto( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglecasesyms( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglevsynchack( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void swap_render_mode( struct machine *oric, struct osdmenuitem *mitem, int newrendermode );
void togglearatio( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglehstretch( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglepalghost( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglescanlines( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglelightpen( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void toggleaciabackend( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void setoverclock( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void savesnap( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void loadsnap( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglekeyboard( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void definemapping( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void togglestickykeys( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void savemapping( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void loadmapping( struct machine *oric, struct osdmenuitem *mitem, int dummy );
void resetmapping( struct machine *oric, struct osdmenuitem *mitem, int dummy );
#ifdef __CBCOPY__
void clipbd_copy_gui( struct machine *oric, struct osdmenuitem *mitem, int dummy );
#endif
#ifdef __CBPASTE__
void clipbd_paste_gui( struct machine *oric, struct osdmenuitem *mitem, int dummy );
#endif
// Menu definitions. Name, key name, SDL key code, function, parameter
// Keys that are also available while emulating should be marked with
// square brackets
struct osdmenuitem mainitems[] = { { "Insert tape...", "T", 't', inserttape, 0, 0 },
{ "Save tape output...", "[F9]", SDLK_F9, toggletapecap, 0, 0 },
{ "Insert disk 0...", "0", SDLK_0, insertdisk, 0, 0 },
{ "Insert disk 1...", "1", SDLK_1, insertdisk, 1, 0 },
{ "Insert disk 2...", "2", SDLK_2, insertdisk, 2, 0 },
{ "Insert disk 3...", "3", SDLK_3, insertdisk, 3, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Save snapshot...", NULL, 0, savesnap, 0, 0 },
{ "Load snapshot...", NULL, 0, loadsnap, 0, 0 },
#if defined(__CBCOPY__) || defined(__CBPASTE__)
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
#endif
#if defined(__CBCOPY__)
{ "Copy to clipboard", "[F11]",SDLK_F11, clipbd_copy_gui, 0, 0 },
#endif
#if defined(__CBPASTE__)
{ "Paste from clipboard", "[F12]",SDLK_F12, clipbd_paste_gui,0, 0 },
#endif
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Hardware options...", "H", 'h', gotomenu, 1, 0 },
{ "Audio options...", "A", 'a', gotomenu, 2, 0 },
{ "Video options...", "V", 'v', gotomenu, 4, 0 },
{ "Keyboard options...", "K", 'k', gotomenu, 7, 0 },
{ "Debug options...", "D", 'd', gotomenu, 3, 0 },
{ "Overclock options...", "C", 'c', gotomenu, 6, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
#ifndef WWW_NO_MONITOR
{ "Monitor", "[F2]", SDLK_F2, setemumode, EM_DEBUG, 0 },
#endif
{ "Reset Button NMI", "[F3]", SDLK_F3, softresetoric, 0, 0 },
{ "Hard Reset", "[F4]", SDLK_F4, resetoric, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,setemumode, EM_RUNNING, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "About", NULL, 0, gotomenu, 5, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
#ifndef WWW
{ "Quit", NULL, 0, setemumode, EM_PLEASEQUIT, 0 },
#endif
{ NULL, } };
struct osdmenuitem hwopitems[] = { { " Oric-1", "1", SDLK_1, swapmach, (0xffff<<16)|MACH_ORIC1, 0 },
{ " Oric-1 16K", "2", SDLK_2, swapmach, (0xffff<<16)|MACH_ORIC1_16K, 0 },
{ " Atmos", "3", SDLK_3, swapmach, (0xffff<<16)|MACH_ATMOS, 0 },
{ " Telestrat", "4", SDLK_4, swapmach, (DRV_NONE<<16)|MACH_TELESTRAT, 0 },
{ " Pravetz 8D", "5", SDLK_5, swapmach, (0xffff<<16)|MACH_PRAVETZ, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ " No disk", "X", 'x', setdrivetype, DRV_NONE, 0 },
{ " Microdisc", "M", 'm', setdrivetype, DRV_MICRODISC, 0 },
{ " Jasmin", "J", 'j', setdrivetype, DRV_JASMIN, 0 },
{ " BD500", "B", 'b', setdrivetype, DRV_BD500, 0 },
// { " Cumana", "C", 'c', NULL, 0, 0 },
{ " Pravetz 8D disk", "P", 'p', setdrivetype, DRV_PRAVETZ, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ " Turbo tape", NULL, 0, toggletapeturbo, 0, 0 },
{ " Autoinsert tape", NULL, 0, toggleautoinsrt, 0, 0 },
{ " Autorewind tape", NULL, 0, toggleautowind, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ " VSync hack", NULL, 0, togglevsynchack, 0, 0 },
{ " Lightpen", NULL, 0, togglelightpen, 0, 0 },
{ " Serial none ", NULL, 0, toggleaciabackend, 0, 0 },
{ " CH376 (Telestrat) ", NULL, 0, togglech376, 0, 0 },
{ " Twilighte board ", NULL, 0, toggletwilighte, 0, 0 },
// { " Mouse", NULL, 0, NULL, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,gotomenu, 0, 0 },
{ NULL, } };
struct osdmenuitem auopitems[] = { { " Sound enabled", NULL, 0, togglesound, 0, 0 },
{ " Tape noise", NULL, 0, toggletapenoise, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,gotomenu, 0, 0 },
{ NULL, } };
struct osdmenuitem keopitems[] = { { " Show keyboard", NULL, 0, togglekeyboard, 0, 0 },
{ " Sticky mod keys", NULL, 0, togglestickykeys,0, 0 },
{ " Define mapping", NULL, 0, definemapping, 0, 0 },
{ "Save mapping...", NULL, 0, savemapping, 0, 0 },
{ "Load mapping...", NULL, 0, loadmapping, 0, 0 },
{ "Reset mapping", NULL, 0, resetmapping, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,gotomenu, 0, 0 },
{ NULL, } };
struct osdmenuitem dbopitems[] = { { " Autoload symbols file", NULL, 0, togglesymbolsauto, 0, 0 },
{ " Case-sensitive symbols",NULL, 0, togglecasesyms, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,gotomenu, 0, 0 },
{ NULL, } };
#ifdef __OPENGL_AVAILABLE__
struct osdmenuitem vdopitems[] = { { " OpenGL rendering", "O", 'o', swap_render_mode, RENDERMODE_GL, 0 },
{ " Software rendering", "S", 's', swap_render_mode, RENDERMODE_SW, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ " Fullscreen", "[F8]", SDLK_F8, togglefullscreen, 0, 0 },
{ " Scanlines", "C", 'c', togglescanlines, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,gotomenu, 0, 0 },
{ NULL, } };
#else
struct osdmenuitem vdopitems[] = { { " Fullscreen", "F", 'f', togglefullscreen, 0, 0 },
{ " Scanlines", "C", 'c', togglescanlines, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,gotomenu, 0, 0 },
{ NULL, } };
#endif
struct osdmenuitem glopitems[] = { { " OpenGL rendering", "O", 'o', swap_render_mode, RENDERMODE_GL, 0 },
{ " Software rendering", "S", 's', swap_render_mode, RENDERMODE_SW, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ " Fullscreen", "F", 'f', togglefullscreen, 0, 0 },
{ " 50Hz/60Hz aspect ratio", "R", 'r', togglearatio, 0, 0 },
{ " Horizontal stretch", "H", 'h', togglehstretch, 0, 0 },
{ " Scanlines", "C", 'c', togglescanlines, 0, 0 },
{ " PAL ghosting", "P", 'p', togglepalghost, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,gotomenu, 0, 0 },
{ NULL, } };
struct osdmenuitem aboutitems[] = { { "", NULL, 0, NULL, 0, 0 },
{ APP_NAME_FULL, NULL, 0, NULL, 0, OMIF_BRIGHT|OMIF_CENTRED },
{ "https://github.com/pete-gordon/oricutron",NULL, 0, gotosite, 0, OMIF_CENTRED },
{ "", NULL, 0, NULL, 0, 0 },
{ "(C)" APP_YEAR " Peter Gordon", NULL, 0, NULL, 0, OMIF_BRIGHT|OMIF_CENTRED },
{ "https://www.petergordon.org.uk", NULL, 0, gotosite, 0, OMIF_CENTRED },
{ "", NULL, 0, NULL, 0, 0 },
{ "Additional programming", NULL, 0, NULL, 0, OMIF_BRIGHT|OMIF_CENTRED },
{ "Francois Revol", NULL, 0, NULL, 0, OMIF_CENTRED },
{ "Stefan Haubenthal", NULL, 0, NULL, 0, OMIF_CENTRED },
{ "Alexandre Devert", NULL, 0, NULL, 0, OMIF_CENTRED },
{ "Ibisum", NULL, 0, NULL, 0, OMIF_CENTRED },
{ "Kamel Biskri", NULL, 0, NULL, 0, OMIF_CENTRED },
{ "Iss", NULL, 0, NULL, 0, OMIF_CENTRED },
{ "Patrice Torguet", NULL, 0, NULL, 0, OMIF_CENTRED },
{ "", NULL, 0, NULL, 0, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE, gotomenu, 0, 0 },
{ NULL, } };
struct osdmenuitem ovopitems[] = { { " 1mhz (None)", "1", '1', setoverclock, 0, 0 },
{ " 2mhz", "2", '2', setoverclock, 1, 0 },
{ " 4mhz", "3", '3', setoverclock, 2, 0 },
{ " 8mhz", "4", '4', setoverclock, 3, 0 },
{ " 16mhz", "5", '5', setoverclock, 4, 0 },
{ " 32mhz", "6", '6', setoverclock, 5, 0 },
{ " 64mhz", "7", '7', setoverclock, 6, 0 },
{ OSDMENUBAR, NULL, 0, NULL, 0, 0 },
{ "Back", "\x17", SDLK_BACKSPACE,gotomenu,0, 0 },
{ NULL, } };
#define LAST_ITEM(x) ((sizeof(x)/sizeof(struct osdmenuitem))-2)
struct osdmenu menus[] = { { "Main Menu", LAST_ITEM(mainitems)-4, mainitems },
{ "Hardware options", LAST_ITEM(hwopitems), hwopitems },
{ "Audio options", LAST_ITEM(auopitems), auopitems },
{ "Debug options", LAST_ITEM(dbopitems), dbopitems },
{ "Video options", LAST_ITEM(vdopitems), vdopitems },
{ "About Oricutron", LAST_ITEM(aboutitems), aboutitems },
{ "Overclock", LAST_ITEM(ovopitems), ovopitems },
{ "Keyboard options", LAST_ITEM(keopitems), keopitems }};
#define MKPATH_MAX (1024)
// Prepend file prefix to filename
static void mkpath( char buf[MKPATH_MAX], const char *filename )
{
strncpy( buf, get_fileprefix(), MKPATH_MAX-1 );
buf[MKPATH_MAX-1] = 0;
strncat( buf, filename, MKPATH_MAX-strlen(buf)-1 );
}
// Load a 24bit BMP for the GUI
SDL_bool gimg_load( struct guiimg *gi )
{
SDL_RWops *f;
Uint8 hdrbuf[640*3];
Sint32 x, y;
SDL_bool fileok;
char path[MKPATH_MAX];
// Get the file
mkpath( path, gi->filename );
f = SDL_RWFromFile( path, "rb" );
if( !f )
{
error_printf( "Unable to open '%s'\n", gi->filename );
return SDL_FALSE;
}
// Read the header
if( SDL_RWread( f, hdrbuf, 54, 1 ) != 1 )
{
error_printf( "Error reading '%s'\n", gi->filename );
SDL_RWclose( f );
return SDL_FALSE;
}
fileok = SDL_TRUE;
if( strncmp( (char *)hdrbuf, "BM", 2 ) != 0 ) fileok = SDL_FALSE; // Must start with "BM"
if( ((hdrbuf[21]<<24)|(hdrbuf[20]<<16)|(hdrbuf[19]<<8)|hdrbuf[18]) != gi->w ) fileok = SDL_FALSE; // Must be the correct width
if( ((hdrbuf[25]<<24)|(hdrbuf[24]<<16)|(hdrbuf[23]<<8)|hdrbuf[22]) != gi->h ) fileok = SDL_FALSE; // Must be the correct height
if( ((hdrbuf[27]<<8)|hdrbuf[26]) != 1 ) fileok = SDL_FALSE; // Must contain one plane
if( ((hdrbuf[29]<<8)|hdrbuf[28]) != 24 ) fileok = SDL_FALSE; // Must be 24 bit
if( ((hdrbuf[33]<<24)|(hdrbuf[32]<<16)|(hdrbuf[31]<<8)|hdrbuf[30]) != 0 ) fileok = SDL_FALSE; // Must not be compressed
if( !fileok )
{
error_printf( "'%s' needs to be a %dx%d, uncompressed, 24-bit BMP image\n", gi->filename, gi->w, gi->h );
SDL_RWclose( f );
return SDL_FALSE;
}
// Get some RAM!
if( !gi->buf )
gi->buf = malloc( gi->w * gi->h * 3 );
if( !gi->buf )
{
error_printf( "Out of memory\n" );
SDL_RWclose( f );
return SDL_FALSE;
}
// BMPs are upside down!
for( y=gi->h-1; y>=0; y-- )
{
SDL_RWread( f, hdrbuf, ((gi->w*3)+3)&0xfffffffc, 1 );
for( x=0; x<gi->w; x++ )
{
gi->buf[(y*gi->w+x)*3+0] = hdrbuf[x*3+2];
gi->buf[(y*gi->w+x)*3+1] = hdrbuf[x*3+1];
gi->buf[(y*gi->w+x)*3+2] = hdrbuf[x*3];
}
}
SDL_RWclose( f );
return SDL_TRUE;
}
// Draw the statusbar at the bottom
void draw_statusbar( struct machine *oric )
{
if (oric->statusbar_mode == STATUSBARMODE_NONE)
oric->render_clear_area( 0, GIMG_POS_SBARY, 640, 480-GIMG_POS_SBARY );
else
oric->render_gimg( GIMG_STATUSBAR, 0, GIMG_POS_SBARY );
}
void draw_keyboard( struct machine *oric ) {
if (oric->show_keyboard) {
switch( oric->type )
{
#ifndef WWW_NO_PRAVETZ
case MACH_PRAVETZ:
oric->render_gimg( GIMG_PRAVETZ_KEYBOARD, 0, 480);
break;
#endif
#ifndef WWW_NO_ORIC1
case MACH_ORIC1:
case MACH_ORIC1_16K:
oric->render_gimg( GIMG_ORIC1_KEYBOARD, 0, 480);
break;
#endif
default:
oric->render_gimg( GIMG_ATMOS_KEYBOARD, 0, 480);
break;
}
}
}
// Overlay the disk icons onto the status bar
void draw_disks( struct machine *oric )
{
Sint32 i, j;
if( oric->statusbar_mode == STATUSBARMODE_NONE )
return;
if( oric->drivetype == DRV_NONE )
{
oric->render_gimgpart( GIMG_STATUSBAR, GIMG_POS_DISKX, GIMG_POS_SBARY, GIMG_POS_DISKX, 0, 18*4, 16 );
return;
}
for( i=0; i<4; i++ )
{
j = GIMG_DISK_EJECTED;
if( oric->wddisk.disk[i] )
{
j = ((oric->wddisk.c_drive==i)&&(oric->wddisk.currentop!=COP_NUFFINK)) ? GIMG_DISK_ACTIVE : GIMG_DISK_IDLE;
if( oric->wddisk.disk[i]->modified ) j+=2;
}
oric->render_gimg( j, GIMG_POS_DISKX+i*GIMG_W_DISK, GIMG_POS_SBARY );
}
}
// Overlay the AVI record icon onto the status bar
void draw_avirec( struct machine *oric, SDL_bool recording )
{
if( oric->statusbar_mode == STATUSBARMODE_NONE)
return;
if( recording )
{
oric->render_gimg( GIMG_AVI_RECORD, GIMG_POS_AVIRECX, GIMG_POS_SBARY );
return;
}
oric->render_gimgpart( GIMG_STATUSBAR, GIMG_POS_AVIRECX, GIMG_POS_SBARY, GIMG_POS_AVIRECX, 0, 16, 16 );
}
// Overlay the tape icon onto the status bar
void draw_tape( struct machine *oric )
{
if( oric->statusbar_mode == STATUSBARMODE_NONE )
return;
if( oric->tapecap )
{
oric->render_gimg( GIMG_TAPE_RECORD, GIMG_POS_TAPEX, GIMG_POS_SBARY );
return;
}
if( !oric->tapebuf )
{
oric->render_gimg( GIMG_TAPE_EJECTED, GIMG_POS_TAPEX, GIMG_POS_SBARY );
return;
}
if( oric->tapemotor )
{
oric->render_gimg( GIMG_TAPE_PLAY, GIMG_POS_TAPEX, GIMG_POS_SBARY );
return;
}
if( oric->tapeoffs >= oric->tapelen )
{
oric->render_gimg( GIMG_TAPE_STOP, GIMG_POS_TAPEX, GIMG_POS_SBARY );
return;
}
oric->render_gimg( GIMG_TAPE_PAUSE, GIMG_POS_TAPEX, GIMG_POS_SBARY );
}
// Pop up some info!
void do_popup( struct machine *oric, char *str )
{
strncpy( oric->popupstr, str, 40 ); oric->popupstr[39] = 0;
oric->newpopupstr = SDL_TRUE;
oric->popuptime = 100;
}
void render_status( struct machine *oric )
{
if( refreshstatus )
draw_statusbar( oric );
if( refreshdisks || refreshstatus )
{
draw_disks( oric );
refreshdisks = SDL_FALSE;
}
if( refreshavi || refreshstatus )
{
draw_avirec( oric, vidcap != NULL );
refreshavi = SDL_FALSE;
}
if( refreshtape || refreshstatus )
{
draw_tape( oric );
refreshtape = SDL_FALSE;
}
if(refreshkeyboard || refreshstatus) {
draw_keyboard( oric );
refreshkeyboard = SDL_FALSE;
}
refreshstatus = SDL_FALSE;
}
// Top-level rendering routine
void render( struct machine *oric )
{
int perc, fps; //, i;
#ifndef WWW_NO_MONITOR
if( oric->emu_mode == EM_DEBUG )
mon_update( oric );
#endif
oric->render_begin( oric );
switch( oric->emu_mode )
{
case EM_MENU:
oric->render_video( oric, SDL_TRUE );
render_status( oric );
if( tz[TZ_MENU] ) oric->render_textzone( oric, TZ_MENU );
break;
case EM_RUNNING:
oric->render_video( oric, SDL_TRUE );
render_status( oric );
if( oric->statusbar_mode == STATUSBARMODE_FULL )
{
fps = 100000/(frametimeave?frametimeave:1);
if( oric->vid_freq )
perc = 200000/(frametimeave?frametimeave:1);
else
perc = 166667/(frametimeave?frametimeave:1);
#ifdef DEBUG_VSYNC
sprintf( oric->statusstr, "%4d.%02d%% - %4dFPS VSYNC:%3d", perc/100, perc%100, fps/100, oric->vid_offset );
#else
sprintf( oric->statusstr, "%4d.%02d%% - %4dFPS", perc/100, perc%100, fps/100 );
#endif
oric->newstatusstr = SDL_TRUE;
}
if( oric->popuptime > 0 )
{
oric->popuptime--;
if( oric->popuptime == 0 )
{
oric->popupstr[0] = 0;
oric->newpopupstr = SDL_TRUE;
}
}
break;
#ifndef WWW_NO_MONITOR
case EM_DEBUG:
mon_render( oric );
break;
#endif
}
oric->render_end( oric );
}
// Draws a box in a textzone (uses the box chars in the font)
// ptz = target textzone
// x,y,w,h = location and dimensions
// fg,bg = colours
void makebox( struct textzone *ptz, int x, int y, int w, int h, int fg, int bg )
{
int cx, cy, o, bo;
o = y*ptz->w+x;
for( cy=0; cy<h; cy++ )
{
for( cx=0; cx<w; cx++ )
{
ptz->tx[o ] = ' ';
ptz->fc[o ] = fg;
ptz->bc[o++] = bg;
}
ptz->tx[o-w] = 5;
ptz->tx[o-1] = 5;
o += ptz->w-w;
}
o = y*ptz->w+x;
bo = o + (h-1)*ptz->w;
for( cx=0; cx<(w-1); cx++ )
{
ptz->tx[o++] = cx==0?1:2;
ptz->tx[bo++] = cx==0?9:2;
}
ptz->tx[o] = 4;
ptz->tx[bo] = 11;
ptz->modified = SDL_TRUE;
}
// Write a string to a textzone
void tzstr( struct textzone *ptz, char *text )
{
int i, o;
o = ptz->py*ptz->w+ptz->px;
for( i=0; text && text[i]; i++ )
{
switch( text[i] )
{
case 10:
ptz->px = 1;
ptz->py++;
o = ptz->py*ptz->w+1;
break;
case 13:
break;
default:
ptz->tx[o ] = text[i];
ptz->fc[o ] = ptz->cfc;
ptz->bc[o++] = ptz->cbc;
ptz->px++;
if( ptz->px >= ptz->w )
{
ptz->px = 1;
ptz->py++;
o = ptz->py*ptz->w+1;
}
break;
}
}
ptz->modified = SDL_TRUE;
}
void tzputc( struct textzone *ptz, char c )
{
char tmp[2];
tmp[0] = c;
tmp[1] = 0;
tzstr( ptz, tmp );
}
// Print a formatted string into a textzone
void tzprintf( struct textzone *ptz, char *fmt, ... )
{
va_list ap;
va_start( ap, fmt );
if( vsnprintf( vsptmp, VSPTMPSIZE, fmt, ap ) != -1 )
{
vsptmp[VSPTMPSIZE-1] = 0;
tzstr( ptz, vsptmp );
}
va_end( ap );
}
// Write a string to a textzone at a specific location
void tzstrpos( struct textzone *ptz, int x, int y, char *text )
{
ptz->px = x;
ptz->py = y;
tzstr( ptz, text );
}
// Print a formatted string into a textzone at a specific location
void tzprintfpos( struct textzone *ptz, int x, int y, char *fmt, ... )
{
va_list ap;
va_start( ap, fmt );
if( vsnprintf( vsptmp, VSPTMPSIZE, fmt, ap ) != -1 )
{
vsptmp[VSPTMPSIZE-1] = 0;
tzstrpos( ptz, x, y, vsptmp );
}
va_end( ap );
}
// Set the foreground and background colours for printing text into a textzone
void tzsetcol( struct textzone *ptz, int fc, int bc )
{
ptz->cfc = fc;
ptz->cbc = bc;
}
// Set the title of a textzone
void tzsettitle( struct textzone *ptz, char *title )
{
int ox, oy;
makebox( ptz, 0, 0, ptz->w, ptz->h, menufc(SDL_FALSE), menubc(SDL_FALSE));
if( !title ) return;
tzsetcol( ptz, menufc(SDL_FALSE), menubc(SDL_FALSE));
ox = ptz->px;
oy = ptz->py;
ptz->px = 3;
ptz->py = 0;
tzstr( ptz, "[ " );
tzstr( ptz, title );
tzstr( ptz, " ]" );
ptz->px = ox;
ptz->py = oy;
}
SDL_bool in_textzone( struct textzone *tz_, int x, int y )
{
if( ( x >= tz_->x ) && ( x < (tz_->x+tz_->w*8) ) &&
( y >= tz_->y ) && ( y < (tz_->y+tz_->h*12) ) )
{
return SDL_TRUE;
}
return SDL_FALSE;
}
// Allocate a textzone structure
SDL_bool alloc_textzone( struct machine *oric, int i, int x, int y, int w, int h, char *title )
{
struct textzone *ntz;
ntz = malloc( sizeof( struct textzone ) + w*h*3 );
if( !ntz ) return SDL_FALSE;
ntz->x = x;
ntz->y = y;
ntz->w = w;
ntz->h = h;
ntz->tx = (unsigned char *)(&ntz[1]);
ntz->fc = &ntz->tx[w*h];
ntz->bc = &ntz->fc[w*h];
tzsettitle( ntz, title );
ntz->px = 1;
ntz->py = 1;
ntz->modified = SDL_TRUE;
tz[i] = ntz;
oric->render_textzone_alloc( oric, i );
return SDL_TRUE;
}
void clear_textzone( struct machine *oric, int i )
{
int x, y;
struct textzone *ptz = tz[i];
if (!ptz) return;
for( y=1; y<(ptz->h-1); y++ )
{
for( x=1; x<(ptz->w-1); x++ )
{
ptz->tx[y*ptz->w+x] = ' ';
ptz->fc[y*ptz->w+x] = 2;
ptz->bc[y*ptz->w+x] = 3;
}
}
ptz->modified = SDL_TRUE;
}
// Free a textzone structure
void free_textzone( struct machine *oric, int i )
{
oric->render_textzone_free( oric, i );
if( !tz[i] ) return;
free( tz[i] );
tz[i] = NULL;
}
// Draw the current menu items into the menu textzone
void drawitems( void )
{
int i, j, o;
// No menu, or no textzone?
if( ( !cmenu ) || ( !tz[TZ_MENU] ) )
return;
// For each item...
for( i=0; cmenu->items[i].name; i++ )
{
// Check if its a menu bar
if( cmenu->items[i].name == OSDMENUBAR )
{
// Fill it with the menu bar char
o = tz[TZ_MENU]->w * (i+1) + 1;
for( j=1; j<tz[TZ_MENU]->w-1; j++, o++ )
{
tz[TZ_MENU]->tx[o] = 12;
tz[TZ_MENU]->fc[o] = menufc(SDL_FALSE);
tz[TZ_MENU]->bc[o] = menubc(SDL_FALSE);
}
continue;
}
// Check if this is the highlighted item, and set the colours accordingly
if( i==cmenu->citem )
tzsetcol( tz[TZ_MENU], menufc(SDL_TRUE), menubc(SDL_TRUE));
else
tzsetcol( tz[TZ_MENU], (cmenu->items[i].flags&OMIF_BRIGHT) ? 1 : menufc(SDL_FALSE), menubc(SDL_FALSE));
// Calculate the position in the textzone
o = tz[TZ_MENU]->w * (i+1) + 1;
// Fill the background colour all the way along
for( j=1; j<tz[TZ_MENU]->w-1; j++, o++ )
tz[TZ_MENU]->bc[o] = tz[TZ_MENU]->cbc;
// Write the text for the item
if( cmenu->items[i].flags & OMIF_CENTRED )
tzstrpos( tz[TZ_MENU], (tz[TZ_MENU]->w-(int)strlen(cmenu->items[i].name))/2, i+1, cmenu->items[i].name );
else
tzstrpos( tz[TZ_MENU], 1, i+1, cmenu->items[i].name );
// And the key (if there is one)
if( cmenu->items[i].key )
tzstrpos( tz[TZ_MENU], tz[TZ_MENU]->w-(1+(int)strlen(cmenu->items[i].key)), i+1, cmenu->items[i].key );
}
}
/***************** These functions can be used directly from the menu system ***************/
void joinpath( char *path, char *file )
{
#if defined(__amigaos4__)
strcpy( filetmp, path );
IDOS->AddPart( filetmp, file, 4096 );
#elif defined(WIN32)
int i;
strncpy( filetmp, path, 4096 ); filetmp[4095] = 0;
i = strlen( filetmp );
if( ( i > 0 ) && ( filetmp[i-1] != PATHSEP ) && ( filetmp[i-1] != ':' ) )
{
filetmp[i++] = PATHSEP;
filetmp[i++] = 0;
}
strncat( filetmp, file, 4096+512 );
filetmp[4096+511] = 0;
#else
int i;
strncpy( filetmp, path, 4096 ); filetmp[4095] = 0;
i = (int)strlen( filetmp );
if( ( i > 0 ) && ( filetmp[i-1] != PATHSEP ) )
{
filetmp[i++] = PATHSEP;
filetmp[i++] = 0;
}
strncat( filetmp, file, 4096+512 );
filetmp[4096+511] = 0;
#endif
}
// "insert" a tape into the virtual tape drive, via filerequester
void inserttape( struct machine *oric, struct osdmenuitem *mitem, int dummy )
{
if( !filerequester( oric, "Insert tape", tapepath, tapefile, FR_TAPELOAD ) ) return;
oric->lasttapefile[0] = 0;
joinpath( tapepath, tapefile );
switch (detect_image_type(filetmp))
{
case IMG_SNAPSHOT:
if (msgbox(oric, MSGBOX_YES_NO,
"The file you selected appears to be a snapshot file.\n"
"Would you like to load it? (All RAM and machine state will be lost)"))
{
load_snapshot(oric, filetmp);
return;
}
break;
case IMG_ATMOS_MICRODISC:
if ((oric->type != MACH_ATMOS) &&
(oric->type != MACH_ORIC1) &&
(oric->type != MACH_PRAVETZ))
{
if (msgbox(oric, MSGBOX_YES_NO,
"The file you selected appears to be a disk for an Oric Atmos with Microdisc.\n"
"Would you like to switch to that configuration and insert it as a disk?"))
{