> compile NEMU

221220000 张三
Linux zzy 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
 13:06:42 up 8 days, 15:51,  1 user,  load average: 0.25, 0.10, 0.02
This commit is contained in:
tracer-ics2023
2024-09-27 13:06:42 +08:00
committed by zzy
parent bf97a6e2b9
commit 7fd92e4c49
5 changed files with 61 additions and 3 deletions

View File

@ -8,6 +8,13 @@ size_t events_read(void *buf, size_t offset, size_t len);
size_t dispinfo_read(void *buf, size_t offset, size_t len);
size_t fb_write(const void *buf, size_t offset, size_t len);
size_t sb_write(const void *buf, size_t offset, size_t len);
// freq, channels, samples
size_t sbctl_write(const void *buf, size_t offset, size_t len);
// the number of sound buffer unused length
size_t sbctl_read(void *buf, size_t offset, size_t len);
int _fb_size();
#endif

View File

@ -49,6 +49,26 @@ size_t fb_write(const void *buf, size_t offset, size_t len) {
return len;
}
size_t sb_write(const void *buf, size_t offset, size_t len) {
Area sbuf = {
.start = (char*)buf,
.end = (char*)buf + len
};
io_write(AM_AUDIO_PLAY, sbuf);
return len;
}
size_t sbctl_write(const void *buf, size_t offset, size_t len) {
io_write(AM_AUDIO_CTRL, ((int32_t*)buf)[0], ((int32_t*)buf)[1], ((int32_t*)buf)[2]);
return 12;
}
size_t sbctl_read(void *buf, size_t offset, size_t len) {
int szbuf = io_read(AM_AUDIO_CONFIG).bufsize;
*(int32_t*)buf = szbuf - io_read(AM_AUDIO_STATUS).count;
return 4;
}
int _fb_size() {
AM_GPU_CONFIG_T gconf = io_read(AM_GPU_CONFIG);
return gconf.vmemsz;

View File

@ -15,7 +15,7 @@ typedef struct {
} Finfo;
enum {FD_STDIN, FD_STDOUT, FD_STDERR,
FD_DEV_EVENTS, FD_DEV_FB,
FD_DEV_EVENTS, FD_DEV_FB, FD_DEV_SB, FD_DEV_SBCTL,
FD_PROC_DISPINFO};
size_t invalid_read(void *buf, size_t offset, size_t len) {
@ -36,6 +36,8 @@ static Finfo file_table[] __attribute__((used)) = {
[FD_DEV_EVENTS] = {"/dev/events", 0, 0, events_read, invalid_write},
[FD_DEV_FB] = {"/dev/fb", 0, 0, invalid_read, fb_write},
[FD_PROC_DISPINFO] = {"/proc/dispinfo", 0, 0, dispinfo_read, invalid_write},
[FD_DEV_SB] = {"/dev/sb", 0, 0, invalid_read, sb_write},
[FD_DEV_SBCTL] = {"/dev/sbctl", 0, 0, sbctl_read, sbctl_write},
#include "files.h"
};

View File

@ -2,10 +2,13 @@
#include <SDL.h>
int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) {
NDL_OpenAudio(desired->freq, desired->channels, desired->samples);
// desired->callback()
return 0;
}
void SDL_CloseAudio() {
NDL_CloseAudio();
}
void SDL_PauseAudio(int pause_on) {

View File

@ -103,17 +103,43 @@ void NDL_DrawRect(uint32_t *pixels, int x, int y, int w, int h) {
}
void NDL_OpenAudio(int freq, int channels, int samples) {
FILE* fp = fopen("/dev/sbctl", "w");
if (fp == NULL) {
printf("cannot open /dev/fb");
exit(-1);
}
int arr[] = {
freq, channels, samples
};
fwrite(arr, sizeof(int), 3, fp);
fclose(fp);
}
void NDL_CloseAudio() {
}
int NDL_PlayAudio(void *buf, int len) {
return 0;
FILE* fp = fopen("/dev/sb", "w");
if (fp == NULL) {
printf("cannot open /dev/fb");
exit(-1);
}
fwrite(buf, 1, len, fp);
fclose(fp);
return len;
}
int NDL_QueryAudio() {
return 0;
FILE* fp = fopen("/dev/sbctl", "r");
if (fp == NULL) {
printf("cannot open /dev/fb");
exit(-1);
}
int ret;
fread(&ret, sizeof(int), 1, fp);
fclose(fp);
return ret;
}
int NDL_Init(uint32_t flags) {