forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcemglue.cpp
1105 lines (992 loc) · 25.8 KB
/
pcemglue.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
#include "uae.h"
#include "ibm.h"
#include "pit.h"
#include "pic.h"
#include "cpu.h"
#include "model.h"
#include "x86.h"
#include "x86_ops.h"
#include "codegen.h"
#include "timer.h"
#include "sound.h"
#include "rom.h"
#include "thread.h"
#ifdef _WIN32
#include <windows.h>
#include "midi.h"
#endif
#include "pcemglue.h"
#include "sysconfig.h"
#include "sysdeps.h"
#include "threaddep/thread.h"
#include "machdep/maccess.h"
#include "gfxboard.h"
#include "uae/time.h"
#include "video.h"
#include "vid_svga.h"
CPU_STATE cpu_state;
PIT pit, pit2;
PIC pic, pic2;
dma_t dma[8];
int AT;
int ppispeakon;
int gated, speakval, speakon;
PPI ppi;
int codegen_flags_changed;
uint32_t codegen_endpc;
int codegen_in_recompile;
int codegen_flat_ds, codegen_flat_ss;
uint32_t recomp_page;
uint16_t *codeblock_hash;
codeblock_t *codeblock;
void codegen_reset(void)
{
}
void codegen_block_init(unsigned int)
{
}
void codegen_block_remove()
{
}
void codegen_block_start_recompile(struct codeblock_t *)
{
}
void codegen_block_end_recompile(struct codeblock_t *)
{
}
void codegen_block_end()
{
}
void codegen_generate_call(uint8_t opcode, OpFn op, uint32_t fetchdat, uint32_t new_pc, uint32_t old_pc)
{
}
void codegen_check_flush(struct page_t *page, uint64_t mask, uint32_t phys_addr)
{
}
void codegen_flush(void)
{
}
void codegen_init(void)
{
}
void pclog(char const *format, ...)
{
va_list parms;
va_start(parms, format);
char buf[256];
vsprintf(buf, format, parms);
write_log("%s", buf);
va_end(parms);
}
extern void activate_debugger(void);
void fatal(char const *format, ...)
{
va_list parms;
va_start(parms, format);
char buf[256];
vsprintf(buf, format, parms);
write_log("PCEMFATAL: %s", buf);
va_end(parms);
activate_debugger();
}
void video_updatetiming(void)
{
write_log(_T("video_updatetiming\n"));
}
void device_speed_changed(void)
{
write_log(_T("device_speed_changed\n"));
}
int model;
int cpuspeed;
int insc;
int hasfpu;
int romset;
int nmi_mask;
uint32_t rammask;
uintptr_t *readlookup2;
uintptr_t *writelookup2;
uint16_t flags, eflags;
int writelookup[256], writelookupp[256];
int readlookup[256], readlookupp[256];
int readlnext;
int writelnext;
uint32_t olddslimit, oldsslimit, olddslimitw, oldsslimitw;
int pci_burst_time, pci_nonburst_time;
uint32_t oxpc;
char logs_path[512];
uint32_t ealimit, ealimitw;
int MCA;
struct svga_t *mb_vga;
uint32_t x87_pc_off, x87_op_off;
uint16_t x87_pc_seg, x87_op_seg;
int xi8088_bios_128kb(void)
{
return 0;
}
uint8_t portin(uint16_t portnum);
uint8_t inb(uint16_t port)
{
return portin(port);
}
void portout(uint16_t, uint8_t);
void outb(uint16_t port, uint8_t v)
{
portout(port, v);
}
uint16_t portin16(uint16_t portnum);
uint16_t inw(uint16_t port)
{
return portin16(port);
}
void portout16(uint16_t portnum, uint16_t value);
void outw(uint16_t port, uint16_t val)
{
portout16(port, val);
}
uint32_t portin32(uint16_t portnum);
uint32_t inl(uint16_t port)
{
return portin32(port);
}
void portout32(uint16_t portnum, uint32_t value);
void outl(uint16_t port, uint32_t val)
{
portout32(port, val);
}
static void model_init(void)
{
}
int AMSTRAD;
int TANDY;
int keybsenddelay;
int mouse_buttons;
int mouse_type;
uint8_t pcem_key[272];
int mouse_get_type(int mouse_type)
{
return 0;
}
void t3100e_notify_set(unsigned char v)
{
}
void t3100e_display_set(unsigned char v)
{
}
void t3100e_turbo_set(unsigned char v)
{
}
void t3100e_mono_set(unsigned char v)
{
}
uint8_t t3100e_display_get()
{
return 0;
}
uint8_t t3100e_config_get()
{
return 0;
}
uint8_t t3100e_mono_get()
{
return 0;
}
void xi8088_turbo_set(unsigned char v)
{
}
uint8_t xi8088_turbo_get()
{
return 0;
}
void ps2_cache_clean(void)
{
}
int video_is_mda()
{
return 0;
}
static FPU fpus_none[] =
{
{ "None", "none", FPU_NONE },
{ NULL, NULL, 0 }
};
static FPU fpus_8088[] =
{
{ "None", "none", FPU_NONE },
{ "8087", "8087", FPU_8087 },
{ NULL, NULL, 0 }
};
static FPU fpus_80286[] =
{
{ "None", "none", FPU_NONE },
{ "287", "287", FPU_287 },
{ "287XL", "287xl", FPU_287XL },
{ NULL, NULL, 0 }
};
static FPU fpus_80386[] =
{
{ "None", "none", FPU_NONE },
{ "387", "387", FPU_387 },
{ NULL, NULL, 0 }
};
static FPU fpus_builtin[] =
{
{ "Built-in", "builtin", FPU_BUILTIN },
{ NULL, NULL, 0 }
};
static CPU cpus_8088[] =
{
/*8088 standard*/
{ "8088/4.77", CPU_8088, fpus_8088, 0, 4772728, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ "8088/7.16", CPU_8088, fpus_8088, 1, 14318184 / 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ "8088/8", CPU_8088, fpus_8088, 1, 8000000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ "8088/10", CPU_8088, fpus_8088, 2, 10000000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ "8088/12", CPU_8088, fpus_8088, 3, 12000000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ "8088/16", CPU_8088, fpus_8088, 4, 16000000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ "", -1, 0, 0, 0, 0 }
};
static CPU cpus_286[] =
{
/*286*/
{ "286/6", CPU_286, fpus_80286, 0, 6000000, 1, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1 },
{ "286/8", CPU_286, fpus_80286, 1, 8000000, 1, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1 },
{ "286/10", CPU_286, fpus_80286, 2, 10000000, 1, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1 },
{ "286/12", CPU_286, fpus_80286, 3, 12000000, 1, 0, 0, 0, 0, 0, 3, 3, 3, 3, 2 },
{ "286/16", CPU_286, fpus_80286, 4, 16000000, 1, 0, 0, 0, 0, 0, 3, 3, 3, 3, 2 },
{ "286/20", CPU_286, fpus_80286, 5, 20000000, 1, 0, 0, 0, 0, 0, 4, 4, 4, 4, 3 },
{ "286/25", CPU_286, fpus_80286, 6, 25000000, 1, 0, 0, 0, 0, 0, 4, 4, 4, 4, 3 },
{ "", -1, 0, 0, 0, 0 }
};
static CPU cpus_i386SX[] =
{
/*i386SX*/
{ "i386SX/16", CPU_386SX, fpus_80386, 0, 16000000, 1, 0, 0x2308, 0, 0, 0, 3, 3, 3, 3, 2 },
{ "i386SX/20", CPU_386SX, fpus_80386, 1, 20000000, 1, 0, 0x2308, 0, 0, 0, 4, 4, 3, 3, 3 },
{ "i386SX/25", CPU_386SX, fpus_80386, 2, 25000000, 1, 0, 0x2308, 0, 0, 0, 4, 4, 3, 3, 3 },
{ "i386SX/33", CPU_386SX, fpus_80386, 3, 33333333, 1, 0, 0x2308, 0, 0, 0, 6, 6, 3, 3, 4 },
{ "", -1, 0, 0, 0 }
};
static CPU cpus_i386DX[] =
{
/*i386DX*/
{ "i386DX/16", CPU_386DX, fpus_80386, 0, 16000000, 1, 0, 0x0308, 0, 0, 0, 3, 3, 3, 3, 2 },
{ "i386DX/20", CPU_386DX, fpus_80386, 1, 20000000, 1, 0, 0x0308, 0, 0, 0, 4, 4, 3, 3, 3 },
{ "i386DX/25", CPU_386DX, fpus_80386, 2, 25000000, 1, 0, 0x0308, 0, 0, 0, 4, 4, 3, 3, 3 },
{ "i386DX/33", CPU_386DX, fpus_80386, 3, 33333333, 1, 0, 0x0308, 0, 0, 0, 6, 6, 3, 3, 4 },
{ "", -1, 0, 0, 0 }
};
static CPU cpus_i486[] =
{
/*i486*/
{ "i486SX/16", CPU_i486SX, fpus_none, 0, 16000000, 1, 16000000, 0x42a, 0, 0, CPU_SUPPORTS_DYNAREC, 3, 3, 3, 3, 2 },
{ "i486SX/20", CPU_i486SX, fpus_none, 1, 20000000, 1, 20000000, 0x42a, 0, 0, CPU_SUPPORTS_DYNAREC, 4, 4, 3, 3, 3 },
{ "i486SX/25", CPU_i486SX, fpus_none, 2, 25000000, 1, 25000000, 0x42a, 0, 0, CPU_SUPPORTS_DYNAREC, 4, 4, 3, 3, 3 },
{ "i486SX/33", CPU_i486SX, fpus_none, 3, 33333333, 1, 33333333, 0x42a, 0, 0, CPU_SUPPORTS_DYNAREC, 6, 6, 3, 3, 4 },
{ "i486SX2/50", CPU_i486SX, fpus_none, 5, 50000000, 2, 25000000, 0x45b, 0, 0, CPU_SUPPORTS_DYNAREC, 8, 8, 6, 6, 2 * 3 },
{ "i486DX/25", CPU_i486DX, fpus_builtin, 2, 25000000, 1, 25000000, 0x404, 0, 0, CPU_SUPPORTS_DYNAREC, 4, 4, 3, 3, 3 },
{ "i486DX/33", CPU_i486DX, fpus_builtin, 3, 33333333, 1, 33333333, 0x404, 0, 0, CPU_SUPPORTS_DYNAREC, 6, 6, 3, 3, 4 },
{ "i486DX/50", CPU_i486DX, fpus_builtin, 5, 50000000, 1, 25000000, 0x404, 0, 0, CPU_SUPPORTS_DYNAREC, 8, 8, 4, 4, 6 },
{ "i486DX2/40", CPU_i486DX, fpus_builtin, 4, 40000000, 2, 20000000, 0x430, 0, 0, CPU_SUPPORTS_DYNAREC, 8, 8, 6, 6, 2 * 3 },
{ "i486DX2/50", CPU_i486DX, fpus_builtin, 5, 50000000, 2, 25000000, 0x430, 0, 0, CPU_SUPPORTS_DYNAREC, 8, 8, 6, 6, 2 * 3 },
{ "i486DX2/66", CPU_i486DX, fpus_builtin, 6, 66666666, 2, 33333333, 0x430, 0, 0, CPU_SUPPORTS_DYNAREC, 12, 12, 6, 6, 2 * 4 },
{ "", -1, 0, 0, 0 }
};
MODEL models[] =
{
{ "[8088] Generic XT clone", ROM_GENXT, "genxt", { { "", cpus_8088 }, { "", NULL }, { "", NULL } }, MODEL_GFX_NONE, 32, 704, 16, model_init, NULL },
{ "[286] AMI 286 clone", ROM_AMI286, "ami286", { { "", cpus_286 }, { "", NULL }, { "", NULL } }, MODEL_GFX_NONE | MODEL_AT | MODEL_HAS_IDE, 512, 16384, 128, model_init, NULL },
{ "[386SX] AMI 386SX clone", ROM_AMI386SX, "ami386", { { "386SX", cpus_i386SX }, { "386DX", cpus_i386DX }, { "486", cpus_i486 } }, MODEL_GFX_NONE | MODEL_AT | MODEL_HAS_IDE, 512, 16384, 128, model_init, NULL },
};
int rom_present(const char *s)
{
return 0;
}
static int midi_open;
void midi_write(uint8_t v)
{
if (!midi_open) {
midi_open = Midi_Open();
}
Midi_Parse(midi_output, &v);
}
void pcem_close(void)
{
if (midi_open)
Midi_Close();
midi_open = 0;
}
#ifdef CPU_i386
void codegen_set_rounding_mode(int mode)
{
/*SSE*/
cpu_state.new_fp_control = (cpu_state.old_fp_control & ~0x6000) | (mode << 13);
/*x87 - used for double -> i64 conversions*/
cpu_state.new_fp_control2 = (cpu_state.old_fp_control2 & ~0x0c00) | (mode << 10);
}
#else
void codegen_set_rounding_mode(int mode)
{
/*SSE*/
cpu_state.new_fp_control = (cpu_state.old_fp_control & ~0x6000) | (mode << 13);
}
#endif
// VIDEO STUFF
int video_timing_read_b;
int video_timing_read_w;
int video_timing_read_l;
int video_timing_write_b;
int video_timing_write_w;
int video_timing_write_l;
int cycles_lost;
uint8_t fontdat[2048][8];
uint8_t fontdatm[2048][16];
uint8_t fontdatw[512][32]; /* Wyse700 font */
uint8_t fontdat8x12[256][16]; /* MDSI Genius font */
uint8_t fontdat12x18[256][36]; /* IM1024 font */
uint8_t fontdatksc5601[16384][32]; /* Korean KSC-5601 font */
uint8_t fontdatksc5601_user[192][32]; /* Korean KSC-5601 user defined font */
int PCI;
int readflash;
int egareads;
int egawrites;
int changeframecount;
PCBITMAP *buffer32;
static int buffer32size;
static uae_u8 *tempbuf;
int vid_resize;
int xsize, ysize;
uint64_t timer_freq;
uint8_t edatlookup[4][4];
uint8_t rotatevga[8][256];
uint32_t *video_15to32, *video_16to32;
static void *gfxboard_priv;
static mem_mapping_t *pcem_mapping_linear;
void *pcem_mapping_linear_priv;
uae_u32 pcem_mapping_linear_offset;
uint8_t(*pcem_linear_read_b)(uint32_t addr, void *priv);
uint16_t(*pcem_linear_read_w)(uint32_t addr, void *priv);
uint32_t(*pcem_linear_read_l)(uint32_t addr, void *priv);
void (*pcem_linear_write_b)(uint32_t addr, uint8_t val, void *priv);
void (*pcem_linear_write_w)(uint32_t addr, uint16_t val, void *priv);
void (*pcem_linear_write_l)(uint32_t addr, uint32_t val, void *priv);
#define MAX_PCEMMAPPINGS 10
static mem_mapping_t *pcemmappings[MAX_PCEMMAPPINGS];
#define PCEMMAPBLOCKSIZE 0x10000
#define MAX_PCEMMAPBLOCKS (0x80000000 / PCEMMAPBLOCKSIZE)
mem_mapping_t **pcemmap;
static uint8_t dummy_bread(uint32_t addr, void *p)
{
return 0;
}
static uint16_t dummy_wread(uint32_t addr, void *p)
{
return 0;
}
static uint32_t dummy_lread(uint32_t addr, void *p)
{
return 0;
}
static void dummy_bwrite(uint32_t addr, uint8_t v, void *p)
{
}
static void dummy_wwrite(uint32_t addr, uint16_t v, void *p)
{
}
static void dummy_lwrite(uint32_t addr, uint32_t v, void *p)
{
}
uint64_t timer_read(void)
{
return read_processor_time();
}
static pc_timer_t *timer_head = NULL;
void timer_enablex(pc_timer_t *timer)
{
pc_timer_t *timer_node = timer_head;
if (timer->enabled)
timer_disablex(timer);
timer->enabled = 1;
if (!timer_head)
{
timer_head = timer;
timer->next = timer->prev = NULL;
return;
}
timer_node = timer_head;
}
void timer_disablex(pc_timer_t *timer)
{
if (!timer->enabled)
return;
timer->enabled = 0;
if (timer->prev)
timer->prev->next = timer->next;
else
timer_head = timer->next;
if (timer->next)
timer->next->prev = timer->prev;
timer->prev = timer->next = NULL;
}
void timer_addx(pc_timer_t *timer, void (*callback)(void* p), void *p, int start_timer)
{
memset(timer, 0, sizeof(pc_timer_t));
timer->callback = callback;
timer->p = p;
timer->enabled = 0;
timer->prev = timer->next = NULL;
}
void timer_set_delay_u64x(pc_timer_t *timer, uint64_t delay)
{
timer_enablex(timer);
}
static void timer_remove_headx(void)
{
if (timer_head)
{
pc_timer_t *timer = timer_head;
timer_head = timer->next;
if (timer_head) {
timer_head->prev = NULL;
}
timer->next = timer->prev = NULL;
timer->enabled = 0;
}
}
void pcemglue_hsync(void)
{
while (timer_head) {
timer_head->callback(timer_head->p);
timer_remove_headx();
}
}
void initpcemvideo(void *p, bool swapped)
{
int c, d, e;
int pcemblocks = MAX_PCEMMAPBLOCKS;
if (!pcemmap) {
pcemmap = xcalloc(mem_mapping_t *, pcemblocks);
if (!pcemmap) {
gui_message(_T("out of memory for PCI mappin table\n"));
abort();
}
}
for (int i = 0; i < pcemblocks; i++) {
pcemmap[i] = NULL;
}
for (int i = 0; i < MAX_PCEMMAPPINGS; i++) {
pcemmappings[i] = NULL;
}
gfxboard_priv = p;
has_vlb = 0;
timer_freq = syncbase;
for (c = 0; c < 256; c++)
{
e = c;
for (d = 0; d < 8; d++)
{
rotatevga[d][c] = e;
e = (e >> 1) | ((e & 1) ? 0x80 : 0);
}
}
for (c = 0; c < 4; c++)
{
for (d = 0; d < 4; d++)
{
edatlookup[c][d] = 0;
if (c & 1) edatlookup[c][d] |= 1;
if (d & 1) edatlookup[c][d] |= 2;
if (c & 2) edatlookup[c][d] |= 0x10;
if (d & 2) edatlookup[c][d] |= 0x20;
// printf("Edat %i,%i now %02X\n",c,d,edatlookup[c][d]);
}
}
if (!video_15to32)
video_15to32 = (uint32_t*)malloc(4 * 65536);
for (c = 0; c < 65536; c++) {
if (swapped) {
video_15to32[c] = (((c >> 10) & 31) << 3) | (((c >> 5) & 31) << 11) | (((c >> 0) & 31) << 19);
} else {
video_15to32[c] = ((c & 31) << 3) | (((c >> 5) & 31) << 11) | (((c >> 10) & 31) << 19);
}
}
if (!video_16to32)
video_16to32 = (uint32_t*)malloc(4 * 65536);
for (c = 0; c < 65536; c++) {
if (swapped) {
video_16to32[c] = (((c >> 11) & 31) << 3) | (((c >> 5) & 63) << 10) | (((c >> 0) & 31) << 19);
} else {
video_16to32[c] = ((c & 31) << 3) | (((c >> 5) & 63) << 10) | (((c >> 11) & 31) << 19);
}
}
if (!buffer32) {
buffer32 = (PCBITMAP *)calloc(sizeof(PCBITMAP) + sizeof(uint8_t *) * 4096, 1);
buffer32->w = 2048;
buffer32->h = 4096;
buffer32->dat = xcalloc(uae_u8, buffer32->w * buffer32->h * 4);
for (int i = 0; i < buffer32->h; i++) {
buffer32->line[i] = buffer32->dat + buffer32->w * 4 * i;
}
}
pcem_linear_read_b = dummy_bread;
pcem_linear_read_w = dummy_wread;
pcem_linear_read_l = dummy_lread;
pcem_linear_write_b = dummy_bwrite;
pcem_linear_write_w = dummy_wwrite;
pcem_linear_write_l = dummy_lwrite;
pcem_mapping_linear = NULL;
pcem_mapping_linear_offset = 0;
timer_head = NULL;
}
extern void *svga_get_object(void);
uae_u8 pcem_read_io(int port, int index)
{
svga_t *svga = (svga_t*)svga_get_object();
if (port == 0x3d5) {
return svga->crtc[index];
} else {
write_log("unknown port %04x!\n", port);
abort();
}
}
#if 0
void update_pcembuffer32(void *buf, int w, int h, int bytesperline)
{
if (!buf) {
w = 2048;
h = 2048;
if (!tempbuf) {
tempbuf = xmalloc(uae_u8, w * 4);
}
buf = tempbuf;
bytesperline = 0;
}
if (!buffer32 || h > buffer32->h) {
free(buffer32);
buffer32 = (PCBITMAP *)calloc(sizeof(PCBITMAP) + sizeof(uint8_t *) * h, 1);
}
if (buffer32->w == w && buffer32->h == h && buffer32->line[0] == buf)
return;
buffer32->w = w;
buffer32->h = h;
uae_u8 *b = (uae_u8*)buf;
for (int i = 0; i < h; i++) {
buffer32->line[i] = b;
b += bytesperline;
}
}
#endif
uae_u8 *getpcembuffer32(int x, int y, int yy)
{
return buffer32->line[y + yy] + x * 4;
}
void video_wait_for_buffer(void)
{
//write_log(_T("video_wait_for_buffer\n"));
}
void updatewindowsize(int x, int mx, int y, int my)
{
x *= mx;
gfxboard_resize(x, y, mx, my, gfxboard_priv);
}
static void (*pci_card_write)(int func, int addr, uint8_t val, void *priv);
static uint8_t(*pci_card_read)(int func, int addr, void *priv);
static void *pci_card_priv;
void put_pci_pcem(uaecptr addr, uae_u8 v)
{
if (pci_card_write) {
pci_card_write(0, addr, v, pci_card_priv);
}
}
uae_u8 get_pci_pcem(uaecptr addr)
{
uae_u8 v = 0;
if (pci_card_read) {
v = pci_card_read(0, addr, pci_card_priv);
}
return v;
}
int pci_add(uint8_t(*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv)
{
pci_card_read = read;
pci_card_write = write;
pci_card_priv = priv;
return 0;
}
extern void gfxboard_intreq(void *, int, bool);
void pci_set_irq_routing(int card, int irq)
{
//write_log(_T("pci_set_irq_routing %d %d\n"), card, irq);
}
void pci_set_irq(int card, int pci_int)
{
//write_log(_T("pci_set_irq %d %d\n"), card, pci_int);
gfxboard_intreq(gfxboard_priv, 1, true);
}
void pci_clear_irq(int card, int pci_int)
{
//write_log(_T("pci_clear_irq %d %d\n"), card, pci_int);
gfxboard_intreq(gfxboard_priv, 0, true);
}
int rom_init(rom_t *rom, char *fn, uint32_t address, int size, int mask, int file_offset, uint32_t flags)
{
return 0;
}
void thread_sleep(int n)
{
sleep_millis(n);
}
thread_t *thread_create(void (*thread_rout)(void *param), void *param)
{
uae_thread_id tid;
uae_start_thread(_T("PCem helper"), thread_rout, param, &tid);
return tid;
}
void thread_kill(thread_t *handle)
{
uae_end_thread((uae_thread_id*)&handle);
}
event_t *thread_create_event(void)
{
uae_sem_t sem = { 0 };
uae_sem_init(&sem, 1, 0);
return sem;
}
void thread_set_event(event_t *event)
{
uae_sem_post((uae_sem_t*)&event);
}
void thread_reset_event(event_t *_event)
{
uae_sem_init((uae_sem_t*)&_event, 1, 0);
}
int thread_wait_event(event_t *event, int timeout)
{
uae_sem_trywait_delay((uae_sem_t*)&event, timeout < 0 ? INFINITE : timeout);
return 0;
}
void thread_destroy_event(event_t *_event)
{
uae_sem_destroy((uae_sem_t*)&_event);
}
typedef struct win_mutex_t
{
HANDLE handle;
} win_mutex_t;
mutex_t* thread_create_mutex(void)
{
win_mutex_t *mutex = xcalloc(win_mutex_t,1);
mutex->handle = CreateSemaphore(NULL, 1, 1, NULL);
return mutex;
}
void thread_lock_mutex(mutex_t *_mutex)
{
win_mutex_t *mutex = (win_mutex_t*)_mutex;
WaitForSingleObject(mutex->handle, INFINITE);
}
void thread_unlock_mutex(mutex_t *_mutex)
{
win_mutex_t *mutex = (win_mutex_t*)_mutex;
ReleaseSemaphore(mutex->handle, 1, NULL);
}
void thread_destroy_mutex(mutex_t *_mutex)
{
win_mutex_t *mutex = (win_mutex_t*)_mutex;
CloseHandle(mutex->handle);
xfree(mutex);
}
static mem_mapping_t *getmm(uaecptr *addrp)
{
uaecptr addr = *addrp;
addr &= 0x7fffffff;
int index = addr / PCEMMAPBLOCKSIZE;
mem_mapping_t *m = pcemmap[index];
if (!m) {
write_log(_T("%08x no mapping\n"), addr);
}
return m;
}
void put_mem_pcem(uaecptr addr, uae_u32 v, int size)
{
#if 0
write_log("put_mem_pcem %08x %08x %d\n", addr, v, size);
#endif
mem_mapping_t *m = getmm(&addr);
if (m) {
if (size == 0) {
m->write_b(addr, v, m->p);
} else if (size == 1) {
m->write_w(addr, v, m->p);
} else if (size == 2) {
m->write_l(addr, v, m->p);
}
}
}
uae_u32 get_mem_pcem(uaecptr addr, int size)
{
uae_u32 v = 0;
mem_mapping_t *m = getmm(&addr);
if (m) {
if (size == 0) {
v = m->read_b(addr, m->p);
} else if (size == 1) {
v = m->read_w(addr, m->p);
} else if (size == 2) {
v = m->read_l(addr, m->p);
}
}
#if 0
write_log("get_mem_pcem %08x %08x %d\n", addr, v, size);
#endif
return v;
}
static void mapping_recalc(mem_mapping_t *mapping)
{
if (mapping->read_b == NULL)
mapping->read_b = dummy_bread;
if (mapping->read_w == NULL)
mapping->read_w = dummy_wread;
if (mapping->read_l == NULL)
mapping->read_l = dummy_lread;
if (mapping->write_b == NULL)
mapping->write_b = dummy_bwrite;
if (mapping->write_w == NULL)
mapping->write_w = dummy_wwrite;
if (mapping->write_l == NULL)
mapping->write_l = dummy_lwrite;
if (mapping == pcem_mapping_linear || (!pcem_mapping_linear && mapping->size >= 1024 * 1024)) {
pcem_mapping_linear = mapping;
pcem_mapping_linear_priv = mapping->p;
pcem_mapping_linear_offset = mapping->base;
if (!mapping->enable) {
pcem_linear_read_b = dummy_bread;
pcem_linear_read_w = dummy_wread;
pcem_linear_read_l = dummy_lread;
pcem_linear_write_b = dummy_bwrite;
pcem_linear_write_w = dummy_wwrite;
pcem_linear_write_l = dummy_lwrite;
} else {
pcem_linear_read_b = mapping->read_b;
pcem_linear_read_w = mapping->read_w;
pcem_linear_read_l = mapping->read_l;
pcem_linear_write_b = mapping->write_b;
pcem_linear_write_w = mapping->write_w;
pcem_linear_write_l = mapping->write_l;
}
}
for (uae_u32 i = 0; i < mapping->size; i += PCEMMAPBLOCKSIZE) {
uae_u32 addr = i + mapping->base;
addr &= 0x7fffffff;
int offset = addr / PCEMMAPBLOCKSIZE;
if (offset >= 0 && offset < MAX_PCEMMAPBLOCKS) {
if (mapping->enable) {
pcemmap[offset] = mapping;
} else {
pcemmap[offset] = NULL;
}
}
}
}
void mem_mapping_addx(mem_mapping_t *mapping,
uint32_t base,
uint32_t size,
uint8_t(*read_b)(uint32_t addr, void *p),
uint16_t(*read_w)(uint32_t addr, void *p),
uint32_t(*read_l)(uint32_t addr, void *p),
void (*write_b)(uint32_t addr, uint8_t val, void *p),
void (*write_w)(uint32_t addr, uint16_t val, void *p),
void (*write_l)(uint32_t addr, uint32_t val, void *p),
uint8_t *exec,
uint32_t flags,
void *p)
{
mapping->enable = 0;
for (int i = 0; i < MAX_PCEMMAPPINGS; i++) {
if (pcemmappings[i] == mapping)
return;
}
for (int i = 0; i < MAX_PCEMMAPPINGS; i++) {
if (pcemmappings[i] == NULL) {
pcemmappings[i] = mapping;
mapping->base = base;
mapping->size = size;
mapping->read_b = read_b;
mapping->read_w = read_w;
mapping->read_l = read_l;
mapping->write_b = write_b;
mapping->write_w = write_w;
mapping->write_l = write_l;
mapping->exec = exec;
mapping->flags = flags;
mapping->p = p;
mapping->next = NULL;
mapping_recalc(mapping);
return;
}
}
}
void mem_mapping_set_handlerx(mem_mapping_t *mapping,
uint8_t(*read_b)(uint32_t addr, void *p),
uint16_t(*read_w)(uint32_t addr, void *p),
uint32_t(*read_l)(uint32_t addr, void *p),
void (*write_b)(uint32_t addr, uint8_t val, void *p),
void (*write_w)(uint32_t addr, uint16_t val, void *p),
void (*write_l)(uint32_t addr, uint32_t val, void *p))
{
mapping->read_b = read_b;
mapping->read_w = read_w;
mapping->read_l = read_l;
mapping->write_b = write_b;
mapping->write_w = write_w;
mapping->write_l = write_l;
mapping_recalc(mapping);
}
void mem_mapping_set_px(mem_mapping_t *mapping, void *p)
{
mapping->p = p;
}
void pci_add_specific(int card, uint8_t(*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv)
{
}
void mca_add(uint8_t(*read)(int addr, void *priv), void (*write)(int addr, uint8_t val, void *priv), void (*reset)(void *priv), void *priv)
{
}
#define MAX_IO_PORT 0x10000
static uint8_t(*port_inb[MAX_IO_PORT])(uint16_t addr, void *priv);
static uint16_t(*port_inw[MAX_IO_PORT])(uint16_t addr, void *priv);
static uint32_t(*port_inl[MAX_IO_PORT])(uint16_t addr, void *priv);
static void(*port_outb[MAX_IO_PORT])(uint16_t addr, uint8_t val, void *priv);
static void(*port_outw[MAX_IO_PORT])(uint16_t addr, uint16_t val, void *priv);
static void(*port_outl[MAX_IO_PORT])(uint16_t addr, uint32_t val, void *priv);
static void *port_priv[MAX_IO_PORT];
void put_io_pcem(uaecptr addr, uae_u32 v, int size)
{
#if 0
write_log(_T("put_io_pcem(%08x,%08x,%d)\n"), addr, v, size);
#endif
addr &= MAX_IO_PORT - 1;
if (size == 0) {
if (port_outb[addr])
port_outb[addr](addr, v, port_priv[addr]);
} else if (size == 1) {
if (port_outw[addr]) {
port_outw[addr](addr, v, port_priv[addr]);
} else {
put_io_pcem(addr + 0, v >> 0, 0);
put_io_pcem(addr + 1, v >> 8, 0);
}
} else if (size == 2) {
if (port_outl[addr]) {
port_outl[addr](addr, v, port_priv[addr]);
} else {
put_io_pcem(addr + 0, v >> 16, 1);
put_io_pcem(addr + 2, v >> 0, 1);
}
}
}
uae_u32 get_io_pcem(uaecptr addr, int size)
{
#if 0
write_log(_T("get_io_pcem(%08x,%d)\n"), addr, size);
#endif
uae_u32 v = 0;
addr &= MAX_IO_PORT - 1;
if (size == 0) {
if (port_inb[addr])
v = port_inb[addr](addr, port_priv[addr]);
} else if (size == 1) {