bd4a86bf310b5a62138610f7b24f9a676f71879c
[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 <config.h>
11 #include <interrupt.h>
12
13 /* sprite data */
14 unsigned char bgtile_gfx[] = {
15   0x31, 0x22, 0x31, 0x32, 0x22, 0x31, 0x23, 0x21, 0x13, 0x13, 0x31, 0x32,
16   0x32, 0x31, 0x23, 0x12, 0x21, 0x32, 0x13, 0x23, 0x23, 0x13, 0x31, 0x31,
17   0x12, 0x32, 0x13, 0x22, 0x23, 0x13, 0x22, 0x13
18 };
19
20 /* palette data */
21 unsigned char bgtile_pal[] = {
22   0x65, 0x06, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0xff, 0x0f, 0xff, 0x0f,
23   0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f,
24   0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f
25 };
26
27
28 /* data */
29 unsigned char lol[5] = { 0xAA, 0x2, 0x3, 0x4, 0x5};
30 unsigned char lol2[5] = { 0x1, 0x2, 0x3, 0x4, 0x5};
31 unsigned char lol3[5] = { 0x1, 0x2, 0x3, 0x4, 0x5};
32 #define PALETTE_T (volatile unsigned *)0xFE00
33 #define SPRITE_T (volatile unsigned *)0x4000
34
35 /* bss */
36 static unsigned char blaat[100];
37
38 void outport(unsigned char portnr, unsigned char val)
39 {
40         __asm__(
41                 "mov %1, %%dl\n\t"
42                 "out %0, (%%dx)"
43                 :
44                 :"r"(val), "r"(portnr)
45                 :);
46 }
47
48 __attribute__ ((naked)) void * dummy_isr(void)
49 {
50         int a = 2;
51         a *= 2;
52         while(1);
53 }
54
55 void setup_ivec(void)
56 {
57         outport(IO_INT_BASE, INT_BASE);
58
59         unsigned short * test_vec = (INT_BASE + INTVEC_VBLANK_START) << 2;
60         *test_vec++ = (&dummy_isr);
61         *test_vec = (0x2000);
62
63         outport(IO_INT_ENABLE, INT_VBLANK_START);
64         __asm__("sti");
65 }
66
67 void init_video(void)
68 {
69 }
70
71 int main(void)
72 {
73         lol[0] = 0xDD;
74         lol[1] = 0xDD;
75
76         blaat[0] = 0xEE;
77         blaat[1] = 0xEE;
78         blaat[32] = 0xEE;
79
80         setup_ivec();
81         init_video();
82         outport(IO_VIDEO_MODE, VMODE_16C_CHK | VMODE_CLEANINIT);
83         unsigned short base = 0x3000; /* screens pos */
84         unsigned short sprite_pos = base - (MAP_SIZE*2) - SPR_TABLE_SIZE;
85         unsigned short scr1_pos = base - (MAP_SIZE*2); /* 0x2000 */
86         unsigned short scr2_pos = base - MAP_SIZE; /* 0x2800 */
87         outport(IO_MAP_BASE, FG_MAP(scr2_pos) | BG_MAP(scr1_pos));
88         outport(IO_SPR_TABLE, SPR_TABLE(sprite_pos));
89
90         /* icons */
91         outport(0x15, 0xEE);
92
93         unsigned char * ptr = PALETTE_T;
94         for (int i = 0; i < sizeof(bgtile_pal); ++i) {
95                 *ptr++ = bgtile_pal[i];
96         }
97         
98         ptr = SPRITE_T;
99         for (int i = 0; i < sizeof(bgtile_gfx); ++i) {
100                 *ptr++ = bgtile_gfx[i];
101         }
102         
103         outport(IO_DISPLAY_CTRL, BG_ON | FG_ON);
104
105         while(1) {
106         }
107
108         return 0;
109 }