Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Pure-Happiness/NJU-DLCO-Experiment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NJU-DLCO-Experiment

总体结构

  • 硬件:CPU 和设备(显示器、键盘、时钟)
  • AM :提供基本 API
  • 软件:基于 AM 编写,生成二进制文件直接在硬件上运行

内存映射约定

地址 功能 权限 内容
[0x00000000, 0x00040000) .text 禁止
[0x00080000, 0x000a0000) .rodata 只读
[0x00100000, 0x0011f000) 数据 读写 从低到高依次.data.bss、堆;栈从高到低
[0x00200000, 0x00296000) 显存 只写,写只能按半字 半字AA[15:12]无效,A[11:8]红,A[7:4]绿,A[3:0]蓝。显存按行连续存储,每行640像素,共480行。
0x00400000 键盘 只读 AA[15]成功取出,A[8]断码,A[7:0]扫描码
0x00800000 时间 只读 从开机至当前经过的微秒数低32
0x00800004 时间 只读 从开机至当前经过的微秒数高32

访问违例属于“未定义行为”,不会触发任何错误或警告。

AM

system.h

  • #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);

    指向yx列像素的指针。此函数不应该频繁调用,如果要访问连续的显存,应只使用此函数获取首指针!

  • 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填充从yx列开始高为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 < 710 <= row < 30,即字符界面的 71 列 30 行。

  • uint64_t get_time();

    从开机至当前经过的微秒数。

  • void halt(int code);

    终止,一般约定code为零时表示成功。此函数主要用于调试。

string.h

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);

stdlib.h

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);

NTerm

命令 功能
clear 清屏
hello 输出Hello World
logo 展示 Logo
time 输出从开机至当前经过的微秒数
fib n 输出前n个斐波那契数
rotate NJU ICS PA 的 video test
snake 贪吃蛇
bird 简化版 Flappy Bird

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages