source: trunk/minix/drivers/tty/vidcopy.s@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 4.0 KB
Line 
1#
2! This file contains two specialized assembly code routines to update the
3! video memory. The routines can copy from user to video memory, or from
4! video to video memory.
5
6! sections
7
8.sect .text; .sect .rom; .sect .data; .sect .bss
9
10! exported functions
11
12.define _mem_vid_copy ! copy data to video ram
13.define _vid_vid_copy ! move data in video ram
14
15! The routines only guarantee to preserve the registers the C compiler
16! expects to be preserved (ebx, esi, edi, ebp, esp, segment registers, and
17! direction bit in the flags).
18
19.sect .text
20!*===========================================================================*
21!* mem_vid_copy *
22!*===========================================================================*
23! PUBLIC void mem_vid_copy(u16 *src, unsigned dst, unsigned count);
24!
25! Copy count characters from kernel memory to video memory. Src is an ordinary
26! pointer to a word, but dst and count are character (word) based video offset
27! and count. If src is null then screen memory is blanked by filling it with
28! blank_color.
29
30_mem_vid_copy:
31 push ebp
32 mov ebp, esp
33 push esi
34 push edi
35 push es
36 mov esi, 8(ebp) ! source
37 mov edi, 12(ebp) ! destination
38 mov edx, 16(ebp) ! count
39 mov es, (_vid_seg) ! segment containing video memory
40 cld ! make sure direction is up
41mvc_loop:
42 and edi, (_vid_mask) ! wrap address
43 mov ecx, edx ! one chunk to copy
44 mov eax, (_vid_size)
45 sub eax, edi
46 cmp ecx, eax
47 jbe 0f
48 mov ecx, eax ! ecx = min(ecx, vid_size - edi)
490: sub edx, ecx ! count -= ecx
50 shl edi, 1 ! byte address
51 add edi, (_vid_off) ! in video memory
52 test esi, esi ! source == 0 means blank the screen
53 jz mvc_blank
54mvc_copy:
55 rep ! copy words to video memory
56 o16 movs
57 jmp mvc_test
58mvc_blank:
59 mov eax, (_blank_color) ! ax = blanking character
60 rep
61 o16 stos ! copy blanks to video memory
62 !jmp mvc_test
63mvc_test:
64 sub edi, (_vid_off)
65 shr edi, 1 ! back to a word address
66 test edx, edx
67 jnz mvc_loop
68mvc_done:
69 pop es
70 pop edi
71 pop esi
72 pop ebp
73 ret
74
75
76!*===========================================================================*
77!* vid_vid_copy *
78!*===========================================================================*
79! PUBLIC void vid_vid_copy(unsigned src, unsigned dst, unsigned count);
80!
81! Copy count characters from video memory to video memory. Handle overlap.
82! Used for scrolling, line or character insertion and deletion. Src, dst
83! and count are character (word) based video offsets and count.
84
85_vid_vid_copy:
86 push ebp
87 mov ebp, esp
88 push esi
89 push edi
90 push es
91 mov esi, 8(ebp) ! source
92 mov edi, 12(ebp) ! destination
93 mov edx, 16(ebp) ! count
94 mov es, (_vid_seg) ! segment containing video memory
95 cmp esi, edi ! copy up or down?
96 jb vvc_down
97vvc_up:
98 cld ! direction is up
99vvc_uploop:
100 and esi, (_vid_mask) ! wrap addresses
101 and edi, (_vid_mask)
102 mov ecx, edx ! one chunk to copy
103 mov eax, (_vid_size)
104 sub eax, esi
105 cmp ecx, eax
106 jbe 0f
107 mov ecx, eax ! ecx = min(ecx, vid_size - esi)
1080: mov eax, (_vid_size)
109 sub eax, edi
110 cmp ecx, eax
111 jbe 0f
112 mov ecx, eax ! ecx = min(ecx, vid_size - edi)
1130: sub edx, ecx ! count -= ecx
114 call vvc_copy ! copy video words
115 test edx, edx
116 jnz vvc_uploop ! again?
117 jmp vvc_done
118vvc_down:
119 std ! direction is down
120 lea esi, -1(esi)(edx*1) ! start copying at the top
121 lea edi, -1(edi)(edx*1)
122vvc_downloop:
123 and esi, (_vid_mask) ! wrap addresses
124 and edi, (_vid_mask)
125 mov ecx, edx ! one chunk to copy
126 lea eax, 1(esi)
127 cmp ecx, eax
128 jbe 0f
129 mov ecx, eax ! ecx = min(ecx, esi + 1)
1300: lea eax, 1(edi)
131 cmp ecx, eax
132 jbe 0f
133 mov ecx, eax ! ecx = min(ecx, edi + 1)
1340: sub edx, ecx ! count -= ecx
135 call vvc_copy
136 test edx, edx
137 jnz vvc_downloop ! again?
138 cld ! C compiler expects up
139 !jmp vvc_done
140vvc_done:
141 pop es
142 pop edi
143 pop esi
144 pop ebp
145 ret
146
147! Copy video words. (Inner code of both the up and downcopying loop.)
148vvc_copy:
149 shl esi, 1
150 shl edi, 1 ! byte addresses
151 add esi, (_vid_off)
152 add edi, (_vid_off) ! in video memory
153 rep
154eseg o16 movs ! copy video words
155 sub esi, (_vid_off)
156 sub edi, (_vid_off)
157 shr esi, 1
158 shr edi, 1 ! back to word addresses
159 ret
160
Note: See TracBrowser for help on using the repository browser.