- 硬件:CPU 和设备(显示器、键盘、时钟)
- AM :提供基本 API
- 软件:基于 AM 编写,生成二进制文件直接在硬件上运行
| 地址 | 功能 | 权限 | 内容 |
|---|---|---|---|
[0x00000000, 0x00040000) |
.text | 禁止 | |
[0x00080000, 0x000a0000) |
.rodata | 只读 | |
[0x00100000, 0x0011f000) |
数据 | 读写 | 从低到高依次.data、.bss、堆;栈从高到低 |
[0x00200000, 0x00296000) |
显存 | 只写,写只能按半字 | 半字A,A[15:12]无效,A[11:8]红,A[7:4]绿,A[3:0]蓝。显存按行连续存储,每行640像素,共480行。 |
0x00400000 |
键盘 | 只读 | 字A,A[15]成功取出,A[8]断码,A[7:0]扫描码 |
0x00800000 |
时间 | 只读 | 从开机至当前经过的微秒数低32位 |
0x00800004 |
时间 | 只读 | 从开机至当前经过的微秒数高32位 |
访问违例属于“未定义行为”,不会触发任何错误或警告。
-
#define VGA_START (volatile uint16_t *)0x200000
显存的起始地址。
-
#define VGA_END (volatile uint16_t *)0x296000
显存的结束地址。
-
#define VGA_WIDTH 640
屏幕宽度。
-
#define VGA_HEIGHT 480
屏幕高度。
-
uint16_t *pixel_at(size_t x, size_t y);
指向
y行x列像素的指针。此函数不应该频繁调用,如果要访问连续的显存,应只使用此函数获取首指针! -
void write_rect(size_t x, size_t y, size_t w, size_t h, const uint16_t *restrict data);
写入一块显存区域,
data应该是连续存储h*w个数据。 -
void fill_rect(size_t x, size_t y, size_t w, size_t h, uint16_t color);
用
color填充从y行x列开始高为h宽为w的矩形区域。 -
void fill_screen(uint16_t color);
用
color填充整个屏幕。 -
struct keyboard_event { uint8_t scan_code; bool release; };
表示键盘事件的结构体,
release为假时表示按下,为真时表示释放。 -
bool get_key(struct keyboard_event *evt);
获取键盘缓冲区中的字符,如果返回
true说明获取成功,返回false说明缓冲区为空。 -
extern unsigned char scancode_to_char[256];
用于将扫描码转化为可视字符。
-
extern unsigned char shift_scancode_to_char[256];
用于将扫描码转化为按下 Shift 键时的字符。
-
void make_char(char c, uint16_t foreground, uint16_t background, uint16_t *dest);
将
c的图形写入dest数组。 -
void write_char_at(char c, uint16_t foreground, uint16_t background, size_t col, size_t row);
将将
c的图形显示到第col列第row行,应保证0 <= col < 71和0 <= row < 30,即字符界面的 71 列 30 行。 -
uint64_t get_time();
从开机至当前经过的微秒数。
-
void halt(int code);
终止,一般约定
code为零时表示成功。此函数主要用于调试。
void *memset(void *s, int c, size_t n);
void *memcpy(void *restrict dst, const void *restrict src, size_t n);
void *memmove(void *dst, const void *src, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
size_t strlen(const char *s);
char *strcat(char *restrict dst, const char *restrict src);
char *strcpy(char *restrict dst, const char *restrict src);
char *strncpy(char *restrict dst, const char *restrict src, size_t n);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);void srand(unsigned int seed);
int rand(void);
void *malloc(size_t size);
void free(void *ptr);
int abs(int x);
int atoi(const char *nptr);| 命令 | 功能 |
|---|---|
clear |
清屏 |
hello |
输出Hello World |
logo |
展示 Logo |
time |
输出从开机至当前经过的微秒数 |
fib n |
输出前n个斐波那契数 |
rotate |
NJU ICS PA 的 video test |
snake |
贪吃蛇 |
bird |
简化版 Flappy Bird |