-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProyecto.asm
1907 lines (1665 loc) · 31.1 KB
/
Proyecto.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
;ESTABLECE EL MODO VIDEO
org 100h
mov ah,00h
mov al,03h
int 10h
;inicializacion
call dibujar_ventana
;inicializa impresora
;mov ah,01h
;mov dx,01h
;int 17h
mov ah,02h
mov dh,6
mov dl,2
int 10h
push ax
push di
push si
mov ax,0b800h
mov es,ax
mov di,4
lea si,titulo
call escribe ;muestra titulo
pop si
pop di
pop ax
buffer db 12000 dup(00h) ;aca va 12000
buffer_copy db 12000 dup(00h) ;para los archivos
banderas db 10 dup(00h)
nombreArchivo db 200 dup(00h)
nombreArchivo2 db 200 dup(00h)
mensaje db 100 dup(00h);"Nombre Archivo:",'$'
mensajeError DB "Error$"
handle dw ?
;aca inicializo "mensaje" porque no me deja ponerlo como esta comentado arriba :/
push si
lea si,mensaje
mov [si],4eh
add si,2
mov [si],6fh
add si,2
mov [si],6dh
add si,2
mov [si],62h
add si,2
mov [si],72h
add si,2
mov [si],65h
add si,2
mov [si],20h
add si,2
mov [si],64h
add si,2
mov [si],65h
add si,2
mov [si],20h
add si,2
mov [si],61h
add si,2
mov [si],72h
add si,2
mov [si],63h
add si,2
mov [si],68h
add si,2
mov [si],69h
add si,2
mov [si],76h
add si,2
mov [si],6fh
add si,2
mov [si],3ah
add si,2
mov [si],24h
pop si
mov ax,0b800h ;memoria de video
mov es,ax
;mov di,802 ;posicion columna 1 fila 5
lea si,buffer
push di
lea di,banderas
mov [di],si ;puntero al comienzo de pagina
add di,4
push ax
mov ax,0h
mov [di],ax ; con 0 usa puntero a pagina, con 1 usa puntero a nombreArchivo
pop ax
pop di
;inicializa mouse
mov ax,00h
int 33h
mov ax,01h
int 33h
call leer_archivo_ayuda
;fin inicializacion
inicio:
call barra
call actualizar_memoria
mov ah,02h ;establece la posicion del cursor
int 10h
call mouse
mov ah,01h
int 16h
je inicio
mov ah,0h
int 16h
call identificar_puntero
inicio2:
call leer_tecla_funcion_barra
jmp tecla_barra
ret
inicio3:
call leer_flechas
call leer_tecla_funcion
;otra tecla
jmp tecla
fin:
ret
identificar_puntero:
push di
lea di,banderas
add di,4
cmp [di],0h
je inicio31
pop di
jmp inicio2
inicio31:
pop di
jmp inicio3
mouse:
push ax
push bx
push cx
push dx
push di
push si
;leo la posicion del cursor (en pixeles): cx=coordenada X ; dx=coordenada Y
mov ax,03h
int 33h
cmp bx,01h
jne endd2
;calculo columna
mov ax,cx
mov cl,8
div cl ;en al me queda el cociente y en ah el residuo
mov ch,al
;calculo fila
mov ax,dx
div cl ;en al me queda el cociente y en ah el residuo
mov cl,al
mov dh,cl
mov dl,ch
;barra superior
cmp dh,1
jl sec_texto ;si la fila es menor a 1
cmp dh,3
jg sec_texto ;si la fila es mayor a 3
cmp dl,2
jl sec_texto ;si la columna es menor a 2
cmp dl,77
jg sec_texto ;si la columna es mayor a 77
push di
lea di,banderas
add di,2
mov si,[di]
add di,2
mov ax,1h
mov [di],ax
pop di
mov dh,2
mov dl,21
lea si,nombreArchivo2
bnm:
cmp dl,77
je hjkl
cmp [si],00h
je hjkl
add si,2
add dl,1
jmp bnm
;sector texto
sec_texto:
;las siguientes restricciones las hago porque no me funciona
;la interrupcion que limita el dezplasamiento del mouse dentro ç
;del marco donde va el texto
cmp dh,6
jl endd2 ;si la fila es menor a 6
cmp dh,20
jg endd2 ;si la fila es mayor a 20
cmp dl,2
jl endd2 ;si la columna es menor a 2
cmp dl,77
jg endd2 ;si la columna es mayor a 77
;verifica memoria de video
push dx
mov di,964 ;comienzo de pagina
sub dl,2
push dx
mov dh,0
add di,dx
add di,dx
pop dx
sub dh,6
mov ax,80
mov dl,dh
mov dh,0
mul dx
add di,ax
add di,ax
pop dx
;mueve el puntero a memoria
mov ah,6 ;primer fila
mov al,2 ;primer columna
push di
lea di,banderas
mov si,[di] ;comienzo de pagina
add di,4
push ax
mov ax,0h
mov [di],ax
pop ax
pop di
bucle12:
cmp ax,dx
jg endd2
cmp ax,dx ;si llegue a la posicion del cursor entonces salgo del bucle
je final_mov
cmp al,77
jne sig_mov
add si,2
mov al,2
add ah,1
jmp bucle12
sig_mov:
cmp [si],0dh ;si es enter
jne sig_mov2
add si,2
mov al,2
add ah,1
jmp bucle12
sig_mov2:
add si,2
add al,1
jmp bucle12
final_mov:
cmp [si],0dh ;si es enter posiciona el cursor igual (en mem. de video es null)
je hjkl
;si hay null en memoria pero el anterior no es null (ultimo renglon en memoria)
;posiciona igual el cursor
cmp [si],00h
jne hjkl
push di
mov di,si
sub di,2
cmp [di],00h
jne ghjkl
pop di
;si en video hay null y en memoria no es enter entonces no posiciona el cursor
cmp es:[di],00h
je endd21
jmp hjkl
ghjkl:
pop di
hjkl:
mov di,si
pop si
mov si,di
pop di
mov ax,dx
pop dx
mov dx,ax
pop cx
pop bx
pop ax
ret
endd21:
cmp dh,6
jne endd2
cmp dl,2
je hjkl
endd2:
pop si
pop di
pop dx
pop cx
pop bx
pop ax
ret
casi_mouse:
push ax
push bx
push cx
push dx
push di
push si
;barra superior
cmp dh,1
jl sec_texto2 ;si la fila es menor a 1
cmp dh,3
jg sec_texto2 ;si la fila es mayor a 3
cmp dl,2
jl sec_texto2 ;si la columna es menor a 2
cmp dl,77
jg sec_texto2 ;si la columna es mayor a 77
push di
lea di,banderas
add di,2
mov si,[di]
add di,2
mov ax,1h
mov [di],ax
pop di
mov dh,2
mov dl,21
lea si,nombreArchivo2
bnm2:
cmp dl,77
je hjkl2
cmp [si],00h
je hjkl2
add si,2
add dl,1
jmp bnm2
;sector texto
sec_texto2:
;verifica memoria de video
push dx
mov di,964 ;comienzo de pagina
sub dl,2
push dx
mov dh,0
add di,dx
add di,dx
pop dx
sub dh,6
mov ax,80
mov dl,dh
mov dh,0
mul dx
add di,ax
add di,ax
pop dx
;mueve el puntero a memoria
mov ah,6 ;primer fila
mov al,2 ;primer columna
push di
lea di,banderas
mov si,[di] ;comienzo de pagina
add di,4
push ax
mov ax,0h
mov [di],ax
pop ax
pop di
bucle122:
cmp ax,dx
jg endd22
cmp ax,dx ;si llegue a la posicion del cursor entonces salgo del bucle
je final_mov2
cmp al,77
jne sig_mov22
add si,2
mov al,2
add ah,1
jmp bucle122
sig_mov22:
cmp [si],0dh ;si es enter
jne sig_mov222
add si,2
mov al,2
add ah,1
jmp bucle122
sig_mov222:
add si,2
add al,1
jmp bucle122
final_mov2:
cmp [si],0dh ;si es enter posiciona el cursor igual (en mem. de video es null)
je hjkl2
;si hay null en memoria pero el anterior no es null (ultimo renglon en memoria)
;posiciona igual el cursor
cmp [si],00h
jne hjkl2
push di
mov di,si
sub di,2
cmp [di],00h
jne ghjkl2
pop di
;si en video hay null y en memoria no es enter entonces no posiciona el cursor
cmp es:[di],00h
je endd212
jmp hjkl2
ghjkl2:
pop di
hjkl2:
mov di,si
pop si
mov si,di
pop di
mov ax,dx
pop dx
mov dx,ax
pop cx
pop bx
pop ax
ret
endd212:
cmp dh,6
jne endd22
cmp dl,2
je hjkl2
endd22:
pop si
pop di
pop dx
pop cx
pop bx
pop ax
ret
actualizar_memoria:
push si
push di
push ax
push dx
; ;barra
lea si,mensaje
mov di,324
bucle_barra:
cmp [si],24h ;$
je nombre_ar
mov al,[si]
mov es:[di],al
add si,2
add di,2
jmp bucle_barra
nombre_ar:
mov di,362
lea si,nombreArchivo2
mov dl,21
bucle_barra2:
cmp dl,77
je act_txt
mov al,[si]
mov es:[di],al
add si,2
add di,2
add dl,1
jmp bucle_barra2
;texto
act_txt:
mov di,964
mov dh,6
mov dl,2
call verificar_comienzo_lectura
ff:
call validar_fila
call validar_columna
mov al,[si]
cmp al,0dh
je verificar_mostrar_enter
mov es:[di],al
cmp di,3354 ;esquina inferior de la ventana (donde va el texto)
jne incrementar
pos_invalida:
pop dx
pop ax
pop di
pop si
ret
verificar_comienzo_lectura:
push di
lea di,banderas
mov si,[di]
pop di
ret
verificar_mostrar_enter:
cmp dh,20 ;verifico si estoy en el ultimo renglon
jne mostrar_enter
ooo:
push ax
mov al,00h
mov es:[di],al
pop ax
add dl,1
add di,2
cmp dl,78
jne ooo
jmp pos_invalida
mostrar_enter:
oo:
push ax
mov al,00h
mov es:[di],al
pop ax
add dl,1
add di,2
cmp dl,78
jne oo
call validar_columna
sub di,2
mov dl,1
jmp incrementar
incrementar:
add di,2
add si,2
add dl,1
jmp ff
validar_columna:
cmp dl,78
je fin_columna
ret
fin_columna:
mov dl,2
add dh,1
add di,8
jmp validar_columna
validar_fila:
cmp dh,21
je pos_invalida
ret
leer_flechas:
;flecha izquierda
cmp ah,4bh
je flecha_izquierda
;flecha derecha
cmp ah,4dh
je flecha_derecha
;flecha arriba
cmp ah,48h
je flecha_arriba
;flecha abajo
cmp ah,50h
je flecha_abajo
ret
leer_tecla_funcion:
;enter
cmp ah,1ch
je enter
cmp ah,47h
je home
cmp ah,4fh
je endl
cmp ah,53h
je supr
cmp ah,0eh
je borrar
cmp ah,3fh
je escribir_archivo
cmp ah,3ch
je vaciar_documento
cmp ah,3dh
je f3 ;imprimir
;cmp ah,3eh
;je f4
cmp ah,0fh
je saltar_a_texto_de_barra
cmp ah,01h
je fin
cmp al,1bh
je fin
ret
f3:
;inicializa impresora
push ax
push dx
mov ah,01h
mov dx,00h
int 17h
pop dx
pop ax
push dx
push di
push ax
mov dx,00h
lea di,buffer
ff12:
mov ah,00h
mov al,[di]
cmp al,0dh
je new_enter
int 17h
jmp new_enter2
new_enter:
mov al,0ah
int 17h
new_enter2:
add di,2
cmp [di],00h ;fin de memoria (null)
jne ff12
mov ah,00h
mov al,0ah
int 17h
pop ax
pop di
pop dx
jmp inicio
vaciar_documento:
push cx
push di
lea di,buffer
vaciar_documento1:
mov [di],0h
inc di
inc cx
cmp cx,12000d
jne vaciar_documento1
pop di
pop cx
mov dh,6
mov dl,2
call casi_mouse
jmp inicio
leer_tecla_funcion_barra:
;flecha izquierda
cmp ah,4bh
je inicio
;flecha derecha
cmp ah,4dh
je inicio
;flecha arriba
cmp ah,48h
je inicio
;flecha abajo
cmp ah,50h
je inicio
cmp ah,0eh
je borrar_barra
cmp ah,40h
je leer_archivo
cmp ah,3fh
je escribir_archivo
cmp ah,0fh
je saltar_a_texto
cmp ah,01h
je fin
cmp al,1bh
je fin
ret
saltar_a_texto:
mov dh,6
mov dl,2
call casi_mouse
jmp inicio
saltar_a_texto_de_barra:
mov dh,2
mov dl,21
call casi_mouse
jmp inicio
borrar_barra:
cmp dl,21
je inicio
sub dl,1
sub si,2
mov [si],00h
jmp inicio
tecla_barra:
cmp dl,77
je inicio
mov [si],al
add si,2
add dl,1
jmp inicio
home:
push ax
cmp dl,2
je inicio
dec dl
push dx
mov dh,0h
sub si,dx
sub si,dx
add si,2
pop dx
mov dl,2
pop ax
jmp inicio
endl:
push ax
end1: cmp dl,77
je end2
cmp [si],0h
je end2
cmp [si],0Dh
jne desplazamiento_enter
end2: pop ax
jmp inicio
desplazamiento_enter:
add si,2
inc dl
jmp end1
supr:
call mover_un_lugar_en_memoria_atras
jmp inicio
borrar:
push si
sub si,2
call mover_un_lugar_en_memoria_atras
pop si
call verificar_izquierda
jmp inicio
flecha_izquierda:
mov ah,03h ;lee la posicion del cursor
int 10h
call verificar_izquierda
jmp inicio
flecha_derecha:
mov ah,03h ;lee la posicion del cursor
int 10h
call verificar_derecha
jmp inicio
flecha_arriba:
mov ah,03h ;lee la posicion del cursor
int 10h
call verificar_arriba
jmp inicio
flecha_abajo:
mov ah,03h ;lee la posicion del cursor
int 10h
call verificar_abajo
jmp inicio
tecla:
cmp al,1bh
je fin
cmp ah,52h
je inicio ;si es insert, vuelvo a inicio
cmp ah,45h
je inicio
push ax
mov ah,02h
int 16h
shr al,8 ;veo si esta activado el insert
pop ax
jc teclaInsert
cmp [si],00h
jne caracter_no_nulo
cnl:
mov [si],al
inc dl
cmp dl,78
jne xx
mov dl,2
inc dh
cmp dh,21
jne xx
mov dh,20
call bajar_un_renglon
xx:
add si,2
jmp inicio
teclaInsert:
cmp dl,77
je cnl
cmp [si],0Dh
je caracter_no_nulo
;je mover_un_lugar_en_memoria
jmp cnl
caracter_no_nulo:
call mover_un_lugar_en_memoria
jmp cnl
bajar_un_renglon:
cmp si,11998 ;ultima posicion en la memoria del buffer
je inicio
push si
push dx
call verificar_comienzo_lectura
mov dl,2
vv:
cmp dl,77
je fin_de_linea
cmp [si],0dh
je fin_de_linea
add si,2
add dl,1
jmp vv
fin_de_linea:
add si,2
push di
lea di,banderas
mov [di],si
pop di
pop dx
pop si
ret
enter:
cmp [si],00h
jne no_nulo
kkk:
add dh,1
mov dl,2
mov [si],al
cmp dh,21
jne gg
call bajar_renglon
gg:
add si,2
jmp inicio
bajar_renglon:
mov dh,20
jmp bajar_un_renglon
no_nulo:
call mover_un_lugar_en_memoria
jmp kkk:
mover_un_lugar_en_memoria:
cmp si,11998 ;ultimo caracter de la memoria
je inicio
push di
push ax
lea di,buffer
add di,11996 ;posicion del anteultimo caracter de la memoria
ttt:
push si
mov si,di
add si,2
mov al,[di]
mov [si],al
sub di,2
pop si
cmp di,si
jge ttt
pop ax
pop di
ret
mover_un_lugar_en_memoria_atras:
push di
push ax
push si
ttt1:
mov di,si
add di,2
mov al,[di]
mov [si],al
add si,2
cmp [si],0h
jne ttt1
pop si
pop ax
pop di
ret
verificar_izquierda:
push di
lea di,buffer
cmp di,si
jne mm
pop di
jmp inicio
mm:
pop di
cmp dl,2 ;verifica columna
je verificar_fila_ini
sub dl,1
sub si,2
ret
verificar_fila_ini:
cmp dh,6
je subir_ventana_un_renglon
jmp buscar_caracter_arriba
buscar_caracter_arriba:
push si
call buscar_caracter_up
pop si
sub si,2
sub dh,1
jmp inicio
subir_ventana_un_renglon:
push si
push di
call buscar_caracter_up
lea si,banderas
mov [si],di
pop di
pop si
sub si,2
jmp inicio
buscar_caracter_up: ;posiciona el cursor arriba
sub si,2
mov dl,2
lea di,buffer
bucle:
cmp di,si
je fin_buscar
cmp [di],0dh
jne incr
mov dl,1
incr:
cmp dl,77
jne re
mov dl,1
re:
add dl,1
add di,2
jmp bucle
fin_buscar:
push dx
sub dl,2
mov dh,0
sub di,dx
sub di,dx
pop dx
ret
verificar_derecha:
cmp [si],0dh
je verificar_fila_der
cmp dl,77 ;verifica la columna