change pixel def

This commit is contained in:
Yanyan Jiang 2017-06-26 11:36:13 -04:00
parent 1d3338c07c
commit 8118b3675e
9 changed files with 30 additions and 34 deletions

View File

@ -4,7 +4,7 @@
* `_Area`代表一段连续的内存,组成`[start, end)`的左闭右开区间。
* `_Screen`描述系统初始化后的屏幕后续可通过PCI总线设置显示控制器则此设置不再有效
* 屏幕的像素颜色由32位整数`typedef u32 _Pixel;`确定,从高位到低位是`00rrggbb`不论大小端红绿蓝各8位。
* 屏幕的像素颜色由32位整数确定从高位到低位是`00rrggbb`不论大小端红绿蓝各8位。
* 按键代码由`_KEY_XXX`指定,其中`_KEY_NONE = 0`。
* `_RegSet`代表体系结构相关的寄存器组。
* `_Event`表示一个异常/中断事件event域由_EVENT_XXX指定cause由具体事件指定。
@ -34,7 +34,7 @@
* `void _ioe_init();` 初始化Extension。
* `ulong _uptime();` 返回系统启动后的毫秒数。溢出后归零。
* `int _read_key();` 返回按键。如果没有按键返回`_KEY_NONE`。
* `void _draw_p(int x, int y, _Pixel p);` 在(`x`, `y`)坐标绘制像素`p`(非立即生效)。
* `void _draw_p(int x, int y, u32 p);` 在(`x`, `y`)坐标绘制像素`p`(非立即生效)。
* `void _draw_f(_Pixel *p);` 绘制W*H个像素的数组填充整个屏幕非立即生效
* `void _draw_sync();` 保证之前绘制的内容显示在屏幕上。
* `extern _Screen _screen;` 屏幕的描述信息。在`_ioe_init`后调用后可用。
@ -51,7 +51,7 @@
* `_EVENT_TRAP`:系统调用自陷(无cause),系统调用参数将`_RegSet`转换为`intptr_t*`后按次序排列。第一个参数为返回值。
* `_RegSet *_make(_Area kstack, void *entry, void *arg);`创建一个内核上下文,参数arg。
* `void _trap();`在内核态自陷。线程需要睡眠/让出CPU时使用。
* `int _istatus(int enable);`设置中断状态(enable非0时打开)。返回设置前的中断状态。
* `int _istatus(int enable);`设置中断状态(enable非0时打开)。返回设置前的中断状态(0/1)
## Protection Extension

View File

@ -94,9 +94,8 @@ extern _Area _heap;
void _ioe_init();
ulong _uptime();
int _read_key();
typedef u32 _Pixel;
void _draw_p(int x, int y, _Pixel p);
void _draw_f(_Pixel *p);
void _draw_p(int x, int y, u32 p);
void _draw_f(u32 *p);
void _draw_sync();
extern _Screen _screen;

View File

@ -8,12 +8,12 @@ _Screen _screen;
#define KEYDOWN_MASK 0x8000
static inline _Pixel pixel(u8 r, u8 g, u8 b) {
static inline u32 pixel(u8 r, u8 g, u8 b) {
return (r << 16) | (g << 8) | b;
}
static inline u8 R(_Pixel p) { return p >> 16; }
static inline u8 G(_Pixel p) { return p >> 8; }
static inline u8 B(_Pixel p) { return p; }
static inline u8 R(u32 p) { return p >> 16; }
static inline u8 G(u32 p) { return p >> 8; }
static inline u8 B(u32 p) { return p; }
static SDL_Window *window;
static SDL_Renderer *renderer;
@ -26,7 +26,7 @@ static int key_f = 0, key_r = 0;
static SDL_mutex *key_queue_lock;
static SDL_Texture *texture;
static _Pixel fb[W * H];
static u32 fb[W * H];
void gui_init() {
_screen.width = W;
@ -42,11 +42,11 @@ void gui_init() {
key_queue_lock = SDL_CreateMutex();
}
void _draw_p(int x, int y, _Pixel p) {
void _draw_p(int x, int y, u32 p) {
fb[y * W + x] = p;
}
void _draw_f(_Pixel *p) {
void _draw_f(u32 *p) {
memcpy(fb, p, W * H * sizeof(Uint32));
}

View File

@ -19,6 +19,4 @@ void _ioe_init() {
gettimeofday(&boot_time, NULL);
}
void _asye_init() {
}

View File

@ -41,12 +41,12 @@ struct VBEInfo {
u8 reserved1[206];
} __attribute__ ((packed));
static inline _Pixel pixel(u8 r, u8 g, u8 b) {
static inline u32 pixel(u8 r, u8 g, u8 b) {
return (r << 16) | (g << 8) | b;
}
static u8 R(_Pixel p) { return p >> 16; }
static u8 G(_Pixel p) { return p >> 8; }
static u8 B(_Pixel p) { return p; }
static u8 R(u32 p) { return p >> 16; }
static u8 G(u32 p) { return p >> 8; }
static u8 B(u32 p) { return p; }
static struct FBPixel {
u8 b, g, r;
@ -59,14 +59,14 @@ static void vga_init() {
fb = reinterpret_cast<FBPixel*>(info->framebuffer);
}
void _draw_p(int x, int y, _Pixel p) {
void _draw_p(int x, int y, u32 p) {
FBPixel &v = fb[x + y * _screen.width];
v.r = R(p);
v.g = G(p);
v.b = B(p);
}
void _draw_f(_Pixel *p) {
void _draw_f(u32 *p) {
int npx = _screen.width * _screen.height;
for (int i = 0; i < npx; i ++) {
fb[i].r = R(p[i]);

View File

@ -11,12 +11,12 @@ typedef int bool;
#define true 1
#define false 0
static inline _Pixel pixel(u8 r, u8 g, u8 b) {
static inline u32 pixel(u8 r, u8 g, u8 b) {
return (r << 16) | (g << 8) | b;
}
static inline u8 R(_Pixel p) { return p >> 16; }
static inline u8 G(_Pixel p) { return p >> 8; }
static inline u8 B(_Pixel p) { return p; }
static inline u8 R(u32 p) { return p >> 16; }
static inline u8 G(u32 p) { return p >> 8; }
static inline u8 B(u32 p) { return p; }
// Byte Bit Operations
void common_set_bitb(byte *variable, byte position);

View File

@ -113,7 +113,7 @@ void fce_run()
// Rendering
static const _Pixel palette[64] = {
static const u32 palette[64] = {
0x808080, 0x0000BB, 0x3700BF, 0x8400A6, 0xBB006A, 0xB7001E,
0xB30000, 0x912600, 0x7B2B00, 0x003E00, 0x00480D, 0x003C22,
0x002F66, 0x000000, 0x050505, 0x050505, 0xC8C8C8, 0x0059FF,
@ -168,7 +168,6 @@ void xmap_init() {
int main() {
_ioe_init();
_asye_init();
xmap_init();
fce_load_rom(rom_mario_nes);

View File

@ -1,6 +1,6 @@
#include "game.h"
static _Pixel canvas[W][H];
static u32 canvas[W][H];
extern char font8x8_basic[128][8];

View File

@ -4,14 +4,14 @@
const int FPS = 30;
const int N = 32;
static inline _Pixel pixel(u8 r, u8 g, u8 b) {
static inline u32 pixel(u8 r, u8 g, u8 b) {
return (r << 16) | (g << 8) | b;
}
static inline u8 R(_Pixel p) { return p >> 16; }
static inline u8 G(_Pixel p) { return p >> 8; }
static inline u8 B(_Pixel p) { return p; }
static inline u8 R(u32 p) { return p >> 16; }
static inline u8 G(u32 p) { return p >> 8; }
static inline u8 B(u32 p) { return p; }
_Pixel canvas[N][N];
u32 canvas[N][N];
bool used[N][N];
void redraw() {
@ -26,7 +26,7 @@ void redraw() {
_draw_sync();
}
static _Pixel p(int tsc) {
static u32 p(int tsc) {
int b = tsc & 0xff;
return pixel(b * 6, b * 7, b);
}