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