Repository navigation
Expand file tree
/
Copy pathvidcopy.s
More file actions
160 lines (148 loc) · 4.03 KB
/
Copy pathvidcopy.s
File metadata and controls
160 lines (148 loc) · 4.03 KB
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
#
! This file contains two specialized assembly code routines to update the
! video memory. The routines can copy from user to video memory, or from
! video to video memory.
! sections
.sect .text; .sect .rom; .sect .data; .sect .bss
! exported functions
.define _mem_vid_copy ! copy data to video ram
.define _vid_vid_copy ! move data in video ram
! The routines only guarantee to preserve the registers the C compiler
! expects to be preserved (ebx, esi, edi, ebp, esp, segment registers, and
! direction bit in the flags).
.sect .text
!*===========================================================================*
!* mem_vid_copy *
!*===========================================================================*
! PUBLIC void mem_vid_copy(u16 *src, unsigned dst, unsigned count);
!
! Copy count characters from kernel memory to video memory. Src is an ordinary
! pointer to a word, but dst and count are character (word) based video offset
! and count. If src is null then screen memory is blanked by filling it with
! blank_color.
_mem_vid_copy:
push ebp
mov ebp, esp
push esi
push edi
push es
mov esi, 8(ebp) ! source
mov edi, 12(ebp) ! destination
mov edx, 16(ebp) ! count
mov es, (_vid_seg) ! segment containing video memory
cld ! make sure direction is up
mvc_loop:
and edi, (_vid_mask) ! wrap address
mov ecx, edx ! one chunk to copy
mov eax, (_vid_size)
sub eax, edi
cmp ecx, eax
jbe 0f
mov ecx, eax ! ecx = min(ecx, vid_size - edi)
0: sub edx, ecx ! count -= ecx
shl edi, 1 ! byte address
add edi, (_vid_off) ! in video memory
test esi, esi ! source == 0 means blank the screen
jz mvc_blank
mvc_copy:
rep ! copy words to video memory
o16 movs
jmp mvc_test
mvc_blank:
mov eax, (_blank_color) ! ax = blanking character
rep
o16 stos ! copy blanks to video memory
!jmp mvc_test
mvc_test:
sub edi, (_vid_off)
shr edi, 1 ! back to a word address
test edx, edx
jnz mvc_loop
mvc_done:
pop es
pop edi
pop esi
pop ebp
ret
!*===========================================================================*
!* vid_vid_copy *
!*===========================================================================*
! PUBLIC void vid_vid_copy(unsigned src, unsigned dst, unsigned count);
!
! Copy count characters from video memory to video memory. Handle overlap.
! Used for scrolling, line or character insertion and deletion. Src, dst
! and count are character (word) based video offsets and count.
_vid_vid_copy:
push ebp
mov ebp, esp
push esi
push edi
push es
mov esi, 8(ebp) ! source
mov edi, 12(ebp) ! destination
mov edx, 16(ebp) ! count
mov es, (_vid_seg) ! segment containing video memory
cmp esi, edi ! copy up or down?
jb vvc_down
vvc_up:
cld ! direction is up
vvc_uploop:
and esi, (_vid_mask) ! wrap addresses
and edi, (_vid_mask)
mov ecx, edx ! one chunk to copy
mov eax, (_vid_size)
sub eax, esi
cmp ecx, eax
jbe 0f
mov ecx, eax ! ecx = min(ecx, vid_size - esi)
0: mov eax, (_vid_size)
sub eax, edi
cmp ecx, eax
jbe 0f
mov ecx, eax ! ecx = min(ecx, vid_size - edi)
0: sub edx, ecx ! count -= ecx
call vvc_copy ! copy video words
test edx, edx
jnz vvc_uploop ! again?
jmp vvc_done
vvc_down:
std ! direction is down
lea esi, -1(esi)(edx*1) ! start copying at the top
lea edi, -1(edi)(edx*1)
vvc_downloop:
and esi, (_vid_mask) ! wrap addresses
and edi, (_vid_mask)
mov ecx, edx ! one chunk to copy
lea eax, 1(esi)
cmp ecx, eax
jbe 0f
mov ecx, eax ! ecx = min(ecx, esi + 1)
0: lea eax, 1(edi)
cmp ecx, eax
jbe 0f
mov ecx, eax ! ecx = min(ecx, edi + 1)
0: sub edx, ecx ! count -= ecx
call vvc_copy
test edx, edx
jnz vvc_downloop ! again?
cld ! C compiler expects up
!jmp vvc_done
vvc_done:
pop es
pop edi
pop esi
pop ebp
ret
! Copy video words. (Inner code of both the up and downcopying loop.)
vvc_copy:
shl esi, 1
shl edi, 1 ! byte addresses
add esi, (_vid_off)
add edi, (_vid_off) ! in video memory
rep
eseg o16 movs ! copy video words
sub esi, (_vid_off)
sub edi, (_vid_off)
shr esi, 1
shr edi, 1 ! back to word addresses
ret