clean up but not for npc

This commit is contained in:
reccetear 2017-04-22 23:59:22 +08:00
parent 59f17b9edb
commit d444d9981a
9 changed files with 50 additions and 29 deletions

View File

@ -7,6 +7,7 @@ ADDI
ADDIU
SUB
SUBU
NEGU
AND
ANDI
OR

View File

@ -7,6 +7,7 @@ typedef unsigned short u16;
typedef short int i16;
typedef unsigned char u8;
typedef char i8;
typedef u32 size_t;
typedef struct _RegSet {
} _RegSet;

View File

@ -2,17 +2,19 @@
#define __NPC_H__
#define VMEM_ADDR ((void *)0xc0000000)
#define SCR_WIDTH 640
#define SCR_HEIGHT 480
#define SCR_WIDTH 160
#define SCR_HEIGHT 160
#define SCR_SIZE (SCR_WIDTH * SCR_HEIGHT)
//outside R G B(outside draw_p)
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; }
void vga_init();
static inline u32 Getcolor(_Pixel p){
return (R(p) << 8 | G(p) << 4 | B(p) << 2);
//inside R G B(print draw_p)
static inline _Pixel pixel(u8 r, u8 g, u8 b) {
return (r << 16) | (g << 8) | b;
}
void vga_init();
#define KEY_CODE_ADDR ((volatile unsigned int *)0xf0000000)
#define KEY_CODE (*KEY_CODE_ADDR)

View File

@ -4,12 +4,18 @@
int curr_line = 0;
int curr_col = 0;
extern void draw_character(char ch, int x, int y, int color);
extern void draw_character(char ch, int x, int y, _Pixel p);
struct FBPixel {
u8 r : 2;
u8 g : 4;
u8 b : 2;
} *fb;
u32 *vmem = VMEM_ADDR;
void vga_init(){
_screen.width = SCR_WIDTH;
_screen.height = SCR_HEIGHT;
fb = VMEM_ADDR;
}
void _putc(char ch) {
@ -19,7 +25,7 @@ void _putc(char ch) {
curr_line += 8;
}
else{
draw_character(ch,curr_line,curr_col,0x3c);
draw_character(ch,curr_line,curr_col,pixel(0xff,0xff,0xff));
}
if (curr_col + 8 >= SCR_WIDTH) {
curr_line += 8; curr_col = 0;
@ -34,14 +40,22 @@ void _putc(char ch) {
void _draw_f(_Pixel *p) {
int i;
for(i = 0;i < SCR_SIZE; i++){
vmem[i] = Getcolor(p[i]);
fb[i].r = R(p[i]);
fb[i].g = G(p[i]);
fb[i].b = B(p[i]);
}
}
void _draw_p(int x, int y, _Pixel p) {
vmem[x * SCR_WIDTH + y] = p;
fb[x + y * _screen.width].r = R(p);
fb[x + y * _screen.width].g = G(p);
fb[x + y * _screen.width].b = B(p);
}
void _draw_sync() {
//not to do
}
int _peek_key(){
return 0;
}

View File

@ -3,19 +3,18 @@
extern char font8x8_basic[128][8];
void draw_character(char ch, int x, int y, int color) {
void draw_character(char ch, int x, int y, _Pixel p) {
int i, j;
_Pixel c = color;
char *p = font8x8_basic[(int)ch];
char *c = font8x8_basic[(int)ch];
for (i = 0; i < 8; i ++)
for (j = 0; j < 8; j ++)
if ((p[i] >> j) & 1)
_draw_p(x + i, y + j, c);
if ((c[i] >> j) & 1)
_draw_p(y + j, x + i, p);
}
void draw_string(const char *str, int x, int y, int color) {
void draw_string(const char *str, int x, int y, _Pixel p) {
while (*str) {
draw_character(*str ++, x, y, color);
draw_character(*str ++, x, y, p);
if (y + 8 >= SCR_WIDTH) {
x += 8; y = 0;
} else {

View File

@ -1,6 +1,5 @@
#ifndef video_h
#define video_h
void prepare_buffer();
void display_buffer();
#endif

View File

@ -2,7 +2,12 @@
#include "video.h"
extern char font8x8_basic[128][8];
char str[30];
static inline unsigned int pixel(int color){
char r = (color >> 24) & 0xff;
char g = (color >> 16) & 0xff;
char b = (color >> 8) & 0xff;
return (r << 16 | g << 8 | b );
}
static char inline *reverse(char *s)
{
@ -49,7 +54,7 @@ static inline void draw_character(char ch, int x, int y, int color) {
for (i = 0; i < 8; i ++)
for (j = 0; j < 8; j ++)
if ((p[i] >> j) & 1)
_draw_p(y + j, x + i, 0xffffff);
_draw_p(y + j, x + i, pixel(color));
}
static inline void draw_string(const char *str, int x, int y, int color) {
@ -73,17 +78,17 @@ redraw_screen() {
for (it = characters(); it != NULL; it = it->_next) {
static char buf[2];
buf[0] = it->text + 'A'; buf[1] = 0;
draw_string(buf, it->x, it->y, 15);
draw_string(buf, it->x, it->y, 0xff000000);
}
/* 绘制命中数、miss数、最后一次按键扫描码和fps */
const char *key = itoa(last_key_code());
draw_string(key, SCR_HEIGHT - 8, 0, 48);
draw_string(key, SCR_HEIGHT - 8, 0, 0x0000ff00);
hit = itoa(get_hit());
draw_string(hit, 0, SCR_WIDTH - strlen(hit) * 8, 10);
draw_string(hit, 0, SCR_WIDTH - strlen(hit) * 8, 0x0000ff00);
miss = itoa(get_miss());
draw_string(miss, SCR_HEIGHT - 8, SCR_WIDTH - strlen(miss) * 8, 12);
draw_string(miss, SCR_HEIGHT - 8, SCR_WIDTH - strlen(miss) * 8, 0x0000ff00);
const char *fps = itoa(get_fps());
draw_string(fps, 0, 0, 14);
draw_string("FPS", 0, 2 * 8, 14);
draw_string(fps, 0, 0, 0x00ff0000);
draw_string("FPS", 0, strlen(fps) * 8, 0x00ff0000);
}

View File

@ -2,6 +2,7 @@
#include "time.h"
volatile unsigned int tick = 0;
_Pixel fb[1024*768] = {0};
static int real_fps;
void set_fps(int value){
@ -15,7 +16,6 @@ int get_fps(){
int main (){
_trm_init();
_ioe_init();
_asye_init();
int now = 0;
int target = 0;
bool redraw = false;

View File

@ -1,7 +1,7 @@
#include "video.h"
#include "common.h"
_Pixel fb[640 *480] = {0};
extern _Pixel fb[1024*768];
void prepare_buffer(){
_draw_f(fb);