-
Notifications
You must be signed in to change notification settings - Fork 1
/
24C04-1.asm
781 lines (778 loc) · 18.1 KB
/
24C04-1.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
ORG #8000
;------------------------------------
; Program For Read/Write EEPROM 24C02
; PA0=SDA (Data) (#1F)
; PB0=SCL (Clock) (#3F)
;------------------------------------
;1C CLS
;1D Set X
;1E Set X,Y
;1F Fill Sym,Num
;FF Inverse
;-----------------
SDA EQU #1F
SCL EQU #3F
PORTSET EQU #7F
ACKTIME EQU #F000
PTIME EQU #01
BORDER2 EQU 2
BORDER EQU 0
;
DI
LD A,BORDER
OUT (#FE),A
LD A,#80
OUT (PORTSET),A
LD A,#FF
OUT (SCL),A
OUT (SDA),A
;
CALL PRI_T
DEFB #1C,#FF
DEFB " Driver For Read/Write on I2C Bus ",#FF
DEFB " Copyright 2000 By (R)soft",13
DEFB 0
;
;=========== Read Sequence of Bytes From Adr ========
LD A,#A6
LD (DEVADR),A
LD A,0 ;Addr EEPROM
LD HL,#C000 ;Read To
LD DE,#100 ;How Many
; CALL RND_READ
; RET C
;----- Read & Dump Bytes ----
CALL NNN
LD A,B
CALL PRIHB
LD A,0 ;Addr EEPROM
LD B,#20 ;How Many
LD C,2 ;Koord Y
CALL PRINTBT
; CALL LLL
EI
RET
;------- Dump Memory ------
LD HL,#C000
LD BC,#100
LD A,2 ;Koord Y
CALL PRINTB
CALL MMM
EI
RET
CALL PRESSP
LD HL,#C100
LD BC,#100
LD A,2
CALL PRINTB
EI
RET
;========== Read From EEPROM =============
LD HL,#C000 ;Read To
LD DE,#100 ;How Many
CALL READ
RET
;========== Read One Byte From EEPROM ========
MMM
LD A,#00 ;Adr EEPROM
CALL READBYTE
RET C
CALL PRIHB
LD A,#C0
CALL READBYTE
RET C
CALL PRIHB
; CALL NNN
EI
RET
;========== Write One Byte To EEPROM ==========
NNN
LD B,16
LD A,0
LD (NNNA),A
NNN1
PUSH BC
LD A,0 ;Adr EEPROM
NNNA EQU $-1
LD C,#04 ;Byte To Write
CALL WRITEBYTE
JR C,NNNE
LD A,(NNNA)
CALL READBYTE
NNNE
POP BC
RET C
LD HL,NNNA
INC (HL)
DJNZ NNN1
LD A,#00
CALL READBYTE
CALL PRIHB
RET
;
LD A,#C8
LD C,#55
CALL WRITEBYTE
LD A,#C8
CALL READBYTE
CALL PRIHB
RET
;========== Write Sequence of Bytes From Adr ========
LLL
LD A,#00 ;To Adr EEPROM
LD HL,#7FF0 ;From MEMORY
LD DE,#10 ;How Many (Maximum 8)
CALL RND_WRITE
RET
RND_READ
LD (POINTAD),A
;
CALL START
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
LD A,1 ;!1
CALL GETACK
JP C,NOACK
LD A,0 ;ADR EEPROM
POINTAD EQU $-1
CALL PUTBYTE
LD A,2 ;!2
CALL GETACK
JP C,NOACK
;
CALL START
LD A,(DEVADR)
SET 0,A ;Read Mode
CALL PUTBYTE
LD A,3 ;!3
CALL GETACK
JP C,NOACK
DEC DE
LOOPRDM
CALL GETBYTE
LD (HL),A
INC HL ;!!!
CALL GIVEACK
DEC DE
LD A,E
OR D
JR NZ,LOOPRDM
CALL GETBYTE
LD (HL),A
CALL GIVENACK
CALL STOP
AND A
RET
READBYTE
LD (POINT1),A
;
CALL START
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
LD A,4 ;!4
CALL GETACK
JP C,NOACK
LD A,0 ;ADR EEPROM
POINT1 EQU $-1
CALL PUTBYTE
LD A,5 ;!5
CALL GETACK
JP C,NOACK
;
CALL START
LD A,(DEVADR)
SET 0,A ;Read Mode
CALL PUTBYTE
LD A,6 ;!6
CALL GETACK
JP C,NOACK
CALL GETBYTE
CALL GIVENACK
CALL STOP
AND A
RET
READ
CALL START
LD A,(DEVADR)
SET 0,A ;Read Mode
CALL PUTBYTE
LD A,7 ;!7
CALL GETACK
JR C,NOACK
DEC DE
LOOPRD
CALL GETBYTE
LD (HL),A
INC HL
CALL GIVEACK
DEC DE
LD A,E
OR D
JR NZ,LOOPRD
CALL GETBYTE
LD (HL),A
CALL GIVENACK
CALL STOP
AND A
RET
NOACK
PUSH AF
CALL PRI_T
DEFB "Error ",0
POP AF
CALL DEC99
CALL PRI_T
DEFB "! No ACKNOWLEDGE Signal",0
SCF
RET
WRITEBYTE
LD (POINT2),A
LD A,C
LD (WBYTE),A
;
CALL START
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
LD A,8 ;!8
CALL GETACK
JP C,NOACK
;
LD A,0 ;ADR EEPROM
POINT2 EQU $-1
CALL PUTBYTE
LD A,9 ;!9
CALL GETACK
JP C,NOACK
;
LD A,0
WBYTE EQU $-1
CALL PUTBYTE
LD A,10 ;!10
CALL GETACK
JP C,NOACK
CALL STOP
AND A
RET
;
CALL START ;Check Writing Byte
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
LD A,11 ;!11
CALL GETACK
JP C,NOACK
LD A,(POINT2) ;ADR EEPROM
CALL PUTBYTE
LD A,12 ;!12
CALL GETACK
JP C,NOACK
;
CALL START
LD A,(DEVADR)
SET 0,A ;Read Mode
CALL PUTBYTE
LD A,13 ;!13
CALL GETACK
JP C,NOACK
CALL GETBYTE
CALL GIVENACK
CALL STOP
LD HL,WBYTE
CP (HL)
JR NZ,ERRWRI
AND A
RET
ERRWRI
CALL PRI_T
DEFB "Error 17! Illegal Writing To Memory!",13,0
SCF
RET
RND_WRITE
LD (POINT3),A
;
CALL START
LD A,(DEVADR)
RES 0,A ;Write Mode
CALL PUTBYTE
LD A,14 ;!14
CALL GETACK
JP C,NOACK
;
LD A,0 ;ADR EEPROM
POINT3 EQU $-1
CALL PUTBYTE
LD A,15 ;!15
CALL GETACK
JP C,NOACK
RNDWR
LD A,(HL)
INC HL
CALL PUTBYTE
LD A,16 ;!16
CALL GETACK
JP C,NOACK
DEC DE
LD A,E
OR D
JR NZ,RNDWR
;
CALL STOP
AND A
RET
PRINTB
LD (PRINTBY),A
PUSH BC
PUSH HL
CALL SHAP
POP HL
PUSH HL
CALL PRIHEX
LD A,":"
CALL PRIA
LD A," "
CALL PRIA
POP HL
POP BC
PRINTB1
LD A,(HL)
INC HL
PUSH BC
PUSH HL
CALL PRIHB
LD A," "
CALL PRIA
LD A,(TMPX)
CP 48+6
JR C,NOEN
CALL PRI_T
DEFB 13,0
POP HL
PUSH HL
CALL PRIHEX
LD A,":"
CALL PRIA
LD A," "
CALL PRIA
NOEN
POP HL
POP BC
DEC BC
LD A,C
OR B
JR NZ,PRINTB1
RET
PRINTBT
LD (PBTA),A
LD A,C
LD (PRINTBY),A
PUSH BC
CALL SHAP
CALL PRI_T
DEFB " ",0
LD A,(PBTA)
CALL PRIHB
CALL PRI_T
DEFB ": ",0
POP BC
PRINTBT1
PUSH BC
LD A,0
PBTA EQU $-1
CALL READBYTE
CALL PRIHB
LD HL,PBTA
INC (HL)
LD A," "
CALL PRIA
LD A,(TMPX)
CP 48+4
JR C,NOENBT
CALL PRI_T
DEFB 13," ",0
LD A,(PBTA)
CALL PRIHB
CALL PRI_T
DEFB ": ",0
NOENBT
POP BC
DJNZ PRINTBT1
RET
SHAP
CALL PRI_T
DEFB #1E,0,2
PRINTBY EQU $-1
DEFB "Addr| +0 +1 +2 +3 +4 +5 +6 +7 +8 "
DEFB "+9 +A +B +C +D +E +F",13
DEFB #1F,"-",53,13,0
RET
GIVEACK
PUSH AF
XOR A
OUT (SDA),A ;SDA -> 0
CALL PAUSE
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
XOR A
OUT (SCL),A ;SCL -> 0
CALL PAUSE
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
POP AF
RET
GIVENACK
PUSH AF
XOR A
OUT (SDA),A ;SDA -> 0
CALL PAUSE
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
POP AF
RET
GETACK
PUSH AF
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
OUT (SCL),A ;SCL -> 1
CALL PAUSE
LD BC,ACKTIME
GETA1
DEC BC ;Counter of Wait
LD A,C
OR B
JR Z,GETERR
IN A,(SDA) ;Wait To SDA=0
BIT 0,A
JR NZ,GETA1
POP AF
XOR A
OUT (SCL),A ;SCL -> 0
CALL PAUSE
RET
GETERR
POP AF
CALL STOP
SCF ;Set CARRY -> NO ACK
RET
PAUSEDE
DEC DE
LD A,E
OR D
JR NZ,PAUSEDE
RET
GETBYTE
LD B,8
GETBL
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
IN A,(SDA)
RRA
RL C
XOR A
OUT (SCL),A ;SCL -> 0
CALL PAUSE
DJNZ GETBL
;
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
LD A,C
RET
PUTBYTE
LD B,8
PUTBL
RLA
PUSH AF
LD A,#FF
JR C,PUTB1
LD A,0
PUTB1
OUT (SDA),A
CALL PAUSE
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
LD A,0
OUT (SCL),A ;SCL -> 0
CALL PAUSE
POP AF
DJNZ PUTBL
;
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
RET
START
PUSH AF
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
XOR A
OUT (SDA),A ;SDA -> 0
CALL PAUSE
OUT (SCL),A ;SCL -> 0
CALL PAUSE
LD A,#FF
OUT (SDA),A ;SDA -> 1
CALL PAUSE
POP AF
RET
STOP
PUSH AF
XOR A
OUT (SDA),A ;SDA -> 0
CALL PAUSE
LD A,#FF
OUT (SCL),A ;SCL -> 1
CALL PAUSE
OUT (SDA),A ;SDA -> 1
CALL PAUSE
POP AF
RET
PAUSE
PUSH AF
LD A,BORDER2
OUT (#FE),A
PUSH BC
LD B,PTIME
DJNZ $
POP BC
LD A,BORDER
OUT (#FE),A
POP AF
RET
PRESSP LD A,#7F
IN A,(#FE)
RRA
JR C,PRESSP
RET
;
PRI_T POP HL
CALL PRI_BB
JP (HL)
PRI_BB LD A,(HL)
INC HL
AND A
RET Z ;0 - Exit
CP 13
JR NZ,PRI_BB0
EX DE,HL
LD HL,TMPX
LD (HL),0
INC HL
LD A,(HL)
CP 23
JR Z,PRIBB0
INC (HL)
PRIBB0
CALL KOOR_Y
JR PRI_BB
PRI_BB0 CP #FF ;Inverse
JR NZ,PRI_BB1
LD A,(INVERSE)
XOR #FF
LD (INVERSE),A
JR PRI_BB
PRI_BB1 CP #20
JR C,PRI_BB2 ;<#20 - Attr Code
PUSH HL
CALL PRIA
POP HL
JR PRI_BB
PRI_BB2 CP #1F ;Fill
JR NZ,PRI_BB3
LD A,(HL) ;Symbol Fill
INC HL
LD B,(HL) ;Num Fill
INC HL
PUSH HL
PRI_BB4 PUSH BC
PUSH AF
CALL PRIA
POP AF
POP BC
DJNZ PRI_BB4
POP HL
JR PRI_BB
PRI_BB3 CP #1E ;Set Koord
JR NZ,PRI_BB5
LD E,(HL)
INC HL
LD D,(HL)
INC HL
LD (TMPX),DE
EX DE,HL
CALL KOOR_Y
JR PRI_BB
PRI_BB5 CP #1D ;Set X Koor
JR NZ,PRI_BB6
LD A,(HL)
INC HL
LD (TMPX),A
JR PRI_BB
PRI_BB6 CP #1C ;Clear Screen
JR Z,PRI_BB7
LD C,A ;1-#1B Add X Koor
LD A,(TMPX) ;(Without #0D)
ADD A,C
LD (TMPX),A
JR PRI_BB
PRI_BB7 PUSH HL
CALL CLSCR
LD HL,0
LD (TMPX),HL
CALL KOOR_Y
POP HL
JP PRI_BB
DEC99 LD C,A ;Decimal 0-99
LD B,0 ;A - Byte
LD HL,FPRIA
LD (#5C51),HL
JP #1A1B
FPRIA DEFW PRIA
PRIHEX LD A,H
PUSH HL
CALL PRIHB
POP HL
LD A,L
PRIHB PUSH AF
RRCA
RRCA
RRCA
RRCA
CALL PRITET
POP AF
PRITET AND #0F
ADD A,#90
DAA
ADC A,#40
DAA
;==============================
PRIA LD E,A ;Symbols Print
LD A,(TMPX)
LD C,A
SRL A
LD HL,0
FOADRS EQU $-2
ADD A,L
LD L,A
LD A,C
RRA
LD D,FONT/256
LD C,0
INVERSE EQU $-1
LD B,#0F
JR C,NOCHET
LD B,#F0
NOCHET LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
INC H
INC D
LD A,(DE)
XOR C
XOR (HL)
AND B
XOR (HL)
LD (HL),A
LD HL,TMPX
INC (HL)
INC HL
RET
KOOR_Y LD H,TABSCR/256
LD A,(TMPY)
ADD A,A
LD L,A
LD A,(HL)
INC HL
LD H,(HL)
LD L,A
LD (FOADRS),HL
EX DE,HL
RET
CLSCR LD HL,#4000
LD E,L
LD D,H
INC DE
LD (HL),L
LD BC,#17FF
LDIR
INC DE
INC HL
LD (HL),7
LD BC,#2FF
LDIR
RET
DEVADR DEFB #A6 ;Address of Device EEPROM 24C02
TMPX DEFB 0
TMPY DEFB 0
;
;
ORG #B700
TABSCR DEFW #4000,#4020,#4040,#4060,#4080,#40A0
DEFW #40C0,#40E0,#4800,#4820,#4840,#4860
DEFW #4880,#48A0,#48C0,#48E0,#5000,#5020
DEFW #5040,#5060,#5080,#50A0,#50C0,#50E0
;
ORG #B800
FONT
; .INCBIN FONT
.RUN #8000