- Audio refactoring;
 - Delete old menuetos wrappers;
 - Fixed tupfile(speed ​​optimization flags) and makefile.


git-svn-id: svn://kolibrios.org@9789 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2022-04-26 08:01:26 +00:00
parent d3e724b908
commit 2f26d486e6
7 changed files with 177 additions and 493 deletions

View File

@ -2,6 +2,7 @@ CC = kos32-gcc
AR = kos32-ar
LD = kos32-ld
STRIP = kos32-strip
NASM = nasm
LIBNAME=libSDL
@ -27,8 +28,8 @@ video_OBJS = video/SDL_blit_0.o video/SDL_blit_1.o video/SDL_blit_A.o \
video/SDL_cursor.o video/SDL_gamma.o video/SDL_pixels.o \
video/SDL_RLEaccel.o video/SDL_stretch.o video/SDL_surface.o \
video/SDL_video.o video/SDL_yuv.o video/SDL_yuv_mmx.o \
video/SDL_yuv_sw.o video/menuetos/SDL_menuetevents.o \
video/menuetos/SDL_menuetvideo.o
video/SDL_yuv_sw.o video/kolibrios/SDL_kolibri_events.o \
video/kolibrios/SDL_kolibri_video.o
audio_OBJS = audio/SDL_kolibri_audio.o audio/SDL_audiocvt.o audio/SDL_mixer.o audio/SDL_wave.o
curr_OBJS = SDL.o SDL_error.o SDL_fatal.o SDL_getenv.o
@ -54,19 +55,18 @@ install: $(LIBNAME)
mv -f $(LIBNAME) $(SDK_DIR)/lib
$(LIBNAME).a: $(OBJS)
$(MAKE) -C SYSCALL/src
$(AR) -crs ../../../lib/$(LIBNAME).a $(OBJS) SYSCALL/src/os.o
$(AR) -crs ../../../lib/$(LIBNAME).a $(OBJS)
$(LIBNAME).dll: $(OBJS)
$(LD) $(LDFLAGS) -o $@ $(OBJS) SYSCALL/src/os.o $(LIBS) -ldll -lsound -lc.dll
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) -ldll -lsound -lc.dll
$(STRIP) -S $@
%.o : %.asm Makefile
nasm -Ihermes -f coff $<
$(NASM) -Ihermes -f coff $<
%.o : %.c Makefile
$(CC) $(CFLAGS) -o $@ $<
clean:
rm -f */*.o \ rm *.o \ rm */*/*.o
rm -f $(OBJS)

View File

@ -1,218 +0,0 @@
#ifndef __GLIBC__MENUET_OS_H
#define __GLIBC__MENUET_OS_H
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned char __u8;
typedef unsigned short __u16;
typedef unsigned long __u32;
#pragma pack(push,1)
void __menuet__define_window(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,
__u32 body_color,__u32 grab_color,__u32 frame_color);
void __menuet__window_redraw(int status);
void __menuet__putpixel(__u32 x,__u32 y,__u32 color);
int __menuet__getkey(void);
__u32 __menuet__getsystemclock(void);
void __menuet__write_text(__u16 x,__u16 y,__u32 color,char * text,int len);
void __menuet__delay100(int m);
__u32 __menuet__open(char * name,char * data);
void __menuet__save(char * name,char * data,__u32 count);
void __menuet__putimage(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,char * image);
void __menuet__make_button(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,
int id,__u32 color);
int __menuet__get_button_id(void);
int __menuet__wait_for_event(void);
int __menuet__check_for_event(void);
void __menuet__bar(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,__u32 color);
void __menuet__sys_exit(void);
void * __menuet__exec_thread(void (* func_ptr)(void),__u32 stack_size,int * retp);
void __menuet__idle(void);
void __menuet__exec_ramdisk(char * filename,char * args,...);
void __menuet__exec_hd(char * filename,char * args,...);
struct process_table_entry
{
__u32 cpu_usage;
__u16 pos_in_windowing_stack;
__u16 win_stack_val_at_ecx;
__u16 reserved1;
char name[12];
__u32 memstart;
__u32 memused;
__u32 pid;
__u32 winx_start,winy_start;
__u32 winx_size,winy_size;
__u16 thread_state;
__u16 reserved2;
__u32 client_left,client_top,client_width,client_height;
__u8 window_state;
__u8 reserved3[1024-71];
};
#define PID_WHOAMI (-1)
int __menuet__get_process_table(struct process_table_entry * proctab,int pid);
void __menuet__get_screen_max(__u16 * x,__u16 * y);
#define BTYPE_TILE 1
#define BTYPE_STRETCH 2
void __menuet__set_background_size(__u32 xsz,__u32 ysz);
void __menuet__write_background_mem(__u32 pos,__u32 color);
void __menuet__draw_background(void);
void __menuet__set_background_draw_type(int type);
void __menuet__background_blockmove(char * src_ptr,__u32 bgr_dst,__u32 count);
void __menuet__reset_mpu401(void);
void __menuet__write_mpu401(__u8 d);
__u32 __menuet__get_date(void);
void __menuet__line(__u16 x1,__u16 y1,__u16 x2,__u16 y2,__u32 color);
void __menuet__set_bitfield_for_wanted_events(__u32 ev);
#define EVENT_REDRAW 0x00000001
#define EVENT_KEY 0x00000002
#define EVENT_BUTTON 0x00000004
#define EVENT_END_REQUEST 0x00000008
#define EVENT_DESKTOP_BACK_DRAW 0x00000010
#define EVENT_MOUSE_CHANGE 0x00000020
#define EVENT_IPC 0x00000040
#define EVENT_MOUSE_CURSOR_MASK 0x40000000 // the window does not receive mouse events if cursor outside window
#define EVENT_MOUSE_WINDOW_MASK 0x80000000 // inactive window does not receive mouse events
__u32 __menuet__get_irq_owner(__u32 irq);
int __menuet__get_data_read_by_irq(__u32 irq,__u32 * num_bytes_in_buf,__u8 * data);
int __menuet__send_data_to_device(__u16 port,__u8 val);
void __menuet__program_irq(void * intr_table,__u32 irq_num);
int __menuet__reserve_irq(int irqno);
int __menuet__free_irq(int irqno);
int __menuet__reserve_port_area(__u32 start,__u32 end);
int __menuet__free_port_area(__u32 start,__u32 end);
#define NAME_LEN 512
#define STC_READ 0
#define STC_WRITE 1
#define STC_APPEND 2
struct systree_info
{
__u32 command;
__u32 file_offset_low;
__u32 file_offset_high;
__u32 size;
__u32 data_pointer;
char _zero;
const char* nameptr;
};
struct systree_info2
{
__u32 command;
__u32 file_offset_low;
__u32 file_offset_high;
__u32 size;
__u32 data_pointer;
char name[NAME_LEN];
};
struct bdfe_time
{
__u8 seconds;
__u8 minutes;
__u8 hours;
__u8 reserved;
};
struct bdfe_date
{
__u8 day;
__u8 month;
__u16 year;
};
struct bdfe_item
{
__u32 attr;
__u8 nametype;
__u8 reserved[3];
struct bdfe_time ctime;
struct bdfe_date cdate;
struct bdfe_time atime;
struct bdfe_date adate;
struct bdfe_time mtime;
struct bdfe_date mdate;
__u32 filesize_low;
__u32 filesize_high;
};
int __kolibri__system_tree_access(struct systree_info * info);
int __kolibri__system_tree_access2(struct systree_info2 * info);
int __fslayer_open(char * name,int flags);
int __fslayer_close(int fd);
int __fslayer_lseek(int fd,int pos,int seek_type);
int __fslayer_tell(int fd);
int __fslayer_read(int fd,void * buffer,__u32 count);
int __fslayer_write(int fd,void * buffer,__u32 count);
typedef struct
{
__u8 lock;
__u8 resvd[3];
__u32 ptr_to_fmsg_pos;
/* Below is for message */
__u32 sender_pid;
__u32 msg_length;
} msgrcva_t /*__attribute__((packed))*/;
void send_message(int pid,void * msg_ptr,int message_size);
void define_receive_area(msgrcva_t * rcva_ptr,int size);
void __menuet__sound_load_block(char * blockptr);
void __menuet__sound_play_block(void);
void __menuet__dga_get_caps(int * xres,int * yres,int * bpp,int * bpscan);
void get_pci_version(__u8 * major,__u8 * minor);
void pci_get_last_bus(__u8 * last_bus);
void get_pci_access_mechanism(__u8 * mechanism);
void pci_write_config_byte(__u8 bus,__u8 dev,__u8 fn,__u8 reg,__u8 val);
void pci_write_config_word(__u8 bus,__u8 dev,__u8 fn,__u8 reg,__u16 val);
void pci_write_config_dword(__u8 bus,__u8 dev,__u8 fn,__u8 reg,__u32 val);
__u8 pci_read_config_byte(__u8 bus,__u8 dev,__u8 fn,__u8 reg);
__u16 pci_read_config_word(__u8 bus,__u8 dev,__u8 fn,__u8 reg);
__u32 pci_read_config_dword(__u8 bus,__u8 dev,__u8 fn,__u8 reg);
typedef struct{
char* name;
void* pointer;
} IMP_ENTRY;
typedef const IMP_ENTRY* IMP_TABLE;
IMP_TABLE __kolibri__cofflib_load(const char*);
__u32 __kolibri__cofflib_getproc(IMP_TABLE, const char*);
//int __kolibri__cofflib_link(FUNC*, IMP_TABLE);
static __inline__ void __menuet__debug_out_byte(const char ch){
__asm__ __volatile__ ("int $0x40"::"a"(63L),"b"(1L),"c"((__u8)ch));
}
void __menuet__debug_out(const char* str);
#define TIME_GETH(x) ((x)&0x000000FF)
#define TIME_GETM(x) ((((x)&0x00FF00)>>8)&0xFF)
#define TIME_GETS(x) ((((x)&0xFF0000)>>16)&0xFF)
#pragma pack(pop)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,19 +0,0 @@
CC = kos32-gcc
LD = kos32-ld
SDK_DIR = $(abspath ../../../../../)
CFLAGS = -c -fno-ident -O2 -fomit-frame-pointer -fno-ident -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32
INCLUDES = -I ../include -I $(SDK_DIR)/sources/newlib/libc/include
SYSCALL_SRC := $(notdir $(wildcard *.c))
OBJECTS = $(patsubst %.c, %.o, $(SYSCALL_SRC))
default: $(patsubst %.c,%.o,$(SYSCALL_SRC))
%.o : %.c Makefile $(SYSCALL_SRC)
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $<
clean:
rm *.o

View File

@ -1,39 +0,0 @@
#include <menuet/os.h>
void __menuet__define_window(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,
__u32 body_color,__u32 grab_color,__u32 frame_color)
{
__u32 a,b;
a=(x1<<16)|xsize;
b=(y1<<16)|ysize;
__asm__ __volatile__("int $0x40"::"a"(0),"b"(a),"c"(b),"d"(body_color),"S"(grab_color),
"D"(frame_color));
}
void __menuet__window_redraw(int status)
{
__asm__ __volatile__("int $0x40"::"a"(12),"b"(status));
}
void __menuet__putimage(__u16 x1,__u16 y1,__u16 xsize,__u16 ysize,char * image)
{
__u32 a,b;
a=(xsize<<16)|ysize;
b=(x1<<16)|y1;
__asm__ __volatile__("int $0x40"::"a"(7),"b"(image),"c"(a),"d"(b));
}
int __menuet__getkey(void)
{
__u16 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(2));
if(!(__ret & 0xFF)) return (__ret>>8)&0xFF; else return 0;
}
int __menuet__check_for_event(void)
{
__u32 __ret;
__asm__ __volatile__("int $0x40":"=a"(__ret):"0"(11));
return __ret;
}

View File

@ -3,6 +3,8 @@ tup.include("../../../../../programs/use_gcc.lua")
tup.include("../../../../../programs/use_newlib.lua")
tup.include("../../../../../programs/use_sound.lua")
INCLUDES = INCLUDES .. " -I. -I../include -Ihermes -Iaudio -Ivideo -Ievents -Ijoystick -Icdrom -Ithread -Itimer -Iendian -Ifile -ISYSCALL/include"
CFLAGS = CFLAGS_OPTIMIZE_SPEED
CFLAGS = CFLAGS .. ' -D_REENTRANT -DPACKAGE=\"SDL\" -DVERSION=\"1.2.2\"'
CFLAGS = CFLAGS .. ' -DENABLE_AUDIO -UDISABLE_AUDIO -DDISABLE_JOYSTICK'
CFLAGS = CFLAGS .. ' -DDISABLE_CDROM -DDISABLE_THREADS -DENABLE_TIMERS'
@ -21,7 +23,6 @@ FOLDERS = {
"timer/dummy/",
"video/",
"video/kolibrios/",
"SYSCALL/src/"
}
for i,v in ipairs(FOLDERS) do

View File

@ -1,60 +1,37 @@
#include "SDL_audio.h"
#include <kos32sys.h>
#include <menuet/os.h>
#include <stdint.h>
#include <sys/ksys.h>
#include <stdlib.h>
#include <string.h>
#include <sound.h>
#include <stdio.h>
static void GetNotify(__u32* event)
{
__asm__("int $0x40" :: "a"(68),"b"(14),"c"(event));
}
static int CreateThread(void* fn, char* p_stack)
{
int res;
__asm__("int $0x40" : "=a"(res) : "a"(51),"b"(1),"c"(fn),"d"(p_stack));
return res;
}
static char pinfo[1024];
static int GetProcessInfo(int slot)
{
int res;
__asm__("int $0x40" : "=a"(res) : "a"(9),"b"(pinfo),"c"(slot));
return res;
}
static void ActivateWnd(int slot)
{
__asm__("int $0x40" :: "a"(18),"b"(3),"c"(slot));
}
static void Yield(void)
{
__asm__("int $0x40" :: "a"(68),"b"(1));
}
extern void SDL_printf(const char * fmt,...);
static int bInitialized=0;
static SNDBUF hBuff=0;
static char* data=NULL;
static int audio_tid=0;
#define AUDIO_THREAD_STACK_SIZE 40960
static ksys_thread_t thread_info;
static int bInitialized = 0;
static SNDBUF hBuff = 0;
static uint8_t* data = NULL;
static int audio_tid = 0;
static int main_slot;
static __u32 main_tid;
static char audio_thread_stack[40960];
static __u32 used_format=0;
static volatile int mix_size=0;
static uint32_t main_tid;
static char audio_thread_stack[AUDIO_THREAD_STACK_SIZE];
static uint32_t used_format = 0;
static int mix_size = 0;
static void (*callback)(void* userdata, Uint8* stream, int len);
static void* userdata;
int SDL_AudioInit(const char* driver_name)
{
if (bInitialized)
{
SDL_SetError("audio already initialized");
if (bInitialized) {
SDL_SetError("Audio already initialized");
return -1;
}
int ver;
if (InitSound(&ver))
{
if (InitSound(&ver)) {
SDL_printf("Warning: cannot load drivers, sound output will be disabled\n");
return 0;
}
@ -62,9 +39,7 @@ int SDL_AudioInit(const char* driver_name)
return 0;
}
void SDL_AudioQuit(void)
{
}
void SDL_AudioQuit(void) {/*STUB*/}
char* SDL_AudioDriverName(char* namebuf, int maxlen)
{
@ -77,108 +52,94 @@ char* SDL_AudioDriverName(char* namebuf, int maxlen)
#define AUDIO_SUSPEND 1
#define AUDIO_RESUME 2
#define AUDIO_DIE 3
static volatile int audio_command=0,audio_response=0,bLocked=0,bInCallback=0;
static volatile int audio_command=0, audio_response=0, bLocked=0, bInCallback=0;
static void audio_thread(void)
{
SDL_printf("audio_thread created\n");
SDL_printf("Audio_thread created\n");
int bPaused;
__u32 event[6];
ksys_signal_info_t snd_signal;
// initialize
if (CreateBuffer(used_format|PCM_RING, 0, &hBuff))
{
if (CreateBuffer(used_format|PCM_RING, 0, &hBuff)) {
audio_response=1;
exit(0);
}
GetBufferSize(hBuff, &mix_size);
SDL_printf("buffer created, size is %d\n",mix_size);
SDL_printf("buffer created, size is %d\n", mix_size);
mix_size >>= 1;
data = malloc(mix_size);
audio_response=1;
audio_response = 1;
if (!data) exit(0);
// wait for resume
while (audio_command!=AUDIO_RESUME)
Yield();
// initialize
/* bInCallback=1;
callback(userdata,data,mix_size);
SetBuffer(hBuff,data,0,mix_size);
callback(userdata,data,mix_size);
SetBuffer(hBuff,data,mix_size,mix_size);
bInCallback=0;*/
audio_command=0;
bPaused=0;
audio_response=1;
PlayBuffer(hBuff,0);
// main loop
for (;;)
{
if (audio_command==AUDIO_RESUME)
{
PlayBuffer(hBuff,0);
while (audio_command != AUDIO_RESUME)
_ksys_thread_yield();
audio_command = 0;
bPaused = 0;
audio_response = 1;
}
else if (audio_command==AUDIO_SUSPEND)
{
PlayBuffer(hBuff, 0);
// main loop
while(1) {
if (audio_command == AUDIO_RESUME) {
PlayBuffer(hBuff, 0);
audio_command = 0;
bPaused = 0;
audio_response = 1;
} else if (audio_command == AUDIO_SUSPEND) {
StopBuffer(hBuff);
audio_command = 0;
bPaused = 1;
audio_response = 1;
}
else if (audio_command==AUDIO_DIE)
{
}else if (audio_command == AUDIO_DIE) {
audio_response = 1;
StopBuffer(hBuff);
DestroyBuffer(hBuff);
exit(0);
}
else
{
GetProcessInfo(main_slot);
if (pinfo[0x32]==9 || *(__u32*)(pinfo+0x1E)!=main_tid)
{
} else {
_ksys_thread_info(&thread_info, main_slot);
if (thread_info.slot_state == KSYS_SLOT_STATE_FREE || thread_info.pid !=main_tid) {
audio_command = AUDIO_DIE;
continue;
}
}
if (bPaused)
delay(5);
else
{
GetNotify(event);
if (event[0] != 0xFF000001)
if (bPaused) {
_ksys_delay(5);
} else {
_ksys_wait_signal(&snd_signal);
if (snd_signal.id != 0xFF000001)
continue;
while (bLocked)
Yield();
_ksys_thread_yield();
bInCallback=1;
callback(userdata,data,mix_size);
callback(userdata, data, mix_size);
bInCallback=0;
SetBuffer(hBuff,data,event[3],mix_size);
SetBuffer(hBuff, data, ((int*)snd_signal.data)[2], mix_size);
}
}
}
int SDL_OpenAudio(SDL_AudioSpec* desired, SDL_AudioSpec* obtained)
{
if (!bInitialized)
{
if (!bInitialized) {
SDL_SetError("Audio device was not initialized");
return -1;
}
if (!obtained)
{
if (!obtained) {
SDL_SetError("Audio format: software emulation is not supported");
return -1;
}
if (used_format)
{
if (used_format) {
SDL_SetError("Audio device was already opened");
return -1;
}
memcpy(obtained,desired,sizeof(SDL_AudioSpec));
switch (desired->freq)
{
memcpy(obtained, desired, sizeof(SDL_AudioSpec));
switch (desired->freq) {
#define HANDLE_FREQ(freq,symb) \
case freq: \
@ -223,47 +184,48 @@ int SDL_OpenAudio(SDL_AudioSpec* desired, SDL_AudioSpec* obtained)
HANDLE_FREQ(11025,11);
HANDLE_FREQ(8000,8);
}
if (!used_format)
{
if (!used_format) {
SDL_SetError("Unknown audio format");
return -1;
}
callback=desired->callback;
userdata=desired->userdata;
GetProcessInfo(-1);
main_tid = *(__u32*)(pinfo+0x1E);
for (main_slot=0;;main_slot++)
{
GetProcessInfo(main_slot);
if (pinfo[0x32]!=9 && *(__u32*)(pinfo+0x1E)==main_tid)
callback = desired->callback;
userdata = desired->userdata;
_ksys_thread_info(&thread_info, KSYS_THIS_SLOT);
main_tid = thread_info.pid;
for (main_slot=0 ;; main_slot++) {
_ksys_thread_info(&thread_info, main_slot);
if (thread_info.slot_state != KSYS_SLOT_STATE_FREE && thread_info.pid == main_tid)
break;
}
audio_tid=CreateThread(audio_thread,audio_thread_stack+40960);
if (audio_tid<0)
{
audio_tid = _ksys_create_thread(audio_thread, audio_thread_stack+AUDIO_THREAD_STACK_SIZE);
if (audio_tid < 0) {
SDL_SetError("Cannot create audio thread");
return -1;
}
ActivateWnd(main_slot);
_ksys_focus_window(main_slot);
while (!audio_response)
Yield();
if (!hBuff)
{
_ksys_thread_yield();
if (!hBuff) {
SDL_SetError("Cannot create audio buffer");
return -1;
}
if (!data)
{
if (!data){
SDL_SetError("Cannot allocate audio buffer");
return -1;
}
obtained->silence = (desired->format == AUDIO_U8 ? 0x80 : 0);
obtained->size = mix_size;
obtained->samples = obtained->size / obtained->channels;
if (desired->format == AUDIO_U16SYS || desired->format == AUDIO_S16SYS)
obtained->samples /= 2;
SDL_printf("obtained size is %d, samples %d\n",obtained->size,
obtained->samples);
SDL_printf("obtained size is %d, samples %d\n", obtained->size, obtained->samples);
return 0;
}
void SDL_CloseAudio(void)
@ -271,8 +233,7 @@ void SDL_CloseAudio(void)
if (!audio_tid) return;
audio_response = 0;
audio_command = AUDIO_DIE;
while (!audio_response)
Yield();
while (!audio_response) _ksys_thread_yield();
free(data);
used_format = 0;
}
@ -281,16 +242,14 @@ void SDL_PauseAudio(int pause_on)
{
if (!audio_tid) return;
audio_response = 0;
audio_command = pause_on?AUDIO_SUSPEND:AUDIO_RESUME;
while (!audio_response)
Yield();
audio_command = pause_on ? AUDIO_SUSPEND : AUDIO_RESUME;
while (!audio_response) _ksys_thread_yield();
}
void SDL_LockAudio(void)
{
if (!audio_tid) return;
bLocked = 1;
while (bInCallback)
Yield();
while (bInCallback) _ksys_thread_yield();
}
void SDL_UnlockAudio(void)
{

View File

@ -219,7 +219,7 @@ void kos_CheckMouseMode(_THIS)
if (this->input_grab == SDL_GRAB_OFF)
return;
ksys_thread_t thread_info;
int top = _ksys_thread_info(&thread_info, -1);
int top = _ksys_thread_info(&thread_info, KSYS_THIS_SLOT);
if (top == thread_info.pos_in_window_stack) {
int x = thread_info.winx_start + thread_info.clientx + this->hidden->win_size_x/2;