-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmega2.c
More file actions
1552 lines (1434 loc) · 33.7 KB
/
mega2.c
File metadata and controls
1552 lines (1434 loc) · 33.7 KB
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
/*
*mega2.c -- Apple ][ soft switches->UNIX emulation for Apple ][ Emulator
*
* Modified 4/20/1990 Randy Frank randy@tessa.iaf.uiowa.edu
*
* DOS 3.3 added and ProDOS emulation patched.
* Reshaped memory and added //e emulation.
* Emulated a bunch of new softswitches.
* Support for 80col card added.
* Support for s5 drives added.
* Ctrl-A hook enhanced.
*
* Known bugs:
* Paddles not emulated currently.
* Several switches emulated but ignored.
* The 16k ram card works but is not quite right...
*
*/
/*
APPLE2E COPYRIGHT (C) 1990, RANDY FRANK
RANDY FRANK ("AUTHOR") GRANTS TO THE PARTY HEREBY RECEIVING "APPLE2E"
FROM AN AUTHORIZED PROVIDER ("RECIPIENT") A NON-EXCLUSIVE, ROYALTY-FREE
LICENSE TO COPY, DISPLAY, DISTRIBUTE, AND PRODUCE DERIVATIVE WORKS OF
"APPLE2E", PROVIDED THAT THE ABOVE COPYRIGHT NOTICE APPEARS IN ALL
COPIES MADE OF "APPLE2E" AND BOTH THE COPYRIGHT NOTICE AND THIS LICENSE
APPEAR IN SUPPORTING DOCUMENTATION, AND THAT THE NAME OF AUTHOR NOT BE
USED IN ADVERTISING OR PUBLICITY PERTAINING TO "APPLE2E". THE AUTHOR
REQUESTS TO BE MADE AWARE OF ANY DERIVATIVE WORKS.
"APPLE2E" IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
AUTHOR DOES NOT AND CANNOT WARRANT THE PERFORMANCE OF "APPLE2E" OR THE
RESULTS THAT MAY BE OBTAINED BY ITS USE OR ITS FITNESS FOR ANY SPECIFIC
USE BY RECIPIENT OR ANY THIRD PARTY. IN NO EVENT SHALL AUTHOR BECOME
LIABLE TO RECIPIENT OR ANY OTHER PARTY, FOR ANY LOSS OR DAMAGES,
CONSEQUENTIAL OR OTHERWISE, INCLUDING BUT NOT LIMITED TO TIME, MONEY,
OR GOODWILL, ARISING FROM USE OR POSSESSION, AUTHORIZED OR NOT, OF
"APPLE2E" BY RECIPIENT OR ANY OTHER PARTY.
*/
#include "apple.h"
#include <curses.h>
#include <execinfo.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <time.h>
#ifdef NOBEEP
#define beep() {}
#endif
/*
* Emulation globals:
*/
BYTE AMemory[65536]; /* Aux memory */
BYTE MMemory[65536]; /* Main memory */
BYTE Rom[16384]; /* 16K ROM bank of Main memory c0000-ffff */
BYTE RamRead = 0; /* set if 16K RAM readable */
BYTE RamWrite = 0; /* set if 16K RAM writeable */
BYTE Bank2Enable = 0; /* set if bank 2 Ram enabled */
BYTE MegaRand = 0; /* Always contains 8-bit random number */
BYTE MegaLastKey = 0; /* $C00X keyboard latch value */
BYTE MegaQuitDetect = 0; /* Set if user requests to quit */
BYTE MegaSerial = 0; /* Set if input from serial */
BYTE MegaSerialOut = 0; /* Set if output to serial */
int BeepNoise = 1;
/* variables for //e emulation */
int slotcxROM;
int slotc3ROM;
int RAMRD;
int RAMWRT;
int STORE80;
int PAGE2;
int HIRES;
int ALTZP;
int DHGR;
int ALTCHAR;
int TEXT;
int MIXED;
int BUTTON0;
int BUTTON1;
int VID80;
int PDL0; /* counters for the paddles */
int PDL1;
float paddle0;
float paddle1;
/*
Switches emulated for //e operation...
write c000 STORE80 off
write c001 STORE80 on
write c002 RAMRD off
write c003 RAMRD on
write c004 RAMWRT off
write c005 RAMWRT on
write c006 slotcxROM off = 0
write c007 slotcxROM on internalrom c100-cfff
write c008 ALTZP off
write c009 ALTZP on
write c00a slotc3ROM off internalC3rom
write c00b slotc3ROM on
write c00c for VID80 off
write c00d for VID80 on
write c00e for ALTCHAR off
write c00f for ALTCHAR on
c010 clear keyboard strobe
c011 and c012 are 16k ram card status
read c013 for RAMRD status
read c014 for RAMWRT status
read c015 slotcxrom status
read c016 for ALTZP status
read c017 slotc3rom status
read c018 for STORE80 status
c019 is the VBL switch (use random numbers)
read c01a for TEXT status
read c01b for MIXED status
read c01c for PAGE2 status
read c01d for HIRES status
read c01e for ALTCHAR status
read c01f for VID80 status
R/W c050 for TEXT off (graphics on)
R/W c051 for TEXT on
R/W c052 for MIXED off (only text or only graphics)
R/W c053 for MIXED on
R/W c054 for PAGE2 off
R/W c055 for PAGE2 on
R/W c056 for HIRES off
R/W c057 for HIRES on
R/W c05e for DHGR on
R/W c05f for DHGR off
read c061 for button0
read c062 for button1
read c07f for DHGR status
*/
void PutC000 ();
void PutC010 ();
void PutC05670 ();
void Put0400 ();
void PutC080 ();
void ChangeVID ();
BYTE GetC080 ();
BYTE GetC000 ();
BYTE GetC200 ();
BYTE GetC010 ();
BYTE GetC030 ();
BYTE GetC05670 ();
void ProInit ();
void ProFormat ();
void ProRead ();
void ProWrite ();
void ProStatus ();
void Dos33init ();
char *ip="127.0.0.1";
/*
* Base address table for 24 lines of text/lores page 1 ($400..$7F8);
* 40 bytes for each line. Note that screen "holes" exist:
*/
int LBasCalc[24] = {
1024,
1152,
1280,
1408,
1536,
1664,
1792,
1920,
1064,
1192,
1320,
1448,
1576,
1704,
1832,
1960,
1104,
1232,
1360,
1488,
1616,
1744,
1872,
2000
};
#define MegaPutChar(c) addch(c)
void
Rsoftswitches ()
{
slotcxROM = 0; /* should be 0 */
slotc3ROM = 0; /* essentially ignored as there is no slot3 card */
RAMRD = 0;
RAMWRT = 0;
STORE80 = 0;
PAGE2 = 0;
HIRES = 0;
ALTZP = 0;
DHGR = 0;
ALTCHAR = 0;
TEXT = 1;
MIXED = 0;
BUTTON0 = 0;
BUTTON1 = 0;
VID80 = 0;
/* record any changes in the state table */
(void) setupstates ();
}
/**************************************************************************/
/* Dispatch routines: The MegaPutMem and MegaGetMem, below, have default */
/* behavior for I/O space. They may also contain calls to other routines */
/* in this file which handle Apple II behavior. If these latter routines */
/* need initialization/shutdown, that code should be placed in the two */
/* MegaStartUp and MegaShutDown routines, below. */
/**************************************************************************/
#ifdef NEVER
void
MegaPutChar (c)
char c; /* This makes a function out of the "putchar" macro */
{
addch (c);
}
#endif
/* This routine is called at emulation startup time. All initialization
stuff, like setting terminal modes, opening files, etc. goes here. */
void
MegaStartUp ()
{
register int i; /* Iterator */
/* init the pseudo disk */
/* ProInit();*/
/* Dos33init();*/
speedinit ();
/* Set input modes on terminal: */
noecho ();
raw ();
/* Fill 40-column screen with simulated initial memory pattern: */
clear ();
/*
for (i = 0; i <= 23; i++)
mvaddstr (i, 0, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
refresh();
/*
/* Initialize some variables: */
MegaQuitDetect = 0;
MegaLastKey = 0;
MegaRand = 0;
MegaSerial = 0;
}
/* This routine is called at emulation shutdown time. All things
started in MegaStartUp, above, should be cleaned up here. */
void
MegaShutDown ()
{
/* Clear screen: */
clear ();
refresh ();
/* Reset sane modes on terminal: */
echo ();
noraw ();
endwin ();
fprintf(log,"%d: Stop %s\n",time(NULL),rcsid);
fflush(log);
}
/* This routine handles ALL stores to the 64K address space, in order to
faciliate special Apple ][ - specific effects. Not all behaviors may
be implemented; to install a new one, install the call in this routine.
Returns: Nothing. */
void
MegaPutMem (addr, byte)
register ADDR addr;
register BYTE byte;
{
register int rbank; /* temp var */
/* Make sure these are in range: */
addr &= 0xffff;
byte &= 0xff;
/* Do random number generation: */
MegaRand = (MegaRand + addr + byte) & 0xff;
/* where and how */
switch (modetable[area[addr >> 8]][writestate])
{
case 0:
MMemory[addr] = byte;
rbank = 0;
if (area[addr >> 8] == 2)
Put0400 (addr, byte, rbank);
return;
break;
case 1:
AMemory[addr] = byte;
rbank = 1;
if (area[addr >> 8] == 2)
Put0400 (addr, byte, rbank);
return;
break;
case 2:
MMemory[addr - (0x1000 * Bank2Enable)] = byte;
return;
break;
case 3:
AMemory[addr - (0x1000 * Bank2Enable)] = byte;
return;
break;
case 4:
/* writing to ROM so NOP */
return;
break;
case 5:
/* handle c000 - cffff */
if ((addr >= 0xc010) && (addr <= 0xc01f)) /* soft switches */
PutC010 (addr, byte);
else if ((addr >= 0xc000) && (addr <= 0xc00f)) /* soft switches */
PutC000 (addr, byte);
else if ((addr >= 0xc050) && (addr <= 0xc07f))
PutC05670 (addr, byte);
else if (addr >= 0xc080 && addr < 0xc090)
PutC080 (addr, byte);
/* record any changes in the state table */
(void) setupstates ();
return;
break;
}
}
/* This routine handles ALL fetches from the 64K address space, in order to
facilitate special Apple ][ - specific effects. Not all behaviors may
be implemented; to install a new one, install the call in this routine.
Returns: Value at location (could be random if I/O, etc.). */
BYTE
MegaGetMem (addr)
register ADDR addr;
{
register BYTE data; /* Data from memory space to be returned */
register int rbank; /* temp var */
/* Make sure we're in range: */
addr &= 0xffff;
/* where and how */
switch (modetable[area[addr >> 8]][readstate])
{
case 0:
return (MMemory[addr]);
break;
case 1:
return (AMemory[addr]);
break;
case 2:
return (MMemory[addr - (0x1000 * Bank2Enable)]);
break;
case 3:
return (AMemory[addr - (0x1000 * Bank2Enable)]);
break;
case 4:
return (Rom[addr - 0xc000]);
break;
case 5:
/* handle c000 - cffff */
if ((addr >= 0xc800) && (addr <= 0xcfff)) /* rom read c800-cfff */
return (Rom[addr - 0xc000]);
else if ((addr >= 0xc100) && (addr <= 0xc7ff) && (slotcxROM == 1))
return (Rom[addr - 0xc000]);
else if ((addr >= 0xc300) && (addr <= 0xc3ff)) /* && (slotc3ROM == 0) */
return (Rom[addr - 0xc000]);
/* We must be in C0x0 space. Default to random value: */
data = MegaRand & 0xff;
MegaRand = (MegaRand + addr * 25 + data) & 0xff;
/* Now do the appropriate memory-mapped INPUT functions, if any: */
if ((addr >= 0xc000) && (addr <= 0xc00f))
data = GetC000 (addr);
else if ((addr >= 0xc010) && (addr <= 0xc01f))
data = GetC010 (addr);
else if ((addr >= 0xc030) && (addr <= 0xc03f))
data = GetC030 (addr);
else if ((addr >= 0xc050) && (addr <= 0xc07f))
data = GetC05670 (addr);
else if ((addr >= 0xc080) && (addr <= 0xc08f))
data = GetC080 (addr);
/*
else if ((addr == 0xc0fd) && (dosver == 2)) {
(void) doclock();
data = 0x60;
}
else if (addr == 0xc0fe) {
(void) dounix();
data = 0x60;
}
else if (addr == 0xc701)
data = 0x20;
else if (addr == 0xc703)
data = 0x00;
else if (addr == 0xc705)
data = 0x03;
else if (addr == 0xc707)
data = 0x3c;
else if (addr == 0xc7ff)
data = 0x80;
else if (addr == 0xc7fe)
data = 0xdf;
else if (addr == 0xc7fc)
data = 0x00;
else if (addr == 0xc7fd)
data = 0x00;
else if (addr == 0xc780)
data = 0x60;
else if (addr == 0xc501)
data = 0x20;
else if (addr == 0xc503)
data = 0x00;
else if (addr == 0xc505)
data = 0x03;
else if (addr == 0xc507)
data = 0x3c;
else if (addr == 0xc5ff)
data = 0x80;
else if (addr == 0xc5fe)
data = 0xdf;
else if (addr == 0xc5fc)
data = 0x00;
else if (addr == 0xc5fd)
data = 0x00;
else if (addr == 0xc580)
data = 0x60;
*/
/* note: make s6 look like a card so PR#6 works under pdos */
else if ((addr >= 0xc600) && (addr <= 0xc6ff))
data = 0x60;
else if ((addr >= 0xc200) && (addr <= 0xc2ff))
data = GetC200 (addr);
else if (addr == 0xc0a8)
data = GetC200 (addr);
/* record any changes in the state table */
(void) setupstates ();
/* Return the data we came up with to the user: */
return (BYTE) (data & 0xff);
break;
}
}
/**************************************************************************/
/* Memory-Mapped I/O routines: These routines actually perform the spe- */
/* cific UNIX operations for get/put to certain addresses. Not all Get */
/* or Put routines must necessarily have a companion Put or Get routine: */
/* */
/* * GetXXXXXX: Return a byte of data from an I/O address */
/* * PutXXXXXX: Receive a byte of data for an I/O address */
/* */
/**************************************************************************/
int CAcount;
int sockfd;
struct sockaddr_in server_addr;
int port = 1977;
BYTE
GetC200 (addr)
ADDR addr;
{
struct sockaddr_in client_addr;
char buffer[1024];
socklen_t addr_size;
int n;
bzero (buffer, 1024);
addr_size = sizeof (client_addr);
n =
recvfrom (sockfd, buffer, 1024, MSG_DONTWAIT,
(struct sockaddr *) &client_addr, &addr_size);
/* fprintf (stderr, "[+]Data recv: %d %s\n\r", n, buffer); */
if (n>1) {
fprintf(log,"recv to big\n");
fflush(log);
}
if (buffer[0])
{
fprintf (stderr, "%x\n", buffer[0]);
return (BYTE) (buffer[0] & 128);
}
else
return (BYTE) (MegaRand & 0xff);
}
/* Get keyboard data in low 7 bits. Msb indicates if hit since last C010: */
BYTE
GetC000 (addr)
ADDR addr;
{
register int fflags;
char data = '*';
struct sockaddr_in client_addr;
char buffer[1024];
socklen_t addr_size;
int n;
switch (addr & 0x000F)
{
case 0x00:
/* Set nonblocking input: */
fflags = fcntl (0, F_GETFL, 0);
(void) fcntl (0, F_SETFL, fflags | O_NDELAY);
/* See if a key was pressed. If yes, update and set hi bit; */
/* else, leave keyboard latch with last value: */
if (read (0, &data, 1) > 0)
MegaLastKey = (int) data | 0x80;
/* Reset nonblocking input: */
(void) fcntl (0, F_SETFL, fflags);
if (MegaLastKey >= 0x80)
{
if ((CAcount == 0) && (data == MEGAQUITKEY)) /* a first ctrl-A */
{
MegaLastKey = (int) data;
CAcount = 1;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == MEGAQUITKEY)) /* two ctrl-As */
{
CAcount = 0;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == 0x30))
{
BUTTON0 = 1 - BUTTON0;
CAcount = 0;
MegaLastKey = (int) data;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == 0x31))
{
BUTTON1 = 1 - BUTTON1;
CAcount = 0;
MegaLastKey = (int) data;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == 0x62))
{
CAcount = 0;
void *callstack[128];
int i, frames = backtrace (callstack, 128);
char **strs = backtrace_symbols (callstack, frames);
for (i = 0; i < frames; ++i)
{
fprintf (log,"%s\n\r", strs[i]);
}
free (strs);
fflush(log);
MegaLastKey = (int) data;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == 0x63))
{
MegaSerial = 1 - MegaSerial;
if (MegaSerial)
{
int n;
sockfd = socket (AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
{
perror ("[-]socket error");
exit (1);
}
memset (&server_addr, '\0', sizeof (server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons (port);
server_addr.sin_addr.s_addr = inet_addr (ip);
n =
bind (sockfd, (struct sockaddr *) &server_addr,
sizeof (server_addr));
if (n < 0)
{
perror ("[-]bind error");
exit (1);
}
fprintf (log, "Bound to sock %d\n",sockfd);
fflush(log);
}
else
{
#ifdef DEBUG
fprintf (stderr, "Unbound\n\r");
#endif
}
CAcount = 0;
MegaLastKey = (int) data;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == 0x64))
{
CAcount = 0;
DebugSingle = 1;
MegaLastKey = (int) data;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == 0x65))
{
CAcount = 0;
MegaSerialOut = 1 - MegaSerialOut;
if (MegaSerialOut)
{
sockfd = socket (AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
{
perror ("[-]socket error");
exit (1);
}
fprintf(log,"open socket %d\n",sockfd);
fflush(log);
}
MegaLastKey = (int) data;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == 0x71))
{
CAcount = 0;
MegaQuitDetect = 1;
MegaLastKey = (int) data;
return (BYTE) MegaLastKey;
}
if ((CAcount == 1) && (data == 0x73))
{
CAcount = 0;
MegaLastKey = (int) 0x93; /* ctrl-a s -> crtl-s */
return (BYTE) MegaLastKey;
}
CAcount = 0;
}
return (BYTE) MegaLastKey;
break;
case 0x8: /* serial */
bzero (buffer, 1024);
addr_size = sizeof (client_addr);
n =
recvfrom (sockfd, buffer, 1024, MSG_DONTWAIT,
(struct sockaddr *) &client_addr, &addr_size);
#ifdef DEBUG
if (n != -1)
fprintf (stderr, "[+]Data recv: %d %s\n\r", n, buffer);
#endif
if (n>1) {
fprintf(log,"recvfrom too big\n");
fflush(log);
}
if (buffer[0])
{
MegaLastKey = buffer[0] | 128;
#ifdef DEBUG
fprintf (stderr, "%x\n", buffer[0]);
#endif
return (BYTE) MegaLastKey;
}
else
return (BYTE) (MegaRand & 0xff);
break;
}
return (BYTE) (MegaRand & 0xff);
}
/* Clear keyboard strobe for C000 msb: */
BYTE
GetC010 (addr)
ADDR addr;
{
switch (addr & 0x001F)
{
case 0x10:
/* keyboard strobe */
MegaLastKey &= 0x7f; /* Clear strobe bit */
return (BYTE) (MegaRand & 0xff);
break;
case 0x11:
/* which bank enabled */
return (BYTE) (0xFF * Bank2Enable);
break;
case 0x12:
/* 16k write enabled? */
return (BYTE) (0xFF * RamRead);
break;
case 0x13:
return (BYTE) (0xFF * RAMRD);
break;
case 0x14:
return (BYTE) (0xFF * RAMWRT);
break;
case 0x15:
/* Cxrom */
return (BYTE) (0xFF * slotcxROM);
break;
case 0x16:
return (BYTE) (0xFF * ALTZP);
break;
case 0x17:
/* C3rom */
return (BYTE) (0xFF * slotc3ROM);
break;
case 0x18:
return (BYTE) (0xFF * STORE80);
break;
/* c019 is the VBL line and a random num does just fine */
case 0x1a:
/* text */
return (BYTE) (0xFF * TEXT);
break;
case 0x1b:
/* mixed */
return (BYTE) (0xFF * MIXED);
break;
case 0x1c:
/* page2 */
return (BYTE) (0xFF * PAGE2);
break;
case 0x1d:
/* hires */
return (BYTE) (0xFF * HIRES);
break;
case 0x1e:
return (BYTE) (0xFF * ALTCHAR);
break;
case 0x1f:
/* vid80 */
return (BYTE) (0xFF * VID80);
break;
}
return (BYTE) (MegaRand & 0xff);
}
BYTE
GetC080 (addr)
ADDR addr;
{
switch (addr & 0x000F)
{
case 0x00:
RamRead = 1;
RamWrite = 0;
Bank2Enable = 1;
break;
case 0x01:
RamRead = 0;
RamWrite = 1;
Bank2Enable = 1;
break;
case 0x02:
RamRead = 0;
RamWrite = 0;
Bank2Enable = 1;
break;
case 0x03:
RamRead = 1;
RamWrite = 1;
Bank2Enable = 1;
break;
case 0x08:
RamRead = 1;
RamWrite = 0;
Bank2Enable = 0;
break;
case 0x09:
RamRead = 0;
RamWrite = 1;
Bank2Enable = 0;
break;
case 0x0a:
RamRead = 0;
RamWrite = 0;
Bank2Enable = 0;
break;
case 0x0b:
RamRead = 1;
RamWrite = 1;
Bank2Enable = 0;
break;
}
return (BYTE) (MegaRand & 0xff);
}
/*ARGSUSED*/ void
PutC010 (addr, data)
ADDR addr;
BYTE data;
{
(void) GetC010 (addr); /* Same thing; either one works */
}
void
PutC05670 (addr, data)
ADDR addr;
BYTE data;
{
(void) GetC05670 (addr); /* for c050 - c07f */
/* for these switches writes do nothing or flip the switch like the read
so this wrapper is appropriate here */
}
BYTE
GetC05670 (addr)
ADDR addr;
{
switch (addr & 0x007F)
{
case 0x50:
TEXT = 0;
break;
case 0x51:
TEXT = 1;
break;
case 0x52:
MIXED = 0;
break;
case 0x53:
MIXED = 1;
break;
case 0x54:
PAGE2 = 0;
break;
case 0x55:
PAGE2 = 1;
break;
case 0x56:
HIRES = 0;
break;
case 0x57:
HIRES = 1;
break;
case 0x5e:
DHGR = 1;
break;
case 0x5f:
DHGR = 0;
break;
case 0x61:
return (BYTE) (0xFF * BUTTON0);
break;
case 0x62:
return (BYTE) (0xFF * BUTTON1);
break;
case 0x64:
if (PDL0 > 0)
{
return (BYTE) (0xff);
}
else
{
return (BYTE) (0x00);
};
break;
case 0x65:
if (PDL1 > 0)
{
return (BYTE) (0xff);
}
else
{
return (BYTE) (0x00);
};
break;
case 0x70:
PDL0 = paddle0 * 2830;
PDL1 = paddle1 * 2830;
break;
case 0x7f:
return (BYTE) (0xFF * DHGR);
break;
}
return (BYTE) (MegaRand & 0xff);
}
void
PutC000 (addr, data)
ADDR addr;
BYTE data;
{
switch (addr & 0x007F)
{
case 0x00:
STORE80 = 0;
break;
case 0x01:
STORE80 = 1;
break;
case 0x02:
RAMRD = 0;
break;
case 0x03:
RAMRD = 1;
break;
case 0x04:
RAMWRT = 0;
break;
case 0x05:
RAMWRT = 1;
break;
case 0x06:
slotcxROM = 0;
break;
case 0x07:
slotcxROM = 1;
break;
case 0x08:
ALTZP = 0;
break;
case 0x09:
ALTZP = 1;
break;
case 0x0a:
slotc3ROM = 0;
break;
case 0x0b:
slotc3ROM = 1;
break;
case 0x0c:
if (VID80 == 0)
break; /* don't bother if it does nothing */
VID80 = 0;
ChangeVID ();
break;
case 0x0d:
if (VID80 == 1)
break; /* don't bother if it does nothing */
VID80 = 1;
ChangeVID ();
break;
case 0x0e:
ALTCHAR = 0;
break;
case 0x0f:
ALTCHAR = 1;
break;
}
}
void
PutC080 (addr, data)
ADDR addr;
BYTE data;
{
(void) GetC080 (addr); /* Same thing; either one works */
}
/* Beeps speaker if accessed a lot: */
BYTE
GetC030 (addr)
ADDR addr;
{
static int count = 0;
/* note std beep hits c030 0xc0 times */
if (count++ >= 190)
{
count = 0;
if (BeepNoise)
beep ();
}
return (BYTE) (MegaRand & 0xff);
}
void
ChangeVID ()