9 附录

这本书如果按顺序读下来的话应该还是一本不错的书,不过在读过一遍之后,忽然想知道关于某个知识点是在哪里讲解的,找起来可就麻烦了。此外,如果对于某个函数的写法不太理解,想找到这个写法是在哪个章节提到的,就更加麻烦了。

因此,我们在这里提供了一个简单的函数索引。它是在bootpack.h和apilib.h的代码中加上注释所构成的,通过这个索引,就可以追溯到某个函数是在哪个章节进行过修改了。

bootpack.h

  1. /* asmhead.nas */
  2. struct BOOTINFO { /* 0x0ff0.0x0fff */ /* 5.2, 6.3, 18.7 */
  3. char cyls; /* 引导扇区读取到磁盘的哪个位置 */
  4. char leds; /* 引导时键盘的LED状态 */
  5. char vmode; /* 显卡的颜色位数 */
  6. char reserve;
  7. short scrnx, scrny; /* 画面分辨率 */
  8. char *vram;
  9. };
  10. #define ADR_BOOTINFO 0x00000ff0
  11. #define ADR_DISKIMG 0x00100000
  12. /* naskfunc.nas */
  13. void io_hlt(void); /* 3.9, 4.6 */
  14. void io_cli(void); /* 4.6 */
  15. void io_sti(void); /* 4.6 */
  16. void io_stihlt(void); /* 4.6 */
  17. int io_in8(int port); /* 4.6 */
  18. void io_out8(int port, int data); /* 4.6 */
  19. int io_load_eflags(void); /* 4.6 */
  20. void io_store_eflags(int eflags); /* 4.6 */
  21. void load_gdtr(int limit, int addr); /* 6.4 */
  22. void load_idtr(int limit, int addr);
  23. int load_cr0(void); /* 9.2 */
  24. void store_cr0(int cr0); /* 9.2 */
  25. void load_tr(int tr); /* 15.1 */
  26. void asm_inthandler0c(void); /* 22.2 */
  27. void asm_inthandler0d(void); /* 21.5, 21.6 */
  28. void asm_inthandler20(void); /* 12.1, 21.4, 21.6 */
  29. void asm_inthandler21(void); /* 6.6 */
  30. void asm_inthandler2c(void);
  31. unsigned int memtest_sub(unsigned int start, unsigned int end); /* 9.2, 9.3 */
  32. void farjmp(int eip, int cs); /* 15.3 */
  33. void farcall(int eip, int cs); /* 20.4 */
  34. void asm_hrb_api(void); /* 20.8, 21.4, 21.6 */
  35. void start_app(int eip, int cs, int esp, int ds, int *tss_esp0); /* 21.4, 21.6 */
  36. void asm_end_app(void); /* 22.3 */
  37. /* fifo.c */
  38. struct FIFO32 { /* 13.4, 16.2 */
  39. int *buf;
  40. int p, q, size, free, flags;
  41. struct TASK *task;
  42. };
  43. void fifo32_init(struct FIFO32 *fifo, int size, int *buf, struct TASK *task); /* 13.4, 16.2 */
  44. int fifo32_put(struct FIFO32 *fifo, int data); /* 13.4, 16.2, 16.4, 16.5 */
  45. int fifo32_get(struct FIFO32 *fifo); /* 13.4 */
  46. int fifo32_status(struct FIFO32 *fifo); /* 13.4 */
  47. /* graphic.c */
  48. void init_palette(void); /* 4.6, 25.2 */
  49. void set_palette(int start, int end, unsigned char *rgb); /* 4.6 */
  50. void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1); /* 4.7 */
  51. void init_screen8(char *vram, int x, int y);
  52. void putfont8(char *vram, int xsize, int x, int y, char c, char *font); /* 5.4 */
  53. void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s); /* 5.6, 28.5, 28.6, 28.7 */
  54. void init_mouse_cursor8(char *mouse, char bc); /* 5.8 */
  55. void putblock8_8(char *vram, int vxsize, int pxsize, /* 5.8 */
  56. int pysize, int px0, int py0, char *buf, int bxsize);
  57. #define COL8_000000 0
  58. #define COL8_FF0000 1
  59. #define COL8_00FF00 2
  60. #define COL8_FFFF00 3
  61. #define COL8_0000FF 4
  62. #define COL8_FF00FF 5
  63. #define COL8_00FFFF 6
  64. #define COL8_FFFFFF 7
  65. #define COL8_C6C6C6 8
  66. #define COL8_840000 9
  67. #define COL8_008400 10
  68. #define COL8_848400 11
  69. #define COL8_000084 12
  70. #define COL8_840084 13
  71. #define COL8_008484 14
  72. #define COL8_848484 15
  73. /* dsctbl.c */
  74. struct SEGMENT_DESCRIPTOR { /* 5.9, 6.4 */
  75. short limit_low, base_low;
  76. char base_mid, access_right;
  77. char limit_high, base_high;
  78. };
  79. struct GATE_DESCRIPTOR { /* 5.9 */
  80. short offset_low, selector;
  81. char dw_count, access_right;
  82. short offset_high;
  83. };
  84. void init_gdtidt(void); /* 5.9, 12.1, 20.5, 20.8, 21.5, 21.6, 22.2 */
  85. void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar); /* 5.9, 6.4 */
  86. void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar); /* 5.9 */
  87. #define ADR_IDT 0x0026f800
  88. #define LIMIT_IDT 0x000007ff
  89. #define ADR_GDT 0x00270000
  90. #define LIMIT_GDT 0x0000ffff
  91. #define ADR_BOTPAK 0x00280000
  92. #define LIMIT_BOTPAK 0x0007ffff
  93. #define AR_DATA32_RW 0x4092
  94. #define AR_CODE32_ER 0x409a
  95. #define AR_LDT 0x0082
  96. #define AR_TSS32 0x0089
  97. #define AR_INTGATE32 0x008e
  98. /* int.c */
  99. void init_pic(void); /* 6.5 */
  100. #define PIC0_ICW1 0x0020
  101. #define PIC0_OCW2 0x0020
  102. #define PIC0_IMR 0x0021
  103. #define PIC0_ICW2 0x0021
  104. #define PIC0_ICW3 0x0021
  105. #define PIC0_ICW4 0x0021
  106. #define PIC1_ICW1 0x00a0
  107. #define PIC1_OCW2 0x00a0
  108. #define PIC1_IMR 0x00a1
  109. #define PIC1_ICW2 0x00a1
  110. #define PIC1_ICW3 0x00a1
  111. #define PIC1_ICW4 0x00a1
  112. /* keyboard.c */
  113. void inthandler21(int *esp); /* 6.6, 7.1, 7.2, 7.3, 7.4, 7.5, 13.4 */
  114. void wait_KBC_sendready(void); /* 7.6 */
  115. void init_keyboard(struct FIFO32 *fifo, int data0); /* 7.6, 13.4 */
  116. #define PORT_KEYDAT 0x0060
  117. #define PORT_KEYCMD 0x0064
  118. /* mouse.c */
  119. struct MOUSE_DEC { /* 8.2, 8.3 */
  120. unsigned char buf[3], phase;
  121. int x, y, btn;
  122. };
  123. void inthandler2c(int *esp); /* 6.6, 7.7 */
  124. void enable_mouse(struct FIFO32 *fifo, int data0, struct MOUSE_DEC *mdec); /* 7.6, 8.2, 13.4 */
  125. int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat); /* 8.2, 8.3 */
  126. /* memory.c */
  127. #define MEMMAN_FREES 4090 /* 约32KB */
  128. #define MEMMAN_ADDR 0x003c0000
  129. struct FREEINFO { /* 剩余容量信息 */ /* 9.4 */
  130. unsigned int addr, size;
  131. };
  132. struct MEMMAN { /*内存管理*/ /* 9.4 */
  133. int frees, maxfrees, lostsize, losts;
  134. struct FREEINFO free[MEMMAN_FREES];
  135. };
  136. unsigned int memtest(unsigned int start, unsigned int end); /* 9.2 */
  137. void memman_init(struct MEMMAN *man); /* 9.4 */
  138. unsigned int memman_total(struct MEMMAN *man); /* 9.4 */
  139. unsigned int memman_alloc(struct MEMMAN *man, unsigned int size); /* 9.4 */
  140. int memman_free(struct MEMMAN *man, unsigned int addr, unsigned int size); /* 9.4 */
  141. unsigned int memman_alloc_4k(struct MEMMAN *man, unsigned int size); /* 10.1 */
  142. int memman_free_4k(struct MEMMAN *man, unsigned int addr, unsigned int size); /* 10.1 */
  143. /* sheet.c */
  144. #define MAX_SHEETS 256
  145. struct SHEET { /* 10.2, 11.3, 23.8 */
  146. unsigned char *buf;
  147. int bxsize, bysize, vx0, vy0, col_inv, height, flags;
  148. struct SHTCTL *ctl;
  149. struct TASK *task;
  150. };
  151. struct SHTCTL { /* 10.2, 11.8 */
  152. unsigned char *vram, *map;
  153. int xsize, ysize, top;
  154. struct SHEET *sheets[MAX_SHEETS];
  155. struct SHEET sheets0[MAX_SHEETS];
  156. };
  157. struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize);
  158. /* 10.2, 11.3, 11.8 */
  159. struct SHEET *sheet_alloc(struct SHTCTL *ctl); /* 10.2, 23.8 */
  160. void sheet_setbuf(struct SHEET *sht, unsigned char *buf, int xsize, int ysize, int col_inv);
  161. /* 10.2 */
  162. void sheet_updown(struct SHEET *sht, int height); /* 10.2, 11.3, 11.7, 11.8 */
  163. void sheet_refresh(struct SHEET *sht, int bx0, int by0, int bx1, int by1); /* 10.2, 10.3, 11.3, 11.7, 11.8 */
  164. void sheet_slide(struct SHEET *sht, int vx0, int vy0); /* 10.2, 10.3, 11.3, 11.7, 11.8 */
  165. void sheet_free(struct SHEET *sht); /* 10.2, 11.3 */
  166. /* timer.c */
  167. #define MAX_TIMER 500
  168. struct TIMER { /* 12.4, 13.4, 13.5, 24.8 */
  169. struct TIMER *next;
  170. unsigned int timeout;
  171. char flags, flags2;
  172. struct FIFO32 *fifo;
  173. int data;
  174. };
  175. struct TIMERCTL { /* 12.2, 12.3, 12.4, 12.6, 12.7, 13.5 */
  176. unsigned int count, next;
  177. struct TIMER *t0;
  178. struct TIMER timers0[MAX_TIMER];
  179. };
  180. extern struct TIMERCTL timerctl;
  181. void init_pit(void); /* 12.1, 12.2, 12.3, 12.4, 12.6, 12.7, 13.6 */
  182. struct TIMER *timer_alloc(void); /* 12.4, 12.7, 24.8 */
  183. void timer_free(struct TIMER *timer); /* 12.4 */
  184. void timer_init(struct TIMER *timer, struct FIFO32 *fifo, int data); /* 12.4, 13.4 */
  185. void timer_settime(struct TIMER *timer, unsigned int timeout); /* 12.4, 12.5, 12.6, 12.7, 13.5, 13.6 */
  186. void inthandler20(int *esp); /* 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 13.4, 13.5, 13.6, 15.7 */
  187. int timer_cancel(struct TIMER *timer); /* 24.8 */
  188. void timer_cancelall(struct FIFO32 *fifo); /* 24.8 */
  189. /* mtask.c */
  190. #define MAX_TASKS 1000 /* 最大任务数量 */
  191. #define TASK_GDT0 3 /* TSS从GDT的几号开始分配 */
  192. #define MAX_TASKS_LV 100
  193. #define MAX_TASKLEVELS 10
  194. struct TSS32 { /* 15.1, 16.1 */
  195. int backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3;
  196. int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
  197. int es, cs, ss, ds, fs, gs;
  198. int ldtr, iomap;
  199. };
  200. struct TASK { /* 16.1, 16.4, 16.5, 17.4, 25.6, 26.7, 27.4, 28.3, 28.4, 28.5, 28.6 */
  201. int sel, flags; /* sel代表GDT编号*/
  202. int level, priority;
  203. struct FIFO32 fifo;
  204. struct TSS32 tss;
  205. struct SEGMENT_DESCRIPTOR ldt[2];
  206. struct CONSOLE *cons;
  207. int ds_base, cons_stack;
  208. struct FILEHANDLE *fhandle;
  209. int *fat;
  210. char *cmdline;
  211. unsigned char langmode, langbyte1;
  212. };
  213. struct TASKLEVEL { /* 16.5 */
  214. int running; /*活动的任务数量*/
  215. int now; /*保存当前活动任务的变量*/
  216. struct TASK *tasks[MAX_TASKS_LV];
  217. };
  218. struct TASKCTL { /* 16.1, 16.5 */
  219. int now_lv; /*当前活动的层级 */
  220. char lv_change; /* 下次切换任务时是否需要改变层级 */
  221. struct TASKLEVEL level[MAX_TASKLEVELS];
  222. struct TASK tasks0[MAX_TASKS];
  223. };
  224. extern struct TASKCTL *taskctl;
  225. extern struct TIMER *task_timer;
  226. struct TASK *task_now(void); /* 16.5 */
  227. struct TASK *task_init(struct MEMMAN *memman); /* 16.1, 16.4, 16.5, 17.1, 27.4 */
  228. struct TASK *task_alloc(void); /* 16.1, 22.3, 27.4 */
  229. void task_run(struct TASK *task, int level, int priority); /* 16.1, 16.4, 16.5 */
  230. void task_switch(void); /* 16.1, 16.4, 16.5 */
  231. void task_sleep(struct TASK *task); /* 16.2, 16.5 */
  232. /* window.c */
  233. void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act); /* 11.4, 16.3, 17.3 */
  234. void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l); /* 13.1, 29.1 */
  235. void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c); /* 14.6 */
  236. void make_wtitle8(unsigned char *buf, int xsize, char *title, char act); /* 17.3 */
  237. void change_wtitle8(struct SHEET *sht, char act); /* 24.5 */
  238. /* console.c */
  239. struct CONSOLE { /* 20.1, 23.6 */
  240. struct SHEET *sht;
  241. int cur_x, cur_y, cur_c;
  242. struct TIMER *timer;
  243. };
  244. struct FILEHANDLE { /* 28.3 */
  245. char *buf;
  246. int size;
  247. int pos;
  248. };
  249. void console_task(struct SHEET *sheet, int memtotal);
  250. /* 17.2, 17.4, 18.2, 18.3, 18.4, 18.5, 18.6, 18.7, 19.1, 19.2, 19.3,19.5, 20.1, 20.2, 25.6, 25.10, 26.8, 26.10, 27.2, 28.3, 28.4, 28.5, 28.6 */
  251. void cons_putchar(struct CONSOLE *cons, int chr, char move); /* 20.1, 26.10 */
  252. void cons_newline(struct CONSOLE *cons); /* 20.1, 26.10, 28.6 */
  253. void cons_putstr0(struct CONSOLE *cons, char *s); /* 20.8 */
  254. void cons_putstr1(struct CONSOLE *cons, char *s, int l); /* 20.8 */
  255. void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal);
  256. /* 20.1, 20.6, 20.8, 26.7, 26.9, 26.10, 28.5 */
  257. void cmd_mem(struct CONSOLE *cons, int memtotal); /* 20.1, 20.8 */
  258. void cmd_cls(struct CONSOLE *cons); /* 20.1 */
  259. void cmd_dir(struct CONSOLE *cons); /* 20.1, 20.8 */
  260. void cmd_exit(struct CONSOLE *cons, int *fat); /* 26.7, 26.10 */
  261. void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal); /* 26.9 */
  262. void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal); /* 26.10 */
  263. void cmd_langmode(struct CONSOLE *cons, char *cmdline); /* 28.5, 28.7 */
  264. int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline);
  265. /* 20.6, 21.1, 21.2, 21.4, 21.6, 22.4, 23.8, 24.5, 24.8, 25.6, 25.7, 27.4, 28.3, 28.6, 29.2 */
  266. int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax);
  267. /* 21.6, 22.1, 22.4, 22.5, 22.6, 23.1, 23.2, 23.3, 23.4, 23.5, 23.6, 23.8,
  268. 24.5, 24.7, 24.8, 25.1, 25.4, 25.6, 26.2, 27.2, 28.3, 28.4, 28.7, 29.2, 29.5 */
  269. int *inthandler0d(int *esp); /* 21.6, 22.2, 25.6 */
  270. int *inthandler0c(int *esp); /* 22.2, 25.6 */
  271. void hrb_api_linewin(struct SHEET *sht, int x0, int y0, int x1, int y1, int col); /* 23.4 */
  272. /* file.c */
  273. struct FILEINFO { /* 18.7, 19.1 */
  274. unsigned char name[8], ext[3], type;
  275. char reserve[10];
  276. unsigned short time, date, clustno;
  277. unsigned int size;
  278. };
  279. void file_readfat(int *fat, unsigned char *img); /* 19.3 */
  280. void file_loadfile(int clustno, int size, char *buf, int *fat, char *img); /* 19.3 */
  281. struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max); /* 20.1 */
  282. char *file_loadfile2(int clustno, int *psize, int *fat); /* 29.2 */
  283. /* tek.c */
  284. int tek_getsize(unsigned char *p); /* 29.2 */
  285. int tek_decomp(unsigned char *p, char *q, int size); /* 29.2 */
  286. /* bootpack.c */
  287. struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal); /* 26.10 */
  288. struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal); /* 26.5, 26.7, 26.10 */

■■■■■

apilib.h

  1. void api_putchar(int c); /* 21.2, 21.6, 27.5 */
  2. void api_putstr0(char *s); /* 22.4, 27.5 */
  3. void api_putstr1(char *s, int l); /* 27.5 */
  4. void api_end(void); /* 21.6 */
  5. int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title); /* 22.5 */
  6. void api_putstrwin(int win, int x, int y, int col, int len, char *str); /* 22.6 */
  7. void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col); /* 22.6 */
  8. void api_initmalloc(void); /* 23.1 */
  9. char *api_malloc(int size); /* 23.1 */
  10. void api_free(char *addr, int size); /* 23.1 */
  11. void api_point(int win, int x, int y, int col); /* 23.2 */
  12. void api_refreshwin(int win, int x0, int y0, int x1, int y1); /* 23.3 */
  13. void api_linewin(int win, int x0, int y0, int x1, int y1, int col); /* 23.4 */
  14. void api_closewin(int win); /* 23.5 */
  15. int api_getkey(int mode); /* 23.6 */
  16. int api_alloctimer(void); /* 24.7 */
  17. void api_inittimer(int timer, int data); /* 24.7 */
  18. void api_settimer(int timer, int time); /* 24.7 */
  19. void api_freetimer(int timer); /* 24.7 */
  20. void api_beep(int tone); /* 25.1 */
  21. int api_fopen(char *fname); /* 28.3 */
  22. void api_fclose(int fhandle); /* 28.3 */
  23. void api_fseek(int fhandle, int offset, int mode); /* 28.3 */
  24. int api_fsize(int fhandle, int mode); /* 28.3 */
  25. int api_fread(char *buf, int maxsize, int fhandle); /* 28.3 */
  26. int api_cmdline(char *buf, int maxsize); /* 28.4 */
  27. int api_getlang(void); /* 28.7 */