-
Notifications
You must be signed in to change notification settings - Fork 0
/
cap32.cpp
4714 lines (4375 loc) · 185 KB
/
cap32.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
/* Caprice32 - Amstrad CPC Emulator
(c) Copyright 1997-2005 Ulrich Doewich
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., 675 Mass Ave, Cambridge, MA 02139, USA.
Oct 11, 2000 - 22:12 preliminary IN/OUT handlers; started with the GA OUT register write routines
Oct 12, 2000 - 23:31 added GA ROM select to z80_OUT_handler
Oct 14, 2000 - 13:58 added PPI IN/OUT handlers
Oct 15, 2000 - 15:33 added CRTC IN/OUT handlers
Oct 20, 2000 - 23:23 fixed some IN/OUT handler bugs
Oct 27, 2000 - 17:39 added reset_CPC
Oct 30, 2000 - 21:05 found the problem with the streched display: scr_bps needs to be in dwords, not bytes!
Nov 01, 2000 - 23:43 aargh! found the BASIC 'reset' bug: the pbROMhi variable was pointing to the wrong location!
Nov 03, 2000 - 18:03 added keyboard_interrupt handler
Nov 03, 2000 - 19:10 added preliminary PSG register write handlers
Nov 03, 2000 - 23:37 fixed the PPI port C handler; CPC keyboard works now!
Dec 12, 2000 - 18:14 changed load_dsk() to work with a C based disk info structure
Jan 24, 2001 - 22:28 loading from disk images works (again)!
Apr 06, 2001 - 12:52 fixed the keyboard translation table (Allegro WIP 3.9.34 added 3 more keys to the array)
Jun 13, 2001 - 17:25 added DirectDraw and DirectInput8 init routines for the new Windows port of Caprice32
Jun 13, 2001 - 20:50 keyboard emualtion works now via the DI8 action mapping
Jun 21, 2001 - 00:30 changed DDraw code to work in windowed mode; added routines to render CPC screen in 32bpp; added drag'n drop functionality for CPC drive A
Jun 23, 2001 - 16:15 only the visible portion of the CPC screen is rendered to the frame buffer; Windows window is now sized to the proper CPC screen dimensions
Jun 28, 2001 - 18:42 fixed the extended DSK parsing; loading DSK images via common dialog file selector; handling of joystick axis data
Jun 29, 2001 - 20:16 speed throttling to original CPC speed; fixed the joystick mapping in the CPC keyboard matrix; implemented more menu commands
Jun 30, 2001 - 22:57 settings stored in and retrieved from the registry; updated emulator_init and emulator_shutdown; file selector remembers path and selected file
Jul 01, 2001 - 17:54 ROM slot cofiguration is stored in and retrieved from the registry; automatically loads last DSK images on startup
Jul 04, 2001 - 00:34 colour tables for 16bpp (555 & 565) and 8bpp PC video modes; DDraw init updated with bit depth dependant code
Jul 04, 2001 - 22:06 fixed 16bpp colour tables; updated VDU screen centering code to work with all bit depths
Jul 06, 2001 - 00:35 implemented pause option; emulation is halted when application becomes inactive
Jul 06, 2001 - 19:34 zip decompression for DSK and SNA loading
Jul 07, 2001 - 00:58 fixed setting of GA colour table in load_snapshot; last DSK image load on startup supports ZIP files
Jul 18, 2001 - 18:40 DirectSound init code finally works correctly!
Jul 20, 2001 - 18:17 found the problem with the sound emulation: snd_multiplier calculation was done with integer arithmetic! grrrr...
Jul 25, 2001 - 00:48 *finally* got a clean sound code that won't break up anymore!
Aug 01, 2001 - 17:38 sound configuration is pulled from and stored in the registry
Aug 02, 2001 - 18:31 floppy drive LED is now shown on the CPC screen during data transfers
Aug 03, 2001 - 19:26 added About box
Aug 03, 2001 - 23:49 altered load_dsk() to allocate memory on a track by track basis (in preparation of fdc_writeID() support)
Aug 06, 2001 - 18:42 started work on the Options dialog
Aug 10, 2001 - 19:10 finished the General Options property sheet
Aug 11, 2001 - 17:29 up to 576KB of RAM supported
Aug 12, 2001 - 21:43 extracted psg_reg_write() from the psg_write #define; fixed the PSG setup in load_snapshot()
Aug 16, 2001 - 00:49 load_snapshot() now adjusts RAM size, and loads the correct CPC ROM as necessary
Aug 20, 2001 - 00:59 added save_snapshot(); header contains preliminary v3 info
Aug 20, 2001 - 16:10 updated load_snapshot() with processing of the 'official' v3 info
Aug 22, 2001 - 23:26 added Audio Options property sheet to control PSG emulation
Oct 06, 2001 - 13:22 removed the "experimental" joystick 2 support from the action map code - did not work as expected
Oct 07, 2001 - 20:27 added the save_dsk() routine
Oct 13, 2001 - 18:51 completed rewrite of zip handling; users can now choose images from multiple file archives
Nov 08, 2001 - 19:08 bug fix: the zip_dir routine caused a crash if a zip archive would not open properly
Nov 09, 2001 - 00:04 the ROM loading routine now checks the validity of the image, and skips a possible 128 bytes header
May 09, 2002 - 19:07 removed the DDSCAPS_3DDEVICE flag from the InitDirectDraw code; modified UpdateBounds to prevent strechblits
Jun 12, 2002 - 18:24 started converting DirectX specific stuff to Allegro
Jun 14, 2002 - 17:49 emulator runs via GDI blits; re-implemented Allegro keyboard handler
Jun 22, 2002 - 17:34 finally got the windowed DirectX mode working using the new Allegro CVS version
Jun 25, 2002 - 18:41 added timer based speed throttling
Jun 27, 2002 - 18:08 CPC screen blits correctly now: source coordinates were being mangled
Jul 14, 2002 - 17:42 rewrote the PC sound playback routine to dynamically adjust the rate at which the buffer is filled
Jul 24, 2002 - 22:16 fixed a possible crash on startup if a zipped DSK in drive A/B had been (re)moved between sessions
Jul 27, 2002 - 16:45 added processing of a "language" file
Jul 27, 2002 - 19:14 changed LoadConfiguration and SaveConfiguration to use the Allegro configuration rountines
Jul 29, 2002 - 22:56 traced the 'access violation' problem back to the sound pause/resume functions
Aug 02, 2002 - 22:37 added some error condition checks and modified sub-routines to report them properly
Aug 24, 2002 - 23:00 determined Allegro to be unsuitable - reverting everything back to DirectX; implemented DirectInput keyboard translation
Aug 26, 2002 - 22:51 fixed the initial application window size to use the correct dimensions
Aug 27, 2002 - 18:23 streamlined the code to be more Windows friendly; app now goes to sleep when minimized
Sep 07, 2002 - 18:28 added fullscreen mode; corrected 8bpp palette init; GDI calls (e.g. file selector) still work
Sep 08, 2002 - 16:06 rewrote PCVideo init routines to support windowed/fullscreen mode switching
Sep 12, 2002 - 00:02 fixed 50Hz timer by using QueryPerformanceCounter
Sep 20, 2002 - 18:19 re-implemented DirectSound support; fixed timing problems - sound playback should no longer pop
Sep 21, 2002 - 15:35 LoadConfiguration & SaveConfiguration now use the cap32.cfg file instead of the Registry
Sep 25, 2002 - 22:49 full screen resolution is selectable in the Options dialog; auto-sizes visible portion; allows mode change while being fs
Sep 26, 2002 - 22:26 added scanline and line doubling (in software) rendering modes
Sep 28, 2002 - 17:38 added a speed slider to the General page of the Options dialog
Sep 29, 2002 - 19:31 added colour monitor and green screen option; switched to QueryPerformanceCounter for the FPS counter
Sep 29, 2002 - 23:03 added the 15 and 16 bpp green monitor colour maps - thanks to Ralf's Excel sheet!
Oct 02, 2002 - 23:43 added fault condition checks to zip_dir, zip_extract and load_snapshot
Oct 04, 2002 - 18:29 added fault condition checks to save_snapshot, load_dsk and save_dsk; added altered DSK check on exit
Oct 04, 2002 - 22:34 added disk drive activity indicator
Oct 07, 2002 - 17:48 fixed switching CPC monitor type "on-the-fly"; fixed surface restore in fullscreen mode
Oct 07, 2002 - 21:58 added line doubling (in hardware) rendering mode
Oct 16, 2002 - 22:18 added enumeration and initilization of all installed keyboards and joysticks
Oct 17, 2002 - 23:40 replaced the controls property page in the options dialog
Oct 28, 2002 - 19:50 added support for custom controls: CPC joystick functions can now be mapped to any attached input device(s)
Nov 01, 2002 - 15:54 added custom print routine for on-screen messages (e.g. FPS counter)
Nov 02, 2002 - 16:44 mouse cursor now auto-hides with no mouse movement for 2 seconds
Nov 10, 2002 - 17:38 added ROM patching to support the french and spanish CPC keyboard layouts
Nov 10, 2002 - 21:31 fixed PPI port C handler
Nov 12, 2002 - 22:08 changes to the OUT handler: GA and CRTC cannot be accessed at the same time; fixed the GA pen selection
Nov 13, 2002 - 22:48 tweaked the IN/OUT handlers a bit more
Dec 05, 2002 - 00:06 fixed the problem with the tape startup delay: the PPI Port C bit manipulation only considered 4 instead of 8 bits
Dec 08, 2002 - 22:05 updated the Z80_OUT_handler to accept FDC data on ports 0x7f and 0x7e, as per Kevin's I/O port document
Dec 10, 2002 - 23:50 print now draws double spaced in scanline mode: don't have to remove the text again this way
Dec 19, 2002 - 23:28 added 48 & 96 kHz audio options; added sanity checks for LoadConfiguration
Dec 21, 2002 - 15:50 PCAudio_init reports if selected sample rate is not supported; added empty path handling to LoadConfiguration
Dec 22, 2002 - 17:21 found a typo in my keyboard lookup table: CPC key 8 was returning the same as CPC key 0
Jan 12, 2003 - 01:05 added the ability to search for multiple extensions to zip_dir
Jan 12, 2003 - 15:57 completed processing of dropped dsk, sna and cdt files
Jan 15, 2003 - 17:30 added the removal of the temp file to process_drop when uncompressing zip archives
Jan 21, 2003 - 18:53 changed the window handle in all MessageBox calls from NULL to hAppWnd: errors display correctly in full-screen mode now
Jan 24, 2003 - 00:44 altered the validity check on loading expansion ROMs, as some may not contain a jump instruction at offset 0x06
Jan 25, 2003 - 16:49 fixed the FDC port handling in z80_in_handler: "Famous 5" loads now!
Jan 27, 2003 - 18:47 updated the resource file to support themed Windows XP controls
Jan 28, 2003 - 19:18 added insert_voc: converts a sound sample into a CDT direct recording block
Jan 30, 2003 - 20:37 added 24bpp display mode support
Jan 31, 2003 - 16:50 CPC speed slider range is now 50% to 800%, and can be set in 25% increments
Jan 31, 2003 - 22:42 AMSDOS is placed in ROM slot 7 if the config file does not yet exist
Feb 23, 2003 - 14:48 fixed the Windows system palette problems in 256 colour mode
Mar 04, 2003 - 21:04 removed the background brush in the app window class; replaced "return 0L" with "break" in WindowProc
Mar 11, 2003 - 22:38 emulation can now continue to run when focus is lost; added more invalid object checks to ensure clean exits
Mar 12, 2003 - 18:08 had to add the background brush again: fullscreen mode would otherwise not update the unused area
Mar 12, 2003 - 19:02 added the 'auto-pause on loss of focus' feature to the Options dialog
Mar 12, 2003 - 22:07 added the display of HRESULT codes for DirectDraw function calls
Mar 17, 2003 - 22:40 added a check_drvX call to the eject disk menu functions
Mar 22, 2003 - 18:39 added the ability to insert blank disks in either CPC drive; the new Disk page in the Options dialog allows you to choose the format; implemented the Flip Disk option to reverse sides
Mar 23, 2003 - 21:41 custom disk formats can now be specified in the config file; modified LoadConfiguration and SaveConfiguration to support this feature
Mar 29, 2003 - 16:40 tape motor is not turned on if there is no tape in the drive
Apr 02, 2003 - 21:31 changes to the Options dialog: moved the ROM slots to their own page; some cosmetic changes; remembers last page user was on
Apr 03, 2003 - 22:12 added the option to capture printer output to file; aborting a save dialog for a changed DSK now drops back to the emulation without taking any further action
Apr 07, 2003 - 19:09 modified the z80_OUT_handler to capture port writes for the MF2; added all the necessary bits for MF2 emulation, but for now it doesn't display the MF2 menu correctly (text is invisible!)...
Apr 07, 2003 - 21:59 doh! fixed the MF2 problem: the MF2 page-out port always set RAM bank0 instead if checking if the lower ROM was active
Apr 09, 2003 - 15:49 MF2 ROM is now restored at every reset to ensure the ROM area has not been corrupted by memory writes
Apr 13, 2003 - 16:18 added code to display the logo in the About box with a transparent background
Apr 16, 2003 - 16:18 joystick emulation can be toggled on/off; keyboard control assignments now override regular CPC keyboard actions; all dialogs now feature the "Caprice32 - " string to make identification easier; ZIP selector shows ZIP file name
Apr 26, 2003 - 14:03 added CaptureScreenshot to save the screen contents to a PNG file
Apr 26, 2003 - 16:25 finished screen capture implementation: added file selector and path/file storage to config file
May 05, 2003 - 22:46 updated the Audio page in the Options dialog with controls to choose the sample size and adjust the volume
May 06, 2003 - 18:59 load_snapshot and save_snapshot now use the v3 PSG information + the printer port data
May 13, 2003 - 17:41 fixed the file selector problem on drag and drop: the exit condition check was reversed
May 18, 2003 - 01:01 moved Gate Array memory handling to ga_memory_manager; save_snapshot correctly stores current RAM bank now
May 21, 2003 - 00:31 changed the colour palette generation to support an intensity level slider
May 21, 2003 - 14:42 added the Intensity slider control to the Video options
May 26, 2003 - 20:06 emulation loop needs to keep running to produce proper key events: fixes the Pause problem
May 28, 2003 - 13:59 modified the shadow of the print routine to make it more readable on a white background
May 29, 2003 - 15:09 implemented the info message display system and added strings for most emulator actions and keyboard shortcuts
May 30, 2003 - 12:17 added the tape PLAY/STOP button control for proper tape operation
Jun 02, 2003 - 15:05 if the CreateSurface call fails with video memory, it now attempts to allocate it in system memory
Jun 04, 2003 - 19:38 added the 'on printer port' drop-down to the Audio options page
Aug 10, 2003 - 14:35 z80_IN_handler: CRTC write only registers return 0; load_snapshot: fixed broken snapshot support (PPI values were written to the wrong ports!); digiblaster/soundplayer combined into one - changed from a drop down to a check box
May 19, 2004 - 23:13 removed all DirectX/Windows specific parts and replaced them (wherever possible) with the SDL equivalent
May 23, 2004 - 17:48 dropped double buffer scheme in favour of a back buffer/custom blit operation; fixed colour palette init in 8bpp mode; added support for half size render mode; back buffer is cleared in video_init(); replaced the SDL_Flip operation with an SDL_BlitSurface; initial ExitCondition is now EC_FRAME_COMPLETE to ensure we have a valid video memory pointer to start with
May 24, 2004 - 00:49 reintroduced snapshot_load & snapshot_save; modified vdu_init to update the two SDL_Rect structures to center or crop the CPC screen; introduced the dwXScale var to support the half size render mode
May 29, 2004 - 18:09 reintroduced tape_eject, tape_insert and tape_insert_voc; added sound support via the native SDL audio routines
*/
#include <zlib.h>
#include "SDL.h"
#include "cap32.h"
#include "crtc.h"
#include "tape.h"
#include "video.h"
#include "z80.h"
#define VERSION_STRING "v4.2.0"
#define ERR_INPUT_INIT 1
#define ERR_VIDEO_INIT 2
#define ERR_VIDEO_SET_MODE 3
#define ERR_VIDEO_SURFACE 4
#define ERR_VIDEO_PALETTE 5
#define ERR_VIDEO_COLOUR_DEPTH 6
#define ERR_AUDIO_INIT 7
#define ERR_AUDIO_RATE 8
#define ERR_OUT_OF_MEMORY 9
#define ERR_CPC_ROM_MISSING 10
#define ERR_NOT_A_CPC_ROM 11
#define ERR_ROM_NOT_FOUND 12
#define ERR_FILE_NOT_FOUND 13
#define ERR_FILE_BAD_ZIP 14
#define ERR_FILE_EMPTY_ZIP 15
#define ERR_FILE_UNZIP_FAILED 16
#define ERR_SNA_INVALID 17
#define ERR_SNA_SIZE 18
#define ERR_SNA_CPC_TYPE 19
#define ERR_SNA_WRITE 20
#define ERR_DSK_INVALID 21
#define ERR_DSK_SIDES 22
#define ERR_DSK_SECTORS 23
#define ERR_DSK_WRITE 24
#define MSG_DSK_ALTERED 25
#define ERR_TAP_INVALID 26
#define ERR_TAP_UNSUPPORTED 27
#define ERR_TAP_BAD_VOC 28
#define ERR_PRINTER 29
#define ERR_BAD_MF2_ROM 30
#define ERR_SDUMP 31
#define MSG_SNA_LOAD 32
#define MSG_SNA_SAVE 33
#define MSG_DSK_LOAD 34
#define MSG_DSK_SAVE 35
#define MSG_JOY_ENABLE 36
#define MSG_JOY_DISABLE 37
#define MSG_SPD_NORMAL 38
#define MSG_SPD_FULL 39
#define MSG_TAP_INSERT 40
#define MSG_SDUMP_SAVE 41
#define MSG_PAUSED 42
#define MSG_TAP_PLAY 43
#define MSG_TAP_STOP 44
#define MAX_LINE_LEN 256
#define MIN_SPEED_SETTING 2
#define MAX_SPEED_SETTING 32
#define DEF_SPEED_SETTING 4
extern byte bTapeLevel;
extern t_z80regs z80;
extern dword *ScanPos;
extern dword *ScanStart;
extern word MaxVSync;
extern t_flags1 flags1;
extern t_new_dt new_dt;
SDL_AudioSpec *audio_spec = NULL;
SDL_Surface *back_surface = NULL;
video_plugin* vid_plugin;
dword dwTicks, dwTicksOffset, dwTicksTarget, dwTicksTargetFPS;
dword dwFPS, dwFrameCount;
dword dwXScale, dwYScale;
dword dwSndBufferCopied;
dword dwBreakPoint, dwTrace, dwMF2ExitAddr;
dword dwMF2Flags = 0;
byte *pbGPBuffer = NULL;
byte *pbSndBuffer = NULL;
byte *pbSndBufferEnd = NULL;
byte *pbSndStream = NULL;
byte *membank_read[4], *membank_write[4], *memmap_ROM[256];
byte *pbRAM = NULL;
byte *pbROMlo = NULL;
byte *pbROMhi = NULL;
byte *pbExpansionROM = NULL;
byte *pbMF2ROMbackup = NULL;
byte *pbMF2ROM = NULL;
byte *pbTapeImage = NULL;
byte *pbTapeImageEnd = NULL;
byte keyboard_matrix[16];
static byte *membank_config[8][4];
FILE *pfileObject;
FILE *pfoPrinter;
#ifdef DEBUG
#define DEBUG_KEY SDLK_F9
dword dwDebugFlag = 0;
FILE *pfoDebug;
#endif
#define MAX_FREQ_ENTRIES 5
dword freq_table[MAX_FREQ_ENTRIES] = {
11025,
22050,
44100,
48000,
96000
};
#include "font.c"
static double colours_rgb[32][3] = {
{ 0.5, 0.5, 0.5 }, { 0.5, 0.5, 0.5 },{ 0.0, 1.0, 0.5 }, { 1.0, 1.0, 0.5 },
{ 0.0, 0.0, 0.5 }, { 1.0, 0.0, 0.5 },{ 0.0, 0.5, 0.5 }, { 1.0, 0.5, 0.5 },
{ 1.0, 0.0, 0.5 }, { 1.0, 1.0, 0.5 },{ 1.0, 1.0, 0.0 }, { 1.0, 1.0, 1.0 },
{ 1.0, 0.0, 0.0 }, { 1.0, 0.0, 1.0 },{ 1.0, 0.5, 0.0 }, { 1.0, 0.5, 1.0 },
{ 0.0, 0.0, 0.5 }, { 0.0, 1.0, 0.5 },{ 0.0, 1.0, 0.0 }, { 0.0, 1.0, 1.0 },
{ 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0 },{ 0.0, 0.5, 0.0 }, { 0.0, 0.5, 1.0 },
{ 0.5, 0.0, 0.5 }, { 0.5, 1.0, 0.5 },{ 0.5, 1.0, 0.0 }, { 0.5, 1.0, 1.0 },
{ 0.5, 0.0, 0.0 }, { 0.5, 0.0, 1.0 },{ 0.5, 0.5, 0.0 }, { 0.5, 0.5, 1.0 }
};
static double colours_green[32] = {
0.5647, 0.5647, 0.7529, 0.9412,
0.1882, 0.3765, 0.4706, 0.6588,
0.3765, 0.9412, 0.9098, 0.9725,
0.3451, 0.4078, 0.6275, 0.6902,
0.1882, 0.7529, 0.7216, 0.7843,
0.1569, 0.2196, 0.4392, 0.5020,
0.2824, 0.8471, 0.8157, 0.8784,
0.2510, 0.3137, 0.5333, 0.5961
};
SDL_Color colours[32];
static byte bit_values[8] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
};
#define MOD_CPC_SHIFT (0x01 << 8)
#define MOD_CPC_CTRL (0x02 << 8)
#define MOD_EMU_KEY (0x10 << 8)
typedef enum {
CAP32_EXIT = MOD_EMU_KEY,
CAP32_FPS,
CAP32_FULLSCRN,
CAP32_JOY,
CAP32_LOADDRVA,
CAP32_LOADDRVB,
CAP32_LOADSNAP,
CAP32_LOADTAPE,
CAP32_MF2RESET,
CAP32_MF2STOP,
CAP32_OPTIONS,
CAP32_PAUSE,
CAP32_RESET,
CAP32_SAVESNAP,
CAP32_SCRNSHOT,
CAP32_SPEED,
CAP32_TAPEPLAY
} CAP32_KEYS;
typedef enum {
CPC_0,
CPC_1,
CPC_2,
CPC_3,
CPC_4,
CPC_5,
CPC_6,
CPC_7,
CPC_8,
CPC_9,
CPC_A,
CPC_B,
CPC_C,
CPC_D,
CPC_E,
CPC_F,
CPC_G,
CPC_H,
CPC_I,
CPC_J,
CPC_K,
CPC_L,
CPC_M,
CPC_N,
CPC_O,
CPC_P,
CPC_Q,
CPC_R,
CPC_S,
CPC_T,
CPC_U,
CPC_V,
CPC_W,
CPC_X,
CPC_Y,
CPC_Z,
CPC_a,
CPC_b,
CPC_c,
CPC_d,
CPC_e,
CPC_f,
CPC_g,
CPC_h,
CPC_i,
CPC_j,
CPC_k,
CPC_l,
CPC_m,
CPC_n,
CPC_o,
CPC_p,
CPC_q,
CPC_r,
CPC_s,
CPC_t,
CPC_u,
CPC_v,
CPC_w,
CPC_x,
CPC_y,
CPC_z,
CPC_AMPERSAND,
CPC_ASTERISK,
CPC_AT,
CPC_BACKQUOTE,
CPC_BACKSLASH,
CPC_CAPSLOCK,
CPC_CLR,
CPC_COLON,
CPC_COMMA,
CPC_CONTROL,
CPC_COPY,
CPC_CPY_DOWN,
CPC_CPY_LEFT,
CPC_CPY_RIGHT,
CPC_CPY_UP,
CPC_CUR_DOWN,
CPC_CUR_LEFT,
CPC_CUR_RIGHT,
CPC_CUR_UP,
CPC_CUR_ENDBL,
CPC_CUR_HOMELN,
CPC_CUR_ENDLN,
CPC_CUR_HOMEBL,
CPC_DBLQUOTE,
CPC_DEL,
CPC_DOLLAR,
CPC_ENTER,
CPC_EQUAL,
CPC_ESC,
CPC_EXCLAMATN,
CPC_F0,
CPC_F1,
CPC_F2,
CPC_F3,
CPC_F4,
CPC_F5,
CPC_F6,
CPC_F7,
CPC_F8,
CPC_F9,
CPC_FPERIOD,
CPC_GREATER,
CPC_HASH,
CPC_LBRACKET,
CPC_LCBRACE,
CPC_LEFTPAREN,
CPC_LESS,
CPC_LSHIFT,
CPC_MINUS,
CPC_PERCENT,
CPC_PERIOD,
CPC_PIPE,
CPC_PLUS,
CPC_POUND,
CPC_POWER,
CPC_QUESTION,
CPC_QUOTE,
CPC_RBRACKET,
CPC_RCBRACE,
CPC_RETURN,
CPC_RIGHTPAREN,
CPC_RSHIFT,
CPC_SEMICOLON,
CPC_SLASH,
CPC_SPACE,
CPC_TAB,
CPC_UNDERSCORE,
CPC_J0_UP,
CPC_J0_DOWN,
CPC_J0_LEFT,
CPC_J0_RIGHT,
CPC_J0_FIRE1,
CPC_J0_FIRE2,
CPC_J1_UP,
CPC_J1_DOWN,
CPC_J1_LEFT,
CPC_J1_RIGHT,
CPC_J1_FIRE1,
CPC_J1_FIRE2,
CPC_ES_NTILDE,
CPC_ES_nTILDE,
CPC_ES_PESETA,
CPC_FR_eACUTE,
CPC_FR_eGRAVE,
CPC_FR_cCEDIL,
CPC_FR_aGRAVE,
CPC_FR_uGRAVE
} CPC_KEYS;
static dword cpc_kbd[3][149] = {
{ // original CPC keyboard
0x40, // CPC_0
0x80, // CPC_1
0x81, // CPC_2
0x71, // CPC_3
0x70, // CPC_4
0x61, // CPC_5
0x60, // CPC_6
0x51, // CPC_7
0x50, // CPC_8
0x41, // CPC_9
0x85 | MOD_CPC_SHIFT, // CPC_A
0x66 | MOD_CPC_SHIFT, // CPC_B
0x76 | MOD_CPC_SHIFT, // CPC_C
0x75 | MOD_CPC_SHIFT, // CPC_D
0x72 | MOD_CPC_SHIFT, // CPC_E
0x65 | MOD_CPC_SHIFT, // CPC_F
0x64 | MOD_CPC_SHIFT, // CPC_G
0x54 | MOD_CPC_SHIFT, // CPC_H
0x43 | MOD_CPC_SHIFT, // CPC_I
0x55 | MOD_CPC_SHIFT, // CPC_J
0x45 | MOD_CPC_SHIFT, // CPC_K
0x44 | MOD_CPC_SHIFT, // CPC_L
0x46 | MOD_CPC_SHIFT, // CPC_M
0x56 | MOD_CPC_SHIFT, // CPC_N
0x42 | MOD_CPC_SHIFT, // CPC_O
0x33 | MOD_CPC_SHIFT, // CPC_P
0x83 | MOD_CPC_SHIFT, // CPC_Q
0x62 | MOD_CPC_SHIFT, // CPC_R
0x74 | MOD_CPC_SHIFT, // CPC_S
0x63 | MOD_CPC_SHIFT, // CPC_T
0x52 | MOD_CPC_SHIFT, // CPC_U
0x67 | MOD_CPC_SHIFT, // CPC_V
0x73 | MOD_CPC_SHIFT, // CPC_W
0x77 | MOD_CPC_SHIFT, // CPC_X
0x53 | MOD_CPC_SHIFT, // CPC_Y
0x87 | MOD_CPC_SHIFT, // CPC_Z
0x85, // CPC_a
0x66, // CPC_b
0x76, // CPC_c
0x75, // CPC_d
0x72, // CPC_e
0x65, // CPC_f
0x64, // CPC_g
0x54, // CPC_h
0x43, // CPC_i
0x55, // CPC_j
0x45, // CPC_k
0x44, // CPC_l
0x46, // CPC_m
0x56, // CPC_n
0x42, // CPC_o
0x33, // CPC_p
0x83, // CPC_q
0x62, // CPC_r
0x74, // CPC_s
0x63, // CPC_t
0x52, // CPC_u
0x67, // CPC_v
0x73, // CPC_w
0x77, // CPC_x
0x53, // CPC_y
0x87, // CPC_z
0x60 | MOD_CPC_SHIFT, // CPC_AMPERSAND
0x35 | MOD_CPC_SHIFT, // CPC_ASTERISK
0x32, // CPC_AT
0x26 | MOD_CPC_SHIFT, // CPC_BACKQUOTE
0x26, // CPC_BACKSLASH
0x86, // CPC_CAPSLOCK
0x20, // CPC_CLR
0x35, // CPC_COLON
0x47, // CPC_COMMA
0x27, // CPC_CONTROL
0x11, // CPC_COPY
0x02 | MOD_CPC_SHIFT, // CPC_CPY_DOWN
0x10 | MOD_CPC_SHIFT, // CPC_CPY_LEFT
0x01 | MOD_CPC_SHIFT, // CPC_CPY_RIGHT
0x00 | MOD_CPC_SHIFT, // CPC_CPY_UP
0x02, // CPC_CUR_DOWN
0x10, // CPC_CUR_LEFT
0x01, // CPC_CUR_RIGHT
0x00, // CPC_CUR_UP
0x02 | MOD_CPC_CTRL, // CPC_CUR_ENDBL
0x10 | MOD_CPC_CTRL, // CPC_CUR_HOMELN
0x01 | MOD_CPC_CTRL, // CPC_CUR_ENDLN
0x00 | MOD_CPC_CTRL, // CPC_CUR_HOMEBL
0x81 | MOD_CPC_SHIFT, // CPC_DBLQUOTE
0x97, // CPC_DEL
0x70 | MOD_CPC_SHIFT, // CPC_DOLLAR
0x06, // CPC_ENTER
0x31 | MOD_CPC_SHIFT, // CPC_EQUAL
0x82, // CPC_ESC
0x80 | MOD_CPC_SHIFT, // CPC_EXCLAMATN
0x17, // CPC_F0
0x15, // CPC_F1
0x16, // CPC_F2
0x05, // CPC_F3
0x24, // CPC_F4
0x14, // CPC_F5
0x04, // CPC_F6
0x12, // CPC_F7
0x13, // CPC_F8
0x03, // CPC_F9
0x07, // CPC_FPERIOD
0x37 | MOD_CPC_SHIFT, // CPC_GREATER
0x71 | MOD_CPC_SHIFT, // CPC_HASH
0x21, // CPC_LBRACKET
0x21 | MOD_CPC_SHIFT, // CPC_LCBRACE
0x50 | MOD_CPC_SHIFT, // CPC_LEFTPAREN
0x47 | MOD_CPC_SHIFT, // CPC_LESS
0x25, // CPC_LSHIFT
0x31, // CPC_MINUS
0x61 | MOD_CPC_SHIFT, // CPC_PERCENT
0x37, // CPC_PERIOD
0x32 | MOD_CPC_SHIFT, // CPC_PIPE
0x34 | MOD_CPC_SHIFT, // CPC_PLUS
0x30 | MOD_CPC_SHIFT, // CPC_POUND
0x30, // CPC_POWER
0x36 | MOD_CPC_SHIFT, // CPC_QUESTION
0x51 | MOD_CPC_SHIFT, // CPC_QUOTE
0x23, // CPC_RBRACKET
0x23 | MOD_CPC_SHIFT, // CPC_RCBRACE
0x22, // CPC_RETURN
0x41 | MOD_CPC_SHIFT, // CPC_RIGHTPAREN
0x25, // CPC_RSHIFT
0x34, // CPC_SEMICOLON
0x36, // CPC_SLASH
0x57, // CPC_SPACE
0x84, // CPC_TAB
0x40 | MOD_CPC_SHIFT, // CPC_UNDERSCORE
0x90, // CPC_J0_UP
0x91, // CPC_J0_DOWN
0x92, // CPC_J0_LEFT
0x93, // CPC_J0_RIGHT
0x94, // CPC_J0_FIRE1
0x95, // CPC_J0_FIRE2
0x60, // CPC_J1_UP
0x61, // CPC_J1_DOWN
0x62, // CPC_J1_LEFT
0x63, // CPC_J1_RIGHT
0x64, // CPC_J1_FIRE1
0x65, // CPC_J1_FIRE2
0xff, // CPC_ES_NTILDE
0xff, // CPC_ES_nTILDE
0xff, // CPC_ES_PESETA
0xff, // CPC_FR_eACUTE
0xff, // CPC_FR_eGRAVE
0xff, // CPC_FR_cCEDIL
0xff, // CPC_FR_aGRAVE
0xff, // CPC_FR_uGRAVE
},
{ // French CPC keyboard
0x40 | MOD_CPC_SHIFT, // CPC_0
0x80 | MOD_CPC_SHIFT, // CPC_1
0x81 | MOD_CPC_SHIFT, // CPC_2
0x71 | MOD_CPC_SHIFT, // CPC_3
0x70 | MOD_CPC_SHIFT, // CPC_4
0x61 | MOD_CPC_SHIFT, // CPC_5
0x60 | MOD_CPC_SHIFT, // CPC_6
0x51 | MOD_CPC_SHIFT, // CPC_7
0x50 | MOD_CPC_SHIFT, // CPC_8
0x41 | MOD_CPC_SHIFT, // CPC_9
0x83 | MOD_CPC_SHIFT, // CPC_A
0x66 | MOD_CPC_SHIFT, // CPC_B
0x76 | MOD_CPC_SHIFT, // CPC_C
0x75 | MOD_CPC_SHIFT, // CPC_D
0x72 | MOD_CPC_SHIFT, // CPC_E
0x65 | MOD_CPC_SHIFT, // CPC_F
0x64 | MOD_CPC_SHIFT, // CPC_G
0x54 | MOD_CPC_SHIFT, // CPC_H
0x43 | MOD_CPC_SHIFT, // CPC_I
0x55 | MOD_CPC_SHIFT, // CPC_J
0x45 | MOD_CPC_SHIFT, // CPC_K
0x44 | MOD_CPC_SHIFT, // CPC_L
0x35 | MOD_CPC_SHIFT, // CPC_M
0x56 | MOD_CPC_SHIFT, // CPC_N
0x42 | MOD_CPC_SHIFT, // CPC_O
0x33 | MOD_CPC_SHIFT, // CPC_P
0x85 | MOD_CPC_SHIFT, // CPC_Q
0x62 | MOD_CPC_SHIFT, // CPC_R
0x74 | MOD_CPC_SHIFT, // CPC_S
0x63 | MOD_CPC_SHIFT, // CPC_T
0x52 | MOD_CPC_SHIFT, // CPC_U
0x67 | MOD_CPC_SHIFT, // CPC_V
0x87 | MOD_CPC_SHIFT, // CPC_W
0x77 | MOD_CPC_SHIFT, // CPC_X
0x53 | MOD_CPC_SHIFT, // CPC_Y
0x73 | MOD_CPC_SHIFT, // CPC_Z
0x83, // CPC_a
0x66, // CPC_b
0x76, // CPC_c
0x75, // CPC_d
0x72, // CPC_e
0x65, // CPC_f
0x64, // CPC_g
0x54, // CPC_h
0x43, // CPC_i
0x55, // CPC_j
0x45, // CPC_k
0x44, // CPC_l
0x35, // CPC_m
0x56, // CPC_n
0x42, // CPC_o
0x33, // CPC_p
0x85, // CPC_q
0x62, // CPC_r
0x74, // CPC_s
0x63, // CPC_t
0x52, // CPC_u
0x67, // CPC_v
0x87, // CPC_w
0x77, // CPC_x
0x53, // CPC_y
0x73, // CPC_z
0x80, // CPC_AMPERSAND
0x21, // CPC_ASTERISK
0x26 | MOD_CPC_SHIFT, // CPC_AT
0xff, // CPC_BACKQUOTE
0x26 | MOD_CPC_CTRL, // CPC_BACKSLASH
0x86, // CPC_CAPSLOCK
0x20, // CPC_CLR
0x37, // CPC_COLON
0x46, // CPC_COMMA
0x27, // CPC_CONTROL
0x11, // CPC_COPY
0x02 | MOD_CPC_SHIFT, // CPC_CPY_DOWN
0x10 | MOD_CPC_SHIFT, // CPC_CPY_LEFT
0x01 | MOD_CPC_SHIFT, // CPC_CPY_RIGHT
0x00 | MOD_CPC_SHIFT, // CPC_CPY_UP
0x02, // CPC_CUR_DOWN
0x10, // CPC_CUR_LEFT
0x01, // CPC_CUR_RIGHT
0x00, // CPC_CUR_UP
0x02 | MOD_CPC_CTRL, // CPC_CUR_ENDBL
0x10 | MOD_CPC_CTRL, // CPC_CUR_HOMELN
0x01 | MOD_CPC_CTRL, // CPC_CUR_ENDLN
0x00 | MOD_CPC_CTRL, // CPC_CUR_HOMEBL
0x71, // CPC_DBLQUOTE
0x97, // CPC_DEL
0x26, // CPC_DOLLAR
0x06, // CPC_ENTER
0x36, // CPC_EQUAL
0x82, // CPC_ESC
0x50, // CPC_EXCLAMATN
0x17, // CPC_F0
0x15, // CPC_F1
0x16, // CPC_F2
0x05, // CPC_F3
0x24, // CPC_F4
0x14, // CPC_F5
0x04, // CPC_F6
0x12, // CPC_F7
0x13, // CPC_F8
0x03, // CPC_F9
0x07, // CPC_FPERIOD
0x23 | MOD_CPC_SHIFT, // CPC_GREATER
0x23, // CPC_HASH
0x31 | MOD_CPC_SHIFT, // CPC_LBRACKET
0xff, // CPC_LCBRACE
0x61, // CPC_LEFTPAREN
0x21 | MOD_CPC_SHIFT, // CPC_LESS
0x25, // CPC_LSHIFT
0x30, // CPC_MINUS
0x34 | MOD_CPC_SHIFT, // CPC_PERCENT
0x47 | MOD_CPC_SHIFT, // CPC_PERIOD
0x32 | MOD_CPC_SHIFT, // CPC_PIPE
0x36 | MOD_CPC_SHIFT, // CPC_PLUS
0xff, // CPC_POUND
0x32, // CPC_POWER
0x46 | MOD_CPC_SHIFT, // CPC_QUESTION
0x70, // CPC_QUOTE
0x60, // CPC_RBRACKET
0xff, // CPC_RCBRACE
0x22, // CPC_RETURN
0x31, // CPC_RIGHTPAREN
0x25, // CPC_RSHIFT
0x47, // CPC_SEMICOLON
0x37 | MOD_CPC_SHIFT, // CPC_SLASH
0x57, // CPC_SPACE
0x84, // CPC_TAB
0x30 | MOD_CPC_SHIFT, // CPC_UNDERSCORE
0x90, // CPC_J0_UP
0x91, // CPC_J0_DOWN
0x92, // CPC_J0_LEFT
0x93, // CPC_J0_RIGHT
0x94, // CPC_J0_FIRE1
0x95, // CPC_J0_FIRE2
0x60, // CPC_J1_UP
0x61, // CPC_J1_DOWN
0x62, // CPC_J1_LEFT
0x63, // CPC_J1_RIGHT
0x64, // CPC_J1_FIRE1
0x65, // CPC_J1_FIRE2
0xff, // CPC_ES_NTILDE
0xff, // CPC_ES_nTILDE
0xff, // CPC_ES_PESETA
0x81, // CPC_FR_eACUTE
0x51, // CPC_FR_eGRAVE
0x41, // CPC_FR_cCEDIL
0x40, // CPC_FR_aGRAVE
0x34, // CPC_FR_uGRAVE
},
{ // Spanish CPC keyboard
0x40, // CPC_0
0x80, // CPC_1
0x81, // CPC_2
0x71, // CPC_3
0x70, // CPC_4
0x61, // CPC_5
0x60, // CPC_6
0x51, // CPC_7
0x50, // CPC_8
0x41, // CPC_9
0x85 | MOD_CPC_SHIFT, // CPC_A
0x66 | MOD_CPC_SHIFT, // CPC_B
0x76 | MOD_CPC_SHIFT, // CPC_C
0x75 | MOD_CPC_SHIFT, // CPC_D
0x72 | MOD_CPC_SHIFT, // CPC_E
0x65 | MOD_CPC_SHIFT, // CPC_F
0x64 | MOD_CPC_SHIFT, // CPC_G
0x54 | MOD_CPC_SHIFT, // CPC_H
0x43 | MOD_CPC_SHIFT, // CPC_I
0x55 | MOD_CPC_SHIFT, // CPC_J
0x45 | MOD_CPC_SHIFT, // CPC_K
0x44 | MOD_CPC_SHIFT, // CPC_L
0x46 | MOD_CPC_SHIFT, // CPC_M
0x56 | MOD_CPC_SHIFT, // CPC_N
0x42 | MOD_CPC_SHIFT, // CPC_O
0x33 | MOD_CPC_SHIFT, // CPC_P
0x83 | MOD_CPC_SHIFT, // CPC_Q
0x62 | MOD_CPC_SHIFT, // CPC_R
0x74 | MOD_CPC_SHIFT, // CPC_S
0x63 | MOD_CPC_SHIFT, // CPC_T
0x52 | MOD_CPC_SHIFT, // CPC_U
0x67 | MOD_CPC_SHIFT, // CPC_V
0x73 | MOD_CPC_SHIFT, // CPC_W
0x77 | MOD_CPC_SHIFT, // CPC_X
0x53 | MOD_CPC_SHIFT, // CPC_Y
0x87 | MOD_CPC_SHIFT, // CPC_Z
0x85, // CPC_a
0x66, // CPC_b
0x76, // CPC_c
0x75, // CPC_d
0x72, // CPC_e
0x65, // CPC_f
0x64, // CPC_g
0x54, // CPC_h
0x43, // CPC_i
0x55, // CPC_j
0x45, // CPC_k
0x44, // CPC_l
0x46, // CPC_m
0x56, // CPC_n
0x42, // CPC_o
0x33, // CPC_p
0x83, // CPC_q
0x62, // CPC_r
0x74, // CPC_s
0x63, // CPC_t
0x52, // CPC_u
0x67, // CPC_v
0x73, // CPC_w
0x77, // CPC_x
0x53, // CPC_y
0x87, // CPC_z
0x60 | MOD_CPC_SHIFT, // CPC_AMPERSAND
0x21 | MOD_CPC_SHIFT, // CPC_ASTERISK
0x32, // CPC_AT
0x26 | MOD_CPC_SHIFT, // CPC_BACKQUOTE
0x26, // CPC_BACKSLASH
0x86, // CPC_CAPSLOCK
0x20, // CPC_CLR
0x34 | MOD_CPC_SHIFT, // CPC_COLON
0x47, // CPC_COMMA
0x27, // CPC_CONTROL
0x11, // CPC_COPY
0x02 | MOD_CPC_SHIFT, // CPC_CPY_DOWN
0x10 | MOD_CPC_SHIFT, // CPC_CPY_LEFT
0x01 | MOD_CPC_SHIFT, // CPC_CPY_RIGHT
0x00 | MOD_CPC_SHIFT, // CPC_CPY_UP
0x02, // CPC_CUR_DOWN
0x10, // CPC_CUR_LEFT
0x01, // CPC_CUR_RIGHT
0x00, // CPC_CUR_UP
0x02 | MOD_CPC_CTRL, // CPC_CUR_ENDBL
0x10 | MOD_CPC_CTRL, // CPC_CUR_HOMELN
0x01 | MOD_CPC_CTRL, // CPC_CUR_ENDLN
0x00 | MOD_CPC_CTRL, // CPC_CUR_HOMEBL
0x81 | MOD_CPC_SHIFT, // CPC_DBLQUOTE
0x97, // CPC_DEL
0x70 | MOD_CPC_SHIFT, // CPC_DOLLAR
0x06, // CPC_ENTER
0x31 | MOD_CPC_SHIFT, // CPC_EQUAL
0x82, // CPC_ESC
0x80 | MOD_CPC_SHIFT, // CPC_EXCLAMATN
0x17, // CPC_F0
0x15, // CPC_F1
0x16, // CPC_F2
0x05, // CPC_F3
0x24, // CPC_F4
0x14, // CPC_F5
0x04, // CPC_F6
0x12, // CPC_F7
0x13, // CPC_F8
0x03, // CPC_F9
0x07, // CPC_FPERIOD
0x37 | MOD_CPC_SHIFT, // CPC_GREATER
0x71 | MOD_CPC_SHIFT, // CPC_HASH
0x21, // CPC_LBRACKET
0xff, // CPC_LCBRACE
0x50 | MOD_CPC_SHIFT, // CPC_LEFTPAREN
0x47 | MOD_CPC_SHIFT, // CPC_LESS
0x25, // CPC_LSHIFT
0x31, // CPC_MINUS
0x61 | MOD_CPC_SHIFT, // CPC_PERCENT
0x37, // CPC_PERIOD
0x32 | MOD_CPC_SHIFT, // CPC_PIPE
0x23 | MOD_CPC_SHIFT, // CPC_PLUS
0xff, // CPC_POUND
0x30, // CPC_POWER
0x36 | MOD_CPC_SHIFT, // CPC_QUESTION
0x51 | MOD_CPC_SHIFT, // CPC_QUOTE
0x23, // CPC_RBRACKET
0xff, // CPC_RCBRACE
0x22, // CPC_RETURN
0x41 | MOD_CPC_SHIFT, // CPC_RIGHTPAREN
0x25, // CPC_RSHIFT
0x34, // CPC_SEMICOLON
0x36, // CPC_SLASH
0x57, // CPC_SPACE
0x84, // CPC_TAB
0x40 | MOD_CPC_SHIFT, // CPC_UNDERSCORE
0x90, // CPC_J0_UP
0x91, // CPC_J0_DOWN
0x92, // CPC_J0_LEFT
0x93, // CPC_J0_RIGHT
0x94, // CPC_J0_FIRE1
0x95, // CPC_J0_FIRE2
0x60, // CPC_J1_UP
0x61, // CPC_J1_DOWN
0x62, // CPC_J1_LEFT
0x63, // CPC_J1_RIGHT
0x64, // CPC_J1_FIRE1
0x65, // CPC_J1_FIRE2
0x35 | MOD_CPC_SHIFT, // CPC_ES_NTILDE
0x35, // CPC_ES_nTILDE
0x30 | MOD_CPC_SHIFT, // CPC_ES_PESETA
0xff, // CPC_FR_eACUTE
0xff, // CPC_FR_eGRAVE
0xff, // CPC_FR_cCEDIL
0xff, // CPC_FR_aGRAVE
0xff, // CPC_FR_uGRAVE
}
};
#define MOD_PC_SHIFT (KMOD_SHIFT << 16)
#define MOD_PC_CTRL (KMOD_CTRL << 16)
#define MOD_PC_MODE (KMOD_MODE << 16)
#define KBD_MAX_ENTRIES 160
static int kbd_layout[4][KBD_MAX_ENTRIES][2] = {
{ // US PC to CPC keyboard layout translation
{ CPC_0, SDLK_0 },
{ CPC_1, SDLK_1 },
{ CPC_2, SDLK_2 },
{ CPC_3, SDLK_3 },
{ CPC_4, SDLK_4 },
{ CPC_5, SDLK_5 },
{ CPC_6, SDLK_6 },
{ CPC_7, SDLK_7 },
{ CPC_8, SDLK_8 },
{ CPC_9, SDLK_9 },
{ CPC_A, SDLK_a | MOD_PC_SHIFT },
{ CPC_B, SDLK_b | MOD_PC_SHIFT },
{ CPC_C, SDLK_c | MOD_PC_SHIFT },
{ CPC_D, SDLK_d | MOD_PC_SHIFT },
{ CPC_E, SDLK_e | MOD_PC_SHIFT },
{ CPC_F, SDLK_f | MOD_PC_SHIFT },
{ CPC_G, SDLK_g | MOD_PC_SHIFT },
{ CPC_H, SDLK_h | MOD_PC_SHIFT },
{ CPC_I, SDLK_i | MOD_PC_SHIFT },
{ CPC_J, SDLK_j | MOD_PC_SHIFT },
{ CPC_K, SDLK_k | MOD_PC_SHIFT },
{ CPC_L, SDLK_l | MOD_PC_SHIFT },
{ CPC_M, SDLK_m | MOD_PC_SHIFT },
{ CPC_N, SDLK_n | MOD_PC_SHIFT },
{ CPC_O, SDLK_o | MOD_PC_SHIFT },
{ CPC_P, SDLK_p | MOD_PC_SHIFT },
{ CPC_Q, SDLK_q | MOD_PC_SHIFT },
{ CPC_R, SDLK_r | MOD_PC_SHIFT },
{ CPC_S, SDLK_s | MOD_PC_SHIFT },
{ CPC_T, SDLK_t | MOD_PC_SHIFT },
{ CPC_U, SDLK_u | MOD_PC_SHIFT },
{ CPC_V, SDLK_v | MOD_PC_SHIFT },
{ CPC_W, SDLK_w | MOD_PC_SHIFT },
{ CPC_X, SDLK_x | MOD_PC_SHIFT },
{ CPC_Y, SDLK_y | MOD_PC_SHIFT },
{ CPC_Z, SDLK_z | MOD_PC_SHIFT },
{ CPC_a, SDLK_a },
{ CPC_b, SDLK_b },
{ CPC_c, SDLK_c },
{ CPC_d, SDLK_d },
{ CPC_e, SDLK_e },
{ CPC_f, SDLK_f },
{ CPC_g, SDLK_g },
{ CPC_h, SDLK_h },
{ CPC_i, SDLK_i },
{ CPC_j, SDLK_j },