printk.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Created by longjin on 2022/1/21.
  3. //
  4. #pragma once
  5. #pragma GCC push_options
  6. #pragma GCC optimize("O0")
  7. #define PAD_ZERO 1 // 0填充
  8. #define LEFT 2 // 靠左对齐
  9. #define RIGHT 4 // 靠右对齐
  10. #define PLUS 8 // 在正数前面显示加号
  11. #define SPACE 16
  12. #define SPECIAL 32 // 在八进制数前面显示 '0o',在十六进制数前面显示 '0x' 或 '0X'
  13. #define SMALL 64 // 十进制以上数字显示小写字母
  14. #define SIGN 128 // 显示符号位
  15. #define is_digit(c) ((c) >= '0' && (c) <= '9') // 用来判断是否是数字的宏
  16. // 字体颜色的宏定义
  17. #define WHITE 0x00ffffff //白
  18. #define BLACK 0x00000000 //黑
  19. #define RED 0x00ff0000 //红
  20. #define ORANGE 0x00ff8000 //橙
  21. #define YELLOW 0x00ffff00 //黄
  22. #define GREEN 0x0000ff00 //绿
  23. #define BLUE 0x000000ff //蓝
  24. #define INDIGO 0x0000ffff //靛
  25. #define PURPLE 0x008000ff //紫
  26. // 异常的宏定义
  27. #define EPOS_OVERFLOW 1 // 坐标溢出
  28. #define EFB_MISMATCH 2 // 帧缓冲区与指定的屏幕大小不匹配
  29. #define EUNSUPPORTED 3 // 当前操作暂不被支持
  30. #include "font.h"
  31. #include "glib.h"
  32. //#include "linkage.h"
  33. #include <stdarg.h>
  34. struct printk_screen_info
  35. {
  36. int width, height; //屏幕大小
  37. int max_x, max_y; // 最大x、y字符数
  38. int x, y; //光标位置
  39. int char_size_x, char_size_y;
  40. uint *FB_address; //帧缓冲区首地址
  41. unsigned long FB_length; // 帧缓冲区长度(乘以4才是字节数)
  42. };
  43. extern unsigned char font_ascii[256][16]; //导出ascii字体的bitmap(8*16大小) ps:位于font.h中
  44. /**
  45. * @brief 初始化printk的屏幕信息
  46. *
  47. * @param char_size_x 字符的列坐标
  48. * @param char_size_y 字符的行坐标
  49. */
  50. int printk_init(const int char_size_x, const int char_size_y);
  51. /**
  52. * @brief 将字符串按照fmt和args中的内容进行格式化,然后保存到buf中
  53. *
  54. * @param buf 结果缓冲区
  55. * @param fmt 格式化字符串
  56. * @param args 内容
  57. * @return 最终字符串的长度
  58. */
  59. int vsprintf(char *buf, const char *fmt, va_list args);
  60. /**
  61. * @brief 格式化打印字符串
  62. *
  63. * @param FRcolor 前景色
  64. * @param BKcolor 背景色
  65. * @param ... 格式化字符串
  66. */
  67. #define printk(...) printk_color(WHITE, BLACK, __VA_ARGS__)
  68. int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ...);
  69. /**
  70. * @brief 获取VBE帧缓冲区长度
  71. */
  72. ul get_VBE_FB_length();
  73. /**
  74. * @brief 设置pos变量中的VBE帧缓存区的线性地址
  75. * @param virt_addr VBE帧缓存区线性地址
  76. */
  77. void set_pos_VBE_FB_addr(uint* virt_addr);
  78. /**
  79. * @brief 使能滚动动画
  80. *
  81. */
  82. void printk_enable_animation();
  83. /**
  84. * @brief 禁用滚动动画
  85. *
  86. */
  87. void printk_disable_animation();
  88. /**
  89. * @brief 格式化字符串并输出到buf
  90. *
  91. * @param buf 输出缓冲区
  92. * @param fmt 格式
  93. * @param ... 参数
  94. * @return int 字符串长度
  95. */
  96. int sprintk(char *buf, const char *fmt, ...);
  97. #pragma GCC pop_options