tools: bmp2tiles create pallete data
[swan-dev] / src / main.c
1 /**
2  * File              : main.c
3  * Author            : Robin Krens <robin@robinkrens.nl>
4  * Date              : 09.06.2022
5  * Last Modified Date: 09.06.2022
6  * Last Modified By  : Robin Krens <robin@robinkrens.nl>
7  */
8 #include <memory.h>
9 #include <video.h>
10 #include <dma_snd.h>
11 #include <config.h>
12 #include <interrupt.h>
13
14 extern void * dummyS_isr;
15
16 /* sprite data */
17 unsigned char bgtile_gfx[] = {
18   0x31, 0x22, 0x31, 0x32, 0x22, 0x31, 0x23, 0x21, 0x13, 0x13, 0x31, 0x32,
19   0x32, 0x31, 0x23, 0x12, 0x21, 0x32, 0x13, 0x23, 0x23, 0x13, 0x31, 0x31,
20   0x12, 0x32, 0x13, 0x22, 0x23, 0x13, 0x22, 0x13
21 };
22
23 /* palette data */
24 //unsigned char bgtile_pal[] = {
25 //  0x65, 0x06, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0xff, 0x0f, 0xff, 0x0f,
26 //  0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f,
27 //  0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f
28 //};
29
30 unsigned char bgtile_pal[] = {
31   0x00, 0x00, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0x00, 0x00, 0x12, 0x0b,
32   0x00, 0x00, 0x10, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
33   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
34 };
35
36
37 /* data */
38 unsigned char lol[5] = { 0xAA, 0x2, 0x3, 0x4, 0x5};
39 unsigned char lol2[5] = { 0x1, 0x2, 0x3, 0x4, 0x5};
40 unsigned char lol3[5] = { 0x1, 0x2, 0x3, 0x4, 0x5};
41 #define PALETTE_T (volatile unsigned *)0xFE00
42 #define SPRITE_T (volatile unsigned *)0x4000
43
44 /* bss */
45 static unsigned char blaat[100];
46
47 void outport(unsigned char portnr, unsigned char val)
48 {
49         __asm__(
50                 "mov %1, %%dl\n\t"
51                 "out %0, (%%dx)"
52                 :
53                 :"r"(val), "r"(portnr)
54                 :);
55 }
56
57 unsigned char inport(unsigned char portnr)
58 {
59         unsigned char val;
60         __asm__(
61                 "mov %1, %%dl\n\t"
62                 "in (%%dx), %%al\n\t"
63                 "mov %%al, %0"
64                 : "=r"(val)
65                 : "r"(portnr)
66                 :);
67
68         return val;
69 }
70
71 void setup_audio(void)
72 {
73         outport(IO_AUDIO_CTRL, AUDIO_4_NOISE | AUDIO_4_ON);
74         outport(IO_AUDIO_NOISE_CTRL, NOISE_RESET | NOISE_ENABLE | 0x2);
75         outport(IO_AUDIO4_VOL, 0x22);
76
77 }
78
79 void setup_ivec(void)
80 {
81         outport(IO_INT_BASE, INT_BASE);
82
83         unsigned short * test_vec = (INT_BASE + INTVEC_VBLANK_START) << 2;
84         *test_vec++ = (&dummyS_isr);
85         *test_vec = (0x2000);
86
87         unsigned short * keyboard_intr = (INT_BASE + INTVEC_KEY_PRESS) << 2;
88         *keyboard_intr++ = (&dummyS_isr);
89         *keyboard_intr = (0x2000);
90
91         //outport(IO_INT_ENABLE, INT_VBLANK_START);
92         //outport(IO_INT_ENABLE, INT_KEY_PRESS);
93         __asm__("sti");
94 }
95
96 static unsigned cnt = 0;
97
98 void scroll_video(void)
99 {
100         unsigned char val = inport(IO_FG_X);
101
102         cnt++;
103         if (cnt > 10) {
104                 cnt = 0;
105                 val++;
106         }
107         
108         outport(IO_FG_X, val);
109         outport(IO_INT_ACK, INT_VBLANK_START);
110         
111         outport(IO_FG_WIN_X0, cnt);
112         outport(IO_FG_WIN_Y0, cnt);
113         outport(IO_FG_WIN_X1, SCREEN_WIDTH - cnt);
114         outport(IO_FG_WIN_Y1, SCREEN_HEIGHT - cnt);
115
116 }
117
118 void init_video(void)
119 {
120 }
121
122 int main(void)
123 {
124         outport(0x15, 0x99);
125         unsigned char ret = inport(0x15);
126         
127         lol[0] = 0xAA;
128         lol[1] = ret;
129
130         blaat[0] = 0xEE;
131         blaat[1] = 0xEE;
132         blaat[32] = 0xEE;
133
134
135         setup_ivec();
136         init_video();
137         setup_audio();
138         outport(IO_VIDEO_MODE, VMODE_16C_CHK | VMODE_CLEANINIT);
139         unsigned short base = 0x3000; /* screens pos */
140         unsigned short sprite_pos = base - (MAP_SIZE*2) - SPR_TABLE_SIZE;
141         unsigned short scr1_pos = base - (MAP_SIZE*2); /* 0x2000 */
142         unsigned short scr2_pos = base - MAP_SIZE; /* 0x2800 */
143         outport(IO_MAP_BASE, FG_MAP(scr2_pos) | BG_MAP(scr1_pos));
144         outport(IO_SPR_TABLE, SPR_TABLE(sprite_pos));
145
146         outport(IO_FG_WIN_X0, 10);
147         outport(IO_FG_WIN_Y0, 10);
148         outport(IO_FG_WIN_X1, SCREEN_WIDTH - 10);
149         outport(IO_FG_WIN_Y1, SCREEN_HEIGHT - 10);
150
151         /* icons */
152         outport(0x15, 0xEE);
153
154         unsigned char * ptr = PALETTE_T;
155         for (int i = 0; i < sizeof(bgtile_pal); ++i) {
156                 *ptr++ = bgtile_pal[i];
157         }
158         
159         ptr = SPRITE_T;
160         for (int i = 0; i < sizeof(bgtile_gfx); ++i) {
161                 *ptr++ = bgtile_gfx[i];
162         }
163         
164         outport(IO_DISPLAY_CTRL, FG_OUT_WIN | FG_ON);
165
166         int a = 0;
167         a++;
168
169         while(1) {
170         }
171
172         return 0;
173 }