/
apple2e.cpp
5906 lines (5037 loc) · 214 KB
/
apple2e.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
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/***************************************************************************
apple2e.cpp - Apple IIe/IIc/IIc Plus and clones
Next generation driver written in September/October 2014 by R. Belmont.
Thanks to the original Apple II series driver's authors: Mike Balfour, Nathan Woods, and R. Belmont.
Special thanks to the Apple II Documentation Project/Antoine Vignau and Peter Ferrie.
IIe: base of this driver. 64K RAM, slot 0 language card emulation without the double-read requirement,
lowercase and SHIFT key on button 2, Open and Solid Apple buttons on joy buttons 0 and 1,
auxiliary slot, built-in 80 column support if extra RAM added.
Physical slot 0 was eliminated thanks to the built-in language card.
Most of the write-only softswitches gained readback locations, necessary to make interrupt-driven
software possible.
Base 80-column card: 1K RAM, allows 80 columns and double-lo-res,
no double-hi-res.
Extended 80-column card: 64K RAM (including a second language card),
allows 80 columns, double-lo-res, and double-hi-res.
Revision A motherboards (very rare) don't support double-hi-res; it's unclear
if double-lo-res works or not. We emulate the much more common Rev B or later
board.
IIe enhanced: 65C02 CPU with more instructions, MouseText in the character generator.
IIe platinum: Like enhanced but with added numeric keypad and extended 80-column card
included in the box. Keypad CLEAR generates ESC by default, one hardware mod
made it generate CTRL-X instead. (new keyboard encoder ROM?)
NOTE: On real IIe and IIe enhanced h/w, pressing SHIFT and paddle button 2 will
short out the power supply and cause a safety shutdown. (We don't emulate
this "feature", and it was relatively rare in real life as Apple joysticks only
had buttons 0 and 1 normally).
IIc: IIe enhanced shrunken into a pizzabox with a Disk II compatible
half-height drive included in the case.
No slots, but included functionality equivalent to the following slots
on the motherboard:
- 2 Super Serial Cards (modem and printer ports)
- extended 80 column card / 128K RAM
- Disk II IWM controller
- Apple II Mouse card (firmware entry points are compatible,
but the hardware implementation omits the 68705 and is quite different!)
Has a 40/80 column switch and a QWERTY/DVORAK switch.
IIc (UniDisk 3.5): IIc with ROM doubled to 32K and the ROMSWITCH register
added to page between the original 16K ROM and the new added 16K. The
extra firmware space was dedicated to implementing the Protocol Converter,
later renamed "SmartPort", which communicates with "smart" packet devices
over the IWM bus.
Partial AppleTalk code also exists in this ROM but it doesn't work and
was not completed.
IIc (Original Memory Expansion):
Removes AppleTalk and adds support for a memory expansion card with up
to 1 MB; this is identical both in hardware and firmware to the "Slinky"
memory expansion card for the Apple IIe (a2bus/a2memexp.c).
IIc (Revised Memory Expansion, Rev. 3):
Fixes several nasty bugs in the Original Memory Expansion version. Not
currently dumped.
IIc (Rev 4):
Fixes memory size detection for memory cards with less than 1MB. Fixes
several screen hole errors introduced in Rev 3, and fixes Terminal Mode
wherein the firmware can be put into a built-in terminal mode for simple
tests with a modem.
IIc Plus:
Like IIc with memory expansion, but with licensed built-in Zip Chip which
runs the 65C02 at 4 MHz turbo speed with a small cache RAM.
The machine has an internal "Apple 3.5" drive plus a custom chip
named "MIG" (Multidrive Interface Glue) which helps with the control
of the drive. This gets around the fact that 1 MHz isn't
sufficient to handle direct Woz-style control of a double-density
3.5" drive.
External drive port allows IIgs-style daisy-chaining.
----------------------------------
TK3000 keyboard matrix:
Data bus D0-D7 is X0-X7
Address bus A0-A11 is Y0-Y11
IIc Plus CGGA speed control:
Fast: Store $08 to $C05B (Zip compatible)
Normal: Store $08 to $C05A (Zip compatible)
Lock: Store $A5 to $C05A (Zip compatible).
Unlock: Store $5A 4 times in a row to $C05A (Zip compatible).
Read state: Cached by the firmware in MIG RAM (see below).
Write state: Store speaker/slot byte at $C05C (Zip compatible). Firmware always enables the paddle
delay at $C05F, regardless of what you pass in.
Previous versions of this driver stated that the IIc+ speaker/slot control byte was not Zip compatible; that
was a misunderstanding.
Accelerator control firmware saves/restores zero page locations 0-7 in MIG RAM page 2 locations $CE10-$CE17.
MIG RAM page 2 $CE02 is the speaker/slot bitfield and $CE03 is the paddle/accelerator bitfield.
***************************************************************************/
#include "emu.h"
#include "apple2video.h"
#include "apple2common.h"
#include "cpu/m6502/m6502.h"
#include "cpu/m6502/m65c02.h"
#include "cpu/mcs48/mcs48.h"
#include "cpu/z80/z80.h"
#include "imagedev/cassette.h"
#include "machine/applefdintf.h"
#include "machine/ds1315.h"
#include "machine/iwm.h"
#include "machine/kb3600.h"
#include "machine/mos6551.h"
#include "machine/ram.h"
#include "machine/timer.h"
#include "sound/spkrdev.h"
#include "bus/a2bus/cards.h"
#include "bus/a2bus/a2mockingboard.h"
#include "bus/a2bus/a2diskiing.h"
#include "bus/a2bus/a2iwm.h"
#include "bus/a2bus/laser128.h"
#include "bus/a2bus/ace2x00.h"
#include "bus/a2bus/a2eauxslot.h"
#include "bus/a2bus/a2eext80col.h"
#include "bus/a2bus/a2eramworks3.h"
#include "bus/a2bus/a2estd80col.h"
#include "bus/a2gameio/gameio.h"
#include "bus/centronics/ctronics.h"
#include "bus/rs232/rs232.h"
#include "screen.h"
#include "softlist_dev.h"
#include "speaker.h"
#include "utf8.h"
namespace {
#define A2_CPU_TAG "maincpu"
#define A2_KBDC_TAG "ay3600"
#define A2_BUS_TAG "a2bus"
#define A2_SPEAKER_TAG "speaker"
#define A2_CASSETTE_TAG "tape"
#define A2_UPPERBANK_TAG "inhbank"
#define IIC_ACIA1_TAG "acia1"
#define IIC_ACIA2_TAG "acia2"
#define LASER128_UDC_TAG "l128udc"
#define PRINTER_PORT_TAG "printer"
#define MODEM_PORT_TAG "modem"
#define A2_AUXSLOT_TAG "auxbus"
#define A2_VIDEO_TAG "a2video"
#define A2_0000_TAG "r00bank"
#define A2_0200_TAG "r02bank"
#define A2_0400_TAG "r04bank"
#define A2_0800_TAG "r08bank"
#define A2_2000_TAG "r20bank"
#define A2_4000_TAG "r40bank"
#define A2_C100_TAG "c1bank"
#define A2_C300_TAG "c3bank"
#define A2_C400_TAG "c4bank"
#define A2_C800_TAG "c8bank"
#define A2_LCBANK_TAG "lcbank"
#define MOUSE_BUTTON_TAG "mse_button"
#define MOUSE_XAXIS_TAG "mse_x"
#define MOUSE_YAXIS_TAG "mse_y"
#define CNXX_UNCLAIMED -1
#define CNXX_INTROM -2
static constexpr int IRQ_SLOT = 0;
static constexpr int IRQ_VBL = 1;
static constexpr int IRQ_MOUSEXY = 2;
class apple2e_state : public driver_device
{
public:
apple2e_state(const machine_config &mconfig, device_type type, const char *tag) :
driver_device(mconfig, type, tag),
m_maincpu(*this, A2_CPU_TAG),
m_screen(*this, "screen"),
m_scantimer(*this, "scantimer"),
m_acceltimer(*this, "acceltimer"),
m_ram(*this, RAM_TAG),
m_rom(*this, "maincpu"),
m_a2common(*this, "a2common"),
m_cecbanks(*this, "cecexp"),
m_ay3600(*this, A2_KBDC_TAG),
m_video(*this, A2_VIDEO_TAG),
m_a2bus(*this, A2_BUS_TAG),
m_a2eauxslot(*this, A2_AUXSLOT_TAG),
m_gameio(*this, "gameio"),
m_mouseb(*this, MOUSE_BUTTON_TAG),
m_mousex(*this, MOUSE_XAXIS_TAG),
m_mousey(*this, MOUSE_YAXIS_TAG),
m_kbdrom(*this, "keyboard"),
m_kbspecial(*this, "keyb_special"),
m_sysconfig(*this, "a2_config"),
m_franklin_fkeys(*this, "franklin_fkeys"),
m_speaker(*this, A2_SPEAKER_TAG),
m_cassette(*this, A2_CASSETTE_TAG),
m_upperbank(*this, A2_UPPERBANK_TAG),
m_0000bank(*this, A2_0000_TAG),
m_0200bank(*this, A2_0200_TAG),
m_0400bank(*this, A2_0400_TAG),
m_0800bank(*this, A2_0800_TAG),
m_2000bank(*this, A2_2000_TAG),
m_4000bank(*this, A2_4000_TAG),
m_c100bank(*this, A2_C100_TAG),
m_c300bank(*this, A2_C300_TAG),
m_c400bank(*this, A2_C400_TAG),
m_c800bank(*this, A2_C800_TAG),
m_lcbank(*this, A2_LCBANK_TAG),
m_acia1(*this, IIC_ACIA1_TAG),
m_acia2(*this, IIC_ACIA2_TAG),
m_iwm(*this, "fdc"),
m_floppy(*this, "fdc:%d", 0U),
m_ds1315(*this, "nsc"),
m_printer_conn(*this, "parallel"),
m_printer_out(*this, "laserprnout")
{
m_accel_laser = false;
m_has_laser_mouse = false;
m_isiic = false;
m_isiicplus = false;
m_iscec = false;
m_iscecm = false;
m_iscec2000 = false;
m_isace500 = false;
m_isace2200 = false;
m_ace2200_axxx_bank = false;
m_pal = false;
m_cur_floppy = nullptr;
m_devsel = 0;
m_laser_speed = 0;
m_laser_fdc_on = false;
}
required_device<cpu_device> m_maincpu;
required_device<screen_device> m_screen;
required_device<timer_device> m_scantimer, m_acceltimer;
required_device<ram_device> m_ram;
required_memory_region m_rom;
required_device<apple2_common_device> m_a2common;
optional_memory_region m_cecbanks;
required_device<ay3600_device> m_ay3600;
required_device<a2_video_device> m_video;
required_device<a2bus_device> m_a2bus;
optional_device<a2eauxslot_device> m_a2eauxslot;
required_device<apple2_gameio_device> m_gameio;
optional_ioport m_mouseb, m_mousex, m_mousey;
optional_memory_region m_kbdrom;
required_ioport m_kbspecial;
optional_ioport m_sysconfig;
optional_ioport m_franklin_fkeys;
required_device<speaker_sound_device> m_speaker;
optional_device<cassette_image_device> m_cassette;
memory_view m_upperbank, m_0000bank, m_0200bank, m_0400bank;
memory_view m_0800bank, m_2000bank, m_4000bank, m_c100bank;
memory_view m_c300bank, m_c400bank, m_c800bank, m_lcbank;
optional_device<mos6551_device> m_acia1, m_acia2;
optional_device<applefdintf_device> m_iwm;
optional_device_array<floppy_connector, 4> m_floppy;
required_device<ds1315_device> m_ds1315;
optional_device<centronics_device> m_printer_conn;
optional_device<output_latch_device> m_printer_out;
TIMER_DEVICE_CALLBACK_MEMBER(apple2_interrupt);
TIMER_DEVICE_CALLBACK_MEMBER(accel_timer);
TIMER_DEVICE_CALLBACK_MEMBER(ay3600_repeat);
virtual void machine_start() override;
virtual void machine_reset() override;
u8 ram0000_r(offs_t offset);
void ram0000_w(offs_t offset, u8 data);
u8 ram0200_r(offs_t offset);
void ram0200_w(offs_t offset, u8 data);
u8 ram0400_r(offs_t offset);
void ram0400_w(offs_t offset, u8 data);
u8 ram0800_r(offs_t offset);
void ram0800_w(offs_t offset, u8 data);
u8 ram2000_r(offs_t offset);
void ram2000_w(offs_t offset, u8 data);
u8 ram4000_r(offs_t offset);
u8 ram4000_ace2200_r(offs_t offset);
void ram4000_w(offs_t offset, u8 data);
u8 cec4000_r(offs_t offset);
u8 cec8000_r(offs_t offset);
void ram8000_w(offs_t offset, u8 data);
u8 auxram0000_r(offs_t offset);
void auxram0000_w(offs_t offset, u8 data);
u8 auxram0200_r(offs_t offset);
void auxram0200_w(offs_t offset, u8 data);
u8 auxram0400_r(offs_t offset);
void auxram0400_w(offs_t offset, u8 data);
u8 auxram0800_r(offs_t offset);
void auxram0800_w(offs_t offset, u8 data);
u8 auxram2000_r(offs_t offset);
void auxram2000_w(offs_t offset, u8 data);
u8 auxram4000_r(offs_t offset);
void auxram4000_w(offs_t offset, u8 data);
u8 c000_r(offs_t offset);
void c000_w(offs_t offset, u8 data);
u8 c000_laser_r(offs_t offset);
void c000_laser_w(offs_t offset, u8 data);
u8 laserprn_busy_r();
void laserprn_w(u8 data);
TIMER_CALLBACK_MEMBER(update_laserprn_strobe);
u8 c000_iic_r(offs_t offset);
void c000_iic_w(offs_t offset, u8 data);
u8 c080_r(offs_t offset);
void c080_w(offs_t offset, u8 data);
u8 c100_r(offs_t offset);
u8 c100_int_r(offs_t offset);
u8 c100_int_bank_r(offs_t offset);
u8 c100_cec_r(offs_t offset);
u8 c100_cec_bank_r(offs_t offset);
void c100_w(offs_t offset, u8 data);
u8 c300_r(offs_t offset);
u8 c300_int_r(offs_t offset);
u8 c300_int_bank_r(offs_t offset);
u8 c300_cec_r(offs_t offset);
u8 c300_cec_bank_r(offs_t offset);
void c300_w(offs_t offset, u8 data);
u8 c400_r(offs_t offset);
u8 c400_int_r(offs_t offset);
u8 c400_int_bank_r(offs_t offset);
u8 c400_cec_r(offs_t offset);
u8 c400_cec_bank_r(offs_t offset);
void c400_w(offs_t offset, u8 data);
void c400_cec_w(offs_t offset, u8 data);
u8 c800_r(offs_t offset);
u8 c800_int_r(offs_t offset);
u8 c800_cec_r(offs_t offset);
u8 c800_cec_bank_r(offs_t offset);
u8 c800_b2_int_r(offs_t offset);
void c800_w(offs_t offset, u8 data);
u8 inh_r(offs_t offset);
void inh_w(offs_t offset, u8 data);
u8 lc_r(offs_t offset);
void lc_w(offs_t offset, u8 data);
u8 lc_romswitch_r(offs_t offset);
void lc_romswitch_w(offs_t offset, u8 data);
u8 laser_mouse_r(offs_t offset);
void laser_mouse_w(offs_t offset, u8 data);
void a2bus_irq_w(int state);
void a2bus_nmi_w(int state);
void a2bus_inh_w(int state);
void busy_w(int state);
int ay3600_shift_r();
int ay3600_control_r();
void ay3600_data_ready_w(int state);
void ay3600_ako_w(int state);
u8 memexp_r(offs_t offset);
void memexp_w(offs_t offset, u8 data);
u8 nsc_backing_r(offs_t offset);
u8 ace500_c0bx_r(offs_t offset);
void ace500_c0bx_w(offs_t offset, u8 data);
void apple2cp(machine_config &config);
void spectred(machine_config &config);
void laser128(machine_config &config);
void laser128o(machine_config &config);
void laser128ex2(machine_config &config);
void ace500(machine_config &config);
void ace2200(machine_config &config);
void apple2c_iwm(machine_config &config);
void apple2c_mem(machine_config &config);
void cec(machine_config &config);
void mprof3(machine_config &config);
void apple2e(machine_config &config);
void apple2epal(machine_config &config);
void apple2ep(machine_config &config);
void apple2c(machine_config &config);
void tk3000(machine_config &config);
void apple2ee(machine_config &config);
void apple2eepal(machine_config &config);
void apple2c_map(address_map &map);
void apple2c_memexp_map(address_map &map);
void base_map(address_map &map);
void laser128_map(address_map &map);
void ace500_map(address_map &map);
void ace2200_map(address_map &map);
void spectred_keyb_map(address_map &map);
void init_laser128();
void init_128ex();
void init_pal();
void init_ace500();
void init_ace2200();
bool m_35sel, m_hdsel, m_intdrive;
private:
int m_speaker_state, m_cassette_state, m_cassette_out;
double m_joystick_x1_time, m_joystick_y1_time, m_joystick_x2_time, m_joystick_y2_time;
u32 m_franklin_last_fkeys;
u16 m_lastchar, m_strobe, m_franklin_strobe;
u8 m_transchar;
bool m_anykeydown;
int m_repeatdelay;
int m_inh_slot, m_cnxx_slot;
bool m_an0, m_an1, m_an2, m_an3;
bool m_vbl, m_vblmask;
bool m_xy, m_x0edge, m_y0edge;
bool m_x0, m_x1, m_y0, m_y1;
bool m_xirq, m_yirq;
int last_mx, last_my, count_x, count_y;
bool m_intcxrom;
bool m_slotc3rom;
bool m_altzp;
bool m_ramrd, m_ramwrt;
bool m_lcram, m_lcram2, m_lcprewrite, m_lcwriteenable;
bool m_ioudis;
bool m_romswitch;
bool m_mockingboard4c;
bool m_intc8rom;
bool m_reset_latch;
bool m_isiic, m_isiicplus, m_iscec, m_iscecm, m_iscec2000, m_pal;
u8 m_migram[0x800];
u16 m_migpage;
bool m_isace500, m_isace2200, m_ace_cnxx_bank, m_ace2200_axxx_bank;
u16 m_ace500rombank;
bool m_accel_unlocked;
bool m_accel_fast;
bool m_accel_present;
bool m_accel_temp_slowdown;
bool m_accel_laser;
bool m_has_laser_mouse;
bool m_laser_fdc_on;
int m_accel_stage;
u32 m_accel_speed;
u8 m_accel_slotspk, m_accel_gameio, m_laser_speed;
emu_timer *m_strobe_timer;
u8 m_next_strobe;
bool m_centronics_busy;
u8 *m_ram_ptr, *m_rom_ptr, *m_cec_ptr;
int m_ram_size;
int m_cec_bank;
u8 *m_aux_ptr, *m_aux_bank_ptr;
u16 m_aux_mask;
int m_inh_bank;
double m_x_calibration, m_y_calibration;
device_a2bus_card_interface *m_slotdevice[8];
device_a2eauxslot_card_interface *m_auxslotdevice;
int m_irqmask;
u8 m_exp_bankhior;
int m_exp_addrmask;
u8 m_exp_regs[0x10];
u8 *m_exp_ram;
int m_exp_wptr, m_exp_liveptr;
void do_io(int offset, bool is_iic);
u8 read_floatingbus();
void update_slotrom_banks();
void lc_update(int offset, bool writing);
u8 read_slot_rom(int slotbias, int offset);
void write_slot_rom(int slotbias, int offset, u8 data);
u8 read_int_rom(int slotbias, int offset);
void auxbank_update();
void lcrom_update();
void cec_lcrom_update();
void raise_irq(int irq);
void lower_irq(int irq);
void update_iic_mouse();
void accel_full_speed();
void accel_normal_speed();
void accel_slot(int slot);
void laser_calc_speed();
u8 m_cec_remap[0x40000];
u8 mig_r(u16 offset);
void mig_w(u16 offset, u8 data);
void phases_w(uint8_t phases);
void sel35_w(int sel35);
void devsel_w(uint8_t devsel);
void hdsel_w(int hdsel);
void recalc_active_device();
floppy_image_device *m_cur_floppy;
int m_devsel;
u8 laser_motor_r(offs_t offset)
{
m_laser_fdc_on = (offset == 1);
laser_calc_speed();
return m_iwm->read(offset + 8);
}
void laser_motor_w(offs_t offset, u8 data)
{
m_laser_fdc_on = (offset == 1);
laser_calc_speed();
m_iwm->write(offset + 8, data);
}
offs_t dasm_trampoline(std::ostream &stream, offs_t pc, const util::disasm_interface::data_buffer &opcodes, const util::disasm_interface::data_buffer ¶ms);
void apple2e_common(machine_config &config, bool enhanced, bool rgb_option);
};
offs_t apple2e_state::dasm_trampoline(std::ostream &stream, offs_t pc, const util::disasm_interface::data_buffer &opcodes, const util::disasm_interface::data_buffer ¶ms)
{
return m_a2common->dasm_override(stream, pc, opcodes, params);
}
u8 apple2e_state::mig_r(u16 offset)
{
//printf("mig_r @ %x\n", offset + 0xc00);
// MIG RAM window
if ((offset >= 0x200) && (offset < 0x220))
{
return m_migram[m_migpage + (offset & 0x1f)];
}
// increment MIG RAM window and return previous value
if ((offset >= 0x220) && (offset < 0x240))
{
u8 rv = m_migram[m_migpage + (offset & 0x1f)];
m_migpage += 0x20;
m_migpage &= 0x7ff;
return rv;
}
if ((offset >= 0x240) && (offset < 0x260))
{
m_hdsel = false;
if (m_cur_floppy)
{
m_cur_floppy->ss_w(0);
}
}
if ((offset >= 0x260) && (offset < 0x280))
{
m_hdsel = true;
if (m_cur_floppy)
{
m_cur_floppy->ss_w(1);
}
}
// reset MIG RAM window
if (offset == 0x2a0)
{
m_migpage = 0;
}
return read_floatingbus();
}
void apple2e_state::mig_w(u16 offset, u8 data)
{
//printf("mig_w %x @ %x\n", data, offset + 0xc00);
if (offset == 0x40)
{
m_iwm->reset();
return;
}
if ((offset >= 0x80) && (offset < 0xa0))
{
//printf("MIG: enable internal drive on d2\n");
m_intdrive = true;
recalc_active_device();
return;
}
if ((offset >= 0xc0) && (offset < 0xe0))
{
//printf("MIG: disable internal drive\n");
m_intdrive = false;
recalc_active_device();
return;
}
// MIG RAM window
if ((offset >= 0x200) && (offset < 0x220))
{
m_migram[m_migpage + (offset & 0x1f)] = data;
return;
}
// increment MIG RAM window, but write value at old location first
if ((offset >= 0x220) && (offset < 0x240))
{
m_migram[m_migpage + (offset & 0x1f)] = data;
m_migpage += 0x20;
m_migpage &= 0x7ff; // make sure we wrap
return;
}
if ((offset >= 0x240) && (offset < 0x260))
{
m_35sel = false;
recalc_active_device();
return;
}
if ((offset >= 0x260) && (offset < 0x280))
{
m_35sel = true;
recalc_active_device();
return;
}
// reset MIG RAM window
if (offset == 0x2a0)
{
m_migpage = 0;
}
}
void apple2e_state::phases_w(uint8_t phases)
{
if (m_cur_floppy)
{
m_cur_floppy->seek_phase_w(phases);
}
}
void apple2e_state::devsel_w(uint8_t devsel)
{
m_devsel = devsel;
recalc_active_device();
}
void apple2e_state::sel35_w(int sel35)
{
}
void apple2e_state::recalc_active_device()
{
if (m_devsel == 1)
{
if (!m_35sel)
{
m_cur_floppy = m_floppy[0]->get_device();
}
else
{
m_cur_floppy = m_floppy[3]->get_device();
}
}
else if (m_devsel == 2)
{
// as per http://apple2.guidero.us/doku.php/mg_notes/apple_iic/mig_chip intdrive + devsel = 2 enables
// the internal drive, no 35sel is necessary. If intdrive is clear, 35sel and devsel work as normal.
if (m_intdrive)
{
m_cur_floppy = m_floppy[2]->get_device();
}
else if (!m_35sel)
{
m_cur_floppy = m_floppy[1]->get_device();
}
else // should be external 3.5 #2, for a 3rd drive
{
m_cur_floppy = nullptr;
}
}
else
{
m_cur_floppy = nullptr;
}
m_iwm->set_floppy(m_cur_floppy);
if (m_cur_floppy)
{
m_cur_floppy->ss_w(m_hdsel ? 1 : 0);
}
}
void apple2e_state::a2bus_irq_w(int state)
{
if (state == ASSERT_LINE)
{
raise_irq(IRQ_SLOT);
}
else
{
lower_irq(IRQ_SLOT);
}
}
void apple2e_state::a2bus_nmi_w(int state)
{
m_maincpu->set_input_line(INPUT_LINE_NMI, state);
}
// TODO: this assumes /INH only on ROM, needs expansion to support e.g. phantom-slotting cards and etc.
void apple2e_state::a2bus_inh_w(int state)
{
if (state == ASSERT_LINE)
{
// assume no cards are pulling /INH
m_inh_slot = -1;
// scan the slots to figure out which card(s) are INHibiting stuff
for (int i = 0; i <= 7; i++)
{
if (m_slotdevice[i])
{
// this driver only can inhibit from 0xd000-0xffff
if ((m_slotdevice[i]->inh_start() == 0xd000) &&
(m_slotdevice[i]->inh_end() == 0xffff))
{
if ((m_slotdevice[i]->inh_type() & INH_READ) == INH_READ)
{
if (m_inh_bank != 1)
{
m_upperbank.select(1);
m_inh_bank = 1;
}
}
else
{
if (m_inh_bank != 0)
{
m_upperbank.select(0);
m_inh_bank = 0;
}
}
m_inh_slot = i;
break;
}
}
}
// if no slots are inhibiting, make sure ROM is fully switched in
if ((m_inh_slot == -1) && (m_inh_bank != 0))
{
m_upperbank.select(0);
m_inh_bank = 0;
}
}
}
void apple2e_state::busy_w(int state)
{
m_centronics_busy = state;
}
u8 apple2e_state::memexp_r(offs_t offset)
{
u8 retval = m_exp_regs[offset];
if (!m_exp_ram)
{
return read_floatingbus();
}
if (offset == 3)
{
if (m_exp_liveptr <= m_exp_addrmask)
{
retval = m_exp_ram[m_exp_liveptr];
}
else
{
retval = 0xff;
}
m_exp_liveptr++;
m_exp_regs[0] = m_exp_liveptr & 0xff;
m_exp_regs[1] = (m_exp_liveptr>>8) & 0xff;
m_exp_regs[2] = ((m_exp_liveptr>>16) & 0xff) | m_exp_bankhior;
}
return retval;
}
void apple2e_state::memexp_w(offs_t offset, u8 data)
{
if (!m_exp_ram)
{
return;
}
switch (offset & 0xf)
{
case 0:
m_exp_wptr &= ~0xff;
m_exp_wptr |= data;
m_exp_regs[0] = m_exp_wptr & 0xff;
m_exp_regs[1] = (m_exp_wptr>>8) & 0xff;
m_exp_regs[2] = ((m_exp_wptr>>16) & 0xff) | m_exp_bankhior;
m_exp_liveptr = m_exp_wptr;
break;
case 1:
m_exp_wptr &= ~0xff00;
m_exp_wptr |= (data<<8);
m_exp_regs[0] = m_exp_wptr & 0xff;
m_exp_regs[1] = (m_exp_wptr>>8) & 0xff;
m_exp_regs[2] = ((m_exp_wptr>>16) & 0xff) | m_exp_bankhior;
m_exp_liveptr = m_exp_wptr;
break;
case 2:
m_exp_wptr &= ~0xff0000;
m_exp_wptr |= (data<<16);
m_exp_regs[0] = m_exp_wptr & 0xff;
m_exp_regs[1] = (m_exp_wptr>>8) & 0xff;
m_exp_regs[2] = ((m_exp_wptr>>16) & 0xff) | m_exp_bankhior;
m_exp_liveptr = m_exp_wptr;
break;
case 3:
// printf("Write %02x to RAM[%x]\n", data, m_liveptr);
if (m_exp_liveptr <= m_exp_addrmask)
{
m_exp_ram[m_exp_liveptr] = data;
}
m_exp_liveptr++;
m_exp_regs[0] = m_exp_liveptr & 0xff;
m_exp_regs[1] = (m_exp_liveptr>>8) & 0xff;
m_exp_regs[2] = ((m_exp_liveptr>>16) & 0xff) | m_exp_bankhior;
break;
default:
m_exp_regs[offset] = data;
break;
}
}
/***************************************************************************
START/RESET
***************************************************************************/
void apple2e_state::machine_start()
{
m_ram_ptr = m_ram->pointer();
m_rom_ptr = m_rom->base();
m_ram_size = m_ram->size();
m_speaker_state = 0;
m_speaker->level_w(m_speaker_state);
m_cassette_state = 0;
m_cassette_out = 0;
if (m_cassette)
{
m_cassette->output(-1.0f);
}
m_upperbank.select(0);
m_lcbank.select(0);
m_0000bank.select(0);
m_0200bank.select(0);
m_0400bank.select(0);
m_0800bank.select(0);
m_2000bank.select(0);
m_4000bank.select(0);
m_inh_bank = 0;
m_migpage = 0;
memset(m_migram, 0, 0x200);
// expansion RAM size
if (m_ram_size > (128*1024))
{
m_exp_addrmask = m_ram_size - (128*1024) - 1;
m_exp_ram = m_ram_ptr + (128*1024);
}
else // no expansion
{
m_exp_addrmask = 0;
m_exp_ram = nullptr;
}
// precalculate joystick time constants
m_x_calibration = attotime::from_nsec(10800).as_double();
m_y_calibration = attotime::from_nsec(10800).as_double();
// cache slot devices
for (int i = 0; i <= 7; i++)
{
m_slotdevice[i] = m_a2bus->get_a2bus_card(i);
}
// and aux slot device if any
m_aux_ptr = nullptr;
m_aux_bank_ptr = nullptr;
m_aux_mask = 0xffff;
if (m_a2eauxslot)
{
m_auxslotdevice = m_a2eauxslot->get_a2eauxslot_card();
if (m_auxslotdevice)
{
m_aux_ptr = m_auxslotdevice->get_vram_ptr();
m_aux_bank_ptr = m_auxslotdevice->get_auxbank_ptr();
m_aux_mask = m_auxslotdevice->get_auxbank_mask();
}
}
else // IIc has 128K right on the motherboard
{
m_auxslotdevice = nullptr;
if (m_ram_size >= (128*1024))
{
m_aux_ptr = &m_ram_ptr[0x10000];
m_aux_bank_ptr = m_aux_ptr;
}
}
// setup video pointers
m_video->set_ram_pointers(m_ram_ptr, m_aux_ptr);
m_video->set_aux_mask(m_aux_mask);
m_video->set_char_pointer(memregion("gfx1")->base(), memregion("gfx1")->bytes());
int ram_size = 0x10000;
if (m_ram_size < 0x10000)
{
ram_size = m_ram_size;
}
for (int adr = 0; adr < ram_size; adr += 2)
{
// invert the fill pattern order on the ACE 500 and 2200, as it interacts with
// Franklin's monitor not returning the same values as Apple's plus some
// bugs in DOS 3.3.
if ((m_isace500) || (m_isace2200))
{
m_ram_ptr[adr] = 0xff;
m_ram_ptr[adr+1] = 0;
}
else
{
m_ram_ptr[adr] = 0;
m_ram_ptr[adr + 1] = 0xff;
}
if (m_ram_size >= (128*1024))
{
m_aux_ptr[adr] = 0;
m_aux_ptr[adr+1] = 0xff;
}
}
m_inh_slot = -1;
m_cnxx_slot = CNXX_UNCLAIMED;
m_mockingboard4c = false;
// remap CEC banking
if ((m_rom_ptr[0x7bb3] == 0x8d) || (m_rom_ptr[0x7bb3] == 0xea) || (m_rom_ptr[0x7bb3] == 0x06))
{
m_lcbank.select(3);
m_cec_ptr = m_cecbanks->base();
m_iscec = true;
m_iscecm = false;
m_iscec2000 = false;
// CEC-M
// write addr C0B0 change to addr C600
if ((m_rom_ptr[0x8000+0x4600] == 0xff) && (m_rom_ptr[0x8000+0x4601] == 0xff))
{
m_iscecm = true;
}
// CEC-2000
if (m_rom_ptr[0x7bb3] == 0x06)