forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   C++ (http://forum.boolean.name/forumdisplay.php?f=22)
-   -   Где ошибка,хелп... (http://forum.boolean.name/showthread.php?t=14826)

RegIon 02.06.2011 17:17

Где ошибка,хелп...
 
Код:

//#include "libgame.h"

#define    NULL    (void*)0

extern void **ftab;

#define COLOR_ROP_TRANSP    0xcc    // transparency
#define COLOR_ROP_NOP        0xf0    // nop - just paint

typedef unsigned char        uint8_t;
typedef unsigned short        uint16_t;
typedef unsigned long        uint32_t;
typedef unsigned long long    uint64_t;
int chars[]={
1,1,1,1,1,1,1,1, //пробел
1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,1,
0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1
};
typedef struct gfx_rect {
    uint16_t    x, y;
    uint16_t    width, height;
} gfx_rect_t;

typedef struct key_data {
    uint32_t    key1;
    uint32_t    key2;
} key_data_t;

void (*dprintf)(char *fmt, ...);

//int (*gfx_init)();
int (*gfx_init)(void *buffer, int buffsize);
int (*gfx_set_framebuffer)(int width, int height);
int (*gfx_set_display_screen)(gfx_rect_t *rect);//int with, int height);
int (*gfx_set_cammmode)(int mode);
int (*gfx_set_fgcolor)(uint32_t *color);
uint32_t (*gfx_get_fgcolor)();
int (*gfx_set_colorrop)(uint32_t rop);
int (*gfx_fillrect)(gfx_rect_t *rect);
int (*gfx_enable_feature)(uint32_t feature);
int (*gfx_flush)();
int (*gfx_paint)();

uint32_t (*get_time)();    // returns system ticks equivalent
void (*get_keys)(key_data_t *keys);//uint64_t *keys);

#define    FUNC(n)        *(ftab + (n >> 2))

#define    MAKE_RGB(r, g, b) (r & 0xff) | ((g & 0xff) << 8) | ((b & 0xff) << 16);
int i,n;
int main()
{
    int i;
    gfx_rect_t rect;
    uint32_t color;
    uint16_t fbuff[320*240];
    key_data_t keys, no_keys;

    // setup function pointers
    dprintf              = FUNC(0x04);
    gfx_init              = FUNC(0x38);
    gfx_set_framebuffer  = FUNC(0x90);
    gfx_set_display_screen= FUNC(0x54);
    gfx_set_cammmode      = FUNC(0x8c);
    gfx_set_colorrop      = FUNC(0x3c);
    gfx_set_fgcolor      = FUNC(0x44);
    gfx_get_fgcolor      = FUNC(0x48);
    gfx_fillrect          = FUNC(0xc4);
    gfx_enable_feature    = FUNC(0x7c);
    gfx_flush            = FUNC(0xc);
    gfx_paint            = FUNC(0x10);
    get_time              = FUNC(0x124);
    get_keys              = FUNC(0x100);

//    dprintf("Hello World!\n");эт нихрена не пашет,своё делаю..
    gfx_init(fbuff, sizeof(fbuff));

    rect.x = 0;
    rect.y = 0;
    rect.width = 320;
    rect.height = 240;

    gfx_set_framebuffer(320,240);
    gfx_set_display_screen(&rect);//320, 240);


    for(i=0;i<8;i++){
    for(n=0;n<8;n++){
    rect.x = 20+i;
    rect.y = 20+n;
    rect.width = 1;
    rect.height = 1;

  if(chars[i*n]==1 )color = MAKE_RGB(255,255,255);
  if(chars[i*n]==0 )color = MAKE_RGB(0,255,255);     
    gfx_set_fgcolor(&color);
    gfx_set_colorrop(COLOR_ROP_NOP);
    gfx_fillrect(&rect);
}
}

    gfx_set_colorrop(COLOR_ROP_NOP);
    gfx_flush();
    gfx_paint();
   
    get_keys(&no_keys);
//    no_keys.key2 &= ~0x5ff0;
    while (1) {
   
        get_keys(&keys);
//        keys.key2 &= ~0x5ff0;
        if (keys.key2!=no_keys.key2) break;
    }

    return 0;
}

(код на процессор spmp8000).
должен рисовать на экране пмп квадрат 8*8 толщиной линии в 1 пиксель,х*ею какую-то рисует типа
11111111
1111100
1110000
1100000
(типо так,картинку не могу...мелко очень)
где косяк?и ещё,у кого-нить есть набор символо аск2 в текстовом(как ниже)
Код:

int chars[]={
0,0,0,0,0,0,0,0,//пробел
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,1,1,0,0,0,//!
0,0,0,1,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,1,1,0,0,0,
0,1,1,0,1,1,0,0,//"
0,1,1,0,1,1,0,0,
0,1,0,0,1,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};

,а то все символы как-то руками не пркол

Dream 02.06.2011 18:03

Ответ: Где ошибка,хелп...
 
извени, но ты кажется ошибся языком

RegIon 03.06.2011 07:00

Ответ: Где ошибка,хелп...
 
чем...не шарп ведь,а С(писал бы на с++,его б компилил...)?ну тогда надо тему "другие платформы й языки"(не раз уже просил)
так кто-нить помогите....

HolyDel 03.06.2011 07:19

Ответ: Где ошибка,хелп...
 
Цитата:

chars[i*n]
чо это?
наверное надо:
Цитата:

chars[i*8+n]
?

RegIon 03.06.2011 07:28

Ответ: Где ошибка,хелп...
 
гуд....спасиб(с таких масивов не доводилось читать)(:-D чуть косячокВложение 13923)
P.S исправил..

RegIon 03.06.2011 08:41

Ответ: Где ошибка,хелп...
 
Код:


//#include "libgame.h"

#define    NULL    (void*)0

extern void **ftab;

#define COLOR_ROP_TRANSP    0xcc    // transparency
#define COLOR_ROP_NOP        0xf0    // nop - just paint

typedef unsigned char        uint8_t;
typedef unsigned short        uint16_t;
typedef unsigned long        uint32_t;
typedef unsigned long long    uint64_t;
int chars[]={
0,0,0,0,0,0,0,0,//пробел
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,1,1,0,0,0,//!
0,0,0,1,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,1,1,0,0,0,
0,0,0,1,1,0,0,0,
0,1,1,0,1,1,0,0,//"
0,1,1,0,1,1,0,0,
0,1,0,0,1,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
typedef struct gfx_rect {
    uint16_t    x, y;
    uint16_t    width, height;
} gfx_rect_t;

typedef struct key_data {
    uint32_t    key1;
    uint32_t    key2;
} key_data_t;

void  altprint(int chars[],int size,int x,int y,char string[],int len);
void (*dprintf)(char *fmt, ...);

//int (*gfx_init)();
int (*gfx_init)(void *buffer, int buffsize);
int (*gfx_set_framebuffer)(int width, int height);
int (*gfx_set_display_screen)(gfx_rect_t *rect);//int with, int height);
int (*gfx_set_cammmode)(int mode);
int (*gfx_set_fgcolor)(uint32_t *color);
uint32_t (*gfx_get_fgcolor)();
int (*gfx_set_colorrop)(uint32_t rop);
int (*gfx_fillrect)(gfx_rect_t *rect);
int (*gfx_enable_feature)(uint32_t feature);
int (*gfx_flush)();
int (*gfx_paint)();

uint32_t (*get_time)();    // returns system ticks equivalent
void (*get_keys)(key_data_t *keys);//uint64_t *keys);

#define    FUNC(n)        *(ftab + (n >> 2))

#define    MAKE_RGB(r, g, b) (r & 0xff) | ((g & 0xff) << 8) | ((b & 0xff) << 16);
//int i,n,p;
int main()
{
    //int i;
    gfx_rect_t rect;
    //uint32_t color;
    uint16_t fbuff[320*240];
    key_data_t keys, no_keys;

    // setup function pointers
    dprintf              = FUNC(0x04);
    gfx_init              = FUNC(0x38);
    gfx_set_framebuffer  = FUNC(0x90);
    gfx_set_display_screen= FUNC(0x54);
    gfx_set_cammmode      = FUNC(0x8c);
    gfx_set_colorrop      = FUNC(0x3c);
    gfx_set_fgcolor      = FUNC(0x44);
    gfx_get_fgcolor      = FUNC(0x48);
    gfx_fillrect          = FUNC(0xc4);
    gfx_enable_feature    = FUNC(0x7c);
    gfx_flush            = FUNC(0xc);
    gfx_paint            = FUNC(0x10);
    get_time              = FUNC(0x124);
    get_keys              = FUNC(0x100);

//    dprintf("Hello World!\n");
    gfx_init(fbuff, sizeof(fbuff));

    rect.x = 0;
    rect.y = 0;
    rect.width = 320;
    rect.height = 240;

    gfx_set_framebuffer(320,240);
    gfx_set_display_screen(&rect);//320, 240);


    altprint(chars,2,20,20,'!!!!!!!!"!!!!!!!',3);
    gfx_set_colorrop(COLOR_ROP_NOP);
    gfx_flush();
    gfx_paint();
   
    get_keys(&no_keys);
//    no_keys.key2 &= ~0x5ff0;
    while (1) {
   
        get_keys(&keys);
//        keys.key2 &= ~0x5ff0;
        if (keys.key2!=no_keys.key2) break;
    }

    return 0;
}
void altprint(int chars[],int size,int x,int y,char string[],int len){


int i,n,p,z,cod;
gfx_rect_t point;
uint32_t c;
for(z=0;string[z];z++){
cod=string[z];
//}
//for(p=1;p<len+1;p++){
    for(i=0;i<8;i++){
    for(n=0;n<8;n++){
    point.x = z*20+i*size;
    point.y = 20+n*size;
    point.width = size;
    point.height = size;

  c = MAKE_RGB(255,255,255); 
    gfx_set_fgcolor(&c);
    gfx_set_colorrop(COLOR_ROP_NOP);
    if(chars[(cod-32)*64+n*8+i]==1 )gfx_fillrect(&point);
 }
 }
 }
}

чет не может напринтить на экране "(кавычку),правильно ведь делаю?

SBJoker 03.06.2011 10:15

Ответ: Где ошибка,хелп...
 
используй двойные кавычки для строк, управляющие символы экранируй слэшем
"\"" - кавычка.

RegIon 03.06.2011 10:47

Ответ: Где ошибка,хелп...
 
ну у кого-нить есть набор аск2 как у мя в коде,пусть даже больше(у меня аж 4 символа)?? туго руками

RegIon 03.06.2011 11:27

Ответ: Где ошибка,хелп...
 
косяк,компилятор КРИЧИТ на функцию ASM в math.h,че-нить сделать можно???или как-то без асамблера можно(ну корень возможно,а вот sin,tan,cos и т.д-нет)

RegIon 03.06.2011 17:02

Ответ: Где ошибка,хелп...
 
Код:

//целый корень....
int isqrt4(unsigned x) {
  unsigned m, y, b;
  m = 0x40000000;
  y = 0;
  while(m != 0) {              // Do 16 times.
      b = y | m;
      y = y >> 1;
      if (x >= b) {  x = x - b; y = y | m; }
      m = m >> 2;
  }
  return y;
  }
 
float sinus(float z)
{  double esp=100000
    float prev = z;
    float S = z;
    float check;
    int iterations_limit = 10000;
    int i;
    /* можно указать максимальное количество итераций
    * на случай, если точность не будет достигнута */
 
    for(i= 0; i < iterations_limit; ++i)
    {
        S += prev*(-1)*z*z / ((2*i + 3)*(2*i + 2));
        check = prev;
        prev = prev*(-1)*z*z / ((2*i + 3)*(2*i + 2));
        if (((check*check) - (prev*prev)) < (eps*esp)) break;
    }
 
    return S;
}

как видно нарыл в сети корень(только целый) и синус,но почему-то синус не фурычит(компилятор на "не декларированные" переменные esp и prev кричит,хотя всё правильно вроде)...
подкиньте идейки как посчитать,и можно код корня изменить так чтоб дробные считал..?(или как асмом через сопроцессор(сам не нашел под арху амр9) посчитать синус и корень(остальное само уже выползет)?)

RegIon 03.06.2011 18:11

Ответ: Где ошибка,хелп...
 
Код:

  public static double Sin(double x, double eps)
        {
            while(x>Math.PI) x -= Math.PI;
            int z = 1, i = 1;
            ulong factorial = 1;
            double stx = x,sint = 0;
 
            while (stx / factorial >= eps)
            {
                sint += z * stx / factorial;
                i += 2;
                stx = stx * x * x;
                factorial = factorial * (ulong)(i - 1) * (ulong)i;
                z = z * (-1);
            }
            return (sint);
}

по рядам Тейлориана,только большие погрешности при больших углах(но можно и меньше 90 конечно использовать и считать их,например через 45 градусов..)
(кстати не проверял работает нет)Как думаете для просчета положения точки в 3д сойдёт?
а 65тысяч цветов на портативке это хорошо(480*272) или большеб?


Часовой пояс GMT +4, время: 18:21.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Перевод: zCarot