Project

General

Profile

Revision 152

added files, and makefiles

View differences:

proj/DR.mk
1
PROG=proj
2

  
3
SRCS= proj.c graphics.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c
4

  
5
CPPFLAGS += -pedantic -D __LCOM_OPTIMIZED_ -D DIOGO
6

  
7
DPADD += ${LIBLCF}
8
LDADD += -llcf
9

  
10
.include <minix.lcom.mk>
0 11

  
proj/TB.mk
1
PROG=proj
2

  
3
SRCS= proj.c graphics.c sprite.c kbc.c keyboard.c mouse.c utils.c timer.c
4

  
5
CPPFLAGS += -pedantic -D __LCOM_OPTIMIZED_ -D TELMO
6

  
7
DPADD += ${LIBLCF}
8
LDADD += -llcf
9

  
10
.include <minix.lcom.mk>
0 11

  
proj/proj.c
36 36

  
37 37
int(proj_main_loop)(int argc, char *argv[]) {
38 38

  
39
    if (vbe_get_mode_information(INDEXED_1024_768)) {
40
        printf("%s: failed to get information for mode %x.\n", __func__, INDEXED_1024_768);
41
        if (vg_exit())
42
            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
43
        return 1;
44
    }
45

  
46
    map_vram(); // if function fails it aborts program
47

  
48
    if (set_graphics_mode(INDEXED_1024_768)) {
49
        printf("%s: failed to set graphic mode %x.\n", __func__, INDEXED_1024_768);
50
        if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__);
51
        if (free_memory_map()) {
52
            printf("%s: lm_free failed\n", __func__);
53
        }
54
        return 1;
55
    };
56

  
57

  
39 58
    /// loop stuff
40 59
    int ipc_status, r;
41 60
    message msg;
......
117 136
    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
118 137
    if (unsubscribe_interrupt(&mouse_id)) return 1; // unsubscribes interrupts
119 138

  
139
    
140
    if (vg_exit()) {
141
        printf("%s: vg_exit failed to exit to text mode.\n", __func__);
142
        if (free_memory_map()) printf("%s: lm_free failed\n", __func__);
143
        return 1;
144
    }
145

  
146
    if (free_memory_map()) {
147
        printf("%s: lm_free failed\n", __func__);
148
        return 1;
149
    }
150

  
151
    
152
    #ifdef DIOGO
153
        hello
154
    #endif
155

  
156

  
120 157
    return 0;
158

  
159
    return 0;
121 160
}
proj/sprite.c
1
#include <lcom/lcf.h>
2

  
3
#include "sprite.h"
4

  
5
#include "graphics.h"
6

  
7
struct sprite{
8
    int x, y;
9
    int w, h;
10
    uint8_t *map;
11
};
12

  
13
sprite_t* sprite_ctor(const xpm_map_t xpm){
14
    sprite_t *ret = (sprite_t*)malloc(sizeof(sprite_t));
15
    if(ret == NULL) return NULL;
16
    enum xpm_image_type type = XPM_INDEXED;
17
    xpm_image_t img;
18
    ret->map = xpm_load(xpm, type, &img);
19
    if(ret->map == NULL){
20
        free(ret);
21
        return NULL;
22
    }
23
    ret->w = img.width;
24
    ret->h = img.height;
25
    return ret;
26
}
27

  
28
void sprite_dtor(sprite_t *p){
29
    if(p == NULL) return;
30
    if(p->map) free(p->map);
31
    free(p);
32
}
33

  
34
void sprite_set_x(sprite_t *p, int x){ p->x = x; }
35
void sprite_set_y(sprite_t *p, int y){ p->y = y; }
36
void sprite_set_pos(sprite_t *p, int x, int y){
37
    sprite_set_x(p, x);
38
    sprite_set_y(p, y);
39
}
40

  
41
int sprite_get_w(const sprite_t *p){ return p->w; }
42
int sprite_get_h(const sprite_t *p){ return p->h; }
43

  
44
void sprite_draw(const sprite_t *p){
45
    for (int i = 0; i < p->w; i++) {
46
        for (int j = 0; j < p->h; j++) {
47
            if (p->x + i < get_XRes() && p->y + j < get_YRes()) {
48
                set_pixel(p->x + i, p->y + j, p->map[i + j * p->w]);
49
            }
50
        }
51
    }
52
}
0 53

  
proj/sprite.h
1
#ifndef SPRITE_H_INCLUDED
2
#define SPRITE_H_INCLUDED
3

  
4
struct sprite;
5
typedef struct sprite sprite_t;
6

  
7
sprite_t* sprite_ctor(const xpm_map_t xpm);
8
void      sprite_dtor(sprite_t *p);
9

  
10
void sprite_set_x(sprite_t *p, int x);
11
void sprite_set_y(sprite_t *p, int y);
12
void sprite_set_pos(sprite_t *p, int x, int y);
13

  
14
int sprite_get_h(const sprite_t *p);
15
int sprite_get_w(const sprite_t *p);
16

  
17
void sprite_draw(const sprite_t *p);
18

  
19
#endif //SPRITE_H_INCLUDED
0 20

  

Also available in: Unified diff