Record networking and DMA development progress
Add the current OS source tree, build scripts, system image layout, and development notes covering DMA page allocation, e1000 bring-up, net API dispatch, and DHCP work in progress.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# Deshab Bitmap Font (.dbf)
|
||||
|
||||
`CODE/font` 包含 Deshab 自研位图字体工具和规范。
|
||||
|
||||
## 文件格式
|
||||
|
||||
```text
|
||||
Offset Size Field
|
||||
0 4 magic "DBF\x10" (version 16)
|
||||
4 4 u32 glyph_count
|
||||
8 2 u16 default_width
|
||||
10 2 u16 default_height
|
||||
12 2 u16 bits_per_pixel (8=grayscale)
|
||||
14 N×12 index table (N entries)
|
||||
... ... glyph bitmap data
|
||||
```
|
||||
|
||||
每条索引:
|
||||
```text
|
||||
[0..1] u16 codepoint (Unicode BMP)
|
||||
[2..3] u16 actual_width (pixels)
|
||||
[4..7] u32 data_offset
|
||||
[8..11] u32 data_size
|
||||
```
|
||||
|
||||
索引按 codepoint 升序排列,可用二分查找。
|
||||
|
||||
## 字体文件
|
||||
|
||||
| 文件 | 大小 | 字形数 | 精度 |
|
||||
|------|------|--------|------|
|
||||
| [simhei_16.dbf](file:///d:/Code/Deshab/SYSTEM/system/font/simhei_16.dbf) | 1.8MB | 6858 | 16×16 8bpp |
|
||||
| [simhei_24.dbf](file:///d:/Code/Deshab/SYSTEM/system/font/simhei_24.dbf) | 3.9MB | 6858 | 24×24 8bpp |
|
||||
| [simhei_32.dbf](file:///d:/Code/Deshab/SYSTEM/system/font/simhei_32.dbf) | 6.9MB | 6858 | 32×32 8bpp |
|
||||
|
||||
字形覆盖:GB2312 全部 6763 个简体汉字 + ASCII 32–126 可打印字符。
|
||||
|
||||
## 生成工具
|
||||
|
||||
```bash
|
||||
python CODE/font/mkfont.py <ttf_path> <pixel_size> <output.dbf>
|
||||
```
|
||||
|
||||
依赖:Python 3 + Pillow (`pip install Pillow`)
|
||||
|
||||
## C 头文件
|
||||
|
||||
[dbf.h](file:///d:/Code/Deshab/CODE/font/dbf.h) 定义数据结构和二分查找函数:
|
||||
|
||||
```c
|
||||
#include "dbf.h"
|
||||
const u8 *font = ...; // 加载 .dbf 到内存
|
||||
dbf_header *hdr = (dbf_header *)font;
|
||||
dbf_index_entry *idx = (dbf_index_entry *)(font + 14);
|
||||
int entry = dbf_lookup(idx, hdr->count, codepoint);
|
||||
if (entry >= 0) {
|
||||
u8 *glyph = font + idx[entry].offset;
|
||||
u16 w = idx[entry].width;
|
||||
u16 h = hdr->height;
|
||||
// 逐行渲染 8bpp 灰度位图
|
||||
}
|
||||
```
|
||||
|
||||
## 使用方式
|
||||
|
||||
1. 启动时将 `.dbf` 文件通过 boot module 或 FAT32 加载到内存
|
||||
2. GBK/GB2312 双字节序列转为 Unicode codepoint 后查表
|
||||
3. 8bpp 灰度可直接 alpha-blend 到 framebuffer
|
||||
@@ -0,0 +1,57 @@
|
||||
/* dbf.h — Deshab Bitmap Font format reader
|
||||
*
|
||||
* DBF File Layout:
|
||||
* [0..3] magic "DBF\x10" (version 16)
|
||||
* [4..7] u32 glyph_count
|
||||
* [8..9] u16 default_glyph_width
|
||||
* [10..11] u16 default_glyph_height
|
||||
* [12..13] u16 bits_per_pixel (8 = grayscale, 1 = BW)
|
||||
* [14..] index[] array of glyph_count entries:
|
||||
* [0..1] u16 codepoint (Unicode BMP)
|
||||
* [2..3] u16 actual_width (pixels)
|
||||
* [4..7] u32 data_offset (from file start)
|
||||
* [8..11] u32 data_size (bytes)
|
||||
* Each index entry is 12 bytes.
|
||||
* [14 + index*12 ..] glyph_bitmap[] raw 8bpp row-major data
|
||||
*
|
||||
* Usage:
|
||||
* const u8 *font_data = ...; // mmap or load entire .dbf
|
||||
* dbf_header *hdr = (dbf_header *)font_data;
|
||||
* dbf_index_entry *idx = (dbf_index_entry *)(font_data + 14);
|
||||
* // binary search for codepoint in idx[0..hdr->count-1]
|
||||
* // glyph data at font_data + idx[i].offset, size idx[i].size
|
||||
*/
|
||||
|
||||
#ifndef DBF_H
|
||||
#define DBF_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t magic[4]; /* "DBF\x10" */
|
||||
uint32_t count;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t bpp;
|
||||
} __attribute__((packed)) dbf_header;
|
||||
|
||||
typedef struct {
|
||||
uint16_t codepoint;
|
||||
uint16_t width;
|
||||
uint32_t offset;
|
||||
uint32_t size;
|
||||
} __attribute__((packed)) dbf_index_entry;
|
||||
|
||||
/* Binary search for codepoint. Returns entry index or -1. */
|
||||
static inline int dbf_lookup(dbf_index_entry *idx, uint32_t count, uint16_t cp) {
|
||||
int lo = 0, hi = (int)count - 1;
|
||||
while (lo <= hi) {
|
||||
int mid = (lo + hi) / 2;
|
||||
if (idx[mid].codepoint == cp) return mid;
|
||||
if (idx[mid].codepoint < cp) lo = mid + 1;
|
||||
else hi = mid - 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,106 @@
|
||||
"""mkfont.py — Deshab Bitmap Font generator
|
||||
Usage: python mkfont.py <ttf_path> <size> <output.dbf>
|
||||
Renders GB2312 charset + ASCII to a packed bitmap font file (.dbf)
|
||||
"""
|
||||
|
||||
import struct
|
||||
import sys
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
|
||||
DBF_MAGIC = b"DBF\x10"
|
||||
|
||||
# GB2312 codepoints for simplified Chinese (3755 level-1 + 3008 level-2)
|
||||
def gb2312_codepoints():
|
||||
cps = []
|
||||
# ASCII 32-126
|
||||
for c in range(32, 127):
|
||||
cps.append(c)
|
||||
# GB2312 level 1: 0xB0A1 - 0xB0FE, ... , 0xD7F9
|
||||
for hi in range(0xB0, 0xD8):
|
||||
for lo in range(0xA1, 0xFF):
|
||||
cps.append((hi << 8) | lo)
|
||||
# GB2312 level 2: skip duplicates, 0xD8A1 - 0xF7FE
|
||||
for hi in range(0xD8, 0xF8):
|
||||
for lo in range(0xA1, 0xFF):
|
||||
if hi == 0xD7 and lo > 0xF9:
|
||||
break
|
||||
cps.append((hi << 8) | lo)
|
||||
return cps
|
||||
|
||||
|
||||
def render_font(ttf_path, size, output_path, bpp=8):
|
||||
font = ImageFont.truetype(ttf_path, size)
|
||||
cps = gb2312_codepoints()
|
||||
|
||||
# Build index and data
|
||||
glyph_w = size
|
||||
glyph_h = size
|
||||
data_parts = []
|
||||
index_entries = []
|
||||
|
||||
ascii_w = size * 3 // 4 # narrower for ASCII
|
||||
|
||||
for cp in cps:
|
||||
if cp < 128:
|
||||
# ASCII — use narrower glyph
|
||||
ch = chr(cp)
|
||||
w = ascii_w
|
||||
else:
|
||||
# GB2312 byte pair → Unicode
|
||||
hi = (cp >> 8) & 0xFF
|
||||
lo = cp & 0xFF
|
||||
try:
|
||||
ch = bytes([hi, lo]).decode("gb2312")
|
||||
except:
|
||||
continue
|
||||
w = glyph_w
|
||||
|
||||
img = Image.new("L", (w, glyph_h), 0)
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.text((0, 0), ch, font=font, fill=255)
|
||||
img = img.resize((w, glyph_h), Image.LANCZOS)
|
||||
|
||||
raw = img.tobytes()
|
||||
if bpp == 1:
|
||||
# pack to 1bpp
|
||||
packed = bytearray()
|
||||
for y in range(glyph_h):
|
||||
row = 0
|
||||
for x in range(w):
|
||||
if raw[y * w + x] >= 128:
|
||||
row |= (1 << (7 - (x & 7)))
|
||||
if (x & 7) == 7:
|
||||
packed.append(row)
|
||||
row = 0
|
||||
if w & 7:
|
||||
packed.append(row)
|
||||
glyph_data = bytes(packed)
|
||||
else:
|
||||
glyph_data = raw
|
||||
|
||||
offset = sum(len(d) for d in data_parts)
|
||||
data_parts.append(glyph_data)
|
||||
index_entries.append((cp, w, offset, len(glyph_data)))
|
||||
|
||||
# Write file
|
||||
total_data = sum(len(d) for d in data_parts)
|
||||
print(f"Glyphs: {len(index_entries)}, Data: {total_data} bytes")
|
||||
|
||||
with open(output_path, "wb") as f:
|
||||
f.write(DBF_MAGIC)
|
||||
f.write(struct.pack("<I", len(index_entries)))
|
||||
f.write(struct.pack("<HHH", glyph_w, glyph_h, bpp))
|
||||
for cp, w, off, sz in index_entries:
|
||||
f.write(struct.pack("<HHII", cp, w, off, sz))
|
||||
for d in data_parts:
|
||||
f.write(d)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 4:
|
||||
print(f"Usage: {sys.argv[0]} <ttf_path> <size> <output.dbf>")
|
||||
sys.exit(1)
|
||||
ttf = sys.argv[1]
|
||||
sz = int(sys.argv[2])
|
||||
out = sys.argv[3]
|
||||
render_font(ttf, sz, out)
|
||||
@@ -0,0 +1,57 @@
|
||||
"""render_embedded.py — render FirstInit Chinese strings at varied sizes"""
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
|
||||
ttf = "SYSTEM/system/font/simhei.ttf"
|
||||
|
||||
texts = [
|
||||
("welcome", "欢迎使用 Deshab", 48), # only welcome stays large
|
||||
("setup", "接下来让我们来引导你设置你的系统", 24), # 32 -> 24
|
||||
("title", "创建你的 Deshab 账户", 24),
|
||||
("computer", "计算机名", 24),
|
||||
("username", "用户名", 24),
|
||||
("password", "密码", 24),
|
||||
("hint", "按 Enter 继续,Backspace 删除", 16), # 20 -> 16
|
||||
("prefs_title", "设置系统偏好", 24),
|
||||
("prefs_language", "语言", 22),
|
||||
("prefs_region", "地区", 22),
|
||||
("prefs_timezone", "时区", 22),
|
||||
("prefs_keyboard", "键盘布局", 22),
|
||||
("prefs_theme", "主题", 22),
|
||||
("prefs_hint", "Enter 切换选项,方向键切换项目,鼠标点击选择", 16),
|
||||
("network_title", "网络设置", 24),
|
||||
("net_mode", "网络模式", 22),
|
||||
("net_device", "网络设备", 22),
|
||||
("net_ip", "地址获取", 22),
|
||||
("net_dns", "DNS", 22),
|
||||
("net_hint", "Enter 切换选项,方向键切换项目,鼠标点击选择", 16),
|
||||
("privacy_title", "隐私与诊断", 24),
|
||||
("done", "设置完成,请重启系统", 24), # final status
|
||||
]
|
||||
|
||||
lines = []
|
||||
lines.append("/* Auto-generated */")
|
||||
lines.append("")
|
||||
|
||||
for name, text, size in texts:
|
||||
font = ImageFont.truetype(ttf, size)
|
||||
bbox = font.getbbox(text)
|
||||
w = bbox[2]
|
||||
h = size + 6
|
||||
img = Image.new("L", (w, h), 0)
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.text((0, 3), text, font=font, fill=255)
|
||||
pixels = list(img.tobytes())
|
||||
|
||||
lines.append(f"static const int g_txt_{name}_w = {w};")
|
||||
lines.append(f"static const int g_txt_{name}_h = {h};")
|
||||
lines.append(f"static const unsigned char g_txt_{name}[{w}*{h}] = {{")
|
||||
for y in range(h):
|
||||
row = ", ".join(str(pixels[y*w + x]) for x in range(w))
|
||||
lines.append(f" {row},")
|
||||
lines.append("};")
|
||||
lines.append("")
|
||||
|
||||
with open("CODE/firstInit/text_bitmaps.c", "w", encoding="ascii") as f:
|
||||
f.write("\n".join(lines))
|
||||
|
||||
print("Generated CODE/firstInit/text_bitmaps.c")
|
||||
@@ -0,0 +1,31 @@
|
||||
"""render_text.py — pre-render specific Chinese strings to C arrays"""
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
|
||||
def render(ttf, texts, size, var_prefix):
|
||||
font = ImageFont.truetype(ttf, size)
|
||||
for name, text in texts:
|
||||
w = font.getbbox(text)[2]
|
||||
h = size + 4
|
||||
img = Image.new("L", (w, h), 0)
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.text((0, 2), text, font=font, fill=255)
|
||||
|
||||
pixels = list(img.tobytes())
|
||||
print(f"/* {text} — {w}x{h} */")
|
||||
print(f"static const int {var_prefix}_{name}_w = {w};")
|
||||
print(f"static const int {var_prefix}_{name}_h = {h};")
|
||||
print(f"static const unsigned char {var_prefix}_{name}_data[{w}*{h}] = {{")
|
||||
for y in range(h):
|
||||
row = ", ".join(str(pixels[y*w + x]) for x in range(w))
|
||||
print(f" {row},")
|
||||
print("};")
|
||||
print()
|
||||
|
||||
texts = [
|
||||
("welcome", "欢迎使用 Deshab"),
|
||||
("setup", "接下来让我们来引导你设置你的系统"),
|
||||
]
|
||||
# Generate for multiple sizes
|
||||
for sz in [24]:
|
||||
print(f"// ===== size={sz}px =====")
|
||||
render("SYSTEM/system/font/simhei.ttf", texts, sz, f"txt{sz}")
|
||||
Reference in New Issue
Block a user