Advertisement
m1o2

Editor RealTime Real time m1o2 fxp Eitan Ronn Braude lab02

Apr 20th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;   Programmed By : m1o2
  2. ;   Course : Real-Time Systems
  3. ;   Date : 25.03.2012
  4.  
  5. ; Cursor2.asm
  6. ;
  7. ;This program demonstrates cursor manipulation.
  8. ;
  9. ;
  10. Stak              SEGMENT PARA STACK 'STACK'
  11. DB                 256 DUP(0)
  12. Stak              ENDS
  13. ;
  14. Data               SEGMENT PARA PUBLIC 'Data'
  15.                     Base dw 0
  16.                     Direction db 0
  17. ;
  18. Data               ENDS
  19. Code               SEGMENT PARA PUBLIC 'Code'
  20.                    .386  ; Enable 386 commands
  21.                    
  22. SetCursorPos          PROC    NEAR
  23. ; Set Cursor to position in BX
  24. ; Input: BX
  25. ; Output: None
  26.  
  27.   MOV              DX,3D4H  ; Point to 3D4H - 3D5H port pair
  28.   MOV              AL,14    ; Address of cursor register pos high byte
  29.   MOV              AH,BH    ; Get desired value of cursor pos high byte
  30.   OUT              DX,AX    ; Port(3D4h) = 14, Port(3D5h) = Value of BH
  31. ;
  32.   MOV              AL,15    ; Address of cursor register pos low byte
  33.   MOV              AH,BL    ; Get desired value pf cursor pos low byte
  34.   OUT              DX,AX    ; Port(3D4h) = 15, Port(3D5h) = Value of BL
  35. ;
  36.   RET                     ; Return to caller
  37. SetCursorPos          ENDP
  38. ;
  39.  
  40. ;
  41. Start              PROC    FAR
  42. ;
  43. ;STANDARD PROGRAM PROLOGUE
  44. ;
  45.   ASSUME           CS:Code
  46.   PUSH             DS          ; Save PSP segment address
  47.   MOV              AX,0
  48.   PUSH             AX          ; Save INT 20h address offset (PSP+0)
  49.   MOV              AX,Data
  50.   MOV              DS,AX       ; Establish Data segment addressability
  51.   ASSUME           DS:Data
  52. ;
  53. ;Part1 : Initialize the display adapter
  54. ;
  55.   MOV              AH,0          ; Select function = 'Set mode'
  56.   MOV              AL,2          ; 25x80 color image
  57.   INT              10h           ; Adapter initialized. Page 0 displayed
  58. ;
  59.   MOV              AX,0B800h     ; Segment address of memory on color adapter
  60. ;
  61.   MOV              ES,AX         ; Set up extra segment register
  62. ;
  63. ; Write 'A' in mid screen
  64. ;
  65.   mov BX,(12*80+40)
  66.   mov si, 2*(12*80+40)
  67.   ;mov bx, 1
  68.   ;mov si, 0
  69.   mov cl, 'A'
  70.   mov ch, 0Eh
  71.   mov Base, 0
  72. ;
  73. ; Set the cursor address registers
  74. ;
  75.  
  76.   CALL SetCursorPos
  77. ;
  78. ;PART 2 : Wait for key strike
  79. ;
  80. ; Wait for key
  81. ;
  82.     jmp ShowAscii
  83.    
  84. NextLoop:
  85.   MOV              AH,0       ; Wait and read key
  86.   INT              16h        ;
  87.   CMP              AH,1       ; Is it Esc?
  88.   JE               ToReturn   ; Yes - Return to DOS
  89.   ;
  90.   ;
  91.   cmp ah, 75
  92.   je Left
  93.   cmp ah, 72
  94.   je Up
  95.   cmp ah, 80
  96.   je Down
  97.   cmp ah, 77
  98.   je Right
  99.   cmp ah, 59
  100.   je AddAttribute
  101.   cmp ah, 60
  102.   je MaxCursor
  103.   cmp ah, 61
  104.   je MinCursor
  105.   ;<DEBUG>
  106.   cmp ah, 62
  107.   je MinAttribute
  108.   cmp ah, 63
  109.   je MaxAttribute
  110.   ;</DEBUG>
  111.  
  112.  
  113.     mov cl, al
  114.  ShowAscii:
  115.   mov word PTR ES:[si],cx
  116.   inc bx
  117.   add si, 2
  118.   jmp SetNewCursor
  119.  Left: 
  120.     dec bx
  121.     sub si, 2
  122.     jmp SetNewCursor
  123.  Up:
  124.     sub bx, 80
  125.     sub si, 2*80
  126.     jmp SetNewCursor
  127. Down:
  128.     add bx, 80
  129.     add si, 2*80
  130.     jmp SetNewCursor
  131.  Right:
  132.     inc bx
  133.     add si, 2
  134.     jmp SetNewCursor
  135. AddAttribute:
  136.     inc ch
  137.     JMP NextLoop   ; Repeat main loop
  138. MaxAttribute:
  139.     mov ch, 255
  140.     JMP NextLoop   ; Repeat main loop
  141. MinAttribute:
  142.     xor ch, ch
  143.     JMP NextLoop   ; Repeat main loop
  144. MaxCursor:
  145.     mov dx, 3D4h
  146.     mov ax, 10
  147.     out dx, ax
  148.     mov ax, 0f0bh
  149.     out dx, ax
  150.     JMP NextLoop   ; Repeat main loop
  151. MinCursor:
  152.     mov dx, 3D4h
  153.     mov ax, 0e0ah
  154.     out dx, ax
  155.     mov ax, 0f0bh
  156.     out dx, ax
  157.     JMP NextLoop   ; Repeat main loop
  158.     ;
  159.     ;
  160. SetNewCursor:  
  161.  
  162.     cmp bx, Base
  163.     jl below                    ; we might need to scroll up
  164.     mov ax, bx
  165.     sub ax, Base                ; find abs( line - base )
  166.     cmp ax, 0
  167.     jge AfterABS               
  168.     neg ax                      ; abs
  169. AfterABS:  
  170.     cmp ax, 2000                ; abs( line - base ) > 2000 ?
  171.     jbe update
  172.     jmp above
  173. below :
  174.     cmp bx, 0
  175.     jge continueScroll
  176. below_Zero_No_Scroll:           ; we are at the first row, can't do up
  177.     add bx, 80
  178.     add si, 2*80
  179.     jmp update
  180. continueScroll:
  181.     sub Base, 80
  182.     jmp scroll
  183. above:
  184.     add Base, 80
  185. Scroll:
  186.    
  187.     push bx
  188.     mov bx, Base
  189.    
  190.     mov dx, 3D4h
  191.     mov al, 12
  192.     mov ah, bh
  193.     out dx, ax
  194.    
  195.     mov al, 13
  196.     mov ah, bl
  197.     out dx, ax
  198.  
  199.     pop bx
  200. update:
  201.     call SetCursorPos
  202.  
  203.     JMP NextLoop   ; Repeat main loop
  204. ;
  205. ToReturn:
  206.                    MOV  AX,2
  207.                    INT  10h
  208.                    RET
  209. Start              ENDP
  210. Code               ENDS
  211.   END              Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement