OSDN Git Service

f67c910319cfb3ee899eb5b45e0810fc516d7b2c
[motonesemu/motonesemu.git] / emulator / ppucore / vscreen.c
1 #include <stdlib.h>
2 #include <string.h>
3
4 #include "libio.h"
5 #include "tools.h"
6 #include "vga.h"
7 #include "ppucore.h"
8 #include "vram.h"
9
10 void load_attribute(unsigned char bank, int tile_index, struct palette *plt);
11 void load_pattern(unsigned char bank, unsigned char ptn_index, struct tile_2* pattern);
12
13 struct tile_rgb15_line {
14     struct rgb15 d[8];
15 };
16
17 struct tile_rgb15 {
18     struct tile_rgb15_line l[8];
19 };
20
21 static struct tile_rgb15 *vscreen;
22
23
24 void set_bgtile(int tile_id) {
25     struct palette plt;
26     struct tile_2 ptn;
27     unsigned char name_index;
28     struct tile_rgb15* set_data;
29     int i;
30
31     load_attribute(0, tile_id, &plt);
32
33     name_index = name_tbl_get(0, tile_id);
34     load_pattern(0, name_index, &ptn);
35
36     set_data = vscreen + tile_id;
37     for (i = 0; i < TILE_DOT_SIZE; i++) {
38         set_data->l[i].d[0] = plt.col[ptn.b0.l[i].dot0 + ptn.b1.l[i].dot0];
39         set_data->l[i].d[1] = plt.col[ptn.b0.l[i].dot1 + ptn.b1.l[i].dot1];
40         set_data->l[i].d[2] = plt.col[ptn.b0.l[i].dot2 + ptn.b1.l[i].dot2];
41         set_data->l[i].d[3] = plt.col[ptn.b0.l[i].dot3 + ptn.b1.l[i].dot3];
42         set_data->l[i].d[4] = plt.col[ptn.b0.l[i].dot4 + ptn.b1.l[i].dot4];
43         set_data->l[i].d[5] = plt.col[ptn.b0.l[i].dot5 + ptn.b1.l[i].dot5];
44         set_data->l[i].d[6] = plt.col[ptn.b0.l[i].dot6 + ptn.b1.l[i].dot6];
45         set_data->l[i].d[7] = plt.col[ptn.b0.l[i].dot7 + ptn.b1.l[i].dot7];
46     }
47
48 }
49
50 void set_bg(void) {
51 /*
52     int i;
53     //struct tile_rgb15* set_data = vscreen + tile_id;
54     unsigned char data;
55     unsigned char *p;
56     struct tile_2 pattern;
57     unsigned short addr;
58     //load name tbl
59     //name_tbl_get();
60
61     //load character pattern
62     p = (unsigned char*)&pattern;
63     addr = tile_id * sizeof(struct tile_2);
64     for (i = 0; i < sizeof(struct tile_2); i++) {
65         data = pattern_tbl_get(bg_bank, addr);
66         *p = data;
67         p++;
68     }
69
70     //load attribute.
71 */
72 }
73
74 void vscreenn_dot_get(int x, int y, struct rgb15 *col) {
75     int tile_id, tile_id_x, tile_id_y;
76     int inner_x, inner_y;
77     struct tile_rgb15* tile;
78
79     tile_id_x = x / TILE_DOT_SIZE;
80     tile_id_y = y / TILE_DOT_SIZE;
81     tile_id = tile_id_x + tile_id_y * H_SCREEN_TILE_SIZE;
82     tile = vscreen + tile_id;
83
84     inner_x = x % TILE_DOT_SIZE;
85     inner_y = y % TILE_DOT_SIZE;
86     *col = tile->l[inner_y].d[inner_x];
87
88 }
89
90 int vscreen_init(void) {
91     vscreen = (struct tile_rgb15 *) malloc(
92         sizeof (struct tile_rgb15) * VIRT_SCREEN_TILE_SIZE * VIRT_SCREEN_TILE_SIZE);
93     if (vscreen == NULL)
94         return FALSE;
95     memset(vscreen, 0, sizeof (struct tile_rgb15) * VIRT_SCREEN_TILE_SIZE * VIRT_SCREEN_TILE_SIZE);
96
97     //dprint("tile_1_line:%d tile_2 size:%d\n", sizeof(struct tile_1_line), sizeof(struct tile_2));
98
99     return TRUE;
100 }
101
102 void clean_vscreen(void) {
103     free(vscreen);
104 }
105