-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathti_graph_link_silver.asm
3097 lines (2996 loc) · 54.2 KB
/
ti_graph_link_silver.asm
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
; Disassembly of TI silver Graph Link program data extracted from
; EEPROM connected to TUSB3410
; TUSB3410 contains 8052 microprocessor. The bootloader in ROM will
; Extract verify valid signature and program header and copy the program
; contents from EEPROM to RAM.
; Build with sdcc toolchain:
; $ make
; sdas8051 -lops ti_graph_link_silver.asm
; sdcc -mmcs51 --code-size 0x1400 ti_graph_link_silver.rel -o ti_graph_link_silver.hex
; makebin -p ti_graph_link_silver.hex ti_graph_link_silver.bin
; definitions of registers
OEPCNF_2 = 0xff10
OEPBBAX_2 = 0xff11
OEPBCTX_2 = 0xff12
OEPSIZXY_2 = 0xff17
IEPCNF_1 = 0xff48
IEPBBAX_1 = 0xff49
IEPBCTX_1 = 0xff4a
IEPSIZXY_1 = 0xff4f
IEPCNFG_0 = 0xff80
IEPBCNT_0 = 0xff81
OEPCNFG_0 = 0xff82
OEPBCNT_0 = 0xff83
WDCSR = 0xff93
VECINT = 0xff92
I2CSTA = 0xfff0
I2CDATO = 0xfff1
I2CADR = 0xfff3
USBCTL = 0xfffc
USBMSK = 0xfffd
USBSTA = 0xfffe
FUNADR = 0xffff
.area PSEG (PAG,XDATA)
;--------------------------------------------------------
; data
;--------------------------------------------------------
.area DSEG (DATA)
.word 0, 0, 0, 0, 0, 0, 0, 0
.word 0, 0, 0, 0, 0, 0, 0, 0
dat_20_start:
dat_20_end:
i2c_addr: ; 0x20
.byte 0
dat_21:
.byte 0
eeprom_addr:
.word 0
dat_24:
.word 0
dat_26:
.byte 0
dat_27: ; TODO: sometimes this is word, sometimes byte?
.word 0
.byte 0, 0, 0, 0, 0, 0, 0
.word 0, 0, 0, 0, 0
.byte 0
bss_start:
i2c_speed: ; 0x3b
.byte 0
.word 0
dat_3e:
.word 0
.word 0, 0, 0
.byte 0
dat_47:
.byte 0
.byte 0, 0, 0, 0, 0, 0
dat_4e:
.byte 0
.byte 0, 0, 0, 0
dat_53:
.byte 0
.byte 0, 0, 0, 0, 0
dat_59:
.byte 0
dat_5a:
.byte 0
dat_5b:
.byte 0
dat_5c:
.byte 0
dat_5d:
.byte 0
.byte 0, 0, 0, 0
bss_end:
data_start:
dat_62:
.word 0
dat_64:
.byte 0
dat_65:
.byte 0
.byte 0, 0
dat_68:
.byte 0
data_end:
stack_start:
;--------------------------------------------------------
; xdata
;--------------------------------------------------------
.area XSEG (XDATA)
xdat_0001:
;--------------------------------------------------------
; code
;--------------------------------------------------------
.area HOME (CODE)
; interrupt vector @ 0x0000
int_vec:
ljmp reset_isr ; 0x0000: Reset
ljmp exti_isr ; 0x0003: External Interrupt 0
nop
nop
nop
nop
nop
ljmp timer0_isr ; 0x000b: Timer-0 Interrupt
;--------------------------------------------------------
; code
;--------------------------------------------------------
.area CSEG (CODE)
reset_isr: ; 0x000e
mov sp, #stack_start-1
lcall fcn_02c9
mov a, r4
orl a, r5
jz lbl_0082
mov r0, #bss_end-1
sjmp lbl_001f
lbl_001c:
mov @r0, #0x00
dec r0
lbl_001f:
cjne r0, #bss_start, lbl_001c
mov r0, #0x1f
sjmp lbl_0029
lbl_0026:
mov @r0, #0x00
dec r0
lbl_0029:
cjne r0, #0x1f, lbl_0026
mov r0, #0x1f
sjmp lbl_0033
lbl_0030:
mov @r0, #0x00
dec r0
lbl_0033:
cjne r0, #0x1f, lbl_0030
mov dptr, #0x0001
mov r6, dph
mov r7, dpl
mov dptr, #0x0001
lbl_0040:
lcall ptr_equal
jz lbl_004a
clr a
movx @dptr, a
inc dptr
sjmp lbl_0040
lbl_004a:
mov dptr, #0x0001
mov r0, dpl
mov dptr, #0x0001
mov r1, dpl
lbl_0054:
mov a, r0
clr c
subb a, r1
jnc lbl_005e
mov @r0, #0x00
inc r0
sjmp lbl_0054
lbl_005e:
mov dptr, #cdat_00e9
lcall data_copy
mov dptr, #cdat_00ed
lcall data_copy
mov dptr, #cdat_00f1
lcall data_copy
mov dptr, #cdat_00f5
lcall xdata_copy
mov dptr, #cdat_00fb
lcall xdata_copy
mov dptr, #cdat_0101
lcall xdata_copy
lbl_0082:
mov psw, #0x00
lcall fcn_042f
ljmp loop_forever
; return 0 if (r7 == dpl) && (r6 == dph)
; else return non-zero
ptr_equal: ; 008b
mov a, r7
xrl a, dpl
jnz lbl_0093
mov a, r6
xrl a, dph
lbl_0093:
ret
; memcpy-like
; input: dptr (code) points to array of 3 pointers
; uint8 dest_start (data)
; uint8 dest_end (data)
; uint16 source (code)
data_copy: ; 0094
clr a
movc a, @a+dptr
mov r0, a ; r0 = dest_start
mov a, #0x01
movc a, @a+dptr
mov r1, a ; r1 = dest_end
mov a, #0x02
movc a, @a+dptr
mov r6, a
mov a, #0x03
movc a, @a+dptr
mov dpl, a
mov dph, r6 ; dptr = source
lbl_00a6:
mov a, r0
xrl a, r1
jnz lbl_00ab ; if r0 == r1, return
ret
lbl_00ab:
clr a
movc a, @a+dptr ; a = *src
mov @r0, a ; *dst = a
inc dptr ; src++
inc r0 ; dst++
sjmp lbl_00a6
; memcpy-like
; input: dptr (code) points to array of 3 16-bit pointers
; ptr[0] = dest (xdata)
; ptr[1] = source_end (code)
; ptr[2] = source_start (code)
xdata_copy:
clr a
movc a, @a+dptr
mov r4, a ; r4 = dest.l
mov a, #0x01
movc a, @a+dptr
mov r5, a ; r5 = dest.h
mov a, #0x02
movc a, @a+dptr
mov r6, a ; r6 = source_end.l
mov a, #0x03
movc a, @a+dptr
mov r7, a ; r7 = source_end.h
mov a, #0x04
movc a, @a+dptr
mov r0, a
mov a, #0x05
movc a, @a+dptr
mov dpl, a
mov dph, r0 ; dptr = source_start
lbl_00cc:
lcall ptr_equal
jnz lbl_00d2 ; if source == source_end, return
ret
lbl_00d2:
clr a
movc a, @a+dptr ; a = *src
inc dptr ; dptr++
mov r0, dph
mov r1, dpl ; r0, r1 = dptr (src += 1)
mov dph, r4
mov dpl, r5
movx @dptr, a ; *dest = a
inc dptr
mov r4, dph
mov r5, dpl
mov dph, r0
mov dpl, r1 ; dptr = r0, r1
sjmp lbl_00cc
cdat_00e9:
.byte dat_20_start, dat_20_end
.word cdat_027e
cdat_00ed:
.byte dat_20_start, dat_20_end
.word cdat_027e
cdat_00f1:
.byte data_start, data_end
.word cdat_027e
cdat_00f5:
.word xdat_0001, cdat_0285_start, cdat_0285_end
cdat_00fb:
.word xdat_0001, cdat_0285_start, cdat_0285_end
cdat_0101:
.word xdat_0001, cdat_02c9_start, cdat_02c9_end
loop_forever: ; 0107
sjmp loop_forever
; jump table lookup
; dptr: points to jump table
; format: u16 jump_addr, u8 value
; a: value to compare
exti_isr_jmp_table_lookup: ; 0109
pop dph
pop dpl
mov b, a
lbl_010f:
clr a
movc a, @a+dptr
jnz lbl_011c
mov a, #0x01
movc a, @a+dptr
jnz lbl_011c
inc dptr
inc dptr
sjmp lbl_0128
lbl_011c:
mov a, #0x02
movc a, @a+dptr
xrl a, b
jz lbl_0128
inc dptr
inc dptr
inc dptr
sjmp lbl_010f
lbl_0128:
mov a, #0x01
movc a, @a+dptr
push acc
clr a
movc a, @a+dptr
push acc
ret
; inputs: r5, r6, r7
; output: a
fcn_0132:
lcall fcn_01ef ; a = fcn_01ef(r5, r6, r7)
ljmp lbl_0138
lbl_0138:
jnb acc.0, lbl_0142
jb acc.3, lbl_0140
mov a, @r0 ; if (a == 0x01) return *r0;
ret
lbl_0140:
mov a, @r1 ; else if (a == 0x09) return *r1;
ret
lbl_0142:
jnb acc.1, lbl_014c
jb acc.3, lbl_014a
movx a, @r0 ; else if (a == 0x02) return *(xdat)r0;
ret
lbl_014a:
movx a, @r1 ; else if (a == 0x0a) return *(xdat)r1;
ret
lbl_014c:
jnb acc.2, lbl_0151
movx a, @dptr ; else if (a == 0x04) return *(xdat)dptr;
ret
lbl_0151:
clr a
movc a, @a+dptr ; else return *(cdat)dptr;
ret
fcn_0154:
lcall fcn_0213
ljmp lbl_015a
lbl_015a:
mov r3, b
lcall fcn_0164
xch a, r3
xch a, b
xch a, r3
ret
fcn_0164:
jnb acc.0, lbl_0177
jb acc.3, lbl_0170
mov a, @r0
mov b, a
inc r0
mov a, @r0 ; if (a == 0x01) return a, b = *(r0+1), *r0;
ret
lbl_0170:
mov a, @r1
mov b, a
inc r1
mov a, @r1
dec r1 ; else if (a == 0x09) return a, b = *(r1+1), *r1;
ret
lbl_0177:
jnb acc.1, lbl_018a
jb acc.3, lbl_0183
movx a, @r0
mov b, a
inc r0
movx a, @r0 ; else if (a == 0x02) return a, b = *(xdata)(r0+1), *(xdata)r0;
ret
lbl_0183:
movx a, @r1
mov b, a
inc r1
movx a, @r1
dec r1 ; else if (a == 0x0a) return a, b = *(xdata)(r1+1), *(xdata)r1;
ret
lbl_018a:
jnb acc.2, lbl_0193
movx a, @dptr
mov b, a
inc dptr
movx a, @dptr ; else if (a == 0x04) return a, b = *(xdata)(dptr+1), *(xdata)dptr;
ret
lbl_0193:
clr a
movc a, @a+dptr
mov b, a
mov a, #0x01
movc a, @a+dptr ; else return a, b = *(cdat)(dptr+1), *(cdat)dptr;
ret
; inputs: r1, r2, r3
; return: a
; fcn_019b(r1, r2, r3) {
; switch (r3) {
; case 0x00:
; return 0x09;
; case 0x01:
; dptr = r2, r1;
; return 0x04;
; case 0x02:
; dptr = r2, r1;
; return 0x10;
; default:
; return 0x0a;
; }
fcn_019b:
cjne r3, #0x00, lbl_01a1
mov a, #0x09
ret
lbl_01a1:
cjne r3, #0x01, lbl_01ab
mov dpl, r1
mov dph, r2
mov a, #0x04
ret
lbl_01ab:
cjne r3, #0x02, lbl_01b5
mov dpl, r1
mov dph, r2
mov a, #0x10
ret
lbl_01b5:
mov a, #0x0a
ret
ljmp fcn_unused_01bb ; TODO: why?
; inputs: r1, r2, r3, dptr
; outputs: a, r0, dptr
; fcn_unused_01bb() {
; switch (r3) {
; case 0x00:
; r0 = dpl + r1;
; return 0x01;
; case 0x01:
; dptr += r2, r1;
; return 0x04;
; case 0x02:
; dptr += r2, r1;
; return 0x10;
; default:
; r0 = dpl + r1;
; return 0x0a;
; }
fcn_unused_01bb:
cjne r3, #0x00, lbl_01c5
mov a, r1
add a, dpl
mov r0, a
mov a, #0x01
ret
lbl_01c5:
cjne r3, #0x01, lbl_01d5
mov a, r1
add a, dpl
mov dpl, a
mov a, r2
addc a, dph
mov dph, a
mov a, #0x04
ret
lbl_01d5:
cjne r3, #0x02, lbl_01e5
mov a, r1
add a, dpl
mov dpl, a
mov a, r2
addc a, dph
mov dph, a
mov a, #0x10
ret
lbl_01e5:
mov a, r1
add a, dpl
mov r0, a
mov a, #0x02
ret
ljmp fcn_01ef ; TODO: why?
; switch (r7) {
; case 0: r0 = r5; a = 1; break;
; case 1: dptr = r5, r6; a = 4; break;
; case 2: dptr = r5, r6; a = 16; break;
; default: r0 = r5; a = 2; break;
; }
fcn_01ef:
cjne r7, #0x00, lbl_01f7
mov a, r5
mov r0, a
mov a, #0x01
ret
lbl_01f7:
cjne r7, #0x01, lbl_0201
mov dpl, r5
mov dph, r6
mov a, #0x04
ret
lbl_0201:
cjne r7, #0x02, lbl_020b
mov dpl, r5
mov dph, r6
mov a, #0x10
ret
lbl_020b:
mov a, r5
mov r0, a
mov a, #0x02
ret
ljmp fcn_0213 ; TODO: why?
; inputs: r7, r5, r6, dpl, dph
; switch (r7) {
; case 0x00:
; r0 = r5 + dpl;
; a = 0x01;
; return;
; case 0x01:
; dpl = r5 + dpl;
; dph = r6 + dph;
; a = 0x04;
; return;
; case 0x02:
; dpl = r5 + dpl;
; dph = r6 + dph;
; a = 0x10;
; return;
; default:
; r0 = r5 + dpl;
; a = 0x02;
; return;
; }
fcn_0213:
cjne r7, #0x00, lbl_021d
mov a, r5
add a, dpl
mov r0, a
mov a, #0x01
ret
lbl_021d:
cjne r7, #0x01, lbl_022d
mov a, r5
add a, dpl
mov dpl, a
mov a, r6
addc a, dph
mov dph, a
mov a, #0x04
ret
lbl_022d:
cjne r7, #0x02, lbl_023d
mov a, r5
add a, dpl
mov dpl, a
mov a, r6
addc a, dph
mov dph, a
mov a, #0x10
ret
lbl_023d:
mov a, r5
add a, dpl
mov r0, a
mov a, #0x02
ret
ljmp fcn_unused_0247 ; TODO: why?
fcn_unused_0247:
push acc
lcall fcn_019b
ljmp lbl_024f
lbl_024f:
jnb acc.0, lbl_025d
jb acc.3, lbl_0259
pop acc
mov @r0, a
ret
lbl_0259:
pop acc
mov @r1, a
ret
lbl_025d:
jnb acc.1, lbl_026b
jb acc.3, lbl_0267
pop acc
movx @r0, a
ret
lbl_0267:
pop acc
movx @r1, a
ret
lbl_026b:
pop acc
movx @dptr, a
ret
; deref dptr from cdat
; dptr = *(u16 cdat*)dptr;
fcn_026f:
mov a, #0x01
movc a, @a+dptr
mov b, a
clr a
movc a, @a+dptr
mov dph, a
mov dpl, b
ret
; jump to dptr
fcn_027c:
clr a
jmp @a+dptr
cdat_027e:
.word 0x00fa
.byte 0x00, 0x00, 0x00, 0x00, 0x00
cdat_0285_start:
cdat_0285_end:
; jump table for fcn_064b
.word lbl_08fd, 0x0020
.word lbl_0663, 0x0021
.word lbl_06e5, 0x0027
.word lbl_072a, 0x002a
.word lbl_06f7, 0x0028
.word lbl_07cb, 0x0027
.word lbl_0807, 0x0028
.word lbl_07b3, 0x0027
.word lbl_07f5, 0x0027
.word lbl_0770, 0x0029
.word lbl_099d, 0x0020
.word lbl_08ac, 0x0020
.word lbl_08cb, 0x0020
.word lbl_0918, 0x0020
.word lbl_092c, 0x0021
.word lbl_0990, 0x0020
; jump for fcn_0b67
.word lbl_0bb1, 0x0029
cdat_02c9_start:
cdat_02c9_end:
; returns 0x01, 0x00
fcn_02c9:
mov r4, #0x01
mov r5, #0x00
ret
exti_isr: ; 02ce
push acc
push b
push dpl
push dph
push psw
mov a, r0
push acc
mov a, r1
push acc
mov a, r2
push acc
mov a, r3
push acc
mov a, r4
push acc
mov a, r5
push acc
mov a, r6
push acc
mov a, r7
push acc
mov dptr, #WDCSR
movx a, @dptr
orl a, #0x01 ; WDT: kick the watchdog
movx @dptr, a
mov dptr, #VECINT
movx a, @dptr
lcall exti_isr_jmp_table_lookup
; jump table
.word lbl_0328
.byte 0x14
.word lbl_031d
.byte 0x22
.word lbl_0346
.byte 0x32
.word lbl_0356
.byte 0x38
.word lbl_0367
.byte 0x3a
.word lbl_0378
.byte 0x3c
.word lbl_038c
.byte 0x3e
.word lbl_033c
.byte 0x44
.word lbl_0332
.byte 0x46
.word 0x0000 ; default case
.word lbl_03a4
lbl_031d: ; 0x22 = Input endpoint 1
lcall fcn_void_0b5c
clr a
mov dptr, #VECINT
movx @dptr, a
ljmp lbl_03aa
lbl_0328: ; 0x14 = Output endpoint 2
lcall fcn_0b5d
clr a
mov dptr, #VECINT
movx @dptr, a
sjmp lbl_03aa
lbl_0332: ; 0x46 = Output endpoint 0
lcall fcn_0b44
clr a
mov dptr, #VECINT
movx @dptr, a
sjmp lbl_03aa
lbl_033c: ; 0x44 = Input endpoint 0
lcall fcn_0b2c
clr a
mov dptr, #VECINT
movx @dptr, a
sjmp lbl_03aa
lbl_0346: ; 0x32 = SETUP packet received
lcall fcn_0ae0
mov a, #0x04
mov dptr, #USBSTA
movx @dptr, a
clr a
mov dptr, #VECINT
movx @dptr, a
sjmp lbl_03aa
lbl_0356: ; 0x38 = RESR interrupt
mov r0, #dat_64
mov @r0, #0x00
mov a, #0x20
mov dptr, #USBSTA
movx @dptr, a
clr a
mov dptr, #VECINT
movx @dptr, a
sjmp lbl_03aa
lbl_0367: ; 0x3a = SUSR interrupt
mov r0, #dat_64
mov @r0, #0x01
mov a, #0x40
mov dptr, #USBSTA
movx @dptr, a
clr a
mov dptr, #VECINT
movx @dptr, a
sjmp lbl_03aa
lbl_0378: ; 0x3c = RSTR interrupt
mov r0, #dat_64
mov @r0, #0x00
lcall fcn_048e
mov a, #0x80
mov dptr, #USBSTA
movx @dptr, a
clr a
mov dptr, #VECINT
movx @dptr, a
sjmp lbl_03aa
lbl_038c: ; 0x3e = Wakeup
mov r0, #dat_64
mov @r0, #0x00
mov a, #0x02
mov dptr, #USBSTA
movx @dptr, a
clr a
mov dptr, #VECINT
movx @dptr, a
mov dptr, #USBCTL
movx a, @dptr
orl a, #0x20
movx @dptr, a
sjmp lbl_03aa
lbl_03a4: ; default
mov a, #0xff
mov dptr, #VECINT
movx @dptr, a
lbl_03aa:
mov dptr, #WDCSR
movx a, @dptr
orl a, #0x01 ; WDT: kick the watchdog
movx @dptr, a
pop acc
mov r7, a
pop acc
mov r6, a
pop acc
mov r5, a
pop acc
mov r4, a
pop acc
mov r3, a
pop acc
mov r2, a
pop acc
mov r1, a
pop acc
mov r0, a
pop psw
pop dph
pop dpl
pop b
pop acc
reti
; Timer-0 Interrupt Handler
; * kicks watchdog
; * reloads 0xF830 into th0/tl0
; * decrements 0x63, if 0, reload 0xfa and decrement dat_62
timer0_isr:
push acc
push dpl
push dph
mov a, r0
push acc
mov dptr, #WDCSR
movx a, @dptr
orl a, #0x01 ; WDT: kick the watchdog
movx @dptr, a
mov th0, #0xf8 ; TH0: Timer0 high
mov tl0, #0x30 ; TL0: Timer0 low
mov r0, #dat_62
mov a, @r0
jnz lbl_03f9
pop acc
mov r0, a
pop dph
pop dpl
pop acc
reti
lbl_03f9:
mov r0, #0x63
dec @r0
mov r0, #0x63
mov a, @r0
jnz lbl_0408
mov r0, #0x63
mov @r0, #0xfa
mov r0, #dat_62
dec @r0
lbl_0408:
pop acc
mov r0, a
pop dph
pop dpl
pop acc
reti
initialize_hardware: ; 0412
clr ie.7 ; EA: disable all interrupts
lcall usb_init
mov r4, #0x01
lcall i2c_set_bus_speed
anl tmod, #0xf0 ; TMOD: timer mode
orl tmod, #0x01 ; TMOD: Timer0 = 16-bit
mov th0, #0xf8 ; TH0: Timer0 high
mov tl0, #0x30 ; TL0: Timer0 low
clr tcon.5 ; TF0: Timer0 overflow flag
setb tcon.4 ; TR0: Timer0 run control bit
setb ie.1 ; ET0: Timer0 interrupt enable
ret
fcn_042f:
mov dptr, #WDCSR
movx a, @dptr
orl a, #0x01 ; WDT: kick the watchdog
movx @dptr, a
setb p3.3
setb p3.4
lcall initialize_hardware
setb ie.7 ; EA: enable all interrupts
setb ie.0 ; EX0: external interrupt 0 enable
mov dptr, #USBCTL
movx a, @dptr
orl a, #0x80
movx @dptr, a
lbl_0448: ; while (dat_65 != 0x02) {
mov r0, #dat_65
mov a, @r0
xrl a, #0x02
jz lbl_0451
sjmp lbl_0448 ; }
lbl_0451:
lcall fcn_0d90
mov r0, #dat_5c
mov a, @r0
jnz lbl_045e
mov r0, #dat_5b
mov a, @r0
jz lbl_0474
lbl_045e:
mov r0, #dat_5c
mov a, @r0
mov r0, #dat_5b
orl a, @r0
mov r1, #dat_53
mov r4, a
mov a, @r1
orl a, r4
mov r0, #dat_53
mov @r0, a
mov r0, #dat_5c
mov @r0, #0x00
mov r0, #dat_5b
mov @r0, #0x00
lbl_0474:
mov r0, #dat_64
mov a, @r0
dec a
jnz lbl_048b
mov dptr, #WDCSR
movx a, @dptr
orl a, #0x01 ; WDT: kick the watchdog
movx @dptr, a
orl pcon, #0x01
mov dptr, #WDCSR
movx a, @dptr
orl a, #0x01 ; WDT: kick the watchdog
movx @dptr, a
lbl_048b:
sjmp lbl_0448
ret