Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Programmed By : m1o2
- ; Course : Real-Time Systems
- ; Date : 25.03.2012
- ; Cursor2.asm
- ;
- ;This program demonstrates cursor manipulation.
- ;
- ;
- Stak SEGMENT PARA STACK 'STACK'
- DB 256 DUP(0)
- Stak ENDS
- ;
- Data SEGMENT PARA PUBLIC 'Data'
- Base dw 0
- Direction db 0
- ;
- Data ENDS
- Code SEGMENT PARA PUBLIC 'Code'
- .386 ; Enable 386 commands
- SetCursorPos PROC NEAR
- ; Set Cursor to position in BX
- ; Input: BX
- ; Output: None
- MOV DX,3D4H ; Point to 3D4H - 3D5H port pair
- MOV AL,14 ; Address of cursor register pos high byte
- MOV AH,BH ; Get desired value of cursor pos high byte
- OUT DX,AX ; Port(3D4h) = 14, Port(3D5h) = Value of BH
- ;
- MOV AL,15 ; Address of cursor register pos low byte
- MOV AH,BL ; Get desired value pf cursor pos low byte
- OUT DX,AX ; Port(3D4h) = 15, Port(3D5h) = Value of BL
- ;
- RET ; Return to caller
- SetCursorPos ENDP
- ;
- ;
- Start PROC FAR
- ;
- ;STANDARD PROGRAM PROLOGUE
- ;
- ASSUME CS:Code
- PUSH DS ; Save PSP segment address
- MOV AX,0
- PUSH AX ; Save INT 20h address offset (PSP+0)
- MOV AX,Data
- MOV DS,AX ; Establish Data segment addressability
- ASSUME DS:Data
- ;
- ;Part1 : Initialize the display adapter
- ;
- MOV AH,0 ; Select function = 'Set mode'
- MOV AL,2 ; 25x80 color image
- INT 10h ; Adapter initialized. Page 0 displayed
- ;
- MOV AX,0B800h ; Segment address of memory on color adapter
- ;
- MOV ES,AX ; Set up extra segment register
- ;
- ; Write 'A' in mid screen
- ;
- mov BX,(12*80+40)
- mov si, 2*(12*80+40)
- ;mov bx, 1
- ;mov si, 0
- mov cl, 'A'
- mov ch, 0Eh
- mov Base, 0
- ;
- ; Set the cursor address registers
- ;
- CALL SetCursorPos
- ;
- ;PART 2 : Wait for key strike
- ;
- ; Wait for key
- ;
- jmp ShowAscii
- NextLoop:
- MOV AH,0 ; Wait and read key
- INT 16h ;
- CMP AH,1 ; Is it Esc?
- JE ToReturn ; Yes - Return to DOS
- ;
- ;
- cmp ah, 75
- je Left
- cmp ah, 72
- je Up
- cmp ah, 80
- je Down
- cmp ah, 77
- je Right
- cmp ah, 59
- je AddAttribute
- cmp ah, 60
- je MaxCursor
- cmp ah, 61
- je MinCursor
- ;<DEBUG>
- cmp ah, 62
- je MinAttribute
- cmp ah, 63
- je MaxAttribute
- ;</DEBUG>
- mov cl, al
- ShowAscii:
- mov word PTR ES:[si],cx
- inc bx
- add si, 2
- jmp SetNewCursor
- Left:
- dec bx
- sub si, 2
- jmp SetNewCursor
- Up:
- sub bx, 80
- sub si, 2*80
- jmp SetNewCursor
- Down:
- add bx, 80
- add si, 2*80
- jmp SetNewCursor
- Right:
- inc bx
- add si, 2
- jmp SetNewCursor
- AddAttribute:
- inc ch
- JMP NextLoop ; Repeat main loop
- MaxAttribute:
- mov ch, 255
- JMP NextLoop ; Repeat main loop
- MinAttribute:
- xor ch, ch
- JMP NextLoop ; Repeat main loop
- MaxCursor:
- mov dx, 3D4h
- mov ax, 10
- out dx, ax
- mov ax, 0f0bh
- out dx, ax
- JMP NextLoop ; Repeat main loop
- MinCursor:
- mov dx, 3D4h
- mov ax, 0e0ah
- out dx, ax
- mov ax, 0f0bh
- out dx, ax
- JMP NextLoop ; Repeat main loop
- ;
- ;
- SetNewCursor:
- cmp bx, Base
- jl below ; we might need to scroll up
- mov ax, bx
- sub ax, Base ; find abs( line - base )
- cmp ax, 0
- jge AfterABS
- neg ax ; abs
- AfterABS:
- cmp ax, 2000 ; abs( line - base ) > 2000 ?
- jbe update
- jmp above
- below :
- cmp bx, 0
- jge continueScroll
- below_Zero_No_Scroll: ; we are at the first row, can't do up
- add bx, 80
- add si, 2*80
- jmp update
- continueScroll:
- sub Base, 80
- jmp scroll
- above:
- add Base, 80
- Scroll:
- push bx
- mov bx, Base
- mov dx, 3D4h
- mov al, 12
- mov ah, bh
- out dx, ax
- mov al, 13
- mov ah, bl
- out dx, ax
- pop bx
- update:
- call SetCursorPos
- JMP NextLoop ; Repeat main loop
- ;
- ToReturn:
- MOV AX,2
- INT 10h
- RET
- Start ENDP
- Code ENDS
- END Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement