Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ros-playground
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
ros-playground
Commits
d726c9e5
There was an error fetching the commit references. Please try again later.
Commit
d726c9e5
authored
4 years ago
by
Bensong Liu
Browse files
Options
Downloads
Patches
Plain Diff
println working
parent
42bda3b6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
kernel/include/stdlib.hpp
+22
-0
22 additions, 0 deletions
kernel/include/stdlib.hpp
kernel/include/vga.hpp
+43
-9
43 additions, 9 deletions
kernel/include/vga.hpp
kernel/kernel.cc
+5
-0
5 additions, 0 deletions
kernel/kernel.cc
with
70 additions
and
9 deletions
kernel/include/stdlib.hpp
0 → 100644
+
22
−
0
View file @
d726c9e5
#ifndef ROS_KERN_STDLIB_HPP
#define ROS_KERN_STDLIB_HPP
#include
"stdint.hpp"
template
<
typename
T
>
inline
void
memcpy
(
T
*
dst
,
const
T
*
src
,
size_t
count
)
{
for
(
auto
i
=
0
;
i
<
count
;
++
i
)
{
dst
[
i
]
=
src
[
i
];
}
}
template
<
typename
T
>
inline
void
memset
(
T
*
dst
,
const
T
&
data_to_set
,
size_t
count
)
{
char
*
cdst
=
reinterpret_cast
<
char
*>
(
dst
);
for
(
auto
i
=
0
;
i
<
count
;
++
i
)
{
cdst
[
i
]
=
data_to_set
;
}
}
#endif
This diff is collapsed.
Click to expand it.
kernel/include/vga.hpp
+
43
−
9
View file @
d726c9e5
#ifndef ROS_KERN_VGA_HPP
#ifndef ROS_KERN_VGA_HPP
#define ROS_KERN_VGA_HPP
#define ROS_KERN_VGA_HPP
inline
char
*
vga_begin
=
(
char
*
)
0xb8000
;
#include
"stdint.hpp"
void
push_char
(
char
c
,
char
color
)
{
#include
"stdlib.hpp"
static
int
pos
=
0
;
vga_begin
[
pos
++
]
=
c
;
#define VGA_BEGIN_ADDR ((uint16_t *)0xb8000)
vga_begin
[
pos
++
]
=
color
;
constexpr
uint16_t
VGA_WIDTH
=
80
;
constexpr
uint16_t
VGA_HEIGHT
=
25
;
constexpr
uint16_t
VGA_MAKE_CHAR
(
char
c
,
uint8_t
color
)
{
return
(
color
<<
8
)
+
uint8_t
(
c
);
}
constexpr
uint8_t
default_color
=
0x0f
;
inline
void
trigger_scroll
(
uint16_t
*
pos
)
{
for
(
uint16_t
row
=
1
;
row
<
VGA_HEIGHT
;
++
row
)
{
memcpy
(
VGA_BEGIN_ADDR
+
(
row
-
1
)
*
VGA_WIDTH
,
VGA_BEGIN_ADDR
+
row
*
VGA_WIDTH
,
VGA_WIDTH
);
}
memset
(
VGA_BEGIN_ADDR
+
(
VGA_HEIGHT
-
1
)
*
VGA_WIDTH
,
VGA_MAKE_CHAR
(
0
,
0
),
VGA_WIDTH
);
(
*
pos
)
-=
VGA_WIDTH
;
}
inline
void
set_char
(
uint16_t
x
,
uint16_t
y
,
char
c
,
char
color
)
{
VGA_BEGIN_ADDR
[
y
*
VGA_WIDTH
+
x
]
=
VGA_MAKE_CHAR
(
c
,
color
);
}
inline
void
put_char
(
char
c
,
uint8_t
color
)
{
static
uint16_t
pos
=
0
;
if
(
pos
>=
VGA_WIDTH
*
VGA_HEIGHT
)
trigger_scroll
(
&
pos
);
switch
(
c
)
{
case
'\n'
:
pos
+=
VGA_WIDTH
;
[[
fallthrough
]];
// unix \n implies \r.
case
'\r'
:
pos
-=
pos
%
VGA_WIDTH
;
break
;
default:
VGA_BEGIN_ADDR
[
pos
++
]
=
VGA_MAKE_CHAR
(
c
,
color
);
}
}
}
void
set_char
(
int
x
,
int
y
,
char
c
,
char
color
)
{
inline
void
print
(
const
char
*
cstr
,
u
int
8_t
color
=
default_
color
)
{
auto
pos
=
x
+
80
*
y
;
while
(
*
cstr
!=
'\0'
)
{
vga_begin
[
pos
*
2
]
=
c
;
put_char
(
*
(
cstr
++
),
color
)
;
vga_begin
[
pos
*
2
+
1
]
=
color
;
}
}
}
#endif
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
kernel/kernel.cc
+
5
−
0
View file @
d726c9e5
...
@@ -17,5 +17,10 @@ void main() {
...
@@ -17,5 +17,10 @@ void main() {
set_char
(
x
,
y
,
c
,
color
);
set_char
(
x
,
y
,
c
,
color
);
}
}
}
}
print
(
"Hello world!
\n
"
);
print
(
"Hello world!
\n
"
,
0xb1
);
print
(
"Hello world!
\n
"
,
0xae
);
print
(
"Hello world!
\n
"
,
0x5c
);
print
(
"Hello world!
\n
"
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment