-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd_text_editor.a
1803 lines (1446 loc) · 71.8 KB
/
lcd_text_editor.a
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
;;-----------------------------------------------------------------------------------------
;; frisc-pynq-system
;;
;; sve informacije o načinima spajanja i definicijama ulazno/izlaznih jedinica možete
;; pročitati u dokumentu:
;; /pynq-lab-starter/docs/pynq-frisc-system.pdf
;;
;; sve informacije o programiranju i konfiguriranju pynq pločice možete pročitati u dokumentu:
;; /pynq-lab-starter/docs/upute-za-programiranje.pdf
;;
;; ovaj predložak ima predefinirani skup memorijskih adresa ui jedinica.
;; ui jedinice koje su postavljene u sustavu:
;; - 4 ledice i 2 rgb ledice
;; - 4 dugmića i 2 prekidača
;; - 2 x 8bit gpio (jedan ulazni i jedan izlazni)
;; - 2 x uart kontrolera (za bluetooth ili seriju)
;; - kontroler za i2c
;; - kontroler za SPI
;;
;; za sva pitanja možete se obratiti na:
;;
;;-----------------------------------------------------------------------------------------
;;
;; Projekt izradili: Marko Lazarić([email protected]) i Tin Blažević([email protected])
;;
;; Kod za komunikaciju s LCD-om i crtanje pravokutnika je preuzet iz prošlogodišnjeg
;; projekta "lcd-pong".
;;
;; Dodatne informacije, slike i upute: https://github.com/mlazaric/FRISC-PYNQ-LCD
;; Alternativni link: https://github.com/TinBlazevic/FRISC-PYNQ-LCD
;;-----------------------------------------------------------------------------------------
;; adrese ulazno/izlaznih jedinica
GPIO0_LEDICE EQU 0FFF80000
GPIO0_RGB EQU 0FFF80008
GPIO1_SWITCHES EQU 0FFF81000
GPIO1_BUTTONS EQU 0FFF81008
GPIO1_ISR EQU 0FFF81120
GPIO1_GIER EQU 0FFF8111C
GPIO1_IER EQU 0FFF81128
GPIO2_INPUT EQU 0FFF82000
GPIO2_OUTPUT EQU 0FFF82008
GPIO2_ISR EQU 0FFF82120
GPIO2_GIER EQU 0FFF8211C
GPIO2_IER EQU 0FFF82128
UART0_RX EQU 0FFF83000
UART0_TX EQU 0FFF83004
UART0_STAT EQU 0FFF83008
UART0_CTRL EQU 0FFF8300C
UART1_RX EQU 0FFF84000
UART1_TX EQU 0FFF84004
UART1_STAT EQU 0FFF84008
UART1_CTRL EQU 0FFF8400C
I2C_GIE EQU 0FFF8501C ; i2c global interrupt enable register
I2C_ISR EQU 0FFF85020 ; i2c interrupt status register
I2C_IER EQU 0FFF85028 ; i2c interrupt enable register
I2C_CR EQU 0FFF85100 ; i2c control register
I2C_SR EQU 0FFF85104 ; i2c status register
I2C_TX_FIFO EQU 0FFF85108 ; i2c transmit fifo
I2C_RX_FIFO EQU 0FFF8510C ; i2c recieve fifo
I2C_SA EQU 0FFF85110 ; i2c slave adress register (adresa na kojoj ce se odazivati - slave mode)
I2C_TX_FIFO_OCY EQU 0FFF85114 ; i2c transmit fifo occupancy 0 = 1 podatak, 1 = 2 podatka...
I2C_RX_FIFO_OCY EQU 0FFF85118 ; i2c recieve fifo occupancy 0 = 1 podatak, 1 = 2 podatka...
I2C_RX_FIFO_PIR EQU 0FFF85120 ; i2c rx fifo - nakon koliko podataka ce se napraviti interrupt, ondosno max velicina RX_FIFO-a
SPI_CR EQU 0FFF86060 ; SPI control register
SPI_SR EQU 0FFF86064 ; SPI status register
SPI_DTR EQU 0FFF86068 ; SPI data transmit register
SPI_DRR EQU 0FFF8606C ; SPI data receive register
SPI_SSR EQU 0FFF86070 ; SPI slave select register
SPI_GIER EQU 0FFF8601C ; SPI global interrupt enable register
SPI_IER EQU 0FFF86028 ; SPI interrupt enable register
SPI_ISR EQU 0FFF86020 ; SPI interrupt status register
TIMER0_CSR EQU 0FFF87000 ; timer 0 control and status register
TIMER0_LR EQU 0FFF87004 ; timer 0 load register
TIMER0_CR EQU 0FFF87008 ; timer 0 counter register
TIMER1_CSR EQU 0FFF87010 ; timer 1 control and status register
TIMER1_LR EQU 0FFF87014 ; timer 1 load register
TIMER1_CR EQU 0FFF87018 ; timer 1 counter register
INTC_NMI_ISR EQU 0FFF88000 ; interrupt status register
INTC_NMI_IAR EQU 0FFF8800C ; interrupt aknowledge register
INTC_NMI_SIE EQU 0FFF88010 ; set interrupt enable
INTC_NMI_CIE EQU 0FFF88014 ; clear interrupt enable
INTC_NMI_MER EQU 0FFF8801C ; master enable register
INTC_MI_ISR EQU 0FFF89000 ; interrupt status register
INTC_MI_IAR EQU 0FFF8900C ; interrupt aknowledge register
INTC_MI_SIE EQU 0FFF89010 ; set interrupt enable
INTC_MI_CIE EQU 0FFF89014 ; clear interrupt enable
INTC_MI_MER EQU 0FFF8901C ; master enable register
; lcd konstante
ILI9341_TFTWIDTH EQU %D 240
ILI9341_TFTHEIGHT EQU %D 320
; lcd komande - za znacenja vidjeti datasheet str 83
ILI9341_SWRESET EQU 01
ILI9341_SLPOUT EQU 11
ILI9341_INVOFF EQU 20
ILI9341_INVON EQU 21
ILI9341_GAMMASET EQU 26
ILI9341_DISPON EQU 29
ILI9341_CASET EQU 2A
ILI9341_PASET EQU 2B
ILI9341_RAMWR EQU 2C
ILI9341_RAMRD EQU 2E
ILI9341_MADCTL EQU 36
ILI9341_PIXFMT EQU 3A
ILI9341_FRMCTR1 EQU 0B1
ILI9341_DFUNCTR EQU 0B6
ILI9341_PWCTR1 EQU 0C0
ILI9341_PWCTR2 EQU 0C1
ILI9341_VMCTR1 EQU 0C5
ILI9341_VMCTR2 EQU 0C7
ILI9341_GMCTRP1 EQU 0E0
ILI9341_GMCTRN1 EQU 0E1
ORG 0
MAIN MOVE 10000, SP
; SPI config
; 876543210
MOVE %B 110000110, R0 ; 0x186
STORE R0, (SPI_CR)
MOVE 0, R0 ; slave select
STORE R0, (SPI_SSR)
; reset lcd
MOVE ILI9341_SWRESET, R6
CALL SEND_CMD
MOVE 100, R6
CALL WAIT
; init lcd
; (sekvenca preuzeta iz python libraryja)
MOVE ILI9341_PWCTR1, R6
CALL SEND_CMD
MOVE 0x23, R6
CALL SEND_DATA
MOVE ILI9341_PWCTR2, R6
CALL SEND_CMD
MOVE 0x10, R6
CALL SEND_DATA
MOVE ILI9341_VMCTR1, R6
CALL SEND_CMD
; block([0x3e, 0x28])
MOVE 2, R0
PUSH R0
MOVE INIT_BLOCK1, R0
PUSH R0
CALL SEND_BLOCK
ADD SP, 8, SP
MOVE ILI9341_VMCTR2, R6
CALL SEND_CMD
MOVE 0x86, R6
CALL SEND_DATA
MOVE ILI9341_MADCTL, R6
CALL SEND_CMD
MOVE 0x48, R6
CALL SEND_DATA
MOVE ILI9341_PIXFMT, R6
CALL SEND_CMD
MOVE 0x55, R6
CALL SEND_DATA
MOVE ILI9341_FRMCTR1, R6
CALL SEND_CMD
; block([0x00, 0x18])
MOVE 2, R0
PUSH R0
MOVE INIT_BLOCK2, R0
PUSH R0
CALL SEND_BLOCK
ADD SP, 8, SP
MOVE ILI9341_DFUNCTR, R6
CALL SEND_CMD
; block([0x08, 0x82, 0x27])
MOVE 3, R0
PUSH R0
MOVE INIT_BLOCK3, R0
PUSH R0
CALL SEND_BLOCK
ADD SP, 8, SP
MOVE 0xF2, R6
CALL SEND_CMD
MOVE 0x00, R6
CALL SEND_DATA
MOVE ILI9341_GAMMASET, R6
CALL SEND_CMD
MOVE 0x01, R6
CALL SEND_DATA
MOVE ILI9341_GMCTRP1, R6
CALL SEND_CMD
; block([0x0f, 0x31, 0x2b, 0x0c, 0x0e, 0x08, 0x4e, 0xf1, 0x37, 0x07, 0x10, 0x03, 0x0e, 0x09, 0x00])
MOVE %D 15, R0
PUSH R0
MOVE INIT_BLOCK4, R0
PUSH R0
CALL SEND_BLOCK
ADD SP, 8, SP
MOVE ILI9341_GMCTRN1, R6
CALL SEND_CMD
; block([0x00, 0x0e, 0x14, 0x03, 0x11, 0x07, 0x31, 0xc1, 0x48, 0x08, 0x0f, 0x0c, 0x31, 0x36, 0x0f])
MOVE %D 15, R0
PUSH R0
MOVE INIT_BLOCK5, R0
PUSH R0
CALL SEND_BLOCK
ADD SP, 8, SP
MOVE ILI9341_SLPOUT, R6
CALL SEND_CMD
MOVE 12, R6
CALL WAIT
MOVE ILI9341_DISPON, R6
CALL SEND_CMD
; nacrtaj pozadinu
RESET_LCD LOAD R0, (CRNA)
PUSH R0
MOVE 0, R0 ; x0
PUSH R0
MOVE 4, R0 ; x1
PUSH R0
MOVE 0, R0 ; y0
PUSH R0
MOVE ILI9341_TFTHEIGHT, R0 ; y1
PUSH R0
CALL PAINT_AREA
ADD SP, 14, SP
LOAD R0, (BOJE)
PUSH R0
MOVE 0, R0 ; x0
PUSH R0
MOVE ILI9341_TFTWIDTH, R0 ; x1
PUSH R0
MOVE 0, R0 ; y0
PUSH R0
MOVE ILI9341_TFTHEIGHT, R0 ; y1
PUSH R0
CALL PAINT_AREA
ADD SP, 14, SP
CALL UI_DRAW_BG
CALL UI_DRAW_ZNAK
CALL UI_DRAW_STUP
CALL UI_DRAW_REDK
CALL UI_DRAW_SCAL
MOVE 123, R0
STORE R0, (PRETH_MODE)
STORE R0, (PRETH_ORJP)
STORE R0, (PRETH_PRNT)
CALL UI_DRAW_ZAST
JR GLAVNA_PETLJA
HALT
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
; init blocks
INIT_BLOCK1 DB 3E, 28
INIT_BLOCK2 DB 00, 18
INIT_BLOCK3 DB 08, 82, 27
INIT_BLOCK4 DB 0F, 31, 2b, 0c, 0e, 08, 4e, 0f1, 37, 07, 10, 03, 0e, 09, 00
INIT_BLOCK5 DB 00, 0e, 14, 03, 11, 07, 31, 0c1, 48, 08, 0f, 0c, 31, 36, 0f
WAIT ; ceka R6 milisekundi
PUSH R6
PUSH R5
WAIT_LP_OUT MOVE 1000, R5 ; cekaj 1 ms
WAIT_LP_IN SUB R5, 1, R5
JR_NZ WAIT_LP_IN
SUB R6, 1, R6
JR_NZ WAIT_LP_OUT
POP R5
POP R6
RET
QUICK_WAIT ; ceka R6 ciklusa
; invalidira R6
SUB R6, 1, R6
JR_NZ QUICK_WAIT
RET
MULTIPLY ; mnozi argumente sa stacka
; ne radi za mnozenje s nulom!
; vraca rezultat na r0
PUSH R1
PUSH R2
LOAD R1, (SP+0C) ; prvi faktor
LOAD R2, (SP+10) ; drugi faktor
MOVE 0, R0 ; rezultat
MULTIPLY_LP ADD R0, R2, R0
SUB R1, 1, R1
JR_NZ MULTIPLY_LP
POP R2
POP R1
RET
PAINT_AREA ; oboja pravokutnik
; prima stogom redom
; boja, x0, x1, y0, y1
PUSH R0
PUSH R1
PUSH R2
PUSH R3
PUSH R6
LOAD R0, (SP+24) ; x0
LOAD R1, (SP+20) ; x1
LOAD R2, (SP+1C) ; y0
LOAD R3, (SP+18) ; y1
PUSH R0 ; set frame
PUSH R1
PUSH R2
PUSH R3
CALL SET_FRAME
ADD SP, %D 16, SP
; izracunaj broj piksela
SUB R1, R0, R0
SUB R3, R2, R1
PUSH R0
PUSH R1
CALL MULTIPLY ; r0 = broj piksela
ADD SP, 8, SP
; popuni pikselima
MOVE ILI9341_RAMWR, R6
CALL SEND_CMD
LOAD R6, (SP+28) ; boja
PAINT_AREA_LP CALL SEND_HW
SUB R0, 1, R0
JR_NZ PAINT_AREA_LP
POP R6
POP R3
POP R2
POP R1
POP R0
RET
SPI_SEND ; opcenito slanje bez postavljanja dc
; salje R6
PUSH R6
PUSH R5
STOREB R6, (SPI_DTR) ; postavi komandu
LOAD R5, (SPI_CR) ; omoguci transakciju
AND R5, %B 011111111, R5 ; master transaction inhibit bit u 0
STORE R5, (SPI_CR)
MOVE 10, R6 ; cekaj da se podatak prenese
; trebalo bi provjeravati statusni registar u petlji, ali to ne funkcionira
CALL QUICK_WAIT
LOAD R5, (SPI_CR) ; onemoguci transakciju
OR R5, %B 100000000, R5 ; master transaction inhibit bit u 1
STORE R5, (SPI_CR)
POP R5
POP R6
RET
SEND_DATA ; salje R6 na SPI
PUSH R5
MOVE 1, R5 ; postavi pisanje podatka
STOREB R5, (GPIO2_OUTPUT)
CALL SPI_SEND
POP R5
RET
SEND_HW ; salje polurijec R6 na SPI
; big endian
PUSH R5
MOVE 1, R5 ; postavi pisanje podatka
STOREB R5, (GPIO2_OUTPUT)
ROTR R6, 8, R6 ; gornja polovica
CALL SPI_SEND
ROTL R6, 8, R6 ; donja polovica
CALL SPI_SEND
POP R5
RET
SEND_BLOCK ; prima stogom
; 1) broj elemenata
; 2) adresu pocetnog
; salje elemente na SPI
PUSH R0 ; sacuvaj
PUSH R1
PUSH R2
PUSH R6
MOVE 1, R0 ; postavi pisanje podatka
STOREB R0, (GPIO2_OUTPUT)
LOAD R0, (SP+18) ; brojac
LOAD R1, (SP+14) ; adresa
SEND_BLOCK_LP LOADB R6, (R1)
CALL SPI_SEND
ADD R1, 1, R1
SUB R0, 1, R0
JR_NZ SEND_BLOCK_LP
POP R6
POP R2
POP R1
POP R0
RET
SEND_CMD ; salje R6 na SPI
PUSH R5
MOVE 0, R5 ; postavi pisanje komande
STOREB R5, (GPIO2_OUTPUT)
CALL SPI_SEND
POP R5
RET
SET_FRAME ; postavi okvir za crtanje
; stogom se prenose redom:
; x0, x1, y0, y1
; redovi i stupci su 0-indeksirani
; skup je [x0, x1> x [y0, y1> (kartezijev produkt)
; (za sliku 10x20 u (0, 5) salje se (0, 9, 5, 5+19))
PUSH R6
MOVE ILI9341_CASET, R6
CALL SEND_CMD
LOAD R6, (SP+14) ; x065K color: 16-bit/pixel (RGB 5-6-5 bits input)
CALL SEND_HW
LOAD R6, (SP+10) ; x1
SUB R6, 1, R6 ; x1-- zatvarajuce granice su exclusive
CALL SEND_HW
MOVE ILI9341_PASET, R6
CALL SEND_CMD
LOAD R6, (SP+0C) ; y0
CALL SEND_HW
LOAD R6, (SP+8) ; y1
SUB R6, 1, R6
CALL SEND_HW
POP R6
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
GLAVNA_PETLJA
UPDATE_INPUT ;opisna labela, ovdje je nekad bio kod
LOAD R0, (GPIO1_SWITCHES) ;ledicu switcha u 1 bojamo u zeleno
MOVE 0, R1
SHR R0, 1, R0
ADC R1, 0, R1
SHL R0, 4, R0
SHL R1, 1, R1
OR R0, R1, R0
STORE R0, (GPIO0_RGB)
LOAD R6, (GPIO1_BUTTONS)
AND R6, %B 1111, R6
CMP R6, %B 1111 ;sva 4 dugmeta = reset
JR_EQ ZOVI_RESET
CALL UI_DRAW_ZAST
LOAD R5, (PRETH_BUTTONS)
CMP R5, R6
JR_EQ GLAVNA_PETLJA ;nije bilo promjene, preskoči donji kod da ne crtamo bezveze
STORE R6, (PRETH_BUTTONS)
LOAD R5, (GPIO1_SWITCHES) ;ispitujemo switcheve
AND R5, %B 11, R5
CMP R5, %B 00
JR_EQ SW_MODE_00
CMP R5, %B 01
JR_EQ SW_MODE_01
CMP R5, %B 10
JR_EQ SW_MODE_10
CMP R5, %B 11
JR_EQ SW_MODE_11
SW_MODE_00 CMP R6, %B 1000 ;mode za znakove i unos
CALL_EQ ZN_DEK
CMP R6, %B 0100
CALL_EQ ZN_INK
CMP R6, %B 0010
CALL_EQ SWITCH_UPIS
CMP R6, %B 0001
CALL_EQ UVJ_ISP_ZNK
JR END_UPDATE
SW_MODE_01 CMP R6, %B 1000 ;mode za boje
CALL_EQ BOJA_BG_DEK
CMP R6, %B 0100
CALL_EQ BOJA_BG_INK
CMP R6, %B 0010
CALL_EQ BOJA_ZN_DEK
CMP R6, %B 0001
CALL_EQ BOJA_ZN_INK
JR END_UPDATE
SW_MODE_10 CALL DIS_UPIS
CMP R6, %B 1000 ;mode za navigaciju
CALL_EQ REDAK_DEK
CMP R6, %B 0100
CALL_EQ REDAK_INK
CMP R6, %B 0010
CALL_EQ STUP_DEK
CMP R6, %B 0001
CALL_EQ STUP_INK
AND R6, %B 0011, R0 ; Crtanje UI-a ovisno o tome koja se koordinata promijenila
CALL_NZ UI_DRAW_STUP
AND R6, %B 1100, R0
CALL_NZ UI_DRAW_REDK
JR END_UPDATE
SW_MODE_11 CMP R6, %B 0011 ;mode za scale i orijentaciju(pozitivni/negativni scale duž neke osi)
CALL_EQ SWCH_PMT_ORJ ;ako pritisnemo switch x i y istovremeno, switchamo PAMTI_ORJ
CMP R6, %B 1100 ;ili ako istovremeno pritisnemo scale ink i dek, što ne utječe na scale
CALL_EQ SWCH_PMT_ORJ
CMP R6, %B 1000
CALL_EQ SCALE_DEK
CMP R6, %B 0100
CALL_EQ SCALE_INK
CMP R6, %B 0010
CALL_EQ XOR_ORJ_X
CMP R6, %B 0001
CALL_EQ XOR_ORJ_Y
AND R6, %B 1100, R0
CALL_NZ UI_DRAW_SCAL
JR END_UPDATE
END_UPDATE STORE R6, (GPIO0_LEDICE)
CALL UVJ_ISP_ZNK
CALL UI_DRAW_ZNAK
JR GLAVNA_PETLJA
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BOJA_BG_INK PUSH R0 ;boja pozadine inkrement
LOAD R0, (BOJA_BG_PNT)
ADD R0, 4, R0
SHR R0, 2, R0
CMP R0, UKUPNO_BOJA ;0-indeksirano
JR_NE SV_BG_CL1
MOVE 0, R0 ;rješavamo overflow
SV_BG_CL1 SHL R0, 2, R0
STORE R0, (BOJA_BG_PNT)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BOJA_BG_DEK PUSH R0 ;boja pozadine dekrement
LOAD R0, (BOJA_BG_PNT)
SUB R0, 4, R0
CMP R0, -4
JR_NE SV_BG_CL2
MOVE UKUPNO_BOJA, R0 ;rješavamo overflow
SUB R0, 1, R0 ;0-indeksirano
SHL R0, 2, R0
SV_BG_CL2 STORE R0, (BOJA_BG_PNT)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BOJA_ZN_INK PUSH R0 ;boja znaka inkrement
LOAD R0, (BOJA_ZNK_PNT)
ADD R0, 4, R0
SHR R0, 2, R0
CMP R0, UKUPNO_BOJA ;0-indeksirano
JR_NE SV_ZN_CL1
MOVE 0, R0 ;rješavamo overflow
SV_ZN_CL1 SHL R0, 2, R0
STORE R0, (BOJA_ZNK_PNT)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BOJA_ZN_DEK PUSH R0 ;boja znaka dekrement
LOAD R0, (BOJA_ZNK_PNT)
SUB R0, 4, R0
CMP R0, -4
JR_NE SV_ZN_CL2
MOVE UKUPNO_BOJA, R0 ;rješavamo overflow
SUB R0, 1, R0 ;0-indeksirano
SHL R0, 2, R0
SV_ZN_CL2 STORE R0, (BOJA_ZNK_PNT)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZN_INK PUSH R0 ;znak inkrement
LOAD R0, (ZNAK_PNT)
ADD R0, 1, R0
CMP R0, UKUPNO_ZNAKOVA ;0-indeksirano
JR_NE SV_ZN1
MOVE 0, R0 ;rješavamo overflow
SV_ZN1 STORE R0, (ZNAK_PNT)
CALL BUFFER_ZNAK
CALL UPDATE_ORJ
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZN_DEK PUSH R0 ;znak dekrement
LOAD R0, (ZNAK_PNT)
SUB R0, 1, R0
CMP R0, -1
JR_NE SV_ZN2
MOVE UKUPNO_ZNAKOVA, R0 ;rješavamo overflow
SUB R0, 1, R0 ;0-indeksirano
SV_ZN2 STORE R0, (ZNAK_PNT)
CALL BUFFER_ZNAK
CALL UPDATE_ORJ
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
STUP_INK PUSH R0 ;stupac inkrement
LOAD R0, (TR_STUPAC)
ADD R0, 1, R0
CMP R0, MAXSTUP ;0-indeksirano
JR_NE SV_ST1
MOVE 0, R0 ;rješavamo overflow
SV_ST1 STORE R0, (TR_STUPAC)
SHL R0, 3, R0
STORE R0, (POZICIJA_X)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
STUP_DEK PUSH R0 ;stupac dekrement
LOAD R0, (TR_STUPAC)
SUB R0, 1, R0
CMP R0, -1
JR_NE SV_ST2
MOVE MAXSTUP, R0 ;rješavamo overflow
SUB R0, 1, R0 ;0-indeksirano
SV_ST2 STORE R0, (TR_STUPAC)
SHL R0, 3, R0
STORE R0, (POZICIJA_X)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
REDAK_INK PUSH R0 ;redak inkrement
LOAD R0, (TR_REDAK)
ADD R0, 1, R0
CMP R0, MAXRED ;0-indeksirano
JR_NE SV_RD1
MOVE 0, R0 ;rješavamo overflow
SV_RD1 STORE R0, (TR_REDAK)
SHL R0, 3, R0
STORE R0, (POZICIJA_Y)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
REDAK_DEK PUSH R0 ;redak dekrement
LOAD R0, (TR_REDAK)
SUB R0, 1, R0
CMP R0, -1
JR_NE SV_RD2
MOVE MAXRED, R0 ;rješavamo overflow
SUB R0, 1, R0 ;0-indeksirano
SV_RD2 STORE R0, (TR_REDAK)
SHL R0, 3, R0
STORE R0, (POZICIJA_Y)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SCALE_INK PUSH R0 ;scale inkrement
LOAD R0, (SCALE)
ADD R0, 1, R0
CMP R0, MAXSCALE ;0-indeksirano
JR_NE SV_SC1
MOVE 1, R0 ;rješavamo overflow
SV_SC1 STORE R0, (SCALE)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SCALE_DEK PUSH R0 ;scale dekrement
LOAD R0, (SCALE)
SUB R0, 1, R0
CMP R0, 0
JR_NE SV_SC2
MOVE MAXSCALE, R0 ;rješavamo overflow
SUB R0, 1, R0 ;0-indeksirano
SV_SC2 STORE R0, (SCALE)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
UPISI_ZNAK
CALL EN_UPIS
CALL ISPISI_ZNAK
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EN_UPIS
MOVE 1, R0
STORE R0, (UPIS_ENABLED)
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DIS_UPIS
MOVE 0, R0
STORE R0, (UPIS_ENABLED)
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SWITCH_UPIS
LOAD R0, (UPIS_ENABLED)
XOR R0, 1, R0
STORE R0, (UPIS_ENABLED)
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SWCH_PMT_ORJ PUSH R0
LOAD R0, (PAMTI_ORJ)
XOR R0, 1, R0
STORE R0, (PAMTI_ORJ)
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZOVI_RESET PUSH R0 ;resetira poziciju na 0,0, scale, znak i zastavice i SKAČE na RESET_LCD ; NE ZVATI SA CALL
LOAD R0, (TR_REDAK)
MOVE 0, R0
STORE R0, (TR_REDAK)
LOAD R0, (TR_STUPAC)
MOVE 0, R0
STORE R0, (TR_STUPAC)
LOAD R0, (POZICIJA_X)
MOVE 0, R0
STORE R0, (POZICIJA_X)
LOAD R0, (POZICIJA_Y)
MOVE 0, R0
STORE R0, (POZICIJA_Y)
LOAD R0, (ZNAK_PNT)
MOVE 0, R0
STORE R0, (ZNAK_PNT)
CALL BUFFER_ZNAK
LOAD R0, (SCALE)
MOVE 1, R0
STORE R0, (SCALE)
LOAD R0, (PAMTI_ORJ)
MOVE 1, R0
STORE R0, (PAMTI_ORJ)
LOAD R0, (ORJ_X)
MOVE 0, R0
STORE R0, (ORJ_X)
LOAD R0, (ORJ_Y)
MOVE 0, R0
STORE R0, (ORJ_Y)
LOAD R0, (UPIS_ENABLED)
MOVE 0, R0
STORE R0, (UPIS_ENABLED)
POP R0
JR RESET_LCD
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE_ORJ PUSH R0
LOAD R0, (PAMTI_ORJ) ;ako pamtimo orijentaciju, treba ju promijeniti nakon učitavanja znaka
CMP R0, 0
JR_EQ NO_ORJ
CHCK_ORJ_X LOAD R0, (ORJ_X)
CMP R0,0
JR_EQ CHCK_ORJ_Y
CALL ZRCALI_X
CHCK_ORJ_Y LOAD R0, (ORJ_Y)
CMP R0,0
JR_EQ NO_ORJ
CALL ZRCALI_Y
NO_ORJ POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DIVMOD PUSH R2 ; Prima dva parametra stogom a i b i računa R0 = a div b, R1 = a mod b
LOAD R1, (SP+0C)
LOAD R2, (SP+8)
MOVE 0, R0
LP_DIVMOD ADD R0, 1, R0
SUB R1, R2, R1
JP_P LP_DIVMOD
SUB R0, 1, R0
ADD R1, R2, R1
POP R2
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BUFFER_ZNAK ;učitava znak iz memorije u buffer
PUSH R0
PUSH R1
LOAD R0, (ZNAK_PNT)
SHL R0, 3, R0
LOAD R1, (R0+ZNAKOVI)
STORE R1, (BUFFER)
ADD R0, 4, R0
LOAD R1, (R0+ZNAKOVI)
MOVE BUFFER, R0
ADD R0, 4, R0
STORE R1, (R0)
POP R1
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XOR_ORJ_X PUSH R0
LOAD R0, (ORJ_X)
XOR R0, 1, R0
STORE R0, (ORJ_X)
CALL ZRCALI_X
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
XOR_ORJ_Y PUSH R0
LOAD R0, (ORJ_Y)
XOR R0, 1, R0
STORE R0, (ORJ_Y)
CALL ZRCALI_Y
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZRCALI_Y PUSH R0 ; Zrcali BUFFER s obzirom na y-os
PUSH R1
PUSH R2
MOVE BUFFER, R1 ; Stavlja adresu prvog bajta BUFFER-a u R1
MOVE 8, R2 ; Brojač - 8 zato što ima 8 bajta
LP_ZRC_Y LOADB R0, (R1)
CALL ZRCALI_BAJT_Y ; Učita - zrcali - upiše natrag
STOREB R0, (R1)
ADD R1, 1, R1 ; Sljedeći bajt BUFFER-a
SUB R2, 1, R2
JR_NZ LP_ZRC_Y
POP R2
POP R1
POP R0
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZRCALI_BAJT_Y PUSH R1 ; Zrcali pojedini bajt s obzirom na y-os, prima taj bajt kao parametar preko R0
PUSH R2 ; Vraća rezultat preko R0
MOVE 8, R1 ; Brojač - 8 zato što ima 8 bita u bajtu
MOVE 0, R2 ; Rezultat
LP_ZRC_B_Y SHL R2, 1, R2 ; Pomaknemo rezultat za jedan bit lijevo
SHR R0, 1, R0 ; Izbacimo jedan bit iz ulaznog parametra pomakom u desno
ADC R2, 0, R2 ; Dodamo taj bit rezultat
; !!!! Ovim redoslijedom idemo kako ne bismo obrisali Carry zastavicu prije ADC
SUB R1, 1, R1
JR_NZ LP_ZRC_B_Y
MOVE R2, R0 ; Vraćamo rezultat preko R0
POP R2
POP R1
RET
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZRCALI_X PUSH R0 ; Zrcali BUFFER s obzirom na x-os
PUSH R1
PUSH R2
PUSH R3
PUSH R4
MOVE BUFFER, R2 ; Adresa prvog bajta BUFFER-a
MOVE R2, R3
ADD R3, 7, R3 ; Adresa zadnje bajta BUFFER-a
MOVE 4, R4 ; Brojač - 4 zato što ćemo morati napraviti 4 zamjene, prvi s zadnjim, drugi s predzadnjim itd.
LP_ZRC_X LOADB R0, (R2) ; Swap bajtova
LOADB R1, (R3)
STOREB R0, (R3)
STOREB R1, (R2)
ADD R2, 1, R2 ; Sljedeći bajt
SUB R3, 1, R3 ; Prethodni bajt
SUB R4, 1, R4
JR_NZ LP_ZRC_X