snd: init and test of noise sound
[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
31 /* data */
32 unsigned char lol[5] = { 0xAA, 0x2, 0x3, 0x4, 0x5};
33 unsigned char lol2[5] = { 0x1, 0x2, 0x3, 0x4, 0x5};
34 unsigned char lol3[5] = { 0x1, 0x2, 0x3, 0x4, 0x5};
35 #define PALETTE_T (volatile unsigned *)0xFE00
36 #define SPRITE_T (volatile unsigned *)0x4000
37
38 /* bss */
39 static unsigned char blaat[100];
40
41 void outport(unsigned char portnr, unsigned char val)
42 {
43         __asm__(
44                 "mov %1, %%dl\n\t"
45                 "out %0, (%%dx)"
46                 :
47                 :"r"(val), "r"(portnr)
48                 :);
49 }
50
51 unsigned char inport(unsigned char portnr)
52 {
53         unsigned char val;
54         __asm__(
55                 "mov %1, %%dl\n\t"
56                 "in (%%dx), %%al\n\t"
57                 "mov %%al, %0"
58                 : "=r"(val)
59                 : "r"(portnr)
60                 :);
61
62         return val;
63 }
64
65 void setup_audio(void)
66 {
67         outport(IO_AUDIO_CTRL, AUDIO_4_NOISE | AUDIO_4_ON);
68         outport(IO_AUDIO_NOISE_CTRL, NOISE_RESET | NOISE_ENABLE | 0x2);
69         outport(IO_AUDIO4_VOL, 0x22);
70
71 }
72
73 void setup_ivec(void)
74 {
75         outport(IO_INT_BASE, INT_BASE);
76
77         unsigned short * test_vec = (INT_BASE + INTVEC_VBLANK_START) << 2;
78         *test_vec++ = (&dummyS_isr);
79         *test_vec = (0x2000);
80
81         unsigned short * keyboard_intr = (INT_BASE + INTVEC_KEY_PRESS) << 2;
82         *keyboard_intr++ = (&dummyS_isr);
83         *keyboard_intr = (0x2000);
84
85         outport(IO_INT_ENABLE, INT_VBLANK_START);
86         //outport(IO_INT_ENABLE, INT_KEY_PRESS);
87         __asm__("sti");
88 }
89
90 static unsigned cnt = 0;
91
92 void scroll_video(void)
93 {
94         unsigned char val = inport(IO_FG_X);
95
96         cnt++;
97         if (cnt > 10) {
98                 cnt = 0;
99                 val++;
100         }
101         
102         outport(IO_FG_X, val);
103         outport(IO_INT_ACK, INT_VBLANK_START);
104         
105         outport(IO_FG_WIN_X0, cnt);
106         outport(IO_FG_WIN_Y0, cnt);
107         outport(IO_FG_WIN_X1, SCREEN_WIDTH - cnt);
108         outport(IO_FG_WIN_Y1, SCREEN_HEIGHT - cnt);
109
110 }
111
112 void init_video(void)
113 {
114 }
115
116 int main(void)
117 {
118         outport(0x15, 0x99);
119         unsigned char ret = inport(0x15);
120         
121         lol[0] = 0xAA;
122         lol[1] = ret;
123
124         blaat[0] = 0xEE;
125         blaat[1] = 0xEE;
126         blaat[32] = 0xEE;
127
128
129         setup_ivec();
130         init_video();
131         setup_audio();
132         outport(IO_VIDEO_MODE, VMODE_16C_CHK | VMODE_CLEANINIT);
133         unsigned short base = 0x3000; /* screens pos */
134         unsigned short sprite_pos = base - (MAP_SIZE*2) - SPR_TABLE_SIZE;
135         unsigned short scr1_pos = base - (MAP_SIZE*2); /* 0x2000 */
136         unsigned short scr2_pos = base - MAP_SIZE; /* 0x2800 */
137         outport(IO_MAP_BASE, FG_MAP(scr2_pos) | BG_MAP(scr1_pos));
138         outport(IO_SPR_TABLE, SPR_TABLE(sprite_pos));
139
140         outport(IO_FG_WIN_X0, 10);
141         outport(IO_FG_WIN_Y0, 10);
142         outport(IO_FG_WIN_X1, SCREEN_WIDTH - 10);
143         outport(IO_FG_WIN_Y1, SCREEN_HEIGHT - 10);
144
145         /* icons */
146         outport(0x15, 0xEE);
147
148         unsigned char * ptr = PALETTE_T;
149         for (int i = 0; i < sizeof(bgtile_pal); ++i) {
150                 *ptr++ = bgtile_pal[i];
151         }
152         
153         ptr = SPRITE_T;
154         for (int i = 0; i < sizeof(bgtile_gfx); ++i) {
155                 *ptr++ = bgtile_gfx[i];
156         }
157         
158         outport(IO_DISPLAY_CTRL, FG_OUT_WIN | FG_ON);
159
160         int a = 0;
161         a++;
162
163         while(1) {
164         }
165
166         return 0;
167 }