main: inport calls
[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 unsigned char inport(unsigned char portnr)
49 {
50         unsigned char val;
51         __asm__(
52                 "mov %1, %%dl\n\t"
53                 "in (%%dx), %%al\n\t"
54                 "mov %%al, %0"
55                 : "=r"(val)
56                 : "r"(portnr)
57                 :);
58
59         return val;
60 }
61
62 __attribute__ ((naked)) void * dummy_isr(void)
63 {
64         int a = 2;
65         a *= 2;
66         while(1);
67 }
68
69 void setup_ivec(void)
70 {
71         outport(IO_INT_BASE, INT_BASE);
72
73         unsigned short * test_vec = (INT_BASE + INTVEC_VBLANK_START) << 2;
74         *test_vec++ = (&dummy_isr);
75         *test_vec = (0x2000);
76
77         outport(IO_INT_ENABLE, INT_VBLANK_START);
78         __asm__("sti");
79 }
80
81 void init_video(void)
82 {
83 }
84
85 int main(void)
86 {
87         outport(0x15, 0x99);
88         unsigned char ret = inport(0x15);
89         
90         lol[0] = 0xAA;
91         lol[1] = ret;
92
93         blaat[0] = 0xEE;
94         blaat[1] = 0xEE;
95         blaat[32] = 0xEE;
96
97
98         setup_ivec();
99         init_video();
100         outport(IO_VIDEO_MODE, VMODE_16C_CHK | VMODE_CLEANINIT);
101         unsigned short base = 0x3000; /* screens pos */
102         unsigned short sprite_pos = base - (MAP_SIZE*2) - SPR_TABLE_SIZE;
103         unsigned short scr1_pos = base - (MAP_SIZE*2); /* 0x2000 */
104         unsigned short scr2_pos = base - MAP_SIZE; /* 0x2800 */
105         outport(IO_MAP_BASE, FG_MAP(scr2_pos) | BG_MAP(scr1_pos));
106         outport(IO_SPR_TABLE, SPR_TABLE(sprite_pos));
107
108         /* icons */
109         outport(0x15, 0xEE);
110
111         unsigned char * ptr = PALETTE_T;
112         for (int i = 0; i < sizeof(bgtile_pal); ++i) {
113                 *ptr++ = bgtile_pal[i];
114         }
115         
116         ptr = SPRITE_T;
117         for (int i = 0; i < sizeof(bgtile_gfx); ++i) {
118                 *ptr++ = bgtile_gfx[i];
119         }
120         
121         outport(IO_DISPLAY_CTRL, BG_ON | FG_ON);
122
123         while(1) {
124         }
125
126         return 0;
127 }