-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideomem.S
131 lines (114 loc) · 2.08 KB
/
videomem.S
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
#define COLS 80
#define ROWS 25
#define ADDR 0xb8000
#define ATTR 7
.section .bootstrap, "ax"
.code32
.global videomem_puts, videomem_putchar, videomem_clrscr
videomem_putchar_at:
movl 8(%esp), %eax // store row number in eax
imul $COLS, %eax // multiply by number of columns in row
addl 12(%esp), %eax // add column number
shll $1, %eax // multiply by 2 (2 bytes per one character)
addl $ADDR, %eax // add video memory offset
movl 4(%esp), %edx // store char to edx
orl $(ATTR << 8), %edx // save attrs
movw %dx, (%eax) // write into video memory
ret
videomem_empty_line:
pushl %ebx
movl 8(%esp), %eax
subl $12, %esp
movl $(' ' | (ATTR << 8)), (%esp)
movl %eax, 4(%esp)
xorl %ebx, %ebx
1:
cmpl $COLS, %ebx
je 1f
movl %ebx, 8(%esp)
call videomem_putchar_at
inc %ebx
jmp 1b
1:
addl $12, %esp
popl %ebx
ret
videomem_row:
.long 0x00
videomem_col:
.long 0x00
videomem_putchar:
movl 4(%esp), %ecx
cmpl $'\n', %ecx
je newline
cmpl $'\r', %ecx
je carrige
movl videomem_col, %eax
movl videomem_row, %edx
pushl %eax
pushl %edx
pushl %ecx
call videomem_putchar_at
popl %ecx
popl %edx
popl %eax
inc %eax
cmpl $COLS, %eax
je newline
movl %eax, videomem_col
ret
newline:
xorl %edx, %edx
movl videomem_row, %eax
inc %eax
movl $ROWS, %ecx
div %ecx
pushl %edx
call videomem_empty_line
popl %edx
movl %edx, videomem_row
carrige:
movl $0x0, videomem_col
ret
videomem_puts:
movl 4(%esp), %eax
subl $8, %esp
movl %esi, 4(%esp)
movl %eax, %esi
1:
xorl %eax, %eax
lodsb
test %al, %al
je 1f
movl %eax, (%esp)
call videomem_putchar
jmp 1b
1:
movl 4(%esp), %esi
addl $8, %esp
ret
videomem_clrscr:
pushl %edi
movl $ADDR, %edi
movl $((' ' | (ATTR << 8)) | ((' ' | (ATTR << 8)) << 16)), %eax
movl $(COLS * ROWS / 2), %ecx
rep stosl
popl %edi
movw $0x3cc, %dx
inb %dx, %al
xorb $1, %al
movw $0x3c2, %dx
out %al, %dx
movw $0x3b4, %dx
movb $0x0a, %al
outb %al, %dx
movw $0x3b5, %dx
movb $(1 << 5), %al
outb %al, %dx
movw $0x3b4, %dx
movb $0x0b, %al
outb %al, %dx
movw $0x3b5, %dx
movb $0, %al
outb %al, %dx
ret