-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSioController.m
More file actions
executable file
·4318 lines (3927 loc) · 128 KB
/
Copy pathSioController.m
File metadata and controls
executable file
·4318 lines (3927 loc) · 128 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
#import <stdio.h>
#import <string.h>
#import <unistd.h>
#import <fcntl.h>
#import <errno.h>
#import <paths.h>
#import <sysexits.h>
#import <sys/param.h>
#import <sys/ioctl.h>
#import <sys/select.h>
#import <sys/types.h>
#import <sys/socket.h>
#import <netinet/in.h>
#import <netdb.h>
#import <Cocoa/Cocoa.h>
#import "Preferences.h"
#import "MediaManager.h"
#import "PrintOutputController.h"
#import <IOKit/IOKitLib.h>
#import <IOKit/serial/IOSerialKeys.h>
#import <IOKit/serial/ioss.h>
#import <IOKit/IOBSD.h>
#import <IOKit/IOCFPlugIn.h>
#import <IOKit/usb/IOUSBLib.h>
#import <mach/mach.h>
#import "SioController.h"
#define ACK_WAIT (delayFactor ? (85 + ( 1000 * delayFactor-1)) : 0)
#define COMPLETE_WAIT (delayFactor ? (255 + ( 1000 * delayFactor)) : 0)
#define POST_COMP_WAIT (delayFactor ? (425 + ( 100 * delayFactor)) : 0)
#define LED_PERSIST 10000
#define XMIT_BLOCK_SIZE 10
#undef DEBUG_PRO
#undef DEBUG_VAPI
#define DEVC_SECTOR_START_WITH_ZERO 0x80
#define DEVC_FIRST_3_SECTORS_FULL_SIZE 0x40
#define DEVC_DEVICE_ACTIVATED 0x02
#define DEVC_FOURTY_TRACK_ON_EIGHTY_TRACK 0x01
typedef struct driveConfigMsg
{
UInt8 trackCount;
UInt8 stepRate;
UInt8 sectorCountHi;
UInt8 sectorCountLo;
UInt8 headCount;
UInt8 formatId;
UInt8 bytesPerSectorHi;
UInt8 bytesPerSectorLo;
UInt8 bitfield;
UInt8 unused[3];
UInt8 checksum;
} DRIVE_CONFIG_MSG;
#define DEVS_ENHANCED_DENSITY 0x80
#define DEVS_DOUBLE_DENSITY 0x20
#define DEVS_MOTOR_ON 0x10
#define DEVS_WRITE_PROTECT 0x08
#define DEVS_WRITE_ERROR 0x04
#define DEVS_DATA_FRAME_ERROR 0x02
#define DEVS_COMMAND_FRAME_ERROR 0x01
#define DEVS_HW_NOT_READY 0x80
#define DEVS_HW_WRITE_PROTECTED 0x40
#define DEVS_HW_RECORD_TYPE 0x20
#define DEVS_HW_RECORD_NOT_FOUND 0x10
#define DEVS_HW_CRC_ERROR 0x08
#define DEVS_HW_DATA_LOST_OR_TRACK0 0x04
#define DEVS_HW_DATA_REQUEST_OR_INDEX 0x02
#define DEVS_CONTROLLER_BUSY 0x01
// TBD need to shut down Cassette server if Serial cable is removed
typedef struct driveStatusMsg
{
UInt8 deviceStatus;
UInt8 hwStatus;
UInt8 timeout;
UInt8 unused;
UInt8 checksum;
} DRIVE_STATUS_MSG;
typedef struct a850StatusMsg
{
UInt8 errors;
UInt8 lineState;
UInt8 checksum;
} A850_STATUS_MSG;
typedef struct concurrentRespMsg
{
UInt8 audf1;
UInt8 audctl1;
UInt8 audf2;
UInt8 audctl2;
UInt8 audf3;
UInt8 audctl3;
UInt8 audf4;
UInt8 audctl4;
UInt8 audioctl;
UInt8 checksum;
} CONCURRENT_RESP_MSG;
typedef struct a850PollResponse
{
UInt8 msg[12];
UInt8 checksum;
} A850_POLL_RESPONSE;
typedef struct cassetteHeader
{
UInt8 recordType[4];
UInt8 lengthLo;
UInt8 lengthHi;
UInt8 aux1;
UInt8 aux2;
} CASSETTE_HEADER;
typedef struct atariDirEnt {
UInt8 flags;
UInt8 secCountLow;
UInt8 secCountHigh;
UInt8 startSecLow;
UInt8 startSecHigh;
char name[11];
} ATARI_DIR_ENT;
static char sectorMap[128] = {
0x02,0xc3,0x02,0x83,0x02,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xfe,0x01,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
#undef OLD_850ROM
#ifdef OLD_850ROM
// Note, there is an extra byte to store checksum
static UInt8 bootHandler850[] =
{
0x00,0x03,0x00,0x05,0xc0,0xe4,0xa9,0x50,0x8d,0x00,0x03,0xad,0xe7,0x02,0x8d,0x04,
0x03,0xad,0xe8,0x02,0x8d,0x05,0x03,0xa9,0xb4,0x8d,0x08,0x03,0xa9,0x05,0x8d,0x09,
0x03,0x8d,0x06,0x03,0xa9,0x01,0x8d,0x01,0x03,0xa9,0x40,0x8d,0x03,0x03,0xa9,0x26,
0x8d,0x02,0x03,0x20,0x59,0xe4,0x10,0x02,0x38,0x60,0xa2,0x88,0x18,0xbd,0xa7,0x05,
0x6d,0xe7,0x02,0x9d,0xa7,0x05,0xbd,0xa8,0x05,0x6d,0xe8,0x02,0x9d,0xa8,0x05,0xca,
0xca,0xd0,0xe9,0xa0,0x00,0x8c,0x59,0x06,0x20,0x44,0x06,0xb1,0x80,0xaa,0xc8,0xb1,
0x80,0x48,0xbd,0xb2,0x05,0x91,0x80,0x88,0xbd,0xb1,0x05,0x91,0x80,0x68,0x20,0x31,
0x06,0xd0,0xe8,0xa2,0x02,0x20,0x44,0x06,0xb1,0x80,0xaa,0xbd,0xb1,0x05,0x91,0x80,
0xae,0x59,0x06,0xee,0x59,0x06,0xbd,0x4f,0x06,0x20,0x31,0x06,0xd0,0xea,0xa2,0x04,
0x20,0x44,0x06,0xa5,0x0c,0x91,0x80,0xc8,0xa5,0x0d,0x91,0x80,0xad,0x2b,0x06,0x85,
0x0c,0xad,0x2c,0x06,0x85,0x0d,0xa2,0x0c,0x4c,0xe9,0x03,0xb2,0x05,0xd5,0x04,0xfc,
0x03,0x66,0x05,0xbf,0x06,0xb7,0x06,0xbb,0x06,0xe0,0x06,0xc7,0x04,0xe5,0x04,0xdf,
0x06,0xdd,0x06,0xde,0x06,0xd7,0x06,0xd6,0x06,0x7e,0x05,0xe1,0x06,0xc3,0x06,0xc2,
0x00,0x0d,0x05,0xef,0x04,0x1f,0x05,0x34,0x06,0x16,0x05,0x38,0x05,0xd2,0x06,0xd3,
0x06,0xd4,0x06,0xd5,0x06,0x48,0x05,0xc7,0x06,0xd3,0x06,0xa5,0x05,0xa4,0x05,0xce,
0x06,0xcc,0x06,0xcf,0x06,0xcd,0x06,0x59,0x05,0xb3,0x06,0xdf,0x06,0xae,0x05,0x0f,
0x01,0xfa,0x04,0x72,0x05,0x23,0x02,0x94,0x05,0x26,0x04,0x39,0x00,0xd0,0x06,0xd1,
0x06,0x29,0x05,0xff,0xff,0x1c,0x00,0x5b,0x01,0x67,0x00,0x0c,0x02,0x56,0x02,0x70,
0x03,0x95,0x03,0x89,0x03,0x9c,0x03,0x71,0x02,0x86,0x04,0xb3,0x03,0xb4,0x05,0xfe,
0x03,0x8d,0x5a,0x06,0x38,0xa5,0x80,0xed,0x5a,0x06,0x85,0x80,0xb0,0x02,0xc6,0x81,
0xad,0x5a,0x06,0x60,0xbd,0xab,0x05,0x85,0x80,0xbd,0xac,0x05,0x85,0x81,0x60,0x0a,
0xf9,0x05,0x85,0x0b,0x48,0x05,0x37,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00};
// Note, there is an extra byte to store checksum
static UInt8 deviceHandler850[] =
{
0x20,0x00,0x00,0xbd,0x02,0x03,0x10,0x03,0xa0,0x96,0x60,0xa5,0x2a,0x09,0x80,0x9d,
0x02,0x0c,0xa9,0x00,0x9d,0x04,0x05,0x9d,0x06,0x03,0xa0,0x01,0x60,0x20,0x00,0x06,
0xec,0x08,0x03,0xf0,0x0c,0xbd,0x04,0x05,0xf0,0x2f,0x20,0x0a,0x05,0xa0,0x80,0xd0,
0x2d,0x20,0x0c,0x07,0xad,0x0e,0x03,0xf0,0xf8,0x78,0xad,0x10,0x06,0x8d,0x16,0x02,
0xad,0x12,0x06,0x8d,0x17,0x02,0xa2,0x05,0xbd,0x14,0x08,0x9d,0x0a,0x02,0xca,0x10,
0xf7,0x58,0xad,0x08,0x0a,0x8e,0x08,0x03,0xaa,0xa0,0x00,0x8c,0x0a,0x03,0xa9,0x00,
0x9d,0x02,0x0b,0xa9,0x57,0x4c,0x18,0x05,0xbc,0x41,0x03,0xc0,0x05,0x90,0x03,0xa0,
0x82,0x60,0x8d,0x1a,0x0d,0xb9,0x02,0x03,0x29,0x08,0xd0,0x03,0xa0,0x87,0x60,0x98,
0xaa,0x86,0x21,0xbd,0x1c,0x0e,0x29,0x30,0xa8,0xf0,0x04,0xc9,0x20,0xb0,0x36,0xad,
0x1a,0x0c,0xc9,0x9b,0xd0,0x19,0xbd,0x1c,0x07,0x29,0x40,0xf0,0x0e,0xa9,0x0d,0x20,
0x1e,0x09,0x10,0x01,0x60,0xa6,0x21,0xa9,0x0a,0xd0,0x17,0xa9,0x0d,0xd0,0x13,0xc0,
0x10,0xf0,0x04,0x29,0x7f,0x10,0x0b,0xc9,0x20,0x90,0x04,0xc9,0x7d,0x90,0x03,0xa0,
0x01,0x60,0x8d,0x1a,0x23,0xbd,0x1c,0x03,0x29,0x03,0xf0,0x1e,0xc9,0x03,0xf0,0x0e,
0xa8,0x20,0x20,0x0c,0x20,0x22,0x03,0x98,0x29,0x02,0xf0,0x0c,0x90,0x0c,0xad,0x1a,
0x0a,0x09,0x80,0x8d,0x1a,0x05,0x30,0x02,0x90,0xf4,0xa6,0x21,0xec,0x08,0x09,0xf0,
0x2d,0x20,0x24,0x05,0x7d,0x04,0x03,0xa8,0xad,0x1a,0x04,0x99,0x26,0x03,0xfe,0x04,
0x03,0xc9,0x0d,0xf0,0x0a,0xa9,0x20,0xdd,0x04,0x09,0xf0,0x03,0xa0,0x01,0x60,0x20,
0x0a,0x08,0xa0,0x80,0xa9,0x00,0x9d,0x04,0x07,0xa9,0x57,0x4c,0x18,0x05,0x20,0x0c,
0x03,0xad,0x16,0x03,0xc9,0x1f,0xb0,0xf6,0x20,0x24,0x07,0x78,0x7d,0x04,0x04,0xa8,
0xad,0x1a,0x04,0x99,0x26,0x03,0xbc,0x04,0x03,0x20,0x28,0x03,0x9d,0x04,0x03,0xee,
0x16,0x03,0xa5,0x10,0xbc,0x1c,0x05,0x30,0x04,0x09,0x18,0xd0,0x02,0x09,0x08,0x85,
0x10,0x8d,0x0e,0xd2,0xa0,0x00,0x8c,0x0e,0x12,0x58,0xc8,0x60,0x20,0x00,0x06,0xbd,
0x02,0x03,0x29,0x04,0xd0,0x03,0xa0,0x83,0x60,0xec,0x08,0x0a,0xf0,0x03,0xa0,0x9a,
0x60,0xa0,0x04,0xa2,0x06,0x58,0x20,0x0c,0x0d,0x78,0x20,0x2a,0x04,0xf0,0xf6,0xa5,
0x2c,0x48,0xa5,0x2d,0x48,0xad,0x2c,0x0b,0x85,0x2c,0xad,0x2e,0x05,0x85,0x2d,0xa0,
0x00,0xb1,0x2c,0x8d,0x1a,0x09,0x68,0x85,0x2d,0x68,0x85,0x2c,0x38,0xad,0x30,0x0a,
0xe9,0x01,0x8d,0x30,0x05,0xb0,0x03,0xce,0x32,0x05,0xa2,0x02,0x20,0x34,0x05,0x58,
0xa6,0x21,0xbd,0x1c,0x06,0x4a,0x4a,0x29,0x03,0xf0,0x23,0xc9,0x03,0xf0,0x1c,0xa8,
0xad,0x1a,0x0e,0x20,0x22,0x03,0x98,0x29,0x02,0xf0,0x0e,0x90,0x0e,0xa6,0x21,0xa9,
0x20,0x1d,0x06,0x0e,0x9d,0x06,0x03,0xd0,0x02,0x90,0xf2,0x20,0x20,0x07,0xa6,0x21,
0xbd,0x1c,0x05,0x29,0x30,0xc9,0x20,0x90,0x06,0xad,0x1a,0x09,0xa0,0x01,0x60,0xa8,
0x20,0x20,0x07,0xc9,0x0d,0xd0,0x04,0xa9,0x9b,0xd0,0x0f,0xc0,0x00,0xf0,0x0b,0xc9,
0x20,0x90,0x04,0xc9,0x7d,0x90,0x03,0xbd,0x36,0x17,0xa0,0x01,0x60,0x20,0x00,0x06,
0xbd,0x06,0x03,0x8d,0xea,0x02,0x8d,0x1a,0x06,0xa9,0x00,0x9d,0x06,0x05,0xec,0x08,
0x03,0xf0,0x27,0xa9,0xea,0x8d,0x04,0x03,0xa9,0x02,0x8d,0x05,0x03,0xa9,0x02,0x8d,
0x08,0x03,0xa9,0x00,0x8d,0x09,0x03,0xa0,0x40,0xa9,0x53,0x20,0x18,0x1d,0xad,0x1a,
0x03,0x0d,0xea,0x02,0x8d,0xea,0x02,0xc0,0x00,0x60,0xa0,0x03,0xb9,0x38,0x0e,0x99,
0xea,0x02,0x88,0xd0,0xf7,0xc8,0x60,0x20,0x00,0x0b,0xa5,0x22,0x29,0x0f,0xc9,0x09,
0xb0,0x0d,0xa8,0x4a,0xb0,0x09,0xb9,0x3a,0x0f,0x48,0xb9,0x3c,0x04,0x48,0x60,0xa0,
0x84,0x60,0xbd,0x02,0x08,0x30,0x03,0xa0,0x85,0x60,0x2c,0x08,0x08,0x70,0x03,0xa0,
0x99,0x60,0x4a,0xb0,0x03,0xa0,0x97,0x60,0x4a,0x4a,0x90,0x4f,0xa5,0x2a,0xf0,0x20,
0xa5,0x28,0x05,0x29,0xf0,0x1a,0x18,0xa5,0x24,0x8d,0x3e,0x1f,0x65,0x28,0x8d,0x40,
0x05,0xa5,0x25,0x8d,0x42,0x05,0x65,0x29,0x8d,0x44,0x05,0x90,0x23,0xa0,0x98,0x60,
0x20,0x24,0x08,0x69,0x7c,0x8d,0x3e,0x05,0xa9,0x7d,0x69,0x00,0x8d,0x42,0x07,0x18,
0xad,0x3e,0x04,0x69,0x1f,0x8d,0x40,0x05,0xad,0x42,0x03,0x69,0x00,0x8d,0x44,0x05,
0xa0,0x06,0x20,0x46,0x05,0x88,0x88,0xc0,0x02,0xd0,0xf7,0xa6,0x21,0xbd,0x02,0x0b,
0x29,0x08,0xf0,0x08,0xa9,0x00,0x9d,0x04,0x09,0x9d,0x48,0x03,0x8d,0x09,0x03,0xa9,
0x14,0x8d,0x04,0x03,0xa9,0x15,0x8d,0x05,0x03,0xbd,0x02,0x10,0x8d,0x0a,0x03,0xa9,
0x09,0x8d,0x08,0x03,0xa0,0x40,0xa9,0x58,0x20,0x18,0x0f,0x10,0x01,0x60,0x78,0xa9,
0x73,0x8d,0x0f,0xd2,0xad,0x4a,0x0c,0x8d,0x08,0xd2,0xa0,0x07,0xb9,0x14,0x08,0x99,
0x00,0xd2,0x88,0x10,0xf7,0xa2,0x05,0xbd,0x0a,0x02,0x9d,0x14,0x0e,0xbd,0x4c,0x03,
0x9d,0x0a,0x02,0xca,0x10,0xf1,0xad,0x16,0x02,0x8d,0x10,0x0c,0xa9,0x7e,0x8d,0x16,
0x02,0xad,0x17,0x02,0x8d,0x12,0x0b,0xa9,0x7f,0x8d,0x17,0x02,0xa9,0x00,0xa0,0x02,
0x99,0x30,0x0c,0x88,0x10,0xfa,0xa6,0x21,0xbd,0x02,0x08,0x29,0x04,0xf0,0x09,0xa5,
0x10,0x09,0x20,0x8d,0x0e,0xd2,0x85,0x10,0x8e,0x08,0x10,0x8e,0x0e,0x03,0x58,0xd0,
0x36,0xbd,0x02,0x06,0x30,0x03,0xa0,0x85,0x60,0x29,0x08,0xd0,0x03,0xa0,0x87,0x60,
0xbd,0x04,0x0f,0xf0,0x22,0x20,0x4e,0x05,0xd0,0x1f,0xa0,0x7f,0x20,0x50,0x07,0xa9,
0x42,0x20,0x52,0x05,0xd0,0x13,0xa9,0x41,0x20,0x52,0x07,0xd0,0x0c,0xa0,0x80,0x20,
0x50,0x07,0xa5,0x2b,0x9d,0x36,0x05,0xa0,0x01,0xa6,0x21,0xbd,0x02,0x07,0x85,0x2a,
0xc0,0x00,0x60,0xa9,0x00,0xa2,0x00,0xdd,0x1a,0x03,0xf0,0x08,0xe8,0xe8,0xe8,0xe0,
0x20,0x90,0xf4,0x60,0xa9,0x52,0x8d,0x08,0x1b,0x9d,0x1a,0x03,0xa9,0x56,0x9d,0x1b,
0x03,0xa9,0x57,0x9d,0x1c,0x03,0x18,0xad,0xe7,0x02,0x69,0xe2,0x8d,0xe7,0x02,0xad,
0xe8,0x02,0x69,0x06,0x8d,0xe8,0x02,0xa2,0x04,0xa9,0x00,0x9d,0x02,0x25,0xca,0xd0,
0xfa,0xe8,0x20,0x54,0x07,0x18,0xa5,0x08,0xd0,0x01,0x60,0x4c,0xff,0xff,0x2c,0x0e,
0xd2,0x10,0x03,0x6c,0x10,0x11,0x48,0x8a,0x48,0x98,0x48,0xae,0x08,0x08,0xbd,0x02,
0x03,0x48,0x8a,0x48,0x20,0x5a,0x06,0x68,0xaa,0x68,0x9d,0x02,0x06,0xa9,0x00,0x85,
0x11,0x9d,0x04,0x07,0xf0,0x5a,0xd8,0x8a,0x48,0x98,0x48,0xa5,0x2c,0x48,0xa5,0x2d,
0x48,0xad,0x5c,0x10,0x85,0x2c,0xad,0x5e,0x05,0x85,0x2d,0xad,0x0d,0xd2,0xa0,0x00,
0x91,0x2c,0xad,0x0f,0xd2,0x8d,0x0a,0xd2,0x49,0xff,0x29,0xc0,0xae,0x08,0x16,0x1d,
0x06,0x03,0x9d,0x06,0x03,0x68,0x85,0x2d,0x68,0x85,0x2c,0xa2,0x00,0x20,0x34,0x0b,
0xa0,0x04,0xa2,0x06,0x20,0x2a,0x07,0xd0,0x12,0xa2,0x02,0x20,0x34,0x07,0xae,0x08,
0x03,0xbd,0x06,0x03,0x09,0x10,0x9d,0x06,0x05,0xd0,0x05,0xa2,0x04,0x20,0x60,0x07,
0x68,0xa8,0x68,0xaa,0x68,0x40,0xd8,0x8a,0x48,0x98,0x48,0xae,0x08,0x0e,0xbd,0x04,
0x03,0xdd,0x48,0x03,0xd0,0x0f,0x8e,0x0e,0x05,0xa5,0x10,0x29,0xe7,0x85,0x10,0x8d,
0x0e,0xd2,0x18,0x90,0xdb,0x20,0x24,0x0f,0x7d,0x48,0x03,0xa8,0xb9,0x26,0x04,0x8d,
0x0d,0xd2,0xbc,0x48,0x06,0x20,0x28,0x03,0x9d,0x48,0x03,0xce,0x16,0x03,0xad,0x0e,
0xd2,0x29,0x08,0xf0,0xf9,0xd0,0xb9,0x20,0x24,0x0c,0x69,0x26,0x8d,0x04,0x03,0xa9,
0x00,0x8d,0x09,0x03,0x69,0x27,0x8d,0x05,0x03,0xbd,0x04,0x12,0x8d,0x0a,0x03,0xa9,
0x40,0x8d,0x08,0x03,0x60,0xa5,0x11,0xf0,0x01,0x60,0x68,0x68,0xa0,0x80,0x60,0xa2,
0x00,0x4a,0x90,0x01,0xe8,0xd0,0xfa,0x8a,0x4a,0x60,0x98,0x3d,0x1c,0x22,0x9d,0x1c,
0x03,0x98,0x49,0xff,0x25,0x2a,0x1d,0x1c,0x08,0x9d,0x1c,0x03,0x60,0xad,0x1a,0x04,
0x29,0x7f,0x8d,0x1a,0x05,0x60,0xc8,0x98,0xc9,0x20,0x90,0x02,0xa9,0x00,0x60,0x8a,
0x38,0xe9,0x01,0x0a,0x0a,0x0a,0x0a,0x0a,0x60,0x18,0xbd,0x5c,0x18,0x69,0x01,0x9d,
0x5c,0x05,0x90,0x03,0xfe,0x5e,0x05,0x60,0xb9,0x44,0x04,0xdd,0x44,0x03,0xf0,0x01,
0x60,0xb9,0x40,0x06,0xdd,0x40,0x03,0x60,0x20,0x60,0x04,0x8a,0x18,0x69,0x04,0xa8,
0xa2,0x00,0x20,0x2a,0x0a,0xf0,0x0e,0x90,0x0c,0xad,0x3e,0x07,0x99,0x40,0x03,0xad,
0x42,0x03,0x99,0x44,0x03,0x60,0xa6,0x21,0xe0,0x05,0xb0,0x01,0x60,0x68,0x68,0xa0,
0x82,0x60,0xa4,0x2a,0x8c,0x0a,0x03,0xa4,0x2b,0x8c,0x0b,0x03,0xa0,0x00,0x8d,0x02,
0x03,0x8e,0x01,0x03,0x8c,0x03,0x03,0xa0,0x50,0x8c,0x00,0x03,0xa0,0x08,0x8c,0x06,
0x03,0x4c,0x59,0xe4,0x62,0x31,0x64,0x02,0x66,0x02,0x68,0x02,0x6a,0x02,0x6c,0x02,
0x4c,0x7a,0x03,0x00,0x6e,0x03,0x70,0x02,0x72,0x02,0x74,0x02,0x76,0x02,0x58,0x02,
0x78,0x02,0x78,0x02,0x00};
#else
// Note, there is an extra byte to store checksum
static UInt8 bootHandler850[] =
{
0x00,0x03,0x00,0x05,0xc0,0xe4,0xa9,0x50,0x8d,0x00,0x03,0xad,0xe7,0x02,0x8d,0x04,
0x03,0xad,0xe8,0x02,0x8d,0x05,0x03,0xa9,0x91,0x8d,0x08,0x03,0xa9,0x05,0x8d,0x09,
0x03,0x8d,0x06,0x03,0xa9,0x01,0x8d,0x01,0x03,0xa9,0x40,0x8d,0x03,0x03,0xa9,0x26,
0x8d,0x02,0x03,0x20,0x59,0xe4,0x10,0x02,0x38,0x60,0xa2,0x84,0x18,0xbd,0xa7,0x05,
0x6d,0xe7,0x02,0x9d,0xa7,0x05,0xbd,0xa8,0x05,0x6d,0xe8,0x02,0x9d,0xa8,0x05,0xca,
0xca,0xd0,0xe9,0xa0,0x00,0x8c,0x55,0x06,0x20,0x40,0x06,0xb1,0x80,0xaa,0xc8,0xb1,
0x80,0x48,0xbd,0xb2,0x05,0x91,0x80,0x88,0xbd,0xb1,0x05,0x91,0x80,0x68,0x20,0x2d,
0x06,0xd0,0xe8,0xa2,0x02,0x20,0x40,0x06,0xb1,0x80,0xaa,0xbd,0xb1,0x05,0x91,0x80,
0xae,0x55,0x06,0xee,0x55,0x06,0xbd,0x4b,0x06,0x20,0x2d,0x06,0xd0,0xea,0xa2,0x04,
0x20,0x40,0x06,0xa5,0x0c,0x91,0x80,0xc8,0xa5,0x0d,0x91,0x80,0xad,0x27,0x06,0x85,
0x0c,0xad,0x28,0x06,0x85,0x0d,0xa2,0x0c,0x4c,0xe9,0x03,0x8f,0x05,0xc2,0x04,0xfc,
0x03,0x43,0x05,0x9c,0x06,0x94,0x06,0x98,0x06,0xbd,0x06,0xb4,0x04,0xbc,0x06,0xba,
0x06,0xbb,0x06,0xb4,0x06,0xb3,0x06,0x5b,0x05,0xbe,0x06,0xa0,0x06,0xc8,0x00,0xf0,
0x04,0xd2,0x04,0x02,0x05,0x11,0x06,0xf9,0x04,0x15,0x05,0xaf,0x06,0xb0,0x06,0xb1,
0x06,0xb2,0x06,0x25,0x05,0xa4,0x06,0xb0,0x06,0x82,0x05,0x81,0x05,0xab,0x06,0xa9,
0x06,0xac,0x06,0xaa,0x06,0x36,0x05,0x90,0x06,0xbc,0x06,0x8b,0x05,0x15,0x01,0xdd,
0x04,0x4f,0x05,0x23,0x02,0x71,0x05,0x13,0x04,0xad,0x06,0xae,0x06,0x0c,0x05,0xff,
0xff,0x25,0x00,0x5e,0x01,0x6d,0x00,0x0c,0x02,0x56,0x02,0x70,0x03,0x95,0x03,0x89,
0x03,0x9c,0x03,0x71,0x02,0x73,0x04,0xb3,0x03,0x91,0x05,0xfe,0x03,0x8d,0x56,0x06,
0x38,0xa5,0x80,0xed,0x56,0x06,0x85,0x80,0xb0,0x02,0xc6,0x81,0xad,0x56,0x06,0x60,
0xbd,0xab,0x05,0x85,0x80,0xbd,0xac,0x05,0x85,0x81,0x60,0x0a,0xe6,0x05,0x85,0x0b,
0x48,0x05,0x37,0x05,0x00,0x00};
// Note, there is an extra byte to store checksum
static UInt8 deviceHandler850[] =
{
0x20,0x00,0x00,0xbd,0x02,0x03,0x10,0x03,0xa0,0x96,0x60,0xa5,0x2a,0xa8,0x29,0x0c,
0xd0,0x03,0xa0,0x84,0x60,0x98,0x09,0x80,0x9d,0x02,0x15,0xa9,0x00,0x9d,0x04,0x05,
0x9d,0x06,0x03,0xa0,0x01,0x60,0x20,0x00,0x06,0xec,0x08,0x03,0xf0,0x0c,0xbd,0x04,
0x05,0xf0,0x2c,0x20,0x0a,0x05,0xa0,0x80,0xd0,0x2a,0xad,0x0c,0x07,0xf0,0xfb,0x78,
0xad,0x0e,0x06,0x8d,0x16,0x02,0xad,0x10,0x06,0x8d,0x17,0x02,0xa2,0x05,0xbd,0x12,
0x08,0x9d,0x0a,0x02,0xca,0x10,0xf7,0x58,0xad,0x08,0x0a,0x8e,0x08,0x03,0xaa,0xa0,
0x00,0x8c,0x0a,0x03,0xa9,0x00,0x9d,0x02,0x0b,0xa9,0x57,0x4c,0x16,0x05,0xbc,0x41,
0x03,0xc0,0x05,0x90,0x03,0xa0,0x82,0x60,0x8d,0x18,0x0d,0xb9,0x02,0x03,0x29,0x08,
0xd0,0x03,0xa0,0x87,0x60,0x98,0xaa,0x86,0x21,0xbd,0x1a,0x0e,0x29,0x30,0xa8,0xf0,
0x04,0xc9,0x20,0xb0,0x36,0xad,0x18,0x0c,0xc9,0x9b,0xd0,0x19,0xbd,0x1a,0x07,0x29,
0x40,0xf0,0x0e,0xa9,0x0d,0x20,0x1c,0x09,0x10,0x01,0x60,0xa6,0x21,0xa9,0x0a,0xd0,
0x17,0xa9,0x0d,0xd0,0x13,0xc0,0x10,0xf0,0x04,0x29,0x7f,0x10,0x0b,0xc9,0x20,0x90,
0x04,0xc9,0x7d,0x90,0x03,0xa0,0x01,0x60,0x8d,0x18,0x23,0xbd,0x1a,0x03,0x29,0x03,
0xf0,0x1e,0xc9,0x03,0xf0,0x0e,0xa8,0x20,0x1e,0x0c,0x20,0x20,0x03,0x98,0x29,0x02,
0xf0,0x0c,0x90,0x0c,0xad,0x18,0x0a,0x09,0x80,0x8d,0x18,0x05,0x30,0x02,0x90,0xf4,
0xa6,0x21,0xec,0x08,0x09,0xf0,0x2d,0x20,0x22,0x05,0x7d,0x04,0x03,0xa8,0xad,0x18,
0x04,0x99,0x24,0x03,0xfe,0x04,0x03,0xc9,0x0d,0xf0,0x0a,0xa9,0x20,0xdd,0x04,0x09,
0xf0,0x03,0xa0,0x01,0x60,0x20,0x0a,0x08,0xa0,0x80,0xa9,0x00,0x9d,0x04,0x07,0xa9,
0x57,0x4c,0x16,0x05,0xad,0x14,0x03,0xc9,0x1f,0xb0,0xf9,0x20,0x22,0x07,0x78,0x7d,
0x04,0x04,0xa8,0xad,0x18,0x04,0x99,0x24,0x03,0xbc,0x04,0x03,0x20,0x26,0x03,0x9d,
0x04,0x03,0xee,0x14,0x03,0xa5,0x10,0xbc,0x1a,0x05,0x30,0x04,0x09,0x18,0xd0,0x02,
0x09,0x08,0x85,0x10,0x8d,0x0e,0xd2,0xa0,0x00,0x8c,0x0c,0x12,0x58,0xc8,0x60,0x20,
0x00,0x06,0xbd,0x02,0x03,0x29,0x04,0xd0,0x03,0xa0,0x83,0x60,0xec,0x08,0x0a,0xf0,
0x03,0xa0,0x9a,0x60,0xa0,0x04,0xa2,0x06,0x58,0x78,0x20,0x28,0x0e,0xf0,0xf9,0xa5,
0x2c,0x48,0xa5,0x2d,0x48,0xad,0x2a,0x0b,0x85,0x2c,0xad,0x2c,0x05,0x85,0x2d,0xa0,
0x00,0xb1,0x2c,0x8d,0x18,0x09,0x68,0x85,0x2d,0x68,0x85,0x2c,0x38,0xad,0x2e,0x0a,
0xe9,0x01,0x8d,0x2e,0x05,0xb0,0x03,0xce,0x30,0x05,0xa2,0x02,0x20,0x32,0x05,0x58,
0xa6,0x21,0xbd,0x1a,0x06,0x4a,0x4a,0x29,0x03,0xf0,0x23,0xc9,0x03,0xf0,0x1c,0xa8,
0xad,0x18,0x0e,0x20,0x20,0x03,0x98,0x29,0x02,0xf0,0x0e,0x90,0x0e,0xa6,0x21,0xa9,
0x20,0x1d,0x06,0x0e,0x9d,0x06,0x03,0xd0,0x02,0x90,0xf2,0x20,0x1e,0x07,0xa6,0x21,
0xbd,0x1a,0x05,0x29,0x30,0xc9,0x20,0x90,0x06,0xad,0x18,0x09,0xa0,0x01,0x60,0xa8,
0x20,0x1e,0x07,0xc9,0x0d,0xd0,0x04,0xa9,0x9b,0xd0,0x0f,0xc0,0x00,0xf0,0x0b,0xc9,
0x20,0x90,0x04,0xc9,0x7d,0x90,0x03,0xbd,0x34,0x17,0xa0,0x01,0x60,0x20,0x00,0x06,
0xbd,0x06,0x03,0x8d,0xea,0x02,0x8d,0x18,0x06,0xa9,0x00,0x9d,0x06,0x05,0xec,0x08,
0x03,0xf0,0x27,0xa9,0xea,0x8d,0x04,0x03,0xa9,0x02,0x8d,0x05,0x03,0xa9,0x02,0x8d,
0x08,0x03,0xa9,0x00,0x8d,0x09,0x03,0xa0,0x40,0xa9,0x53,0x20,0x16,0x1d,0xad,0x18,
0x03,0x0d,0xea,0x02,0x8d,0xea,0x02,0xc0,0x00,0x60,0xa0,0x03,0xb9,0x36,0x0e,0x99,
0xea,0x02,0x88,0xd0,0xf7,0xc8,0x60,0x20,0x00,0x0b,0xa5,0x22,0x29,0x0f,0xc9,0x09,
0xb0,0x0d,0xa8,0x4a,0xb0,0x09,0xb9,0x38,0x0f,0x48,0xb9,0x3a,0x04,0x48,0x60,0xa0,
0x84,0x60,0xbd,0x02,0x08,0x30,0x03,0xa0,0x85,0x60,0x2c,0x08,0x08,0x70,0x03,0xa0,
0x99,0x60,0x4a,0xb0,0x03,0xa0,0x97,0x60,0x4a,0x4a,0x90,0x4f,0xa5,0x2a,0xf0,0x20,
0xa5,0x28,0x05,0x29,0xf0,0x1a,0x18,0xa5,0x24,0x8d,0x3c,0x1f,0x65,0x28,0x8d,0x3e,
0x05,0xa5,0x25,0x8d,0x40,0x05,0x65,0x29,0x8d,0x42,0x05,0x90,0x23,0xa0,0x98,0x60,
0x20,0x22,0x08,0x69,0x78,0x8d,0x3c,0x05,0xa9,0x79,0x69,0x00,0x8d,0x40,0x07,0x18,
0xad,0x3c,0x04,0x69,0x1f,0x8d,0x3e,0x05,0xad,0x40,0x03,0x69,0x00,0x8d,0x42,0x05,
0xa0,0x06,0x20,0x44,0x05,0x88,0x88,0xc0,0x02,0xd0,0xf7,0xa6,0x21,0xbd,0x02,0x0b,
0x29,0x08,0xf0,0x08,0xa9,0x00,0x9d,0x04,0x09,0x9d,0x46,0x03,0x8d,0x09,0x03,0xa9,
0x12,0x8d,0x04,0x03,0xa9,0x13,0x8d,0x05,0x03,0xbd,0x02,0x10,0x8d,0x0a,0x03,0xa9,
0x09,0x8d,0x08,0x03,0xa0,0x40,0xa9,0x58,0x20,0x16,0x0f,0x10,0x01,0x60,0x78,0xa9,
0x73,0x8d,0x0f,0xd2,0xad,0x48,0x0c,0x8d,0x08,0xd2,0xa0,0x07,0xb9,0x12,0x08,0x99,
0x00,0xd2,0x88,0x10,0xf7,0xa2,0x05,0xbd,0x0a,0x02,0x9d,0x12,0x0e,0xbd,0x4a,0x03,
0x9d,0x0a,0x02,0xca,0x10,0xf1,0xad,0x16,0x02,0x8d,0x0e,0x0c,0xa9,0x7a,0x8d,0x16,
0x02,0xad,0x17,0x02,0x8d,0x10,0x0b,0xa9,0x7b,0x8d,0x17,0x02,0xa9,0x00,0xa0,0x02,
0x99,0x2e,0x0c,0x88,0x10,0xfa,0xa6,0x21,0xbd,0x02,0x08,0x29,0x04,0xf0,0x09,0xa5,
0x10,0x09,0x20,0x8d,0x0e,0xd2,0x85,0x10,0x8e,0x08,0x10,0x8e,0x0c,0x03,0x58,0xd0,
0x36,0xbd,0x02,0x06,0x30,0x03,0xa0,0x85,0x60,0x29,0x08,0xd0,0x03,0xa0,0x87,0x60,
0xbd,0x04,0x0f,0xf0,0x22,0x20,0x4c,0x05,0xd0,0x1f,0xa0,0x7f,0x20,0x4e,0x07,0xa9,
0x42,0x20,0x50,0x05,0xd0,0x13,0xa9,0x41,0x20,0x50,0x07,0xd0,0x0c,0xa0,0x80,0x20,
0x4e,0x07,0xa5,0x2b,0x9d,0x34,0x05,0xa0,0x01,0xa6,0x21,0xbd,0x02,0x07,0x85,0x2a,
0xc0,0x00,0x60,0xa9,0x00,0xa2,0x00,0xdd,0x1a,0x03,0xf0,0x08,0xe8,0xe8,0xe8,0xe0,
0x20,0x90,0xf4,0x60,0xa9,0x52,0x8d,0x08,0x1b,0x9d,0x1a,0x03,0xa9,0x54,0x9d,0x1b,
0x03,0xa9,0x55,0x9d,0x1c,0x03,0x18,0xad,0xe7,0x02,0x69,0xc0,0x8d,0xe7,0x02,0xad,
0xe8,0x02,0x69,0x06,0x8d,0xe8,0x02,0xa2,0x04,0xa9,0x00,0x9d,0x02,0x25,0xca,0xd0,
0xfa,0xe8,0x20,0x52,0x07,0x18,0xa5,0x08,0xd0,0x01,0x60,0x4c,0xff,0xff,0x2c,0x0e,
0xd2,0x10,0x03,0x6c,0x0e,0x11,0x48,0xa9,0x7f,0x8d,0x0e,0xd2,0xa5,0x10,0x8d,0x0e,
0xd2,0x68,0x40,0xd8,0x8a,0x48,0x98,0x48,0xa5,0x2c,0x48,0xa5,0x2d,0x48,0xad,0x58,
0x1b,0x85,0x2c,0xad,0x5a,0x05,0x85,0x2d,0xad,0x0d,0xd2,0xa0,0x00,0x91,0x2c,0xad,
0x0f,0xd2,0x8d,0x0a,0xd2,0x49,0xff,0x29,0xc0,0xae,0x08,0x16,0x1d,0x06,0x03,0x9d,
0x06,0x03,0x68,0x85,0x2d,0x68,0x85,0x2c,0xa2,0x00,0x20,0x32,0x0b,0xa0,0x04,0xa2,
0x06,0x20,0x28,0x07,0xd0,0x12,0xa2,0x02,0x20,0x32,0x07,0xae,0x08,0x03,0xbd,0x06,
0x03,0x09,0x10,0x9d,0x06,0x05,0xd0,0x05,0xa2,0x04,0x20,0x5c,0x07,0x68,0xa8,0x68,
0xaa,0x68,0x40,0xd8,0x8a,0x48,0x98,0x48,0xae,0x08,0x0e,0xbd,0x04,0x03,0xdd,0x46,
0x03,0xd0,0x0f,0x8e,0x0c,0x05,0xa5,0x10,0x29,0xe7,0x85,0x10,0x8d,0x0e,0xd2,0x18,
0x90,0xdb,0x20,0x22,0x0f,0x7d,0x46,0x03,0xa8,0xb9,0x24,0x04,0x8d,0x0d,0xd2,0xbc,
0x46,0x06,0x20,0x26,0x03,0x9d,0x46,0x03,0xce,0x14,0x03,0xad,0x0e,0xd2,0x29,0x08,
0xf0,0xf9,0xd0,0xb9,0x20,0x22,0x0c,0x69,0x24,0x8d,0x04,0x03,0xa9,0x00,0x8d,0x09,
0x03,0x69,0x25,0x8d,0x05,0x03,0xbd,0x04,0x12,0x8d,0x0a,0x03,0xa9,0x40,0x8d,0x08,
0x03,0x60,0xa2,0x00,0x4a,0x90,0x01,0xe8,0xd0,0xfa,0x8a,0x4a,0x60,0x98,0x3d,0x1a,
0x18,0x9d,0x1a,0x03,0x98,0x49,0xff,0x25,0x2a,0x1d,0x1a,0x08,0x9d,0x1a,0x03,0x60,
0xad,0x18,0x04,0x29,0x7f,0x8d,0x18,0x05,0x60,0xc8,0x98,0xc9,0x20,0x90,0x02,0xa9,
0x00,0x60,0x8a,0x38,0xe9,0x01,0x0a,0x0a,0x0a,0x0a,0x0a,0x60,0xfe,0x58,0x17,0xd0,
0x03,0xfe,0x5a,0x05,0x60,0xb9,0x42,0x04,0xdd,0x42,0x03,0xf0,0x01,0x60,0xb9,0x3e,
0x06,0xdd,0x3e,0x03,0x60,0x20,0x5c,0x04,0x8a,0x18,0x69,0x04,0xa8,0xa2,0x00,0x20,
0x28,0x0a,0xf0,0x0e,0x90,0x0c,0xad,0x3c,0x07,0x99,0x3e,0x03,0xad,0x40,0x03,0x99,
0x42,0x03,0x60,0xa6,0x21,0xe0,0x05,0xb0,0x01,0x60,0x68,0x68,0xa0,0x82,0x60,0xa4,
0x2a,0x8c,0x0a,0x03,0xa4,0x2b,0x8c,0x0b,0x03,0xa0,0x00,0x8d,0x02,0x03,0x8e,0x01,
0x03,0x8c,0x03,0x03,0xa0,0x50,0x8c,0x00,0x03,0xa0,0x08,0x8c,0x06,0x03,0x4c,0x59,
0xe4,0x5e,0x31,0x60,0x02,0x62,0x02,0x64,0x02,0x66,0x02,0x68,0x02,0x4c,0x76,0x03,
0x00,0x6a,0x03,0x6c,0x02,0x6e,0x02,0x70,0x02,0x72,0x02,0x56,0x02,0x74,0x02,0x74,
0x02,0x00};
#endif
int driveState[NUMBER_OF_ATARI_DRIVES];
char driveFilename[NUMBER_OF_ATARI_DRIVES][FILENAME_MAX];
char diskImageDefaultDirectory[FILENAME_MAX];
char cassImageDefaultDirectory[FILENAME_MAX];
char diskSetDefaultDirectory[FILENAME_MAX];
char printerOutputDefaultDirectory[FILENAME_MAX];
int currPrinter;
SIO_PREF prefsSio;
FILE *logFile = NULL;
#define LOGICAL_SECTORS 0
#define PHYSICAL_SECTORS 1
#define SIO2PC_SECTORS 2
void SioControllerLogPrint(char *format, ... )
{
va_list args;
if (!logFile) {
NSString *home;
char filename[FILENAME_MAX];
home = NSHomeDirectory();
[home getCString:filename];
strcat(filename,"/Sio2OSXLog.txt");
logFile = fopen(filename,"w");
if (!logFile) {
return;
}
}
va_start(args, format);
vfprintf(logFile,format,args);
fflush(logFile);
va_end(args);
}
/* Global variables for USB device notification */
static IONotificationPortRef gNotifyPort;
static io_iterator_t gAddedIter;
static io_iterator_t gRemovedIter;
/*------------------------------------------------------------------------------
* UsbDeviceAdded - Process an USB Device added notification
*-----------------------------------------------------------------------------*/
void UsbDeviceAdded(void *refCon, io_iterator_t iterator)
{
io_service_t usbDevice;
static int first = TRUE;
while (usbDevice = IOIteratorNext(iterator))
{
}
if (first)
first = FALSE;
else {
[[SioController sharedInstance] rescanModems:YES];
}
}
/*------------------------------------------------------------------------------
* UsbDeviceRemoved - Process an USB Device removed notification
*-----------------------------------------------------------------------------*/
void UsbDeviceRemoved(void *refCon, io_iterator_t iterator)
{
io_service_t usbDevice;
static int first = TRUE;
while (usbDevice = IOIteratorNext(iterator))
{
}
if (first)
first = FALSE;
else {
[[SioController sharedInstance] rescanModems:NO];
}
}
/*------------------------------------------------------------------------------
* Setup_USB_Notifications - Setup so that we are notified if a USB
* device is plugged in.
*-----------------------------------------------------------------------------*/
int Setup_USB_Notifications(void)
{
mach_port_t masterPort;
CFMutableDictionaryRef matchingDict;
CFRunLoopSourceRef runLoopSource;
kern_return_t result;
//Create a master port for communication with the I/O Kit
result = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (result || !masterPort)
{
printf("ERR: CouldnÕt create a master I/O Kit port(%08x)\n", result);
return -1;
}
//Set up matching dictionary for class IOUSBDevice and its subclasses
matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
if (!matchingDict)
{
printf("CouldnÕt create a USB matching dictionary\n");
mach_port_deallocate(mach_task_self(), masterPort);
return -1;
}
//To set up asynchronous notifications, create a notification port and
//add its run loop event source to the programÕs run loop
gNotifyPort = IONotificationPortCreate(masterPort);
runLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource,
kCFRunLoopCommonModes);
//Retain additional dictionary references because each call to
//IOServiceAddMatchingNotification consumes one reference
matchingDict = (CFMutableDictionaryRef) CFRetain(matchingDict);
matchingDict = (CFMutableDictionaryRef) CFRetain(matchingDict);
//Now set up two notifications: one to be called when a USB device
//is first matched by the I/O Kit and another to be called when the
//device is terminated
//Notification of first match
result = IOServiceAddMatchingNotification(gNotifyPort,
kIOFirstMatchNotification, matchingDict,
UsbDeviceAdded, NULL, &gAddedIter);
//Iterate over set of matching devices to access already-present devices
//and to arm the notification
UsbDeviceAdded(NULL, gAddedIter);
//Notification of termination
result = IOServiceAddMatchingNotification(gNotifyPort,
kIOTerminatedNotification, matchingDict,
UsbDeviceRemoved, NULL, &gRemovedIter);
//Iterate over set of matching devices to release each one and to
//arm the notification
UsbDeviceRemoved(NULL, gRemovedIter);
return(0);
}
/*------------------------------------------------------------------------------
* Clenup_USB_Notifications - Cleanup notification structures on quiting.
*-----------------------------------------------------------------------------*/
void Cleanup_USB_Notifications(void)
{
IONotificationPortDestroy(gNotifyPort);
if (gAddedIter)
{
IOObjectRelease(gAddedIter);
gAddedIter = 0;
}
if (gRemovedIter)
{
IOObjectRelease(gRemovedIter);
gRemovedIter = 0;
}
}
@implementation SioController
static SioController *sharedInstance = nil;
+ (SioController *)sharedInstance {
return sharedInstance ? sharedInstance : [[self alloc] init];
}
- (id)init {
if (sharedInstance) {
[self dealloc];
} else {
[super init];
maxSpeed = 3;
currentSpeed = 1;
sharedInstance = self;
offline = NO;
printerFile = NULL;
diskServerPause = 0;
cassFile = NULL;
diskServerStarted = NO;
diskServerExited = NO;
modemChanged = NO;
onUpdate = [LedUpdate withOn:YES];
offUpdate = [LedUpdate withOn:NO];
cassStatusUpdate = [[CassStatusUpdate alloc] init];
cassInfoUpdate = [[CassInfoUpdate alloc] init];
enable850 = YES;
strncpy(netServerBusyMessage,"The BBS is currently connected to another client. Please try again later.\n",255);
strncpy(netServerNotReadyMessage,"The BBS is not ready to accept connections. Please try again later.\n",255);
[self init850State];
Setup_USB_Notifications();
}
return sharedInstance;
}
- (void) init850State
{
int i;
concurrentMode = NO;
concurrentPort = 0;
for (i=0;i<NUM_850_PORTS;i++) {
baud850[i] = B300;
bits850[i] = 8;
stopBits850[i] = 1;
dsrHandshake850[i] = NO;
ctsHandshake850[i] = NO;
dsrLast[i] = NO;
ctsLast[i] = NO;
crxLast[i] = NO;
port850fd[i] = -1;
port850Mode[i] = PORT_850_OFF;
}
port850Mode[0] = PORT_850_NET_MODE;
netATMode = YES;
netCarrierDetected = NO;
netTerminalReady = NO;
netServerFd = -1;
netServerStarted = NO;
netServerExit = NO;
netServerExited = NO;
modemCharCount = 0;
modemEcho = YES;
modemEscapeCharacter = '+';
modemAutoAnswer = NO;
modemAtascii = NO;
}
- (void)dealloc {
[super dealloc];
}
- (void) updatePreferences
{
int i,j;
static BOOL firstTime = YES;
[mutex lock];
maxSpeed = prefsSio.maxSerialSpeed;
delayFactor = prefsSio.delayFactor;
ignoreAtrWriteProtect = prefsSio.ignoreAtrWriteProtect;
sioHWType = prefsSio.sioHWType;
if (currPrinter != prefsSio.currPrinter)
PrintOutputControllerSelectPrinter(prefsSio.currPrinter);
currPrinter = prefsSio.currPrinter;
strcpy(diskSetDefaultDirectory,prefsSio.diskSetDir);
strcpy(diskImageDefaultDirectory,prefsSio.diskImageDir);
strcpy(cassImageDefaultDirectory,prefsSio.cassImageDir);
strcpy(printerOutputDefaultDirectory,prefsSio.printDir);
strcpy(printerCommand,prefsSio.printerCommand);
strcpy(serialPort,prefsSio.serialPort);
for (i=0;i<NUM_STORED_NAMES;i++) {
strcpy(storedNameAddr[i], prefsSio.storedNameAddr[i]);
storedNamePort[i] = prefsSio.storedNamePort[i];
if (storedNameAddr[i][0] == 0)
storedNameInUse[i] = NO;
else
storedNameInUse[i] = YES;
}
strcpy(netServerNotReadyMessage, prefsSio.netServerNotReadyMessage);
strcpy(netServerBusyMessage, prefsSio.netServerBusyMessage);
if (!firstTime) {
// If we have changed server port or if it is enabled, then restart
if (netServerNetPort != prefsSio.netServerNetPort ||
netServerEnable != prefsSio.netServerEnable) {
if (netServerStarted) {
[self stopNetServer];
if (netCarrierDetected) {
close(port850fd[netServerPort]);
port850fd[netServerPort] = -1;
netCarrierDetected = NO;
}
}
netServerNetPort = prefsSio.netServerNetPort;
netServerEnable = prefsSio.netServerEnable;
[self startNetServer];
}
}
else {
netServerNetPort = prefsSio.netServerNetPort;
netServerEnable = prefsSio.netServerEnable;
}
if (firstTime) {
modemEcho = prefsSio.modemEcho;
modemEscapeCharacter = prefsSio.modemEscapeCharacter;
modemAutoAnswer = prefsSio.modemAutoAnswer;
enable850 = prefsSio.enable850;
for (i=0;i<NUM_850_PORTS;i++) {
port850Mode[i] = prefsSio.port850Mode[i];
strcpy(port850Port[i],prefsSio.port850Port[i]);
}
firstTime = FALSE;
}
else {
BOOL changes[NUM_850_PORTS];
// Check if anything changed on each port
for (i=0;i<NUM_850_PORTS;i++) {
changes[i] = NO;
if ((port850Mode[i] != prefsSio.port850Mode[i]) ||
(port850Mode[i] == PORT_850_SERIAL_MODE &&
strcmp(port850Port[i],prefsSio.port850Port[i])==0))
changes[i] = YES;
}
// Close out the old stuff on the changed ports.....
for (i=0;i<NUM_850_PORTS;i++) {
if (changes[i]) {
if (port850Mode[i] == PORT_850_NET_MODE) {
if (netServerStarted) {
[self stopNetServer];
if (netCarrierDetected) {
close(port850fd[netServerPort]);
port850fd[netServerPort] = -1;
netCarrierDetected = NO;
}
}
}
else if (port850Mode[i] == PORT_850_SERIAL_MODE) {
close(port850fd[i]);
}
}
}
// Open the new stuff on the changed ports.....
for (i=0;i<NUM_850_PORTS;i++) {
port850Mode[i] = prefsSio.port850Mode[i];
strcpy(port850Port[i],prefsSio.port850Port[i]);
if (changes[i]) {
if (prefsSio.port850Mode[i] == PORT_850_NET_MODE) {
[self startNetServer];
}
else if (prefsSio.port850Mode[i] == PORT_850_SERIAL_MODE) {
for (j=0;j<modemCount;j++) {
if (strcmp(modemNames[j],port850Port[i])==0)
{
port850fd[i] = [self openSerialPort:bsdPaths[j]:B300];
}
}
}
}
}
}
[mutex unlock];
}
// Returns an iterator across all known modems. Caller is responsible for
// releasing the iterator when iteration is complete.
- (kern_return_t) findModems:(io_iterator_t *) matchingServices
{
kern_return_t kernResult;
mach_port_t masterPort;
CFMutableDictionaryRef classesToMatch;
kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (KERN_SUCCESS != kernResult)
SioControllerLogPrint("IOMasterPort returned %d\n", kernResult);
// Serial devices are instances of class IOSerialBSDClient
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
if (classesToMatch == NULL)
SioControllerLogPrint("IOServiceMatching returned a NULL dictionary.\n");
else {
CFDictionarySetValue(classesToMatch,
CFSTR(kIOSerialBSDTypeKey),
CFSTR(kIOSerialBSDRS232Type));
}
kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, matchingServices);
if (KERN_SUCCESS != kernResult)
SioControllerLogPrint("IOServiceGetMatchingServices returned %d\n", kernResult);
return kernResult;
}
// Given an iterator across a set of modems, return a list of the
// modems BSD paths.
// If no modems are found the path name is set to an empty string.
- (int) getModemPaths:(io_iterator_t )serialPortIterator
{
io_object_t modemService;
kern_return_t kernResult = KERN_FAILURE;
int modems = 0;
while ((modemService = IOIteratorNext(serialPortIterator)) && modems < MAX_MODEMS)
{
CFTypeRef modemNameAsCFString;
CFTypeRef bsdPathAsCFString;
kernResult = KERN_SUCCESS;
modems++;
modemNameAsCFString = IORegistryEntryCreateCFProperty(modemService,
CFSTR(kIOTTYDeviceKey),
kCFAllocatorDefault,
0);
if (modemNameAsCFString)
{
Boolean result;
result = CFStringGetCString(modemNameAsCFString,
modemNames[modems-1],
FILENAME_MAX,
kCFStringEncodingASCII);
CFRelease(modemNameAsCFString);
}
bsdPathAsCFString = IORegistryEntryCreateCFProperty(modemService,
CFSTR(kIOCalloutDeviceKey),
kCFAllocatorDefault,
0);
if (bsdPathAsCFString)
{
Boolean result;
result = CFStringGetCString(bsdPathAsCFString,
bsdPaths[modems-1],
FILENAME_MAX,
kCFStringEncodingASCII);
CFRelease(bsdPathAsCFString);
}
(void) IOObjectRelease(modemService);
}
return modems;
}
// Given the path to a serial device, open the device and configure it.
// Return the file descriptor associated with the device.
- (int) openSerialPort:(const char *) bsdPath:(int)initialBaud
{
int newFileDescriptor = -1;
struct termios options;
newFileDescriptor = open(bsdPath, O_RDWR | O_NOCTTY);
if (newFileDescriptor == -1)
{
SioControllerLogPrint("Error opening serial port %s - %s(%d).\n",
bsdPath, strerror(errno), errno);
goto error;
}
SioControllerLogPrint("Opened serial port %s.\n",bsdPath);
// Get the current options and save them for later reset
if (tcgetattr(newFileDescriptor, &gOriginalTTYAttrs) == -1)
{
SioControllerLogPrint("openSerialPort - Error getting tty attributes %s - %s(%d).\n",
bsdPath, strerror(errno), errno);
goto error;
}
// Set raw input/output, one second timeout
options = gOriginalTTYAttrs;
cfmakeraw(&options);
options.c_cflag = (CREAD | CLOCAL | CS8);
options.c_lflag = 0;
options.c_iflag = 0;
options.c_oflag = 0;
options.c_cc[ VMIN ] = 1;
options.c_cc[ VTIME ] = 0;
cfsetospeed(&options,initialBaud);
cfsetispeed(&options,initialBaud);
// Set the options
if (tcsetattr(newFileDescriptor, TCSANOW, &options) == -1)
{
SioControllerLogPrint("openSerialPort - Error setting tty attributes %s - %s(%d).\n",
bsdPath, strerror(errno), errno);
goto error;
}
// Success
return newFileDescriptor;
// Failure path
error:
if (newFileDescriptor != -1)
close(newFileDescriptor);
return -1;
}
// Given the file descriptor for a serial device, close that device.
- (void) closeSerialPort: (int) descriptor: (BOOL) reset
{
if (reset) {
if (tcsetattr(fileDescriptor, TCSANOW, &gOriginalTTYAttrs) == -1)
{
SioControllerLogPrint("closeSerialPort - Error resetting tty attributes - %s(%d).\n",
strerror(errno), errno);
}
}
close(descriptor);
}
// Set the speed on a serial port
- (void) setSerialPortSpeed: (int) descriptor : (int) speed
{
struct termios options;
speed_t portSpeed;
// Get the current options and save them for later reset
if (tcgetattr(descriptor, &options) == -1)
{
SioControllerLogPrint("setSerialPortSpeed - Error getting tty attributes - %s(%d).\n",
strerror(errno), errno);
return;
}
switch(speed) {
case 0:
SioControllerLogPrint("Setting serial port speed to 600\n");
[[MediaManager sharedInstance] performSelectorOnMainThread:@selector(displaySpeed:)
withObject:[NSNumber numberWithInt:600] waitUntilDone:NO];
portSpeed = B600;
break;
case 1:
default:
SioControllerLogPrint("Setting serial port speed to 19200\n");
[[MediaManager sharedInstance] performSelectorOnMainThread:@selector(displaySpeed:)
withObject:[NSNumber numberWithInt:19200] waitUntilDone:NO];
portSpeed = B19200;
break;
case 2:
SioControllerLogPrint("Setting serial port speed to 38400\n");
[[MediaManager sharedInstance] performSelectorOnMainThread:@selector(displaySpeed:)
withObject:[NSNumber numberWithInt:38400] waitUntilDone:NO];
portSpeed = B38400;
break;
case 3:
SioControllerLogPrint("Setting serial port speed to 57600\n");
[[MediaManager sharedInstance] performSelectorOnMainThread:@selector(displaySpeed:)
withObject:[NSNumber numberWithInt:57600] waitUntilDone:NO];
portSpeed = B57600;
break;
}
cfsetospeed(&options,portSpeed);
cfsetispeed(&options,portSpeed);
if (tcsetattr(descriptor, TCSAFLUSH, &options) == -1)
{
SioControllerLogPrint("setSerialPortSpeed - Error resetting tty attributes - %s(%d).\n",
strerror(errno), errno);
}
tcflush(descriptor ,TCIFLUSH); /* Clear out garbage */
currentSpeed = speed;
}
- (UInt8) checksum: (UInt8 *) buffer: (UInt32) count
{
UInt16 sum = 0;
UInt32 i;
for (i=0;i<count;i++)
sum =((sum+buffer[i]) >> 8) + ((sum+buffer[i]) & 0xFF);
return((UInt8) sum);
}
- (void) writeBlocks:(UInt8 *) buffer: (int) count: (int) blockSize
{
int left = count;
int xmitCount = blockSize;
while (left > 0)
{
if (left < blockSize)
xmitCount = left;
write(fileDescriptor,buffer,xmitCount);
left -= xmitCount;
buffer += xmitCount;
}
}
- (void) sendAck: (UInt8) c
{
write(fileDescriptor,&c,1);
tcdrain(fileDescriptor);
}
- (void) processDiskWriteCommand:(int) unit: (UInt8 *) cmd
{
UInt8 sectorBuff[257];
UInt32 sector = cmd[2] + 256*cmd[3];
int size;
int i;
if (driveState[unit-1] == DRIVE_POWER_OFF) {
SioControllerLogPrint("Disk %d Write sector %d - Error Drive Off\n",unit,(int) sector);
return;
}
[self microDelay:ACK_WAIT];
if (driveState[unit-1] == DRIVE_READ_ONLY ||
driveState[unit-1] == DRIVE_NO_DISK) {
[self sendAck:'N'];